Skip to contentSkip to conversation

Universal Payload initial series

RFC PATCH Superseded Simon Glass 2 participants 11 messages Aug 30, 2023 – Aug 31, 2023 Generic include/asm header files

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Universal Payload initial series

Universal Payload (UPL) is an upcoming Industry Standard for firmware components. UPL is designed to improve interoperability within the firmware industry, allowing mixing and matching of projects with less friction and fewer project-specific implementations. UPL is cross-platform, supporting ARM, x86 and RISC-V initially.

This series provides some initial support for this, for comment only.

Simon Glass (9):
upl: Add support for reading a upl handoff
upl: Add support for writing a upl handoff
upl: Add basic tests
upl: Add a command
upl: Add support for Universal Payload in SPL
spl: Plumb in the Universal Payload handoff
Plumb in universal payload to the init process
sandbox_vpl: Enable Universal Payload
upl: Add initial documentation

 boot/Kconfig                      |  72 +++-
 boot/Makefile                     |   4 +
 boot/upl_common.c                 |  51 +++
 boot/upl_common.h                 |  24 ++
 boot/upl_read.c                   | 607 +++++++++++++++++++++++++++++
 boot/upl_write.c                  | 623 ++++++++++++++++++++++++++++++
 cmd/Kconfig                       |   7 +
 cmd/Makefile                      |   1 +
 cmd/upl.c                         |  99 +++++
 common/board_f.c                  |  22 ++
 common/board_r.c                  |   2 +
 common/spl/Makefile               |   2 +
 common/spl/spl.c                  |   6 +
 common/spl/spl_fit.c              |  22 ++
 common/spl/spl_upl.c              | 153 ++++++++
 configs/sandbox_defconfig         |   6 +-
 configs/sandbox_vpl_defconfig     |   4 +
 doc/usage/cmd/upl.rst             | 149 +++++++
 doc/usage/index.rst               |   2 +
 doc/usage/upl.rst                 |  27 ++
 include/asm-generic/global_data.h |  15 +
 include/spl.h                     |  11 +
 include/upl.h                     | 361 +++++++++++++++++
 test/boot/Makefile                |   2 +
 test/boot/upl.c                   | 457 ++++++++++++++++++++++
 test/py/tests/test_upl.py         |  25 ++
 26 files changed, 2750 insertions(+), 4 deletions(-)
 create mode 100644 boot/upl_common.c
 create mode 100644 boot/upl_common.h
 create mode 100644 boot/upl_read.c
 create mode 100644 boot/upl_write.c
 create mode 100644 cmd/upl.c
 create mode 100644 common/spl/spl_upl.c
 create mode 100644 doc/usage/cmd/upl.rst
 create mode 100644 doc/usage/upl.rst
 create mode 100644 include/upl.h
 create mode 100644 test/boot/upl.c
 create mode 100644 test/py/tests/test_upl.py
Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
#1 lore raw

RFC PATCH 1/9 upl: Add support for reading a upl handoff

Universal Payload provides a standard way of handing off control between two firmware phases. Add support for reading the handoff information into a structure.

---

 boot/Kconfig              |  21 +-
 boot/Makefile             |   3 +
 boot/upl_common.c         |  51 ++++
 boot/upl_common.h         |  24 ++
 boot/upl_read.c           | 607 ++++++++++++++++++++++++++++++++++++++
 configs/sandbox_defconfig |   6 +-
 include/upl.h             | 361 +++++++++++++++++++++++
 7 files changed, 1069 insertions(+), 4 deletions(-)
 create mode 100644 boot/upl_common.c
 create mode 100644 boot/upl_common.h
 create mode 100644 boot/upl_read.c
 create mode 100644 include/upl.h
boot/Kconfig +20 -1
index 86ccfd78031..e4625cc5fcb 100644
@@ -676,7 +676,26 @@ config BOOTMETH_SCRIPT
 	  This provides a way to try out standard boot on an existing boot flow.
 	  It is not enabled by default to save space.
 
-endif
+config UPL
+	bool "upl - Universal Payload Specification"
+	imply UPL_READ
+	help
+	  Provides support for UPL payloads and handoff information. U-Boot
+	  supports generating and accepting handoff information. The mkimage
+	  tool will eventually support creating payloads.
+
+if UPL
+
+config UPL_READ
+	bool "upl - Support reading a Universal Payload handoff"
+	help
+	  Provides support for decoding a UPL-format payload into a C structure
+	  which can be used elsewhere in U-Boot. This is just the reading
+	  implementation, useful for trying it out.
+
+endif  # UPL
+
+endif  # BOOTSTD
 
 config LEGACY_IMAGE_FORMAT
 	bool "Enable support for the legacy image format"
