2018-06-03 18:56:42 +00:00
|
|
|
# Copyright (c) 2018, Linaro Limited
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
|
|
|
#
|
|
|
|
# Android Verified Boot 2.0 Test
|
|
|
|
|
|
|
|
"""
|
2023-05-17 07:17:16 +00:00
|
|
|
This tests Android Verified Boot 2.0 support in U-Boot:
|
2018-06-03 18:56:42 +00:00
|
|
|
|
|
|
|
For additional details about how to build proper vbmeta partition
|
2020-01-24 15:53:44 +00:00
|
|
|
check doc/android/avb2.rst
|
2018-06-03 18:56:42 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-10-24 15:59:18 +00:00
|
|
|
@pytest.mark.buildconfigspec('cmd_avb')
|
|
|
|
@pytest.mark.buildconfigspec('cmd_mmc')
|
2018-06-03 18:56:42 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2019-10-24 15:59:18 +00:00
|
|
|
@pytest.mark.buildconfigspec('cmd_avb')
|
|
|
|
@pytest.mark.buildconfigspec('cmd_mmc')
|
2023-01-06 14:52:19 +00:00
|
|
|
@pytest.mark.notbuildconfigspec('sandbox')
|
2018-06-03 18:56:42 +00:00
|
|
|
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 = {}
|
2018-12-27 15:11:13 +00:00
|
|
|
cur_partname = ''
|
2018-06-03 18:56:42 +00:00
|
|
|
|
|
|
|
for line in part_lines:
|
2018-12-27 15:11:13 +00:00
|
|
|
if '"' in line:
|
|
|
|
start_pt = line.find('"')
|
|
|
|
end_pt = line.find('"', start_pt + 1)
|
2018-06-03 18:56:42 +00:00
|
|
|
cur_partname = line[start_pt + 1: end_pt]
|
|
|
|
|
2018-12-27 15:11:13 +00:00
|
|
|
if 'guid:' in line:
|
|
|
|
guid_to_check = line.split('guid:\t')
|
2018-06-03 18:56:42 +00:00
|
|
|
part_list[cur_partname] = guid_to_check[1]
|
|
|
|
|
|
|
|
# lets check all guids with avb get_guid
|
2022-02-11 20:23:23 +00:00
|
|
|
for part, guid in part_list.items():
|
2018-06-03 18:56:42 +00:00
|
|
|
avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part)
|
2018-12-27 15:11:13 +00:00
|
|
|
assert guid == avb_guid_resp.split('UUID: ')[1]
|
2018-06-03 18:56:42 +00:00
|
|
|
|
|
|
|
|
2018-06-18 23:04:25 +00:00
|
|
|
@pytest.mark.buildconfigspec('cmd_avb')
|
2018-06-03 18:56:42 +00:00
|
|
|
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')
|
2018-09-25 14:40:21 +00:00
|
|
|
assert response == 'Rollback index: 0'
|
2018-06-03 18:56:42 +00:00
|
|
|
|
|
|
|
|
2018-06-18 23:04:25 +00:00
|
|
|
@pytest.mark.buildconfigspec('cmd_avb')
|
2018-06-03 18:56:42 +00:00
|
|
|
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')
|
2018-09-25 14:40:21 +00:00
|
|
|
assert response == 'Unlocked = 1'
|
2018-06-03 18:56:42 +00:00
|
|
|
|
|
|
|
|
2019-10-24 15:59:18 +00:00
|
|
|
@pytest.mark.buildconfigspec('cmd_avb')
|
|
|
|
@pytest.mark.buildconfigspec('cmd_mmc')
|
2023-01-06 14:52:19 +00:00
|
|
|
@pytest.mark.notbuildconfigspec('sandbox')
|
2018-06-03 18:56:42 +00:00
|
|
|
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')
|
2019-04-09 13:38:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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'
|