Skip to contentSkip to conversation

Universal Payload initial series

PATCH Superseded Simon Glass 2 participants 23 messages Jul 21, 2024 – Aug 7, 2024

Subsystems (5)
USB Block layer Kbuild Library code +1 more subsystems

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Universal Payload initial series

Universal Payload (UPL) is an Industry Standard for firmware components[1]. 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, targeting 0.9.1 and sandbox only.

Features still to come include:
- Support for architectures
- FIT validation
- Handoff validation
- Interoperability tests

This series is available at dm/uplb-working and requires the alist series at dm/alist-working[2]

[1] https://universalpayload.github.io/spec/
[2] https://patchwork.ozlabs.org/project/uboot/list/?series=414642

Changes in v3:
- Use longer error messages
- Use -errno instead of inventing a new error
- Use sizeof(*header) instead of 512
- Use a block size of 1 if !CONFIG_SPL_LOAD_BLOCK
- Fix 'handed' typo
- Rebase on earlier change
- Allow up.h to be built by the host build
- Split out into its own commit

Changes in v2:
- Put the upl tests under their own subcommand to avoid bootstd init
- Add a function to init the UPL process in SPL
- Hang when something goes wrong, to avoid a broken boot
- Add a runtime flag to enable UPL
- Put upl_image() calls in a common place
- Add a link to the spec
- Add a link to the command
- Support CI testing
- Rework to use alist instead of fixed-length arrays

Simon Glass (21):
sandbox: Use const in os_jump_to_file()
sandbox: Fix a comment in os_find_u_boot()
test: Move some SPL-loading test-code into sandbox common
fdt: Don't overwrite bloblist devicetree
sandbox: fdt: Avoid overwriting an existing fdt
sandbox: Return error code from read/write/seek
sandbox: Add ELF file to VPL u-boot.img
sandbox: Set up global_data earlier
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: Set SPL_FIT_FOUND for full FIT also
spl: Plumb in the Universal Payload handoff
upl: Plumb in universal payload to the init process
sandbox_vpl: Enable Universal Payload
upl: Add initial documentation
sandbox: Add a flag to enable UPL
sandbox: Add an SPL loader for UPL
upl: Add an end-to-end test

 MAINTAINERS                       |  13 +
 Makefile                          |   4 +-
 arch/sandbox/cpu/cpu.c            |   2 +
 arch/sandbox/cpu/os.c             |  30 +-
 arch/sandbox/cpu/spl.c            | 120 +++++-
 arch/sandbox/cpu/start.c          |  18 +-
 arch/sandbox/include/asm/spl.h    |  15 +
 arch/sandbox/include/asm/state.h  |   1 +
 boot/Kconfig                      |  70 ++++
 boot/Makefile                     |   4 +
 boot/image-fit.c                  |   4 +
 boot/upl_common.c                 |  60 +++
 boot/upl_common.h                 |  24 ++
 boot/upl_read.c                   | 588 ++++++++++++++++++++++++++++
 boot/upl_write.c                  | 622 ++++++++++++++++++++++++++++++
 cmd/Kconfig                       |   7 +
 cmd/Makefile                      |   1 +
 cmd/upl.c                         | 118 ++++++
 common/board_f.c                  |  22 ++
 common/board_r.c                  |   2 +
 common/spl/Makefile               |   2 +
 common/spl/spl.c                  |   8 +
 common/spl/spl_fit.c              |  10 +
 common/spl/spl_upl.c              | 171 ++++++++
 configs/sandbox_defconfig         |   1 +
 configs/sandbox_vpl_defconfig     |   4 +
 doc/usage/cmd/upl.rst             | 186 +++++++++
 doc/usage/index.rst               |   2 +
 doc/usage/upl.rst                 |  46 +++
 drivers/block/sandbox.c           |   4 +-
 drivers/usb/emul/sandbox_flash.c  |   2 +-
 fs/sandbox/sandboxfs.c            |   6 +-
 include/asm-generic/global_data.h |  19 +
 include/os.h                      |   6 +-
 include/spl.h                     |  16 +
 include/test/suites.h             |   1 +
 include/upl.h                     | 364 +++++++++++++++++
 lib/fdtdec.c                      |   1 +
 test/boot/Makefile                |   2 +
 test/boot/upl.c                   | 437 +++++++++++++++++++++
 test/cmd_ut.c                     |   3 +
 test/image/spl_load_os.c          |  53 +--
 test/py/tests/test_upl.py         |  38 ++
 43 files changed, 3035 insertions(+), 72 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.34.1
#1 lore raw

PATCH v3 1/21 sandbox: Use const in os_jump_to_file()

The argument array is not changed by the callee, so mark it const.

---

(no changes since v1)

 arch/sandbox/cpu/os.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/sandbox/cpu/os.c +2 -2
index 46ff305b536..a04eb5aa18c 100644
@@ -808,7 +808,7 @@ static int make_exec(char *fname, const void *data, int size)
  * @count: Number of arguments in @add_args
  * Return: 0 if OK, -ENOMEM if out of memory
  */
