Skip to contentSkip to conversation

test: spl: Test some load methods

PATCH In review Sean Anderson 4 participants 43 messages Oct 15, 2023 – Oct 18, 2023

Subsystems (8)
Networking Arm (32-bit) VFS USB +4 more subsystems
lore
Share & tools
lore
#0 lore raw

v2 cover test: spl: Test some load methods

This series adds some tests for various SPL load methods, with the intent of helping debug v6 of [1]. With that in mind, notable omissions include NAND and ROMAPI, which both lack sandbox implementations, and OS_BOOT, which I have deferred due to its complexity. Semihosting is also omitted, but I think we can test that with qemu.

In order to test all of these methods, we must first generate suitable images, possibly on filesystems. While other tests have historically generated these images using external tools (e.g. mkimage, mkfs, etc.), I have chosen to generate them on the fly. This is for a few reasons:

- By removing external dependencies on pytest to create certain files, the tests become self-contained. This makes them easier to iterate on and debug.
- By generating tests at runtime, we can dynamically vary the content. This helps detect test failures, as even if tests are loaded to the same location, the expected content will be different.
- We are not testing the image parsers themselves (e.g. spl_load_simple_fit or fs_read) but rather the load methods (e.g. spl_mmc_load_image). It is unnecessary to exercise full functionality or generate 100% correct images.
- By reducing functionality to only what is necessary, the complexity of various formats can often be greatly reduced.

This series depends on [2-3], which are small fixes identified through this patch set. The organization of patches in this series is as follows:

- General fixes for bugs which are unlikely to be triggered outside of this series
- Changes to IMX8 container images to facilitate testing
- General prep. work, particularly regarding linker issues
- The tests themselves

Passing CI at [4].

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://source.denx.de/u-boot/custodians/u-boot-clk/-/pipelines/18128

Changes in v2:
- Use "address of" to describe the "&" operator
- Remove check for zero entry point in spl_load_fit_image
- Use log_err for errors in read_auth_container
- Clarify commit message for patch "Check header before calling spl_load_imx_container"
- Hide SPL_OF_REAL unless SANDBOX is enabled
- Disable sandbox filesystem in SPL instead of compiling it in
- Split ext4 defines into their own commit
- Use SPL_TPL_ for compiling fastboot functions
- Use callbacks to invalidate SPL caches instead of disabling them entirely
- Split off -T support into its own commit
- Compare to PHASE_SPL in sandbox_cmdline_cb_test_fdt for clarity
- Remove redundant condition on CONFIG_SPL_UT_LOAD in test/image/Makefile
- Remove unused mapmem.h include in spl_load_os.c
- Fix size not being updated in board_spl_fit_buffer_addr
- Fix return value documentation for check_image_info
- Explicitly invalidate FAT block device cache before testing
- Remove unused dm.h include in spl_load.c
- Add note about why we enable SPL_TIMER
- Explicitly invalidate FAT block device cache before testing
- Correct return value documentation for do_spl_test_load
- Explicitly invalidate FAT and MMC caches before testing
- Add a comment about why we need to initialize bi_dram
- Clarify generation process for LZMA data

Sean Anderson (29):
spl: legacy: Fix referencing _image_binary_end
spl: nor: Don't allocate header on stack
spl: fit: Fix entry point for SPL_LOAD_FIT_FULL
arm: imx: Fix i.MX8 container load address
arm: imx: Add newlines after error messages
arm: imx: Use log_err for errors in read_auth_container
arm: imx: Add function to validate i.MX8 containers
arm: imx: Check header before calling spl_load_imx_container Move i.MX8 container image loading support to common/spl
spl: Allow enabling SPL_OF_REAL and SPL_OF_PLATDATA at the same time
lib: acpi: Fix linking SPL when ACPIGEN is enabled
fs: Disable sandbox filesystem in SPL
fs: ext4: Fix building ext4 in SPL if write is enabled
fs: ext4: Add some defines for testing
net: Fix compiling SPL when fastboot is enabled
net: bootp: Move port numbers to header
net: bootp: Fall back to BOOTP from DHCP when unit testing
spl: Add callbacks to invalidate cached devices
spl: Use map_sysmem where appropriate
sandbox: Support -T in spl
test: spl: Split tests up and use some configs
test: spl: Fix spl_test_load not failing if fname doesn't exist
test: spl: Add functions to create images
test: spl: Add functions to create filesystems
test: spl: Add a test for spl_blk_load_image
test: spl: Add a test for the MMC load method
test: spl: Add a test for the NET load method
test: spl: Add a test for the NOR load method
test: spl: Add a test for the SPI load method

 .azure-pipelines.yml                          |   4 +
 .gitlab-ci.yml                                |   7 +
 MAINTAINERS                                   |   2 +
 arch/arm/include/asm/mach-imx/ahab.h          |   2 +-
 arch/arm/mach-imx/Kconfig                     |  13 -
 arch/arm/mach-imx/Makefile                    |   2 +-
 arch/arm/mach-imx/cmd_dek.c                   |   4 +-
 arch/arm/mach-imx/ele_ahab.c                  |   4 +-
 arch/arm/mach-imx/image-container.c           |   4 +-
 arch/arm/mach-imx/imx8/ahab.c                 |   4 +-
 arch/arm/mach-imx/spl_imx_romapi.c            |   8 +-
 arch/sandbox/cpu/spl.c                        |   4 +
 arch/sandbox/cpu/start.c                      |   9 +-
 arch/sandbox/cpu/u-boot-spl.lds               |   2 +
 arch/sandbox/include/asm/spl.h                |   3 +
 common/spl/Kconfig                            |  15 +
 common/spl/Makefile                           |   1 +
 common/spl/spl.c                              |   4 +-
 common/spl/spl_blk_fs.c                       |   6 +-
 common/spl/spl_ext.c                          |   4 +-
 common/spl/spl_fat.c                          |  16 +-
 common/spl/spl_fit.c                          |  39 +-
 .../spl/spl_imx_container.c                   |  13 +-
 common/spl/spl_legacy.c                       |   8 +-
 common/spl/spl_mmc.c                          |  16 +-
 common/spl/spl_nand.c                         |   4 +-
 common/spl/spl_net.c                          |  10 +-
 common/spl/spl_nor.c                          |  18 +-
 common/spl/spl_spi.c                          |  18 +-
 configs/deneb_defconfig                       |   2 +
 configs/giedi_defconfig                       |   2 +
 configs/imx8qm_mek_defconfig                  |   2 +
 configs/imx8qxp_mek_defconfig                 |   2 +
 configs/sandbox_noinst_defconfig              |  31 +-
 configs/sandbox_spl_defconfig                 |   8 +
 configs/sandbox_vpl_defconfig                 |   1 +
 drivers/core/Makefile                         |   1 +
 drivers/core/root.c                           |   2 +-
 drivers/i2c/Makefile                          |   2 +-
 drivers/i2c/i2c-emul-uclass.c                 |   2 +-
 drivers/serial/sandbox.c                      |   2 +-
 drivers/sysreset/sysreset_sandbox.c           |   2 +-
 drivers/usb/gadget/f_sdp.c                    |   4 +-
 dts/Kconfig                                   |   8 +-
 fs/fs.c                                       |   2 +-
 include/configs/sandbox.h                     |   3 +
 include/ext4fs.h                              |   1 +
 include/ext_common.h                          |  14 +
 .../image.h => include/imx_container.h        |   9 +
 include/spl.h                                 |  36 +
 include/test/spl.h                            | 155 ++++
 lib/Kconfig                                   |   6 +
 lib/Makefile                                  |   1 +
 net/Makefile                                  |   4 +-
 net/bootp.c                                   |   9 +-
 net/bootp.h                                   |   3 +
 net/net.c                                     |   4 +-
 test/Kconfig                                  |   1 +
 test/Makefile                                 |   5 +-
 test/image/Kconfig                            |  50 ++
 test/image/Makefile                           |   7 +-
 test/image/spl_load.c                         | 690 ++++++++++++++++--
 test/image/spl_load_fs.c                      | 428 +++++++++++
 test/image/spl_load_net.c                     | 252 +++++++
 test/image/spl_load_nor.c                     |  39 +
 test/image/spl_load_os.c                      |  76 ++
 test/image/spl_load_spi.c                     |  41 ++
 test/py/tests/test_spl.py                     |  10 +
 test/test-main.c                              |   2 +-
 69 files changed, 2000 insertions(+), 163 deletions(-)
 rename arch/arm/mach-imx/parse-container.c => common/spl/spl_imx_container.c (91%)
 rename arch/arm/include/asm/mach-imx/image.h => include/imx_container.h (82%)
 create mode 100644 include/test/spl.h
 create mode 100644 test/image/Kconfig
 create mode 100644 test/image/spl_load_fs.c
 create mode 100644 test/image/spl_load_net.c
 create mode 100644 test/image/spl_load_nor.c
 create mode 100644 test/image/spl_load_os.c
 create mode 100644 test/image/spl_load_spi.c
Signature · 1 line
2.37.1
#1 lore raw

PATCH v2 1/29 spl: legacy: Fix referencing _image_binary_end

On non-arm architectures, _image_binary_end is defined as a ulong and not a char[]. Take the address of it when accessing it, which is correct for both.

Fixes 1b8a1be1a1f ("spl: spl_legacy: Fix spl_end address")

---

Changes in v2:
- Use "address of" to describe the "&" operator

 common/spl/spl_legacy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/spl/spl_legacy.c +1 -1
index 095443c63d8..e9564e5c2a5 100644
@@ -19,7 +19,7 @@
 static void spl_parse_legacy_validate(uintptr_t start, uintptr_t size)
 {
 	uintptr_t spl_start = (uintptr_t)_start;
-	uintptr_t spl_end = (uintptr_t)_image_binary_end;
+	uintptr_t spl_end = (uintptr_t)&_image_binary_end;
 	uintptr_t end = start + size;
 
 	if ((start >= spl_start && start < spl_end) ||
Signature · 1 line
2.37.1
#2 lore raw

PATCH v2 2/29 spl: nor: Don't allocate header on stack

In reply to Sean Anderson

spl_image_info.name contains a reference to legacy_img_hdr. If we allocate the latter on the stack, it will be clobbered after we return. This was addressed for NAND back in 06377c5a1fc ("spl: spl_legacy: Fix NAND boot on OMAP3 BeagleBoard"), but that commit didn't fix NOR.

---

(no changes since v1)

 common/spl/spl_nor.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
common/spl/spl_nor.c +4 -7
index 79d4f1d7aa8..c141a9ae629 100644
@@ -26,7 +26,7 @@ unsigned long __weak spl_nor_get_uboot_base(void)
 static int spl_nor_load_image(struct spl_image_info *spl_image,
 			      struct spl_boot_device *bootdev)
 {
-	__maybe_unused const struct legacy_img_hdr *header;
+	struct legacy_img_hdr *header;
 	__maybe_unused struct spl_load_info load;
 
 	/*
@@ -41,7 +41,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 		 * Load Linux from its location in NOR flash to its defined
 		 * location in SDRAM
 		 */
-		header = (const struct legacy_img_hdr *)CONFIG_SYS_OS_BASE;
+		header = (void *)CONFIG_SYS_OS_BASE;
 #ifdef CONFIG_SPL_LOAD_FIT
 		if (image_get_magic(header) == FDT_MAGIC) {
 			int ret;
@@ -91,8 +91,8 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 	 * Load real U-Boot from its location in NOR flash to its
 	 * defined location in SDRAM
 	 */
-#ifdef CONFIG_SPL_LOAD_FIT
 	header = (const struct legacy_img_hdr *)spl_nor_get_uboot_base();
+#ifdef CONFIG_SPL_LOAD_FIT
 	if (image_get_magic(header) == FDT_MAGIC) {
 		debug("Found FIT format U-Boot\n");
 		load.bl_len = 1;
@@ -111,14 +111,11 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 
 	/* Legacy image handling */
 	if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT)) {
-		struct legacy_img_hdr hdr;
-
 		load.bl_len = 1;
 		load.read = spl_nor_load_read;
-		spl_nor_load_read(&load, spl_nor_get_uboot_base(), sizeof(hdr), &hdr);
 		return spl_load_legacy_img(spl_image, bootdev, &load,
 					   spl_nor_get_uboot_base(),
-					   &hdr);
+					   header);
 	}
 
 	return -EINVAL;
Signature · 1 line
2.37.1
#3 lore raw

PATCH v2 3/29 spl: fit: Fix entry point for SPL_LOAD_FIT_FULL

In reply to Sean Anderson

The entry point is not always the same as the load address. Use the value of the entry property if it exists.

Fixes 8a9dc16e4d0 ("spl: Add full fitImage support")

---

Changes in v2:
- Remove check for zero entry point in spl_load_fit_image

 common/spl/spl_fit.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
common/spl/spl_fit.c +2 -1
index ce6b8aa370a..4f8b951efe2 100644
@@ -884,8 +884,9 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 		return ret;
 
 	spl_image->size = fw_len;
-	spl_image->entry_point = fw_data;
 	spl_image->load_addr = fw_data;
+	if (fit_image_get_entry(header, ret, &spl_image->entry_point))
+		spl_image->entry_point = fw_data;
 	if (fit_image_get_os(header, ret, &spl_image->os))
 		spl_image->os = IH_OS_INVALID;
 	spl_image->name = genimg_get_os_name(spl_image->os);
Signature · 1 line
2.37.1
#4 lore raw

PATCH v2 4/29 arm: imx: Fix i.MX8 container load address

In reply to Sean Anderson

We should load images to their destination, not their entry point.

Fixes 7b86cd4274e ("imx8: support parsing i.MX8 Container file")

---

(no changes since v1)

 arch/arm/mach-imx/parse-container.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-imx/parse-container.c +1 -1
index e2a9e2b2732..d7275a58c17 100644
@@ -45,7 +45,7 @@ static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image,
 	debug("%s: container: %p sector: %lu sectors: %u\n", __func__,
 	      container, sector, sectors);
 	if (info->read(info, sector, sectors,
-		       (void *)images[image_index].entry) != sectors) {
+		       (void *)images[image_index].dst) != sectors) {
 		printf("%s wrong\n", __func__);
 		return NULL;
 	}
Signature · 1 line
2.37.1
#5 lore raw

PATCH v2 5/29 arm: imx: Add newlines after error messages

In reply to Sean Anderson

These error messages are missing newlines. Add them.

Fixes 6e81ca220e0 ("imx: parse-container: Use malloc for container processing")

---

(no changes since v1)

 arch/arm/mach-imx/parse-container.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-imx/parse-container.c +2 -2
index d7275a58c17..c5df78d1c58 100644
@@ -85,13 +85,13 @@ static int read_auth_container(struct spl_image_info *spl_image,
 	}
 
 	if (container->tag != 0x87 && container->version != 0x0) {
-		printf("Wrong container header");
+		printf("Wrong container header\n");
 		ret = -ENOENT;
 		goto end;
 	}
 
 	if (!container->num_images) {
-		printf("Wrong container, no image found");
+		printf("Wrong container, no image found\n");
 		ret = -ENOENT;
 		goto end;
 	}
Signature · 1 line
2.37.1
#6 lore raw

PATCH v2 6/29 arm: imx: Use log_err for errors in read_auth_container

In reply to Sean Anderson

To allow for more flexible handling of errors, use log_err instead of printf.

---

Changes in v2:
- New

 arch/arm/mach-imx/parse-container.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm/mach-imx/parse-container.c +3 -2
index c5df78d1c58..48cffb3ab4d 100644
@@ -3,6 +3,7 @@
  * Copyright 2018-2021 NXP
  */
 
+#define LOG_CATEGORY LOGC_ARCH
 #include <common.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -85,13 +86,13 @@ static int read_auth_container(struct spl_image_info *spl_image,
 	}
 
 	if (container->tag != 0x87 && container->version != 0x0) {
-		printf("Wrong container header\n");
+		log_err("Wrong container header\n");
 		ret = -ENOENT;
 		goto end;
 	}
 
 	if (!container->num_images) {
-		printf("Wrong container, no image found\n");
+		log_err("Wrong container, no image found\n");
 		ret = -ENOENT;
 		goto end;
 	}
Signature · 1 line
2.37.1
#7 lore raw

PATCH v2 7/29 arm: imx: Add function to validate i.MX8 containers

In reply to Sean Anderson

Add a function to abstract the common task of validating i.MX8 container image headers.

---

