GK SDK 源码库: XMIPCLinuxV100R005C00SPC030 (kernel/tools/open_source excluded)

This commit is contained in:
lai
2026-09-06 03:52:57 +08:00
commit b1928b41c0
21813 changed files with 4413081 additions and 0 deletions
@@ -0,0 +1,75 @@
# SPDX-License-Identifier: GPL-2.0
# (C) Copyright 2018 Texas Instruments, <www.ti.com>
# Test A/B update commands.
import os
import pytest
import u_boot_utils
class ABTestDiskImage(object):
"""Disk Image used by the A/B tests."""
def __init__(self, u_boot_console):
"""Initialize a new ABTestDiskImage object.
Args:
u_boot_console: A U-Boot console.
Returns:
Nothing.
"""
filename = 'test_ab_disk_image.bin'
persistent = u_boot_console.config.persistent_data_dir + '/' + filename
self.path = u_boot_console.config.result_dir + '/' + filename
with u_boot_utils.persistent_file_helper(u_boot_console.log, persistent):
if os.path.exists(persistent):
u_boot_console.log.action('Disk image file ' + persistent +
' already exists')
else:
u_boot_console.log.action('Generating ' + persistent)
fd = os.open(persistent, os.O_RDWR | os.O_CREAT)
os.ftruncate(fd, 524288)
os.close(fd)
cmd = ('sgdisk', persistent)
u_boot_utils.run_and_log(u_boot_console, cmd)
cmd = ('sgdisk', '--new=1:64:512', '--change-name=1:misc',
persistent)
u_boot_utils.run_and_log(u_boot_console, cmd)
cmd = ('sgdisk', '--load-backup=' + persistent)
u_boot_utils.run_and_log(u_boot_console, cmd)
cmd = ('cp', persistent, self.path)
u_boot_utils.run_and_log(u_boot_console, cmd)
di = None
@pytest.fixture(scope='function')
def ab_disk_image(u_boot_console):
global di
if not di:
di = ABTestDiskImage(u_boot_console)
return di
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('android_ab')
@pytest.mark.buildconfigspec('cmd_ab_select')
@pytest.mark.requiredtool('sgdisk')
def test_ab(ab_disk_image, u_boot_console):
"""Test the 'ab_select' command."""
u_boot_console.run_command('host bind 0 ' + ab_disk_image.path)
output = u_boot_console.run_command('ab_select slot_name host 0#misc')
assert 're-initializing A/B metadata' in output
assert 'Attempting slot a, tries remaining 7' in output
output = u_boot_console.run_command('printenv slot_name')
assert 'slot_name=a' in output
output = u_boot_console.run_command('ab_select slot_name host 0:1')
assert 'Attempting slot b, tries remaining 7' in output
output = u_boot_console.run_command('printenv slot_name')
assert 'slot_name=b' in output
@@ -0,0 +1,137 @@
# Copyright (c) 2018, Linaro Limited
#
# SPDX-License-Identifier: GPL-2.0+
#
# Android Verified Boot 2.0 Test
"""
This tests Android Verified Boot 2.0 support in U-boot:
For additional details about how to build proper vbmeta partition
check doc/android/avb2.txt
For configuration verification:
- Corrupt boot partition and check for failure
- Corrupt vbmeta partition and check for failure
"""
import pytest
import u_boot_utils as util
# defauld mmc id
mmc_dev = 1
temp_addr = 0x90000000
temp_addr2 = 0x90002000
@pytest.mark.buildconfigspec('cmd_avb')
@pytest.mark.buildconfigspec('cmd_mmc')
def test_avb_verify(u_boot_console):
"""Run AVB 2.0 boot verification chain with avb subset of commands
"""
success_str = "Verification passed successfully"
response = u_boot_console.run_command('avb init %s' %str(mmc_dev))
assert response == ''
response = u_boot_console.run_command('avb verify')
assert response.find(success_str)
@pytest.mark.buildconfigspec('cmd_avb')
@pytest.mark.buildconfigspec('cmd_mmc')
def test_avb_mmc_uuid(u_boot_console):
"""Check if 'avb get_uuid' works, compare results with
'part list mmc 1' output
"""
response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
assert response == ''
response = u_boot_console.run_command('mmc rescan; mmc dev %s' %
str(mmc_dev))
assert response.find('is current device')
part_lines = u_boot_console.run_command('mmc part').splitlines()
part_list = {}
cur_partname = ''
for line in part_lines:
if '"' in line:
start_pt = line.find('"')
end_pt = line.find('"', start_pt + 1)
cur_partname = line[start_pt + 1: end_pt]
if 'guid:' in line:
guid_to_check = line.split('guid:\t')
part_list[cur_partname] = guid_to_check[1]
# lets check all guids with avb get_guid
for part, guid in part_list.iteritems():
avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part)
assert guid == avb_guid_resp.split('UUID: ')[1]
@pytest.mark.buildconfigspec('cmd_avb')
def test_avb_read_rb(u_boot_console):
"""Test reading rollback indexes
"""
response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
assert response == ''
response = u_boot_console.run_command('avb read_rb 1')
assert response == 'Rollback index: 0'
@pytest.mark.buildconfigspec('cmd_avb')
def test_avb_is_unlocked(u_boot_console):
"""Test if device is in the unlocked state
"""
response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
assert response == ''
response = u_boot_console.run_command('avb is_unlocked')
assert response == 'Unlocked = 1'
@pytest.mark.buildconfigspec('cmd_avb')
@pytest.mark.buildconfigspec('cmd_mmc')
def test_avb_mmc_read(u_boot_console):
"""Test mmc read operation
"""
response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' %
str(mmc_dev))
assert response.find('is current device')
response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
assert response.find('read: OK')
response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
assert response == ''
response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' %
temp_addr2)
assert response.find('Read 512 bytes')
# Now lets compare two buffers
response = u_boot_console.run_command('cmp 0x%x 0x%x 40' %
(temp_addr, temp_addr2))
assert response.find('64 word')
@pytest.mark.buildconfigspec('cmd_avb')
@pytest.mark.buildconfigspec('optee_ta_avb')
def test_avb_persistent_values(u_boot_console):
"""Test reading/writing persistent storage to avb
"""
response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
assert response == ''
response = u_boot_console.run_command('avb write_pvalue test value_value')
assert response == 'Wrote 12 bytes'
response = u_boot_console.run_command('avb read_pvalue test 12')
assert response == 'Read 12 bytes, value = value_value'