blob: 137d83e1deab775694385946119a4607aadc6a90 [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
Igor Opaniuka2846322018-06-03 21:56:42 +030018
19# defauld mmc id
20mmc_dev = 1
21temp_addr = 0x90000000
22temp_addr2 = 0x90002000
23
Tom Rini1ba07812019-10-24 11:59:18 -040024@pytest.mark.buildconfigspec('cmd_avb')
25@pytest.mark.buildconfigspec('cmd_mmc')
Simon Glassddba5202025-02-09 09:07:14 -070026def test_avb_verify(ubman):
Igor Opaniuka2846322018-06-03 21:56:42 +030027 """Run AVB 2.0 boot verification chain with avb subset of commands
28 """
29
30 success_str = "Verification passed successfully"
31
Simon Glassddba5202025-02-09 09:07:14 -070032 response = ubman.run_command('avb init %s' %str(mmc_dev))
Igor Opaniuka2846322018-06-03 21:56:42 +030033 assert response == ''
Simon Glassddba5202025-02-09 09:07:14 -070034 response = ubman.run_command('avb verify')
Igor Opaniuka2846322018-06-03 21:56:42 +030035 assert response.find(success_str)
36
37
Tom Rini1ba07812019-10-24 11:59:18 -040038@pytest.mark.buildconfigspec('cmd_avb')
39@pytest.mark.buildconfigspec('cmd_mmc')
Simon Glass461b7912023-01-06 08:52:19 -060040@pytest.mark.notbuildconfigspec('sandbox')
Simon Glassddba5202025-02-09 09:07:14 -070041def test_avb_mmc_uuid(ubman):
Igor Opaniuka2846322018-06-03 21:56:42 +030042 """Check if 'avb get_uuid' works, compare results with
43 'part list mmc 1' output
44 """
45
Simon Glassddba5202025-02-09 09:07:14 -070046 response = ubman.run_command('avb init %s' % str(mmc_dev))
Igor Opaniuka2846322018-06-03 21:56:42 +030047 assert response == ''
48
Simon Glassddba5202025-02-09 09:07:14 -070049 response = ubman.run_command('mmc rescan; mmc dev %s' %
Igor Opaniuka2846322018-06-03 21:56:42 +030050 str(mmc_dev))
51 assert response.find('is current device')
52
Simon Glassddba5202025-02-09 09:07:14 -070053 part_lines = ubman.run_command('mmc part').splitlines()
Igor Opaniuka2846322018-06-03 21:56:42 +030054 part_list = {}
Simon Glasse9f4d872018-12-27 08:11:13 -070055 cur_partname = ''
Igor Opaniuka2846322018-06-03 21:56:42 +030056
57 for line in part_lines:
Simon Glasse9f4d872018-12-27 08:11:13 -070058 if '"' in line:
59 start_pt = line.find('"')
60 end_pt = line.find('"', start_pt + 1)
Igor Opaniuka2846322018-06-03 21:56:42 +030061 cur_partname = line[start_pt + 1: end_pt]
62
Simon Glasse9f4d872018-12-27 08:11:13 -070063 if 'guid:' in line:
64 guid_to_check = line.split('guid:\t')
Igor Opaniuka2846322018-06-03 21:56:42 +030065 part_list[cur_partname] = guid_to_check[1]
66
67 # lets check all guids with avb get_guid
Simon Glassf7990762022-02-11 13:23:23 -070068 for part, guid in part_list.items():
Simon Glassddba5202025-02-09 09:07:14 -070069 avb_guid_resp = ubman.run_command('avb get_uuid %s' % part)
Simon Glasse9f4d872018-12-27 08:11:13 -070070 assert guid == avb_guid_resp.split('UUID: ')[1]
Igor Opaniuka2846322018-06-03 21:56:42 +030071
72
Tom Rini6c03ea12018-06-18 19:04:25 -040073@pytest.mark.buildconfigspec('cmd_avb')
Simon Glassddba5202025-02-09 09:07:14 -070074def test_avb_read_rb(ubman):
Igor Opaniuka2846322018-06-03 21:56:42 +030075 """Test reading rollback indexes
76 """
77
Simon Glassddba5202025-02-09 09:07:14 -070078 response = ubman.run_command('avb init %s' % str(mmc_dev))
Igor Opaniuka2846322018-06-03 21:56:42 +030079 assert response == ''
80
Simon Glassddba5202025-02-09 09:07:14 -070081 response = ubman.run_command('avb read_rb 1')
Jens Wiklander404dee12018-09-25 16:40:21 +020082 assert response == 'Rollback index: 0'
Igor Opaniuka2846322018-06-03 21:56:42 +030083
84
Tom Rini6c03ea12018-06-18 19:04:25 -040085@pytest.mark.buildconfigspec('cmd_avb')
Simon Glassddba5202025-02-09 09:07:14 -070086def test_avb_is_unlocked(ubman):
Igor Opaniuka2846322018-06-03 21:56:42 +030087 """Test if device is in the unlocked state
88 """
89
Simon Glassddba5202025-02-09 09:07:14 -070090 response = ubman.run_command('avb init %s' % str(mmc_dev))
Igor Opaniuka2846322018-06-03 21:56:42 +030091 assert response == ''
92
Simon Glassddba5202025-02-09 09:07:14 -070093 response = ubman.run_command('avb is_unlocked')
Jens Wiklander404dee12018-09-25 16:40:21 +020094 assert response == 'Unlocked = 1'
Igor Opaniuka2846322018-06-03 21:56:42 +030095
96
Tom Rini1ba07812019-10-24 11:59:18 -040097@pytest.mark.buildconfigspec('cmd_avb')
98@pytest.mark.buildconfigspec('cmd_mmc')
Simon Glass461b7912023-01-06 08:52:19 -060099@pytest.mark.notbuildconfigspec('sandbox')
Simon Glassddba5202025-02-09 09:07:14 -0700100def test_avb_mmc_read(ubman):
Igor Opaniuka2846322018-06-03 21:56:42 +0300101 """Test mmc read operation
102 """
103
Simon Glassddba5202025-02-09 09:07:14 -0700104 response = ubman.run_command('mmc rescan; mmc dev %s 0' %
Igor Opaniuka2846322018-06-03 21:56:42 +0300105 str(mmc_dev))
106 assert response.find('is current device')
107
Simon Glassddba5202025-02-09 09:07:14 -0700108 response = ubman.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
Igor Opaniuka2846322018-06-03 21:56:42 +0300109 assert response.find('read: OK')
110
Simon Glassddba5202025-02-09 09:07:14 -0700111 response = ubman.run_command('avb init %s' % str(mmc_dev))
Igor Opaniuka2846322018-06-03 21:56:42 +0300112 assert response == ''
113
Simon Glassddba5202025-02-09 09:07:14 -0700114 response = ubman.run_command('avb read_part xloader 0 100 0x%x' %
Igor Opaniuka2846322018-06-03 21:56:42 +0300115 temp_addr2)
116 assert response.find('Read 512 bytes')
117
118 # Now lets compare two buffers
Simon Glassddba5202025-02-09 09:07:14 -0700119 response = ubman.run_command('cmp 0x%x 0x%x 40' %
Igor Opaniuka2846322018-06-03 21:56:42 +0300120 (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')
Simon Glassddba5202025-02-09 09:07:14 -0700126def test_avb_persistent_values(ubman):
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200127 """Test reading/writing persistent storage to avb
128 """
129
Simon Glassddba5202025-02-09 09:07:14 -0700130 response = ubman.run_command('avb init %s' % str(mmc_dev))
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200131 assert response == ''
132
Simon Glassddba5202025-02-09 09:07:14 -0700133 response = ubman.run_command('avb write_pvalue test value_value')
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200134 assert response == 'Wrote 12 bytes'
135
Simon Glassddba5202025-02-09 09:07:14 -0700136 response = ubman.run_command('avb read_pvalue test 12')
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200137 assert response == 'Read 12 bytes, value = value_value'