From 98bedf42ea49ceec934e0a47aa35caa38aac31b7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 20 Oct 2022 18:23:05 -0600 Subject: vbe: Rename vbe_fixup to vbe_request The vbe_fixup file handles device tree fixups, but these are called OS requests in VBE. Rename the file to reflect its wider purpose. Signed-off-by: Simon Glass --- test/py/tests/test_event_dump.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/py/tests') diff --git a/test/py/tests/test_event_dump.py b/test/py/tests/test_event_dump.py index 674df2ea00..0984efaf3c 100644 --- a/test/py/tests/test_event_dump.py +++ b/test/py/tests/test_event_dump.py @@ -16,7 +16,7 @@ def test_event_dump(u_boot_console): out = util.run_and_log(cons, ['scripts/event_dump.py', sandbox]) expect = '''.*Event type Id Source location -------------------- ------------------------------ ------------------------------ -EVT_FT_FIXUP bootmeth_vbe_ft_fixup .*vbe_fixup.c:.* +EVT_FT_FIXUP bootmeth_vbe_ft_fixup .*vbe_request.c:.* EVT_FT_FIXUP bootmeth_vbe_simple_ft_fixup .*vbe_simple.c:.* EVT_MISC_INIT_F sandbox_misc_init_f .*start.c:''' assert re.match(expect, out, re.MULTILINE) is not None -- cgit v1.2.3 From c263e21bcb01f19e6ccb2452fdcc601ff84942db Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 20 Oct 2022 18:23:11 -0600 Subject: vbe: Move OS implementation into a separate file Move this into its own file so it can be built only by U-Boot proper. Signed-off-by: Simon Glass --- boot/Makefile | 1 + boot/vbe_simple.c | 102 +-------------------------------------- boot/vbe_simple.h | 34 +++++++++++++ boot/vbe_simple_os.c | 89 ++++++++++++++++++++++++++++++++++ test/py/tests/test_event_dump.py | 1 - 5 files changed, 126 insertions(+), 101 deletions(-) create mode 100644 boot/vbe_simple_os.c (limited to 'test/py/tests') diff --git a/boot/Makefile b/boot/Makefile index e5c27900ea..f0c3154921 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -50,3 +50,4 @@ endif obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += vbe.o vbe_request.o obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE) += vbe_simple.o obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_FW) += vbe_simple_fw.o +obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_OS) += vbe_simple_os.o diff --git a/boot/vbe_simple.c b/boot/vbe_simple.c index 1ccd416e4b..59676d8613 100644 --- a/boot/vbe_simple.c +++ b/boot/vbe_simple.c @@ -17,37 +17,11 @@ #include #include #include -#include #include #include #include #include "vbe_simple.h" -enum { - MAX_VERSION_LEN = 256, - - NVD_HDR_VER_SHIFT = 0, - NVD_HDR_VER_MASK = 0xf, - NVD_HDR_SIZE_SHIFT = 4, - NVD_HDR_SIZE_MASK = 0xf << NVD_HDR_SIZE_SHIFT, - - /* Firmware key-version is in the top 16 bits of fw_ver */ - FWVER_KEY_SHIFT = 16, - FWVER_FW_MASK = 0xffff, - - NVD_HDR_VER_CUR = 1, /* current version */ -}; - -/** struct simple_state - state information read from media - * - * @fw_version: Firmware version string - * @fw_vernum: Firmware version number - */ -struct simple_state { - char fw_version[MAX_VERSION_LEN]; - u32 fw_vernum; -}; - /** struct simple_nvdata - storage format for non-volatile data */ struct simple_nvdata { u8 crc8; @@ -116,7 +90,7 @@ static int simple_read_nvdata(struct udevice *dev, struct blk_desc *desc, return 0; } -static int simple_read_state(struct udevice *dev, struct simple_state *state) +int vbe_simple_read_state(struct udevice *dev, struct simple_state *state) { ALLOC_CACHE_ALIGN_BUFFER(u8, buf, MMC_MAX_BLOCK_LEN); struct simple_priv *priv = dev_get_priv(dev); @@ -157,7 +131,7 @@ static int vbe_simple_get_state_desc(struct udevice *dev, char *buf, struct simple_state state; int ret; - ret = simple_read_state(dev, &state); + ret = vbe_simple_read_state(dev, &state); if (ret) return log_msg_ret("read", ret); @@ -206,78 +180,6 @@ static struct bootmeth_ops bootmeth_vbe_simple_ops = { .read_file = vbe_simple_read_file, }; -int vbe_simple_fixup_node(ofnode node, struct simple_state *state) -{ - char *version; - int ret; - - version = strdup(state->fw_version); - if (!version) - return log_msg_ret("dup", -ENOMEM); - - ret = ofnode_write_string(node, "cur-version", version); - if (ret) - return log_msg_ret("ver", ret); - ret = ofnode_write_u32(node, "cur-vernum", state->fw_vernum); - if (ret) - return log_msg_ret("num", ret); - ret = ofnode_write_string(node, "bootloader-version", version_string); - if (ret) - return log_msg_ret("bl", ret); - - return 0; -} - -/** - * bootmeth_vbe_simple_ft_fixup() - Write out all VBE simple data to the DT - * - * @ctx: Context for event - * @event: Event to process - * @return 0 if OK, -ve on error - */ -static int bootmeth_vbe_simple_ft_fixup(void *ctx, struct event *event) -{ - oftree tree = event->data.ft_fixup.tree; - struct udevice *dev; - - /* - * Ideally we would have driver model support for fixups, but that does - * not exist yet. It is a step too far to try to do this before VBE is - * in place. - */ - for (vbe_find_first_device(&dev); dev; vbe_find_next_device(&dev)) { - struct simple_state state; - ofnode node, subnode; - int ret; - - if (strcmp("vbe_simple", dev->driver->name)) - continue; - - /* Check if there is a node to fix up */ - node = oftree_path(tree, "/chosen/fwupd"); - if (!ofnode_valid(node)) - continue; - subnode = ofnode_find_subnode(node, dev->name); - if (!ofnode_valid(subnode)) - continue; - - log_debug("Fixing up: %s\n", dev->name); - ret = device_probe(dev); - if (ret) - return log_msg_ret("probe", ret); - ret = simple_read_state(dev, &state); - if (ret) - return log_msg_ret("read", ret); - - ret = vbe_simple_fixup_node(subnode, &state); - if (ret) - return log_msg_ret("fix", ret); - } - - return 0; -} -EVENT_SPY(EVT_FT_FIXUP, bootmeth_vbe_simple_ft_fixup); - static int bootmeth_vbe_simple_probe(struct udevice *dev) { struct simple_priv *priv = dev_get_priv(dev); diff --git a/boot/vbe_simple.h b/boot/vbe_simple.h index e37a9fae37..56d319206f 100644 --- a/boot/vbe_simple.h +++ b/boot/vbe_simple.h @@ -9,6 +9,21 @@ #ifndef __VBE_SIMPLE_H #define __VBE_SIMPLE_H +enum { + MAX_VERSION_LEN = 256, + + NVD_HDR_VER_SHIFT = 0, + NVD_HDR_VER_MASK = 0xf, + NVD_HDR_SIZE_SHIFT = 4, + NVD_HDR_SIZE_MASK = 0xf << NVD_HDR_SIZE_SHIFT, + + /* Firmware key-version is in the top 16 bits of fw_ver */ + FWVER_KEY_SHIFT = 16, + FWVER_FW_MASK = 0xffff, + + NVD_HDR_VER_CUR = 1, /* current version */ +}; + /** struct simple_priv - information read from the device tree */ struct simple_priv { u32 area_start; @@ -21,6 +36,16 @@ struct simple_priv { const char *storage; }; +/** struct simple_state - state information read from media + * + * @fw_version: Firmware version string + * @fw_vernum: Firmware version number + */ +struct simple_state { + char fw_version[MAX_VERSION_LEN]; + u32 fw_vernum; +}; + /** * vbe_simple_read_fw_bootflow() - Read a bootflow for firmware * @@ -34,4 +59,13 @@ struct simple_priv { */ int vbe_simple_read_bootflow_fw(struct udevice *dev, struct bootflow *bflow); +/** + * vbe_simple_read_state() - Read the VBE simple state information + * + * @dev: VBE bootmeth + * @state: Place to put the state + * @return 0 if OK, -ve on error + */ +int vbe_simple_read_state(struct udevice *dev, struct simple_state *state); + #endif /* __VBE_SIMPLE_H */ diff --git a/boot/vbe_simple_os.c b/boot/vbe_simple_os.c new file mode 100644 index 0000000000..7761b9ef65 --- /dev/null +++ b/boot/vbe_simple_os.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Verified Boot for Embedded (VBE) loading firmware phases + * + * Copyright 2022 Google LLC + * Written by Simon Glass + */ + +#define LOG_CATEGORY LOGC_BOOT + +#include +#include +#include +#include +#include +#include +#include "vbe_simple.h" + +int vbe_simple_fixup_node(ofnode node, struct simple_state *state) +{ + char *version; + int ret; + + version = strdup(state->fw_version); + if (!version) + return log_msg_ret("dup", -ENOMEM); + + ret = ofnode_write_string(node, "cur-version", version); + if (ret) + return log_msg_ret("ver", ret); + ret = ofnode_write_u32(node, "cur-vernum", state->fw_vernum); + if (ret) + return log_msg_ret("num", ret); + ret = ofnode_write_string(node, "bootloader-version", version_string); + if (ret) + return log_msg_ret("bl", ret); + + return 0; +} + +/** + * bootmeth_vbe_simple_ft_fixup() - Write out all VBE simple data to the DT + * + * @ctx: Context for event + * @event: Event to process + * @return 0 if OK, -ve on error + */ +static int bootmeth_vbe_simple_ft_fixup(void *ctx, struct event *event) +{ + oftree tree = event->data.ft_fixup.tree; + struct udevice *dev; + + /* + * Ideally we would have driver model support for fixups, but that does + * not exist yet. It is a step too far to try to do this before VBE is + * in place. + */ + for (vbe_find_first_device(&dev); dev; vbe_find_next_device(&dev)) { + struct simple_state state; + ofnode node, subnode; + int ret; + + if (strcmp("vbe_simple", dev->driver->name)) + continue; + + /* Check if there is a node to fix up */ + node = oftree_path(tree, "/chosen/fwupd"); + if (!ofnode_valid(node)) + continue; + subnode = ofnode_find_subnode(node, dev->name); + if (!ofnode_valid(subnode)) + continue; + + log_debug("Fixing up: %s\n", dev->name); + ret = device_probe(dev); + if (ret) + return log_msg_ret("probe", ret); + ret = simple_read_state(dev, &state); + if (ret) + return log_msg_ret("read", ret); + + ret = vbe_simple_fixup_node(subnode, &state); + if (ret) + return log_msg_ret("fix", ret); + } + + return 0; +} +EVENT_SPY(EVT_FT_FIXUP, bootmeth_vbe_simple_ft_fixup); diff --git a/test/py/tests/test_event_dump.py b/test/py/tests/test_event_dump.py index 0984efaf3c..972c383711 100644 --- a/test/py/tests/test_event_dump.py +++ b/test/py/tests/test_event_dump.py @@ -17,6 +17,5 @@ def test_event_dump(u_boot_console): expect = '''.*Event type Id Source location -------------------- ------------------------------ ------------------------------ EVT_FT_FIXUP bootmeth_vbe_ft_fixup .*vbe_request.c:.* -EVT_FT_FIXUP bootmeth_vbe_simple_ft_fixup .*vbe_simple.c:.* EVT_MISC_INIT_F sandbox_misc_init_f .*start.c:''' assert re.match(expect, out, re.MULTILINE) is not None -- cgit v1.2.3 From 4218456b3fac98966a320c3f2db36d543a32ec17 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 20 Oct 2022 18:23:13 -0600 Subject: vbe: Add Kconfig options for VPL Enable the various features needed in VPL, by adding Kconfig options. Update the defconfig for sandbox_vpl so that the build for each phase includes what is needed. Drop LZMA for now and make sure partition support is omitted in SPL, since it is not needed. Signed-off-by: Simon Glass --- boot/Kconfig | 137 +++++++++++++++++++++++++++++++++++++++ boot/vbe_simple_os.c | 2 +- common/spl/Kconfig.vpl | 30 +++++++++ configs/sandbox_vpl_defconfig | 13 +++- test/py/tests/test_event_dump.py | 1 + 5 files changed, 181 insertions(+), 2 deletions(-) (limited to 'test/py/tests') diff --git a/boot/Kconfig b/boot/Kconfig index 6eb056def0..93344975a6 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -292,6 +292,57 @@ config SPL_FIT_GENERATOR endif # SPL +if VPL + +config VPL_FIT + bool "Support Flattened Image Tree within VPL" + depends on VPL + default y + select VPL_HASH + select VPL_OF_LIBFDT + +config VPL_FIT_PRINT + bool "Support FIT printing within VPL" + depends on VPL_FIT + default y + help + Support printing the content of the fitImage in a verbose manner in VPL. + +config VPL_FIT_FULL_CHECK + bool "Do a full check of the FIT before using it" + default y + help + Enable this do a full check of the FIT to make sure it is valid. This + helps to protect against carefully crafted FITs which take advantage + of bugs or omissions in the code. This includes a bad structure, + multiple root nodes and the like. + +config VPL_FIT_SIGNATURE + bool "Enable signature verification of FIT firmware within VPL" + depends on VPL_DM + depends on VPL_LOAD_FIT || VPL_LOAD_FIT_FULL + default y + select FIT_SIGNATURE + select VPL_FIT + select VPL_CRYPTO + select VPL_HASH + imply VPL_RSA + imply VPL_RSA_VERIFY + select VPL_IMAGE_SIGN_INFO + select VPL_FIT_FULL_CHECK + +config VPL_FIT_SIGNATURE_MAX_SIZE + hex "Max size of signed FIT structures in VPL" + depends on VPL_FIT_SIGNATURE + default 0x10000000 + help + This option sets a max size in bytes for verified FIT uImages. + A sane value of 256MB protects corrupted DTB structures from overlapping + device memory. Assure this size does not extend past expected storage + space. + +endif # VPL + endif # FIT config PXE_UTILS @@ -334,6 +385,26 @@ config BOOTSTD_FULL - support for selecting the ordering of bootdevs using the devicetree as well as the "boot_targets" environment variable +config SPL_BOOTSTD + bool "Standard boot support in VPL" + depends on SPL && SPL_DM && SPL_OF_CONTROL && SPL_BLK + default y if VPL + help + This enables standard boot in SPL. This is neeeded so that VBE + (Verified Boot for Embedded) can be used, since it depends on standard + boot. It is enabled by default since the main purpose of VPL is to + handle the firmware part of VBE. + +config VPL_BOOTSTD + bool "Standard boot support in VPL" + depends on VPL && VPL_DM && VPL_OF_CONTROL && VPL_BLK + default y + help + This enables standard boot in SPL. This is neeeded so that VBE + (Verified Boot for Embedded) can be used, since it depends on standard + boot. It is enabled by default since the main purpose of VPL is to + handle the firmware part of VBE. + if BOOTSTD config BOOTSTD_BOOTCOMMAND @@ -408,6 +479,24 @@ config BOOTMETH_VBE supports selection of various firmware components, seleciton of an OS to boot as well as updating these using fwupd. +config SPL_BOOTMETH_VBE + bool "Bootdev support for Verified Boot for Embedded (SPL)" + depends on SPL && FIT + default y if VPL + help + Enables support for VBE boot. This is a standard boot method which + supports selection of various firmware components, seleciton of an OS to + boot as well as updating these using fwupd. + +config VPL_BOOTMETH_VBE + bool "Bootdev support for Verified Boot for Embedded (VPL)" + depends on VPL && FIT + default y + help + Enables support for VBE boot. This is a standard boot method which + supports selection of various firmware components, seleciton of an OS to + boot as well as updating these using fwupd. + if BOOTMETH_VBE config BOOTMETH_VBE_SIMPLE @@ -418,6 +507,54 @@ config BOOTMETH_VBE_SIMPLE firmware image in boot media such as MMC. It does not support any sort of rollback, recovery or A/B boot. +config BOOTMETH_VBE_SIMPLE_OS + bool "Bootdev support for VBE 'simple' method OS phase" + default y + help + Enables support for the OS parts of VBE 'simple' boot. This includes + fixing up the device tree with the required VBE information, ready + for booting into the OS. This option is only enabled for U-Boot + proper, since it is the phase where device tree fixups happen. + +config SPL_BOOTMETH_VBE_SIMPLE + bool "Bootdev support for VBE 'simple' method (SPL)" + depends on SPL + default y if VPL + help + Enables support for VBE 'simple' boot. This allows updating a single + firmware image in boot media such as MMC. It does not support any sort + of rollback, recovery or A/B boot. + +config VPL_BOOTMETH_VBE_SIMPLE + bool "Bootdev support for VBE 'simple' method (VPL)" + depends on VPL + default y + help + Enables support for VBE 'simple' boot. This allows updating a single + firmware image in boot media such as MMC. It does not support any sort + of rollback, recovery or A/B boot. + +config SPL_BOOTMETH_VBE_SIMPLE_FW + bool "Bootdev support for VBE 'simple' method firmware phase (SPL)" + depends on VPL + default y + help + Enables support for the firmware parts of VBE 'simple' boot. This + includes an SPL loader which locates the correct U-Boot to boot into. + This option should really only be enabled for VPL, since it is the + phase where the SPL + U-Boot decision should be made. But for now, + SPL does its own FIT-configuration selection. + +config VPL_BOOTMETH_VBE_SIMPLE_FW + bool "Bootdev support for VBE 'simple' method firmware phase (VPL)" + depends on VPL + default y + help + Enables support for the firmware parts of VBE 'simple' boot. This + includes an SPL loader which locates the correct SPL to boot into. + This option enabled for VPL, since it is the phase where the SPL + decision is made. + endif # BOOTMETH_VBE config BOOTMETH_SANDBOX diff --git a/boot/vbe_simple_os.c b/boot/vbe_simple_os.c index 058db6154b..87778bba97 100644 --- a/boot/vbe_simple_os.c +++ b/boot/vbe_simple_os.c @@ -80,7 +80,7 @@ static int bootmeth_vbe_simple_ft_fixup(void *ctx, struct event *event) ret = device_probe(dev); if (ret) return log_msg_ret("probe", ret); - ret = simple_read_state(dev, &state); + ret = vbe_simple_read_state(dev, &state); if (ret) return log_msg_ret("read", ret); diff --git a/common/spl/Kconfig.vpl b/common/spl/Kconfig.vpl index f33162276d..ae1a3c724f 100644 --- a/common/spl/Kconfig.vpl +++ b/common/spl/Kconfig.vpl @@ -133,6 +133,36 @@ config VPL_I2C_SUPPORT Enable support for the I2C bus in VPL. Vee SPL_I2C_SUPPORT for details. +config VPL_MMC + bool "Support MMC in VPL" + depends on VPL && MMC + default y if MMC + help + Enable support for MMC (Multimedia Card) within VPL This enables + the MMC protocol implementation and allows any enabled drivers to + be used within VPL. MMC can be used with or without disk partition + support depending on the application (SPL_LIBDISK_SUPPORT). Enable + this option to build the drivers in drivers/mmc as part of an VPL + build. + +config VPL_DM_MMC + bool "Enable MMC controllers using Driver Model in VPL" + depends on VPL_DM && DM_MMC + default y + help + This enables the MultiMediaCard (MMC) uclass which supports MMC and + Secure Digital I/O (SDIO) cards. Both removable (SD, micro-SD, etc.) + and non-removable (e.g. eMMC chip) devices are supported. These + appear as block devices in U-Boot and can support filesystems such + as EXT4 and FAT. + +config VPL_MMC_WRITE + bool "MMC/SD/SDIO card support for write operations in VPL" + depends on VPL_MMC + default y + help + Enable write access to MMC and SD Cards in VPL + config VPL_PCH_SUPPORT bool "Support PCH drivers" default y if TPL_PCH_SUPPORT diff --git a/configs/sandbox_vpl_defconfig b/configs/sandbox_vpl_defconfig index a2a1295549..557fdd141f 100644 --- a/configs/sandbox_vpl_defconfig +++ b/configs/sandbox_vpl_defconfig @@ -4,7 +4,10 @@ CONFIG_SPL_LIBGENERIC_SUPPORT=y CONFIG_NR_DRAM_BANKS=1 CONFIG_ENV_SIZE=0x2000 CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_SPL_TEXT_BASE=0x100000 +CONFIG_SPL_MMC=y CONFIG_SPL_SERIAL=y +CONFIG_TPL_TEXT_BASE=0x100000 CONFIG_TPL_LIBCOMMON_SUPPORT=y CONFIG_TPL_LIBGENERIC_SUPPORT=y CONFIG_TPL_SERIAL=y @@ -23,6 +26,7 @@ CONFIG_DISTRO_DEFAULTS=y CONFIG_FIT=y CONFIG_FIT_SIGNATURE=y CONFIG_FIT_VERBOSE=y +CONFIG_FIT_BEST_MATCH=y CONFIG_SPL_LOAD_FIT=y # CONFIG_USE_SPL_FIT_GENERATOR is not set CONFIG_BOOTSTAGE=y @@ -47,6 +51,7 @@ CONFIG_TPL_I2C=y CONFIG_TPL_RTC=y CONFIG_VPL=y CONFIG_VPL_ENV_SUPPORT=y +CONFIG_VPL_TEXT_BASE=0x100000 CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTZ=y @@ -98,7 +103,9 @@ CONFIG_CMD_CBFS=y CONFIG_CMD_CRAMFS=y CONFIG_CMD_EXT4_WRITE=y CONFIG_MAC_PARTITION=y -CONFIG_AMIGA_PARTITION=y +# CONFIG_SPL_MAC_PARTITION is not set +# CONFIG_SPL_DOS_PARTITION is not set +# CONFIG_SPL_EFI_PARTITION is not set CONFIG_OF_CONTROL=y CONFIG_SPL_OF_CONTROL=y CONFIG_TPL_OF_CONTROL=y @@ -113,6 +120,7 @@ CONFIG_NETCONSOLE=y CONFIG_IP_DEFRAG=y CONFIG_SPL_DM=y CONFIG_TPL_DM=y +CONFIG_SPL_DM_SEQ_ALIAS=y CONFIG_DM_DMA=y CONFIG_REGMAP=y CONFIG_SPL_REGMAP=y @@ -226,6 +234,8 @@ CONFIG_SPL_SYSRESET=y CONFIG_TPL_SYSRESET=y CONFIG_DM_THERMAL=y CONFIG_TIMER=y +CONFIG_SPL_TIMER=y +CONFIG_VPL_TIMER=y CONFIG_TIMER_EARLY=y CONFIG_SANDBOX_TIMER=y CONFIG_USB=y @@ -246,6 +256,7 @@ CONFIG_CMD_DHRYSTONE=y CONFIG_RSA_VERIFY_WITH_PKEY=y CONFIG_TPM=y CONFIG_LZ4=y +# CONFIG_VPL_LZMA is not set CONFIG_ERRNO_STR=y CONFIG_UNIT_TEST=y CONFIG_SPL_UNIT_TEST=y diff --git a/test/py/tests/test_event_dump.py b/test/py/tests/test_event_dump.py index 972c383711..1a46ca30f4 100644 --- a/test/py/tests/test_event_dump.py +++ b/test/py/tests/test_event_dump.py @@ -17,5 +17,6 @@ def test_event_dump(u_boot_console): expect = '''.*Event type Id Source location -------------------- ------------------------------ ------------------------------ EVT_FT_FIXUP bootmeth_vbe_ft_fixup .*vbe_request.c:.* +EVT_FT_FIXUP bootmeth_vbe_simple_ft_fixup .*vbe_simple_os.c:.* EVT_MISC_INIT_F sandbox_misc_init_f .*start.c:''' assert re.match(expect, out, re.MULTILINE) is not None -- cgit v1.2.3 From 2a5c67f50a438b266dc72c9401e578ec8b81db16 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 20 Oct 2022 18:23:17 -0600 Subject: vbe: Use a manual test Use a manual test for the VBE test, so we can make the pytest and the C unit test work together properly. Signed-off-by: Simon Glass --- test/boot/vbe_fixup.c | 19 ++++++++----------- test/py/tests/test_vbe.py | 7 ++----- 2 files changed, 10 insertions(+), 16 deletions(-) (limited to 'test/py/tests') diff --git a/test/boot/vbe_fixup.c b/test/boot/vbe_fixup.c index 7f0f809499..eba5c4ebe6 100644 --- a/test/boot/vbe_fixup.c +++ b/test/boot/vbe_fixup.c @@ -13,21 +13,18 @@ #include #include "bootstd_common.h" -/* Basic test of reading nvdata and updating a fwupd node in the device tree */ -static int vbe_test_fixup(struct unit_test_state *uts) +/* + * Basic test of reading nvdata and updating a fwupd node in the device tree + * This test works when called from test_vbe.py and it must use the flat tree, + * since device tree fix-ups do not yet support live tree. + */ +static int vbe_test_fixup_norun(struct unit_test_state *uts) { ofnode chosen, node; const char *data; oftree tree; int size; - /* - * This test works when called from test_vbe.py and it must use the - * flat tree, since device tree fix-ups do not yet support live tree. - */ - if (!working_fdt) - return -EAGAIN; - tree = oftree_from_fdt(working_fdt); ut_assert(oftree_valid(tree)); @@ -55,5 +52,5 @@ static int vbe_test_fixup(struct unit_test_state *uts) return 0; } -BOOTSTD_TEST(vbe_test_fixup, - UT_TESTF_DM | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE); +BOOTSTD_TEST(vbe_test_fixup_norun, UT_TESTF_DM | UT_TESTF_SCAN_FDT | + UT_TESTF_FLAT_TREE | UT_TESTF_MANUAL); diff --git a/test/py/tests/test_vbe.py b/test/py/tests/test_vbe.py index 559c291886..50b6c1cd91 100644 --- a/test/py/tests/test_vbe.py +++ b/test/py/tests/test_vbe.py @@ -85,7 +85,7 @@ bootm loados bootm prep fdt addr fdt print -ut bootstd vbe_test_fixup +ut bootstd -f vbe_test_fixup_norun ''' @pytest.mark.boardspec('sandbox_flattree') @@ -117,7 +117,4 @@ def test_vbe(u_boot_console): with cons.log.section('Kernel load'): output = cons.run_command_list(cmd.splitlines()) - # This is a little wonky since there are two tests running in CI. The final - # one is the 'ut bootstd' command above - failures = [line for line in output if 'Failures' in line] - assert len(failures) >= 1 and 'Failures: 0' in failures[-1] + assert 'Failures: 0' in output[-1] -- cgit v1.2.3 From 77bec9e3d8bd2dc307447b92a3d5cefd693a62ad Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 20 Oct 2022 18:23:20 -0600 Subject: vbe: Add a test for the VBE flow into U-Boot proper Add a test which checks that VBE boots correctly from TPL through to U-Boot proper. Signed-off-by: Simon Glass --- arch/sandbox/dts/test.dts | 37 +++++++++++++++++++++++++++++++++++++ test/py/tests/test_vbe_vpl.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 test/py/tests/test_vbe_vpl.py (limited to 'test/py/tests') diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 75eeaf8ca1..25fd2bcab8 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -37,6 +37,8 @@ i2c0 = "/i2c@0"; mmc0 = "/mmc0"; mmc1 = "/mmc1"; + mmc2 = "/mmc2"; + mmc3 = "/mmc3"; pci0 = &pci0; pci1 = &pci1; pci2 = &pci2; @@ -92,6 +94,11 @@ compatible = "u-boot,distro-efi"; }; + /* + * This is used for the VBE OS-request tests. A FAT filesystem + * created in a partition with the VBE information appearing + * before the parititon starts + */ firmware0 { u-boot,dm-vpl; compatible = "fwupd,vbe-simple"; @@ -104,6 +111,28 @@ version-offset = <0x800>; version-size = <0x100>; }; + + /* + * This is used for the VBE VPL tests. The MMC device holds the + * binman image.bin file. The test progresses through each phase + * of U-Boot, loading each in turn from MMC. + * + * Note that the test enables this node (and mmc3) before + * running U-Boot + */ + firmware1 { + u-boot,dm-vpl; + status = "disabled"; + compatible = "fwupd,vbe-simple"; + storage = "mmc3"; + skip-offset = <0x400000>; + area-start = <0>; + area-size = <0xe00000>; + state-offset = <0xdffc00>; + state-size = <0x40>; + version-offset = <0xdffe00>; + version-size = <0x100>; + }; }; fuzzing-engine { @@ -976,6 +1005,14 @@ compatible = "sandbox,mmc"; }; + /* This is used for VBE VPL tests */ + mmc3 { + status = "disabled"; + compatible = "sandbox,mmc"; + filename = "image.bin"; + non-removable; + }; + pch { compatible = "sandbox,pch"; }; diff --git a/test/py/tests/test_vbe_vpl.py b/test/py/tests/test_vbe_vpl.py new file mode 100644 index 0000000000..d1c9d0548a --- /dev/null +++ b/test/py/tests/test_vbe_vpl.py @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2022 Google LLC +# +# Test addition of VBE + +import os + +import pytest +import u_boot_utils + +@pytest.mark.boardspec('sandbox_vpl') +@pytest.mark.requiredtool('dtc') +def test_vbe_vpl(u_boot_console): + cons = u_boot_console + #cmd = [cons.config.build_dir + fname, '-v'] + ram = os.path.join(cons.config.build_dir, 'ram.bin') + fdt = os.path.join(cons.config.build_dir, 'arch/sandbox/dts/test.dtb') + + # Enable firmware1 and the mmc that it uses. These are needed for the full + # VBE flow. + u_boot_utils.run_and_log( + cons, f'fdtput -t s {fdt} /bootstd/firmware0 status disabled') + u_boot_utils.run_and_log( + cons, f'fdtput -t s {fdt} /bootstd/firmware1 status okay') + u_boot_utils.run_and_log( + cons, f'fdtput -t s {fdt} /mmc3 status okay') + + # Remove any existing RAM file, so we don't have old data present + if os.path.exists(ram): + os.remove(ram) + flags = ['-p', os.path.join(cons.config.build_dir, 'image.bin'), '-w', + '-s', 'state.dtb'] + cons.restart_uboot_with_flags(flags) + + # Make sure that VBE was used in both VPL (to load SPL) and SPL (to load + # U-Boot + output = cons.run_command('vbe state') + assert output == 'Phases: VPL SPL' -- cgit v1.2.3