1# Copyright (c) 2018, Linaro Limited 2# 3# SPDX-License-Identifier: GPL-2.0+ 4# 5# Android Verified Boot 2.0 Test 6 7""" 8This tests Android Verified Boot 2.0 support in U-boot: 9 10For additional details about how to build proper vbmeta partition 11check doc/README.avb2 12 13For configuration verification: 14- Corrupt boot partition and check for failure 15- Corrupt vbmeta partition and check for failure 16""" 17 18import pytest 19import u_boot_utils as util 20 21# defauld mmc id 22mmc_dev = 1 23temp_addr = 0x90000000 24temp_addr2 = 0x90002000 25 26@pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc') 27def 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 39@pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc') 40def 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 72@pytest.mark.buildconfigspec('cmd_avb') 73def 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') 81 assert response == 'Rollback index: 0' 82 83 84@pytest.mark.buildconfigspec('cmd_avb') 85def 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') 93 assert response == 'Unlocked = 1' 94 95 96@pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc') 97def 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') 119