blob: e70a010c9ac018439746c915a0b966c4f0ed4579 [file] [log] [blame]
Igor Opaniuka2846322018-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
Jens Wiklander404dee12018-09-25 16:40:21 +020026@pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc')
Igor Opaniuka2846322018-06-03 21:56:42 +030027def 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
Jens Wiklander404dee12018-09-25 16:40:21 +020039@pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc')
Igor Opaniuka2846322018-06-03 21:56:42 +030040def 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 = {}
Simon Glasse9f4d872018-12-27 08:11:13 -070054 cur_partname = ''
Igor Opaniuka2846322018-06-03 21:56:42 +030055
56 for line in part_lines:
Simon Glasse9f4d872018-12-27 08:11:13 -070057 if '"' in line:
58 start_pt = line.find('"')
59 end_pt = line.find('"', start_pt + 1)
Igor Opaniuka2846322018-06-03 21:56:42 +030060 cur_partname = line[start_pt + 1: end_pt]
61
Simon Glasse9f4d872018-12-27 08:11:13 -070062 if 'guid:' in line:
63 guid_to_check = line.split('guid:\t')
Igor Opaniuka2846322018-06-03 21:56:42 +030064 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)
Simon Glasse9f4d872018-12-27 08:11:13 -070069 assert guid == avb_guid_resp.split('UUID: ')[1]
Igor Opaniuka2846322018-06-03 21:56:42 +030070
71
Tom Rini6c03ea12018-06-18 19:04:25 -040072@pytest.mark.buildconfigspec('cmd_avb')
Igor Opaniuka2846322018-06-03 21:56:42 +030073def 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')
Jens Wiklander404dee12018-09-25 16:40:21 +020081 assert response == 'Rollback index: 0'
Igor Opaniuka2846322018-06-03 21:56:42 +030082
83
Tom Rini6c03ea12018-06-18 19:04:25 -040084@pytest.mark.buildconfigspec('cmd_avb')
Igor Opaniuka2846322018-06-03 21:56:42 +030085def test_avb_is_unlocked(u_boot_console):
86 """Test if device is in the unlocked state
87 """
88
89 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
90 assert response == ''
91
92 response = u_boot_console.run_command('avb is_unlocked')
Jens Wiklander404dee12018-09-25 16:40:21 +020093 assert response == 'Unlocked = 1'
Igor Opaniuka2846322018-06-03 21:56:42 +030094
95
Jens Wiklander404dee12018-09-25 16:40:21 +020096@pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc')
Igor Opaniuka2846322018-06-03 21:56:42 +030097def test_avb_mmc_read(u_boot_console):
98 """Test mmc read operation
99 """
100
101 response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' %
102 str(mmc_dev))
103 assert response.find('is current device')
104
105 response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
106 assert response.find('read: OK')
107
108 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
109 assert response == ''
110
111 response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' %
112 temp_addr2)
113 assert response.find('Read 512 bytes')
114
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')