Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 1 | # Copyright (c) 2018, Linaro Limited |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0+ |
| 4 | # |
| 5 | # Android Verified Boot 2.0 Test |
| 6 | |
| 7 | """ |
Michal Simek | 50fa118 | 2023-05-17 09:17:16 +0200 | [diff] [blame] | 8 | This tests Android Verified Boot 2.0 support in U-Boot: |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 9 | |
| 10 | For additional details about how to build proper vbmeta partition |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 11 | check doc/android/avb2.rst |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 12 | |
| 13 | For configuration verification: |
| 14 | - Corrupt boot partition and check for failure |
| 15 | - Corrupt vbmeta partition and check for failure |
| 16 | """ |
| 17 | |
| 18 | import pytest |
| 19 | import u_boot_utils as util |
| 20 | |
| 21 | # defauld mmc id |
| 22 | mmc_dev = 1 |
| 23 | temp_addr = 0x90000000 |
| 24 | temp_addr2 = 0x90002000 |
| 25 | |
Tom Rini | 1ba0781 | 2019-10-24 11:59:18 -0400 | [diff] [blame] | 26 | @pytest.mark.buildconfigspec('cmd_avb') |
| 27 | @pytest.mark.buildconfigspec('cmd_mmc') |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 28 | def 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 Rini | 1ba0781 | 2019-10-24 11:59:18 -0400 | [diff] [blame] | 40 | @pytest.mark.buildconfigspec('cmd_avb') |
| 41 | @pytest.mark.buildconfigspec('cmd_mmc') |
Simon Glass | 461b791 | 2023-01-06 08:52:19 -0600 | [diff] [blame] | 42 | @pytest.mark.notbuildconfigspec('sandbox') |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 43 | def test_avb_mmc_uuid(u_boot_console): |
| 44 | """Check if 'avb get_uuid' works, compare results with |
| 45 | 'part list mmc 1' output |
| 46 | """ |
| 47 | |
| 48 | response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) |
| 49 | assert response == '' |
| 50 | |
| 51 | response = u_boot_console.run_command('mmc rescan; mmc dev %s' % |
| 52 | str(mmc_dev)) |
| 53 | assert response.find('is current device') |
| 54 | |
| 55 | part_lines = u_boot_console.run_command('mmc part').splitlines() |
| 56 | part_list = {} |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame] | 57 | cur_partname = '' |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 58 | |
| 59 | for line in part_lines: |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame] | 60 | if '"' in line: |
| 61 | start_pt = line.find('"') |
| 62 | end_pt = line.find('"', start_pt + 1) |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 63 | cur_partname = line[start_pt + 1: end_pt] |
| 64 | |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame] | 65 | if 'guid:' in line: |
| 66 | guid_to_check = line.split('guid:\t') |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 67 | part_list[cur_partname] = guid_to_check[1] |
| 68 | |
| 69 | # lets check all guids with avb get_guid |
Simon Glass | f799076 | 2022-02-11 13:23:23 -0700 | [diff] [blame] | 70 | for part, guid in part_list.items(): |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 71 | avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part) |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame] | 72 | assert guid == avb_guid_resp.split('UUID: ')[1] |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 73 | |
| 74 | |
Tom Rini | 6c03ea1 | 2018-06-18 19:04:25 -0400 | [diff] [blame] | 75 | @pytest.mark.buildconfigspec('cmd_avb') |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 76 | def test_avb_read_rb(u_boot_console): |
| 77 | """Test reading rollback indexes |
| 78 | """ |
| 79 | |
| 80 | response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) |
| 81 | assert response == '' |
| 82 | |
| 83 | response = u_boot_console.run_command('avb read_rb 1') |
Jens Wiklander | 404dee1 | 2018-09-25 16:40:21 +0200 | [diff] [blame] | 84 | assert response == 'Rollback index: 0' |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 85 | |
| 86 | |
Tom Rini | 6c03ea1 | 2018-06-18 19:04:25 -0400 | [diff] [blame] | 87 | @pytest.mark.buildconfigspec('cmd_avb') |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 88 | def test_avb_is_unlocked(u_boot_console): |
| 89 | """Test if device is in the unlocked state |
| 90 | """ |
| 91 | |
| 92 | response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) |
| 93 | assert response == '' |
| 94 | |
| 95 | response = u_boot_console.run_command('avb is_unlocked') |
Jens Wiklander | 404dee1 | 2018-09-25 16:40:21 +0200 | [diff] [blame] | 96 | assert response == 'Unlocked = 1' |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 97 | |
| 98 | |
Tom Rini | 1ba0781 | 2019-10-24 11:59:18 -0400 | [diff] [blame] | 99 | @pytest.mark.buildconfigspec('cmd_avb') |
| 100 | @pytest.mark.buildconfigspec('cmd_mmc') |
Simon Glass | 461b791 | 2023-01-06 08:52:19 -0600 | [diff] [blame] | 101 | @pytest.mark.notbuildconfigspec('sandbox') |
Igor Opaniuk | a284632 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 102 | def test_avb_mmc_read(u_boot_console): |
| 103 | """Test mmc read operation |
| 104 | """ |
| 105 | |
| 106 | response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' % |
| 107 | str(mmc_dev)) |
| 108 | assert response.find('is current device') |
| 109 | |
| 110 | response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr) |
| 111 | assert response.find('read: OK') |
| 112 | |
| 113 | response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) |
| 114 | assert response == '' |
| 115 | |
| 116 | response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' % |
| 117 | temp_addr2) |
| 118 | assert response.find('Read 512 bytes') |
| 119 | |
| 120 | # Now lets compare two buffers |
| 121 | response = u_boot_console.run_command('cmp 0x%x 0x%x 40' % |
| 122 | (temp_addr, temp_addr2)) |
| 123 | assert response.find('64 word') |
Igor Opaniuk | 78b0b9d | 2019-04-09 15:38:14 +0200 | [diff] [blame] | 124 | |
| 125 | |
| 126 | @pytest.mark.buildconfigspec('cmd_avb') |
| 127 | @pytest.mark.buildconfigspec('optee_ta_avb') |
| 128 | def test_avb_persistent_values(u_boot_console): |
| 129 | """Test reading/writing persistent storage to avb |
| 130 | """ |
| 131 | |
| 132 | response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) |
| 133 | assert response == '' |
| 134 | |
| 135 | response = u_boot_console.run_command('avb write_pvalue test value_value') |
| 136 | assert response == 'Wrote 12 bytes' |
| 137 | |
| 138 | response = u_boot_console.run_command('avb read_pvalue test 12') |
| 139 | assert response == 'Read 12 bytes, value = value_value' |