boot/Makefile +3 -0
index 10f01572237..e50f3f91430 100644
@@ -37,6 +37,9 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootflow_menu.o
 obj-$(CONFIG_$(SPL_TPL_)CEDIT) += cedit.o
 endif
 
+obj-$(CONFIG_$(SPL_TPL_)UPL) += upl_common.o
+obj-$(CONFIG_$(SPL_TPL_)UPL_READ) += upl_read.o
+
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
 obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
 obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o
boot/upl_common.c new file +51 -0

51 lines not on this page · raw message

boot/upl_common.h new file +24 -0
new file mode 100644
index 00000000000..0f134c0393f
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * UPL handoff command functions
+ *
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#ifndef __UPL_COMMON_H
+#define __UPL_COMMON_H
+
+/* Names of bootmodes */
+extern const char *const bootmode_names[UPLBM_COUNT];
+
+/* Names of memory usages */
+extern const char *const usage_names[UPLUS_COUNT];
+
+/* Names of access types */
+extern const char *const access_types[UPLUS_COUNT];
+
+/* Names of graphics formats */
+extern const char *const graphics_formats[UPLUS_COUNT];
+
+#endif /* __UPL_COMMON_H */
boot/upl_read.c new file +607 -0

607 lines not on this page · raw message

configs/sandbox_defconfig +3 -3
index 0f01471367d..a51d2275ab5 100644
@@ -13,6 +13,7 @@ CONFIG_FIT=y
 CONFIG_FIT_RSASSA_PSS=y
 CONFIG_FIT_CIPHER=y
 CONFIG_FIT_VERBOSE=y
+CONFIG_UPL=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTSTAGE=y
@@ -144,7 +145,6 @@ CONFIG_IP_DEFRAG=y
 CONFIG_BOOTP_SERVERIP=y
 CONFIG_IPV6=y
 CONFIG_DM_DMA=y
-CONFIG_DEVRES=y
 CONFIG_DEBUG_DEVRES=y
 CONFIG_SIMPLE_PM_BUS=y
 CONFIG_ADC=y
@@ -183,6 +183,7 @@ CONFIG_DMA_CHANNELS=y
 CONFIG_SANDBOX_DMA=y
 CONFIG_FASTBOOT_FLASH=y
 CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_ARM_FFA_TRANSPORT=y
 CONFIG_GPIO_HOG=y
 CONFIG_DM_GPIO_LOOKUP_LABEL=y
 CONFIG_QCOM_PMIC_GPIO=y
@@ -230,8 +231,8 @@ CONFIG_MULTIPLEXER=y
 CONFIG_MUX_MMIO=y
 CONFIG_NVME_PCI=y
 CONFIG_PCI_REGION_MULTI_ENTRY=y
-CONFIG_PCI_SANDBOX=y
 CONFIG_PCI_FTPCI100=y
+CONFIG_PCI_SANDBOX=y
 CONFIG_PHY=y
 CONFIG_PHY_SANDBOX=y
 CONFIG_PINCTRL=y
@@ -346,4 +347,3 @@ CONFIG_TEST_FDTDEC=y
 CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
-CONFIG_ARM_FFA_TRANSPORT=y
include/upl.h new file +361 -0

361 lines not on this page · raw message

Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
#2 lore raw

RFC PATCH 2/9 upl: Add support for writing a upl handoff

In reply to Simon Glass

Universal Payload provides a standard way of handing off control between two firmware phases. Add support for writing the handoff information from a structure.

---

 boot/Kconfig     |   8 +
 boot/Makefile    |   1 +
 boot/upl_write.c | 623 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 632 insertions(+)
 create mode 100644 boot/upl_write.c
boot/Kconfig +8 -0
index e4625cc5fcb..d44684aaa04 100644
@@ -679,6 +679,7 @@ config BOOTMETH_SCRIPT
 config UPL
 	bool "upl - Universal Payload Specification"
 	imply UPL_READ
