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 FIT images
11 from subprocess import check_call, check_output, CalledProcessError
13 from capsule_defs import *
16 @pytest.mark.boardspec('sandbox_flattree')
17 @pytest.mark.buildconfigspec('efi_capsule_firmware_fit')
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 TestEfiCapsuleFirmwareFit(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)
37 # other tests might have run and the
38 # system might not be in a clean state.
39 # Restart before starting the tests.
40 u_boot_console.restart_uboot()
42 disk_img = efi_capsule_data
43 with u_boot_console.log.section('Test Case 1-a, before reboot'):
44 output = u_boot_console.run_command_list([
45 'host bind 0 %s' % disk_img,
46 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi -s ""',
47 'efidebug boot order 1',
48 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
49 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
53 output = u_boot_console.run_command_list([
55 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR,
56 'sf write 4000000 100000 10',
57 'sf read 5000000 100000 10',
59 assert 'Old' in ''.join(output)
60 output = u_boot_console.run_command_list([
62 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR,
63 'sf write 4000000 150000 10',
64 'sf read 5000000 150000 10',
66 assert 'Old' in ''.join(output)
68 # place a capsule file
69 output = u_boot_console.run_command_list([
70 'fatload host 0:1 4000000 %s/Test05' % CAPSULE_DATA_DIR,
71 'fatwrite host 0:1 4000000 %s/Test05 $filesize' % CAPSULE_INSTALL_DIR,
72 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
73 assert 'Test05' in ''.join(output)
75 capsule_early = u_boot_config.buildconfig.get(
76 'config_efi_capsule_on_disk_early')
77 capsule_auth = u_boot_config.buildconfig.get(
78 'config_efi_capsule_authenticate')
81 u_boot_console.restart_uboot(expect_reset = capsule_early)
83 with u_boot_console.log.section('Test Case 1-b, after reboot'):
85 # make sure that dfu_alt_info exists even persistent variables
87 output = u_boot_console.run_command_list([
88 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
89 'host bind 0 %s' % disk_img,
90 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
91 assert 'Test05' in ''.join(output)
93 # need to run uefi command to initiate capsule handling
94 output = u_boot_console.run_command(
95 'env print -e Capsule0000', wait_for_reboot = True)
97 output = u_boot_console.run_command_list([
99 'sf read 4000000 100000 10',
101 assert 'u-boot:Old' in ''.join(output)
103 output = u_boot_console.run_command_list([
104 'sf read 4000000 150000 10',
106 assert 'u-boot-env:Old' in ''.join(output)
108 def test_efi_capsule_fw2(
109 self, u_boot_config, u_boot_console, efi_capsule_data):
111 Test Case 2 - Update U-Boot and U-Boot environment on SPI Flash
112 0x100000-0x150000: U-Boot binary (but dummy)
113 0x150000-0x200000: U-Boot environment (but dummy)
115 disk_img = efi_capsule_data
116 with u_boot_console.log.section('Test Case 2-a, before reboot'):
117 output = u_boot_console.run_command_list([
118 'host bind 0 %s' % disk_img,
119 'printenv -e PlatformLangCodes', # workaround for terminal size determination
120 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi -s ""',
121 'efidebug boot order 1',
122 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
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 a capsule file
143 output = u_boot_console.run_command_list([
144 'fatload host 0:1 4000000 %s/Test04' % CAPSULE_DATA_DIR,
145 'fatwrite host 0:1 4000000 %s/Test04 $filesize' % CAPSULE_INSTALL_DIR,
146 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
147 assert 'Test04' in ''.join(output)
149 capsule_early = u_boot_config.buildconfig.get(
150 'config_efi_capsule_on_disk_early')
151 capsule_auth = u_boot_config.buildconfig.get(
152 'config_efi_capsule_authenticate')
155 u_boot_console.restart_uboot(expect_reset = capsule_early)
157 with u_boot_console.log.section('Test Case 2-b, after reboot'):
158 if not capsule_early:
159 # make sure that dfu_alt_info exists even persistent variables
161 output = u_boot_console.run_command_list([
162 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
163 'host bind 0 %s' % disk_img,
164 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
165 assert 'Test04' in ''.join(output)
167 # need to run uefi command to initiate capsule handling
168 output = u_boot_console.run_command(
169 'env print -e Capsule0000', wait_for_reboot = True)
171 output = u_boot_console.run_command_list([
172 'host bind 0 %s' % disk_img,
173 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
174 assert 'Test04' not in ''.join(output)
176 output = u_boot_console.run_command_list([
178 'sf read 4000000 100000 10',
181 assert 'u-boot:Old' in ''.join(output)
183 assert 'u-boot:New' in ''.join(output)
185 output = u_boot_console.run_command_list([
186 'sf read 4000000 150000 10',
189 assert 'u-boot-env:Old' in ''.join(output)
191 assert 'u-boot-env:New' in ''.join(output)