]> git.sur5r.net Git - u-boot/blob - test/py/tests/test_avb.py
libavb: Update SPDX tag style
[u-boot] / test / py / tests / test_avb.py
1 # Copyright (c) 2018, Linaro Limited
2 #
3 # SPDX-License-Identifier:  GPL-2.0+
4 #
5 # Android Verified Boot 2.0 Test
6
7 """
8 This tests Android Verified Boot 2.0 support in U-boot:
9
10 For additional details about how to build proper vbmeta partition
11 check doc/README.avb2
12
13 For configuration verification:
14 - Corrupt boot partition and check for failure
15 - Corrupt vbmeta partition and check for failure
16 """
17
18 import pytest
19 import u_boot_utils as util
20
21 # defauld mmc id
22 mmc_dev = 1
23 temp_addr = 0x90000000
24 temp_addr2 = 0x90002000
25
26 def test_avb_verify(u_boot_console):
27     """Run AVB 2.0 boot verification chain with avb subset of commands
28     """
29
30     success_str = "Verification passed successfully"
31
32     response = u_boot_console.run_command('avb init %s' %str(mmc_dev))
33     assert response == ''
34     response = u_boot_console.run_command('avb verify')
35     assert response.find(success_str)
36
37
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
41     """
42
43     response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
44     assert response == ''
45
46     response = u_boot_console.run_command('mmc rescan; mmc dev %s' %
47                                           str(mmc_dev))
48     assert response.find('is current device')
49
50     part_lines = u_boot_console.run_command('mmc part').splitlines()
51     part_list = {}
52     cur_partname = ""
53
54     for line in part_lines:
55         if "\"" in line:
56             start_pt = line.find("\"")
57             end_pt = line.find("\"", start_pt + 1)
58             cur_partname = line[start_pt + 1: end_pt]
59
60         if "guid:" in line:
61             guid_to_check = line.split("guid:\t")
62             part_list[cur_partname] = guid_to_check[1]
63
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]
68
69
70 def test_avb_read_rb(u_boot_console):
71     """Test reading rollback indexes
72     """
73
74     response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
75     assert response == ''
76
77     response = u_boot_console.run_command('avb read_rb 1')
78
79
80 def test_avb_is_unlocked(u_boot_console):
81     """Test if device is in the unlocked state
82     """
83
84     response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
85     assert response == ''
86
87     response = u_boot_console.run_command('avb is_unlocked')
88
89
90 def test_avb_mmc_read(u_boot_console):
91     """Test mmc read operation
92     """
93
94     response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' %
95                                           str(mmc_dev))
96     assert response.find('is current device')
97
98     response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
99     assert response.find('read: OK')
100
101     response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
102     assert response == ''
103
104     response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' %
105                                            temp_addr2)
106     assert response.find('Read 512 bytes')
107
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')