(no changes since v1)

 arch/arm/include/asm/mach-imx/image.h | 9 +++++++++
 arch/arm/mach-imx/ele_ahab.c          | 2 +-
 arch/arm/mach-imx/image-container.c   | 2 +-
 arch/arm/mach-imx/imx8/ahab.c         | 2 +-
 arch/arm/mach-imx/parse-container.c   | 2 +-
 arch/arm/mach-imx/spl_imx_romapi.c    | 3 ++-
 6 files changed, 15 insertions(+), 5 deletions(-)
arch/arm/include/asm/mach-imx/image.h +9 -0
index ee67ca96f4c..54cd684e35d 100644
@@ -18,6 +18,9 @@
 #define CONTAINER_HDR_QSPI_OFFSET SZ_4K
 #define CONTAINER_HDR_NAND_OFFSET SZ_128M
 
+#define CONTAINER_HDR_TAG 0x87
+#define CONTAINER_HDR_VERSION 0
+
 struct container_hdr {
 	u8 version;
 	u8 length_lsb;
@@ -66,4 +69,10 @@ struct generate_key_blob_hdr {
 } __packed;
 
 int get_container_size(ulong addr, u16 *header_length);
+
+static inline bool valid_container_hdr(struct container_hdr *container)
+{
+	return container->tag == CONTAINER_HDR_TAG &&
+	       container->version == CONTAINER_HDR_VERSION;
+}
 #endif
arch/arm/mach-imx/ele_ahab.c +1 -1
index 785b0d6ec3c..6a1ad198f89 100644
@@ -343,7 +343,7 @@ int authenticate_os_container(ulong addr)
 	}
 
 	phdr = (struct container_hdr *)addr;
-	if (phdr->tag != 0x87 || phdr->version != 0x0) {
+	if (!valid_container_hdr(phdr)) {
 		printf("Error: Wrong container header\n");
 		return -EFAULT;
 	}
arch/arm/mach-imx/image-container.c +1 -1
index 5f188ab32d1..eff9e0c4597 100644
@@ -50,7 +50,7 @@ int get_container_size(ulong addr, u16 *header_length)
 	u32 max_offset = 0, img_end;
 
 	phdr = (struct container_hdr *)addr;
-	if (phdr->tag != 0x87 || phdr->version != 0x0) {
+	if (!valid_container_hdr(phdr)) {
 		debug("Wrong container header\n");
 		return -EFAULT;
 	}
arch/arm/mach-imx/imx8/ahab.c +1 -1
index b58b14ca9b4..44ea63584aa 100644
@@ -146,7 +146,7 @@ int authenticate_os_container(ulong addr)
 	}
 
 	phdr = (struct container_hdr *)addr;
-	if (phdr->tag != 0x87 && phdr->version != 0x0) {
+	if (!valid_container_hdr(phdr)) {
 		printf("Error: Wrong container header\n");
 		return -EFAULT;
 	}
arch/arm/mach-imx/parse-container.c +1 -1
index 48cffb3ab4d..d57f25df6dc 100644
@@ -85,7 +85,7 @@ static int read_auth_container(struct spl_image_info *spl_image,
 		goto end;
 	}
 
-	if (container->tag != 0x87 && container->version != 0x0) {
+	if (!valid_container_hdr(container)) {
 		log_err("Wrong container header\n");
 		ret = -ENOENT;
 		goto end;
arch/arm/mach-imx/spl_imx_romapi.c +2 -1
index 4af41699678..b51061b987b 100644
@@ -184,7 +184,8 @@ static u8 *search_container_header(u8 *p, int size)
 
 	for (i = 0; i < size; i += 4) {
 		hdr = p + i;
-		if (*(hdr + 3) == 0x87 && *hdr == 0 && (*(hdr + 1) != 0 || *(hdr + 2) != 0))
+		if (valid_container_hdr((void *)hdr) &&
+		    (*(hdr + 1) != 0 || *(hdr + 2) != 0))
 			return p + i;
 	}
 
Signature · 1 line
2.37.1
#8 lore raw

PATCH v2 8/29 arm: imx: Check header before calling spl_load_imx_container

In reply to Sean Anderson

Make sure we have an IMX header before calling spl_load_imx_container, since if we don't it will fail with -ENOENT. This allows us to fall back to legacy/raw images if they are also enabled.

This is a functional change, one which likely should have been in place from the start, but a functional change nonetheless. Previously, all non-IMX8 images (except FITs without FIT_FULL) would be optimized out if the only image load method enabled supported IMX8 images. With this change, support for other image types now has an effect.

There are seven boards with SPL_LOAD_IMX_CONTAINER enabled: three with SPL_BOOTROM_SUPPORT:

    imx93_11x11_evk_ld imx93_11x11_evk imx8ulp_evk

and four with SPL_MMC:

deneb imx8qxp_mek giedi imx8qm_mek

All of these boards also have SPL_RAW_IMAGE_SUPPORT and SPL_LEGACY_IMAGE_FORMAT enabled as well. However, none have FIT support enabled. Of the six load methods affected by this patch, only SPL_MMC and SPL_BOOTROM_SUPPORT are enabled with SPL_LOAD_IMX_CONTAINER. spl_romapi_load_image_seekable does not support legacy or raw images, so there is no growth. However, mmc_load_image_raw_sector does support loading legacy/raw images. Since these images could not have been booted before, I have disabled support for legacy/raw images on these four boards. This reduces bloat from around 800 bytes to around 200.

There are no in-tree boards with SPL_LOAD_IMX_CONTAINER and AHAB_BOOT both enabled, so we do not need to worry about potentially falling back to legacy images in a secure boot scenario.

Future work could include merging imx_container.h with imx8image.h, since they appear to define mostly the same structures.

---

Changes in v2:
- Clarify commit message

 MAINTAINERS                                                  | 1 +
 arch/arm/include/asm/mach-imx/ahab.h                         | 2 +-
 arch/arm/mach-imx/cmd_dek.c                                  | 4 ++--
 arch/arm/mach-imx/ele_ahab.c                                 | 2 +-
 arch/arm/mach-imx/image-container.c                          | 2 +-
 arch/arm/mach-imx/imx8/ahab.c                                | 2 +-
 arch/arm/mach-imx/parse-container.c                          | 2 +-
 arch/arm/mach-imx/spl_imx_romapi.c                           | 5 +++--
 common/spl/spl_mmc.c                                         | 4 +++-
 common/spl/spl_nand.c                                        | 4 +++-
 common/spl/spl_nor.c                                         | 4 +++-
 common/spl/spl_spi.c                                         | 4 +++-
 configs/deneb_defconfig                                      | 2 ++
 configs/giedi_defconfig                                      | 2 ++
 configs/imx8qm_mek_defconfig                                 | 2 ++
 configs/imx8qxp_mek_defconfig                                | 2 ++
 drivers/usb/gadget/f_sdp.c                                   | 4 +++-
 .../include/asm/mach-imx/image.h => include/imx_container.h  | 0
 18 files changed, 34 insertions(+), 14 deletions(-)
 rename arch/arm/include/asm/mach-imx/image.h => include/imx_container.h (100%)
MAINTAINERS +1 -0
index 7d5d05320c0..35209e73af5 100644
@@ -300,6 +300,7 @@ F:	arch/arm/include/asm/mach-imx/
 F:	board/freescale/*mx*/
 F:	board/freescale/common/
 F:	drivers/serial/serial_mxc.c
+F:	include/imx_container.h
 
 ARM HISILICON
 M:	Peter Griffin <[email protected]>
arch/arm/include/asm/mach-imx/ahab.h +1 -1
index 4222e3db278..4884f056251 100644
@@ -6,7 +6,7 @@
 #ifndef __IMX_AHAB_H__
 #define __IMX_AHAB_H__
 
-#include <asm/mach-imx/image.h>
+#include <imx_container.h>
 
 int ahab_auth_cntr_hdr(struct container_hdr *container, u16 length);
 int ahab_auth_release(void);
arch/arm/mach-imx/cmd_dek.c +2 -2
index 6fa5b41fcd3..2f389dbe8df 100644
@@ -18,12 +18,12 @@
 #include <mapmem.h>
 #include <tee.h>
 #ifdef CONFIG_IMX_SECO_DEK_ENCAP
+#include <imx_container.h>
 #include <firmware/imx/sci/sci.h>
-#include <asm/mach-imx/image.h>
 #endif
 #ifdef CONFIG_IMX_ELE_DEK_ENCAP
+#include <imx_container.h>
 #include <asm/mach-imx/ele_api.h>
-#include <asm/mach-imx/image.h>
 #endif
 
 #include <cpu_func.h>
arch/arm/mach-imx/ele_ahab.c +1 -1
index 6a1ad198f89..295c055ad0a 100644
@@ -6,12 +6,12 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
+#include <imx_container.h>
 #include <asm/io.h>
 #include <asm/mach-imx/ele_api.h>
 #include <asm/mach-imx/sys_proto.h>
 #include <asm/arch-imx/cpu.h>
 #include <asm/arch/sys_proto.h>
-#include <asm/mach-imx/image.h>
 #include <console.h>
 #include <cpu_func.h>
 #include <asm/global_data.h>
arch/arm/mach-imx/image-container.c +1 -1
index eff9e0c4597..ebc8021d7cc 100644
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <errno.h>
+#include <imx_container.h>
 #include <log.h>
 #include <malloc.h>
 #include <asm/io.h>
@@ -12,7 +13,6 @@
 #include <spi_flash.h>
 #include <spl.h>
 #include <nand.h>
-#include <asm/mach-imx/image.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/mach-imx/boot_mode.h>
 
arch/arm/mach-imx/imx8/ahab.c +1 -1
index 44ea63584aa..994becccefd 100644
@@ -6,6 +6,7 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
+#include <imx_container.h>
 #include <log.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
@@ -13,7 +14,6 @@
 #include <asm/mach-imx/sys_proto.h>
 #include <asm/arch-imx/cpu.h>
 #include <asm/arch/sys_proto.h>
-#include <asm/mach-imx/image.h>
 #include <console.h>
 #include <cpu_func.h>
 #include "u-boot/sha256.h"
arch/arm/mach-imx/parse-container.c +1 -1
index d57f25df6dc..c29cb15f55e 100644
@@ -7,9 +7,9 @@
 #include <common.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <imx_container.h>
 #include <log.h>
 #include <spl.h>
-#include <asm/mach-imx/image.h>
 #ifdef CONFIG_AHAB_BOOT
 #include <asm/mach-imx/ahab.h>
 #endif
arch/arm/mach-imx/spl_imx_romapi.c +3 -2
index b51061b987b..8816566b364 100644
@@ -6,11 +6,11 @@
 #include <common.h>
 #include <errno.h>
 #include <image.h>
+#include <imx_container.h>
 #include <log.h>
 #include <asm/global_data.h>
 #include <linux/libfdt.h>
 #include <spl.h>
-#include <asm/mach-imx/image.h>
 #include <asm/arch/sys_proto.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -111,7 +111,8 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image,
 		load.read = spl_romapi_read_seekable;
 		load.priv = &pagesize;
 		return spl_load_simple_fit(spl_image, &load, offset / pagesize, header);
-	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+		   valid_container_hdr((void *)header)) {
 		struct spl_load_info load;
 
 		memset(&load, 0, sizeof(load));
common/spl/spl_mmc.c +3 -1
index 02ad32a23e0..67c7ae34a58 100644
@@ -16,6 +16,7 @@
 #include <errno.h>
 #include <mmc.h>
 #include <image.h>
+#include <imx_container.h>
 
 static int mmc_load_legacy(struct spl_image_info *spl_image,
 			   struct spl_boot_device *bootdev,
@@ -108,7 +109,8 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
 		load.bl_len = mmc->read_bl_len;
 		load.read = h_spl_load_read;
 		ret = spl_load_simple_fit(spl_image, &load, sector, header);
-	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+		   valid_container_hdr((void *)header)) {
 		struct spl_load_info load;
 
 		load.dev = mmc;
common/spl/spl_nand.c +3 -1
index 6cc34004f49..07916bedbb9 100644
@@ -7,6 +7,7 @@
 #include <config.h>
 #include <fdt_support.h>
 #include <image.h>
+#include <imx_container.h>
 #include <log.h>
 #include <spl.h>
 #include <asm/io.h>
@@ -99,7 +100,8 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		load.bl_len = bl_len;
 		load.read = spl_nand_fit_read;
 		return spl_load_simple_fit(spl_image, &load, offset / bl_len, header);
-	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+		   valid_container_hdr((void *)header)) {
 		struct spl_load_info load;
 
 		load.dev = NULL;
common/spl/spl_nor.c +3 -1
index c141a9ae629..dd447982071 100644
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <image.h>
+#include <imx_container.h>
 #include <log.h>
 #include <spl.h>
 
@@ -102,7 +103,8 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 					   (void *)header);
 	}
 #endif
-	if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+	if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+	    valid_container_hdr((void *)header)) {
 		load.bl_len = 1;
 		load.read = spl_nor_load_read;
 		return spl_load_imx_container(spl_image, &load,
common/spl/spl_spi.c +3 -1
index d69069a75bf..1427c9478c0 100644
@@ -10,6 +10,7 @@
 
 #include <common.h>
 #include <image.h>
+#include <imx_container.h>
 #include <log.h>
 #include <spi.h>
 #include <spi_flash.h>
@@ -153,7 +154,8 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 			err = spl_load_simple_fit(spl_image, &load,
 						  payload_offs,
 						  header);
-		} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+		} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+			   valid_container_hdr((void *)header)) {
 			struct spl_load_info load;
 
 			load.dev = flash;
configs/deneb_defconfig +2 -0
index 82869e4e0f9..ee2478aa0bb 100644
@@ -44,6 +44,8 @@ CONFIG_SPL_HAS_BSS_LINKER_SECTION=y
 CONFIG_SPL_BSS_START_ADDR=0x128000
 CONFIG_SPL_BSS_MAX_SIZE=0x1000
 CONFIG_SPL_BOARD_INIT=y
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
+# CONFIG_SPL_LEGACY_IMAGE_FORMAT is not set
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 # CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
 CONFIG_SPL_SYS_MALLOC=y
configs/giedi_defconfig +2 -0
index b56b736c436..5e403c90c8c 100644
@@ -44,6 +44,8 @@ CONFIG_SPL_HAS_BSS_LINKER_SECTION=y
 CONFIG_SPL_BSS_START_ADDR=0x128000
 CONFIG_SPL_BSS_MAX_SIZE=0x1000
 CONFIG_SPL_BOARD_INIT=y
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
+# CONFIG_SPL_LEGACY_IMAGE_FORMAT is not set
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 # CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
 CONFIG_SPL_SYS_MALLOC=y
configs/imx8qm_mek_defconfig +2 -0
index b9083b0453f..4c5206306ee 100644
@@ -38,6 +38,8 @@ CONFIG_SPL_HAS_BSS_LINKER_SECTION=y
 CONFIG_SPL_BSS_START_ADDR=0x128000
 CONFIG_SPL_BSS_MAX_SIZE=0x1000
 CONFIG_SPL_BOARD_INIT=y
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
+# CONFIG_SPL_LEGACY_IMAGE_FORMAT is not set
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 # CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
 CONFIG_SPL_SYS_MALLOC=y
configs/imx8qxp_mek_defconfig +2 -0
index f516b0b5557..f312d3945fb 100644
@@ -38,6 +38,8 @@ CONFIG_SPL_HAS_BSS_LINKER_SECTION=y
 CONFIG_SPL_BSS_START_ADDR=0x128000
 CONFIG_SPL_BSS_MAX_SIZE=0x1000
 CONFIG_SPL_BOARD_INIT=y
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
+# CONFIG_SPL_LEGACY_IMAGE_FORMAT is not set
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 # CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
 CONFIG_SPL_SYS_MALLOC=y
drivers/usb/gadget/f_sdp.c +3 -1
index 2b3a9c5fd4c..ee9384fb37e 100644
@@ -34,6 +34,7 @@
 #include <spl.h>
 #include <image.h>
 #include <imximage.h>
+#include <imx_container.h>
 #include <watchdog.h>
 
 #define HID_REPORT_ID_MASK	0x000000ff
@@ -852,7 +853,8 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
 				return SDP_EXIT;
 			}
 #endif
-			if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+			if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+			    valid_container_hdr((void *)header)) {
 				struct spl_load_info load;
 
 				load.dev = header;
include/imx_container.h renamed from arch/arm/include/asm/mach-imx/image.h +0 -0
similarity index 100%
rename from arch/arm/include/asm/mach-imx/image.h
rename to include/imx_container.h
Signature · 1 line
2.37.1
#9 lore raw

PATCH v2 9/29 Move i.MX8 container image loading support to common/spl

In reply to Sean Anderson

To facilitate testing loading i.MX8 container images, move the parse-container code to common/spl.

---

(no changes since v1)

 MAINTAINERS                                        |  1 +
 arch/arm/mach-imx/Kconfig                          | 13 -------------
 arch/arm/mach-imx/Makefile                         |  2 +-
 common/spl/Kconfig                                 | 14 ++++++++++++++
 common/spl/Makefile                                |  1 +
 .../spl/spl_imx_container.c                        |  0
 6 files changed, 17 insertions(+), 14 deletions(-)
 rename arch/arm/mach-imx/parse-container.c => common/spl/spl_imx_container.c (100%)
MAINTAINERS +1 -0
index 35209e73af5..dd6bb558dc4 100644
@@ -299,6 +299,7 @@ F:	arch/arm/include/asm/arch-vf610/
 F:	arch/arm/include/asm/mach-imx/
 F:	board/freescale/*mx*/
 F:	board/freescale/common/
+F:	common/spl/spl_imx_container.c
 F:	drivers/serial/serial_mxc.c
 F:	include/imx_container.h
 
arch/arm/mach-imx/Kconfig +0 -13
index 266bb20df9d..08ab7069187 100644
@@ -194,19 +194,6 @@ config IMX_DCD_ADDR
 	  This information is shared with the user via mkimage -l just so the
 	  image can be signed.
 
-config SPL_LOAD_IMX_CONTAINER
-	bool "Enable SPL loading U-Boot as a i.MX Container image"
-	depends on SPL
-	help
-	  This is to let SPL could load i.MX Container image
-
-config IMX_CONTAINER_CFG
-	string "i.MX Container config file"
-	depends on SPL
-	help
-	  This is to specific the cfg file for generating container
-	  image which will be loaded by SPL.
-
 config IOMUX_LPSR
 	bool
 
arch/arm/mach-imx/Makefile +1 -1
index aebfa6517bd..7c4e03278e3 100644
@@ -79,7 +79,7 @@ obj-$(CONFIG_CMD_NANDBCB) += cmd_nandbcb.o
 endif
 
 ifeq ($(CONFIG_SPL_BUILD),y)
-obj-$(CONFIG_SPL_LOAD_IMX_CONTAINER) += image-container.o parse-container.o
+obj-$(CONFIG_SPL_LOAD_IMX_CONTAINER) += image-container.o
 endif
 
 ifeq ($(SOC),$(filter $(SOC),imx8ulp imx9))
common/spl/Kconfig +14 -0
index 46323597942..ad574a600e3 100644
@@ -330,6 +330,20 @@ config SPL_LEGACY_IMAGE_CRC_CHECK
 	  If disabled, Legacy images are booted if the image magic and size
 	  are correct, without further integrity checks.
 
+config SPL_LOAD_IMX_CONTAINER
+	bool "Enable SPL loading and booting of i.MX8 Containers"
+	depends on SPL
+	help
+	  Support booting U-Boot from an i.MX8 container image. If you are not
+	  using i.MX8, say 'n'.
+
+config IMX_CONTAINER_CFG
+	string "i.MX8 Container config file"
+	depends on SPL && SPL_LOAD_IMX_CONTAINER
+	help
+	  Specify the cfg file for generating the container image which will be
+	  loaded by SPL.
+
 config SPL_SYS_MALLOC_SIMPLE
 	bool "Only use malloc_simple functions in the SPL"
 	help
common/spl/Makefile +1 -0
index bad2bbf6cf1..4f8eb2ec0ca 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_$(SPL_TPL_)OPENSBI) += spl_opensbi.o
 obj-$(CONFIG_$(SPL_TPL_)USB_STORAGE) += spl_usb.o
 obj-$(CONFIG_$(SPL_TPL_)FS_FAT) += spl_fat.o
 obj-$(CONFIG_$(SPL_TPL_)FS_EXT4) += spl_ext.o