+	imply UPL_WRITE
 	help
 	  Provides support for UPL payloads and handoff information. U-Boot
 	  supports generating and accepting handoff information. The mkimage
@@ -693,6 +694,13 @@ config UPL_READ
 	  which can be used elsewhere in U-Boot. This is just the reading
 	  implementation, useful for trying it out.
 
+config UPL_WRITE
+	bool "upl - Support writing a Universal Payload handoff"
+	help
+	  Provides support for encoding a UPL-format payload from a C structure
+	  so it can be passed to another program. This is just the writing
+	  implementation, useful for trying it out.
+
 endif  # UPL
 
 endif  # BOOTSTD
boot/Makefile +1 -0
index e50f3f91430..45f06b43c30 100644
@@ -39,6 +39,7 @@ endif
 
 obj-$(CONFIG_$(SPL_TPL_)UPL) += upl_common.o
 obj-$(CONFIG_$(SPL_TPL_)UPL_READ) += upl_read.o
+obj-$(CONFIG_$(SPL_TPL_)UPL_WRITE) += upl_write.o
 
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
 obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
boot/upl_write.c new file +623 -0

623 lines not on this page · raw message

Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
#3 lore raw

RFC PATCH 3/9 upl: Add basic tests

In reply to Simon Glass

Add some unit tests to check that we can write a UPL handoff and read it back.

---

 test/boot/Makefile |   2 +
 test/boot/upl.c    | 420 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 422 insertions(+)
 create mode 100644 test/boot/upl.c
test/boot/Makefile +2 -0
index 52947580ae6..9f97223eed3 100644
@@ -12,3 +12,5 @@ ifdef CONFIG_OF_LIVE
 obj-$(CONFIG_BOOTMETH_VBE_SIMPLE) += vbe_simple.o
 endif
 obj-$(CONFIG_BOOTMETH_VBE) += vbe_fixup.o
+
+obj-$(CONFIG_UPL) += upl.o
test/boot/upl.c new file +420 -0

420 lines not on this page · raw message

Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
#4 lore raw

RFC PATCH 4/9 upl: Add a command

In reply to Simon Glass

Add a 'upl' command to work with Universal Payload features. For now it only supports reading and writing a handoff structure.

---

 boot/Kconfig                      |   1 +
 cmd/Kconfig                       |   7 ++
 cmd/Makefile                      |   1 +
 cmd/upl.c                         |  99 ++++++++++++++++++++
 doc/usage/cmd/upl.rst             | 149 ++++++++++++++++++++++++++++++
 doc/usage/index.rst               |   1 +
 include/asm-generic/global_data.h |  15 +++
 test/boot/upl.c                   |  37 ++++++++
 8 files changed, 310 insertions(+)
 create mode 100644 cmd/upl.c
 create mode 100644 doc/usage/cmd/upl.rst
boot/Kconfig +1 -0
index d44684aaa04..b8b1032ca63 100644
@@ -678,6 +678,7 @@ config BOOTMETH_SCRIPT
 
 config UPL
 	bool "upl - Universal Payload Specification"
+	imply CMD_UPL
 	imply UPL_READ
 	imply UPL_WRITE
 	help
cmd/Kconfig +7 -0
index 3f14923b5ef..105d2647b88 100644
@@ -351,6 +351,13 @@ config CMD_SEAMA
 	help
 	  Support reading NAND Seattle Image (SEAMA) images.
 
+config CMD_UPL
+	bool "upl - Universal Payload Specification"
+	help
+	  Provides commands to deal with  UPL payloads and handoff information.
+	  U-Boot supports generating and accepting handoff information. The
+	  mkimage tool will eventually support creating payloads.
+
 config CMD_VBE
 	bool "vbe - Verified Boot for Embedded"
 	depends on BOOTMETH_VBE
cmd/Makefile +1 -0
index 9bebf321c39..877eb0be9ef 100644
@@ -185,6 +185,7 @@ obj-$(CONFIG_CMD_UBIFS) += ubifs.o
 obj-$(CONFIG_CMD_UNIVERSE) += universe.o
 obj-$(CONFIG_CMD_UNLZ4) += unlz4.o
 obj-$(CONFIG_CMD_UNZIP) += unzip.o
+obj-$(CONFIG_CMD_UPL) += upl.o
 obj-$(CONFIG_CMD_VIRTIO) += virtio.o
 obj-$(CONFIG_CMD_WDT) += wdt.o
 obj-$(CONFIG_CMD_LZMADEC) += lzmadec.o