-static int add_args(char ***argvp, char *add_args[], int count)
+static int add_args(char ***argvp, const char *add_args[], int count)
 {
 	char **argv, **ap;
 	int argc;
@@ -859,7 +859,7 @@ static int os_jump_to_file(const char *fname, bool delete_it)
 	struct sandbox_state *state = state_get_current();
 	char mem_fname[30];
 	int fd, err;
-	char *extra_args[5];
+	const char *extra_args[5];
 	char **argv = state->argv;
 	int argc;
 #ifdef DEBUG
Signature · 1 line
2.34.1
#2 lore raw

PATCH v3 2/21 sandbox: Fix a comment in os_find_u_boot()

In reply to Simon Glass

Fix a missing dot in a comment, since '..' is confusing.

---

(no changes since v1)

 arch/sandbox/cpu/os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sandbox/cpu/os.c +1 -1
index a04eb5aa18c..da96ebe43c9 100644
@@ -964,7 +964,7 @@ int os_find_u_boot(char *fname, int maxlen, bool use_img,
 	p = strstr(fname, subdir);
 	if (p) {
 		if (*next_prefix)
-			/* e.g. ".../tpl/u-boot-spl"  to "../spl/u-boot-spl" */
+			/* e.g. ".../tpl/u-boot-spl"  to ".../spl/u-boot-spl" */
 			memcpy(p + 1, next_prefix, strlen(next_prefix));
 		else
 			/* e.g. ".../spl/u-boot" to ".../u-boot" */
Signature · 1 line
2.34.1
#3 lore raw

PATCH v3 3/21 test: Move some SPL-loading test-code into sandbox common

In reply to Simon Glass

This code is useful for loading an image in sandbox_spl so move it into a place where it can be called as needed.

---

Changes in v3:
- Use longer error messages
- Use -errno instead of inventing a new error
- Use sizeof(*header) instead of 512
- Use a block size of 1 if !CONFIG_SPL_LOAD_BLOCK

 arch/sandbox/cpu/spl.c         | 73 ++++++++++++++++++++++++++++++++++
 arch/sandbox/include/asm/spl.h | 14 +++++++
 test/image/spl_load_os.c       | 53 +-----------------------
 3 files changed, 88 insertions(+), 52 deletions(-)
arch/sandbox/cpu/spl.c +73 -0
index 9ad9da686c6..49abe02f322 100644
@@ -6,6 +6,7 @@
 #include <dm.h>
 #include <hang.h>
 #include <handoff.h>
+#include <image.h>
 #include <init.h>
 #include <log.h>
 #include <os.h>
@@ -179,3 +180,75 @@ int handoff_arch_save(struct spl_handoff *ho)
 
 	return 0;
 }
+
+/* Context used to hold file descriptor */
+struct load_ctx {
+	int fd;
+};
+
+static ulong read_fit_image(struct spl_load_info *load, ulong offset,
+			    ulong size, void *buf)
+{
+	struct load_ctx *load_ctx = load->priv;
+	off_t ret;
+	ssize_t res;
+
+	ret = os_lseek(load_ctx->fd, offset, OS_SEEK_SET);
+	if (ret < 0) {
+		printf("Failed to seek to %zx, got %zx (errno=%d)\n", offset,
+		       ret, errno);
+		return log_msg_ret("lse", -errno);
+	}
+
+	res = os_read(load_ctx->fd, buf, size);
+	if (res < 0) {
+		printf("Failed to read %lx bytes, got %ld (errno=%d)\n",
+		       size, res, errno);
+		return log_msg_ret("osr", -errno);
+	}
+
+	return size;
+}
+
+int sandbox_spl_load_fit(char *fname, int maxlen, struct spl_image_info *image)
+{
+	struct legacy_img_hdr *header;
+	struct load_ctx load_ctx;
+	struct spl_load_info load;
+	int ret;
+	int fd;
+
+	memset(&load, '\0', sizeof(load));
+	spl_set_bl_len(&load, IS_ENABLED(CONFIG_SPL_LOAD_BLOCK) ? 512 : 1);
+	load.read = read_fit_image;
+
+	ret = sandbox_find_next_phase(fname, maxlen, true);
+	if (ret) {
+		printf("%s not found, error %d\n", fname, ret);
+		return log_msg_ret("nph", ret);
+	}
+
+	header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
+
+	log_debug("reading from %s\n", fname);
+	fd = os_open(fname, OS_O_RDONLY);
+	if (fd < 0) {
+		printf("Failed to open '%s'\n", fname);
+		return log_msg_ret("ope", -errno);
+	}
+	ret = os_read(fd, header, sizeof(*header));
+	if (ret != sizeof(*header)) {
+		printf("Failed to read %lx bytes, got %ld (errno=%d)\n",
+		       sizeof(*header), ret, -errno);
+		return log_msg_ret("rea", -errno);
+	}
+	load_ctx.fd = fd;
+
+	load.priv = &load_ctx;
+
+	ret = spl_load_simple_fit(image, &load, 0, header);
+	if (ret)
+		return log_msg_ret("slf", ret);
+
+	return 0;
+}
arch/sandbox/include/asm/spl.h +14 -0
index 4fab24cd156..d50d9ad6b48 100644
@@ -6,6 +6,8 @@
 #ifndef __asm_spl_h
 #define __asm_spl_h
 
+struct spl_image_info;
+
 enum {
 	BOOT_DEVICE_MMC1,
 	BOOT_DEVICE_MMC2,
@@ -31,4 +33,16 @@ enum {
  */
 int sandbox_find_next_phase(char *fname, int maxlen, bool use_img);
 
+/**
+ * sandbox_spl_load_fit() - Load the next phase from a FIT
+ *
+ * Loads a FIT containing the next phase and sets it up for booting
+ *
+ * @fname: Returns filename loaded
+ * @maxlen: Maximum length for @fname including \0
+ * @image: Place to put SPL-image information
+ * Return: 0 if OK, -ve on error
+ */
+int sandbox_spl_load_fit(char *fname, int maxlen, struct spl_image_info *image);
+
 #endif
test/image/spl_load_os.c +1 -52

64 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

PATCH v3 4/21 fdt: Don't overwrite bloblist devicetree

In reply to Simon Glass

When the devicetree comes from a bloblist, it is currently overwritten by the appended one, if present. It should be preserved.

Adjust the logic to support this.

Fixes 70fe2385943 ("fdt: Allow the devicetree to come from a bloblist")

---

(no changes since v1)

 lib/fdtdec.c | 1 +
 1 file changed, 1 insertion(+)
lib/fdtdec.c +1 -0
index 5b3b26df968..01048b19737 100644
@@ -1677,6 +1677,7 @@ int fdtdec_setup(void)
 				gd->fdt_src = FDTSRC_BLOBLIST;
 				log_debug("Devicetree is in bloblist at %p\n",
 					  gd->fdt_blob);
+				ret = 0;
 			} else {
 				log_debug("No FDT found in bloblist\n");
 				ret = -ENOENT;
Signature · 1 line
2.34.1
#5 lore raw

PATCH v3 5/21 sandbox: fdt: Avoid overwriting an existing fdt

In reply to Simon Glass

Since the removal of OF_HOSTFILE logic in board_fdt_blob_setup(), the logic for obtaining the DT is handled in the OF_BOARD option. If a devicetree comes from a bloblist it is immediately overwritten by this function.

Fix this by skipping the function if a devicetree is already present.

This is sort-of a fix for e7fb7896 ("sandbox: Remove OF_HOSTFILE") but it has only come to light since bloblist was added, so I have not added a Fixes tag.

Unfortunately it is not possible to report the correct FDT source with the current code. It might be best to use an error-return code for board_fdt_blob_setup() so that an error can be reported if the board does not provide the DT.

---

Changes in v3:
- Fix 'handed' typo

 arch/sandbox/cpu/cpu.c | 2 ++
 1 file changed, 2 insertions(+)
arch/sandbox/cpu/cpu.c +2 -0
index 0ed85b354cf..4f15a560902 100644
@@ -340,6 +340,8 @@ void *board_fdt_blob_setup(int *ret)
 	int err;
 	int fd;
 
+	if (gd->fdt_blob)
+		return (void *)gd->fdt_blob;
 	blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0);
 	*ret = 0;
 	if (!state->fdt_fname) {
Signature · 1 line
2.34.1
#6 lore raw

PATCH v3 6/21 sandbox: Return error code from read/write/seek

In reply to Simon Glass

The existing API for these functions is different from the rest of U-Boot, in that any error code must be obtained from the errno variable on failure. This variable is part of the C library, so accessing it outside of the special 'sandbox' shim-functions is not ideal.

Adjust the API to return an error code, to avoid this. Update existing uses to check for any negative value, rather than just -1.

---

Changes in v3:
- Rebase on earlier change

 arch/sandbox/cpu/os.c            | 24 +++++++++++++++++++++---
 arch/sandbox/cpu/spl.c           | 16 +++++++---------
 drivers/block/sandbox.c          |  4 ++--
 drivers/usb/emul/sandbox_flash.c |  2 +-
 fs/sandbox/sandboxfs.c           |  6 +++---
 include/os.h                     |  6 +++---
 6 files changed, 37 insertions(+), 21 deletions(-)
arch/sandbox/cpu/os.c +21 -3
index da96ebe43c9..f5c9a8aecf2 100644
@@ -47,12 +47,24 @@ struct os_mem_hdr {
 
 ssize_t os_read(int fd, void *buf, size_t count)
 {
-	return read(fd, buf, count);
+	ssize_t ret;
+
+	ret = read(fd, buf, count);
+	if (ret == -1)
+		return -errno;
+
+	return ret;
 }
 
 ssize_t os_write(int fd, const void *buf, size_t count)
 {
-	return write(fd, buf, count);
+	ssize_t ret;
+
+	ret = write(fd, buf, count);
+	if (ret == -1)
+		return -errno;
+
+	return ret;
 }
 
 int os_printf(const char *fmt, ...)
@@ -69,6 +81,8 @@ int os_printf(const char *fmt, ...)
 
 off_t os_lseek(int fd, off_t offset, int whence)
 {
+	off_t ret;
+
 	if (whence == OS_SEEK_SET)
 		whence = SEEK_SET;
 	else if (whence == OS_SEEK_CUR)
@@ -77,7 +91,11 @@ off_t os_lseek(int fd, off_t offset, int whence)
 		whence = SEEK_END;
 	else
 		os_exit(1);
-	return lseek(fd, offset, whence);
+	ret = lseek(fd, offset, whence);
+	if (ret == -1)
+		return -errno;
+
+	return ret;
 }
 
 int os_open(const char *pathname, int os_flags)
arch/sandbox/cpu/spl.c +7 -9
index 49abe02f322..e86193de419 100644
@@ -195,16 +195,14 @@ static ulong read_fit_image(struct spl_load_info *load, ulong offset,
 
 	ret = os_lseek(load_ctx->fd, offset, OS_SEEK_SET);
 	if (ret < 0) {
-		printf("Failed to seek to %zx, got %zx (errno=%d)\n", offset,
-		       ret, errno);
-		return log_msg_ret("lse", -errno);
+		printf("Failed to seek to %zx, got %zx\n", offset, ret);
+		return log_msg_ret("lse", ret);
 	}
 
 	res = os_read(load_ctx->fd, buf, size);
 	if (res < 0) {
-		printf("Failed to read %lx bytes, got %ld (errno=%d)\n",
-		       size, res, errno);
-		return log_msg_ret("osr", -errno);
+		printf("Failed to read %lx bytes, got %ld\n", size, res);
+		return log_msg_ret("osr", res);
 	}
 
 	return size;
@@ -238,9 +236,9 @@ int sandbox_spl_load_fit(char *fname, int maxlen, struct spl_image_info *image)
 	}
 	ret = os_read(fd, header, sizeof(*header));
 	if (ret != sizeof(*header)) {
-		printf("Failed to read %lx bytes, got %ld (errno=%d)\n",
-		       sizeof(*header), ret, -errno);
-		return log_msg_ret("rea", -errno);
+		printf("Failed to read %lx bytes, got %d\n", sizeof(*header),
+		       ret);
+		return log_msg_ret("rea", ret);
 	}
 	load_ctx.fd = fd;
 
drivers/block/sandbox.c +2 -2
index ec34f1ad8c2..6c74d66037e 100644
@@ -25,7 +25,7 @@ static unsigned long host_block_read(struct udevice *dev,
 	struct udevice *host_dev = dev_get_parent(dev);
 	struct host_sb_plat *plat = dev_get_plat(host_dev);
 
-	if (os_lseek(plat->fd, start * desc->blksz, OS_SEEK_SET) == -1) {
+	if (os_lseek(plat->fd, start * desc->blksz, OS_SEEK_SET) < 0) {
 		printf("ERROR: Invalid block %lx\n", start);
 		return -1;
 	}
@@ -44,7 +44,7 @@ static unsigned long host_block_write(struct udevice *dev,
 	struct udevice *host_dev = dev_get_parent(dev);
 	struct host_sb_plat *plat = dev_get_plat(host_dev);
 
-	if (os_lseek(plat->fd, start * desc->blksz, OS_SEEK_SET) == -1) {
+	if (os_lseek(plat->fd, start * desc->blksz, OS_SEEK_SET) < 0) {
 		printf("ERROR: Invalid block %lx\n", start);
 		return -1;
 	}
drivers/usb/emul/sandbox_flash.c +1 -1
index 24420e3d51e..b5176bb30ce 100644
@@ -196,7 +196,7 @@ static int handle_ufi_command(struct sandbox_flash_priv *priv, const void *buff,
 		   priv->fd != -1) {
 		offset = os_lseek(priv->fd, info->seek_block * info->block_size,
 				  OS_SEEK_SET);
-		if (offset == (off_t)-1)
+		if (offset < 0)
 			setup_fail_response(priv);
 		else
 			setup_response(priv);
fs/sandbox/sandboxfs.c +3 -3
index 773b583fa43..76f1a71f412 100644
@@ -28,7 +28,7 @@ int sandbox_fs_read_at(const char *filename, loff_t pos, void *buffer,
 	if (fd < 0)
 		return fd;
 	ret = os_lseek(fd, pos, OS_SEEK_SET);
-	if (ret == -1) {
+	if (ret < 0) {
 		os_close(fd);
 		return ret;
 	}
@@ -65,14 +65,14 @@ int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer,
 	if (fd < 0)
 		return fd;
 	ret = os_lseek(fd, pos, OS_SEEK_SET);
-	if (ret == -1) {
+	if (ret < 0) {
 		os_close(fd);
 		return ret;
 	}
 	size = os_write(fd, buffer, towrite);
 	os_close(fd);
 
-	if (size == -1) {
+	if (size < 0) {
 		ret = -1;
 	} else {
 		ret = 0;
include/os.h +3 -3
index 877404a6c13..4371270a1ee 100644
@@ -29,7 +29,7 @@ int os_printf(const char *format, ...);
  * @fd:		File descriptor as returned by os_open()
  * @buf:	Buffer to place data
  * @count:	Number of bytes to read
- * Return:	number of bytes read, or -1 on error
+ * Return:	number of bytes read, or -errno on error
  */
 ssize_t os_read(int fd, void *buf, size_t count);
 
@@ -39,7 +39,7 @@ ssize_t os_read(int fd, void *buf, size_t count);
  * @fd:		File descriptor as returned by os_open()
  * @buf:	Buffer containing data to write
  * @count:	Number of bytes to write
- * Return:	number of bytes written, or -1 on error
+ * Return:	number of bytes written, or -errno on error
  */
 ssize_t os_write(int fd, const void *buf, size_t count);
 
@@ -49,7 +49,7 @@ ssize_t os_write(int fd, const void *buf, size_t count);
  * @fd:		File descriptor as returned by os_open()
  * @offset:	File offset (based on whence)
  * @whence:	Position offset is relative to (see below)
- * Return:	new file offset
+ * Return:	new file offset, or -errno on error
  */
 off_t os_lseek(int fd, off_t offset, int whence);
 
Signature · 1 line
2.34.1
#7 lore raw

PATCH v3 7/21 sandbox: Add ELF file to VPL u-boot.img

In reply to Simon Glass

At present sandbox builds package up u-boot.bin in the .img file. This cannot actually be executed, since it is not an ELF file.

For sandbox_vpl we want to be able to run the full boot flow.

Adjust the build rule for sandbox_vpl to package the ELF file and thereby allow full testing of the sandbox transition from SPL to U-Boot proper.

---

(no changes since v1)

 Makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Makefile +3 -1
index f5b2512f369..f364cd31ade 100644
@@ -1470,8 +1470,10 @@ u-boot.bin.lzma: u-boot.bin FORCE
 u-boot-lzma.img: u-boot.bin.lzma FORCE
 	$(call if_changed,mkimage)
 
+fit_image := $(if $(CONFIG_SANDBOX_VPL),u-boot,u-boot-nodtb.bin)
+
 u-boot-dtb.img u-boot.img u-boot.kwb u-boot.pbl u-boot-ivt.img: \
-		$(if $(CONFIG_SPL_LOAD_FIT),u-boot-nodtb.bin \
+		$(if $(CONFIG_SPL_LOAD_FIT),$(fit_image) \
 			$(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SANDBOX),dts/dt.dtb) \
 		,$(UBOOT_BIN)) FORCE
 	$(call if_changed,mkimage)
Signature · 1 line
2.34.1
#8 lore raw

PATCH v3 8/21 sandbox: Set up global_data earlier

In reply to Simon Glass

It is possible for U-Boot functions such as printf() to be called within state_init(). This can end up checking gd->flags (e.g. in putc()) before global_data is set up.

Move the setup earlier to avoid this. This fixes the suppression of some debug output in memory allocation (when enabled).

---

(no changes since v1)

 arch/sandbox/cpu/start.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/sandbox/cpu/start.c +3 -2
index dce80416529..0920ed55965 100644
@@ -483,6 +483,9 @@ int sandbox_main(int argc, char *argv[])
 
 	text_base = os_find_text_base();
 
+	memset(&data, '\0', sizeof(data));
+	gd = &data;
+
 	/*
 	 * This must be the first invocation of os_malloc() to have
 	 * state->ram_buf in the low 4 GiB.
@@ -501,8 +504,6 @@ int sandbox_main(int argc, char *argv[])
 		os_exit(1);
 	memcpy(os_argv, argv, size);
 
-	memset(&data, '\0', sizeof(data));
-	gd = &data;
 	gd->arch.text_base = text_base;
 
 	state = state_get_current();
Signature · 1 line
2.34.1
#9 lore raw

PATCH v3 9/21 upl: Add support for reading 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 reading the handoff information into a structure.

---

Changes in v3:
- Allow up.h to be built by the host build

 MAINTAINERS               |   7 +
 boot/Kconfig              |  19 ++
 boot/Makefile             |   3 +
 boot/upl_common.c         |  60 ++++
 boot/upl_common.h         |  24 ++
 boot/upl_read.c           | 588 ++++++++++++++++++++++++++++++++++++++
 configs/sandbox_defconfig |   1 +
 include/upl.h             | 355 +++++++++++++++++++++++
 8 files changed, 1057 insertions(+)
 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
MAINTAINERS +7 -0
index a6e47e8a217..070a766a76f 100644
@@ -1701,6 +1701,13 @@ M:	Neha Malcom Francis <[email protected]>
 S:	Maintained
 F:	drivers/ufs/
 
+UPL
+M:	Simon Glass <[email protected]>
+S:	Maintained
+T:	git https://source.denx.de/u-boot/custodians/u-boot-dm.git
+F:	boot/upl*
+F:	include/upl.h
+
 USB
 M:	Marek Vasut <[email protected]>
 S:	Maintained
boot/Kconfig +19 -0
index def483a41f1..6e907b45095 100644
@@ -736,6 +736,25 @@ 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.
 
+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
boot/Makefile +3 -0
index 75d1cd46fab..97b52a3404c 100644
@@ -43,6 +43,9 @@ endif
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += fdt_support.o
 obj-$(CONFIG_$(SPL_TPL_)FDT_SIMPLEFB) += fdt_simplefb.o
 
+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 +60 -0

60 lines not on this page · raw message

boot/upl_common.h new file +24 -0
new file mode 100644
index 00000000000..cc517dc1de9
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * UPL handoff command functions
+ *
+ * Copyright 2024 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 +588 -0

588 lines not on this page · raw message

configs/sandbox_defconfig +1 -0
index dc5fcdbd1c9..484f9e1bf8d 100644
@@ -16,6 +16,7 @@ CONFIG_FIT_RSASSA_PSS=y
 CONFIG_FIT_CIPHER=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_BOOTMETH_ANDROID=y
+CONFIG_UPL=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_MEASURED_BOOT=y
 CONFIG_BOOTSTAGE=y
include/upl.h new file +355 -0

355 lines not on this page · raw message

Signature · 1 line
2.34.1
#10 lore raw

PATCH v3 10/21 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.

---

(no changes since v1)

 boot/Kconfig     |   8 +
 boot/Makefile    |   1 +
 boot/upl_write.c | 622 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 631 insertions(+)
 create mode 100644 boot/upl_write.c
boot/Kconfig +8 -0
index 6e907b45095..fa4f766054c 100644
@@ -739,6 +739,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
@@ -753,6 +754,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 97b52a3404c..b8b63d31e88 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_$(SPL_TPL_)FDT_SIMPLEFB) += fdt_simplefb.o
 
 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 +622 -0

622 lines not on this page · raw message

Signature · 1 line
2.34.1
#11 lore raw

PATCH v3 11/21 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.

---

(no changes since v2)

Changes in v2:
- Put the upl tests under their own subcommand to avoid bootstd init

 MAINTAINERS           |   1 +
 include/test/suites.h |   1 +
 include/upl.h         |   9 ++
 test/boot/Makefile    |   2 +
 test/boot/upl.c       | 368 ++++++++++++++++++++++++++++++++++++++++++
 test/cmd_ut.c         |   3 +
 6 files changed, 384 insertions(+)
 create mode 100644 test/boot/upl.c
MAINTAINERS +1 -0
index 070a766a76f..1c41fd30b2a 100644
@@ -1707,6 +1707,7 @@ S:	Maintained
 T:	git https://source.denx.de/u-boot/custodians/u-boot-dm.git
 F:	boot/upl*
 F:	include/upl.h
+F:	test/boot/upl.c
 
 USB
 M:	Marek Vasut <[email protected]>
include/test/suites.h +1 -0
index 365d5f20dfe..2ceef577f7f 100644
@@ -63,5 +63,6 @@ int do_ut_str(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_time(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_unicode(struct cmd_tbl *cmdtp, int flag, int argc,
 		  char *const argv[]);
+int do_ut_upl(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 
 #endif /* __TEST_SUITES_H__ */
include/upl.h +9 -0
index fca7e5fd49f..fa784e57f74 100644
@@ -308,6 +308,15 @@ int upl_create_handoff_tree(const struct upl *upl, oftree *treep);
  * Return: 0 on success, -ve on error
  */
 int upl_read_handoff(struct upl *upl, oftree tree);
+
+/**
+ * upl_get_test_data() - Fill a UPL with some test data
+ *
+ * @uts: Test state (can be uninited)
+ * @upl: Returns test data
+ * Return: 0 on success, 1 on error
+ */
+int upl_get_test_data(struct unit_test_state *uts, struct upl *upl);
 #endif /* USE_HOSTCC */
 
 #if CONFIG_IS_ENABLED(UPL) && defined(CONFIG_SPL_BUILD)
test/boot/Makefile +2 -0
index 068522cb9e0..8ec5daa7bfe 100644
@@ -13,3 +13,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 +368 -0

368 lines not on this page · raw message

test/cmd_ut.c +3 -0
index 4e4aa8f1cb2..38ba89ee33e 100644
@@ -133,6 +133,9 @@ static struct cmd_tbl cmd_ut_sub[] = {
 #ifdef CONFIG_CMD_SEAMA
 	U_BOOT_CMD_MKENT(seama, CONFIG_SYS_MAXARGS, 1, do_ut_seama, "", ""),
 #endif
+#ifdef CONFIG_CMD_UPL
+	U_BOOT_CMD_MKENT(upl, CONFIG_SYS_MAXARGS, 1, do_ut_upl, "", ""),
+#endif
 };
 
 static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
Signature · 1 line
2.34.1
#12 lore raw

PATCH v3 12/21 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.

---

(no changes since v1)

 MAINTAINERS                       |   2 +
 boot/Kconfig                      |   1 +
 cmd/Kconfig                       |   7 ++
 cmd/Makefile                      |   1 +
 cmd/upl.c                         | 118 +++++++++++++++++++
 doc/usage/cmd/upl.rst             | 186 ++++++++++++++++++++++++++++++
 doc/usage/index.rst               |   1 +
 include/asm-generic/global_data.h |  15 +++
 test/boot/upl.c                   |  40 +++++++
 9 files changed, 371 insertions(+)
 create mode 100644 cmd/upl.c
 create mode 100644 doc/usage/cmd/upl.rst
MAINTAINERS +2 -0
index 1c41fd30b2a..538d975748d 100644
@@ -1706,6 +1706,8 @@ M:	Simon Glass <[email protected]>
 S:	Maintained
 T:	git https://source.denx.de/u-boot/custodians/u-boot-dm.git
 F:	boot/upl*
+F:	cmd/upl.c
+F:	doc/usage/cmd/upl.rst
 F:	include/upl.h
 F:	test/boot/upl.c
 
boot/Kconfig +1 -0
index fa4f766054c..f9a44550ac4 100644
@@ -738,6 +738,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 0cf0d8ad8ab..3c602bd5ba3 100644
@@ -388,6 +388,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 87133cc27a8..91227f1249c 100644
@@ -189,6 +189,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 +118 -0

118 lines not on this page · raw message

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

186 lines not on this page · raw message

doc/usage/index.rst +1 -0
index 49b354e6ffd..b34e388bfd1 100644
@@ -113,6 +113,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 aa336d63e3a..98d822530d8 100644
@@ -30,6 +30,7 @@
 
 struct acpi_ctx;
 struct driver_rt;
+struct upl;
 
 typedef struct global_data gd_t;
 
@@ -491,6 +492,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);
@@ -590,6 +597,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 +40 -0
index e9d92efd80d..c55f1d297d1 100644
@@ -358,6 +358,46 @@ static int upl_test_base(struct unit_test_state *uts)
 }
 UPL_TEST(upl_test_base, 0);
 
+/* Test 'upl info' command */
+static int upl_test_info(struct unit_test_state *uts)
+{
+	gd_set_upl(NULL);
+	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;
+}
+UPL_TEST(upl_test_info, UT_TESTF_CONSOLE_REC);
+
+/* Test 'upl read' and 'upl_write' commands */
+static int upl_test_read_write(struct unit_test_state *uts)
+{
+	ulong addr;
+
+	if (!CONFIG_IS_ENABLED(OFNODE_MULTI_TREE))
+		return -EAGAIN;  /* skip test */
+	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;
+}
+UPL_TEST(upl_test_read_write, UT_TESTF_CONSOLE_REC);
+
 int do_ut_upl(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	struct unit_test *tests = UNIT_TEST_SUITE_START(upl_test);
Signature · 1 line
2.34.1
#13 lore raw

PATCH v3 13/21 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.

---

(no changes since v2)

Changes in v2:
- Add a function to init the UPL process in SPL

 MAINTAINERS          |   1 +
 boot/Kconfig         |  32 ++++++++
 common/spl/Makefile  |   2 +
 common/spl/spl_upl.c | 171 +++++++++++++++++++++++++++++++++++++++++++
 include/spl.h        |  16 ++++
 5 files changed, 222 insertions(+)
 create mode 100644 common/spl/spl_upl.c
MAINTAINERS +1 -0
index 538d975748d..efb557b2524 100644
@@ -1707,6 +1707,7 @@ S:	Maintained
 T:	git https://source.denx.de/u-boot/custodians/u-boot-dm.git
 F:	boot/upl*
 F:	cmd/upl.c
+F:	common/spl/spl_upl.c
 F:	doc/usage/cmd/upl.rst
 F:	include/upl.h
 F:	test/boot/upl.c
boot/Kconfig +32 -0
index f9a44550ac4..1fdbb0755c5 100644
@@ -741,6 +741,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
@@ -757,11 +758,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 4809f9c3ec1..137b18428bd 100644
@@ -37,3 +37,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 +171 -0

171 lines not on this page · raw message

include/spl.h +16 -0
index 5dfdf778d2d..089b1864c57 100644
@@ -1074,4 +1074,20 @@ static inline bool spl_decompression_enabled(void)
 {
 	return IS_ENABLED(CONFIG_SPL_GZIP) || IS_ENABLED(CONFIG_SPL_LZMA);
 }
+
+/**
+ * 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);
+
+/**
+ * spl_upl_init() - Get UPL ready for information to be added
+ *
+ * This must be called before upl_add_image(), etc.
+ */
+void spl_upl_init(void);
+
 #endif
Signature · 1 line
2.34.1
#14 lore raw

PATCH v3 14/21 spl: Set SPL_FIT_FOUND for full FIT also

In reply to Simon Glass

This flag is set for simple FIT, so set it for full FIT too.

---

Changes in v3:
- Split out into its own commit

 common/spl/spl_fit.c | 1 +
 1 file changed, 1 insertion(+)
common/spl/spl_fit.c +1 -0
index 2a097f4464c..527a5691ac6 100644
@@ -941,6 +941,7 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 		if (ret < 0)
 			return ret;
 	}
+	spl_image->flags |= SPL_FIT_FOUND;
 
 	return 0;
 }
Signature · 1 line
2.34.1
#15 lore raw

PATCH v3 15/21 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.

Control this using a runtime flag to avoid conflicting with other handoff mechanisms.

---

(no changes since v2)

Changes in v2:
- Hang when something goes wrong, to avoid a broken boot
- Add a runtime flag to enable UPL
- Put upl_image() calls in a common place

 boot/image-fit.c                  | 4 ++++
 common/spl/spl.c                  | 8 ++++++++
 common/spl/spl_fit.c              | 9 +++++++++
 include/asm-generic/global_data.h | 4 ++++
 4 files changed, 25 insertions(+)
boot/image-fit.c +4 -0
index 9253f81fff5..c38ccd6754f 100644
@@ -36,6 +36,7 @@ DECLARE_GLOBAL_DATA_PTR;
 #include <bootm.h>
 #include <image.h>
 #include <bootstage.h>
+#include <upl.h>
 #include <u-boot/crc.h>
 
 /*****************************************************************************/
@@ -2294,6 +2295,9 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
 
 	bootstage_mark(bootstage_id + BOOTSTAGE_SUB_LOAD);
 
+	upl_add_image(noffset, load, len,
+		      fdt_getprop(fit, noffset, FIT_DESC_PROP, NULL));
+
 	*datap = load;
 	*lenp = len;
 	if (fit_unamep)
common/spl/spl.c +8 -0
index 7794ddccade..d6a364de6ee 100644
@@ -810,6 +810,14 @@ 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) && (gd->flags & GD_FLG_UPL)) {
+		ret = spl_write_upl_handoff(&spl_image);
+		if (ret) {
+			printf(SPL_TPL_PROMPT
+			       "UPL hand-off write failed (err=%d)\n", ret);
+			hang();
+		}
+	}
 	if (CONFIG_IS_ENABLED(BLOBLIST)) {
 		ret = bloblist_finish();
 		if (ret)
common/spl/spl_fit.c +9 -0
index 527a5691ac6..03a2ad4ebe7 100644
@@ -12,6 +12,7 @@
 #include <memalign.h>
 #include <mapmem.h>
 #include <spl.h>
+#include <upl.h>
 #include <sysinfo.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
@@ -336,6 +337,9 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,
 			image_info->entry_point = FDT_ERROR;
 	}
 
+	upl_add_image(node, load_addr, length,
+		      fdt_getprop(fit, node, FIT_DESC_PROP, NULL));
+
 	return 0;
 }
 
@@ -847,6 +851,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;
 }
@@ -943,5 +949,8 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 	}
 	spl_image->flags |= SPL_FIT_FOUND;
 
+	upl_set_fit_info(map_to_sysmem(header), conf_noffset,
+			 spl_image->entry_point);
+
 	return 0;
 }
include/asm-generic/global_data.h +4 -0
index 98d822530d8..37643a4bbb9 100644
@@ -716,6 +716,10 @@ enum gd_flags {
 	 * @GD_FLG_HUSH_MODERN_PARSER: Use hush 2021 parser.
 	 */
 	GD_FLG_HUSH_MODERN_PARSER = 0x2000000,
+	/**
+	 * @GD_FLG_UPL: Read/write a Universal Payload (UPL) handoff
+	 */
+	GD_FLG_UPL = 0x4000000,
 };
 
 #endif /* __ASSEMBLY__ */
Signature · 1 line
2.34.1
#16 lore raw

PATCH v3 16/21 upl: 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.

---

(no changes since v1)

 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 1fdbb0755c5..ca14a614152 100644
@@ -754,7 +754,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"
@@ -765,6 +767,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 22c180b2187..ebcc63f34dc 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>
@@ -862,6 +863,26 @@ __weak int clear_bss(void)
 	return 0;
 }
 
+static int initf_upl(void)
+{
+	struct upl *upl;
+	int ret;
+
+	if (!IS_ENABLED(CONFIG_UPL_IN) || !(gd->flags & GD_FLG_UPL))
+		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
@@ -871,6 +892,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 d4ba245ac69..f445803d7a4 100644
@@ -521,6 +521,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.34.1
#17 lore raw

PATCH v3 17/21 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.

---

(no changes since v1)

 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 72483d8ba10..96e9211bd19 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_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_BOOTSTAGE_FDT=y
@@ -35,6 +38,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..171079f8dba
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2024 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.34.1
#18 lore raw

PATCH v3 18/21 upl: Add initial documentation

In reply to Simon Glass

Add some documentation to explain the basic concept along with a link to the full spec.

---

(no changes since v2)

Changes in v2:
- Add a link to the spec
- Add a link to the command

 MAINTAINERS           |  1 +
 doc/usage/cmd/upl.rst |  4 ++--
 doc/usage/index.rst   |  1 +
 doc/usage/upl.rst     | 46 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 doc/usage/upl.rst
MAINTAINERS +1 -0
index efb557b2524..8842ff8ad91 100644
@@ -1708,6 +1708,7 @@ T:	git https://source.denx.de/u-boot/custodians/u-boot-dm.git
 F:	boot/upl*
 F:	cmd/upl.c
 F:	common/spl/spl_upl.c
+F:	doc/usage/upl.rst
 F:	doc/usage/cmd/upl.rst
 F:	include/upl.h
 F:	test/boot/upl.c
doc/usage/cmd/upl.rst +2 -2
index a64063d42d5..8d6ea5daa37 100644
@@ -16,8 +16,8 @@ Description
 -----------
 
 The *upl* command is used to test U-Boot's support for the Universal Payload
-Specification (UPL) firmware standard. It allows creation of a fake handoff for
-use in testing.
+Specification (UPL) firmware standard (see :doc:`../upl`). It allows creation of
+a fake handoff for use in testing.
 
 
 upl write
doc/usage/index.rst +1 -0
index b34e388bfd1..d67fe355446 100644
@@ -15,6 +15,7 @@ Use U-Boot
    cmdline
    semihosting
    measured_boot
+   upl
 
 Shell commands
 --------------
doc/usage/upl.rst new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.34.1
#19 lore raw

PATCH v3 19/21 sandbox: Add a flag to enable UPL

In reply to Simon Glass

UPL significantly alters the boot flow for sandbox. Add a flag to enable this so that it can be enabled only on tests which need it.

---

(no changes since v1)

 arch/sandbox/cpu/start.c         | 13 ++++++++++++-
 arch/sandbox/include/asm/state.h |  1 +
 2 files changed, 13 insertions(+), 1 deletion(-)
arch/sandbox/cpu/start.c +12 -1
index 0920ed55965..9ad5d46271a 100644
@@ -431,6 +431,14 @@ static int sandbox_cmdline_cb_autoboot_keyed(struct sandbox_state *state,
 }
 SANDBOX_CMDLINE_OPT(autoboot_keyed, 0, "Allow keyed autoboot");
 
+static int sandbox_cmdline_cb_upl(struct sandbox_state *state, const char *arg)
+{
+	state->upl = true;
+
+	return 0;
+}
+SANDBOX_CMDLINE_OPT(upl, 0, "Enable Universal Payload (UPL)");
+
 static void setup_ram_buf(struct sandbox_state *state)
 {
 	/* Zero the RAM buffer if we didn't read it, to keep valgrind happy */
@@ -540,6 +548,9 @@ int sandbox_main(int argc, char *argv[])
 			goto err;
 	}
 
+	if (state->upl)
+		gd->flags |= GD_FLG_UPL;
+
 #if CONFIG_IS_ENABLED(SYS_MALLOC_F)
 	gd->malloc_base = CFG_MALLOC_F_ADDR;
 #endif
@@ -558,7 +569,7 @@ int sandbox_main(int argc, char *argv[])
 	log_debug("debug: %s\n", __func__);
 
 	/* Do pre- and post-relocation init */
-	board_init_f(0);
+	board_init_f(gd->flags);
 
 	board_init_r(gd->new_gd, 0);
 
arch/sandbox/include/asm/state.h +1 -0
index c84a1f7060f..6b50473ed41 100644
@@ -97,6 +97,7 @@ struct sandbox_state {
 	bool autoboot_keyed;		/* Use keyed-autoboot feature */
 	bool disable_eth;		/* Disable Ethernet devices */
 	bool disable_sf_bootdevs;	/* Don't bind SPI flash bootdevs */
+	bool upl;			/* Enable Universal Payload (UPL) */
 
 	/* Pointer to information for each SPI bus/cs */
 	struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS]
Signature · 1 line
2.34.1
#20 lore raw

PATCH v3 20/21 sandbox: Add an SPL loader for UPL

In reply to Simon Glass

Add support for loading a UPL image from SPL. This uses the simple FIT implementation, but also loads the full FIT just to permit more testing.

---

(no changes since v1)

 arch/sandbox/cpu/spl.c         | 49 +++++++++++++++++++++++++++++++++-
 arch/sandbox/include/asm/spl.h |  1 +
 2 files changed, 49 insertions(+), 1 deletion(-)
arch/sandbox/cpu/spl.c +48 -1
index e86193de419..bcb1ca10a51 100644
@@ -3,14 +3,18 @@
  * Copyright (c) 2016 Google, Inc
  */
 
+#define LOG_CATEGORY	LOGC_BOOT
+
 #include <dm.h>
 #include <hang.h>
 #include <handoff.h>
 #include <image.h>
 #include <init.h>
 #include <log.h>
+#include <mapmem.h>
 #include <os.h>
 #include <spl.h>
+#include <upl.h>
 #include <asm/global_data.h>
 #include <asm/spl.h>
 #include <asm/state.h>
@@ -52,7 +56,8 @@ void board_init_f(ulong flag)
 void board_boot_order(u32 *spl_boot_list)
 {
 	spl_boot_list[0] = BOOT_DEVICE_VBE;
-	spl_boot_list[1] = BOOT_DEVICE_BOARD;
+	spl_boot_list[1] = BOOT_DEVICE_UPL;
+	spl_boot_list[2] = BOOT_DEVICE_BOARD;
 }
 
 static int spl_board_load_file(struct spl_image_info *spl_image,
@@ -250,3 +255,45 @@ int sandbox_spl_load_fit(char *fname, int maxlen, struct spl_image_info *image)
 
 	return 0;
 }
+
+static int upl_load_from_image(struct spl_image_info *spl_image,
+			       struct spl_boot_device *bootdev)
+{
+	long long size;
+	char *fname;
+	int ret, fd;
+	ulong addr;
+
+	if (!CONFIG_IS_ENABLED(UPL_OUT))
+		return -ENOTSUPP;
+
+	spl_upl_init();
+	fname = os_malloc(256);
+
+	ret = sandbox_spl_load_fit(fname, 256, spl_image);
+	if (ret)
+		return log_msg_ret("fit", ret);
+	spl_image->flags = SPL_SANDBOXF_ARG_IS_BUF;
+	spl_image->arg = map_sysmem(spl_image->load_addr, 0);
+	/* size is set by load_simple_fit(), offset is left as 0 */
+
+	/* now read the whole FIT into memory */
+	fd = os_open(fname, OS_O_RDONLY);
+	if (fd < 0)
+		return log_msg_ret("op2", -ENOENT);
+	if (os_get_filesize(fname,  &size))
+		return log_msg_ret("fis", -ENOENT);
+
+	/* place it after the loaded image, allowing plenty of space */
+	addr = ALIGN(spl_image->load_addr + size, 0x1000);
+	log_debug("Loading whole FIT to %lx\n", addr);
+	if (os_read(fd, map_sysmem(addr, 0), size) != size)
+		return log_msg_ret("rea", -EIO);
+	os_close(fd);
+
+	/* tell UPL where it is */
+	upl_set_fit_addr(addr);
+
+	return 0;
+}
+SPL_LOAD_IMAGE_METHOD("upl", 4, BOOT_DEVICE_UPL, upl_load_from_image);
arch/sandbox/include/asm/spl.h +1 -0
index d50d9ad6b48..d824b2123a2 100644
@@ -18,6 +18,7 @@ enum {
 	BOOT_DEVICE_NOR,
 	BOOT_DEVICE_SPI,
 	BOOT_DEVICE_NAND,
+	BOOT_DEVICE_UPL,
 };
 
 /**
Signature · 1 line
2.34.1
#21 lore raw

PATCH v3 21/21 upl: Add an end-to-end test

In reply to Simon Glass

Now that sandbox_vpl supports UPL, add a test that checks that the payload can be loaded by SPL and the handoff information passed through to U-Boot proper.

---

(no changes since v2)

Changes in v2:
- Support CI testing
- Rework to use alist instead of fixed-length arrays

 MAINTAINERS               |  1 +
 test/boot/upl.c           | 29 +++++++++++++++++++++++++++++
 test/py/tests/test_upl.py | 17 +++++++++++++++--
 3 files changed, 45 insertions(+), 2 deletions(-)
MAINTAINERS +1 -0
index 8842ff8ad91..7f988e0762f 100644
@@ -1712,6 +1712,7 @@ F:	doc/usage/upl.rst
 F:	doc/usage/cmd/upl.rst
 F:	include/upl.h
 F:	test/boot/upl.c
+F:	test/py/tests/test_upl.py
 
 USB
 M:	Marek Vasut <[email protected]>
test/boot/upl.c +29 -0
index c55f1d297d1..707bc9c9065 100644
@@ -398,6 +398,35 @@ static int upl_test_read_write(struct unit_test_state *uts)
 }
 UPL_TEST(upl_test_read_write, UT_TESTF_CONSOLE_REC);
 
+/* Test UPL passthrough */
+static int upl_test_info_norun(struct unit_test_state *uts)
+{
+	const struct upl_image *img;
+	struct upl *upl = gd_upl();
+	const void *fit;
+
+	ut_assertok(run_command("upl info -v", 0));
+	ut_assert_nextline("UPL state: active");
+	ut_assert_nextline("fit %lx", upl->fit);
+	ut_assert_nextline("conf_offset %x", upl->conf_offset);
+	ut_assert_nextlinen("image 0");
+	ut_assert_nextlinen("image 1");
+	ut_assert_console_end();
+
+	/* check the offsets */
+	fit = map_sysmem(upl->fit, 0);
+	ut_asserteq_str("conf-1", fdt_get_name(fit, upl->conf_offset, NULL));
+
+	ut_asserteq(2, upl->image.count);
+
+	img = alist_get(&upl->image, 1, struct upl_image);
+	ut_asserteq_str("firmware-1", fdt_get_name(fit, img->offset, NULL));
+	ut_asserteq(CONFIG_TEXT_BASE, img->load);
+
+	return 0;
+}
+UPL_TEST(upl_test_info_norun, UT_TESTF_CONSOLE_REC | UT_TESTF_MANUAL);
+
 int do_ut_upl(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	struct unit_test *tests = UNIT_TEST_SUITE_START(upl_test);
test/py/tests/test_upl.py +15 -2
index 171079f8dba..3164bda6b71 100644
@@ -10,6 +10,15 @@ import u_boot_utils
 
 @pytest.mark.boardspec('sandbox_vpl')
 def test_upl_handoff(u_boot_console):
+    """Test of UPL handoff
+
+    This works by starting up U-Boot VPL, which gets to SPL and then sets up a
+    UPL handoff using the FIT containing U-Boot proper. It then jumps to U-Boot
+    proper and runs a test to check that the parameters are correct.
+
+    The entire FIT is loaded into memory in SPL (in upl_load_from_image()) so
+    that it can be inpected in upl_test_info_norun
+    """
     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')
@@ -17,9 +26,13 @@ def test_upl_handoff(u_boot_console):
     # 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]
+    flags = ['-m', ram, '-d', fdt, '--upl']
     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'
+    assert 'UPL state: active' == output
+
+    # Check the FIT offsets look correct
+    output = cons.run_command('ut upl -f upl_test_info_norun')
+    assert 'Failures: 0' in output
Signature · 1 line
2.34.1
#22 lore raw
In reply to Simon Glass
Quoted 15 lines · Simon Glass

Universal Payload (UPL) is an Industry Standard for firmware components[1]. 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, targeting 0.9.1 and sandbox only.

Features still to come include:
- Support for architectures
- FIT validation
- Handoff validation
- Interoperability tests

Quoted 5 lines

This series is available at dm/uplb-working and requires the alist series at dm/alist-working[2]

[1] https://universalpayload.github.io/spec/
[2] https://patchwork.ozlabs.org/project/uboot/list/?series=414642

Please rebase and repost v4 on top of current next, which has v5 of alist. Also, the changes to load_simple_fit() aren't size-neutral in SPL since it looks like upl_add_image() doesn't get nop'd out when SPL_UPL isn't set. Thanks!

Signature · 1 line
Tom