]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - test/py/tests/test_avb.py
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', 'cmd_mmc')
27 def test_avb_verify(u_boot_console
):
28 """Run AVB 2.0 boot verification chain with avb subset of commands
31 success_str
= "Verification passed successfully"
33 response
= u_boot_console
.run_command('avb init %s' %str
(mmc_dev
))
35 response
= u_boot_console
.run_command('avb verify')
36 assert response
.find(success_str
)
39 @pytest.mark
.buildconfigspec('cmd_avb', 'cmd_mmc')
40 def test_avb_mmc_uuid(u_boot_console
):
41 """Check if 'avb get_uuid' works, compare results with
42 'part list mmc 1' output
45 response
= u_boot_console
.run_command('avb init %s' % str(mmc_dev
))
48 response
= u_boot_console
.run_command('mmc rescan; mmc dev %s' %
50 assert response
.find('is current device')
52 part_lines
= u_boot_console
.run_command('mmc part').splitlines()
56 for line
in part_lines
:
58 start_pt
= line
.find('"')
59 end_pt
= line
.find('"', start_pt
+ 1)
60 cur_partname
= line
[start_pt
+ 1: end_pt
]
63 guid_to_check
= line
.split('guid:\t')
64 part_list
[cur_partname
] = guid_to_check
[1]
66 # lets check all guids with avb get_guid
67 for part
, guid
in part_list
.iteritems():
68 avb_guid_resp
= u_boot_console
.run_command('avb get_uuid %s' % part
)
69 assert guid
== avb_guid_resp
.split('UUID: ')[1]
72 @pytest.mark
.buildconfigspec('cmd_avb')
73 def test_avb_read_rb(u_boot_console
):
74 """Test reading rollback indexes
77 response
= u_boot_console
.run_command('avb init %s' % str(mmc_dev
))
80 response
= u_boot_console
.run_command('avb read_rb 1')
81 assert response
== 'Rollback index: 0'
84 @pytest.mark
.buildconfigspec('cmd_avb')
85 def test_avb_is_unlocked(u_boot_console
):
86 """Test if device is in the unlocked state
89 response
= u_boot_console
.run_command('avb init %s' % str(mmc_dev
))
92 response
= u_boot_console
.run_command('avb is_unlocked')
93 assert response
== 'Unlocked = 1'
96 @pytest.mark
.buildconfigspec('cmd_avb', 'cmd_mmc')
97 def test_avb_mmc_read(u_boot_console
):
98 """Test mmc read operation
101 response
= u_boot_console
.run_command('mmc rescan; mmc dev %s 0' %
103 assert response
.find('is current device')
105 response
= u_boot_console
.run_command('mmc read 0x%x 0x100 0x1' % temp_addr
)
106 assert response
.find('read: OK')
108 response
= u_boot_console
.run_command('avb init %s' % str(mmc_dev
))
109 assert response
== ''
111 response
= u_boot_console
.run_command('avb read_part xloader 0 100 0x%x' %
113 assert response
.find('Read 512 bytes')
115 # Now lets compare two buffers
116 response
= u_boot_console
.run_command('cmp 0x%x 0x%x 40' %
117 (temp_addr
, temp_addr2
))
118 assert response
.find('64 word')
121 @pytest.mark
.buildconfigspec('cmd_avb')
122 @pytest.mark
.buildconfigspec('optee_ta_avb')
123 def test_avb_persistent_values(u_boot_console
):
124 """Test reading/writing persistent storage to avb
127 response
= u_boot_console
.run_command('avb init %s' % str(mmc_dev
))
128 assert response
== ''
130 response
= u_boot_console
.run_command('avb write_pvalue test value_value')
131 assert response
== 'Wrote 12 bytes'
133 response
= u_boot_console
.run_command('avb read_pvalue test 12')
134 assert response
== 'Read 12 bytes, value = value_value'