cmd/upl.c new file +99 -0

99 lines not on this page · raw message

doc/usage/cmd/upl.rst new file +149 -0

149 lines not on this page · raw message

doc/usage/index.rst +1 -0
index 3326ec82fff..ed896dfb3a0 100644
@@ -103,6 +103,7 @@ Shell commands
    cmd/tftpput
    cmd/trace
    cmd/true
+   cmd/upl
    cmd/ums
    cmd/unbind
    cmd/ut
include/asm-generic/global_data.h +15 -0
index b0485f3dd2a..86fabac12ef 100644
@@ -30,6 +30,7 @@
 
 struct acpi_ctx;
 struct driver_rt;
+struct upl;
 
 typedef struct global_data gd_t;
 
@@ -495,6 +496,12 @@ struct global_data {
 	 * @dmtag_list: List of DM tags
 	 */
 	struct list_head dmtag_list;
+#if CONFIG_IS_ENABLED(UPL)
+	/**
+	 * @upl: Universal Payload-handoff information
+	 */
+	struct upl *upl;
+#endif
 };
 #ifndef DO_DEPS_ONLY
 static_assert(sizeof(struct global_data) == GD_SIZE);
@@ -580,6 +587,14 @@ static_assert(sizeof(struct global_data) == GD_SIZE);
 #define gd_malloc_ptr()		0L
 #endif
 
+#if CONFIG_IS_ENABLED(UPL)
+#define gd_upl()		gd->upl
+#define gd_set_upl(_val)	gd->upl = (_val)
+#else
+#define gd_upl()		NULL
+#define gd_set_upl(val)
+#endif
+
 /**
  * enum gd_flags - global data flags
  *
test/boot/upl.c +37 -0
index 8319a93e057..e72027f4974 100644
@@ -418,3 +418,40 @@ static int upl_test_read_failure(struct unit_test_state *uts)
 	return 0;
 }
 BOOTSTD_TEST(upl_test_read_failure, 0);
+
+/* Test 'upl info' command */
+static int dm_test_upl_info(struct unit_test_state *uts)
+{
+	ut_assertok(run_command("upl info", 0));
+	ut_assert_nextline("UPL state: inactive");
+	ut_assert_console_end();
+
+	gd_set_upl((struct upl *)uts);	/* set it to any non-zero value */
+	ut_assertok(run_command("upl info", 0));
+	ut_assert_nextline("UPL state: active");
+	ut_assert_console_end();
+	gd_set_upl(NULL);
+
+	return 0;
+}
+BOOTSTD_TEST(dm_test_upl_info, UT_TESTF_CONSOLE_REC);
+
+/* Test 'upl read' and 'upl_write' commands */
+static int dm_test_upl_read_write(struct unit_test_state *uts)
+{
+	ulong addr;
+
+	ut_assertok(run_command("upl write", 0));
+
+	addr = env_get_hex("upladdr", 0);
+	ut_assert_nextline("UPL handoff written to %lx size %lx", addr,
+			   env_get_hex("uplsize", 0));
+	ut_assert_console_end();
+
+	ut_assertok(run_command("upl read ${upladdr}", 0));
+	ut_assert_nextline("Reading UPL at %lx", addr);
+	ut_assert_console_end();
+
+	return 0;
+}
+BOOTSTD_TEST(dm_test_upl_read_write, UT_TESTF_CONSOLE_REC);
Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
#5 lore raw

RFC PATCH 5/9 upl: Add support for Universal Payload in SPL

In reply to Simon Glass

Add the basic code to create a handoff structure in SPL, so it can be passed to the next phase. For now this is not plumbed in.

---

 boot/Kconfig         |  32 +++++++++
 common/spl/Makefile  |   2 +
 common/spl/spl_upl.c | 153 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 187 insertions(+)
 create mode 100644 common/spl/spl_upl.c
boot/Kconfig +32 -0
index b8b1032ca63..1cefa7d6873 100644
@@ -681,6 +681,7 @@ config UPL
 	imply CMD_UPL
 	imply UPL_READ
 	imply UPL_WRITE
+	imply SPL_UPL if SPL
 	help
 	  Provides support for UPL payloads and handoff information. U-Boot
 	  supports generating and accepting handoff information. The mkimage
