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
11 check doc/android/avb2.txt
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 @pytest.mark.buildconfigspec('cmd_avb')
27 @pytest.mark.buildconfigspec('cmd_mmc')
28 def test_avb_verify(u_boot_console):
29 """Run AVB 2.0 boot verification chain with avb subset of commands
32 success_str = "Verification passed successfully"
34 response = u_boot_console.run_command('avb init %s' %str(mmc_dev))
36 response = u_boot_console.run_command('avb verify')
37 assert response.find(success_str)
40 @pytest.mark.buildconfigspec('cmd_avb')
41 @pytest.mark.buildconfigspec('cmd_mmc')
42 def test_avb_mmc_uuid(u_boot_console):
43 """Check if 'avb get_uuid' works, compare results with
44 'part list mmc 1' output
47 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
50 response = u_boot_console.run_command('mmc rescan; mmc dev %s' %
52 assert response.find('is current device')
54 part_lines = u_boot_console.run_command('mmc part').splitlines()
58 for line in part_lines:
60 start_pt = line.find('"')
61 end_pt = line.find('"', start_pt + 1)
62 cur_partname = line[start_pt + 1: end_pt]
65 guid_to_check = line.split('guid:\t')
66 part_list[cur_partname] = guid_to_check[1]
68 # lets check all guids with avb get_guid
69 for part, guid in part_list.iteritems():
70 avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part)
71 assert guid == avb_guid_resp.split('UUID: ')[1]
74 @pytest.mark.buildconfigspec('cmd_avb')
75 def test_avb_read_rb(u_boot_console):
76 """Test reading rollback indexes
79 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
82 response = u_boot_console.run_command('avb read_rb 1')
83 assert response == 'Rollback index: 0'
86 @pytest.mark.buildconfigspec('cmd_avb')
87 def test_avb_is_unlocked(u_boot_console):
88 """Test if device is in the unlocked state
91 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
94 response = u_boot_console.run_command('avb is_unlocked')
95 assert response == 'Unlocked = 1'
98 @pytest.mark.buildconfigspec('cmd_avb')
99 @pytest.mark.buildconfigspec('cmd_mmc')
100 def test_avb_mmc_read(u_boot_console):
101 """Test mmc read operation
104 response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' %
106 assert response.find('is current device')
108 response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
109 assert response.find('read: OK')
111 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
112 assert response == ''
114 response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' %
116 assert response.find('Read 512 bytes')
118 # Now lets compare two buffers
119 response = u_boot_console.run_command('cmp 0x%x 0x%x 40' %
120 (temp_addr, temp_addr2))
121 assert response.find('64 word')
124 @pytest.mark.buildconfigspec('cmd_avb')
125 @pytest.mark.buildconfigspec('optee_ta_avb')
126 def test_avb_persistent_values(u_boot_console):
127 """Test reading/writing persistent storage to avb
130 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
131 assert response == ''
133 response = u_boot_console.run_command('avb write_pvalue test value_value')
134 assert response == 'Wrote 12 bytes'
136 response = u_boot_console.run_command('avb read_pvalue test 12')
137 assert response == 'Read 12 bytes, value = value_value'