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