@@ -697,11 +698,42 @@ config UPL_READ
 
 config UPL_WRITE
 	bool "upl - Support writing a Universal Payload handoff"
+	help
+	  Provides support for encoding a UPL-format payload from a C structure
+	  so it can be passed to another program. This is just the writing
+	  implementation, useful for trying it out. See SPL_UPL_OUT
+	  for how to tell U-Boot SPL to actually write it before jumping to
+	  the next phase.
+
+if SPL
+
+config SPL_UPL
+	bool "Write a UPL handoff in SPL"
+	imply SPL_UPL_OUT
+	help
+	  This tells SPL to write a UPL handoff and pass it to the next phase
+	  (e.g. to U-Boot or another program which SPL loads and runs). THis
+	  provides information to help that program run correctly and
+	  efficiently on the machine.
+
+config SPL_UPL_WRITE
+	bool  # upl - Support writing a Universal Payload handoff in SPL
+	select SPL_BLOBLIST
 	help
 	  Provides support for encoding a UPL-format payload from a C structure
 	  so it can be passed to another program. This is just the writing
 	  implementation, useful for trying it out.
 
+config SPL_UPL_OUT
+	bool "upl - Support writing a Universal Payload handoff in SPL"
+	select SPL_UPL_WRITE
+	help
+	  Provides support for encoding a UPL-format payload and passing it to
+	  the next firmware phase. This allows U-Boot SPL to function as
+	  Platform Init in the meaning of the specification.
+
+endif  # SPL
+
 endif  # UPL
 
 endif  # BOOTSTD
common/spl/Makefile +2 -0
index bad2bbf6cf1..8e34933230c 100644
@@ -36,3 +36,5 @@ obj-$(CONFIG_$(SPL_TPL_)SPI_LOAD) += spl_spi.o
 obj-$(CONFIG_$(SPL_TPL_)RAM_SUPPORT) += spl_ram.o
 obj-$(CONFIG_$(SPL_TPL_)USB_SDP_SUPPORT) += spl_sdp.o
 endif
+
+obj-$(CONFIG_$(SPL_TPL_)UPL) += spl_upl.o
common/spl/spl_upl.c new file +153 -0

153 lines not on this page · raw message

Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
#6 lore raw

RFC PATCH 6/9 spl: Plumb in the Universal Payload handoff

In reply to Simon Glass

Specify the FIT and include information about each loaded image, as required by the UPL handoff.

Write the UPL handoff into the bloblist before jumping to the next phase.

---

 common/spl/spl.c     |  6 ++++++
 common/spl/spl_fit.c | 22 ++++++++++++++++++++++
 include/spl.h        | 11 +++++++++++
 3 files changed, 39 insertions(+)
common/spl/spl.c +6 -0
index 0a9fea4f22d..1bfefaafd93 100644
@@ -792,6 +792,12 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 			printf(SPL_TPL_PROMPT
 			       "SPL hand-off write failed (err=%d)\n", ret);
 	}
+	if (CONFIG_IS_ENABLED(UPL_OUT)) {
+		ret = spl_write_upl_handoff(&spl_image);
+		if (ret)
+			printf(SPL_TPL_PROMPT
+			       "UPL hand-off write failed (err=%d)\n", ret);
+	}
 	if (CONFIG_IS_ENABLED(BLOBLIST)) {
 		ret = bloblist_finish();
 		if (ret)
common/spl/spl_fit.c +22 -0
index 03ff9a5db9a..89b5f624340 100644
@@ -13,6 +13,7 @@
 #include <memalign.h>
 #include <mapmem.h>
 #include <spl.h>
+#include <upl.h>
 #include <sysinfo.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
@@ -621,6 +622,8 @@ static int spl_fit_load_fpga(struct spl_fit_info *ctx,
 		printf("%s: Cannot load the FPGA: %i\n", __func__, ret);
 		return ret;
 	}
+	upl_add_image(node, fpga_image.load_addr, fpga_image.size,
+		      fdt_getprop(ctx->fit, node, FIT_DESC_PROP, NULL));
 
 	return spl_fit_upload_fpga(ctx, node, &fpga_image);
 }
@@ -745,6 +748,9 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 	if (ret)
 		return ret;
 
