summaryrefslogtreecommitdiff
path: root/test/boot
diff options
context:
space:
mode:
Diffstat (limited to 'test/boot')
-rw-r--r--test/boot/Makefile1
-rw-r--r--test/boot/bootflow.c2
-rw-r--r--test/boot/bootmeth.c2
-rw-r--r--test/boot/bootstd_common.c49
-rw-r--r--test/boot/bootstd_common.h16
-rw-r--r--test/boot/vbe_fixup.c59
-rw-r--r--test/boot/vbe_simple.c34
7 files changed, 132 insertions, 31 deletions
diff --git a/test/boot/Makefile b/test/boot/Makefile
index 9e9d5ae21f3..5bb3f889759 100644
--- a/test/boot/Makefile
+++ b/test/boot/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_BOOTSTD) += bootdev.o bootstd_common.o bootflow.o bootmeth.o
ifdef CONFIG_OF_LIVE
obj-$(CONFIG_BOOTMETH_VBE_SIMPLE) += vbe_simple.o
endif
+obj-$(CONFIG_BOOTMETH_VBE) += vbe_fixup.o
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 85305234e01..1e8ea754bcd 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -329,6 +329,8 @@ static int bootflow_system(struct unit_test_state *uts)
{
struct udevice *dev;
+ if (!IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR))
+ return 0;
ut_assertok(uclass_get_device_by_name(UCLASS_BOOTMETH, "efi_mgr",
&dev));
sandbox_set_fake_efi_mgr_dev(dev, true);
diff --git a/test/boot/bootmeth.c b/test/boot/bootmeth.c
index fb627313396..f0b5ab9adb3 100644
--- a/test/boot/bootmeth.c
+++ b/test/boot/bootmeth.c
@@ -156,7 +156,7 @@ static int bootmeth_state(struct unit_test_state *uts)
struct udevice *dev;
char buf[50];
- ut_assertok(uclass_first_device(UCLASS_BOOTMETH, &dev));
+ ut_assertok(uclass_first_device_err(UCLASS_BOOTMETH, &dev));
ut_assertnonnull(dev);
ut_assertok(bootmeth_get_state_desc(dev, buf, sizeof(buf)));
diff --git a/test/boot/bootstd_common.c b/test/boot/bootstd_common.c
index 05347d87106..7a40836507a 100644
--- a/test/boot/bootstd_common.c
+++ b/test/boot/bootstd_common.c
@@ -9,10 +9,52 @@
#include <common.h>
#include <bootstd.h>
#include <dm.h>
+#include <memalign.h>
+#include <mmc.h>
+#include <linux/log2.h>
#include <test/suites.h>
#include <test/ut.h>
+#include <u-boot/crc.h>
#include "bootstd_common.h"
+/* tracks whether bootstd_setup_for_tests() has been run yet */
+bool vbe_setup_done;
+
+/* set up MMC for VBE tests */
+int bootstd_setup_for_tests(void)
+{
+ ALLOC_CACHE_ALIGN_BUFFER(u8, buf, MMC_MAX_BLOCK_LEN);
+ struct udevice *mmc;
+ struct blk_desc *desc;
+ int ret;
+
+ if (vbe_setup_done)
+ return 0;
+
+ /* Set up the version string */
+ ret = uclass_get_device(UCLASS_MMC, 1, &mmc);
+ if (ret)
+ return log_msg_ret("mmc", -EIO);
+ desc = blk_get_by_device(mmc);
+
+ memset(buf, '\0', MMC_MAX_BLOCK_LEN);
+ strcpy(buf, TEST_VERSION);
+ if (blk_dwrite(desc, VERSION_START_BLK, 1, buf) != 1)
+ return log_msg_ret("wr1", -EIO);
+
+ /* Set up the nvdata */
+ memset(buf, '\0', MMC_MAX_BLOCK_LEN);
+ buf[1] = ilog2(0x40) << 4 | 1;
+ *(u32 *)(buf + 4) = TEST_VERNUM;
+ buf[0] = crc8(0, buf + 1, 0x3f);
+ if (blk_dwrite(desc, NVDATA_START_BLK, 1, buf) != 1)
+ return log_msg_ret("wr2", -EIO);
+
+ vbe_setup_done = true;
+
+ return 0;
+}
+
int bootstd_test_drop_bootdev_order(struct unit_test_state *uts)
{
struct bootstd_priv *priv;
@@ -29,6 +71,13 @@ int do_ut_bootstd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
struct unit_test *tests = UNIT_TEST_SUITE_START(bootstd_test);
const int n_ents = UNIT_TEST_SUITE_COUNT(bootstd_test);
+ int ret;
+
+ ret = bootstd_setup_for_tests();
+ if (ret) {
+ printf("Failed to set up for bootstd tests (err=%d)\n", ret);
+ return CMD_RET_FAILURE;
+ }
return cmd_ut_category("bootstd", "bootstd_test_",
tests, n_ents, argc, argv);
diff --git a/test/boot/bootstd_common.h b/test/boot/bootstd_common.h
index 676ef0a57f9..c5e0fd1ceab 100644
--- a/test/boot/bootstd_common.h
+++ b/test/boot/bootstd_common.h
@@ -9,10 +9,17 @@
#ifndef __bootstd_common_h
#define __bootstd_common_h
+#include <version_string.h>
+
/* Declare a new bootdev test */
#define BOOTSTD_TEST(_name, _flags) \
UNIT_TEST(_name, _flags, bootstd_test)
+#define NVDATA_START_BLK ((0x400 + 0x400) / MMC_MAX_BLOCK_LEN)
+#define VERSION_START_BLK ((0x400 + 0x800) / MMC_MAX_BLOCK_LEN)
+#define TEST_VERSION "U-Boot v2022.04-local2"
+#define TEST_VERNUM 0x00010002
+
struct unit_test_state;
/**
@@ -24,4 +31,13 @@ struct unit_test_state;
*/
int bootstd_test_drop_bootdev_order(struct unit_test_state *uts);
+/**
+ * bootstd_setup_for_tests() - Set up MMC data for VBE tests
+ *
+ * Some data is needed for VBE tests to work. This function sets that up.
+ *
+ * @return 0 if OK, -ve on error
+ */
+int bootstd_setup_for_tests(void);
+
#endif
diff --git a/test/boot/vbe_fixup.c b/test/boot/vbe_fixup.c
new file mode 100644
index 00000000000..1b488e25ab6
--- /dev/null
+++ b/test/boot/vbe_fixup.c
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for VBE device tree fix-ups
+ *
+ * Copyright 2022 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <dm/ofnode.h>
+#include <linux/libfdt.h>
+#include <test/test.h>
+#include <test/ut.h>
+#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)
+{
+ 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 0;
+
+ tree = oftree_from_fdt(working_fdt);
+ ut_assert(oftree_valid(tree));
+
+ chosen = oftree_path(tree, "/chosen");
+ ut_assert(ofnode_valid(chosen));
+
+ /* check the things set up for the FIT in test_vbe.py */
+ node = ofnode_find_subnode(chosen, "random");
+
+ /* ignore if this test is run on its own */
+ if (!ofnode_valid(node))
+ return 0;
+ data = ofnode_read_prop(node, "data", &size);
+ ut_asserteq(0x40, size);
+
+ node = ofnode_find_subnode(chosen, "aslr2");
+ ut_assert(ofnode_valid(node));
+ data = ofnode_read_prop(node, "data", &size);
+ ut_asserteq(4, size);
+
+ node = ofnode_find_subnode(chosen, "efi-runtime");
+ ut_assert(ofnode_valid(node));
+ data = ofnode_read_prop(node, "data", &size);
+ ut_asserteq(4, size);
+
+ return 0;
+}
+BOOTSTD_TEST(vbe_test_fixup,
+ UT_TESTF_DM | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
diff --git a/test/boot/vbe_simple.c b/test/boot/vbe_simple.c
index 8acd777f4cd..faba9e8f90b 100644
--- a/test/boot/vbe_simple.c
+++ b/test/boot/vbe_simple.c
@@ -10,54 +10,27 @@
#include <bootmeth.h>
#include <dm.h>
#include <image.h>
-#include <memalign.h>
-#include <mmc.h>
#include <of_live.h>
#include <vbe.h>
-#include <version_string.h>
-#include <linux/log2.h>
#include <test/suites.h>
#include <test/ut.h>
-#include <u-boot/crc.h>
#include "bootstd_common.h"
-#define NVDATA_START_BLK ((0x400 + 0x400) / MMC_MAX_BLOCK_LEN)
-#define VERSION_START_BLK ((0x400 + 0x800) / MMC_MAX_BLOCK_LEN)
-#define TEST_VERSION "U-Boot v2022.04-local2"
-#define TEST_VERNUM 0x00010002
-
/* Basic test of reading nvdata and updating a fwupd node in the device tree */
static int vbe_simple_test_base(struct unit_test_state *uts)
{
- ALLOC_CACHE_ALIGN_BUFFER(u8, buf, MMC_MAX_BLOCK_LEN);
const char *version, *bl_version;
struct event_ft_fixup fixup;
- struct udevice *dev, *mmc;
+ struct udevice *dev;
struct device_node *np;
- struct blk_desc *desc;
char fdt_buf[0x400];
char info[100];
int node_ofs;
ofnode node;
u32 vernum;
- /* Set up the version string */
- ut_assertok(uclass_get_device(UCLASS_MMC, 1, &mmc));
- desc = blk_get_by_device(mmc);
- ut_assertnonnull(desc);
-
- memset(buf, '\0', MMC_MAX_BLOCK_LEN);
- strcpy(buf, TEST_VERSION);
- if (blk_dwrite(desc, VERSION_START_BLK, 1, buf) != 1)
- return log_msg_ret("write", -EIO);
-
- /* Set up the nvdata */
- memset(buf, '\0', MMC_MAX_BLOCK_LEN);
- buf[1] = ilog2(0x40) << 4 | 1;
- *(u32 *)(buf + 4) = TEST_VERNUM;
- buf[0] = crc8(0, buf + 1, 0x3f);
- if (blk_dwrite(desc, NVDATA_START_BLK, 1, buf) != 1)
- return log_msg_ret("write", -EIO);
+ /* Set up the VBE info */
+ ut_assertok(bootstd_setup_for_tests());
/* Read the version back */
ut_assertok(vbe_find_by_any("firmware0", &dev));
@@ -90,6 +63,7 @@ static int vbe_simple_test_base(struct unit_test_state *uts)
*
* Two fix this we need image_setup_libfdt() is updated to use ofnode
*/
+ fixup.images = NULL;
ut_assertok(event_notify(EVT_FT_FIXUP, &fixup, sizeof(fixup)));
node = oftree_path(fixup.tree, "/chosen/fwupd/firmware0");