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