+	upl_add_image(node, spl_image->load_addr, spl_image->size,
+		      fdt_getprop(ctx.fit, node, FIT_DESC_PROP, NULL));
+
 	/*
 	 * For backward compatibility, we treat the first node that is
 	 * as a U-Boot image, if no OS-type has been declared.
@@ -788,6 +794,8 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 			       __func__, index, ret);
 			return ret;
 		}
+		upl_add_image(node, image_info.load_addr, image_info.size,
+			      fdt_getprop(ctx.fit, node, FIT_DESC_PROP, NULL));
 
 		if (spl_fit_image_is_fpga(ctx.fit, node))
 			spl_fit_upload_fpga(&ctx, node, &image_info);
@@ -824,6 +832,8 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 		spl_image->entry_point = spl_image->load_addr;
 
 	spl_image->flags |= SPL_FIT_FOUND;
+	upl_set_fit_info(map_to_sysmem(ctx.fit), ctx.conf_node,
+			 spl_image->entry_point);
 
 	return 0;
 }
@@ -868,6 +878,9 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 	if (ret < 0)
 		return ret;
 
+	upl_add_image(ret, fw_data, fw_len,
+		      fdt_getprop((void *)header, ret, FIT_DESC_PROP, NULL));
+
 	spl_image->size = fw_len;
 	spl_image->entry_point = fw_data;
 	spl_image->load_addr = fw_data;
@@ -887,6 +900,9 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 	if (ret >= 0) {
 		spl_image->fdt_addr = (void *)dt_data;
 
+		upl_add_image(ret, dt_data, dt_len,
+		      fdt_getprop((void *)header, ret, FIT_DESC_PROP, NULL));
+
 		if (spl_image->os == IH_OS_U_BOOT) {
 			/* HACK: U-Boot expects FDT at a specific address */
 			fdt_hack = spl_image->load_addr + spl_image->size;
@@ -916,7 +932,13 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 				     &img_data, &img_len);
 		if (ret < 0)
 			return ret;
+		upl_add_image(ret, img_data, img_len,
+		      fdt_getprop((void *)header, ret, FIT_DESC_PROP, NULL));
 	}
 
+	spl_image->flags |= SPL_FIT_FOUND;
+	upl_set_fit_info(map_to_sysmem(header), conf_noffset,
+			 spl_image->entry_point);
+
 	return 0;
 }
include/spl.h +11 -0
index e958ace2cc6..ed51e6c862d 100644
@@ -250,6 +250,9 @@ struct spl_image_info {
 	uintptr_t entry_point;
 #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
 	void *fdt_addr;
+#endif
+#if CONFIG_IS_ENABLED(UPL)
+	int conf_node;		/* FDT offset to selected configuration node */
 #endif
 	u32 boot_device;
 	u32 offset;
@@ -921,4 +924,12 @@ void spl_save_restore_data(void);
 int spl_load_fit_image(struct spl_image_info *spl_image,
 		       const struct legacy_img_hdr *header);
 
+/**
+ * spl_write_upl_handoff() - Write a Universal Payload hand-off structure
+ *
+ * @spl_image: Information about the image being booted
+ * Return: 0 if OK, -ve on error
+ */
+int spl_write_upl_handoff(struct spl_image_info *spl_image);
+
 #endif
Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
#7 lore raw

RFC PATCH 7/9 Plumb in universal payload to the init process

In reply to Simon Glass

Read the UPL early in boot so that it is available. For now none of the information is used.

---

 boot/Kconfig     | 12 +++++++++++-
 common/board_f.c | 22 ++++++++++++++++++++++
 common/board_r.c |  2 ++
 3 files changed, 35 insertions(+), 1 deletion(-)
boot/Kconfig +11 -1
index 1cefa7d6873..b4b78a8b5b5 100644
@@ -694,7 +694,9 @@ config UPL_READ
 	help
 	  Provides support for decoding a UPL-format payload into a C structure
 	  which can be used elsewhere in U-Boot. This is just the reading
-	  implementation, useful for trying it out.
+	  implementation, useful for trying it out. See UPL_IN for how
+	  to tell U-Boot to actually read it on startup and use it for memory
+	  and device information, etc.
 
 config UPL_WRITE
 	bool "upl - Support writing a Universal Payload handoff"
@@ -705,6 +707,14 @@ config UPL_WRITE
 	  for how to tell U-Boot SPL to actually write it before jumping to
 	  the next phase.
 
+config UPL_IN
+	bool "upl - Read the UPL handoff on startup"
+	select UPL_READ
+	help
+	  Read an SPL handoff when U-Boot starts and use it to provide
+	  devices, memory layout, etc. required by U-Boot. This allows U-Boot
+	  to function as a payload in the meaning of the specification.
+
 if SPL
 
 config SPL_UPL
common/board_f.c +22 -0
index 76ae415487d..716025601c5 100644
@@ -40,6 +40,7 @@
 #include <sysreset.h>
 #include <timer.h>
 #include <trace.h>
+#include <upl.h>
 #include <video.h>
 #include <watchdog.h>
 #include <asm/cache.h>
@@ -841,6 +842,26 @@ static int misc_init_f(void)
 	return event_notify_null(EVT_MISC_INIT_F);
 }
 