+obj-$(CONFIG_$(SPL_TPL_)LOAD_IMX_CONTAINER) += spl_imx_container.o
 obj-$(CONFIG_$(SPL_TPL_)SATA) += spl_sata.o
 obj-$(CONFIG_$(SPL_TPL_)NVME) += spl_nvme.o
 obj-$(CONFIG_$(SPL_TPL_)SEMIHOSTING) += spl_semihosting.o
common/spl/spl_imx_container.c renamed from arch/arm/mach-imx/parse-container.c +0 -0
similarity index 100%
rename from arch/arm/mach-imx/parse-container.c
rename to common/spl/spl_imx_container.c
Signature · 1 line
2.37.1
#10 lore raw

PATCH v2 10/29 spl: Allow enabling SPL_OF_REAL and SPL_OF_PLATDATA at the same time

In reply to Sean Anderson

Sandbox unit tests in U-Boot proper load a test device tree to have some devices to work with. In order to do the same in SPL, we must enable SPL_OF_REAL. However, we already have SPL_OF_PLATDATA enabled. When generating platdata from a devicetree, it is expected that we will not need devicetree access functions (even though SPL_OF_CONTROL is enabled). This expectation does not hold for sandbox, so allow user control of SPL_OF_REAL.

There are several places in the tree where conditions involving OF_PLATDATA or OF_REAL no longer function correctly when both of these options can be selected at the same time. Adjust these conditions accordingly.

---

Changes in v2:
- Hide SPL_OF_REAL unless SANDBOX is enabled

 drivers/core/Makefile               | 1 +
 drivers/i2c/i2c-emul-uclass.c       | 2 +-
 drivers/serial/sandbox.c            | 2 +-
 drivers/sysreset/sysreset_sandbox.c | 2 +-
 dts/Kconfig                         | 8 +++++---
 test/test-main.c                    | 2 +-
 6 files changed, 10 insertions(+), 7 deletions(-)
drivers/core/Makefile +1 -0
index bce0a3f65cb..acbd2bf2cef 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_$(SPL_)OF_LIVE) += of_access.o of_addr.o
 ifndef CONFIG_DM_DEV_READ_INLINE
 obj-$(CONFIG_OF_CONTROL) += read.o
 endif
+obj-$(CONFIG_$(SPL_)OF_PLATDATA) += read.o
 obj-$(CONFIG_OF_CONTROL) += of_extra.o ofnode.o read_extra.o
 
 ccflags-$(CONFIG_DM_DEBUG) += -DDEBUG
drivers/i2c/i2c-emul-uclass.c +1 -1
index 1107cf309fc..d421ddfcbe2 100644
@@ -46,7 +46,7 @@ int i2c_emul_find(struct udevice *dev, struct udevice **emulp)
 	struct udevice *emul;
 	int ret;
 
