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
6 This test verifies capsule-on-disk firmware update for raw images
10 from capsule_common import (
18 do_reboot_dtb_specified
21 @pytest.mark.boardspec('sandbox')
22 @pytest.mark.buildconfigspec('efi_capsule_firmware_raw')
23 @pytest.mark.buildconfigspec('efi_capsule_on_disk')
24 @pytest.mark.buildconfigspec('dfu')
25 @pytest.mark.buildconfigspec('dfu_sf')
26 @pytest.mark.buildconfigspec('cmd_efidebug')
27 @pytest.mark.buildconfigspec('cmd_fat')
28 @pytest.mark.buildconfigspec('cmd_memory')
29 @pytest.mark.buildconfigspec('cmd_nvedit_efi')
30 @pytest.mark.buildconfigspec('cmd_sf')
32 class TestEfiCapsuleFirmwareRaw:
33 """ Tests verifying capsule-on-disk firmware update for raw images
36 def test_efi_capsule_fw1(
37 self, u_boot_config, u_boot_console, efi_capsule_data):
39 Update U-Boot and U-Boot environment on SPI Flash
40 but with an incorrect GUID value in the capsule
41 No update should happen
42 0x100000-0x150000: U-Boot binary (but dummy)
43 0x150000-0x200000: U-Boot environment (but dummy)
46 # other tests might have run and the
47 # system might not be in a clean state.
48 # Restart before starting the tests.
49 u_boot_console.restart_uboot()
51 disk_img = efi_capsule_data
52 capsule_files = ['Test03']
53 with u_boot_console.log.section('Test Case 1-a, before reboot'):
54 setup(u_boot_console, disk_img, '0x0000000000000004')
55 init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
56 init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
57 place_capsule_file(u_boot_console, capsule_files)
60 u_boot_console.restart_uboot()
62 capsule_early = u_boot_config.buildconfig.get(
63 'config_efi_capsule_on_disk_early')
65 with u_boot_console.log.section('Test Case 1-b, after reboot'):
67 exec_manual_update(u_boot_console, disk_img, capsule_files)
70 check_file_removed(u_boot_console, disk_img, capsule_files)
72 verify_content(u_boot_console, '100000', 'u-boot:Old')
73 verify_content(u_boot_console, '150000', 'u-boot-env:Old')
75 def test_efi_capsule_fw2(
76 self, u_boot_config, u_boot_console, efi_capsule_data):
78 Update U-Boot and U-Boot environment on SPI Flash but with OsIndications unset
79 No update should happen
80 0x100000-0x150000: U-Boot binary (but dummy)
81 0x150000-0x200000: U-Boot environment (but dummy)
83 disk_img = efi_capsule_data
84 capsule_files = ['Test01', 'Test02']
85 with u_boot_console.log.section('Test Case 2-a, before reboot'):
86 setup(u_boot_console, disk_img, None)
87 init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
88 init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
89 place_capsule_file(u_boot_console, capsule_files)
92 u_boot_console.restart_uboot()
94 capsule_early = u_boot_config.buildconfig.get(
95 'config_efi_capsule_on_disk_early')
96 with u_boot_console.log.section('Test Case 2-b, after reboot'):
98 exec_manual_update(u_boot_console, disk_img, capsule_files, False)
100 check_file_exist(u_boot_console, disk_img, capsule_files)
102 verify_content(u_boot_console, '100000', 'u-boot:Old')
103 verify_content(u_boot_console, '150000', 'u-boot-env:Old')
105 def test_efi_capsule_fw3(
106 self, u_boot_config, u_boot_console, efi_capsule_data):
108 Update U-Boot on SPI Flash, raw image format
109 0x100000-0x150000: U-Boot binary (but dummy)
111 disk_img = efi_capsule_data
112 capsule_files = ['Test01', 'Test02']
113 with u_boot_console.log.section('Test Case 3-a, before reboot'):
114 setup(u_boot_console, disk_img, '0x0000000000000004')
115 init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
116 init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
117 place_capsule_file(u_boot_console, capsule_files)
119 capsule_early = u_boot_config.buildconfig.get(
120 'config_efi_capsule_on_disk_early')
121 capsule_auth = u_boot_config.buildconfig.get(
122 'config_efi_capsule_authenticate')
125 u_boot_console.restart_uboot(expect_reset = capsule_early)
127 with u_boot_console.log.section('Test Case 3-b, after reboot'):
128 if not capsule_early:
129 exec_manual_update(u_boot_console, disk_img, capsule_files)
131 # make sure the dfu_alt_info exists because it is required for making ESRT.
132 output = u_boot_console.run_command_list([
133 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
134 'efidebug capsule esrt'])
136 # ensure that SANDBOX_UBOOT_ENV_IMAGE_GUID is in the ESRT.
137 assert '5A7021F5-FEF2-48B4-AABA-832E777418C0' in ''.join(output)
139 # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
140 assert '09D7CF52-0720-4710-91D1-08469B7FE9C8' in ''.join(output)
142 check_file_removed(u_boot_console, disk_img, capsule_files)
144 expected = 'u-boot:Old' if capsule_auth else 'u-boot:New'
145 verify_content(u_boot_console, '100000', expected)
147 expected = 'u-boot-env:Old' if capsule_auth else 'u-boot-env:New'
148 verify_content(u_boot_console, '150000', expected)
150 def test_efi_capsule_fw4(
151 self, u_boot_config, u_boot_console, efi_capsule_data):
153 Update U-Boot on SPI Flash, raw image format with fw_version and lowest_supported_version
154 0x100000-0x150000: U-Boot binary (but dummy)
155 0x150000-0x200000: U-Boot environment (but dummy)
157 disk_img = efi_capsule_data
158 capsule_files = ['Test101', 'Test102']
159 with u_boot_console.log.section('Test Case 4-a, before reboot'):
160 setup(u_boot_console, disk_img, '0x0000000000000004')
161 init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
162 init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
163 place_capsule_file(u_boot_console, capsule_files)
166 do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
168 capsule_early = u_boot_config.buildconfig.get(
169 'config_efi_capsule_on_disk_early')
170 capsule_auth = u_boot_config.buildconfig.get(
171 'config_efi_capsule_authenticate')
172 with u_boot_console.log.section('Test Case 4-b, after reboot'):
173 if not capsule_early:
174 exec_manual_update(u_boot_console, disk_img, capsule_files)
177 check_file_removed(u_boot_console, disk_img, capsule_files)
179 # make sure the dfu_alt_info exists because it is required for making ESRT.
180 output = u_boot_console.run_command_list([
181 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000'
182 'u-boot-env raw 0x150000 0x200000"',
183 'efidebug capsule esrt'])
186 # capsule authentication failed
187 verify_content(u_boot_console, '100000', 'u-boot:Old')
188 verify_content(u_boot_console, '150000', 'u-boot-env:Old')
190 # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
191 assert '09D7CF52-0720-4710-91D1-08469B7FE9C8' in ''.join(output)
192 assert 'ESRT: fw_version=5' in ''.join(output)
193 assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output)
195 # ensure that SANDBOX_UBOOT_ENV_IMAGE_GUID is in the ESRT.
196 assert '5A7021F5-FEF2-48B4-AABA-832E777418C0' in ''.join(output)
197 assert 'ESRT: fw_version=10' in ''.join(output)
198 assert 'ESRT: lowest_supported_fw_version=7' in ''.join(output)
200 verify_content(u_boot_console, '100000', 'u-boot:New')
201 verify_content(u_boot_console, '150000', 'u-boot-env:New')
203 def test_efi_capsule_fw5(
204 self, u_boot_config, u_boot_console, efi_capsule_data):
206 Update U-Boot on SPI Flash, raw image format with fw_version and lowest_supported_version
207 but fw_version is lower than lowest_supported_version
208 No update should happen
209 0x100000-0x150000: U-Boot binary (but dummy)
211 disk_img = efi_capsule_data
212 capsule_files = ['Test103']
213 with u_boot_console.log.section('Test Case 5-a, before reboot'):
214 setup(u_boot_console, disk_img, '0x0000000000000004')
215 init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
216 place_capsule_file(u_boot_console, capsule_files)
219 do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
221 capsule_early = u_boot_config.buildconfig.get(
222 'config_efi_capsule_on_disk_early')
223 with u_boot_console.log.section('Test Case 5-b, after reboot'):
224 if not capsule_early:
225 exec_manual_update(u_boot_console, disk_img, capsule_files)
227 check_file_removed(u_boot_console, disk_img, capsule_files)
229 verify_content(u_boot_console, '100000', 'u-boot:Old')