+static int initf_upl(void)
+{
+	struct upl *upl;
+	int ret;
+
+	if (!IS_ENABLED(CONFIG_UPL_IN))
+		return 0;
+
+	upl = malloc(sizeof(struct upl));
+	if (upl)
+		ret = upl_read_handoff(upl, oftree_default());
+	if (ret) {
+		printf("UPL handoff: read failure (err=%dE)\n", ret);
+		return ret;
+	}
+	gd_set_upl(upl);
+
+	return 0;
+}
+
 static const init_fnc_t init_sequence_f[] = {
 	setup_mon_len,
 #ifdef CONFIG_OF_CONTROL
@@ -850,6 +871,7 @@ static const init_fnc_t init_sequence_f[] = {
 	trace_early_init,
 #endif
 	initf_malloc,
+	initf_upl,
 	log_init,
 	initf_bootstage,	/* uses its own timer, so does not need DM */
 	event_init,
common/board_r.c +2 -0
index 598155c7753..1c1f139430b 100644
@@ -549,6 +549,8 @@ static int dm_announce(void)
 		       uclass_count);
 		if (CONFIG_IS_ENABLED(OF_REAL))
 			printf(", devicetree: %s", fdtdec_get_srcname());
+		if (CONFIG_IS_ENABLED(UPL))
+			printf(", universal payload active");
 		printf("\n");
 		if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE) &&
 		    (gd->fdt_src == FDTSRC_SEPARATE ||
Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
#8 lore raw

RFC PATCH 8/9 sandbox_vpl: Enable Universal Payload

In reply to Simon Glass

Use the sandbox_vpl build to test UPL since it supports a real devicetree in SPL. The sandbox_spl build uses OF_PLATDATA.

Enable writing the UPL handoff in SPL and reading it in U-Boot proper. Provide a test to check that this handoff works.

Note that the test uses the standard devicetree rather than the test one, since it is a lot smaller and fits in the existing bloblist.

---

 configs/sandbox_vpl_defconfig |  4 ++++
 test/py/tests/test_upl.py     | 25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
 create mode 100644 test/py/tests/test_upl.py
configs/sandbox_vpl_defconfig +4 -0
index 27354b8b5ed..598ec9620b0 100644
@@ -27,6 +27,9 @@ CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_FIT_BEST_MATCH=y
 CONFIG_SPL_LOAD_FIT=y
+CONFIG_UPL=y
+CONFIG_UPL_IN=y
+CONFIG_SPL_UPL_OUT=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
@@ -36,6 +39,7 @@ CONFIG_BOOTSTAGE_STASH_SIZE=0x4096
 CONFIG_CONSOLE_RECORD=y
 CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
 CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_BLOBLIST_SIZE=0x5000
 CONFIG_SPL_NO_BSS_LIMIT=y
 CONFIG_HANDOFF=y
 CONFIG_SPL_BOARD_INIT=y
test/py/tests/test_upl.py new file +25 -0
new file mode 100644
index 00000000000..0b24053e222
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2023 Google LLC
+#
+# Test addition of Universal Payload
+
+import os
+
+import pytest
+import u_boot_utils
+
[email protected]('sandbox_vpl')
+def test_upl_handoff(u_boot_console):
+    cons = u_boot_console
+    ram = os.path.join(cons.config.build_dir, 'ram.bin')
+    fdt = os.path.join(cons.config.build_dir, 'u-boot.dtb')
+
+    # Remove any existing RAM file, so we don't have old data present
+    if os.path.exists(ram):
+        os.remove(ram)
+    flags = ['-m', ram, '-d', fdt]
+    cons.restart_uboot_with_flags(flags, use_dtb=False)
+
+    # Make sure that Universal Payload is detected in U-Boot proper
+    output = cons.run_command('upl info')
+    assert output == 'UPL state: active'
Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
#9 lore raw

RFC PATCH 9/9 upl: Add initial documentation

In reply to Simon Glass

Add some placeholder documentation to explain the basic concept. Once the spec is published, more can be added and this series applied.

---

 doc/usage/index.rst |  1 +
 doc/usage/upl.rst   | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 doc/usage/upl.rst
doc/usage/index.rst +1 -0
index ed896dfb3a0..78665fd5759 100644
@@ -13,6 +13,7 @@ Use U-Boot
    partitions
    cmdline
    semihosting
+   upl
 
 Shell commands
 --------------
doc/usage/upl.rst new file +27 -0
new file mode 100644
index 00000000000..2ae4d4a1178
@@ -0,0 +1,27 @@
+Universal Payload
+~~~~~~~~~~~~~~~~~
+
+Universal Payload (UPL) is an upcoming Industry Standard for firmware
+components. UPL is designed to improve interoperability within the firmware
+industry, allowing mixing and matching of projects with less friction and fewer
+project-specific implementations. UPL is cross-platform, supporting ARM, x86 and
+RISC-V initially.
+
+UPL is defined in termns of two firmware components:
+
+`Platform Init`
+	Perhaps initial setup of the hardware and jumps to the payload.
+
+`Payload`
+	Selects the OS to boot
+
+In practice UPL can be used to handle any number of handoffs through the
+firmware startup process, with one program acting as platform init and another
+acting as the payload.
+
+UPL provides a standard for three main pieces:
+
+- file format for the payload, which may comprise multiple images to load
+- handoff format for the information the payload needs, such as serial port,
+  memory layout, etc.
+- machine state and register settings at the point of handoff
Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
#10 lore raw

Re: [RFC PATCH 9/9] upl: Add initial documentation

Am 31. August 2023 01:29:23 MESZ schrieb Simon Glass <[email protected]>:

Quoted 29 lines

Add some placeholder documentation to explain the basic concept. Once the spec is published, more can be added and this series applied.

---

doc/usage/index.rst | 1 +
doc/usage/upl.rst | 27 +++++++++++++++++++++++++++

2 files changed, 28 insertions(+)

create mode 100644 doc/usage/upl.rst

doc/usage/index.rst +1 -0
index ed896dfb3a0..78665fd5759 100644
@@ -13,6 +13,7 @@ Use U-Boot
   partitions
   cmdline
   semihosting
+   upl
 

Shell commands
--------------

doc/usage/upl.rst new file +0 -0
new file mode 100644
index 00000000000..2ae4d4a1178

doc/usage/upl.rst line 8

Quoted 8 lines
doc/usage/upl.rst new file +8 -0
@@ -0,0 +1,27 @@
+Universal Payload
+~~~~~~~~~~~~~~~~~
+
+Universal Payload (UPL) is an upcoming Industry Standard for firmware
+components. UPL is designed to improve interoperability within the firmware
+industry, allowing mixing and matching of projects with less friction and fewer
+project-specific implementations. UPL is cross-platform, supporting ARM, x86 and
+RISC-V initially.

Please, provide a link to the specification.

doc/usage/upl.rst line 10

Quoted 2 lines
doc/usage/upl.rst new file +2 -0
+
+UPL is defined in termns of two firmware components:

terms

doc/usage/upl.rst line 13

Quoted 3 lines
doc/usage/upl.rst new file +3 -0
+
+`Platform Init`
+	Perhaps initial setup of the hardware and jumps to the payload.

%s/Perhaps/Possible/

doc/usage/upl.rst line 16

Quoted 3 lines
doc/usage/upl.rst new file +3 -0
+
+`Payload`
+	Selects the OS to boot

IIRC the UPL payload typically is not the OS but other firmware or a boot loader.

Best regards

Heinrich

Quoted 11 lines
doc/usage/upl.rst new file +11 -0
+
+In practice UPL can be used to handle any number of handoffs through the
+firmware startup process, with one program acting as platform init and another
+acting as the payload.
+
+UPL provides a standard for three main pieces:
+
+- file format for the payload, which may comprise multiple images to load
+- handoff format for the information the payload needs, such as serial port,
+  memory layout, etc.
+- machine state and register settings at the point of handoff