blob: 451a476da766c972b92e66dc87f82bb1070a90c3 [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')
Simon Glassddba5202025-02-09 09:07:14 -070027def test_avb_verify(ubman):
Igor Opaniuka2846322018-06-03 21:56:42 +030028 """Run AVB 2.0 boot verification chain with avb subset of commands
29 """
30
31 success_str = "Verification passed successfully"
32
Simon Glassddba5202025-02-09 09:07:14 -070033 response = ubman.run_command('avb init %s' %str(mmc_dev))
Igor Opaniuka2846322018-06-03 21:56:42 +030034 assert response == ''
Simon Glassddba5202025-02-09 09:07:14 -070035 response = ubman.run_command('avb verify')
Igor Opaniuka2846322018-06-03 21:56:42 +030036 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')
Simon Glassddba5202025-02-09 09:07:14 -070042def test_avb_mmc_uuid(ubman):
Igor Opaniuka2846322018-06-03 21:56:42 +030043 """Check if 'avb get_uuid' works, compare results with
44 'part list mmc 1' output
45 """
46
Simon Glassddba5202025-02-09 09:07:14 -070047 response = ubman.run_command('avb init %s' % str(mmc_dev))
Igor Opaniuka2846322018-06-03 21:56:42 +030048 assert response == ''
49
Simon Glassddba5202025-02-09 09:07:14 -070050 response = ubman.run_command('mmc rescan; mmc dev %s' %
Igor Opaniuka2846322018-06-03 21:56:42 +030051 str(mmc_dev))
52 assert response.find('is current device')
53
Simon Glassddba5202025-02-09 09:07:14 -070054 part_lines = ubman.run_command('mmc part').splitlines()
Igor Opaniuka2846322018-06-03 21:56:42 +030055 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():
Simon Glassddba5202025-02-09 09:07:14 -070070 avb_guid_resp = ubman.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')
Simon Glassddba5202025-02-09 09:07:14 -070075def test_avb_read_rb(ubman):
Igor Opaniuka2846322018-06-03 21:56:42 +030076 """Test reading rollback indexes
77 """
78
Simon Glassddba5202025-02-09 09:07:14 -070079 response = ubman.run_command('avb init %s' % str(mmc_dev))
Igor Opaniuka2846322018-06-03 21:56:42 +030080 assert response == ''
81
Simon Glassddba5202025-02-09 09:07:14 -070082 response = ubman.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')
Simon Glassddba5202025-02-09 09:07:14 -070087def test_avb_is_unlocked(ubman):
Igor Opaniuka2846322018-06-03 21:56:42 +030088 """Test if device is in the unlocked state
89 """
90
Simon Glassddba5202025-02-09 09:07:14 -070091 response = ubman.run_command('avb init %s' % str(mmc_dev))
Igor Opaniuka2846322018-06-03 21:56:42 +030092 assert response == ''
93
Simon Glassddba5202025-02-09 09:07:14 -070094 response = ubman.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')
Simon Glassddba5202025-02-09 09:07:14 -0700101def test_avb_mmc_read(ubman):
Igor Opaniuka2846322018-06-03 21:56:42 +0300102 """Test mmc read operation
103 """
104
Simon Glassddba5202025-02-09 09:07:14 -0700105 response = ubman.run_command('mmc rescan; mmc dev %s 0' %
Igor Opaniuka2846322018-06-03 21:56:42 +0300106 str(mmc_dev))
107 assert response.find('is current device')
108
Simon Glassddba5202025-02-09 09:07:14 -0700109 response = ubman.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
Igor Opaniuka2846322018-06-03 21:56:42 +0300110 assert response.find('read: OK')
111
Simon Glassddba5202025-02-09 09:07:14 -0700112 response = ubman.run_command('avb init %s' % str(mmc_dev))
Igor Opaniuka2846322018-06-03 21:56:42 +0300113 assert response == ''
114
Simon Glassddba5202025-02-09 09:07:14 -0700115 response = ubman.run_command('avb read_part xloader 0 100 0x%x' %
Igor Opaniuka2846322018-06-03 21:56:42 +0300116 temp_addr2)
117 assert response.find('Read 512 bytes')
118
119 # Now lets compare two buffers
Simon Glassddba5202025-02-09 09:07:14 -0700120 response = ubman.run_command('cmp 0x%x 0x%x 40' %
Igor Opaniuka2846322018-06-03 21:56:42 +0300121 (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')
Simon Glassddba5202025-02-09 09:07:14 -0700127def test_avb_persistent_values(ubman):
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200128 """Test reading/writing persistent storage to avb
129 """
130
Simon Glassddba5202025-02-09 09:07:14 -0700131 response = ubman.run_command('avb init %s' % str(mmc_dev))
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200132 assert response == ''
133
Simon Glassddba5202025-02-09 09:07:14 -0700134 response = ubman.run_command('avb write_pvalue test value_value')
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200135 assert response == 'Wrote 12 bytes'
136
Simon Glassddba5202025-02-09 09:07:14 -0700137 response = ubman.run_command('avb read_pvalue test 12')
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200138 assert response == 'Read 12 bytes, value = value_value'