1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2020, Linaro Limited
3 # Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
5 # U-Boot UEFI: Firmware Update Test
8 This test verifies capsule-on-disk firmware update for raw images
11 from subprocess import check_call, check_output, CalledProcessError
13 from capsule_defs import *
16 @pytest.mark.boardspec('sandbox')
17 @pytest.mark.buildconfigspec('efi_capsule_firmware_raw')
18 @pytest.mark.buildconfigspec('efi_capsule_on_disk')
19 @pytest.mark.buildconfigspec('dfu')
20 @pytest.mark.buildconfigspec('dfu_sf')
21 @pytest.mark.buildconfigspec('cmd_efidebug')
22 @pytest.mark.buildconfigspec('cmd_fat')
23 @pytest.mark.buildconfigspec('cmd_memory')
24 @pytest.mark.buildconfigspec('cmd_nvedit_efi')
25 @pytest.mark.buildconfigspec('cmd_sf')
27 class TestEfiCapsuleFirmwareRaw(object):
28 def test_efi_capsule_fw1(
29 self, u_boot_config, u_boot_console, efi_capsule_data):
31 Test Case 1 - Update U-Boot and U-Boot environment on SPI Flash
32 but with an incorrect GUID value in the capsule
33 No update should happen
34 0x100000-0x150000: U-Boot binary (but dummy)
35 0x150000-0x200000: U-Boot environment (but dummy)
38 # other tests might have run and the
39 # system might not be in a clean state.
40 # Restart before starting the tests.
41 u_boot_console.restart_uboot()
43 disk_img = efi_capsule_data
44 with u_boot_console.log.section('Test Case 1-a, before reboot'):
45 output = u_boot_console.run_command_list([
46 'host bind 0 %s' % disk_img,
47 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi -s ""',
48 'efidebug boot order 1',
49 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
50 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
54 output = u_boot_console.run_command_list([
56 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR,
57 'sf write 4000000 100000 10',
58 'sf read 5000000 100000 10',
60 assert 'Old' in ''.join(output)
61 output = u_boot_console.run_command_list([
63 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR,
64 'sf write 4000000 150000 10',
65 'sf read 5000000 150000 10',
67 assert 'Old' in ''.join(output)
69 # place a capsule file
70 output = u_boot_console.run_command_list([
71 'fatload host 0:1 4000000 %s/Test03' % CAPSULE_DATA_DIR,
72 'fatwrite host 0:1 4000000 %s/Test03 $filesize' % CAPSULE_INSTALL_DIR,
73 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
74 assert 'Test03' in ''.join(output)
77 u_boot_console.restart_uboot()
79 capsule_early = u_boot_config.buildconfig.get(
80 'config_efi_capsule_on_disk_early')
82 with u_boot_console.log.section('Test Case 1-b, after reboot'):
84 # make sure that dfu_alt_info exists even persistent variables
86 output = u_boot_console.run_command_list([
87 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
88 'host bind 0 %s' % disk_img,
89 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
90 assert 'Test03' in ''.join(output)
92 # need to run uefi command to initiate capsule handling
93 output = u_boot_console.run_command(
94 'env print -e Capsule0000', wait_for_reboot = True)
96 output = u_boot_console.run_command_list([
98 'sf read 4000000 100000 10',
100 assert 'u-boot:Old' in ''.join(output)
102 output = u_boot_console.run_command_list([
103 'sf read 4000000 150000 10',
105 assert 'u-boot-env:Old' in ''.join(output)
107 def test_efi_capsule_fw2(
108 self, u_boot_config, u_boot_console, efi_capsule_data):
110 Test Case 2 - Update U-Boot and U-Boot environment on SPI Flash
111 but with OsIndications unset
112 No update should happen
113 0x100000-0x150000: U-Boot binary (but dummy)
114 0x150000-0x200000: U-Boot environment (but dummy)
116 disk_img = efi_capsule_data
117 with u_boot_console.log.section('Test Case 2-a, before reboot'):
118 output = u_boot_console.run_command_list([
119 'host bind 0 %s' % disk_img,
120 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi -s ""',
121 'efidebug boot order 1',
122 'env set -e OsIndications',
123 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
126 # initialize contents
127 output = u_boot_console.run_command_list([
129 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR,
130 'sf write 4000000 100000 10',
131 'sf read 5000000 100000 10',
133 assert 'Old' in ''.join(output)
134 output = u_boot_console.run_command_list([
136 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR,
137 'sf write 4000000 150000 10',
138 'sf read 5000000 150000 10',
140 assert 'Old' in ''.join(output)
142 # place the capsule files
143 output = u_boot_console.run_command_list([
144 'fatload host 0:1 4000000 %s/Test01' % CAPSULE_DATA_DIR,
145 'fatwrite host 0:1 4000000 %s/Test01 $filesize' % CAPSULE_INSTALL_DIR,
146 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
147 assert 'Test01' in ''.join(output)
149 output = u_boot_console.run_command_list([
150 'fatload host 0:1 4000000 %s/Test02' % CAPSULE_DATA_DIR,
151 'fatwrite host 0:1 4000000 %s/Test02 $filesize' % CAPSULE_INSTALL_DIR,
152 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
153 assert 'Test02' in ''.join(output)
156 u_boot_console.restart_uboot()
158 capsule_early = u_boot_config.buildconfig.get(
159 'config_efi_capsule_on_disk_early')
160 with u_boot_console.log.section('Test Case 2-b, after reboot'):
161 if not capsule_early:
162 # make sure that dfu_alt_info exists even persistent variables
164 output = u_boot_console.run_command_list([
165 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
166 'host bind 0 %s' % disk_img,
167 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
168 assert 'Test01' in ''.join(output)
169 assert 'Test02' in ''.join(output)
171 # need to run uefi command to initiate capsule handling
172 output = u_boot_console.run_command(
173 'env print -e Capsule0000')
175 output = u_boot_console.run_command_list([
176 'host bind 0 %s' % disk_img,
177 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
178 assert 'Test01' in ''.join(output)
179 assert 'Test02' in ''.join(output)
181 output = u_boot_console.run_command_list([
183 'sf read 4000000 100000 10',
185 assert 'u-boot:Old' in ''.join(output)
187 output = u_boot_console.run_command_list([
188 'sf read 4000000 150000 10',
190 assert 'u-boot-env:Old' in ''.join(output)
192 def test_efi_capsule_fw3(
193 self, u_boot_config, u_boot_console, efi_capsule_data):
195 Test Case 3 - Update U-Boot on SPI Flash, raw image format
196 0x100000-0x150000: U-Boot binary (but dummy)
198 disk_img = efi_capsule_data
199 with u_boot_console.log.section('Test Case 3-a, before reboot'):
200 output = u_boot_console.run_command_list([
201 'host bind 0 %s' % disk_img,
202 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi -s ""',
203 'efidebug boot order 1',
204 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
205 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
208 # initialize contents
209 output = u_boot_console.run_command_list([
211 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR,
212 'sf write 4000000 100000 10',
213 'sf read 5000000 100000 10',
215 assert 'Old' in ''.join(output)
217 output = u_boot_console.run_command_list([
219 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR,
220 'sf write 4000000 150000 10',
221 'sf read 5000000 100000 10',
223 assert 'Old' in ''.join(output)
225 # place the capsule files
226 output = u_boot_console.run_command_list([
227 'fatload host 0:1 4000000 %s/Test01' % CAPSULE_DATA_DIR,
228 'fatwrite host 0:1 4000000 %s/Test01 $filesize' % CAPSULE_INSTALL_DIR,
229 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
230 assert 'Test01' in ''.join(output)
232 output = u_boot_console.run_command_list([
233 'fatload host 0:1 4000000 %s/Test02' % CAPSULE_DATA_DIR,
234 'fatwrite host 0:1 4000000 %s/Test02 $filesize' % CAPSULE_INSTALL_DIR,
235 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
236 assert 'Test02' in ''.join(output)
238 capsule_early = u_boot_config.buildconfig.get(
239 'config_efi_capsule_on_disk_early')
240 capsule_auth = u_boot_config.buildconfig.get(
241 'config_efi_capsule_authenticate')
244 u_boot_console.restart_uboot(expect_reset = capsule_early)
246 with u_boot_console.log.section('Test Case 3-b, after reboot'):
247 if not capsule_early:
248 # make sure that dfu_alt_info exists even persistent variables
250 output = u_boot_console.run_command_list([
251 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
252 'host bind 0 %s' % disk_img,
253 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
254 assert 'Test01' in ''.join(output)
255 assert 'Test02' in ''.join(output)
257 # need to run uefi command to initiate capsule handling
258 output = u_boot_console.run_command(
259 'env print -e Capsule0000', wait_for_reboot = True)
261 # make sure the dfu_alt_info exists because it is required for making ESRT.
262 output = u_boot_console.run_command_list([
263 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
264 'efidebug capsule esrt'])
266 # ensure that SANDBOX_UBOOT_ENV_IMAGE_GUID is in the ESRT.
267 assert '5A7021F5-FEF2-48B4-AABA-832E777418C0' in ''.join(output)
269 # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
270 assert '09D7CF52-0720-4710-91D1-08469B7FE9C8' in ''.join(output)
272 output = u_boot_console.run_command_list([
273 'host bind 0 %s' % disk_img,
274 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
275 assert 'Test01' not in ''.join(output)
276 assert 'Test02' not in ''.join(output)
278 output = u_boot_console.run_command_list([
280 'sf read 4000000 100000 10',
283 assert 'u-boot:Old' in ''.join(output)
285 assert 'u-boot:New' in ''.join(output)
287 output = u_boot_console.run_command_list([
289 'sf read 4000000 150000 10',
292 assert 'u-boot-env:Old' in ''.join(output)
294 assert 'u-boot-env:New' in ''.join(output)