blob: 20ccaf6712f2008282a35c8524f3a370b83409d7 [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
Eugeniu Roscac37e68f2019-07-19 23:26:11 +020011check doc/android/avb2.txt
Igor Opaniuka2846322018-06-03 21:56:42 +030012
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
Tom Rini1ba07812019-10-24 11:59:18 -040026@pytest.mark.buildconfigspec('cmd_avb')
27@pytest.mark.buildconfigspec('cmd_mmc')
Igor Opaniuka2846322018-06-03 21:56:42 +030028def test_avb_verify(u_boot_console):
29 """Run AVB 2.0 boot verification chain with avb subset of commands
30 """
31
32 success_str = "Verification passed successfully"
33
34 response = u_boot_console.run_command('avb init %s' %str(mmc_dev))
35 assert response == ''
36 response = u_boot_console.run_command('avb verify')
37 assert response.find(success_str)
38
39
Tom Rini1ba07812019-10-24 11:59:18 -040040@pytest.mark.buildconfigspec('cmd_avb')
41@pytest.mark.buildconfigspec('cmd_mmc')
Igor Opaniuka2846322018-06-03 21:56:42 +030042def test_avb_mmc_uuid(u_boot_console):
43 """Check if 'avb get_uuid' works, compare results with
44 'part list mmc 1' output
45 """
46
47 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
48 assert response == ''
49
50 response = u_boot_console.run_command('mmc rescan; mmc dev %s' %
51 str(mmc_dev))
52 assert response.find('is current device')
53
54 part_lines = u_boot_console.run_command('mmc part').splitlines()
55 part_list = {}
Simon Glasse9f4d872018-12-27 08:11:13 -070056 cur_partname = ''
Igor Opaniuka2846322018-06-03 21:56:42 +030057
58 for line in part_lines:
Simon Glasse9f4d872018-12-27 08:11:13 -070059 if '"' in line:
60 start_pt = line.find('"')
61 end_pt = line.find('"', start_pt + 1)
Igor Opaniuka2846322018-06-03 21:56:42 +030062 cur_partname = line[start_pt + 1: end_pt]
63
Simon Glasse9f4d872018-12-27 08:11:13 -070064 if 'guid:' in line:
65 guid_to_check = line.split('guid:\t')
Igor Opaniuka2846322018-06-03 21:56:42 +030066 part_list[cur_partname] = guid_to_check[1]
67
68 # lets check all guids with avb get_guid
69 for part, guid in part_list.iteritems():
70 avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part)
Simon Glasse9f4d872018-12-27 08:11:13 -070071 assert guid == avb_guid_resp.split('UUID: ')[1]
Igor Opaniuka2846322018-06-03 21:56:42 +030072
73
Tom Rini6c03ea12018-06-18 19:04:25 -040074@pytest.mark.buildconfigspec('cmd_avb')
Igor Opaniuka2846322018-06-03 21:56:42 +030075def test_avb_read_rb(u_boot_console):
76 """Test reading rollback indexes
77 """
78
79 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
80 assert response == ''
81
82 response = u_boot_console.run_command('avb read_rb 1')
Jens Wiklander404dee12018-09-25 16:40:21 +020083 assert response == 'Rollback index: 0'
Igor Opaniuka2846322018-06-03 21:56:42 +030084
85
Tom Rini6c03ea12018-06-18 19:04:25 -040086@pytest.mark.buildconfigspec('cmd_avb')
Igor Opaniuka2846322018-06-03 21:56:42 +030087def test_avb_is_unlocked(u_boot_console):
88 """Test if device is in the unlocked state
89 """
90
91 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
92 assert response == ''
93
94 response = u_boot_console.run_command('avb is_unlocked')
Jens Wiklander404dee12018-09-25 16:40:21 +020095 assert response == 'Unlocked = 1'
Igor Opaniuka2846322018-06-03 21:56:42 +030096
97
Tom Rini1ba07812019-10-24 11:59:18 -040098@pytest.mark.buildconfigspec('cmd_avb')
99@pytest.mark.buildconfigspec('cmd_mmc')
Igor Opaniuka2846322018-06-03 21:56:42 +0300100def test_avb_mmc_read(u_boot_console):
101 """Test mmc read operation
102 """
103
104 response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' %
105 str(mmc_dev))
106 assert response.find('is current device')
107
108 response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
109 assert response.find('read: OK')
110
111 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
112 assert response == ''
113
114 response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' %
115 temp_addr2)
116 assert response.find('Read 512 bytes')
117
118 # Now lets compare two buffers
119 response = u_boot_console.run_command('cmp 0x%x 0x%x 40' %
120 (temp_addr, temp_addr2))
121 assert response.find('64 word')
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200122
123
124@pytest.mark.buildconfigspec('cmd_avb')
125@pytest.mark.buildconfigspec('optee_ta_avb')
126def test_avb_persistent_values(u_boot_console):
127 """Test reading/writing persistent storage to avb
128 """
129
130 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
131 assert response == ''
132
133 response = u_boot_console.run_command('avb write_pvalue test value_value')
134 assert response == 'Wrote 12 bytes'
135
136 response = u_boot_console.run_command('avb read_pvalue test 12')
137 assert response == 'Read 12 bytes, value = value_value'