Re: [PATCH v2 14/14] vbe: Add a test for VBE device tree fixups

2022-10-17 Thread Simon Glass
When a FIT includes some OS requests, U-Boot should process these and add
the requested info to corresponding subnodes of the /chosen node. Add a
pytest for this, which sets up the FIT, runs bootm and then uses a C
unit test to check that everything looks OK.

The test needs to run on sandbox_flattree since we don't support
device tree fixups on sandbox (live tree) yet. So enable BOOTMETH_VBE and
disable bootflow_system(), since EFI is not supported on
sandbox_flattree.

Add a link to the initial documentation.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 configs/sandbox_flattree_defconfig |   2 +-
 doc/develop/vbe.rst|   3 +-
 test/boot/Makefile |   1 +
 test/boot/bootflow.c   |   2 +
 test/boot/vbe_fixup.c  |  59 ++
 test/py/tests/fit_util.py  |   5 +-
 test/py/tests/test_vbe.py  | 123 +
 7 files changed, 192 insertions(+), 3 deletions(-)
 create mode 100644 test/boot/vbe_fixup.c
 create mode 100644 test/py/tests/test_vbe.py

Applied to u-boot-dm, thanks!


[PATCH v2 14/14] vbe: Add a test for VBE device tree fixups

2022-10-11 Thread Simon Glass
When a FIT includes some OS requests, U-Boot should process these and add
the requested info to corresponding subnodes of the /chosen node. Add a
pytest for this, which sets up the FIT, runs bootm and then uses a C
unit test to check that everything looks OK.

The test needs to run on sandbox_flattree since we don't support
device tree fixups on sandbox (live tree) yet. So enable BOOTMETH_VBE and
disable bootflow_system(), since EFI is not supported on
sandbox_flattree.

Add a link to the initial documentation.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 configs/sandbox_flattree_defconfig |   2 +-
 doc/develop/vbe.rst|   3 +-
 test/boot/Makefile |   1 +
 test/boot/bootflow.c   |   2 +
 test/boot/vbe_fixup.c  |  59 ++
 test/py/tests/fit_util.py  |   5 +-
 test/py/tests/test_vbe.py  | 123 +
 7 files changed, 192 insertions(+), 3 deletions(-)
 create mode 100644 test/boot/vbe_fixup.c
 create mode 100644 test/py/tests/test_vbe.py

diff --git a/configs/sandbox_flattree_defconfig 
b/configs/sandbox_flattree_defconfig
index a2eb7afcf9b..0d8e3132320 100644
--- a/configs/sandbox_flattree_defconfig
+++ b/configs/sandbox_flattree_defconfig
@@ -11,7 +11,6 @@ CONFIG_DISTRO_DEFAULTS=y
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_FIT_VERBOSE=y
-# CONFIG_BOOTMETH_VBE is not set
 CONFIG_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_BOOTSTAGE_FDT=y
@@ -83,6 +82,7 @@ CONFIG_REGMAP=y
 CONFIG_SYSCON=y
 CONFIG_DEVRES=y
 CONFIG_DEBUG_DEVRES=y
+CONFIG_OFNODE_MULTI_TREE=y
 CONFIG_ADC=y
 CONFIG_ADC_SANDBOX=y
 CONFIG_AXI=y
diff --git a/doc/develop/vbe.rst b/doc/develop/vbe.rst
index 8f147fd9360..cca193c8fd4 100644
--- a/doc/develop/vbe.rst
+++ b/doc/develop/vbe.rst
@@ -19,8 +19,9 @@ listing methods and getting the status for a method.
 
 For a detailed overview of VBE, see vbe-intro_. A fuller description of
 bootflows is at vbe-bootflows_ and the firmware-update mechanism is described 
at
-vbe-fwupdate_.
+vbe-fwupdate_. VBE OS requests are described at  vbe-osrequests_.
 
 .. _vbe-intro: 
https://docs.google.com/document/d/e/2PACX-1vQjXLPWMIyVktaTMf8edHZYDrEvMYD_iNzIj1FgPmKF37fpglAC47Tt5cvPBC5fvTdoK-GA5Zv1wifo/pub
 .. _vbe-bootflows: 
https://docs.google.com/document/d/e/2PACX-1vR0OzhuyRJQ8kdeOibS3xB1rVFy3J4M_QKTM5-3vPIBNcdvR0W8EXu9ymG-yWfqthzWoM4JUNhqwydN/pub
 .. _vbe-fwupdate: 
https://docs.google.com/document/d/e/2PACX-1vTnlIL17vVbl6TVoTHWYMED0bme7oHHNk-g5VGxblbPiKIdGDALE1HKId8Go5f0g1eziLsv4h9bocbk/pub
+.. _vbe-osrequests: 
https://docs.google.com/document/d/e/2PACX-1vTHhxX7WSZe68i9rAkW-DHdx6koU-jxYHhamLhZn9GQ9QT2_epSBosMV1_r7yPHOXZccx71rF_t0PXL/pub
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",
  ));
sandbox_set_fake_efi_mgr_dev(dev, true);
diff --git a/test/boot/vbe_fixup.c b/test/boot/vbe_fixup.c
new file mode 100644
index 000..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 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#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)
+{
+   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", );
+   ut_asserteq(0x40, size);
+
+   node = ofnode_find_subnode(chosen, "aslr2");
+