Igor Opaniuk | f96c948 | 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 | """ |
| 8 | This tests Android Verified Boot 2.0 support in U-boot: |
| 9 | |
| 10 | For additional details about how to build proper vbmeta partition |
| 11 | check doc/README.avb2 |
| 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 | |
Jens Wiklander | 07cbae7 | 2018-09-25 16:40:21 +0200 | [diff] [blame] | 26 | @pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc') |
Igor Opaniuk | f96c948 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 27 | def 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 | |
Jens Wiklander | 07cbae7 | 2018-09-25 16:40:21 +0200 | [diff] [blame] | 39 | @pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc') |
Igor Opaniuk | f96c948 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 40 | def test_avb_mmc_uuid(u_boot_console): |
| 41 | """Check if 'avb get_uuid' works, compare results with |
| 42 | 'part list mmc 1' output |
| 43 | """ |
| 44 | |
| 45 | response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) |
| 46 | assert response == '' |
| 47 | |
| 48 | response = u_boot_console.run_command('mmc rescan; mmc dev %s' % |
| 49 | str(mmc_dev)) |
| 50 | assert response.find('is current device') |
| 51 | |
| 52 | part_lines = u_boot_console.run_command('mmc part').splitlines() |
| 53 | part_list = {} |
| 54 | cur_partname = "" |
| 55 | |
| 56 | for line in part_lines: |
| 57 | if "\"" in line: |
| 58 | start_pt = line.find("\"") |
| 59 | end_pt = line.find("\"", start_pt + 1) |
| 60 | cur_partname = line[start_pt + 1: end_pt] |
| 61 | |
| 62 | if "guid:" in line: |
| 63 | guid_to_check = line.split("guid:\t") |
| 64 | part_list[cur_partname] = guid_to_check[1] |
| 65 | |
| 66 | # lets check all guids with avb get_guid |
| 67 | for part, guid in part_list.iteritems(): |
| 68 | avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part) |
| 69 | assert guid == avb_guid_resp.split("UUID: ")[1] |
| 70 | |
| 71 | |
Tom Rini | 4e899d8 | 2018-06-18 19:04:25 -0400 | [diff] [blame] | 72 | @pytest.mark.buildconfigspec('cmd_avb') |
Igor Opaniuk | f96c948 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 73 | def test_avb_read_rb(u_boot_console): |
| 74 | """Test reading rollback indexes |
| 75 | """ |
| 76 | |
| 77 | response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) |
| 78 | assert response == '' |
| 79 | |
| 80 | response = u_boot_console.run_command('avb read_rb 1') |
Jens Wiklander | 07cbae7 | 2018-09-25 16:40:21 +0200 | [diff] [blame] | 81 | assert response == 'Rollback index: 0' |
Igor Opaniuk | f96c948 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 82 | |
| 83 | |
Tom Rini | 4e899d8 | 2018-06-18 19:04:25 -0400 | [diff] [blame] | 84 | @pytest.mark.buildconfigspec('cmd_avb') |
Igor Opaniuk | f96c948 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 85 | def test_avb_is_unlocked(u_boot_console): |
| 86 | """Test if device is in the unlocked state |
| 87 | """ |
| 88 | |
| 89 | response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) |
| 90 | assert response == '' |
| 91 | |
| 92 | response = u_boot_console.run_command('avb is_unlocked') |
Jens Wiklander | 07cbae7 | 2018-09-25 16:40:21 +0200 | [diff] [blame] | 93 | assert response == 'Unlocked = 1' |
Igor Opaniuk | f96c948 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 94 | |
| 95 | |
Jens Wiklander | 07cbae7 | 2018-09-25 16:40:21 +0200 | [diff] [blame] | 96 | @pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc') |
Igor Opaniuk | f96c948 | 2018-06-03 21:56:42 +0300 | [diff] [blame] | 97 | def test_avb_mmc_read(u_boot_console): |
| 98 | """Test mmc read operation |
| 99 | """ |
| 100 | |
| 101 | response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' % |
| 102 | str(mmc_dev)) |
| 103 | assert response.find('is current device') |
| 104 | |
| 105 | response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr) |
| 106 | assert response.find('read: OK') |
| 107 | |
| 108 | response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) |
| 109 | assert response == '' |
| 110 | |
| 111 | response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' % |
| 112 | temp_addr2) |
| 113 | assert response.find('Read 512 bytes') |
| 114 | |
| 115 | # Now lets compare two buffers |
| 116 | response = u_boot_console.run_command('cmp 0x%x 0x%x 40' % |
| 117 | (temp_addr, temp_addr2)) |
| 118 | assert response.find('64 word') |