From patchwork Fri Jul 10 01:25:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 241236 List-Id: U-Boot discussion From: takahiro.akashi at linaro.org (AKASHI Takahiro) Date: Fri, 10 Jul 2020 10:25:37 +0900 Subject: [PATCH v3 17/17] test/py: add a test for uefi firmware update capsule of raw image In-Reply-To: <20200710012537.6264-1-takahiro.akashi@linaro.org> References: <20200710012537.6264-1-takahiro.akashi@linaro.org> Message-ID: <20200710012537.6264-18-takahiro.akashi@linaro.org> The test can run on sandbox build and it attempts to execute a firmware update via a capsule-on-disk, using a raw image capsule, CONFIG_EFI_CAPSULE_RAW. To run this test successfully, you need configure U-Boot specifically; See test_capsule_firmware.py for requirements, and hence it won't run on Travis CI. Signed-off-by: AKASHI Takahiro --- .../test_efi_capsule/test_capsule_firmware.py | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware.py b/test/py/tests/test_efi_capsule/test_capsule_firmware.py index 490dc039d81f..e7c88c796a65 100644 --- a/test/py/tests/test_efi_capsule/test_capsule_firmware.py +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware.py @@ -306,3 +306,78 @@ class TestEfiCapsuleFirmwareFit(object): 'sf read 4000000 150000 10', 'md.b 4000000 10']) assert 'u-boot-env:New' in ''.join(output) + + def test_efi_capsule_fw4( + self, u_boot_config, u_boot_console, efi_capsule_data): + """ + Test Case 4 - Update U-Boot on SPI Flash, raw image format + 0x100000-0x150000: U-Boot binary (but dummy) + """ + # "-T" (or "-D") is required to enable spi flash on sandbox + u_boot_console.restart_uboot_with_flags('-T') + + disk_img = efi_capsule_data + with u_boot_console.log.section('Test Case 4-a, before reboot'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'efidebug boot add 1 TEST host 0:1 /helloworld.efi ""', + 'efidebug boot order 1', + 'env set -e -nv -bs -rt OsIndications =0x0000000000000004', + 'env set dfu_alt_info sf 0:0=u-boot-bin raw 0x100000 0x50000\;u-boot-env raw 0x150000 0x200000', + 'env save']) + + # initialize content + output = u_boot_console.run_command_list( + ['sf probe 0:0', 'fatload host 0:1 4000000 %s/u-boot.bin.old' % + CAPSULE_DATA_DIR, 'sf write 4000000 100000 10', + 'sf read 5000000 100000 10', 'md.b 5000000 10']) + assert 'Old' in ''.join(output) + + # create a capsule file + try: + loop_dev = check_output( + 'sudo losetup -o 1MiB --sizelimit %dMiB --show -f %s | tr -d "\n"' % + (EFI_BOOTDEV_PART_SIZE, disk_img), shell=True).decode() + check_call('sudo mount -t %s -o umask=000 %s %s' + % (EFI_BOOTDEV_FS_TYPE, loop_dev, MNT_PNT), shell=True) + check_call( + '%s/tools/mkeficapsule --raw %s%s/u-boot.bin.new --version 1 --index 1 %s%s/Test01' % + (u_boot_config.build_dir, + MNT_PNT, + CAPSULE_DATA_DIR, + MNT_PNT, + CAPSULE_INSTALL_DIR), + shell=True) + check_call('ls -l %s/%s' % (MNT_PNT, CAPSULE_INSTALL_DIR), + shell=True) + check_call('sudo umount %s' % loop_dev, shell=True) + check_call('sudo losetup -d %s' % loop_dev, shell=True) + except CalledProcessError as exception: + assert 'failed to create firmware capsule: %s' % exception.cmd + + # reboot + u_boot_console.restart_uboot_with_flags('-T') + + capsule_early = u_boot_config.buildconfig.get( + 'config_efi_capsule_on_disk_early') + with u_boot_console.log.section('Test Case 4-b, after reboot'): + if not capsule_early: + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR]) + assert 'Test01' in ''.join(output) + + # need to run uefi command to initiate capsule handling + output = u_boot_console.run_command( + 'env print -e -all Capsule0000') + + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR]) + assert 'Test01' not in ''.join(output) + + output = u_boot_console.run_command_list([ + 'sf probe 0:0', + 'sf read 4000000 100000 10', + 'md.b 4000000 10']) + assert 'u-boot:New' in ''.join(output)