
From: Simon Glass <sjg@chromium.org> Create two new images (vbe0 and vbe1) containing the two types of VBE-OS setups: with and without an OEM FIT. Put this in a new img/ subdirectory since the test_ut.py file is getting quite large. Most of the test is in C, with just the image-setup done in Python. Enable the test for non-SPL sandbox builds. Signed-off-by: Simon Glass <sjg@chromium.org> --- arch/sandbox/dts/test.dts | 11 +++ boot/Kconfig | 1 + test/boot/Makefile | 1 + test/boot/bootflow.c | 75 ++++++++++++----- test/boot/bootmeth.c | 19 +++-- test/boot/vbe_abrec_os.c | 138 +++++++++++++++++++++++++++++++ test/py/test.py | 4 + test/py/tests/img/vbe.py | 167 ++++++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 3 +- test/py/tests/test_vbe.py | 22 +++++ 10 files changed, 412 insertions(+), 29 deletions(-) create mode 100644 test/boot/vbe_abrec_os.c create mode 100644 test/py/tests/img/vbe.py diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index b62531e9166..1783a21894a 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -128,6 +128,10 @@ compatible = "u-boot,distro-efi"; }; + vbe { + compatible = "vbe,abrec-os"; + }; + theme { font-size = <30>; menu-inset = <3>; @@ -1176,6 +1180,13 @@ filename = "mmc9.img"; }; + /* This is used for VBE ABrec tests */ + mmc10 { + status = "disabled"; + compatible = "sandbox,mmc"; + filename = "mmc10.img"; + }; + pch { compatible = "sandbox,pch"; }; diff --git a/boot/Kconfig b/boot/Kconfig index 6f42cd7ec23..ddb5b26ec15 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -822,6 +822,7 @@ config BOOTMETH_VBE_ABREC_OS bool "Bootdev support for VBE 'a/b/recovery' method for the OS" imply SPL_CRC8 imply VPL_CRC8 + default y if SANDBOX && !SPL help Enables support for VBE 'abrec' boot. This allows updating one of an A or B Operating System in boot media such as MMC. The new OS is diff --git a/test/boot/Makefile b/test/boot/Makefile index 00223b44fe0..e8b423b0c43 100644 --- a/test/boot/Makefile +++ b/test/boot/Makefile @@ -19,5 +19,6 @@ ifdef CONFIG_OF_LIVE obj-$(CONFIG_BOOTMETH_VBE_SIMPLE) += vbe_simple.o endif obj-$(CONFIG_BOOTMETH_VBE) += vbe_fixup.o +obj-$(CONFIG_BOOTMETH_VBE_ABREC_OS) += vbe_abrec_os.o obj-$(CONFIG_UPL) += upl.o diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index 697037e7b69..620af312700 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -184,6 +184,7 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts) { ut_assertok(bootstd_test_drop_bootdev_order(uts)); + ut_assertok(run_command("bootmeth order ", 0)); ut_assertok(run_command("bootflow scan -aleGH", 0)); ut_assert_nextline("Scanning for bootflows in all bootdevs"); ut_assert_nextline("Seq Method State Uclass Part Name Filename"); @@ -193,24 +194,28 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts) ut_assert_nextline(" ** No partition found, err=-93: Protocol not supported"); ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole "); ut_assert_nextline(" ** No partition found, err=-93: Protocol not supported"); + ut_assert_nextline(" 2 vbe media mmc 0 mmc2.bootdev.whole "); + ut_assert_nextline(" ** No partition found, err=-93: Protocol not supported"); ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); - ut_assert_nextline(" 2 extlinux media mmc 0 mmc1.bootdev.whole "); + ut_assert_nextline(" 3 extlinux media mmc 0 mmc1.bootdev.whole "); + ut_assert_nextline(" ** No partition found, err=-2: No such file or directory"); + ut_assert_nextline(" 4 efi media mmc 0 mmc1.bootdev.whole "); ut_assert_nextline(" ** No partition found, err=-2: No such file or directory"); - ut_assert_nextline(" 3 efi media mmc 0 mmc1.bootdev.whole "); + ut_assert_nextline(" 5 vbe media mmc 0 mmc1.bootdev.whole "); ut_assert_nextline(" ** No partition found, err=-2: No such file or directory"); - ut_assert_nextline(" 4 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); + ut_assert_nextline(" 6 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); ut_assert_nextline( - " 5 efi fs mmc 1 mmc1.bootdev.part_1 /EFI/BOOT/%s", + " 7 efi fs mmc 1 mmc1.bootdev.part_1 /EFI/BOOT/%s", efi_get_basename()); ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':"); ut_assert_skip_to_line( - " 3f efi media mmc 0 mmc0.bootdev.whole "); + " 5f vbe media mmc 0 mmc0.bootdev.whole "); ut_assert_nextline(" ** No partition found, err=-93: Protocol not supported"); ut_assert_nextline("No more bootdevs"); ut_assert_nextlinen("---"); - ut_assert_nextline("(64 bootflows, 1 valid)"); + ut_assert_nextline("(96 bootflows, 1 valid)"); ut_assert_console_end(); ut_assertok(run_command("bootflow list", 0)); @@ -219,11 +224,9 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts) ut_assert_nextlinen("---"); ut_assert_nextline(" 0 extlinux media mmc 0 mmc2.bootdev.whole "); ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole "); - ut_assert_skip_to_line( - " 4 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); - ut_assert_skip_to_line(" 3f efi media mmc 0 mmc0.bootdev.whole "); + ut_assert_skip_to_line(" 5f vbe media mmc 0 mmc0.bootdev.whole "); ut_assert_nextlinen("---"); - ut_assert_nextline("(64 bootflows, 1 valid)"); + ut_assert_nextline("(96 bootflows, 1 valid)"); ut_assert_console_end(); return 0; @@ -304,7 +307,7 @@ static int bootflow_iter(struct unit_test_state *uts) bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWIF_ALL | BOOTFLOWIF_SKIP_GLOBAL | BOOTFLOWIF_ONLY_BOOTABLE, &bflow)); - ut_asserteq(2, iter.num_methods); + ut_asserteq(3, iter.num_methods); ut_asserteq(0, iter.cur_method); ut_asserteq(0, iter.part); ut_asserteq(0, iter.max_part); @@ -320,7 +323,7 @@ static int bootflow_iter(struct unit_test_state *uts) ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); ut_asserteq(-EPROTONOSUPPORT, bootflow_scan_next(&iter, &bflow)); - ut_asserteq(2, iter.num_methods); + ut_asserteq(3, iter.num_methods); ut_asserteq(1, iter.cur_method); ut_asserteq(0, iter.part); ut_asserteq(0, iter.max_part); @@ -329,9 +332,20 @@ static int bootflow_iter(struct unit_test_state *uts) ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); bootflow_free(&bflow); + /* now the VBE boothmeth */ + ut_asserteq(-EPROTONOSUPPORT, bootflow_scan_next(&iter, &bflow)); + ut_asserteq(3, iter.num_methods); + ut_asserteq(2, iter.cur_method); + ut_asserteq(0, iter.part); + ut_asserteq(0, iter.max_part); + ut_asserteq_str("vbe", iter.method->name); + ut_asserteq(0, bflow.err); + ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); + bootflow_free(&bflow); + /* The next device is mmc1.bootdev - at first we use the whole device */ ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); - ut_asserteq(2, iter.num_methods); + ut_asserteq(3, iter.num_methods); ut_asserteq(0, iter.cur_method); ut_asserteq(0, iter.part); ut_asserteq(0x1e, iter.max_part); @@ -341,7 +355,7 @@ static int bootflow_iter(struct unit_test_state *uts) bootflow_free(&bflow); ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); - ut_asserteq(2, iter.num_methods); + ut_asserteq(3, iter.num_methods); ut_asserteq(1, iter.cur_method); ut_asserteq(0, iter.part); ut_asserteq(0x1e, iter.max_part); @@ -350,9 +364,20 @@ static int bootflow_iter(struct unit_test_state *uts) ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); bootflow_free(&bflow); - /* Then more to partition 1 where we find something */ + /* now the VBE boothmeth */ + ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); + ut_asserteq(3, iter.num_methods); + ut_asserteq(2, iter.cur_method); + ut_asserteq(0, iter.part); + ut_asserteq(0x1e, iter.max_part); + ut_asserteq_str("vbe", iter.method->name); + ut_asserteq(0, bflow.err); + ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); + bootflow_free(&bflow); + + /* Then move to partition 1 where we find something */ ut_assertok(bootflow_scan_next(&iter, &bflow)); - ut_asserteq(2, iter.num_methods); + ut_asserteq(3, iter.num_methods); ut_asserteq(0, iter.cur_method); ut_asserteq(1, iter.part); ut_asserteq(0x1e, iter.max_part); @@ -362,7 +387,7 @@ static int bootflow_iter(struct unit_test_state *uts) bootflow_free(&bflow); ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); - ut_asserteq(2, iter.num_methods); + ut_asserteq(3, iter.num_methods); ut_asserteq(1, iter.cur_method); ut_asserteq(1, iter.part); ut_asserteq(0x1e, iter.max_part); @@ -371,9 +396,19 @@ static int bootflow_iter(struct unit_test_state *uts) ut_asserteq(BOOTFLOWST_FS, bflow.state); bootflow_free(&bflow); + ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); + ut_asserteq(3, iter.num_methods); + ut_asserteq(2, iter.cur_method); + ut_asserteq(1, iter.part); + ut_asserteq(0x1e, iter.max_part); + ut_asserteq_str("vbe", iter.method->name); + ut_asserteq(0, bflow.err); + ut_asserteq(BOOTFLOWST_FS, bflow.state); + bootflow_free(&bflow); + /* Then more to partition 2 which exists but is not bootable */ ut_asserteq(-EINVAL, bootflow_scan_next(&iter, &bflow)); - ut_asserteq(2, iter.num_methods); + ut_asserteq(3, iter.num_methods); ut_asserteq(0, iter.cur_method); ut_asserteq(2, iter.part); ut_asserteq(0x1e, iter.max_part); @@ -441,7 +476,7 @@ static int bootflow_iter_disable(struct unit_test_state *uts) /* Try to boot the bootmgr flow, which will fail */ console_record_reset_enable(); ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); - ut_asserteq(3, iter.num_methods); + ut_asserteq(4, iter.num_methods); ut_asserteq_str("sandbox", iter.method->name); ut_assertok(inject_response(uts)); ut_asserteq(-ENOTSUPP, bootflow_run_boot(&iter, &bflow)); @@ -450,7 +485,7 @@ static int bootflow_iter_disable(struct unit_test_state *uts) ut_assert_console_end(); /* Check that the sandbox bootmeth has been removed */ - ut_asserteq(2, iter.num_methods); + ut_asserteq(3, iter.num_methods); for (i = 0; i < iter.num_methods; i++) ut_assert(strcmp("sandbox", iter.method_order[i]->name)); diff --git a/test/boot/bootmeth.c b/test/boot/bootmeth.c index 577f259fb37..88fa3200cbc 100644 --- a/test/boot/bootmeth.c +++ b/test/boot/bootmeth.c @@ -20,11 +20,12 @@ static int bootmeth_cmd_list(struct unit_test_state *uts) ut_assert_nextlinen("---"); ut_assert_nextline(" 0 0 extlinux Extlinux boot from a block device"); ut_assert_nextline(" 1 1 efi EFI boot from an .efi file"); + ut_assert_nextline(" 2 2 vbe VBE A/B/recovery for OS"); if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) - ut_assert_nextline(" glob 2 firmware0 VBE simple"); + ut_assert_nextline(" glob 3 firmware0 VBE simple"); ut_assert_nextlinen("---"); ut_assert_nextline(IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) ? - "(3 bootmeths)" : "(2 bootmeths)"); + "(4 bootmeths)" : "(3 bootmeths)"); ut_assert_console_end(); return 0; @@ -55,11 +56,12 @@ static int bootmeth_cmd_order(struct unit_test_state *uts) ut_assert_nextlinen("---"); ut_assert_nextline(" 0 0 extlinux Extlinux boot from a block device"); ut_assert_nextline(" - 1 efi EFI boot from an .efi file"); + ut_assert_nextline(" - 2 vbe VBE A/B/recovery for OS"); if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) - ut_assert_nextline(" glob 2 firmware0 VBE simple"); + ut_assert_nextline(" glob 3 firmware0 VBE simple"); ut_assert_nextlinen("---"); ut_assert_nextline(IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) ? - "(3 bootmeths)" : "(2 bootmeths)"); + "(4 bootmeths)" : "(3 bootmeths)"); ut_assert_console_end(); /* Check the -a flag with the reverse order */ @@ -70,11 +72,12 @@ static int bootmeth_cmd_order(struct unit_test_state *uts) ut_assert_nextlinen("---"); ut_assert_nextline(" 1 0 extlinux Extlinux boot from a block device"); ut_assert_nextline(" 0 1 efi EFI boot from an .efi file"); + ut_assert_nextline(" - 2 vbe VBE A/B/recovery for OS"); if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) - ut_assert_nextline(" glob 2 firmware0 VBE simple"); + ut_assert_nextline(" glob 3 firmware0 VBE simple"); ut_assert_nextlinen("---"); ut_assert_nextline(IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) ? - "(3 bootmeths)" : "(2 bootmeths)"); + "(4 bootmeths)" : "(3 bootmeths)"); ut_assert_console_end(); /* Now reset the order to empty, which should show all of them again */ @@ -83,7 +86,7 @@ static int bootmeth_cmd_order(struct unit_test_state *uts) ut_assertnull(env_get("bootmeths")); ut_assertok(run_command("bootmeth list", 0)); ut_assert_skip_to_line(IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) ? - "(3 bootmeths)" : "(2 bootmeths)"); + "(4 bootmeths)" : "(3 bootmeths)"); /* Try reverse order */ ut_assertok(run_command("bootmeth order \"efi extlinux\"", 0)); @@ -115,7 +118,7 @@ static int bootmeth_cmd_order_glob(struct unit_test_state *uts) ut_assert_nextline("Order Seq Name Description"); ut_assert_nextlinen("---"); ut_assert_nextline(" 0 1 efi EFI boot from an .efi file"); - ut_assert_nextline(" glob 2 firmware0 VBE simple"); + ut_assert_nextline(" glob 3 firmware0 VBE simple"); ut_assert_nextlinen("---"); ut_assert_nextline("(2 bootmeths)"); ut_assertnonnull(env_get("bootmeths")); diff --git a/test/boot/vbe_abrec_os.c b/test/boot/vbe_abrec_os.c new file mode 100644 index 00000000000..3ac95d7b4c3 --- /dev/null +++ b/test/boot/vbe_abrec_os.c @@ -0,0 +1,138 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test for VBE A/B boot of OS + * + * Copyright 2025 Simon Glass <simon.glass@canonical.com> + */ + +#include <bootflow.h> +#include <bootstd.h> +#include <dm.h> +#include <mapmem.h> +#include <vbe.h> +#include <test/test.h> +#include <test/ut.h> +#include "bootstd_common.h" +#include "../boot/vbe_abrec.h" + +/** + * check_abrec_norun() - Check operation with or without an OEM FIT + * + * @uts: Unit-test state + * @use_oem: Use an OEM devicetree + */ +static int check_abrec_norun(struct unit_test_state *uts, bool use_oem, + enum vbe_pick_t expect_pick) +{ + static const char *order[] = {"host", NULL}; + const struct bootflow_img *img; + struct bootflow_iter iter; + struct bootstd_priv *std; + struct abrec_priv *abpriv; + struct udevice *bootstd; + const char **old_order; + struct bootflow bflow; + struct vbe_bflow_priv *priv; + struct udevice *dev; + ofnode root; + oftree tree; + int ret; + + ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); + std = dev_get_priv(bootstd); + old_order = std->bootdev_order; + std->bootdev_order = order; + ut_assertok(env_set("boot_targets", NULL)); + + ut_assertok(uclass_get_device_by_driver(UCLASS_BOOTMETH, + DM_DRIVER_GET(vbe_abrec_os), + &dev)); + abpriv = dev_get_priv(dev); + abpriv->oem_devicetree = use_oem; + + ret = bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWIF_SHOW, &bflow); + std->bootdev_order = old_order; + ut_assertok(ret); + + ut_asserteq_str("host-0.bootdev.part_2", bflow.name); + + /* Check that we got the state OK */ + img = bootflow_img_find(&bflow, BFI_VBE_STATE); + ut_assertnonnull(img); + ut_assert(img->addr); + + tree = oftree_from_fdt(map_sysmem(img->addr, 0)); + ut_assert(oftree_valid(tree)); + + root = oftree_root(tree); + ut_asserteq_str("vbe,abrec-state", + ofnode_read_string(root, "compatible")); + + /* check the private data */ + priv = bflow.bootmeth_priv; + ut_assertnonnull(priv); + ut_asserteq(expect_pick, priv->pick_slot); + + if (use_oem) { + /* Check that we got the OEM FIT */ + img = bootflow_img_find(&bflow, BFI_VBE_OEM_FIT); + ut_assertnonnull(img); + ut_assert(img->addr); + ut_assert(img->size > 0); + ut_assertok(fit_check_format(map_sysmem(img->addr, img->size), + img->size)); + } + + /* Select the first kernel from the extlinux menu */ + ut_asserteq(2, console_in_puts("1\n")); + + /* + * We expect it to get through to boot although sandbox always returns + * -EFAULT as it cannot actually boot the kernel + */ + ut_asserteq(-EFAULT, bootflow_boot(&bflow)); + + ut_assert_skip_to_line("VBE: Picked slot %s", + priv->pick_slot == VBEP_A ? "a" : "b"); + + if (use_oem) + ut_assert_skip_to_line("Loading OEM devicetree from FIT"); + + if (use_oem) + ut_assert_skip_to_line("Loading OS FIT keeping existing FDT"); + else + ut_assert_skip_to_line("Loading OS FIT"); + + ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux"); + ut_assert_console_end(); + + /* + * check the FDT we booted with: we should have loaded conf-1 as the + * compatible string for sandbox does not match + */ + ut_assertnonnull(working_fdt); + tree = oftree_from_fdt(working_fdt); + root = oftree_root(tree); + + ut_asserteq_str("snow", ofnode_read_string(root, "compatible")); + + return 0; +} + +/* Test without an OEM FIT */ +static int vbe_test_abrec_no_oem_norun(struct unit_test_state *uts) +{ + ut_assertok(check_abrec_norun(uts, false, VBEP_A)); + + return 0; +} +BOOTSTD_TEST(vbe_test_abrec_no_oem_norun, UTF_MANUAL | UTF_CONSOLE); + +/* Test with an OEM FIT */ +static int vbe_test_abrec_oem_norun(struct unit_test_state *uts) +{ + ut_assertok(check_abrec_norun(uts, true, VBEP_B)); + + return 0; +} +BOOTSTD_TEST(vbe_test_abrec_oem_norun, UTF_MANUAL | UTF_CONSOLE); diff --git a/test/py/test.py b/test/py/test.py index 7c477903d6b..ab47282db35 100755 --- a/test/py/test.py +++ b/test/py/test.py @@ -12,6 +12,10 @@ import os.path import sys import pytest +# Bring in the U-Boot libraries +our_path = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(our_path, '../../tools')) + if __name__ == '__main__': # argv; py.test test_directory_name user-supplied-arguments args = [os.path.dirname(__file__) + '/tests'] diff --git a/test/py/tests/img/vbe.py b/test/py/tests/img/vbe.py new file mode 100644 index 00000000000..1e4c7df68aa --- /dev/null +++ b/test/py/tests/img/vbe.py @@ -0,0 +1,167 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright 2025 Simon Glass <sjg@chromium.org> +# Author: Simon Glass <sjg@chromium.org> + +"""Create test disk-images for VBE""" + +import gzip +import os +import shutil +import tempfile + +import utils +from fs_helper import DiskHelper, FsHelper +from dtoc import fdt_util +from u_boot_pylib import tools + + +def dtb_for_compatible(ubman, kernpath, version, model): + """Create a fake devicetree binary for a given model name + + Args: + ubman (ConsoleBase): U-Boot fixture + kernpath (str): Path to place the created DTB + version (str): Version string to use with the dtb + model (str): Model name + + Return: + str: Filename of devicetree file written + """ + dtb_file = os.path.join(kernpath, f'dtb-{version}-{model}') + data = f'/dts-v1/; / {{ compatible = "{model}"; version = "{version}"; }};' + utils.run_and_log(ubman, f'dtc -o {dtb_file}', stdin=data.encode('utf-8')) + return dtb_file + + +def create_extlinux(ubman, kernpath, dirpath, slot, version, has_oem): + """Create a fake extlinux image + + Args: + ubman (ConsoleBase): U-Boot fixture + kernpath (str): Directory path for the kernel + dirpath (str): Directory path to write to (created by this function) + slot (str): Slot name (A, B or recovery) + version (str): Linux version to use, e.g. '6.14.0-24' + has_oem (bool): true to create an OEM FIT + """ + ext_path = os.path.join(dirpath, 'extlinux') + if not os.path.exists(dirpath): + os.mkdir(dirpath) + if not os.path.exists(ext_path): + os.mkdir(ext_path) + dtb_info = ' (no-dtb)' if has_oem else '' + with open(os.path.join(ext_path, 'extlinux.conf'), 'w', + encoding='ascii') as outf: + print(f'''## /boot/extlinux/extlinux.conf +## +## IMPORTANT WARNING +## +## The configuration of this file is generated automatically. +## Do not edit this file manually, use: u-boot-update + +default l0 +menu title Ubuntu Menu ({slot}) +prompt 1 +timeout 50 + + +label l0 + menu label Ubuntu 24.04.2 LTS {version}{dtb_info} + + fit /ubuntu-{version}.fit + append root=/dev/disk/by-id/dm-uuid-LVM-lNvIY7Drx7RGUJpQZGPr2axs2ueSe57B7p7jtyJGIUnMJMHCSPVphCu9IFivkJhK ro earlycon +''', file=outf) + + # True to add devicetrees and multiple configurations + add_dts = not has_oem + + # Create a FIT containing kernel, initrd and devicetree + with tempfile.TemporaryDirectory(suffix='vbe') as tmp: + kern = os.path.join(tmp, 'kern') + tools.write_file(kern, gzip.compress(f'vmlinux-{slot}'.encode('utf-8'))) + mkimage = ubman.config.build_dir + '/tools/mkimage' + + initrd = os.path.join(tmp, f'initrd.img-{version}') + tools.write_file(initrd, f'initrd {version}', binary=False) + + snow = dtb_for_compatible(ubman, tmp, version, 'snow') + kevin = dtb_for_compatible(ubman, tmp, version, 'kevin') + + fit = os.path.join(kernpath, f'ubuntu-{version}.fit') + cmd = f'{mkimage} -f auto -T kernel -A sandbox -O linux ' + dts = f'-b {snow} -b {kevin}' if add_dts else '' + utils.run_and_log(ubman, cmd + f'-d {kern} -i {initrd} {dts} {fit}') + + # Create a FIT containing OEM devicetrees + if has_oem: + oem_snow = dtb_for_compatible(ubman, tmp, 'oem', 'snow') + oem_kevin = dtb_for_compatible(ubman, tmp, 'oem', 'kevin') + + fit = os.path.join(dirpath, 'oem.fit') + utils.run_and_log( + ubman, + f'{mkimage} -f auto -A sandbox -O linux -T flat_dt --load-only' + f' -b {oem_snow} -b {oem_kevin} {fit}') + +def setup_vbe_image(ubman): + """Create three partitions (fat, boot and root) for a VBE boot flow + + The intent is to load either one or two FITs. + + Two separate images are created: + + - vbe0 has no OEM FIT; OS FIT contains the devicetrees + - vbe1 has an OEM FIT containing the devicetrees; OS FIT does not + """ + for seq in range(2): + with (DiskHelper(ubman.config, seq, 'vbe') as img, + FsHelper(ubman.config, 'fat', 1, 'efi') as vfat, + FsHelper(ubman.config, 'ext4', 1, f'boot{seq}') as boot, + FsHelper(ubman.config, 'ext4', 17, 'root') as root): + with open(os.path.join(vfat.srcdir, 'u-boot.efi'), 'wb') as outf: + outf.write(b'fake binary\n') + vfat.mk_fs() + img.add_fs(vfat, DiskHelper.VFAT, bootable=True) + + has_oem = bool(seq) + + dir_a = os.path.join(boot.srcdir, 'a') + vera = '6.14.0-24-generic' + create_extlinux(ubman, boot.srcdir, dir_a, 'A', vera, has_oem) + + dir_b = os.path.join(boot.srcdir, 'b') + verb = '6.8.0-1028-intel' + create_extlinux(ubman, boot.srcdir, dir_b, 'B', verb, has_oem) + + boot_slot = 'b' if seq else 'a' + fname = os.path.join(ubman.config.result_dir, 'vbe-state.dts') + tools.write_file(fname, b'''// VBE state file + +/dts-v1/; + +/ { + compatible = "vbe,abrec-state"; + + os { + compatible = "vbe,os-state"; + + next-boot { + slot = "boot_slot"; + }; + }; +}; +'''.replace(b'boot_slot', boot_slot.encode('utf-8'))) + + dtb = fdt_util.EnsureCompiled(fname, ubman.config.result_dir) + print('dtb', dtb) + shutil.copy(dtb, f'{boot.srcdir}/vbe-state') + + boot.mk_fs() + img.add_fs(boot, DiskHelper.EXT4) + + root.mk_fs() + img.add_fs(root, DiskHelper.EXT4) + + img.create() + img.remove_img = False diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 87c4231a86d..afd7e29e404 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -15,9 +15,9 @@ import pytest import utils # pylint: disable=E0611 -from tests import fs_helper from fs_helper import DiskHelper, FsHelper from test_android import test_abootimg +from img.vbe import setup_vbe_image def mkdir_cond(dirname): """Create a directory if it doesn't already exist @@ -642,6 +642,7 @@ def test_ut_dm_init_bootstd(ubman): setup_efi_image(ubman) setup_ubuntu_image(ubman, 3, 'flash') setup_localboot_image(ubman) + setup_vbe_image(ubman) # Restart so that the new mmc1.img is picked up ubman.restart_uboot() diff --git a/test/py/tests/test_vbe.py b/test/py/tests/test_vbe.py index 7a9a3141f07..e5b489bc819 100644 --- a/test/py/tests/test_vbe.py +++ b/test/py/tests/test_vbe.py @@ -3,6 +3,8 @@ # # Test addition of VBE +import os + import pytest import fit_util @@ -118,3 +120,23 @@ def test_vbe_os_request(ubman): output = ubman.run_command_list(cmd.splitlines()) assert 'failures: 0' in output[-1] + +@pytest.mark.boardspec('sandbox') +def test_vbe_extlinux_fit_no_oem(ubman): + """Test reading a FIT from an extlinux.conf file""" + fname = os.path.join(ubman.config.persistent_data_dir, 'vbe0.img') + ubman.run_command(f'host bind 0 {fname}') + + ubman.run_command('ut -f bootstd vbe_test_abrec_no_oem_norun') + result = ubman.run_command('echo $?') + assert '0' == result + +@pytest.mark.boardspec('sandbox') +def test_vbe_extlinux_fit_oem(ubman): + """Test reading an OEM FIT, then an OS FIT from an extlinux.conf file""" + fname = os.path.join(ubman.config.persistent_data_dir, 'vbe1.img') + ubman.run_command(f'host bind 0 {fname}') + + ubman.run_command('ut -f bootstd vbe_test_abrec_oem_norun') + result = ubman.run_command('echo $?') + assert '0' == result -- 2.43.0