-	if (!CONFIG_IS_ENABLED(OF_PLATDATA)) {
+	if (CONFIG_IS_ENABLED(OF_REAL)) {
 		ret = uclass_find_device_by_phandle(UCLASS_I2C_EMUL, dev,
 						    "sandbox,emul", &emul);
 	} else {
drivers/serial/sandbox.c +1 -1
index f4003811ee7..f6ac3d22852 100644
@@ -280,7 +280,7 @@ U_BOOT_DRIVER(sandbox_serial) = {
 	.flags = DM_FLAG_PRE_RELOC,
 };
 
-#if CONFIG_IS_ENABLED(OF_REAL)
+#if CONFIG_IS_ENABLED(OF_REAL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 static const struct sandbox_serial_plat platdata_non_fdt = {
 	.colour = -1,
 };
drivers/sysreset/sysreset_sandbox.c +1 -1
index 3750c60b9b9..f485a135299 100644
@@ -132,7 +132,7 @@ U_BOOT_DRIVER(warm_sysreset_sandbox) = {
 	.ops		= &sandbox_warm_sysreset_ops,
 };
 
-#if CONFIG_IS_ENABLED(OF_REAL)
+#if CONFIG_IS_ENABLED(OF_REAL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 /* This is here in case we don't have a device tree */
 U_BOOT_DRVINFO(sysreset_sandbox_non_fdt) = {
 	.name = "sysreset_sandbox",
dts/Kconfig +5 -3
index 9152f5885e9..00c0aeff893 100644
@@ -410,12 +410,14 @@ config SPL_OF_PLATDATA
 	  declarations for each node. See of-plat.txt for more information.
 
 config SPL_OF_REAL
-	bool
+	bool "Support a real devicetree in SPL" if SANDBOX
+	depends on SPL_OF_CONTROL
+	select SPL_OF_LIBFDT
 	help
 	  Indicates that a real devicetree is available which can be accessed
 	  at runtime. This means that dev_read_...() functions can be used to
-	  read data from the devicetree for each device. This is true if
-	  SPL_OF_CONTROL is enabled and not SPL_OF_PLATDATA
+	  read data from the devicetree for each device. You do not need to
+	  enable this option if you have enabled SPL_OF_PLATDATA.
 
 if SPL_OF_PLATDATA
 
test/test-main.c +1 -1
index edb20bc4b9c..b7015d9f38d 100644
@@ -303,7 +303,7 @@ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
 	if (test->flags & UT_TESTF_PROBE_TEST)
 		ut_assertok(do_autoprobe(uts));
 
-	if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
+	if (CONFIG_IS_ENABLED(OF_REAL) &&
 	    (test->flags & UT_TESTF_SCAN_FDT)) {
 		/*
 		 * only set this if we know the ethernet uclass will be created
Signature · 1 line
2.37.1
#11 lore raw

PATCH v2 11/29 lib: acpi: Fix linking SPL when ACPIGEN is enabled

In reply to Sean Anderson

lib/acpi/acpigen.o is only compiled into SPL when SPL_ACPIGEN is enabled. Update several files which reference these functions accordingly.

---

(no changes since v1)

 drivers/core/root.c  | 2 +-
 drivers/i2c/Makefile | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/core/root.c +1 -1
index 126b3140666..d4ae652bcfb 100644
@@ -426,7 +426,7 @@ void dm_get_mem(struct dm_stats *stats)
 		stats->tag_size;
 }
 
-#ifdef CONFIG_ACPIGEN
+#if CONFIG_IS_ENABLED(ACPIGEN)
 static int root_acpi_get_name(const struct udevice *dev, char *out_name)
 {
 	return acpi_copy_name(out_name, "\\_SB");
drivers/i2c/Makefile +1 -1
index d5b85f398db..a96a8c7e955 100644
@@ -3,7 +3,7 @@
 # (C) Copyright 2000-2007
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 obj-$(CONFIG_$(SPL_)DM_I2C) += i2c-uclass.o
-ifdef CONFIG_ACPIGEN
+ifdef CONFIG_$(SPL_)ACPIGEN
 obj-$(CONFIG_$(SPL_)DM_I2C) += acpi_i2c.o
 endif
 obj-$(CONFIG_$(SPL_)DM_I2C_GPIO) += i2c-gpio.o
Signature · 1 line
2.37.1
#12 lore raw

PATCH v2 12/29 fs: Disable sandbox filesystem in SPL

In reply to Sean Anderson

Don't bother compiling the sandbox filesystem in SPL for now, as it is not needed.

---

Changes in v2:
- Disable sandbox filesystem in SPL instead of compiling it in

 fs/fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fs.c +1 -1
index cfc781bbb8d..4cb4310c9cc 100644
@@ -237,7 +237,7 @@ static struct fstype_info fstypes[] = {
 		.mkdir = fs_mkdir_unsupported,
 	},
 #endif
-#ifdef CONFIG_SANDBOX
+#if IS_ENABLED(CONFIG_SANDBOX) && !IS_ENABLED(CONFIG_SPL_BUILD)
 	{
 		.fstype = FS_TYPE_SANDBOX,
 		.name = "sandbox",
Signature · 1 line
2.37.1
#13 lore raw

Re: [PATCH v2 12/29] fs: Disable sandbox filesystem in SPL

Am 14. Oktober 2023 22:47:48 MESZ schrieb Sean Anderson <[email protected]>:

Quoted 17 lines

Don't bother compiling the sandbox filesystem in SPL for now, as it is not needed.

---

Changes in v2:
- Disable sandbox filesystem in SPL instead of compiling it in

fs/fs.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
fs/fs.c +0 -0
index cfc781bbb8d..4cb4310c9cc 100644

fs/fs.c static struct fstype_info fstypes[] = { · line 240

Quoted 5 lines
fs/fs.c +1 -1
@@ -237,7 +237,7 @@ static struct fstype_info fstypes[] = {
 		.mkdir = fs_mkdir_unsupported,
 	},
 #endif
-#ifdef CONFIG_SANDBOX
+#if IS_ENABLED(CONFIG_SANDBOX) && !IS_ENABLED(CONFIG_SPL_BUILD)

Why do would you disable the sandbox file system in SPL for CONFIG_SANDBOX_SPL=y?

I cannot see that this is necessary to enable the unit tests you are striving for. Instead we should extend the SPL unit tests to sandbox_spl_defconfig in the long run.

Best regards

Heinrich

Quoted 3 lines
fs/fs.c +0 -0
 	{
 		.fstype = FS_TYPE_SANDBOX,
 		.name = "sandbox",
#14 lore raw

Re: [PATCH v2 12/29] fs: Disable sandbox filesystem in SPL

Quoted 15 lines · Heinrich Schuchardt

Am 14. Oktober 2023 22:47:48 MESZ schrieb Sean Anderson <[email protected]>:

Quoted 12 lines

Don't bother compiling the sandbox filesystem in SPL for now, as it is not needed.

---

Changes in v2:
- Disable sandbox filesystem in SPL instead of compiling it in

fs/fs.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

fs/fs.c static struct fstype_info fstypes[] = { · line 240

Quoted 10 lines
fs/fs.c +1 -1
index cfc781bbb8d..4cb4310c9cc 100644
@@ -237,7 +237,7 @@ static struct fstype_info fstypes[] = {
 .mkdir = fs_mkdir_unsupported,
 },
 #endif
-#ifdef CONFIG_SANDBOX
+#if IS_ENABLED(CONFIG_SANDBOX) && !IS_ENABLED(CONFIG_SPL_BUILD)

Why do would you disable the sandbox file system in SPL for CONFIG_SANDBOX_SPL=y?

It was never enabled in the first place, since we never had fs.c compiled in SPL before. This just fixes linking.

Quoted 1 line

I cannot see that this is necessary to enable the unit tests you are striving for. Instead we should extend the SPL unit tests to sandbox_spl_defconfig in the long run.

The purpose of the sandbox filesystem is to test routines which use the filesystem API in U-Boot. However, there are very few which do so in SPL. SPL_FS_LOADER is the only one I know of off the top of my head. However, FS_LOADER is tested in U-Boot proper. I don't think there is a pressing need to enable the sandbox filesystem in SPL.

--Sean

Reviewed-by on v2 12/29
#15 lore raw

Re: [PATCH v2 12/29] fs: Disable sandbox filesystem in SPL

In reply to Sean Anderson
Quoted 4 lines · Sean Anderson

Don't bother compiling the sandbox filesystem in SPL for now, as it is not needed.

Quoted 8 lines

---

Changes in v2:
- Disable sandbox filesystem in SPL instead of compiling it in

 fs/fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#16 lore raw

PATCH v2 13/29 fs: ext4: Fix building ext4 in SPL if write is enabled

In reply to Sean Anderson

If EXT4_WRITE is enabled, write capabilities will be compiled into SPL, but not CRC16. Add an option to enable CRC16 to avoid linker errors.

---

(no changes since v1)

 common/spl/Kconfig | 1 +
 lib/Kconfig        | 6 ++++++
 lib/Makefile       | 1 +
 3 files changed, 8 insertions(+)
common/spl/Kconfig +1 -0
index ad574a600e3..6bc4066fad7 100644
@@ -657,6 +657,7 @@ config SPL_ETH
 
 config SPL_FS_EXT4
 	bool "Support EXT filesystems"
+	select SPL_CRC16 if EXT4_WRITE
 	help
 	  Enable support for EXT2/3/4 filesystems with SPL. This permits
 	  U-Boot (or Linux in Falcon mode) to be loaded from an EXT
lib/Kconfig +6 -0
index 79cf9ef0fa3..f6ca559897e 100644
@@ -687,6 +687,12 @@ config SPL_CRC8
 	  checksum with feedback to produce an 8-bit result. The code is small
 	  and it does not require a lookup table (unlike CRC32).
 
+config SPL_CRC16
+	bool "Support CRC16 in SPL"
+	depends on SPL
+	help
+	  Enables CRC16 support in SPL. This is not normally required.
+
 config CRC32
 	def_bool y
 	help
lib/Makefile +1 -0
index 1c31ad9531e..2a76acf100d 100644
@@ -64,6 +64,7 @@ obj-$(CONFIG_TPM_V2) += tpm-v2.o
 endif
 
 obj-$(CONFIG_$(SPL_TPL_)CRC8) += crc8.o
+obj-$(CONFIG_$(SPL_TPL_)CRC16) += crc16.o
 
 obj-y += crypto/
 
Signature · 1 line
2.37.1
#17 lore raw

PATCH v2 14/29 fs: ext4: Add some defines for testing

In reply to Sean Anderson

Add various defines which are not necessary for reading/writing filesystems, but which are useful for creating them. These mostly come from Linux v6.5-rc2 (what I had checked out).

---

Changes in v2:
- Split off from fs test

 include/ext4fs.h     |  1 +
 include/ext_common.h | 14 ++++++++++++++
 2 files changed, 15 insertions(+)
include/ext4fs.h +1 -0
index cb5d9cc0a5c..dd66d27f776 100644
@@ -31,6 +31,7 @@
 struct disk_partition;
 
 #define EXT4_INDEX_FL		0x00001000 /* Inode uses hash tree index */
+#define EXT4_TOPDIR_FL		0x00020000 /* Top of directory hierarchies*/
 #define EXT4_EXTENTS_FL		0x00080000 /* Inode uses extents */
 #define EXT4_EXT_MAGIC			0xf30a
 #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM	0x0010
include/ext_common.h +14 -0
index 30a0c248414..b09bbde116a 100644
@@ -35,6 +35,16 @@ struct cmd_tbl;
 #define EXT2_PATH_MAX				4096
 /* Maximum nesting of symlinks, used to prevent a loop.  */
 #define	EXT2_MAX_SYMLINKCNT		8
+/* Maximum file name length */
+#define EXT2_NAME_LEN 255
+
+/*
+ * Revision levels
+ */
+#define EXT2_GOOD_OLD_REV	0	/* The good old (original) format */
+#define EXT2_DYNAMIC_REV	1	/* V2 format w/ dynamic inode sizes */
+
+#define EXT2_GOOD_OLD_INODE_SIZE 128
 
 /* Filetype used in directory entry.  */
 #define	FILETYPE_UNKNOWN		0
@@ -48,6 +58,10 @@ struct cmd_tbl;
 #define FILETYPE_INO_DIRECTORY		0040000
 #define FILETYPE_INO_SYMLINK		0120000
 #define EXT2_ROOT_INO			2 /* Root inode */
+#define EXT2_BOOT_LOADER_INO		5 /* Boot loader inode */
+
+/* First non-reserved inode for old ext2 filesystems */
+#define EXT2_GOOD_OLD_FIRST_INO	11
 
 /* The size of an ext2 block in bytes.  */
 #define EXT2_BLOCK_SIZE(data)	   (1 << LOG2_BLOCK_SIZE(data))
Signature · 1 line
2.37.1
Reviewed-by on v2 14/29
#18 lore raw

Re: [PATCH v2 14/29] fs: ext4: Add some defines for testing

Quoted 6 lines · Sean Anderson

Add various defines which are not necessary for reading/writing filesystems, but which are useful for creating them. These mostly come from Linux v6.5-rc2 (what I had checked out).

Quoted 8 lines

---

Changes in v2:
- Split off from fs test

 include/ext4fs.h     |  1 +
 include/ext_common.h | 14 ++++++++++++++
 2 files changed, 15 insertions(+)
#19 lore raw

PATCH v2 15/29 net: Fix compiling SPL when fastboot is enabled

In reply to Sean Anderson

When fastboot is enabled in U-Boot proper and SPL_NET is enabled, we will try to (unsuccessfully) reference it in SPL. Fix these linker errors by conditioning on SPL_UDP/TCP_FUNCTION_FASTBOOT.

---

Changes in v2:
- Use SPL_TPL_ for compiling fastboot functions

 net/Makefile | 4 ++--
 net/net.c    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
net/Makefile +2 -2
index 3e2d061338d..64ab7ec740a 100644
@@ -27,8 +27,8 @@ obj-$(CONFIG_CMD_PCAP) += pcap.o
 obj-$(CONFIG_CMD_RARP) += rarp.o
 obj-$(CONFIG_CMD_SNTP) += sntp.o
 obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
-obj-$(CONFIG_UDP_FUNCTION_FASTBOOT)  += fastboot_udp.o
-obj-$(CONFIG_TCP_FUNCTION_FASTBOOT)  += fastboot_tcp.o
+obj-$(CONFIG_$(SPL_TPL_)UDP_FUNCTION_FASTBOOT)  += fastboot_udp.o
+obj-$(CONFIG_$(SPL_TPL_)TCP_FUNCTION_FASTBOOT)  += fastboot_tcp.o
 obj-$(CONFIG_CMD_WOL)  += wol.o
 obj-$(CONFIG_PROT_UDP) += udp.o
 obj-$(CONFIG_PROT_TCP) += tcp.o
net/net.c +2 -2
index e6f61f0f8f6..8357f084101 100644
@@ -511,12 +511,12 @@ restart:
 			tftp_start_server();
 			break;
 #endif
-#if defined(CONFIG_UDP_FUNCTION_FASTBOOT)
+#if CONFIG_IS_ENABLED(UDP_FUNCTION_FASTBOOT)
 		case FASTBOOT_UDP:
 			fastboot_udp_start_server();
 			break;
 #endif
-#if defined(CONFIG_TCP_FUNCTION_FASTBOOT)
+#if CONFIG_IS_ENABLED(TCP_FUNCTION_FASTBOOT)
 		case FASTBOOT_TCP:
 			fastboot_tcp_start_server();
 			break;
Signature · 1 line
2.37.1
#20 lore raw

PATCH v2 16/29 net: bootp: Move port numbers to header

In reply to Sean Anderson

These defines are useful when testing bootp.

---

(no changes since v1)

 net/bootp.c | 3 ---
 net/bootp.h | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)
net/bootp.c +0 -3
index 8b1a4ae2ef8..2053cce88c6 100644
@@ -41,9 +41,6 @@
  */
 #define TIMEOUT_MS	((3 + (CONFIG_NET_RETRY_COUNT * 5)) * 1000)
 
-#define PORT_BOOTPS	67		/* BOOTP server UDP port */
-#define PORT_BOOTPC	68		/* BOOTP client UDP port */
-
 #ifndef CFG_DHCP_MIN_EXT_LEN		/* minimal length of extension list */
 #define CFG_DHCP_MIN_EXT_LEN 64
 #endif
net/bootp.h +3 -0
index 567340ec5d4..4e32b19d424 100644
@@ -15,6 +15,9 @@
 
 /**********************************************************************/
 
+#define PORT_BOOTPS	67		/* BOOTP server UDP port */
+#define PORT_BOOTPC	68		/* BOOTP client UDP port */
+
 /*
  *	BOOTP header.
  */
Signature · 1 line
2.37.1
#21 lore raw

Re: [PATCH v2 16/29] net: bootp: Move port numbers to header

Am 14. Oktober 2023 22:47:52 MESZ schrieb Sean Anderson <[email protected]>:

Quoted 32 lines

These defines are useful when testing bootp.

---

(no changes since v1)

net/bootp.c | 3 ---
net/bootp.h | 3 +++

2 files changed, 3 insertions(+), 3 deletions(-)
net/bootp.c +0 -3
index 8b1a4ae2ef8..2053cce88c6 100644
@@ -41,9 +41,6 @@
 */
 #define TIMEOUT_MS	((3 + (CONFIG_NET_RETRY_COUNT * 5)) * 1000)
 
-#define PORT_BOOTPS	67		/* BOOTP server UDP port */
-#define PORT_BOOTPC	68		/* BOOTP client UDP port */
-
 #ifndef CFG_DHCP_MIN_EXT_LEN		/* minimal length of extension list */
 #define CFG_DHCP_MIN_EXT_LEN 64
 #endif
net/bootp.h +0 -0
index 567340ec5d4..4e32b19d424 100644

net/bootp.h line 18

Quoted 4 lines
net/bootp.h +1 -0
@@ -15,6 +15,9 @@
 
 /**********************************************************************/
 
+#define PORT_BOOTPS	67		/* BOOTP server UDP port */

Reading code I would have a hard time to immediately see what this constant name stands for.

Shouldn't this be renamed BOOTP_SERVER_PORT to create readable code?

Regards Heinrich

Quoted 5 lines
net/bootp.h +2 -0
+#define PORT_BOOTPC	68		/* BOOTP client UDP port */
+
 /*
 *	BOOTP header.
 */
#22 lore raw

Re: [PATCH v2 16/29] net: bootp: Move port numbers to header

Quoted 36 lines · Heinrich Schuchardt

Am 14. Oktober 2023 22:47:52 MESZ schrieb Sean Anderson <[email protected]>:

Quoted 33 lines

These defines are useful when testing bootp.

---

(no changes since v1)

net/bootp.c | 3 ---
net/bootp.h | 3 +++

2 files changed, 3 insertions(+), 3 deletions(-)
net/bootp.c +0 -3
index 8b1a4ae2ef8..2053cce88c6 100644
@@ -41,9 +41,6 @@
 */
 #define TIMEOUT_MS	((3 + (CONFIG_NET_RETRY_COUNT * 5)) * 1000)
 
-#define PORT_BOOTPS	67		/* BOOTP server UDP port */
-#define PORT_BOOTPC	68		/* BOOTP client UDP port */
-
 #ifndef CFG_DHCP_MIN_EXT_LEN		/* minimal length of extension list */
 #define CFG_DHCP_MIN_EXT_LEN 64
 #endif
net/bootp.h +0 -0
index 567340ec5d4..4e32b19d424 100644
@@ -15,6 +15,9 @@
 
Quoted 7 lines

net/bootp.h line 18

Quoted 3 lines
net/bootp.h +1 -0
 /**********************************************************************/
 
+#define PORT_BOOTPS	67		/* BOOTP server UDP port */

Reading code I would have a hard time to immediately see what this constant name stands for.

Shouldn't this be renamed BOOTP_SERVER_PORT to create readable code?

We're just moving the code around for now, and this should get replaced by lwip in time.

Signature · 1 line
Tom
#23 lore raw

PATCH v2 17/29 net: bootp: Fall back to BOOTP from DHCP when unit testing

In reply to Sean Anderson

If we sent a DHCP packet and get a BOOTP response from the server, we shouldn't try to send a DHCPREQUEST packet, since it won't be DHCPACKed. Transition straight to BIND. This is only enabled for UNIT_TEST to avoid bloat, since I suspect the number of BOOTP servers in the wild is vanishingly small.

---

(no changes since v1)

 net/bootp.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/bootp.c +6 -0
index 2053cce88c6..7b0f45e18a9 100644
@@ -1073,6 +1073,11 @@ static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
 			    CONFIG_SYS_BOOTFILE_PREFIX,
 			    strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0) {
 #endif	/* CONFIG_SYS_BOOTFILE_PREFIX */
+			if (CONFIG_IS_ENABLED(UNIT_TEST) &&
+			    dhcp_message_type((u8 *)bp->bp_vend) == -1) {
+				debug("got BOOTP response; transitioning to BOUND\n");
+				goto dhcp_got_bootp;
+			}
 			dhcp_packet_process_options(bp);
 			if (CONFIG_IS_ENABLED(EFI_LOADER) &&
 			    IS_ENABLED(CONFIG_NETDEVICES))
@@ -1099,6 +1104,7 @@ static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
 		debug("DHCP State: REQUESTING\n");
 
 		if (dhcp_message_type((u8 *)bp->bp_vend) == DHCP_ACK) {
+dhcp_got_bootp:
 			dhcp_packet_process_options(bp);
 			/* Store net params from reply */
 			store_net_params(bp);
Signature · 1 line
2.37.1
#24 lore raw

Re: [PATCH v2 17/29] net: bootp: Fall back to BOOTP from DHCP when unit testing

Am 14. Oktober 2023 22:47:53 MESZ schrieb Sean Anderson <[email protected]>:

Quoted 20 lines

If we sent a DHCP packet and get a BOOTP response from the server, we shouldn't try to send a DHCPREQUEST packet, since it won't be DHCPACKed. Transition straight to BIND. This is only enabled for UNIT_TEST to avoid bloat, since I suspect the number of BOOTP servers in the wild is vanishingly small.

---

(no changes since v1)

net/bootp.c | 6 ++++++

1 file changed, 6 insertions(+)
net/bootp.c +0 -0
index 2053cce88c6..7b0f45e18a9 100644

net/bootp.c static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip, · line 1077

Quoted 5 lines
net/bootp.c +2 -0
@@ -1073,6 +1073,11 @@ static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
 			    CONFIG_SYS_BOOTFILE_PREFIX,
 			    strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0) {
 #endif	/* CONFIG_SYS_BOOTFILE_PREFIX */
+			if (CONFIG_IS_ENABLED(UNIT_TEST) &&
+			    dhcp_message_type((u8 *)bp->bp_vend) == -1) {

As written before, please, do not add unit test specific code paths.

Best regards

Heinrich

Quoted 14 lines
net/bootp.c +4 -0
+				debug("got BOOTP response; transitioning to BOUND\n");
+				goto dhcp_got_bootp;
+			}
 			dhcp_packet_process_options(bp);
 			if (CONFIG_IS_ENABLED(EFI_LOADER) &&
 			    IS_ENABLED(CONFIG_NETDEVICES))
@@ -1099,6 +1104,7 @@ static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
 		debug("DHCP State: REQUESTING\n");
 
 		if (dhcp_message_type((u8 *)bp->bp_vend) == DHCP_ACK) {
+dhcp_got_bootp:
 			dhcp_packet_process_options(bp);
 			/* Store net params from reply */
 			store_net_params(bp);
#25 lore raw

Re: [PATCH v2 17/29] net: bootp: Fall back to BOOTP from DHCP when unit testing

Quoted 18 lines · Heinrich Schuchardt

Am 14. Oktober 2023 22:47:53 MESZ schrieb Sean Anderson <[email protected]>:

Quoted 15 lines

If we sent a DHCP packet and get a BOOTP response from the server, we shouldn't try to send a DHCPREQUEST packet, since it won't be DHCPACKed. Transition straight to BIND. This is only enabled for UNIT_TEST to avoid bloat, since I suspect the number of BOOTP servers in the wild is vanishingly small.

---

(no changes since v1)

net/bootp.c | 6 ++++++

1 file changed, 6 insertions(+)
Quoted 12 lines

net/bootp.c static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip, · line 1077

Quoted 10 lines
net/bootp.c +2 -0
index 2053cce88c6..7b0f45e18a9 100644
@@ -1073,6 +1073,11 @@ static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
 			    CONFIG_SYS_BOOTFILE_PREFIX,
 			    strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0) {
 #endif	/* CONFIG_SYS_BOOTFILE_PREFIX */
+			if (CONFIG_IS_ENABLED(UNIT_TEST) &&
+			    dhcp_message_type((u8 *)bp->bp_vend) == -1) {

As written before, please, do not add unit test specific code paths.

While it is convenient for tests to implement a BOOTP server, there are effectively no BOOTP servers in the wild. However, BOOTP is commonly enabled in U-Boot. In an effort to avoid growing most U-Boots for testing purposes, I enabled this path just for unit tests. That said, only 6 boards enable SPL_ETH, so maybe it is not too bad.

--Sean

#26 lore raw

Re: [PATCH v2 17/29] net: bootp: Fall back to BOOTP from DHCP when unit testing

Hi Sean,

Quoted 33 lines · Sean Anderson
Quoted 18 lines · Heinrich Schuchardt

Am 14. Oktober 2023 22:47:53 MESZ schrieb Sean Anderson <[email protected]>:

Quoted 15 lines

If we sent a DHCP packet and get a BOOTP response from the server, we shouldn't try to send a DHCPREQUEST packet, since it won't be DHCPACKed. Transition straight to BIND. This is only enabled for UNIT_TEST to avoid bloat, since I suspect the number of BOOTP servers in the wild is vanishingly small.

---

(no changes since v1)

net/bootp.c | 6 ++++++

1 file changed, 6 insertions(+)
Quoted 12 lines

net/bootp.c static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip, · line 1077

Quoted 10 lines
net/bootp.c +2 -0
index 2053cce88c6..7b0f45e18a9 100644
@@ -1073,6 +1073,11 @@ static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
                         CONFIG_SYS_BOOTFILE_PREFIX,
                         strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0) {
 #endif       /* CONFIG_SYS_BOOTFILE_PREFIX */
+                    if (CONFIG_IS_ENABLED(UNIT_TEST) &&
+                        dhcp_message_type((u8 *)bp->bp_vend) == -1) {

As written before, please, do not add unit test specific code paths.

Quoted 5 lines

While it is convenient for tests to implement a BOOTP server, there are effectively no BOOTP servers in the wild. However, BOOTP is commonly enabled in U-Boot. In an effort to avoid growing most U-Boots for testing purposes, I enabled this path just for unit tests. That said, only 6 boards enable SPL_ETH, so maybe it is not too bad.

Yes, also if you are using networking in SPL, you can expect it to add quite a bit to code size.

Regards,
Simon

#27 lore raw

Re: [PATCH v2 17/29] net: bootp: Fall back to BOOTP from DHCP when unit testing

Quoted 36 lines · Simon Glass

Hi Sean,

Quoted 33 lines · Sean Anderson
Quoted 30 lines · Heinrich Schuchardt

Am 14. Oktober 2023 22:47:53 MESZ schrieb Sean Anderson <[email protected]>:

Quoted 20 lines

If we sent a DHCP packet and get a BOOTP response from the server, we shouldn't try to send a DHCPREQUEST packet, since it won't be DHCPACKed. Transition straight to BIND. This is only enabled for UNIT_TEST to avoid bloat, since I suspect the number of BOOTP servers in the wild is vanishingly small.

---

(no changes since v1)

net/bootp.c | 6 ++++++

1 file changed, 6 insertions(+)
net/bootp.c +0 -0
index 2053cce88c6..7b0f45e18a9 100644

net/bootp.c static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip, · line 1077

Quoted 5 lines
net/bootp.c +2 -0
@@ -1073,6 +1073,11 @@ static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
                         CONFIG_SYS_BOOTFILE_PREFIX,
                         strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0) {
 #endif       /* CONFIG_SYS_BOOTFILE_PREFIX */
+                    if (CONFIG_IS_ENABLED(UNIT_TEST) &&
+                        dhcp_message_type((u8 *)bp->bp_vend) == -1) {

As written before, please, do not add unit test specific code paths.

Quoted 8 lines
Quoted 5 lines

While it is convenient for tests to implement a BOOTP server, there are effectively no BOOTP servers in the wild. However, BOOTP is commonly enabled in U-Boot. In an effort to avoid growing most U-Boots for testing purposes, I enabled this path just for unit tests. That said, only 6 boards enable SPL_ETH, so maybe it is not too bad.

Yes, also if you are using networking in SPL, you can expect it to add quite a bit to code size.

And so long as this doesn't lead to overflowing them, OK. But size is not infinite there, am335x_evm and am43xx_hs_evm are both a bit constrained.

Signature · 1 line
Tom
#28 lore raw

PATCH v2 18/29 spl: Add callbacks to invalidate cached devices

In reply to Sean Anderson

Several SPL functions try to avoid performing initialization twice by caching devices. This is fine for regular boot, but does not work with UNIT_TEST, since all devices are torn down after each test. Add some functions to invalidate the caches which can be called before testing these load methods.

---

Changes in v2:
- Use callbacks to invalidate SPL caches instead of disabling them entirely

 common/spl/spl_fat.c |  5 +++++
 common/spl/spl_mmc.c |  8 +++++++-
 include/spl.h        | 22 ++++++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)
common/spl/spl_fat.c +5 -0
index c6e2526ade1..b7b6a7794fd 100644
@@ -20,6 +20,11 @@
 
 static int fat_registered;
 
+void spl_fat_force_reregister(void)
+{
+	fat_registered = 0;
+}
+
 static int spl_register_fat_device(struct blk_desc *block_dev, int partition)
 {
 	int err = 0;
common/spl/spl_mmc.c +7 -1
index 67c7ae34a58..03a081fa47e 100644
@@ -403,13 +403,19 @@ static int spl_mmc_get_mmc_devnum(struct mmc *mmc)
 	return block_dev->devnum;
 }
 
+static struct mmc *mmc;
+
+void spl_mmc_clear_cache(void)
+{
+	mmc = NULL;
+}
+
 int spl_mmc_load(struct spl_image_info *spl_image,
 		 struct spl_boot_device *bootdev,
 		 const char *filename,
 		 int raw_part,
 		 unsigned long raw_sect)
 {
-	static struct mmc *mmc;
 	u32 boot_mode;
 	int err = 0;
 	__maybe_unused int part = 0;
include/spl.h +22 -0
index 7d30fb57dac..5b051ef2aae 100644
@@ -674,6 +674,18 @@ static inline const char *spl_loader_name(const struct spl_image_loader *loader)
 #endif
 
 /* SPL FAT image functions */
+
+/**
+ * spl_fat_force_reregister() - Force reregistration of FAT block devices
+ *
+ * To avoid repeatedly looking up block devices, spl_load_image_fat keeps track
+ * of whether it has already registered a block device. This is fine for most
+ * cases, but when running unit tests all devices are removed and recreated
+ * in-between tests. This function will force re-registration of any block
+ * devices, ensuring that we don't try to use an invalid block device.
+ */
+void spl_fat_force_reregister(void);
+
 int spl_load_image_fat(struct spl_image_info *spl_image,
 		       struct spl_boot_device *bootdev,
 		       struct blk_desc *block_dev, int partition,
@@ -753,6 +765,16 @@ bool spl_was_boot_source(void);
  */
 int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr);
 
+/**
+ * spl_mmc_clear_cache() - Clear cached MMC devices
+ *
+ * To avoid reinitializing MMCs, spl_mmc_load caches the most-recently-used MMC
+ * device. This is fine for most cases, but when running unit tests all devices
+ * are removed and recreated in-between tests. This function will clear any
+ * cached state, ensuring that we don't try to use an invalid MMC.
+ */
+void spl_mmc_clear_cache(void);
+
 int spl_mmc_load_image(struct spl_image_info *spl_image,
 		       struct spl_boot_device *bootdev);
 
Signature · 1 line
2.37.1
#29 lore raw

PATCH v2 19/29 spl: Use map_sysmem where appropriate

In reply to Sean Anderson

All "physical" addresses in SPL must be converted to virtual addresses before access in order for sandbox to work. Add some calls to map_sysmem in appropriate places. We do not generally call unmap_sysmem, since we need the image memory to still be mapped when we jump to the image. This doesn't matter at the moment since unmap_sysmem is a no-op.

---

(no changes since v1)

 common/spl/spl.c               |  4 +++-
 common/spl/spl_blk_fs.c        |  6 ++++--
 common/spl/spl_ext.c           |  4 +++-
 common/spl/spl_fat.c           | 11 +++++++----
 common/spl/spl_fit.c           | 36 +++++++++++++++++++++-------------
 common/spl/spl_imx_container.c |  4 +++-
 common/spl/spl_legacy.c        |  6 ++++--
 common/spl/spl_mmc.c           |  4 +++-
 common/spl/spl_net.c           | 10 +++++++---
 common/spl/spl_nor.c           |  5 +++--
 common/spl/spl_spi.c           | 14 +++++++++----
 11 files changed, 69 insertions(+), 35 deletions(-)
common/spl/spl.c +3 -1
index 66eeea41a34..732d90d39e6 100644
@@ -653,7 +653,9 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	spl_set_bd();
 
 	if (IS_ENABLED(CONFIG_SPL_SYS_MALLOC)) {
-		mem_malloc_init(SPL_SYS_MALLOC_START, SPL_SYS_MALLOC_SIZE);
+		mem_malloc_init((ulong)map_sysmem(SPL_SYS_MALLOC_START,
+						  SPL_SYS_MALLOC_SIZE),
+				SPL_SYS_MALLOC_SIZE);
 		gd->flags |= GD_FLG_FULL_MALLOC_INIT;
 	}
 	if (!(gd->flags & GD_FLG_SPL_INIT)) {
common/spl/spl_blk_fs.c +4 -2
index ea5d1a51d9f..63825d620d1 100644
@@ -9,6 +9,7 @@
 #include <spl.h>
 #include <image.h>
 #include <fs.h>
+#include <asm/io.h>
 
 struct blk_dev {
 	const char *ifname;
@@ -29,7 +30,8 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
 		return ret;
 	}
 
-	ret = fs_read(load->filename, (ulong)buf, file_offset, size, &actlen);
+	ret = fs_read(load->filename, virt_to_phys(buf), file_offset, size,
+		      &actlen);
 	if (ret < 0) {
 		printf("spl: error reading image %s. Err - %d\n",
 		       load->filename, ret);
@@ -69,7 +71,7 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
 		goto out;
 	}
 
-	ret = fs_read(filename, (ulong)header, 0,
+	ret = fs_read(filename, virt_to_phys(header), 0,
 		      sizeof(struct legacy_img_hdr), &actlen);
 	if (ret) {
 		printf("spl: unable to read file %s. Err - %d\n", filename,
common/spl/spl_ext.c +3 -1
index 902564a6077..af836ca15b8 100644
@@ -2,6 +2,7 @@
 
 #include <common.h>
 #include <env.h>
+#include <mapmem.h>
 #include <part.h>
 #include <spl.h>
 #include <asm/u-boot.h>
@@ -53,7 +54,8 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
 		goto end;
 	}
 
-	err = ext4fs_read((char *)spl_image->load_addr, 0, filelen, &actlen);
+	err = ext4fs_read(map_sysmem(spl_image->load_addr, filelen), 0, filelen,
+			  &actlen);
 
 end:
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
common/spl/spl_fat.c +7 -4
index b7b6a7794fd..014074f85be 100644
@@ -11,6 +11,7 @@
 #include <common.h>
 #include <env.h>
 #include <log.h>
+#include <mapmem.h>
 #include <spl.h>
 #include <asm/u-boot.h>
 #include <fat.h>
@@ -79,11 +80,13 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
 
 	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
 	    image_get_magic(header) == FDT_MAGIC) {
-		err = file_fat_read(filename, (void *)CONFIG_SYS_LOAD_ADDR, 0);
+		err = file_fat_read(filename,
+				    map_sysmem(CONFIG_SYS_LOAD_ADDR, 0), 0);
 		if (err <= 0)
 			goto end;
 		err = spl_parse_image_header(spl_image, bootdev,
-				(struct legacy_img_hdr *)CONFIG_SYS_LOAD_ADDR);
+					     map_sysmem(CONFIG_SYS_LOAD_ADDR,
+							err));
 		if (err == -EAGAIN)
 			return err;
 		if (err == 0)
@@ -104,8 +107,8 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
 		if (err)
 			goto end;
 
-		err = file_fat_read(filename,
-				    (u8 *)(uintptr_t)spl_image->load_addr, 0);
+		err = file_fat_read(filename, map_sysmem(spl_image->load_addr,
+							 spl_image->size), 0);
 	}
 
 end:
common/spl/spl_fit.c +22 -14
index 4f8b951efe2..c3b493cdb92 100644
@@ -16,6 +16,7 @@
 #include <sysinfo.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
+#include <asm/io.h>
 #include <linux/libfdt.h>
 #include <linux/printk.h>
 
@@ -388,25 +389,32 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 	/* Figure out which device tree the board wants to use */
 	node = spl_fit_get_image_node(ctx, FIT_FDT_PROP, index++);
 	if (node < 0) {
+		size_t size;
+
 		debug("%s: cannot find FDT node\n", __func__);
 
 		/*
 		 * U-Boot did not find a device tree inside the FIT image. Use
 		 * the U-Boot device tree instead.
 		 */
-		if (gd->fdt_blob)
-			memcpy((void *)image_info.load_addr, gd->fdt_blob,
-			       fdt_totalsize(gd->fdt_blob));
-		else
+		if (!gd->fdt_blob)
 			return node;
+
+		/*
+		 * Make the load-address of the FDT available for the SPL
+		 * framework
+		 */
+		size = fdt_totalsize(gd->fdt_blob);
+		spl_image->fdt_addr = map_sysmem(image_info.load_addr, size);
+		memcpy(spl_image->fdt_addr, gd->fdt_blob, size);
 	} else {
 		ret = load_simple_fit(info, sector, ctx, node, &image_info);
 		if (ret < 0)
 			return ret;
+
+		spl_image->fdt_addr = phys_to_virt(image_info.load_addr);
 	}
 
-	/* Make the load-address of the FDT available for the SPL framework */
-	spl_image->fdt_addr = map_sysmem(image_info.load_addr, 0);
 	if (CONFIG_IS_ENABLED(FIT_IMAGE_TINY))
 		return 0;
 
@@ -859,7 +867,7 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 #ifdef CONFIG_SPL_FIT_SIGNATURE
 	images.verify = 1;
 #endif
-	ret = fit_image_load(&images, (ulong)header,
+	ret = fit_image_load(&images, virt_to_phys((void *)header),
 			     NULL, &fit_uname_config,
 			     IH_ARCH_DEFAULT, IH_TYPE_STANDALONE, -1,
 			     FIT_LOAD_OPTIONAL, &fw_data, &fw_len);
@@ -867,15 +875,15 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 		printf("DEPRECATED: 'standalone = ' property.");
 		printf("Please use either 'firmware =' or 'kernel ='\n");
 	} else {
-		ret = fit_image_load(&images, (ulong)header, NULL,
-				     &fit_uname_config, IH_ARCH_DEFAULT,
+		ret = fit_image_load(&images, virt_to_phys((void *)header),
+				     NULL, &fit_uname_config, IH_ARCH_DEFAULT,
 				     IH_TYPE_FIRMWARE, -1, FIT_LOAD_OPTIONAL,
 				     &fw_data, &fw_len);
 	}
 
 	if (ret < 0) {
-		ret = fit_image_load(&images, (ulong)header, NULL,
-				     &fit_uname_config, IH_ARCH_DEFAULT,
+		ret = fit_image_load(&images, virt_to_phys((void *)header),
+				     NULL, &fit_uname_config, IH_ARCH_DEFAULT,
 				     IH_TYPE_KERNEL, -1, FIT_LOAD_OPTIONAL,
 				     &fw_data, &fw_len);
 	}
@@ -897,9 +905,9 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 #ifdef CONFIG_SPL_FIT_SIGNATURE
 	images.verify = 1;
 #endif
-	ret = fit_image_load(&images, (ulong)header, NULL, &fit_uname_config,
-			     IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1,
-			     FIT_LOAD_OPTIONAL, &dt_data, &dt_len);
+	ret = fit_image_load(&images, virt_to_phys((void *)header), NULL,
+			     &fit_uname_config, IH_ARCH_DEFAULT, IH_TYPE_FLATDT,
+			     -1, FIT_LOAD_OPTIONAL, &dt_data, &dt_len);
 	if (ret >= 0) {
 		spl_image->fdt_addr = (void *)dt_data;
 
common/spl/spl_imx_container.c +3 -1
index c29cb15f55e..127802f5cb7 100644
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <imx_container.h>
 #include <log.h>
+#include <mapmem.h>
 #include <spl.h>
 #ifdef CONFIG_AHAB_BOOT
 #include <asm/mach-imx/ahab.h>
@@ -46,7 +47,8 @@ static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image,
 	debug("%s: container: %p sector: %lu sectors: %u\n", __func__,
 	      container, sector, sectors);
 	if (info->read(info, sector, sectors,
-		       (void *)images[image_index].dst) != sectors) {
+		       map_sysmem(images[image_index].dst,
+				  images[image_index].size)) != sectors) {
 		printf("%s wrong\n", __func__);
 		return NULL;
 	}
common/spl/spl_legacy.c +4 -2
index e9564e5c2a5..51656fb9617 100644
@@ -7,6 +7,7 @@
 #include <image.h>
 #include <log.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <asm/sections.h>
 #include <spl.h>
 
@@ -129,7 +130,7 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
 			dataptr += sizeof(*hdr);
 
 		load->read(load, dataptr, spl_image->size,
-			   (void *)(unsigned long)spl_image->load_addr);
+			   map_sysmem(spl_image->load_addr, spl_image->size));
 		break;
 
 	case IH_COMP_LZMA:
@@ -148,7 +149,8 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
 		}
 
 		load->read(load, dataptr, spl_image->size, src);
-		ret = lzmaBuffToBuffDecompress((void *)spl_image->load_addr,
+		ret = lzmaBuffToBuffDecompress(map_sysmem(spl_image->load_addr,
+							  spl_image->size),
 					       &lzma_len, src, spl_image->size);
 		if (ret) {
 			printf("LZMA decompression error: %d\n", ret);
common/spl/spl_mmc.c +3 -1
index 03a081fa47e..0b01368d9de 100644
@@ -8,6 +8,7 @@
 #include <common.h>
 #include <dm.h>
 #include <log.h>
+#include <mapmem.h>
 #include <part.h>
 #include <spl.h>
 #include <linux/compiler.h>
@@ -46,7 +47,8 @@ static int mmc_load_legacy(struct spl_image_info *spl_image,
 	count = blk_dread(mmc_get_blk_desc(mmc),
 			  sector + image_offset_sectors,
 			  image_size_sectors,
-			  (void *)(ulong)spl_image->load_addr);
+			  map_sysmem(spl_image->load_addr,
+				     image_size_sectors * mmc->read_bl_len));
 	debug("read %x sectors to %lx\n", image_size_sectors,
 	      spl_image->load_addr);
 	if (count != image_size_sectors)
common/spl/spl_net.c +7 -3
index b2c901b554b..f01d4df8bc6 100644
@@ -11,6 +11,7 @@
 #include <errno.h>
 #include <image.h>
 #include <log.h>
+#include <mapmem.h>
 #include <spl.h>
 #include <net.h>
 #include <linux/libfdt.h>
@@ -21,14 +22,15 @@ static ulong spl_net_load_read(struct spl_load_info *load, ulong sector,
 {
 	debug("%s: sector %lx, count %lx, buf %lx\n",
 	      __func__, sector, count, (ulong)buf);
-	memcpy(buf, (void *)(image_load_addr + sector), count);
+	memcpy(buf, map_sysmem(image_load_addr + sector, count), count);
 	return count;
 }
 
 static int spl_net_load_image(struct spl_image_info *spl_image,
 			      struct spl_boot_device *bootdev)
 {
-	struct legacy_img_hdr *header = (struct legacy_img_hdr *)image_load_addr;
+	struct legacy_img_hdr *header = map_sysmem(image_load_addr,
+						   sizeof(*header));
 	int rv;
 
 	env_init();
@@ -62,7 +64,9 @@ static int spl_net_load_image(struct spl_image_info *spl_image,
 		if (rv)
 			return rv;
 
-		memcpy((void *)spl_image->load_addr, header, spl_image->size);
+		memcpy(map_sysmem(spl_image->load_addr, spl_image->size),
+		       map_sysmem(image_load_addr, spl_image->size),
+		       spl_image->size);
 	}
 
 	return rv;
common/spl/spl_nor.c +3 -2
index dd447982071..236b0718283 100644
@@ -7,6 +7,7 @@
 #include <image.h>
 #include <imx_container.h>
 #include <log.h>
+#include <mapmem.h>
 #include <spl.h>
 
 static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
@@ -14,7 +15,7 @@ static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
 {
 	debug("%s: sector %lx, count %lx, buf %p\n",
 	      __func__, sector, count, buf);
-	memcpy(buf, (void *)sector, count);
+	memcpy(buf, map_sysmem(sector, count), count);
 
 	return count;
 }
@@ -92,7 +93,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 	 * Load real U-Boot from its location in NOR flash to its
 	 * defined location in SDRAM
 	 */
-	header = (const struct legacy_img_hdr *)spl_nor_get_uboot_base();
+	header = map_sysmem(spl_nor_get_uboot_base(), sizeof(*header));
 #ifdef CONFIG_SPL_LOAD_FIT
 	if (image_get_magic(header) == FDT_MAGIC) {
 		debug("Found FIT format U-Boot\n");
common/spl/spl_spi.c +10 -4
index 1427c9478c0..3ac4b1b5091 100644
@@ -12,11 +12,13 @@
 #include <image.h>
 #include <imx_container.h>
 #include <log.h>
+#include <mapmem.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <errno.h>
 #include <spl.h>
 #include <asm/global_data.h>
+#include <asm/io.h>
 #include <dm/ofnode.h>
 
 #if CONFIG_IS_ENABLED(OS_BOOT)
@@ -134,13 +136,16 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 
 		if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
 		    image_get_magic(header) == FDT_MAGIC) {
+			u32 size = roundup(fdt_totalsize(header), 4);
+
 			err = spi_flash_read(flash, payload_offs,
-					     roundup(fdt_totalsize(header), 4),
-					     (void *)CONFIG_SYS_LOAD_ADDR);
+					     size,
+					     map_sysmem(CONFIG_SYS_LOAD_ADDR,
+							size));
 			if (err)
 				return err;
 			err = spl_parse_image_header(spl_image, bootdev,
-					(struct legacy_img_hdr *)CONFIG_SYS_LOAD_ADDR);
+					phys_to_virt(CONFIG_SYS_LOAD_ADDR));
 		} else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
 			   image_get_magic(header) == FDT_MAGIC) {
 			struct spl_load_info load;
@@ -172,7 +177,8 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 				return err;
 			err = spi_flash_read(flash, payload_offs + spl_image->offset,
 					     spl_image->size,
-					     (void *)spl_image->load_addr);
+					     map_sysmem(spl_image->load_addr,
+							spl_image->size));
 		}
 		if (IS_ENABLED(CONFIG_SPI_FLASH_SOFT_RESET)) {
 			err = spi_nor_remove(flash);
Signature · 1 line
2.37.1
#30 lore raw

PATCH v2 20/29 sandbox: Support -T in spl

In reply to Sean Anderson

The test devicetree is only compiled for U-Boot proper. When accessing it in SPL we need to go up one directory.

---

Changes in v2:
- Compare to PHASE_SPL in sandbox_cmdline_cb_test_fdt for clarity
- Split off from fs test

 arch/sandbox/cpu/start.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/sandbox/cpu/start.c +7 -2
index 2c8a72590b5..2589c2eba73 100644
@@ -13,6 +13,7 @@
 #include <log.h>
 #include <os.h>
 #include <sort.h>
+#include <spl.h>
 #include <asm/getopt.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
@@ -202,10 +203,14 @@ static int sandbox_cmdline_cb_test_fdt(struct sandbox_state *state,
 {
 	char buf[256];
 	char *fname;
+	char *relname;
 	int len;
 
-	len = state_get_rel_filename("arch/sandbox/dts/test.dtb", buf,
-				     sizeof(buf));
+	if (spl_phase() <= PHASE_SPL)
+		relname = "../arch/sandbox/dts/test.dtb";
+	else
+		relname = "arch/sandbox/dts/test.dtb";
+	len = state_get_rel_filename(relname, buf, sizeof(buf));
 	if (len < 0)
 		return len;
 
Signature · 1 line
2.37.1
Reviewed-by on v2 20/29
#31 lore raw

Re: [PATCH v2 20/29] sandbox: Support -T in spl

Quoted 5 lines · Sean Anderson

The test devicetree is only compiled for U-Boot proper. When accessing it in SPL we need to go up one directory.

Quoted 8 lines

---

Changes in v2:
- Compare to PHASE_SPL in sandbox_cmdline_cb_test_fdt for clarity
- Split off from fs test

 arch/sandbox/cpu/start.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

BTW that function is in mainline now - spl_in_proper()

This is fine though

#32 lore raw

PATCH v2 21/29 test: spl: Split tests up and use some configs

In reply to Sean Anderson

In order to make adding new spl unit tests easier, especially when they may have many dependencies, add some Kconfigs for the existing image test. Split it into the parts which are generic (such as callbacks) and the test-specific parts.

---

Changes in v2:
- Remove redundant condition on CONFIG_SPL_UT_LOAD in test/image/Makefile
- Remove unused mapmem.h include in spl_load_os.c

 test/Kconfig             |  1 +
 test/Makefile            |  5 +--
 test/image/Kconfig       | 20 ++++++++++
 test/image/Makefile      |  3 +-
 test/image/spl_load.c    | 76 +-------------------------------------
 test/image/spl_load_os.c | 80 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 106 insertions(+), 79 deletions(-)
 create mode 100644 test/image/Kconfig
 create mode 100644 test/image/spl_load_os.c
test/Kconfig +1 -0
index 830245b6f9a..ca648d23376 100644
@@ -101,6 +101,7 @@ config UT_UNICODE
 
 source "test/dm/Kconfig"
 source "test/env/Kconfig"
+source "test/image/Kconfig"
 source "test/lib/Kconfig"
 source "test/optee/Kconfig"
 source "test/overlay/Kconfig"
test/Makefile +2 -3
index 178773647a8..8e1fed2c28b 100644
@@ -3,9 +3,6 @@
 # (C) Copyright 2012 The Chromium Authors
 
 obj-y += test-main.o
-ifdef CONFIG_SPL_LOAD_FIT
-obj-$(CONFIG_SANDBOX) += image/
-endif
 
 ifneq ($(CONFIG_$(SPL_)BLOBLIST),)
 obj-$(CONFIG_$(SPL_)CMDLINE) += bloblist.o
@@ -30,4 +27,6 @@ obj-$(CONFIG_UNIT_TEST) += boot/
 obj-$(CONFIG_UNIT_TEST) += common/
 obj-y += log/
 obj-$(CONFIG_$(SPL_)UT_UNICODE) += unicode_ut.o
+else
+obj-$(CONFIG_SPL_UT_LOAD) += image/
 endif
test/image/Kconfig new file +20 -0
new file mode 100644
index 00000000000..70ffe0ff276
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2023 Sean Anderson <[email protected]>
+
+config SPL_UT_LOAD
+	bool "Unit tests for SPL load methods"
+	depends on SPL_UNIT_TEST
+	default y if SANDBOX
+	help
+	  Test various SPL load methods.
+
+if SPL_UT_LOAD
+
+config SPL_UT_LOAD_OS
+	bool "Test loading from the host OS"
+	depends on SANDBOX && SPL_LOAD_FIT
+	default y
+	help
+	  Smoke test to ensure that loading U-boot works in sandbox.
+
+endif
test/image/Makefile +2 -1
index c4039df707f..f7ae996bc86 100644
@@ -2,4 +2,5 @@
 #
 # Copyright 2021 Google LLC
 
-obj-$(CONFIG_SPL_BUILD) += spl_load.o
+obj-y += spl_load.o
+obj-$(CONFIG_SPL_UT_LOAD_OS) += spl_load_os.o
test/image/spl_load.c +1 -75

88 lines not on this page · raw message

test/image/spl_load_os.c new file +80 -0

80 lines not on this page · raw message

Signature · 1 line
2.37.1
#33 lore raw

PATCH v2 22/29 test: spl: Fix spl_test_load not failing if fname doesn't exist

In reply to Sean Anderson

Returning a negative value from a unit test doesn't automatically fail the test. We have to fail an assertion. Modify the test to do so.

This now causes the test to count as a failure on VPL. This is because the fname of SPL (and U-Boot) is generated with make_exec in os_jump_to_image. The original name of SPL is gone, and we can't determine the name of U-Boot from the generated name.

---

(no changes since v1)

 configs/sandbox_vpl_defconfig | 1 +
 test/image/spl_load_os.c      | 6 ++----
 2 files changed, 3 insertions(+), 4 deletions(-)
configs/sandbox_vpl_defconfig +1 -0
index 8d76f19729b..5bd0281796d 100644
@@ -262,3 +262,4 @@ CONFIG_UNIT_TEST=y
 CONFIG_SPL_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
+# CONFIG_SPL_UT_LOAD_OS is not set
test/image/spl_load_os.c +2 -4
index bf374f2164d..3b2967d017a 100644
@@ -58,10 +58,8 @@ static int spl_test_load(struct unit_test_state *uts)
 	load.read = read_fit_image;
 
 	ret = sandbox_find_next_phase(fname, sizeof(fname), true);
-	if (ret) {
-		printf("(%s not found, error %d)\n", fname, ret);
-		return ret;
-	}
+	if (ret)
+		ut_assertf(0, "%s not found, error %d\n", fname, ret);
 	load.filename = fname;
 
 	header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
Signature · 1 line
2.37.1
#34 lore raw

PATCH v2 23/29 test: spl: Add functions to create images

In reply to Sean Anderson

This add some basic functions to create images, and a test for said functions. This is not intended to be a test of the image parsing functions, but rather a framework for creating minimal images for testing load methods. That said, it does do an OK job at finding bugs in the image parsing directly.

Since we have two methods for loading/parsing FIT images, add LOAD_FIT_FULL as a separate CI run.

---

Changes in v2:
- Fix size not being updated in board_spl_fit_buffer_addr
- Fix return value documentation for check_image_info

 .azure-pipelines.yml             |   4 +
 .gitlab-ci.yml                   |   7 +
 arch/sandbox/cpu/u-boot-spl.lds  |   2 +
 configs/sandbox_noinst_defconfig |   6 +
 configs/sandbox_spl_defconfig    |   6 +
 include/test/spl.h               | 117 +++++++++++
 test/image/spl_load.c            | 350 +++++++++++++++++++++++++++++++
 test/image/spl_load_os.c         |   4 +-
 8 files changed, 493 insertions(+), 3 deletions(-)
 create mode 100644 include/test/spl.h
.azure-pipelines.yml +4 -0
index 7985ff5523c..6f91553e861 100644
@@ -299,6 +299,10 @@ stages:
         sandbox_noinst:
           TEST_PY_BD: "sandbox_noinst"
           TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
+        sandbox_noinst_load_fit_full:
+          TEST_PY_BD: "sandbox_noinst"
+          TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
+          OVERRIDE: "-a CONFIG_SPL_LOAD_FIT_FULL=y"
         sandbox_flattree:
           TEST_PY_BD: "sandbox_flattree"
         sandbox_trace:
.gitlab-ci.yml +7 -0
index 129234ba3db..6decdfdee33 100644
@@ -293,6 +293,13 @@ sandbox_noinst_test.py:
     TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
   <<: *buildman_and_testpy_dfn
 
+sandbox_noinst with LOAD_FIT_FULL test.py:
+  variables:
+    TEST_PY_BD: "sandbox_noinst"
+    TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
+    OVERRIDE: "-a CONFIG_SPL_LOAD_FIT_FULL=y"
+  <<: *buildman_and_testpy_dfn
+
 sandbox_vpl test.py:
   variables:
     TEST_PY_BD: "sandbox_vpl"
arch/sandbox/cpu/u-boot-spl.lds +2 -0
index ef885fd0cb0..a81d66a6f2e 100644
@@ -26,6 +26,8 @@ SECTIONS
 		KEEP(*(_u_boot_sandbox_getopt))
 		*(_u_boot_sandbox_getopt_end)
 	}
+
+	_image_binary_end = .;
 }
 
 INSERT AFTER .data;
configs/sandbox_noinst_defconfig +6 -0
index d39e54f98d2..908155be8a3 100644
@@ -32,6 +32,12 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_NO_BSS_LIMIT=y
 CONFIG_HANDOFF=y
 CONFIG_SPL_BOARD_INIT=y
+CONFIG_SPL_LEGACY_IMAGE_FORMAT=y
+CONFIG_SPL_LOAD_IMX_CONTAINER=y
+CONFIG_SPL_SYS_MALLOC=y
+CONFIG_SPL_HAS_CUSTOM_MALLOC_START=y
+CONFIG_SPL_CUSTOM_SYS_MALLOC_ADDR=0xa000000
+CONFIG_SPL_SYS_MALLOC_SIZE=0x4000000
 CONFIG_SPL_ENV_SUPPORT=y
 CONFIG_SPL_I2C=y
 CONFIG_SPL_RTC=y
configs/sandbox_spl_defconfig +6 -0
index 4a67af2f088..b578cc8e443 100644
@@ -32,6 +32,12 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_NO_BSS_LIMIT=y
 CONFIG_HANDOFF=y
 CONFIG_SPL_BOARD_INIT=y
+CONFIG_SPL_LEGACY_IMAGE_FORMAT=y
+CONFIG_SPL_LOAD_IMX_CONTAINER=y
+CONFIG_SPL_SYS_MALLOC=y
+CONFIG_SPL_HAS_CUSTOM_MALLOC_START=y
+CONFIG_SPL_CUSTOM_SYS_MALLOC_ADDR=0xa000000
+CONFIG_SPL_SYS_MALLOC_SIZE=0x4000000
 CONFIG_SPL_ENV_SUPPORT=y
 CONFIG_SPL_FPGA=y
 CONFIG_SPL_I2C=y
include/test/spl.h new file +117 -0

117 lines not on this page · raw message

test/image/spl_load.c +350 -0

360 lines not on this page · raw message

test/image/spl_load_os.c +1 -3
index 3b2967d017a..49edf152d78 100644
@@ -8,11 +8,9 @@
 #include <image.h>
 #include <os.h>
 #include <spl.h>
+#include <test/spl.h>
 #include <test/ut.h>
 
-/* Declare a new SPL test */
-#define SPL_TEST(_name, _flags)		UNIT_TEST(_name, _flags, spl_test)
-
 /* Context used for this test */
 struct text_ctx {
 	int fd;
Signature · 1 line
2.37.1
#35 lore raw

PATCH v2 24/29 test: spl: Add functions to create filesystems

In reply to Sean Anderson

Add some functions for creating fat/ext2 filesystems with a single file and a test for them. Filesystems require block devices, and it is easiest to just use MMC for this. To get an MMC, we must also pull in the test device tree. SPL_TIMER is necessary for SPL_MMC, perhaps because it uses a timeout.

---

Changes in v2:
- Explicitly invalidate FAT block device cache before testing
- Remove unused dm.h include in spl_load.c
- Add note about why we enable SPL_TIMER
- Split off ext/-T changes into their own commits

 configs/sandbox_noinst_defconfig |   7 +
 include/test/spl.h               |   3 +
 test/image/Kconfig               |  11 ++
 test/image/Makefile              |   1 +
 test/image/spl_load_fs.c         | 306 +++++++++++++++++++++++++++++++
 5 files changed, 328 insertions(+)
 create mode 100644 test/image/spl_load_fs.c
configs/sandbox_noinst_defconfig +7 -0
index 908155be8a3..0a542cfb6aa 100644
@@ -6,10 +6,12 @@ CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2000
 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
 CONFIG_DM_RESET=y
+CONFIG_SPL_MMC=y
 CONFIG_SPL_SERIAL=y
 CONFIG_SPL_DRIVERS_MISC=y
 CONFIG_SPL_SYS_MALLOC_F_LEN=0x8000
 CONFIG_SPL=y
+CONFIG_SPL_FS_FAT=y
 CONFIG_SYS_LOAD_ADDR=0x0
 CONFIG_PCI=y
 CONFIG_SANDBOX_SPL=y
@@ -39,7 +41,9 @@ CONFIG_SPL_HAS_CUSTOM_MALLOC_START=y
 CONFIG_SPL_CUSTOM_SYS_MALLOC_ADDR=0xa000000
 CONFIG_SPL_SYS_MALLOC_SIZE=0x4000000
 CONFIG_SPL_ENV_SUPPORT=y
+CONFIG_SPL_FS_EXT4=y
 CONFIG_SPL_I2C=y
+CONFIG_SPL_MMC_WRITE=y
 CONFIG_SPL_RTC=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
@@ -97,6 +101,7 @@ CONFIG_AMIGA_PARTITION=y
 CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_SPL_OF_PLATDATA=y
+CONFIG_SPL_OF_REAL=y
 CONFIG_ENV_IS_NOWHERE=y
 CONFIG_ENV_IS_IN_EXT4=y
 CONFIG_ENV_EXT4_INTERFACE="host"
@@ -159,6 +164,7 @@ CONFIG_CROS_EC_SPI=y
 CONFIG_P2SB=y
 CONFIG_PWRSEQ=y
 CONFIG_SPL_PWRSEQ=y
+CONFIG_FS_LOADER=y
 CONFIG_MMC_SANDBOX=y
 CONFIG_SPI_FLASH_SANDBOX=y
 CONFIG_SPI_FLASH_ATMEL=y
@@ -220,6 +226,7 @@ CONFIG_SYSRESET=y
 CONFIG_SPL_SYSRESET=y
 CONFIG_DM_THERMAL=y
 CONFIG_TIMER=y
+CONFIG_SPL_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_USB=y
include/test/spl.h +3 -0
index 4c6b789e478..7dba3f03d07 100644
@@ -114,4 +114,7 @@ SPL_TEST(func##_##type, flags)
 /* More than a couple blocks, and will not be aligned to anything */
 #define SPL_TEST_DATA_SIZE	4099
 
+/* Flags necessary for accessing DM devices */
+#define DM_FLAGS (UT_TESTF_DM | UT_TESTF_SCAN_FDT)
+
 #endif /* TEST_SPL_H */
test/image/Kconfig +11 -0
index 70ffe0ff276..963c86cc290 100644
@@ -10,6 +10,17 @@ config SPL_UT_LOAD
 
 if SPL_UT_LOAD
 
+config SPL_UT_LOAD_FS
+	bool "Unit tests for filesystems"
+	depends on SANDBOX && SPL_OF_REAL
+	depends on FS_LOADER
+	depends on SPL_FS_FAT
+	depends on SPL_FS_EXT4
+	depends on SPL_MMC_WRITE
+	default y
+	help
+	  Test filesystems in SPL.
+
 config SPL_UT_LOAD_OS
 	bool "Test loading from the host OS"
 	depends on SANDBOX && SPL_LOAD_FIT
test/image/Makefile +1 -0
index f7ae996bc86..6bd77bf0aab 100644
@@ -3,4 +3,5 @@
 # Copyright 2021 Google LLC
 
 obj-y += spl_load.o
+obj-$(CONFIG_SPL_UT_LOAD_FS) += spl_load_fs.o
 obj-$(CONFIG_SPL_UT_LOAD_OS) += spl_load_os.o
test/image/spl_load_fs.c new file +306 -0

306 lines not on this page · raw message

Signature · 1 line
2.37.1
Reviewed-by on v2 24/29
#36 lore raw

Re: [PATCH v2 24/29] test: spl: Add functions to create filesystems

Quoted 15 lines · Sean Anderson

Add some functions for creating fat/ext2 filesystems with a single file and a test for them. Filesystems require block devices, and it is easiest to just use MMC for this. To get an MMC, we must also pull in the test device tree. SPL_TIMER is necessary for SPL_MMC, perhaps because it uses a timeout.

---

Changes in v2:
- Explicitly invalidate FAT block device cache before testing
- Remove unused dm.h include in spl_load.c
- Add note about why we enable SPL_TIMER
- Split off ext/-T changes into their own commits

Quoted 7 lines
 configs/sandbox_noinst_defconfig |   7 +
 include/test/spl.h               |   3 +
 test/image/Kconfig               |  11 ++
 test/image/Makefile              |   1 +
 test/image/spl_load_fs.c         | 306 +++++++++++++++++++++++++++++++
 5 files changed, 328 insertions(+)
 create mode 100644 test/image/spl_load_fs.c
#37 lore raw

PATCH v2 25/29 test: spl: Add a test for spl_blk_load_image

In reply to Sean Anderson

Add a test for spl_blk_load_image, currently used only by NVMe. Because there is no sandbox NVMe driver, just use MMC instead. Avoid falling back to raw images to make failures more obvious.

---

Changes in v2:
- Explicitly invalidate FAT block device cache before testing

 configs/sandbox_noinst_defconfig |  2 +
 test/image/Kconfig               |  3 +-
 test/image/spl_load_fs.c         | 63 ++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 1 deletion(-)
configs/sandbox_noinst_defconfig +2 -0
index 0a542cfb6aa..11be2dccf7d 100644
@@ -34,6 +34,7 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_NO_BSS_LIMIT=y
 CONFIG_HANDOFF=y
 CONFIG_SPL_BOARD_INIT=y
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
 CONFIG_SPL_LEGACY_IMAGE_FORMAT=y
 CONFIG_SPL_LOAD_IMX_CONTAINER=y
 CONFIG_SPL_SYS_MALLOC=y
@@ -123,6 +124,7 @@ CONFIG_ADC=y
 CONFIG_ADC_SANDBOX=y
 CONFIG_AXI=y
 CONFIG_AXI_SANDBOX=y
+CONFIG_SPL_BLK_FS=y
 CONFIG_SYS_IDE_MAXBUS=1
 CONFIG_SYS_ATA_BASE_ADDR=0x100
 CONFIG_SYS_ATA_STRIDE=4
test/image/Kconfig +2 -1
index 963c86cc290..a52766b77d4 100644
@@ -14,12 +14,13 @@ config SPL_UT_LOAD_FS
 	bool "Unit tests for filesystems"
 	depends on SANDBOX && SPL_OF_REAL
 	depends on FS_LOADER
+	depends on SPL_BLK_FS
 	depends on SPL_FS_FAT
 	depends on SPL_FS_EXT4
 	depends on SPL_MMC_WRITE
 	default y
 	help
-	  Test filesystems in SPL.
+	  Test filesystems and the various load methods which use them.
 
 config SPL_UT_LOAD_OS
 	bool "Test loading from the host OS"
test/image/spl_load_fs.c +63 -0

72 lines not on this page · raw message

Signature · 1 line
2.37.1
#38 lore raw

PATCH v2 26/29 test: spl: Add a test for the MMC load method

In reply to Sean Anderson

Add a test for the MMC load method. This shows the general shape of tests to come: The main test function calls do_spl_test_load with an appropriate callback to write the image to the medium.

---

Changes in v2:
- Correct return value documentation for do_spl_test_load
- Explicitly invalidate FAT and MMC caches before testing

 configs/sandbox_noinst_defconfig |  2 +
 include/spl.h                    |  4 ++
 include/test/spl.h               | 30 ++++++++++++++
 test/image/Kconfig               |  1 +
 test/image/spl_load.c            | 36 +++++++++++++++++
 test/image/spl_load_fs.c         | 69 +++++++++++++++++++++++++++++---
 6 files changed, 137 insertions(+), 5 deletions(-)
configs/sandbox_noinst_defconfig +2 -0
index 11be2dccf7d..4f16d9860d2 100644
@@ -41,6 +41,8 @@ CONFIG_SPL_SYS_MALLOC=y
 CONFIG_SPL_HAS_CUSTOM_MALLOC_START=y
 CONFIG_SPL_CUSTOM_SYS_MALLOC_ADDR=0xa000000
 CONFIG_SPL_SYS_MALLOC_SIZE=0x4000000
+CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR=y
+CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR=0x0
 CONFIG_SPL_ENV_SUPPORT=y
 CONFIG_SPL_FS_EXT4=y
 CONFIG_SPL_I2C=y
include/spl.h +4 -0
index 5b051ef2aae..708b15a0c7f 100644
@@ -673,6 +673,10 @@ static inline const char *spl_loader_name(const struct spl_image_loader *loader)
 	}
 #endif
 
+#define SPL_LOAD_IMAGE_GET(_priority, _boot_device, _method) \
+	ll_entry_get(struct spl_image_loader, \
+		     _boot_device ## _priority ## _method, spl_image_loader)
+
 /* SPL FAT image functions */
 
 /**
include/test/spl.h +30 -0
index 7dba3f03d07..009c6b35462 100644
@@ -79,6 +79,36 @@ size_t create_image(void *dst, enum spl_test_image type,
 int check_image_info(struct unit_test_state *uts, struct spl_image_info *info1,
 		     struct spl_image_info *info2);
 
+/**
+ * typedef write_image_t - Callback for writing an image
+ * @uts: Current unit test state
+ * @img: Image to write
+ * @size: Size of @img
+ *
+ * Write @img to a location which will be read by a &struct spl_image_loader.
+ *
+ * Return: 0 on success or 1 on failure
+ */
+typedef int write_image_t(struct unit_test_state *its, void *img, size_t size);
+
+/**
+ * do_spl_test_load() - Test loading with an SPL image loader
+ * @uts: Current unit test state
+ * @test_name: Name of the current test
+ * @type: Type of image to try loading
+ * @loader: The loader to test
+ * @write_image: Callback to write the image to the backing storage
+ *
+ * Test @loader, performing the common tasks of setting up the image and
+ * checking it was loaded correctly. The caller must supply a @write_image
+ * callback to write the image to a location which will be read by @loader.
+ *
+ * Return: 0 on success or 1 on failure
+ */
+int do_spl_test_load(struct unit_test_state *uts, const char *test_name,
+		     enum spl_test_image type, struct spl_image_loader *loader,
+		     write_image_t write_image);
+
 /**
  * image_supported() - Determine whether an image type is supported
  * @type: The image type to check
test/image/Kconfig +1 -0
index a52766b77d4..e6be1b829f3 100644
@@ -18,6 +18,7 @@ config SPL_UT_LOAD_FS
 	depends on SPL_FS_FAT
 	depends on SPL_FS_EXT4
 	depends on SPL_MMC_WRITE
+	depends on SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
 	default y
 	help
 	  Test filesystems and the various load methods which use them.
test/image/spl_load.c +36 -0
index de2fddae359..d2ce66071bc 100644
@@ -365,3 +365,39 @@ SPL_IMG_TEST(spl_test_image, LEGACY, 0);
 SPL_IMG_TEST(spl_test_image, IMX8, 0);
 SPL_IMG_TEST(spl_test_image, FIT_INTERNAL, 0);
 SPL_IMG_TEST(spl_test_image, FIT_EXTERNAL, 0);
+
+int do_spl_test_load(struct unit_test_state *uts, const char *test_name,
+		     enum spl_test_image type, struct spl_image_loader *loader,
+		     int (*write_image)(struct unit_test_state *, void *, size_t))
+{
+	size_t img_size, img_data, plain_size = SPL_TEST_DATA_SIZE;
+	struct spl_image_info info_write = {
+		.name = test_name,
+		.size = plain_size,
+	}, info_read = { };
+	struct spl_boot_device bootdev = {
+		.boot_device = loader->boot_device,
+	};
+	char *plain;
+	void *img;
+
+	img_size = create_image(NULL, type, &info_write, &img_data);
+	ut_assert(img_size);
+	img = calloc(img_size, 1);
+	ut_assertnonnull(img);
+
+	plain = img + img_data;
+	generate_data(plain, plain_size, test_name);
+	ut_asserteq(img_size, create_image(img, type, &info_write, NULL));
+
+	if (write_image(uts, img, img_size))
+		return CMD_RET_FAILURE;
+
+	ut_assertok(loader->load_image(&info_read, &bootdev));
+	if (check_image_info(uts, &info_write, &info_read))
+		return CMD_RET_FAILURE;
+	ut_asserteq_mem(plain, phys_to_virt(info_write.load_addr), plain_size);
+
+	free(img);
+	return 0;
+}
test/image/spl_load_fs.c +64 -5

97 lines not on this page · raw message

Signature · 1 line
2.37.1
#39 lore raw

PATCH v2 27/29 test: spl: Add a test for the NET load method

In reply to Sean Anderson

Add a test for loading U-Boot over TFTP. As with other sandbox net routines, we need to initialize our packets manually since things like net_set_ether and net_set_udp_header always use "our" addresses. We use BOOTP instead of DHCP, since DHCP has a tag/length-based format which is harder to parse. Our TFTP implementation doesn't define as many constants as I'd like, so I create some here. Note that the TFTP block size is one-based, but offsets are zero-based.

In order to avoid address errors, we need to set up/define some additional address information settings. dram_init_banksize would be a good candidate for settig up bi_dram, but it gets called too late in board_init_r.

---

Changes in v2:
- Add a comment about why we need to initialize bi_dram

 arch/sandbox/cpu/spl.c           |   4 +
 arch/sandbox/include/asm/spl.h   |   1 +
 configs/sandbox_noinst_defconfig |   6 +-
 test/image/Kconfig               |   9 ++
 test/image/Makefile              |   1 +
 test/image/spl_load_net.c        | 252 +++++++++++++++++++++++++++++++
 6 files changed, 272 insertions(+), 1 deletion(-)
 create mode 100644 test/image/spl_load_net.c
arch/sandbox/cpu/spl.c +4 -0
index 09e3d10d6a5..e8a75e73d24 100644
@@ -126,6 +126,10 @@ void spl_board_init(void)
 {
 	struct sandbox_state *state = state_get_current();
 
+	/* These are necessary so TFTP can use LMBs to check its load address */
+	gd->bd->bi_dram[0].start = gd->ram_base;
+	gd->bd->bi_dram[0].size = get_effective_memsize();
+
 	if (state->run_unittests) {
 		struct unit_test *tests = UNIT_TEST_ALL_START();
 		const int count = UNIT_TEST_ALL_COUNT();
arch/sandbox/include/asm/spl.h +1 -0
index 2f8b5fcfcfe..ab9475567e0 100644
@@ -12,6 +12,7 @@ enum {
 	BOOT_DEVICE_MMC2_2,
 	BOOT_DEVICE_BOARD,
 	BOOT_DEVICE_VBE,
+	BOOT_DEVICE_CPGMAC,
 };
 
 /**
configs/sandbox_noinst_defconfig +5 -1
index 4f16d9860d2..57cbadedb7d 100644
@@ -12,7 +12,7 @@ CONFIG_SPL_DRIVERS_MISC=y
 CONFIG_SPL_SYS_MALLOC_F_LEN=0x8000
 CONFIG_SPL=y
 CONFIG_SPL_FS_FAT=y
-CONFIG_SYS_LOAD_ADDR=0x0
+CONFIG_SYS_LOAD_ADDR=0x1000000
 CONFIG_PCI=y
 CONFIG_SANDBOX_SPL=y
 CONFIG_DEBUG_UART=y
@@ -44,9 +44,11 @@ CONFIG_SPL_SYS_MALLOC_SIZE=0x4000000
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR=0x0
 CONFIG_SPL_ENV_SUPPORT=y
+CONFIG_SPL_ETH=y
 CONFIG_SPL_FS_EXT4=y
 CONFIG_SPL_I2C=y
 CONFIG_SPL_MMC_WRITE=y
+CONFIG_SPL_NET=y
 CONFIG_SPL_RTC=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
@@ -109,6 +111,8 @@ CONFIG_ENV_IS_NOWHERE=y
 CONFIG_ENV_IS_IN_EXT4=y
 CONFIG_ENV_EXT4_INTERFACE="host"
 CONFIG_ENV_EXT4_DEVICE_AND_PART="0:0"
+CONFIG_USE_BOOTFILE=y
+CONFIG_BOOTFILE="uImage"
 CONFIG_BOOTP_SEND_HOSTNAME=y
 CONFIG_NETCONSOLE=y
 CONFIG_IP_DEFRAG=y
test/image/Kconfig +9 -0
index e6be1b829f3..99c50787816 100644
@@ -23,6 +23,15 @@ config SPL_UT_LOAD_FS
 	help
 	  Test filesystems and the various load methods which use them.
 
+config SPL_UT_LOAD_NET
+	bool "Test loading over TFTP"
+	depends on SANDBOX && SPL_OF_REAL
+	depends on SPL_ETH
+	depends on USE_BOOTFILE
+	default y
+	help
+	  Test loading images over TFTP using the NET image load method.
+
 config SPL_UT_LOAD_OS
 	bool "Test loading from the host OS"
 	depends on SANDBOX && SPL_LOAD_FIT
test/image/Makefile +1 -0
index 6bd77bf0aab..245672f8d83 100644
@@ -4,4 +4,5 @@
 
 obj-y += spl_load.o
 obj-$(CONFIG_SPL_UT_LOAD_FS) += spl_load_fs.o
+obj-$(CONFIG_SPL_UT_LOAD_NET) += spl_load_net.o
 obj-$(CONFIG_SPL_UT_LOAD_OS) += spl_load_os.o
test/image/spl_load_net.c new file +252 -0

252 lines not on this page · raw message

Signature · 1 line
2.37.1
#40 lore raw

PATCH v2 28/29 test: spl: Add a test for the NOR load method

In reply to Sean Anderson

Add a test for the NOR load method. Since NOR is memory-mapped we can substitute a buffer instead. The only major complication is testing LZMA decompression. It's too complex to implement LZMA compression in a test, and we have no in-tree compressor, so we just include some pre-compressed data. This data was generated through something like

generate_data(plain, plain_size, "lzma")
cat plain.dat | lzma | hexdump -C

and was cleaned up further in my editor.

---

Changes in v2:
- Clarify generation process for LZMA data

 arch/sandbox/include/asm/spl.h   |   1 +
 configs/sandbox_noinst_defconfig |   2 +
 configs/sandbox_spl_defconfig    |   2 +
 include/configs/sandbox.h        |   3 +
 include/test/spl.h               |   5 +
 test/image/Makefile              |   1 +
 test/image/spl_load.c            | 269 ++++++++++++++++++++++++++++++-
 test/image/spl_load_nor.c        |  39 +++++
 8 files changed, 316 insertions(+), 6 deletions(-)
 create mode 100644 test/image/spl_load_nor.c
arch/sandbox/include/asm/spl.h +1 -0
index ab9475567e0..cf16af5278a 100644
@@ -13,6 +13,7 @@ enum {
 	BOOT_DEVICE_BOARD,
 	BOOT_DEVICE_VBE,
 	BOOT_DEVICE_CPGMAC,
+	BOOT_DEVICE_NOR,
 };
 
 /**
configs/sandbox_noinst_defconfig +2 -0
index 57cbadedb7d..085cc30c1e2 100644
@@ -49,6 +49,7 @@ CONFIG_SPL_FS_EXT4=y
 CONFIG_SPL_I2C=y
 CONFIG_SPL_MMC_WRITE=y
 CONFIG_SPL_NET=y
+CONFIG_SPL_NOR_SUPPORT=y
 CONFIG_SPL_RTC=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
@@ -257,6 +258,7 @@ CONFIG_RSA_VERIFY_WITH_PKEY=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
 CONFIG_ZSTD=y
+CONFIG_SPL_LZMA=y
 CONFIG_ERRNO_STR=y
 CONFIG_EFI_CAPSULE_ON_DISK=y
 CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
configs/sandbox_spl_defconfig +2 -0
index b578cc8e443..56072b15ad2 100644
@@ -41,6 +41,7 @@ CONFIG_SPL_SYS_MALLOC_SIZE=0x4000000
 CONFIG_SPL_ENV_SUPPORT=y
 CONFIG_SPL_FPGA=y
 CONFIG_SPL_I2C=y
+CONFIG_SPL_NOR_SUPPORT=y
 CONFIG_SPL_RTC=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
@@ -249,6 +250,7 @@ CONFIG_TPM=y
 CONFIG_SPL_CRC8=y
 CONFIG_LZ4=y
 CONFIG_ZSTD=y
+CONFIG_SPL_LZMA=y
 CONFIG_ERRNO_STR=y
 CONFIG_SPL_HEXDUMP=y
 CONFIG_EFI_CAPSULE_ON_DISK=y
include/configs/sandbox.h +3 -0
index 4e5653dc886..2372485c84e 100644
@@ -18,4 +18,7 @@
 #define CFG_SYS_BAUDRATE_TABLE	{4800, 9600, 19200, 38400, 57600,\
 					115200}
 
+/* Unused but necessary to build */
+#define CFG_SYS_UBOOT_BASE	CONFIG_TEXT_BASE
+
 #endif
include/test/spl.h +5 -0
index 009c6b35462..c1f64658502 100644
@@ -27,12 +27,14 @@ void generate_data(char *data, size_t size, const char *test_name);
 /**
  * enum spl_test_image - Image types for testing
  * @LEGACY: "Legacy" uImages
+ * @LEGACY_LZMA: "Legacy" uImages, LZMA compressed
  * @IMX8: i.MX8 Container images
  * @FIT_INTERNAL: FITs with internal data
  * @FIT_EXTERNAL: FITs with external data
  */
 enum spl_test_image {
 	LEGACY,
+	LEGACY_LZMA,
 	IMX8,
 	FIT_INTERNAL,
 	FIT_EXTERNAL,
@@ -118,6 +120,9 @@ int do_spl_test_load(struct unit_test_state *uts, const char *test_name,
 static inline bool image_supported(enum spl_test_image type)
 {
 	switch (type) {
+	case LEGACY_LZMA:
+		if (!IS_ENABLED(CONFIG_SPL_LZMA))
+			return false;
 	case LEGACY:
 		return IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT);
 	case IMX8:
test/image/Makefile +1 -0
index 245672f8d83..a82aa40449d 100644
@@ -5,4 +5,5 @@
 obj-y += spl_load.o
 obj-$(CONFIG_SPL_UT_LOAD_FS) += spl_load_fs.o
 obj-$(CONFIG_SPL_UT_LOAD_NET) += spl_load_net.o
+obj-$(CONFIG_SPL_NOR_SUPPORT) += spl_load_nor.o
 obj-$(CONFIG_SPL_UT_LOAD_OS) += spl_load_os.o
test/image/spl_load.c +263 -6

323 lines not on this page · raw message

test/image/spl_load_nor.c new file +39 -0
new file mode 100644
index 00000000000..a62bb60d253
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Sean Anderson <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <spl.h>
+#include <asm/io.h>
+#include <test/spl.h>
+#include <test/ut.h>
+
+static void *spl_test_nor_base;
+
+unsigned long spl_nor_get_uboot_base(void)
+{
+	return virt_to_phys(spl_test_nor_base);
+}
+
+static int spl_test_nor_write_image(struct unit_test_state *uts, void *img,
+				    size_t img_size)
+{
+	spl_test_nor_base = img;
+	return 0;
+}
+
+static int spl_test_nor(struct unit_test_state *uts, const char *test_name,
+			enum spl_test_image type)
+{
+	return do_spl_test_load(uts, test_name, type,
+				SPL_LOAD_IMAGE_GET(0, BOOT_DEVICE_NOR,
+						   spl_nor_load_image),
+				spl_test_nor_write_image);
+}
+SPL_IMG_TEST(spl_test_nor, LEGACY, 0);
+SPL_IMG_TEST(spl_test_nor, LEGACY_LZMA, 0);
+SPL_IMG_TEST(spl_test_nor, IMX8, 0);
+SPL_IMG_TEST(spl_test_nor, FIT_INTERNAL, 0);
+SPL_IMG_TEST(spl_test_nor, FIT_EXTERNAL, 0);
Signature · 1 line
2.37.1
#41 lore raw

PATCH v2 29/29 test: spl: Add a test for the SPI load method

In reply to Sean Anderson

Add test for the SPI load method. This one is pretty straightforward. We can't enable FIT_EXTERNAL with LOAD_FIT_FULL because spl_spi_load_image doesn't know the total image size and has to guess from fdt_totalsize. This doesn't include external data, so loading it will fail.

---

(no changes since v1)

 arch/sandbox/include/asm/spl.h   |  1 +
 configs/sandbox_noinst_defconfig |  6 +++++
 include/spl.h                    | 10 ++++++++
 test/image/Kconfig               |  8 +++++++
 test/image/Makefile              |  1 +
 test/image/spl_load.c            |  1 +
 test/image/spl_load_spi.c        | 41 ++++++++++++++++++++++++++++++++
 test/py/tests/test_spl.py        | 10 ++++++++
 8 files changed, 78 insertions(+)
 create mode 100644 test/image/spl_load_spi.c
arch/sandbox/include/asm/spl.h +1 -0
index cf16af5278a..f349ea19971 100644
@@ -14,6 +14,7 @@ enum {
 	BOOT_DEVICE_VBE,
 	BOOT_DEVICE_CPGMAC,
 	BOOT_DEVICE_NOR,
+	BOOT_DEVICE_SPI,
 };
 
 /**
configs/sandbox_noinst_defconfig +6 -0
index 085cc30c1e2..db05e630832 100644
@@ -4,6 +4,7 @@ CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2000
+CONFIG_SPL_DM_SPI=y
 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
 CONFIG_DM_RESET=y
 CONFIG_SPL_MMC=y
@@ -12,6 +13,8 @@ CONFIG_SPL_DRIVERS_MISC=y
 CONFIG_SPL_SYS_MALLOC_F_LEN=0x8000
 CONFIG_SPL=y
 CONFIG_SPL_FS_FAT=y
+CONFIG_SPL_SPI_FLASH_SUPPORT=y
+CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x1000000
 CONFIG_PCI=y
 CONFIG_SANDBOX_SPL=y
@@ -48,9 +51,12 @@ CONFIG_SPL_ETH=y
 CONFIG_SPL_FS_EXT4=y
 CONFIG_SPL_I2C=y
 CONFIG_SPL_MMC_WRITE=y
+CONFIG_SPL_DM_SPI_FLASH=y
 CONFIG_SPL_NET=y
 CONFIG_SPL_NOR_SUPPORT=y
 CONFIG_SPL_RTC=y
+# CONFIG_SPL_SPI_FLASH_TINY is not set
+CONFIG_SPL_SPI_LOAD=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
 CONFIG_CMD_BOOTZ=y
include/spl.h +10 -0
index 708b15a0c7f..2c32e37e6b0 100644
@@ -416,6 +416,16 @@ int spl_load_imx_container(struct spl_image_info *spl_image,
 void preloader_console_init(void);
 u32 spl_boot_device(void);
 
+struct spi_flash;
+
+/**
+ * spl_spi_get_uboot_offs() - Lookup function for the SPI boot offset
+ * @flash: The spi flash to boot from
+ *
+ * Return: The offset of U-Boot within the SPI flash
+ */
+unsigned int spl_spi_get_uboot_offs(struct spi_flash *flash);
+
 /**
  * spl_spi_boot_bus() - Lookup function for the SPI boot bus source.
  *
test/image/Kconfig +8 -0
index 99c50787816..8f9e6ae036b 100644
@@ -32,6 +32,14 @@ config SPL_UT_LOAD_NET
 	help
 	  Test loading images over TFTP using the NET image load method.
 
+config SPL_UT_LOAD_SPI
+	bool "Test loading from SPI Flash"
+	depends on SANDBOX && SPL_OF_REAL
+	depends on SPL_SPI_LOAD
+	default y
+	help
+	  Test the SPI flash image load metod.
+
 config SPL_UT_LOAD_OS
 	bool "Test loading from the host OS"
 	depends on SANDBOX && SPL_LOAD_FIT
test/image/Makefile +1 -0
index a82aa40449d..b30210106a4 100644
@@ -7,3 +7,4 @@ obj-$(CONFIG_SPL_UT_LOAD_FS) += spl_load_fs.o
 obj-$(CONFIG_SPL_UT_LOAD_NET) += spl_load_net.o
 obj-$(CONFIG_SPL_NOR_SUPPORT) += spl_load_nor.o
 obj-$(CONFIG_SPL_UT_LOAD_OS) += spl_load_os.o
+obj-$(CONFIG_SPL_UT_LOAD_SPI) += spl_load_spi.o
test/image/spl_load.c +1 -0
index 07a986258d9..ab4c14d6491 100644
@@ -9,6 +9,7 @@
 #include <mapmem.h>
 #include <memalign.h>
 #include <rand.h>
+#include <spi_flash.h>
 #include <spl.h>
 #include <test/spl.h>
 #include <test/ut.h>
test/image/spl_load_spi.c new file +41 -0

41 lines not on this page · raw message

test/py/tests/test_spl.py +10 -0
index bd273dad893..42e4c4342b2 100644
@@ -5,6 +5,16 @@
 import os.path
 import pytest
 
[email protected]('spl_unit_test')
+def test_ut_spl_init(u_boot_console):
+    """Initialize data for ut spl tests."""
+
+    fn = u_boot_console.config.source_dir + '/spi.bin'
+    if not os.path.exists(fn):
+        data = b'\x00' * (2 * 1024 * 1024)
+        with open(fn, 'wb') as fh:
+            fh.write(data)
+
 def test_spl(u_boot_console, ut_spl_subtest):
     """Execute a "ut" subtest.
 
Signature · 1 line
2.37.1
#42 lore raw
In reply to Sean Anderson
Quoted 31 lines · Sean Anderson

This series adds some tests for various SPL load methods, with the intent of helping debug v6 of [1]. With that in mind, notable omissions include NAND and ROMAPI, which both lack sandbox implementations, and OS_BOOT, which I have deferred due to its complexity. Semihosting is also omitted, but I think we can test that with qemu.

In order to test all of these methods, we must first generate suitable images, possibly on filesystems. While other tests have historically generated these images using external tools (e.g. mkimage, mkfs, etc.), I have chosen to generate them on the fly. This is for a few reasons:

- By removing external dependencies on pytest to create certain files, the tests become self-contained. This makes them easier to iterate on and debug.
- By generating tests at runtime, we can dynamically vary the content. This helps detect test failures, as even if tests are loaded to the same location, the expected content will be different.
- We are not testing the image parsers themselves (e.g. spl_load_simple_fit or fs_read) but rather the load methods (e.g. spl_mmc_load_image). It is unnecessary to exercise full functionality or generate 100% correct images.
- By reducing functionality to only what is necessary, the complexity of various formats can often be greatly reduced.

This series depends on [2-3], which are small fixes identified through this patch set. The organization of patches in this series is as follows:

- General fixes for bugs which are unlikely to be triggered outside of this series
- Changes to IMX8 container images to facilitate testing
- General prep. work, particularly regarding linker issues
- The tests themselves

Quoted 6 lines

Passing CI at [4].

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://source.denx.de/u-boot/custodians/u-boot-clk/-/pipelines/18128

For the series, applied to u-boot/master, thanks!

Signature · 1 line
Tom