1 # Copyright (c) 2018, Linaro Limited
3 # SPDX-License-Identifier: GPL-2.0+
5 # Android Verified Boot 2.0 Test
8 This tests Android Verified Boot 2.0 support in U-boot:
10 For additional details about how to build proper vbmeta partition
13 For configuration verification:
14 - Corrupt boot partition and check for failure
15 - Corrupt vbmeta partition and check for failure
19 import u_boot_utils as util
23 temp_addr = 0x90000000
24 temp_addr2 = 0x90002000
26 def test_avb_verify(u_boot_console):
27 """Run AVB 2.0 boot verification chain with avb subset of commands
30 success_str = "Verification passed successfully"
32 response = u_boot_console.run_command('avb init %s' %str(mmc_dev))
34 response = u_boot_console.run_command('avb verify')
35 assert response.find(success_str)
38 def test_avb_mmc_uuid(u_boot_console):
39 """Check if 'avb get_uuid' works, compare results with
40 'part list mmc 1' output
43 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
46 response = u_boot_console.run_command('mmc rescan; mmc dev %s' %
48 assert response.find('is current device')
50 part_lines = u_boot_console.run_command('mmc part').splitlines()
54 for line in part_lines:
56 start_pt = line.find("\"")
57 end_pt = line.find("\"", start_pt + 1)
58 cur_partname = line[start_pt + 1: end_pt]
61 guid_to_check = line.split("guid:\t")
62 part_list[cur_partname] = guid_to_check[1]
64 # lets check all guids with avb get_guid
65 for part, guid in part_list.iteritems():
66 avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part)
67 assert guid == avb_guid_resp.split("UUID: ")[1]
70 def test_avb_read_rb(u_boot_console):
71 """Test reading rollback indexes
74 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
77 response = u_boot_console.run_command('avb read_rb 1')
80 def test_avb_is_unlocked(u_boot_console):
81 """Test if device is in the unlocked state
84 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
87 response = u_boot_console.run_command('avb is_unlocked')
90 def test_avb_mmc_read(u_boot_console):
91 """Test mmc read operation
94 response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' %
96 assert response.find('is current device')
98 response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
99 assert response.find('read: OK')
101 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
102 assert response == ''
104 response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' %
106 assert response.find('Read 512 bytes')
108 # Now lets compare two buffers
109 response = u_boot_console.run_command('cmp 0x%x 0x%x 40' %
110 (temp_addr, temp_addr2))
111 assert response.find('64 word')