blob: e70a010c9ac018439746c915a0b966c4f0ed4579 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# Copyright (c) 2018, Linaro Limited
#
# SPDX-License-Identifier: GPL-2.0+
#
# Android Verified Boot 2.0 Test
"""
This tests Android Verified Boot 2.0 support in U-boot:
For additional details about how to build proper vbmeta partition
check doc/README.avb2
For configuration verification:
- Corrupt boot partition and check for failure
- Corrupt vbmeta partition and check for failure
"""
import pytest
import u_boot_utils as util
# defauld mmc id
mmc_dev = 1
temp_addr = 0x90000000
temp_addr2 = 0x90002000
@pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc')
def test_avb_verify(u_boot_console):
"""Run AVB 2.0 boot verification chain with avb subset of commands
"""
success_str = "Verification passed successfully"
response = u_boot_console.run_command('avb init %s' %str(mmc_dev))
assert response == ''
response = u_boot_console.run_command('avb verify')
assert response.find(success_str)
@pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc')
def test_avb_mmc_uuid(u_boot_console):
"""Check if 'avb get_uuid' works, compare results with
'part list mmc 1' output
"""
response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
assert response == ''
response = u_boot_console.run_command('mmc rescan; mmc dev %s' %
str(mmc_dev))
assert response.find('is current device')
part_lines = u_boot_console.run_command('mmc part').splitlines()
part_list = {}
cur_partname = ''
for line in part_lines:
if '"' in line:
start_pt = line.find('"')
end_pt = line.find('"', start_pt + 1)
cur_partname = line[start_pt + 1: end_pt]
if 'guid:' in line:
guid_to_check = line.split('guid:\t')
part_list[cur_partname] = guid_to_check[1]
# lets check all guids with avb get_guid
for part, guid in part_list.iteritems():
avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part)
assert guid == avb_guid_resp.split('UUID: ')[1]
@pytest.mark.buildconfigspec('cmd_avb')
def test_avb_read_rb(u_boot_console):
"""Test reading rollback indexes
"""
response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
assert response == ''
response = u_boot_console.run_command('avb read_rb 1')
assert response == 'Rollback index: 0'
@pytest.mark.buildconfigspec('cmd_avb')
def test_avb_is_unlocked(u_boot_console):
"""Test if device is in the unlocked state
"""
response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
assert response == ''
response = u_boot_console.run_command('avb is_unlocked')
assert response == 'Unlocked = 1'
@pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc')
def test_avb_mmc_read(u_boot_console):
"""Test mmc read operation
"""
response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' %
str(mmc_dev))
assert response.find('is current device')
response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
assert response.find('read: OK')
response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
assert response == ''
response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' %
temp_addr2)
assert response.find('Read 512 bytes')
# Now lets compare two buffers
response = u_boot_console.run_command('cmp 0x%x 0x%x 40' %
(temp_addr, temp_addr2))
assert response.find('64 word')
|