blob: 865efbca4de784e193bf0670bf3e13e8309bb8bb [file] [log] [blame]
Igor Opaniuka2846322018-06-03 21:56:42 +03001# SPDX-License-Identifier: GPL-2.0+
Igor Opaniuk29cb8862024-02-09 20:20:40 +01002# Copyright (c) 2018, Linaro Limited
Igor Opaniuka2846322018-06-03 21:56:42 +03003#
4# Android Verified Boot 2.0 Test
5
6"""
Michal Simek50fa1182023-05-17 09:17:16 +02007This tests Android Verified Boot 2.0 support in U-Boot:
Igor Opaniuka2846322018-06-03 21:56:42 +03008
9For additional details about how to build proper vbmeta partition
Sam Protsenkocd43fa12020-01-24 17:53:44 +020010check doc/android/avb2.rst
Igor Opaniuka2846322018-06-03 21:56:42 +030011
12For configuration verification:
13- Corrupt boot partition and check for failure
14- Corrupt vbmeta partition and check for failure
15"""
16
17import pytest
18import u_boot_utils as util
19
20# defauld mmc id
21mmc_dev = 1
22temp_addr = 0x90000000
23temp_addr2 = 0x90002000
24
Tom Rini1ba07812019-10-24 11:59:18 -040025@pytest.mark.buildconfigspec('cmd_avb')
26@pytest.mark.buildconfigspec('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
Tom Rini1ba07812019-10-24 11:59:18 -040039@pytest.mark.buildconfigspec('cmd_avb')
40@pytest.mark.buildconfigspec('cmd_mmc')
Simon Glass461b7912023-01-06 08:52:19 -060041@pytest.mark.notbuildconfigspec('sandbox')
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
Simon Glassf7990762022-02-11 13:23:23 -070069 for part, guid in part_list.items():
Igor Opaniuka2846322018-06-03 21:56:42 +030070 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')
Simon Glass461b7912023-01-06 08:52:19 -0600100@pytest.mark.notbuildconfigspec('sandbox')
Igor Opaniuka2846322018-06-03 21:56:42 +0300101def test_avb_mmc_read(u_boot_console):
102 """Test mmc read operation
103 """
104
105 response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' %
106 str(mmc_dev))
107 assert response.find('is current device')
108
109 response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
110 assert response.find('read: OK')
111
112 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
113 assert response == ''
114
115 response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' %
116 temp_addr2)
117 assert response.find('Read 512 bytes')
118
119 # Now lets compare two buffers
120 response = u_boot_console.run_command('cmp 0x%x 0x%x 40' %
121 (temp_addr, temp_addr2))
122 assert response.find('64 word')
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200123
124
125@pytest.mark.buildconfigspec('cmd_avb')
126@pytest.mark.buildconfigspec('optee_ta_avb')
127def test_avb_persistent_values(u_boot_console):
128 """Test reading/writing persistent storage to avb
129 """
130
131 response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
132 assert response == ''
133
134 response = u_boot_console.run_command('avb write_pvalue test value_value')
135 assert response == 'Wrote 12 bytes'
136
137 response = u_boot_console.run_command('avb read_pvalue test 12')
138 assert response == 'Read 12 bytes, value = value_value'