blob: 770bdde4ad0cc318d495173e20ec2c5969532ae6 [file] [log] [blame]
Igor Opaniukf96c9482018-06-03 21:56:42 +03001# 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
26def 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
38def 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
70def 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
80def 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
90def 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')