test: spl: Test some load methods
Subsystems (8)
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
Mostly-passing CI at [4]; I have since fixed the typo/missing cast.
[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/18091
Sean Anderson (26):
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: 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: ext4: Fix building ext4 in SPL if write is enabled
fs: Compile in sandbox filesystem in SPL if it is enabled
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: Don't cache devices when UNIT_TEST is enabled
spl: Use map_sysmem where appropriate
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 | 3 + 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 | 13 +- common/spl/spl_fit.c | 40 +- .../spl/spl_imx_container.c | 12 +- common/spl/spl_legacy.c | 8 +- common/spl/spl_mmc.c | 11 +- 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/Makefile | 1 + include/configs/sandbox.h | 3 + include/ext4fs.h | 1 + include/ext_common.h | 14 + .../image.h => include/imx_container.h | 9 + include/spl.h | 14 + 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 | 693 ++++++++++++++++-- test/image/spl_load_fs.c | 423 +++++++++++ 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, 1966 insertions(+), 163 deletions(-) rename arch/arm/mach-imx/parse-container.c => common/spl/spl_imx_container.c (92%) 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
PATCH 1/26 spl: legacy: Fix referencing _image_binary_end
On non-arm architectures, _image_binary_end is defined as a ulong and not a char[]. Dereference it when accessing it, which is correct for both.
---
common/spl/spl_legacy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/spl/spl_legacy.c +1 -1
@@ -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
Re: [PATCH 01/26] spl: legacy: Fix referencing _image_binary_end
Quoted 3 lines · Sean Anderson
On non-arm architectures,
_image_binary_endis defined as a ulong and not a char[]. Dereference it when accessing it, which is correct for both.
Is 'dereference' the right word?
Quoted 7 lines
Fixes 1b8a1be1a1f ("spl: spl_legacy: Fix spl_end address")Signed-off-by Sean Anderson <[email protected]>---
common/spl/spl_legacy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 17 lines
common/spl/spl_legacy.c +1
-2@@ -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) || --2.37.1
Re: [PATCH 01/26] spl: legacy: Fix referencing _image_binary_end
Quoted 6 lines · Simon Glass
Quoted 3 lines · Sean Anderson
On non-arm architectures,
_image_binary_endis defined as a ulong and not a char[]. Dereference it when accessing it, which is correct for both.Is 'dereference' the right word?
Yeah...
"Take the address of it when accessing it"?
--Sean
Quoted 28 lines
Quoted 7 lines
Fixes 1b8a1be1a1f ("spl: spl_legacy: Fix spl_end address")Signed-off-by Sean Anderson <[email protected]>---
common/spl/spl_legacy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>Quoted 17 lines
common/spl/spl_legacy.c +1
-2@@ -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) || --2.37.1
Re: [PATCH 01/26] spl: legacy: Fix referencing _image_binary_end
Hi Sean,
Quoted 4 lines · Sean Anderson
Quoted 2 lines · Simon Glass
Quoted 1 line · Sean Anderson
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
On non-arm architectures,
_image_binary_endis defined as a ulong and not a char[]. Dereference it when accessing it, which is correct for both.Is 'dereference' the right word?
Yeah...
"Take the address of it when accessing it"?
That seems better.
Regards,
Simon
Quoted 32 lines
--Sean
Quoted 28 lines
Quoted 7 lines
Fixes 1b8a1be1a1f ("spl: spl_legacy: Fix spl_end address")Signed-off-by Sean Anderson <[email protected]>---
common/spl/spl_legacy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>Quoted 17 lines
common/spl/spl_legacy.c +1
-2@@ -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) || --2.37.1
PATCH 2/26 spl: nor: Don't allocate header on stack
In reply to Sean Andersonspl_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.
---
common/spl/spl_nor.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
common/spl/spl_nor.c +4 -7
@@ -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
Re: [PATCH 02/26] spl: nor: Don't allocate header on stack
Quoted 11 lines · 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 in06377c5a1fc("spl:spl_legacy: Fix NAND boot on OMAP3 BeagleBoard"), but that commit didn't fix NOR.Signed-off-by Sean Anderson <[email protected]>---
common/spl/spl_nor.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
Michael Nazzareno Trimarchi
Reviewed-byRe: [PATCH 02/26] spl: nor: Don't allocate header on stack
Quoted 8 lines · Simon Glass
Quoted 6 lines · 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 in06377c5a1fc("spl:spl_legacy: Fix NAND boot on OMAP3 BeagleBoard"), but that commit didn't fix NOR.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Sean Anderson <[email protected]>---
common/spl/spl_nor.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)Reviewed-by Simon Glass <[email protected]>
Signature · 11 lines
Michael Nazzareno Trimarchi Co-Founder & Chief Executive Officer M. +39 347 913 2170 [email protected] __________________________________ Amarula Solutions BV Joop Geesinkweg 125, 1114 AB, Amsterdam, NL T. +31 (0)85 111 9172 [email protected] www.amarulasolutions.com
PATCH 3/26 spl: fit: Fix entry point for SPL_LOAD_FIT_FULL
In reply to Sean AndersonThe entry point is not always the same as the load address. Use the value of the entrypoint property if it exists and is nonzero (following the example of spl_load_simple_fit).
---
common/spl/spl_fit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
common/spl/spl_fit.c +3 -1
@@ -884,8 +884,10 @@ 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) + 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
Re: [PATCH 03/26] spl: fit: Fix entry point for SPL_LOAD_FIT_FULL
Quoted 11 lines · Sean Anderson
The entry point is not always the same as the load address. Use the value of the entrypoint property if it exists and is nonzero (following the example of
spl_load_simple_fit).Fixes 8a9dc16e4d0 ("spl: Add full fitImage support")Signed-off-by Sean Anderson <[email protected]>---
common/spl/spl_fit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
The check for 0 makes me uneasy, but I can't imagine it being valid in practice.
Quoted 20 lines
common/spl/spl_fit.c +3
-2@@ -884,8 +884,10 @@ 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) + 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); --2.37.1
Re: [PATCH 03/26] spl: fit: Fix entry point for SPL_LOAD_FIT_FULL
Quoted 10 lines · Simon Glass
Quoted 9 lines · Sean Anderson
The entry point is not always the same as the load address. Use the value of the entrypoint property if it exists and is nonzero (following the example of
spl_load_simple_fit).Fixes 8a9dc16e4d0 ("spl: Add full fitImage support")Signed-off-by Sean Anderson <[email protected]>---
Quoted 6 lines
Quoted 2 lines
common/spl/spl_fit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>The check for 0 makes me uneasy, but I can't imagine it being valid in practice.
This is mostly to match spl_load_simple_fit:
/*
* If a platform does not provide CONFIG_SYS_UBOOT_START, U-Boot's
* Makefile will set it to 0 and it will end up as the entry point
* here. What it actually means is: use the load address. */
SYS_UBOOT_START doesn't seem to be set very often and defaults to TEXT_BASE. That appears to be undefined on
efi-x86_app64 efi-x86_app32 xtfpga 3c120 10m50
but none of these platforms define SPL_LOAD_FIT. So maybe this is moot?
--Sean
Quoted 21 lines
Quoted 21 lines
common/spl/spl_fit.c +3
-2@@ -884,8 +884,10 @@ 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) + 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); --2.37.1
Re: [PATCH 03/26] spl: fit: Fix entry point for SPL_LOAD_FIT_FULL
Quoted 26 lines · Sean Anderson
Quoted 10 lines · Simon Glass
Quoted 9 lines · Sean Anderson
The entry point is not always the same as the load address. Use the value of the entrypoint property if it exists and is nonzero (following the example of
spl_load_simple_fit).Fixes 8a9dc16e4d0 ("spl: Add full fitImage support")Signed-off-by Sean Anderson <[email protected]>---
Quoted 6 lines
Quoted 2 lines
common/spl/spl_fit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>The check for 0 makes me uneasy, but I can't imagine it being valid in practice.
This is mostly to match
spl_load_simple_fit:/*
* If a platform does not provideCONFIG_SYS_UBOOT_START, U-Boot's
*Makefilewill set it to 0 and it will end up as the entry point
* here. What it actually means is: use the load address. */
Quoted 6 lines
SYS_UBOOT_STARTdoesn't seem to be set very often and defaults toTEXT_BASE. That appears to be undefined onefi-x86_app64 efi-x86_app32 xtfpga 3c120 10m50but none of these platforms define
SPL_LOAD_FIT. So maybe this is moot?
Moot for the last 3 there yes. Not sure about the U-Boot as EFI app builds.
Signature · 1 line
Tom
Re: [PATCH 03/26] spl: fit: Fix entry point for SPL_LOAD_FIT_FULL
In reply to Sean AndersonHi,
Quoted 27 lines · Sean Anderson
Quoted 10 lines · Simon Glass
Quoted 9 lines · Sean Anderson
The entry point is not always the same as the load address. Use the value of the entrypoint property if it exists and is nonzero (following the example of
spl_load_simple_fit).Fixes 8a9dc16e4d0 ("spl: Add full fitImage support")Signed-off-by Sean Anderson <[email protected]>---
Quoted 6 lines
Quoted 2 lines
common/spl/spl_fit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>The check for 0 makes me uneasy, but I can't imagine it being valid in practice.
This is mostly to match
spl_load_simple_fit:/*
* If a platform does not provideCONFIG_SYS_UBOOT_START, U-Boot's
*Makefilewill set it to 0 and it will end up as the entry point
* here. What it actually means is: use the load address. */
Quoted 6 lines
SYS_UBOOT_STARTdoesn't seem to be set very often and defaults toTEXT_BASE. That appears to be undefined onefi-x86_app64 efi-x86_app32 xtfpga 3c120 10m50but none of these platforms define
SPL_LOAD_FIT. So maybe this is moot?
Yes, it should be fine.
Regards,
Simon
Quoted 25 lines
--Sean
Quoted 21 lines
Quoted 21 lines
common/spl/spl_fit.c +3
-2@@ -884,8 +884,10 @@ 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) + 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); --2.37.1
PATCH 4/26 arm: imx: Fix i.MX8 container load address
In reply to Sean AndersonWe should load images to their destination, not their entry point.
---
arch/arm/mach-imx/parse-container.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-imx/parse-container.c +1 -1
@@ -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
PATCH 5/26 arm: imx: Add newlines after error messages
In reply to Sean AndersonThese error messages are missing newlines. Add them.
---
arch/arm/mach-imx/parse-container.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-imx/parse-container.c +2 -2
@@ -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
Re: [PATCH 05/26] arm: imx: Add newlines after error messages
Quoted 14 lines · Sean Anderson
These error messages are missing newlines. Add them.
Fixes 6e81ca220e0 ("imx: parse-container: Use malloc for container processing")Signed-off-by Sean Anderson <[email protected]>---
arch/arm/mach-imx/parse-container.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/arm/mach-imx/parse-container.c +0
-0
arch/arm/mach-imx/parse-container.c static int read_auth_container(struct spl_image_info *spl_image, · line 88
Quoted 5 lines
arch/arm/mach-imx/parse-container.c +1
-1@@ -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" );
Please, use log_err() and add
#define LOG_CATEGORY LOGC_ARCH
to the top of the file.
Best regards
Heinrich
Quoted 10 lines
arch/arm/mach-imx/parse-container.c +1
-1ret = -ENOENT ; goto end; }if (!container->num_images) { -printf ("Wrong container, no image found" ); +printf ("Wrong container, no image found\n" ); ret = -ENOENT ; goto end; }
PATCH 6/26 arm: imx: Add function to validate i.MX8 containers
In reply to Sean AndersonAdd a function to abstract the common task of validating i.MX8 container image headers.
---
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -84,7 +84,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)) {printf ("Wrong container header\n" ); ret = -ENOENT ; goto end;
arch/arm/mach-imx/spl_imx_romapi.c +2 -1
@@ -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
PATCH 7/26 arm: imx: Check header before calling spl_load_imx_container
In reply to Sean AndersonMake 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.
To avoid too much bloat, Legacy/Raw images are disabled for the four configs which only boot from raw MMC.
Future work could include merging imx_container.h with imx8image.h, since they appear to define mostly the same structures.
---
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -6,9 +6,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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Signature · 1 line
2.37.1
Re: [PATCH 07/26] arm: imx: Check header before calling spl_load_imx_container
Quoted 3 lines · 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.
Looking at CONFIG_AHAB_BOOT (related to secure boot) we must be sure that we don't introduce any unsolicited fallback on existing configurations.
Best regards
Heinrich
Quoted 341 lines
To avoid too much bloat, Legacy/Raw images are disabled for the four configs which only boot from raw MMC.
Future work could include merging
imx_container.hwithimx8image.h, since they appear to define mostly the same structures.Signed-off-by Sean Anderson <[email protected]>---
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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -6,9 +6,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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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=yconfigs/giedi_defconfig +2
-0@@ -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=yconfigs/imx8qm_mek_defconfig +2
-0@@ -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=yconfigs/imx8qxp_mek_defconfig +2
-0@@ -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=ydrivers/usb/gadget/f_sdp.c +3
-1@@ -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
Re: [PATCH 07/26] arm: imx: Check header before calling spl_load_imx_container
Quoted 7 lines · Heinrich Schuchardt
Quoted 3 lines · 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.Looking at
CONFIG_AHAB_BOOT(related to secure boot) we must be sure that we don't introduce any unsolicited fallback on existing configurations.
There are no in-tree boards with SPL_LOAD_IMX_CONTAINER and AHAB_BOOT both enabled.
--Sean
Quoted 342 lines
Quoted 341 lines
To avoid too much bloat, Legacy/Raw images are disabled for the four configs which only boot from raw MMC.
Future work could include merging
imx_container.hwithimx8image.h, since they appear to define mostly the same structures.Signed-off-by Sean Anderson <[email protected]>---
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 | 018 files changed, 34 insertions(+), 14 deletions(-)rename
arch/arm/include/asm/mach-imx/image.h=>include/imx_container.h(100%)MAINTAINERS +0
-0@@ -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.hARM HISILICON
M: Peter Griffin <[email protected]>arch/arm/include/asm/mach-imx/ahab.h +1
-1@@ -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@@ -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@@ -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@@ -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@@ -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@@ -6,9 +6,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> #endifarch/arm/mach-imx/spl_imx_romapi.c +3
-2@@ -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@@ -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@@ -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@@ -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@@ -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 +0
-0@@ -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=yconfigs/deneb_defconfig +2
-0+# 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_ADDRis not set
CONFIG_SPL_SYS_MALLOC=yconfigs/giedi_defconfig +0
-0@@ -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=yconfigs/giedi_defconfig +2
-0+# 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_ADDRis not set
CONFIG_SPL_SYS_MALLOC=yconfigs/imx8qm_mek_defconfig +0
-0@@ -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=yconfigs/imx8qm_mek_defconfig +2
-0+# 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_ADDRis not set
CONFIG_SPL_SYS_MALLOC=yconfigs/imx8qxp_mek_defconfig +0
-0@@ -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=yconfigs/imx8qxp_mek_defconfig +2
-0+# 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_ADDRis not set
CONFIG_SPL_SYS_MALLOC=ydrivers/usb/gadget/f_sdp.c +3
-1@@ -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
Re: [PATCH 07/26] arm: imx: Check header before calling spl_load_imx_container
In reply to Sean AndersonQuoted 11 lines · 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.To avoid too much bloat, Legacy/Raw images are disabled for the four configs which only boot from raw MMC.
Future work could include merging
imx_container.hwithimx8image.h, since they appear to define mostly the same structures.Signed-off-by Sean Anderson <[email protected]>
So, since you mention bloat, this sounds like it's making functional changes here, but that's not intentional, yes? Or to ask another way, is deneb disabling features here, to save space now that it can, or because they're growing "a bunch" and this reduces the growth?
Signature · 1 line
Tom
Re: [PATCH 07/26] arm: imx: Check header before calling spl_load_imx_container
Quoted 11 lines · Tom Rini
Quoted 10 lines · 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.To avoid too much bloat, Legacy/Raw images are disabled for the four configs which only boot from raw MMC.
Future work could include merging
imx_container.hwithimx8image.h, since they appear to define mostly the same structures.
Quoted 7 lines
Quoted 1 line
Signed-off-by Sean Anderson <[email protected]>So, since you mention bloat, this sounds like it's making functional changes here, but that's not intentional, yes? Or to ask another way, is deneb disabling features here, to save space now that it can, or because they're growing "a bunch" and this reduces the growth?
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 supported IMX8 images. With this change, support for these image types now has an effect.
There are seven boards with SPL_LOAD_IMX_CONTAINER enabled:
imx93_11x11_evk_ld imx8qm_mek imx8qxp_mek giedi imx93_11x11_evk imx8ulp_evk deneb
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.
--Sean
Re: [PATCH 07/26] arm: imx: Check header before calling spl_load_imx_container
Quoted 30 lines · Sean Anderson
Quoted 11 lines · Tom Rini
Quoted 10 lines · 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.To avoid too much bloat, Legacy/Raw images are disabled for the four configs which only boot from raw MMC.
Future work could include merging
imx_container.hwithimx8image.h, since they appear to define mostly the same structures.Quoted 7 lines
Quoted 1 line
Signed-off-by Sean Anderson <[email protected]>So, since you mention bloat, this sounds like it's making functional changes here, but that's not intentional, yes? Or to ask another way, is deneb disabling features here, to save space now that it can, or because they're growing "a bunch" and this reduces the growth?
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 supported IMX8 images. With this change, support for these image types now has an effect.There are seven boards with
SPL_LOAD_IMX_CONTAINERenabled:
imx93_11x11_evk_ldimx8qm_mekimx8qxp_mekgiediimx93_11x11_evkimx8ulp_evkdeneb
Quoted 8 lines
All of these boards also have
SPL_RAW_IMAGE_SUPPORTandSPL_LEGACY_IMAGE_FORMATenabled as well. However, none have FIT support enabled. Of the six load methods affected by this patch, onlySPL_MMCandSPL_BOOTROM_SUPPORTare enabled withSPL_LOAD_IMX_CONTAINER.spl_romapi_load_image_seekabledoes not support legacy or raw images, so there is no growth. However,mmc_load_image_raw_sectordoes 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.
Ah, OK, thanks for explaining.
Signature · 1 line
Tom
PATCH 8/26 Move i.MX8 container image loading support to common/spl
In reply to Sean AndersonTo facilitate testing loading i.MX8 container images, move the parse-container code to common/spl.
---
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Signature · 1 line
2.37.1
PATCH 9/26 spl: Allow enabling SPL_OF_REAL and SPL_OF_PLATDATA at the same time
In reply to Sean AndersonSandbox 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.
---
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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" + 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
@@ -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
Re: [PATCH 09/26] spl: Allow enabling SPL_OF_REAL and SPL_OF_PLATDATA at the same time
Hi Sean,
Quoted 16 lines · 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 haveSPL_OF_PLATDATAenabled. When generating platdata from a devicetree, it is expected that we will not need devicetree access functions (even thoughSPL_OF_CONTROLis enabled). This expectation does not hold for sandbox, so allow user control ofSPL_OF_REAL.There are several places in the tree where conditions involving
OF_PLATDATAorOF_REALno longer function correctly when both of these options can be selected at the same time. Adjust these conditions accordingly.Signed-off-by Sean Anderson <[email protected]>---
Quoted 7 lines
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(-)
with a due sense of foreboding
I wonder whether this might create confusion?
Quoted 57 lines
drivers/core/Makefile +1
-0@@ -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) += -DDEBUGdrivers/i2c/i2c-emul-uclass.c +1
-1@@ -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@@ -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@@ -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 +0
-0
dts/Kconfig config SPL_OF_PLATDATA · line 413
Quoted 5 lines
dts/Kconfig +1
-1@@ -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"
To avoid the user doing something silly, I wonder if it would be better to keep this option hidden, but enable it for sandbox_spl via Kconfig?
Quoted 26 lines
dts/Kconfig +4
-2+ 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_PLATDATAtest/test-main.c +1
-2@@ -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 --
Quoted 2 lines
2.37.1
Regards,
Simon
Re: [PATCH 09/26] spl: Allow enabling SPL_OF_REAL and SPL_OF_PLATDATA at the same time
Quoted 27 lines · Simon Glass
Hi Sean,
Quoted 16 lines · 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 haveSPL_OF_PLATDATAenabled. When generating platdata from a devicetree, it is expected that we will not need devicetree access functions (even thoughSPL_OF_CONTROLis enabled). This expectation does not hold for sandbox, so allow user control ofSPL_OF_REAL.There are several places in the tree where conditions involving
OF_PLATDATAorOF_REALno longer function correctly when both of these options can be selected at the same time. Adjust these conditions accordingly.Signed-off-by Sean Anderson <[email protected]>---
Quoted 7 lines
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(-)
Quoted 5 lines
Reviewed-by Simon Glass <[email protected]>with a due sense of foreboding
I wonder whether this might create confusion?
Yeah, I was a bit worried about that as well.
Quoted 59 lines
Quoted 59 lines
drivers/core/Makefile +1
-0@@ -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) += -DDEBUGdrivers/i2c/i2c-emul-uclass.c +1
-1@@ -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@@ -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@@ -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 +0
-0@@ -410,12 +410,14 @@ config SPL_OF_PLATDATA declarations for each node. See of-plat.txt for more information.
Quoted 7 lines
dts/Kconfig config SPL_OF_PLATDATA · line 413
Quoted 3 lines
dts/Kconfig +1
-1config SPL_OF_REAL - bool + bool "Support a real devicetree in SPL"To avoid the user doing something silly, I wonder if it would be better to keep this option hidden, but enable it for
sandbox_splviaKconfig?
So
visible if SANDBOX
?
Quoted 31 lines
Quoted 26 lines
dts/Kconfig +4
-2+ 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_PLATDATAtest/test-main.c +1
-2@@ -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 -- Quoted 2 lines
2.37.1
Regards,
Simon
PATCH 10/26 lib: acpi: Fix linking SPL when ACPIGEN is enabled
In reply to Sean Andersonlib/acpi/acpigen.o is only compiled into SPL when SPL_ACPIGEN is enabled. Update several files which reference these functions accordingly.
---
drivers/core/root.c | 2 +- drivers/i2c/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/core/root.c +1 -1
@@ -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
@@ -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
Re: [PATCH 10/26] lib: acpi: Fix linking SPL when ACPIGEN is enabled
Quoted 11 lines · Sean Anderson
lib/acpi/acpigen.ois only compiled into SPL whenSPL_ACPIGENis enabled. Update several files which reference these functions accordingly.Signed-off-by Sean Anderson <[email protected]>---
drivers/core/root.c | 2 +- drivers/i2c/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
PATCH 11/26 fs: ext4: Fix building ext4 in SPL if write is enabled
In reply to Sean AndersonIf EXT4_WRITE is enabled, write capabilities will be compiled into SPL, but not CRC16. Add an option to enable CRC16 to avoid linker errors.
---
common/spl/Kconfig | 1 + lib/Kconfig | 6 ++++++ lib/Makefile | 1 + 3 files changed, 8 insertions(+)
common/spl/Kconfig +1 -0
@@ -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
@@ -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
@@ -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
Re: [PATCH 11/26] fs: ext4: Fix building ext4 in SPL if write is enabled
Quoted 11 lines · Sean Anderson
If
EXT4_WRITEis enabled, write capabilities will be compiled into SPL, but not CRC16. Add an option to enable CRC16 to avoid linker errors.Signed-off-by Sean Anderson <[email protected]>---
common/spl/Kconfig | 1 + lib/Kconfig | 6 ++++++ lib/Makefile | 1 + 3 files changed, 8 insertions(+)
PATCH 12/26 fs: Compile in sandbox filesystem in SPL if it is enabled
In reply to Sean Andersonfs.c thinks that the sandbox filesystem is available if SANDBOX is enabled, but it is not in SPL. Compile it in SPL to avoid linker errors.
---
fs/Makefile | 1 + 1 file changed, 1 insertion(+)
fs/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_FS_LOADER) += fs.o obj-$(CONFIG_SPL_FS_FAT) += fat/ obj-$(CONFIG_SPL_FS_EXT4) += ext4/ obj-$(CONFIG_SPL_FS_CBFS) += cbfs/ +obj-$(CONFIG_SANDBOX) += sandbox/ obj-$(CONFIG_SPL_FS_SQUASHFS) += squashfs/ else obj-y += fs.o
Signature · 1 line
2.37.1
Re: [PATCH 12/26] fs: Compile in sandbox filesystem in SPL if it is enabled
Quoted 10 lines · Sean Anderson
fs.cthinks that the sandbox filesystem is available if SANDBOX is enabled, but it is not in SPL. Compile it in SPL to avoid linker errors.Signed-off-by Sean Anderson <[email protected]>---
fs/Makefile | 1 + 1 file changed, 1 insertion(+)
Re: [PATCH 12/26] fs: Compile in sandbox filesystem in SPL if it is enabled
In reply to Sean AndersonQuoted 14 lines · Sean Anderson
fs.cthinks that the sandbox filesystem is available if SANDBOX is enabled, but it is not in SPL. Compile it in SPL to avoid linker errors.Signed-off-by Sean Anderson <[email protected]>---
fs/Makefile | 1 + 1 file changed, 1 insertion(+)fs/Makefile +0
-0
fs/Makefile obj-$(CONFIG_FS_LOADER) += fs.o · line 12
Quoted 4 lines
fs/Makefile +1
-0@@ -9,6 +9,7 @@ obj-$(CONFIG_FS_LOADER) += fs.o obj-$(CONFIG_SPL_FS_FAT) += fat/ obj-$(CONFIG_SPL_FS_EXT4) += ext4/ obj-$(CONFIG_SPL_FS_CBFS) += cbfs/ +obj-$(CONFIG_SANDBOX) += sandbox/
Why wouldn't you use CONFIG_SANDBOX_SPL here?
Best regards
Heinrich
Quoted 3 lines
fs/Makefile +0
-0obj-$(CONFIG_SPL_FS_SQUASHFS) += squashfs/ else obj-y += fs.o
Re: [PATCH 12/26] fs: Compile in sandbox filesystem in SPL if it is enabled
Quoted 10 lines · Heinrich Schuchardt
Quoted 9 lines · Sean Anderson
fs.cthinks that the sandbox filesystem is available if SANDBOX is enabled, but it is not in SPL. Compile it in SPL to avoid linker errors.Signed-off-by Sean Anderson <[email protected]>---
fs/Makefile | 1 +
1 file changed, 1 insertion(+)
Quoted 11 lines
Quoted 9 lines
fs/Makefile +0
-0@@ -9,6 +9,7 @@ obj-$(CONFIG_FS_LOADER) += fs.oobj-$(CONFIG_SPL_FS_FAT) += fat/
obj-$(CONFIG_SPL_FS_EXT4) += ext4/
obj-$(CONFIG_SPL_FS_CBFS) += cbfs/
+obj-$(CONFIG_SANDBOX) += sandbox/Why wouldn't you use
CONFIG_SANDBOX_SPLhere?
Because that's what the check is in fs.c. Maybe it should be CONFIG_IS_ENABLED(SANDBOX) in there.
--Sean
Re: [PATCH 12/26] fs: Compile in sandbox filesystem in SPL if it is enabled
Quoted 23 lines · Sean Anderson
Quoted 10 lines · Heinrich Schuchardt
Quoted 9 lines · Sean Anderson
fs.cthinks that the sandbox filesystem is available if SANDBOX is enabled, but it is not in SPL. Compile it in SPL to avoid linker errors.Signed-off-by Sean Anderson <[email protected]>---
fs/Makefile | 1 +
1 file changed, 1 insertion(+)Quoted 11 lines
Quoted 9 lines
fs/Makefile +0
-0@@ -9,6 +9,7 @@ obj-$(CONFIG_FS_LOADER) += fs.oobj-$(CONFIG_SPL_FS_FAT) += fat/
obj-$(CONFIG_SPL_FS_EXT4) += ext4/
obj-$(CONFIG_SPL_FS_CBFS) += cbfs/
+obj-$(CONFIG_SANDBOX) += sandbox/Why wouldn't you use
CONFIG_SANDBOX_SPLhere?
Quoted 2 lines
Because that's what the check is in
fs.c. Maybe it should beCONFIG_IS_ENABLED(SANDBOX)in there.
"CONFIG_SANDBOX_SPL" is not "CONFIG_SPL_SANDBOX", so CONFIG_IS_ENABLED doesn't work. I would suggest that fs/Makefile needs a bit of cleaning to make use of obj-$(CONFIG_$(SPL_)_... logic instead of ifdef CONFIG_SPL_BUILD, but I think Simon dislikes that form. We could just move the existing line outside of the SPL/else conditional.
Signature · 1 line
Tom
Re: [PATCH 12/26] fs: Compile in sandbox filesystem in SPL if it is enabled
In reply to Sean AndersonQuoted 23 lines · Sean Anderson
Quoted 10 lines · Heinrich Schuchardt
Quoted 9 lines · Sean Anderson
fs.cthinks that the sandbox filesystem is available if SANDBOX is enabled, but it is not in SPL. Compile it in SPL to avoid linker errors.Signed-off-by Sean Anderson <[email protected]>---
fs/Makefile | 1 +
1 file changed, 1 insertion(+)Quoted 11 lines
Quoted 9 lines
fs/Makefile +0
-0@@ -9,6 +9,7 @@ obj-$(CONFIG_FS_LOADER) += fs.oobj-$(CONFIG_SPL_FS_FAT) += fat/
obj-$(CONFIG_SPL_FS_EXT4) += ext4/
obj-$(CONFIG_SPL_FS_CBFS) += cbfs/
+obj-$(CONFIG_SANDBOX) += sandbox/Why wouldn't you use
CONFIG_SANDBOX_SPLhere?
Quoted 2 lines
Because that's what the check is in
fs.c. Maybe it should beCONFIG_IS_ENABLED(SANDBOX)in there.
And, yes I just said one thing, but on the other hand, if we don't need this for tests in SPL then fixing fs/fs.c instead is indeed better.
Signature · 1 line
Tom
PATCH 13/26 net: Fix compiling SPL when fastboot is enabled
In reply to Sean AndersonWhen 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.
---
net/Makefile | 4 ++-- net/net.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
net/Makefile +2 -2
@@ -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_)UDP_FUNCTION_FASTBOOT) += fastboot_udp.o +obj-$(CONFIG_$(SPL_)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
@@ -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
Re: [PATCH 13/26] net: Fix compiling SPL when fastboot is enabled
Quoted 5 lines · Sean Anderson
When fastboot is enabled in U-Boot proper and
SPL_NETis enabled, we will try to (unsuccessfully) reference it in SPL. Fix these linker errors by conditioning on SPL_UDP/TCP_FUNCTION_FASTBOOT.
Quoted 7 lines
Signed-off-by Sean Anderson <[email protected]>---
net/Makefile | 4 ++-- net/net.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
Re: [PATCH 13/26] net: Fix compiling SPL when fastboot is enabled
In reply to Sean AndersonQuoted 16 lines · Sean Anderson
When fastboot is enabled in U-Boot proper and
SPL_NETis enabled, we will try to (unsuccessfully) reference it in SPL. Fix these linker errors by conditioning on SPL_UDP/TCP_FUNCTION_FASTBOOT.Signed-off-by Sean Anderson <[email protected]>---
net/Makefile | 4 ++-- net/net.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)net/Makefile +0
-0
net/Makefile obj-$(CONFIG_CMD_PCAP) += pcap.o · line 31
Quoted 7 lines
net/Makefile +2
-2@@ -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_)UDP_FUNCTION_FASTBOOT) += fastboot_udp.o +obj-$(CONFIG_$(SPL_)TCP_FUNCTION_FASTBOOT) += fastboot_tcp.o
Please, use $(SPL_TPL) so that we don't have to revisit this should we ever decide to enable fastboot in SPL in future.
Best regards
Heinrich
Quoted 22 lines
net/Makefile +0
-0obj-$(CONFIG_CMD_WOL) += wol.o obj-$(CONFIG_PROT_UDP) += udp.o obj-$(CONFIG_PROT_TCP) += tcp.onet/net.c +2
-2@@ -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 ;
Re: [PATCH 13/26] net: Fix compiling SPL when fastboot is enabled
Quoted 12 lines · Heinrich Schuchardt
Quoted 11 lines · Sean Anderson
When fastboot is enabled in U-Boot proper and
SPL_NETis enabled, we will try to (unsuccessfully) reference it in SPL. Fix these linker errors by conditioning on SPL_UDP/TCP_FUNCTION_FASTBOOT.Signed-off-by Sean Anderson <[email protected]>---
net/Makefile | 4 ++--
net/net.c | 4 ++--2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 15 lines
net/Makefile obj-$(CONFIG_CMD_PCAP) += pcap.o · line 31
Quoted 12 lines
net/Makefile +0
-0@@ -27,8 +27,8 @@ obj-$(CONFIG_CMD_PCAP) += pcap.oobj-$(CONFIG_CMD_RARP) += rarp.o
obj-$(CONFIG_CMD_SNTP) += sntp.o
obj-$(CONFIG_CMD_TFTPBOOT) += tftp.onet/Makefile +2
-2-obj-$(CONFIG_UDP_FUNCTION_FASTBOOT) += fastboot_udp.o -obj-$(CONFIG_TCP_FUNCTION_FASTBOOT) += fastboot_tcp.o +obj-$(CONFIG_$(SPL_)UDP_FUNCTION_FASTBOOT) += fastboot_udp.o +obj-$(CONFIG_$(SPL_)TCP_FUNCTION_FASTBOOT) += fastboot_tcp.oPlease, use $(SPL_TPL) so that we don't have to revisit this should we ever decide to enable fastboot in SPL in future.
You are going to enable fastboot in TPL?
--Sean
Re: [PATCH 13/26] net: Fix compiling SPL when fastboot is enabled
In reply to Sean AndersonQuoted 5 lines · Sean Anderson
When fastboot is enabled in U-Boot proper and
SPL_NETis enabled, we will try to (unsuccessfully) reference it in SPL. Fix these linker errors by conditioning on SPL_UDP/TCP_FUNCTION_FASTBOOT.Signed-off-by Sean Anderson <[email protected]>
Signature · 1 line
Tom
PATCH 14/26 net: bootp: Move port numbers to header
In reply to Sean AndersonThese defines are useful when testing bootp.
---
net/bootp.c | 3 --- net/bootp.h | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-)
net/bootp.c +0 -3
@@ -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
@@ -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
Re: [PATCH 14/26] net: bootp: Move port numbers to header
Quoted 10 lines · Sean Anderson
These defines are useful when testing bootp.
Signed-off-by Sean Anderson <[email protected]>---
net/bootp.c | 3 --- net/bootp.h | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-)
Re: [PATCH 14/26] net: bootp: Move port numbers to header
In reply to Sean AndersonQuoted 3 lines · Sean Anderson
These defines are useful when testing bootp.
Signed-off-by Sean Anderson <[email protected]>
Quoted 34 lines
---
net/bootp.c | 3 --- net/bootp.h | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-)net/bootp.c +0
-3@@ -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@@ -15,6 +15,9 @@/**********************************************************************/ +#define PORT_BOOTPS 67/* BOOTP server UDP port */ +#define PORT_BOOTPC 68/* BOOTP client UDP port */ +/* * BOOTP header. */
PATCH 15/26 net: bootp: Fall back to BOOTP from DHCP when unit testing
In reply to Sean AndersonIf 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.
---
net/bootp.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/bootp.c +6 -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 ) { +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
Re: [PATCH 15/26] net: bootp: Fall back to BOOTP from DHCP when unit testing
Quoted 7 lines · 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_TESTto avoid bloat, since I suspect the number of BOOTP servers in the wild is vanishingly small.
Quoted 6 lines
Signed-off-by Sean Anderson <[email protected]>---
net/bootp.c | 6 ++++++ 1 file changed, 6 insertions(+)
Re: [PATCH 15/26] net: bootp: Fall back to BOOTP from DHCP when unit testing
In reply to Sean AndersonQuoted 17 lines · 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_TESTto avoid bloat, since I suspect the number of BOOTP servers in the wild is vanishingly small.Signed-off-by Sean Anderson <[email protected]>---
net/bootp.c | 6 ++++++ 1 file changed, 6 insertions(+)net/bootp.c +0
-0
net/bootp.c static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip, · line 1079
Quoted 7 lines
net/bootp.c +4
-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 ) { +debug ("got BOOTP response; transitioning to BOUND\n" ); + goto dhcp_got_bootp;
This may result in unexpected behavior when running tests against an actual network. Please, avoid this.
Best regards
Heinrich
Quoted 12 lines
net/bootp.c +2
-0+ }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);
Re: [PATCH 15/26] net: bootp: Fall back to BOOTP from DHCP when unit testing
Quoted 13 lines · Heinrich Schuchardt
Quoted 12 lines · 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_TESTto avoid bloat, since I suspect the number of BOOTP servers in the wild is vanishingly small.Signed-off-by Sean Anderson <[email protected]>---
net/bootp.c| 6 ++++++1 file changed, 6 insertions(+)
Quoted 15 lines
net/bootp.c static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip, · line 1079
Quoted 12 lines
net/bootp.c +4
-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) { + debug("got BOOTP response; transitioning to BOUND\n"); + goto dhcp_got_bootp;This may result in unexpected behavior when running tests against an actual network. Please, avoid this.
What is unexpected behavior? If you get a BOOTP (not DHCP) packet, you should behave according to the BOOTP protocol, not the DHCP protocol.
--Sean
PATCH 16/26 spl: Don't cache devices when UNIT_TEST is enabled
In reply to Sean AndersonSeveral 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. Disable caching so we don't use stale devices.
---
common/spl/spl_fat.c | 2 +- common/spl/spl_mmc.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
common/spl/spl_fat.c +1 -1
@@ -24,7 +24,7 @@ static int spl_register_fat_device(struct blk_desc *block_dev, int partition) {int err =0 ; -if (fat_registered) +if (!CONFIG_IS_ENABLED (UNIT_TEST ) && fat_registered)return err; err =fat_register_device (block_dev, partition);
common/spl/spl_mmc.c +2 -1
@@ -417,7 +417,8 @@ int spl_mmc_load(struct spl_image_info *spl_image,/* Perform peripheral init only once for an mmc device */ mmc_dev =spl_mmc_get_device_index (bootdev->boot_device); -if (!mmc ||spl_mmc_get_mmc_devnum (mmc) != mmc_dev) { +if (CONFIG_IS_ENABLED (UNIT_TEST ) || !mmc || +spl_mmc_get_mmc_devnum (mmc) != mmc_dev) { err =spl_mmc_find_device (&mmc, bootdev->boot_device);if (err)return err;
Signature · 1 line
2.37.1
Re: [PATCH 16/26] spl: Don't cache devices when UNIT_TEST is enabled
Hi Sean,
Quoted 18 lines · 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. Disable caching so we don't use stale devices.Signed-off-by Sean Anderson <[email protected]>---
common/spl/spl_fat.c | 2 +- common/spl/spl_mmc.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)common/spl/spl_fat.c +0
-0
common/spl/spl_fat.c static int spl_register_fat_device(struct blk_desc *block_dev, int partition) · line 27
Quoted 5 lines
common/spl/spl_fat.c +1
-1@@ -24,7 +24,7 @@ static int spl_register_fat_device(struct blk_desc *block_dev, int partition) {int err =0 ; -if (fat_registered) +if (!CONFIG_IS_ENABLED (UNIT_TEST ) && fat_registered)
These sort of things worry me, since we are bringing test code / conditions into the 'real' code. Is it possible to pass this as a parameter, or adjust the value of fat_registered?
Quoted 18 lines
common/spl/spl_fat.c +0
-0return err; err =fat_register_device (block_dev, partition);common/spl/spl_mmc.c +2
-2@@ -417,7 +417,8 @@ int spl_mmc_load(struct spl_image_info *spl_image,/* Perform peripheral init only once for an mmc device */ mmc_dev =spl_mmc_get_device_index (bootdev->boot_device); -if (!mmc ||spl_mmc_get_mmc_devnum (mmc) != mmc_dev) { +if (CONFIG_IS_ENABLED (UNIT_TEST ) || !mmc || +spl_mmc_get_mmc_devnum (mmc) != mmc_dev) { err =spl_mmc_find_device (&mmc, bootdev->boot_device);if (err)return err; --
Quoted 2 lines
2.37.1
Regards,
Simon
Re: [PATCH 16/26] spl: Don't cache devices when UNIT_TEST is enabled
Quoted 24 lines · Simon Glass
Hi Sean,
Quoted 21 lines · 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. Disable caching so we don't use stale devices.Signed-off-by Sean Anderson <[email protected]>---
common/spl/spl_fat.c | 2 +- common/spl/spl_mmc.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)common/spl/spl_fat.c +0
-0@@ -24,7 +24,7 @@ static int spl_register_fat_device(struct blk_desc *block_dev, int partition) {int err =0 ;
Quoted 6 lines
common/spl/spl_fat.c static int spl_register_fat_device(struct blk_desc *block_dev, int partition) · line 27
Quoted 2 lines
common/spl/spl_fat.c +1
-1-if (fat_registered) +if (!CONFIG_IS_ENABLED (UNIT_TEST ) && fat_registered)These sort of things worry me, since we are bringing test code / conditions into the 'real' code. Is it possible to pass this as a parameter, or adjust the value of
fat_registered?
At the moment these variables are static, and I would like to keep them that way to avoid size growth. We really are doing an unusual thing with UNIT_TEST where devices which were previously valid can be free'd and then recreated later. This is why I decided on using UNIT_TEST as the determiner here, since nothing else should cause this situation.
--Sean
Quoted 23 lines
Quoted 18 lines
common/spl/spl_fat.c +0
-0return err; err =fat_register_device (block_dev, partition);common/spl/spl_mmc.c +2
-2@@ -417,7 +417,8 @@ int spl_mmc_load(struct spl_image_info *spl_image,/* Perform peripheral init only once for an mmc device */ mmc_dev =spl_mmc_get_device_index (bootdev->boot_device); -if (!mmc ||spl_mmc_get_mmc_devnum (mmc) != mmc_dev) { +if (CONFIG_IS_ENABLED (UNIT_TEST ) || !mmc || +spl_mmc_get_mmc_devnum (mmc) != mmc_dev) { err =spl_mmc_find_device (&mmc, bootdev->boot_device);if (err)return err; --Quoted 2 lines
2.37.1
Regards,
Simon
Re: [PATCH 16/26] spl: Don't cache devices when UNIT_TEST is enabled
In reply to Sean AndersonQuoted 17 lines · 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. Disable caching so we don't use stale devices.Signed-off-by Sean Anderson <[email protected]>---
common/spl/spl_fat.c | 2 +- common/spl/spl_mmc.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)common/spl/spl_fat.c +0
-0
common/spl/spl_fat.c static int spl_register_fat_device(struct blk_desc *block_dev, int partition) · line 27
Quoted 5 lines
common/spl/spl_fat.c +1
-1@@ -24,7 +24,7 @@ static int spl_register_fat_device(struct blk_desc *block_dev, int partition) {int err =0 ; -if (fat_registered) +if (!CONFIG_IS_ENABLED (UNIT_TEST ) && fat_registered)
Please, avoid separate code paths depending on CONFIG_UNIT_TESTS.
We shouldn't change normal behavior if unit tests are not running. It is preferable to let the unit test framework call a new function resetting fat_registered when needed. This will allow future tests to test all code paths separately.
Best regards
Heinrich
Quoted 17 lines
common/spl/spl_fat.c +0
-0return err; err =fat_register_device (block_dev, partition);common/spl/spl_mmc.c +2
-1@@ -417,7 +417,8 @@ int spl_mmc_load(struct spl_image_info *spl_image,/* Perform peripheral init only once for an mmc device */ mmc_dev =spl_mmc_get_device_index (bootdev->boot_device); -if (!mmc ||spl_mmc_get_mmc_devnum (mmc) != mmc_dev) { +if (CONFIG_IS_ENABLED (UNIT_TEST ) || !mmc || +spl_mmc_get_mmc_devnum (mmc) != mmc_dev) { err =spl_mmc_find_device (&mmc, bootdev->boot_device);if (err)return err;
Re: [PATCH 16/26] spl: Don't cache devices when UNIT_TEST is enabled
Quoted 26 lines · Heinrich Schuchardt
Quoted 17 lines · 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. Disable caching so we don't use stale devices.Signed-off-by Sean Anderson <[email protected]>---
common/spl/spl_fat.c| 2 +-
common/spl/spl_mmc.c| 3 ++-2 files changed, 3 insertions(+), 2 deletions(-)common/spl/spl_fat.c +0
-0common/spl/spl_fat.c static int spl_register_fat_device(struct blk_desc *block_dev, int partition) · line 27
Quoted 5 lines
common/spl/spl_fat.c +1
-1@@ -24,7 +24,7 @@ static int spl_register_fat_device(struct blk_desc *block_dev, int partition) { int err = 0; - if (fat_registered) + if (!CONFIG_IS_ENABLED(UNIT_TEST) && fat_registered)Please, avoid separate code paths depending on
CONFIG_UNIT_TESTS.
Quoted 4 lines
We shouldn't change normal behavior if unit tests are not running. It is preferable to let the unit test framework call a new function resetting
fat_registeredwhen needed. This will allow future tests to test all code paths separately.
OK, that sounds reasonable to me.
--Sean
PATCH 17/26 spl: Use map_sysmem where appropriate
In reply to Sean AndersonAll "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.
---
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
@@ -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
@@ -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
@@ -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
@@ -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>
@@ -74,11 +75,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 )
@@ -99,8 +102,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
@@ -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); }
@@ -898,9 +906,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
@@ -8,6 +8,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>
@@ -45,7 +46,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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [PATCH 17/26] spl: Use map_sysmem where appropriate
Quoted 10 lines · 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_sysmemin appropriate places. We do not generally callunmap_sysmem, since we need the image memory to still be mapped when we jump to the image. This doesn't matter at the moment sinceunmap_sysmemis a no-op.Signed-off-by Sean Anderson <[email protected]>---
Quoted 12 lines
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(-)
PATCH 18/26 test: spl: Split tests up and use some configs
In reply to Sean AndersonIn 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.
---
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 | 81 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 107 insertions(+), 79 deletions(-) create mode 100644 test/image/Kconfig create mode 100644 test/image/spl_load_os.c
test/Kconfig +1 -0
@@ -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
@@ -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
@@ -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
@@ -2,4 +2,5 @@ # # Copyright 2021 Google LLC -obj-$(CONFIG_SPL_BUILD) += spl_load.o +obj-$(CONFIG_SPL_UT_LOAD) += 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 +81 -0
81 lines not on this page · raw message
Signature · 1 line
2.37.1
Re: [PATCH 18/26] test: spl: Split tests up and use some configs
Quoted 9 lines · 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.
Signed-off-by Sean Anderson <[email protected]>---
Quoted 10 lines
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 | 81 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 107 insertions(+), 79 deletions(-) create mode 100644 test/image/Kconfig create mode 100644 test/image/spl_load_os.c
PATCH 19/26 test: spl: Fix spl_test_load not failing if fname doesn't exist
In reply to Sean AndersonReturning 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.
---
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
@@ -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
@@ -59,10 +59,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
Re: [PATCH 19/26] test: spl: Fix spl_test_load not failing if fname doesn't exist
Quoted 9 lines · 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_execinos_jump_to_image. The original name of SPL is gone, and we can't determine the name of U-Boot from the generated name.
Quoted 6 lines
Signed-off-by Sean Anderson <[email protected]>---
configs/sandbox_vpl_defconfig | 1 + test/image/spl_load_os.c | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-)
PATCH 20/26 test: spl: Add functions to create images
In reply to Sean AndersonThis 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.
---
.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 | 352 +++++++++++++++++++++++++++++++ test/image/spl_load_os.c | 5 +- 8 files changed, 495 insertions(+), 4 deletions(-) create mode 100644 include/test/spl.h
.azure-pipelines.yml +4 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 +352 -0
362 lines not on this page · raw message
test/image/spl_load_os.c +1 -4
@@ -6,14 +6,11 @@#include <common.h> #include <image.h> -#include <mapmem.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
Re: [PATCH 20/26] test: spl: Add functions to create images
Quoted 13 lines · 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_FULLas a separate CI run.Signed-off-by Sean Anderson <[email protected]>---
Quoted 10 lines
.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 | 352 +++++++++++++++++++++++++++++++ test/image/spl_load_os.c | 5 +- 8 files changed, 495 insertions(+), 4 deletions(-) create mode 100644 include/test/spl.h
The error handling for the FDT creation is a bit unusual, but it is test code, so if it fails all bets are off. So OK.
Re: [SPAM] [PATCH 20/26] test: spl: Add functions to create images
In reply to Sean AndersonEl Wed, Oct 11, 2023 at 09:56:20PM -0400, Sean Anderson deia:
Quoted 23 lines
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_FULLas a separate CI run.Signed-off-by Sean Anderson <[email protected]>---
.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 | 352 +++++++++++++++++++++++++++++++ test/image/spl_load_os.c | 5 +- 8 files changed, 495 insertions(+), 4 deletions(-) create mode 100644 include/test/spl.h
[...]
Quoted 27 lines
test/image/spl_load.c +11
-0@@ -4,7 +4,15 @@*/ #include <common.h> +#include <image.h> +#include <imx_container.h> #include <mapmem.h> +#include <memalign.h> +#include <rand.h> +#include <spl.h> +#include <test/spl.h> +#include <test/ut.h> +#include <u-boot/crc.h> int board_fit_config_name_match (const char *name) {@@ -15,3 +23,347 @@ struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size) {return map_sysmem (0x100000 ,0 ); } + +/* Try to reuse the load buffer to conserve memory */ +void *board_spl_fit_buffer_addr (ulong fit_size,int sectors,int bl_len)
test/image/spl_load.c struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size) · line 38
Quoted 10 lines
test/image/spl_load.c +10
-0+{ +static void *buf; +static size_t size; +static bool invalid = true; + +if (invalid || size < sectors * bl_len) { +if (!invalid) +free (buf); + buf =malloc_cache_aligned (sectors * bl_len); + invalid = false;
Should size be updated here or am I being thick ?
size = ALIGN(sectors * bl_len, ARCH_DMA_MINALIGN);
Quoted 4 lines
test/image/spl_load.c +4
-0+ } +return buf; +} +
Re: [SPAM] [PATCH 20/26] test: spl: Add functions to create images
Quoted 64 lines · Xavier Drudis Ferran
El Wed, Oct 11, 2023 at 09:56:20PM -0400, Sean Anderson deia:
Quoted 23 lines
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_FULLas a separate CI run.Signed-off-by Sean Anderson <[email protected]>---
.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 | 352 +++++++++++++++++++++++++++++++ test/image/spl_load_os.c | 5 +- 8 files changed, 495 insertions(+), 4 deletions(-)create mode 100644
include/test/spl.h[...]
Quoted 27 lines
test/image/spl_load.c +11
-0@@ -4,7 +4,15 @@*/ #include <common.h> +#include <image.h> +#include <imx_container.h> #include <mapmem.h> +#include <memalign.h> +#include <rand.h> +#include <spl.h> +#include <test/spl.h> +#include <test/ut.h> +#include <u-boot/crc.h> int board_fit_config_name_match (const char *name) {@@ -15,3 +23,347 @@ struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size) {return map_sysmem (0x100000 ,0 ); } + +/* Try to reuse the load buffer to conserve memory */ +void *board_spl_fit_buffer_addr (ulong fit_size,int sectors,int bl_len)test/image/spl_load.c struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size) · line 38
Quoted 10 lines
test/image/spl_load.c +10
-0+{ +static void *buf; +static size_t size; +static bool invalid = true; + +if (invalid || size < sectors * bl_len) { +if (!invalid) +free (buf); + buf =malloc_cache_aligned (sectors * bl_len); + invalid = false;Should size be updated here or am I being thick ?
Quoted 1 line
size = ALIGN(sectors * bl_len, ARCH_DMA_MINALIGN);
It should.
--Sean
PATCH 21/26 test: spl: Add functions to create filesystems
In reply to Sean AndersonAdd 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.
---
arch/sandbox/cpu/start.c | 9 +- configs/sandbox_noinst_defconfig | 7 + include/ext4fs.h | 1 + include/ext_common.h | 14 ++ include/test/spl.h | 3 + test/image/Kconfig | 11 ++ test/image/Makefile | 1 + test/image/spl_load.c | 1 + test/image/spl_load_fs.c | 305 +++++++++++++++++++++++++++++++ 9 files changed, 350 insertions(+), 2 deletions(-) create mode 100644 test/image/spl_load_fs.c
arch/sandbox/cpu/start.c +7 -2
@@ -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_BOARD_F ) + 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;
configs/sandbox_noinst_defconfig +7 -0
@@ -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/ext4fs.h +1 -0
@@ -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
@@ -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))
include/test/spl.h +3 -0
@@ -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
@@ -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
@@ -3,4 +3,5 @@ # Copyright 2021 Google LLC obj-$(CONFIG_SPL_UT_LOAD) += 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.c +1 -0
@@ -4,6 +4,7 @@*/ #include <common.h> +#include <dm.h> #include <image.h> #include <imx_container.h> #include <mapmem.h>
test/image/spl_load_fs.c new file +305 -0
305 lines not on this page · raw message
Signature · 1 line
2.37.1
Re: [PATCH 21/26] test: spl: Add functions to create filesystems
Hi Sean,
Quoted 9 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.
Signed-off-by Sean Anderson <[email protected]>---
Quoted 11 lines
arch/sandbox/cpu/start.c | 9 +- configs/sandbox_noinst_defconfig | 7 + include/ext4fs.h | 1 + include/ext_common.h | 14 ++ include/test/spl.h | 3 + test/image/Kconfig | 11 ++ test/image/Makefile | 1 + test/image/spl_load.c | 1 + test/image/spl_load_fs.c | 305 +++++++++++++++++++++++++++++++ 9 files changed, 350 insertions(+), 2 deletions(-) create mode 100644 test/image/spl_load_fs.c
Wow there is a lot going on in this patch. It might be good to split it.
Quoted 14 lines
arch/sandbox/cpu/start.c +1
-0@@ -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>
arch/sandbox/cpu/start.c static int sandbox_cmdline_cb_test_fdt(struct sandbox_state *state, · line 209
Quoted 9 lines
arch/sandbox/cpu/start.c +2
-2@@ -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_BOARD_F )
I think <= PHASE_SPL is better since you care about whether it is in SPL or not. I did send a patch to check for SPL, but I don't think it is merged yet.
Quoted 51 lines
arch/sandbox/cpu/start.c +4
-0+ 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;configs/sandbox_noinst_defconfig +6
-0@@ -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
configs/sandbox_noinst_defconfig CONFIG_SYSRESET=y · line 232
Quoted 7 lines
configs/sandbox_noinst_defconfig +1
-0@@ -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
I think these would be better in their own patch
Quoted 34 lines
include/ext4fs.h +1
-0@@ -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 0x0010include/ext_common.h +10
-0@@ -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
include/ext_common.h struct cmd_tbl; · line 67
Quoted 10 lines
include/ext_common.h +4
-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))
Again I think these ext2 changes would be better in their own patch
Quoted 368 lines
include/test/spl.h +3
-0@@ -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@@ -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_FITtest/image/Makefile +1
-0@@ -3,4 +3,5 @@ # Copyright 2021 Google LLC obj-$(CONFIG_SPL_UT_LOAD) += spl_load.o +obj-$(CONFIG_SPL_UT_LOAD_FS) += spl_load_fs.o obj-$(CONFIG_SPL_UT_LOAD_OS) += spl_load_os.otest/image/spl_load.c +1
-0@@ -4,6 +4,7 @@*/ #include <common.h> +#include <dm.h> #include <image.h> #include <imx_container.h> #include <mapmem.h> test/image/spl_load_fs.c new file +305
-1@@ -0,0 +1,305 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2023 Sean Anderson <[email protected]> +*/ + +#include <common.h> +#include <blk.h> +#include <ext_common.h> +#include <ext4fs.h> +#include <fat.h> +#include <fs.h> +#include <memalign.h> +#include <asm/io.h> +#include <linux/stat.h> +#include <test/spl.h> +#include <test/ut.h> + +/** +* create_ext2() - Create an "ext2" filesystem with a single file +* @dst: The location of the new filesystem; MUST be zeroed +* @size: The size of the file +* @filename: The name of the file +* @data_offset: Filled with the offset of the file data from @dst +* +* Budget mke2fs. We use 1k blocks (to reduce overhead) with a single block +* group, which limits us to 8M of data. Almost every feature which increases +* complexity (checksums, hash tree directories, etc.) is disabled. We do cheat +* a little and use extents from ext4 to save having to deal with indirects, but +* U-Boot doesn't care. +* +* If @dst is %NULL, nothing is copied. +* +* Return: The size of the filesystem in bytes +*/ +static size_t create_ext2 (void *dst,size_t size,const char *filename, +size_t *data_offset) +{ +u32 super_block =1 ; +u32 group_block =2 ; +u32 block_bitmap_block =3 ; +u32 inode_bitmap_block =4 ; +u32 inode_table_block =5 ; +u32 root_block =6 ; +u32 file_block =7 ; + +u32 root_ino =EXT2_ROOT_INO ; +u32 file_ino =EXT2_BOOT_LOADER_INO ; + +u32 block_size =EXT2_MIN_BLOCK_SIZE ; +u32 inode_size =sizeof (struct ext2_inode ); + +u32 file_blocks = (size + block_size -1 ) / block_size; +u32 blocks = file_block + file_blocks; +u32 inodes = block_size / inode_size; +u32 filename_len =strlen (filename); +u32 dirent_len =ALIGN (filename_len,sizeof (struct ext2_dirent )) + +sizeof (struct ext2_dirent ); + +struct ext2_sblock *sblock = dst + super_block * block_size; +struct ext2_block_group *bg = dst + group_block * block_size; +struct ext2_inode *inode_table = dst + inode_table_block * block_size; +struct ext2_inode *root_inode = &inode_table[root_ino -1 ]; +struct ext2_inode *file_inode = &inode_table[file_ino -1 ]; +struct ext4_extent_header *ext_block = (void *)&file_inode->b; +struct ext4_extent *extent = (void *)(ext_block +1 ); +struct ext2_dirent *dot = dst + root_block * block_size; +struct ext2_dirent *dotdot = dot +2 ; +struct ext2_dirent *dirent = dotdot +2 ; +struct ext2_dirent *last = ((void *)dirent) + dirent_len; + +/* Make sure we fit in one block group */ +if (blocks > block_size *8 ) +return 0 ; + +if (filename_len >EXT2_NAME_LEN ) +return 0 ; + +if (data_offset) + *data_offset = file_block * block_size; + +if (!dst) + goto out; + + sblock->total_inodes =cpu_to_le32 (inodes); + sblock->total_blocks =cpu_to_le32 (blocks); + sblock->first_data_block =cpu_to_le32 (super_block); + sblock->blocks_per_group =cpu_to_le32 (blocks); + sblock->fragments_per_group =cpu_to_le32 (blocks); + sblock->inodes_per_group =cpu_to_le32 (inodes); + sblock->magic =cpu_to_le16 (EXT2_MAGIC ); +/* Done mostly so we can pretend to be (in)compatible */ + sblock->revision_level =cpu_to_le32 (EXT2_DYNAMIC_REV ); +/* Not really accurate but it doesn't matter */ + sblock->first_inode =cpu_to_le32 (EXT2_GOOD_OLD_FIRST_INO ); + sblock->inode_size =cpu_to_le32 (inode_size); + sblock->feature_incompat =cpu_to_le32 (EXT4_FEATURE_INCOMPAT_EXTENTS ); + + bg->block_id =cpu_to_le32 (block_bitmap_block); + bg->inode_id =cpu_to_le32 (inode_bitmap_block); + bg->inode_table_id =cpu_to_le32 (inode_table_block); + +/* +* All blocks/inodes are in-use. I don't want to have to deal with +* endianness, so just fill everything in. +*/ +memset (dst + block_bitmap_block * block_size,0xff , block_size *2 ); + + root_inode->mode =cpu_to_le16 (S_IFDIR |0755 ); + root_inode->size =cpu_to_le32 (block_size); + root_inode->nlinks =cpu_to_le16 (3 ); + root_inode->blockcnt =cpu_to_le32 (1 ); + root_inode->flags =cpu_to_le32 (EXT4_TOPDIR_FL ); + root_inode->b.blocks.dir_blocks[0 ] = root_block; + + file_inode->mode =cpu_to_le16 (S_IFREG |0644 ); + file_inode->size =cpu_to_le32 (size); + file_inode->nlinks =cpu_to_le16 (1 ); + file_inode->blockcnt =cpu_to_le32 (file_blocks); + file_inode->flags =cpu_to_le32 (EXT4_EXTENTS_FL ); + ext_block->eh_magic =cpu_to_le16 (EXT4_EXT_MAGIC ); + ext_block->eh_entries =cpu_to_le16 (1 ); + ext_block->eh_max =cpu_to_le16 (sizeof (file_inode->b) / +sizeof (*ext_block) -1 ); + extent->ee_len =cpu_to_le16 (file_blocks); + extent->ee_start_lo =cpu_to_le16 (file_block); + +/* I'm not sure we need these, but it can't hurt */ + dot->inode =cpu_to_le32 (root_ino); + dot->direntlen =cpu_to_le16 (2 *sizeof (*dot)); + dot->namelen =1 ; + dot->filetype =FILETYPE_DIRECTORY ; +memcpy (dot +1 ,"." , dot->namelen); + + dotdot->inode =cpu_to_le32 (root_ino); + dotdot->direntlen =cpu_to_le16 (2 *sizeof (*dotdot)); + dotdot->namelen =2 ; + dotdot->filetype =FILETYPE_DIRECTORY ; +memcpy (dotdot +1 ,".." , dotdot->namelen); + + dirent->inode =cpu_to_le32 (file_ino); + dirent->direntlen =cpu_to_le16 (dirent_len); + dirent->namelen = filename_len; + dirent->filetype =FILETYPE_REG ; +memcpy (dirent +1 , filename, filename_len); + + last->direntlen = block_size - dirent_len; + +out: +return (size_t )blocks * block_size; +} + +/** +* create_fat() - Create a FAT32 filesystem with a single file +* @dst: The location of the new filesystem; MUST be zeroed +* @size: The size of the file +* @filename: The name of the file +* @data_offset: Filled with the offset of the file data from @dst +* +* Budget mkfs.fat. We use FAT32 (so I don't have to deal with FAT12) with no +* info sector, and a single one-sector FAT. This limits us to 64k of data +* (enough for anyone). The filename must fit in 8.3. +* +* If @dst is %NULL, nothing is copied. +* +* Return: The size of the filesystem in bytes +*/ +static size_t create_fat (void *dst,size_t size,const char *filename, +size_t *data_offset) +{ +u16 boot_sector =0 ; +u16 fat_sector =1 ; +u32 root_sector =2 ; +u32 file_sector =3 ; + +u16 sector_size =512 ; +u32 file_sectors = (size + sector_size -1 ) / sector_size; +u32 sectors = file_sector + file_sectors; + +char *ext; +size_t filename_len, ext_len; +int i; + +struct boot_sector *bs = dst + boot_sector * sector_size; +struct volume_info *vi = (void *)(bs +1 ); +__le32 *fat = dst + fat_sector * sector_size; +struct dir_entry *dirent = dst + root_sector * sector_size; + +/* Make sure we fit in the FAT */ +if (sectors > sector_size /sizeof (u32)) +return 0 ; + + ext =strchr (filename,'.' ); +if (ext) { + filename_len = ext - filename; + ext++; + ext_len =strlen (ext); + }else { + filename_len =strlen (filename); + ext_len =0 ; + } + +if (filename_len >8 || ext_len >3 ) +return 0 ; + +if (data_offset) + *data_offset = file_sector * sector_size; + +if (!dst) + goto out; + + bs->sector_size[0 ] = sector_size &0xff ; + bs->sector_size[1 ] = sector_size >>8 ; + bs->cluster_size =1 ; + bs->reserved =cpu_to_le16 (fat_sector); + bs->fats =1 ; + bs->media =0xf8 ; + bs->total_sect =cpu_to_le32 (sectors); + bs->fat32_length =cpu_to_le32 (1 ); + bs->root_cluster =cpu_to_le32 (root_sector); + + vi->ext_boot_sign =0x29 ; +memcpy (vi->fs_type,FAT32_SIGN ,sizeof (vi->fs_type)); + +memcpy (dst +0x1fe ,"\x55\xAA" ,2 ); + + fat[0 ] =cpu_to_le32 (0x0ffffff8 ); + fat[1 ] =cpu_to_le32 (0x0fffffff ); + fat[2 ] =cpu_to_le32 (0x0ffffff8 ); +for (i = file_sector; file_sectors >1 ; file_sectors--, i++) + fat[i] =cpu_to_le32 (i +1 ); + fat[i] =cpu_to_le32 (0x0ffffff8 ); + +for (i =0 ; i <sizeof (dirent->nameext.name); i++) { +if (i < filename_len) + dirent->nameext.name[i] =toupper (filename[i]); +else + dirent->nameext.name[i] =' ' ; + } + +for (i =0 ; i <sizeof (dirent->nameext.ext); i++) { +if (i < ext_len) + dirent->nameext.ext[i] =toupper (ext[i]); +else + dirent->nameext.ext[i] =' ' ; + } + + dirent->start =cpu_to_le16 (file_sector); + dirent->size =cpu_to_le32 (size); + +out: +return sectors * sector_size; +} + +typedef size_t (*create_fs_t )(void *,size_t ,const char *,size_t *); + +static int spl_test_fs (struct unit_test_state *uts,const char *test_name, +create_fs_t create) +{ +const char *filename =CONFIG_SPL_FS_LOAD_PAYLOAD_NAME ; +struct blk_desc *dev_desc; +char *data_write, *data_read; +void *fs; +size_t fs_size, fs_data, fs_blocks, data_size =SPL_TEST_DATA_SIZE ; +loff_t actread; + + fs_size =create (NULL , data_size, filename, &fs_data); +ut_assert (fs_size); + fs =calloc (fs_size,1 ); +ut_assertnonnull (fs); + + data_write = fs + fs_data; +generate_data (data_write, data_size, test_name); +ut_asserteq (fs_size,create (fs, data_size, filename,NULL )); + + dev_desc =blk_get_devnum_by_uclass_id (UCLASS_MMC ,0 ); +ut_assertnonnull (dev_desc); +ut_asserteq (512 , dev_desc->blksz); + fs_blocks = fs_size / dev_desc->blksz; +ut_asserteq (fs_blocks,blk_dwrite (dev_desc,0 , fs_blocks, fs)); + +/* We have to use malloc so we can call virt_to_phys */ + data_read =malloc_cache_aligned (data_size); +ut_assertnonnull (data_read); +ut_assertok (fs_set_blk_dev_with_part (dev_desc,0 )); +ut_assertok (fs_read ("/" CONFIG_SPL_FS_LOAD_PAYLOAD_NAME , +virt_to_phys (data_read),0 , data_size, &actread)); +ut_asserteq (data_size, actread); +ut_asserteq_mem (data_write, data_read, data_size); + +free (data_read); +free (fs); +return 0 ; +} + +static int spl_test_ext (struct unit_test_state *uts) +{ +return spl_test_fs (uts, __func__, create_ext2); +} +SPL_TEST (spl_test_ext,DM_FLAGS ); + +static int spl_test_fat (struct unit_test_state *uts) +{ +return spl_test_fs (uts, __func__, create_fat); +} +SPL_TEST (spl_test_fat,DM_FLAGS ); --
Quoted 2 lines
2.37.1
Regards,
Simon
Re: [PATCH 21/26] test: spl: Add functions to create filesystems
Quoted 24 lines · Simon Glass
Hi Sean,
Quoted 19 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.
Signed-off-by Sean Anderson <[email protected]>---
arch/sandbox/cpu/start.c | 9 +- configs/sandbox_noinst_defconfig | 7 + include/ext4fs.h | 1 + include/ext_common.h | 14 ++ include/test/spl.h | 3 + test/image/Kconfig | 11 ++ test/image/Makefile | 1 + test/image/spl_load.c | 1 + test/image/spl_load_fs.c | 305 +++++++++++++++++++++++++++++++ 9 files changed, 350 insertions(+), 2 deletions(-)Quoted 1 line
create mode 100644
test/image/spl_load_fs.c
Quoted 3 lines
Reviewed-by Simon Glass <[email protected]>Wow there is a lot going on in this patch. It might be good to split it.
OK.
Quoted 20 lines
Quoted 20 lines
arch/sandbox/cpu/start.c +2
-0@@ -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;
Quoted 7 lines
arch/sandbox/cpu/start.c static int sandbox_cmdline_cb_test_fdt(struct sandbox_state *state, · line 209
Quoted 3 lines
arch/sandbox/cpu/start.c +1
-2- len =state_get_rel_filename ("arch/sandbox/dts/test.dtb" , buf, -sizeof (buf)); +if (spl_phase () <PHASE_BOARD_F )I think <=
PHASE_SPLis better since you care about whether it is in SPL or not. I did send a patch to check for SPL, but I don't think it is merged yet.
Fine by me.
Quoted 52 lines
Quoted 52 lines
arch/sandbox/cpu/start.c +4
-0+ 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;configs/sandbox_noinst_defconfig +6
-0@@ -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
Quoted 8 lines
configs/sandbox_noinst_defconfig CONFIG_SYSRESET=y · line 232
Quoted 6 lines
configs/sandbox_noinst_defconfig +1
-0CONFIG_DM_THERMAL=y CONFIG_TIMER=y +CONFIG_SPL_TIMER=y CONFIG_TIMER_EARLY=y CONFIG_SANDBOX_TIMER=y CONFIG_USB=yI think these would be better in their own patch
Surprisingly, MMC_WRITE actually depends on SPL_TIMER. I didn't check on the exact dependency, but presumably there is some poll/timeout loop in the MMC write code.
Quoted 42 lines
Quoted 42 lines
include/ext4fs.h +1
-0@@ -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 0x0010include/ext_common.h +14
-0@@ -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
Quoted 4 lines
include/ext_common.h struct cmd_tbl; · line 67
Quoted 2 lines
include/ext_common.h +0
-0/* The size of an ext2 block in bytes. */ #define EXT2_BLOCK_SIZE (data) (1 << LOG2_BLOCK_SIZE(data))Again I think these ext2 changes would be better in their own patch
OK.
FWIW These are really only used by this patch.
--Sean
Quoted 373 lines
Quoted 368 lines
include/test/spl.h +3
-0@@ -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@@ -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_FITtest/image/Makefile +1
-0@@ -3,4 +3,5 @@ # Copyright 2021 Google LLC obj-$(CONFIG_SPL_UT_LOAD) += spl_load.o +obj-$(CONFIG_SPL_UT_LOAD_FS) += spl_load_fs.o obj-$(CONFIG_SPL_UT_LOAD_OS) += spl_load_os.otest/image/spl_load.c +1
-0@@ -4,6 +4,7 @@*/ #include <common.h> +#include <dm.h> #include <image.h> #include <imx_container.h> #include <mapmem.h> test/image/spl_load_fs.c new file +305
-1@@ -0,0 +1,305 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2023 Sean Anderson <[email protected]> +*/ + +#include <common.h> +#include <blk.h> +#include <ext_common.h> +#include <ext4fs.h> +#include <fat.h> +#include <fs.h> +#include <memalign.h> +#include <asm/io.h> +#include <linux/stat.h> +#include <test/spl.h> +#include <test/ut.h> + +/** +* create_ext2() - Create an "ext2" filesystem with a single file +* @dst: The location of the new filesystem; MUST be zeroed +* @size: The size of the file +* @filename: The name of the file +* @data_offset: Filled with the offset of the file data from @dst +* +* Budget mke2fs. We use 1k blocks (to reduce overhead) with a single block +* group, which limits us to 8M of data. Almost every feature which increases +* complexity (checksums, hash tree directories, etc.) is disabled. We do cheat +* a little and use extents from ext4 to save having to deal with indirects, but +* U-Boot doesn't care. +* +* If @dst is %NULL, nothing is copied. +* +* Return: The size of the filesystem in bytes +*/ +static size_t create_ext2 (void *dst,size_t size,const char *filename, +size_t *data_offset) +{ +u32 super_block =1 ; +u32 group_block =2 ; +u32 block_bitmap_block =3 ; +u32 inode_bitmap_block =4 ; +u32 inode_table_block =5 ; +u32 root_block =6 ; +u32 file_block =7 ; + +u32 root_ino =EXT2_ROOT_INO ; +u32 file_ino =EXT2_BOOT_LOADER_INO ; + +u32 block_size =EXT2_MIN_BLOCK_SIZE ; +u32 inode_size =sizeof (struct ext2_inode ); + +u32 file_blocks = (size + block_size -1 ) / block_size; +u32 blocks = file_block + file_blocks; +u32 inodes = block_size / inode_size; +u32 filename_len =strlen (filename); +u32 dirent_len =ALIGN (filename_len,sizeof (struct ext2_dirent )) + +sizeof (struct ext2_dirent ); + +struct ext2_sblock *sblock = dst + super_block * block_size; +struct ext2_block_group *bg = dst + group_block * block_size; +struct ext2_inode *inode_table = dst + inode_table_block * block_size; +struct ext2_inode *root_inode = &inode_table[root_ino -1 ]; +struct ext2_inode *file_inode = &inode_table[file_ino -1 ]; +struct ext4_extent_header *ext_block = (void *)&file_inode->b; +struct ext4_extent *extent = (void *)(ext_block +1 ); +struct ext2_dirent *dot = dst + root_block * block_size; +struct ext2_dirent *dotdot = dot +2 ; +struct ext2_dirent *dirent = dotdot +2 ; +struct ext2_dirent *last = ((void *)dirent) + dirent_len; + +/* Make sure we fit in one block group */ +if (blocks > block_size *8 ) +return 0 ; + +if (filename_len >EXT2_NAME_LEN ) +return 0 ; + +if (data_offset) + *data_offset = file_block * block_size; + +if (!dst) + goto out; + + sblock->total_inodes =cpu_to_le32 (inodes); + sblock->total_blocks =cpu_to_le32 (blocks); + sblock->first_data_block =cpu_to_le32 (super_block); + sblock->blocks_per_group =cpu_to_le32 (blocks); + sblock->fragments_per_group =cpu_to_le32 (blocks); + sblock->inodes_per_group =cpu_to_le32 (inodes); + sblock->magic =cpu_to_le16 (EXT2_MAGIC ); +/* Done mostly so we can pretend to be (in)compatible */ + sblock->revision_level =cpu_to_le32 (EXT2_DYNAMIC_REV ); +/* Not really accurate but it doesn't matter */ + sblock->first_inode =cpu_to_le32 (EXT2_GOOD_OLD_FIRST_INO ); + sblock->inode_size =cpu_to_le32 (inode_size); + sblock->feature_incompat =cpu_to_le32 (EXT4_FEATURE_INCOMPAT_EXTENTS ); + + bg->block_id =cpu_to_le32 (block_bitmap_block); + bg->inode_id =cpu_to_le32 (inode_bitmap_block); + bg->inode_table_id =cpu_to_le32 (inode_table_block); + +/* +* All blocks/inodes are in-use. I don't want to have to deal with +* endianness, so just fill everything in. +*/ +memset (dst + block_bitmap_block * block_size,0xff , block_size *2 ); + + root_inode->mode =cpu_to_le16 (S_IFDIR |0755 ); + root_inode->size =cpu_to_le32 (block_size); + root_inode->nlinks =cpu_to_le16 (3 ); + root_inode->blockcnt =cpu_to_le32 (1 ); + root_inode->flags =cpu_to_le32 (EXT4_TOPDIR_FL ); + root_inode->b.blocks.dir_blocks[0 ] = root_block; + + file_inode->mode =cpu_to_le16 (S_IFREG |0644 ); + file_inode->size =cpu_to_le32 (size); + file_inode->nlinks =cpu_to_le16 (1 ); + file_inode->blockcnt =cpu_to_le32 (file_blocks); + file_inode->flags =cpu_to_le32 (EXT4_EXTENTS_FL ); + ext_block->eh_magic =cpu_to_le16 (EXT4_EXT_MAGIC ); + ext_block->eh_entries =cpu_to_le16 (1 ); + ext_block->eh_max =cpu_to_le16 (sizeof (file_inode->b) / +sizeof (*ext_block) -1 ); + extent->ee_len =cpu_to_le16 (file_blocks); + extent->ee_start_lo =cpu_to_le16 (file_block); + +/* I'm not sure we need these, but it can't hurt */ + dot->inode =cpu_to_le32 (root_ino); + dot->direntlen =cpu_to_le16 (2 *sizeof (*dot)); + dot->namelen =1 ; + dot->filetype =FILETYPE_DIRECTORY ; +memcpy (dot +1 ,"." , dot->namelen); + + dotdot->inode =cpu_to_le32 (root_ino); + dotdot->direntlen =cpu_to_le16 (2 *sizeof (*dotdot)); + dotdot->namelen =2 ; + dotdot->filetype =FILETYPE_DIRECTORY ; +memcpy (dotdot +1 ,".." , dotdot->namelen); + + dirent->inode =cpu_to_le32 (file_ino); + dirent->direntlen =cpu_to_le16 (dirent_len); + dirent->namelen = filename_len; + dirent->filetype =FILETYPE_REG ; +memcpy (dirent +1 , filename, filename_len); + + last->direntlen = block_size - dirent_len; + +out: +return (size_t )blocks * block_size; +} + +/** +* create_fat() - Create a FAT32 filesystem with a single file +* @dst: The location of the new filesystem; MUST be zeroed +* @size: The size of the file +* @filename: The name of the file +* @data_offset: Filled with the offset of the file data from @dst +* +* Budget mkfs.fat. We use FAT32 (so I don't have to deal with FAT12) with no +* info sector, and a single one-sector FAT. This limits us to 64k of data +* (enough for anyone). The filename must fit in 8.3. +* +* If @dst is %NULL, nothing is copied. +* +* Return: The size of the filesystem in bytes +*/ +static size_t create_fat (void *dst,size_t size,const char *filename, +size_t *data_offset) +{ +u16 boot_sector =0 ; +u16 fat_sector =1 ; +u32 root_sector =2 ; +u32 file_sector =3 ; + +u16 sector_size =512 ; +u32 file_sectors = (size + sector_size -1 ) / sector_size; +u32 sectors = file_sector + file_sectors; + +char *ext; +size_t filename_len, ext_len; +int i; + +struct boot_sector *bs = dst + boot_sector * sector_size; +struct volume_info *vi = (void *)(bs +1 ); +__le32 *fat = dst + fat_sector * sector_size; +struct dir_entry *dirent = dst + root_sector * sector_size; + +/* Make sure we fit in the FAT */ +if (sectors > sector_size /sizeof (u32)) +return 0 ; + + ext =strchr (filename,'.' ); +if (ext) { + filename_len = ext - filename; + ext++; + ext_len =strlen (ext); + }else { + filename_len =strlen (filename); + ext_len =0 ; + } + +if (filename_len >8 || ext_len >3 ) +return 0 ; + +if (data_offset) + *data_offset = file_sector * sector_size; + +if (!dst) + goto out; + + bs->sector_size[0 ] = sector_size &0xff ; + bs->sector_size[1 ] = sector_size >>8 ; + bs->cluster_size =1 ; + bs->reserved =cpu_to_le16 (fat_sector); + bs->fats =1 ; + bs->media =0xf8 ; + bs->total_sect =cpu_to_le32 (sectors); + bs->fat32_length =cpu_to_le32 (1 ); + bs->root_cluster =cpu_to_le32 (root_sector); + + vi->ext_boot_sign =0x29 ; +memcpy (vi->fs_type,FAT32_SIGN ,sizeof (vi->fs_type)); + +memcpy (dst +0x1fe ,"\x55\xAA" ,2 ); + + fat[0 ] =cpu_to_le32 (0x0ffffff8 ); + fat[1 ] =cpu_to_le32 (0x0fffffff ); + fat[2 ] =cpu_to_le32 (0x0ffffff8 ); +for (i = file_sector; file_sectors >1 ; file_sectors--, i++) + fat[i] =cpu_to_le32 (i +1 ); + fat[i] =cpu_to_le32 (0x0ffffff8 ); + +for (i =0 ; i <sizeof (dirent->nameext.name); i++) { +if (i < filename_len) + dirent->nameext.name[i] =toupper (filename[i]); +else + dirent->nameext.name[i] =' ' ; + } + +for (i =0 ; i <sizeof (dirent->nameext.ext); i++) { +if (i < ext_len) + dirent->nameext.ext[i] =toupper (ext[i]); +else + dirent->nameext.ext[i] =' ' ; + } + + dirent->start =cpu_to_le16 (file_sector); + dirent->size =cpu_to_le32 (size); + +out: +return sectors * sector_size; +} + +typedef size_t (*create_fs_t )(void *,size_t ,const char *,size_t *); + +static int spl_test_fs (struct unit_test_state *uts,const char *test_name, +create_fs_t create) +{ +const char *filename =CONFIG_SPL_FS_LOAD_PAYLOAD_NAME ; +struct blk_desc *dev_desc; +char *data_write, *data_read; +void *fs; +size_t fs_size, fs_data, fs_blocks, data_size =SPL_TEST_DATA_SIZE ; +loff_t actread; + + fs_size =create (NULL , data_size, filename, &fs_data); +ut_assert (fs_size); + fs =calloc (fs_size,1 ); +ut_assertnonnull (fs); + + data_write = fs + fs_data; +generate_data (data_write, data_size, test_name); +ut_asserteq (fs_size,create (fs, data_size, filename,NULL )); + + dev_desc =blk_get_devnum_by_uclass_id (UCLASS_MMC ,0 ); +ut_assertnonnull (dev_desc); +ut_asserteq (512 , dev_desc->blksz); + fs_blocks = fs_size / dev_desc->blksz; +ut_asserteq (fs_blocks,blk_dwrite (dev_desc,0 , fs_blocks, fs)); + +/* We have to use malloc so we can call virt_to_phys */ + data_read =malloc_cache_aligned (data_size); +ut_assertnonnull (data_read); +ut_assertok (fs_set_blk_dev_with_part (dev_desc,0 )); +ut_assertok (fs_read ("/" CONFIG_SPL_FS_LOAD_PAYLOAD_NAME , +virt_to_phys (data_read),0 , data_size, &actread)); +ut_asserteq (data_size, actread); +ut_asserteq_mem (data_write, data_read, data_size); + +free (data_read); +free (fs); +return 0 ; +} + +static int spl_test_ext (struct unit_test_state *uts) +{ +return spl_test_fs (uts, __func__, create_ext2); +} +SPL_TEST (spl_test_ext,DM_FLAGS ); + +static int spl_test_fat (struct unit_test_state *uts) +{ +return spl_test_fs (uts, __func__, create_fat); +} +SPL_TEST (spl_test_fat,DM_FLAGS ); --Quoted 2 lines
2.37.1
Regards,
Simon
PATCH 22/26 test: spl: Add a test for spl_blk_load_image
In reply to Sean AndersonAdd 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.
---
configs/sandbox_noinst_defconfig | 2 ++ test/image/Kconfig | 3 +- test/image/spl_load_fs.c | 62 ++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-)
configs/sandbox_noinst_defconfig +2 -0
@@ -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
@@ -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 +62 -0
71 lines not on this page · raw message
Signature · 1 line
2.37.1
Re: [PATCH 22/26] test: spl: Add a test for spl_blk_load_image
Quoted 5 lines · 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.
Quoted 7 lines
Signed-off-by Sean Anderson <[email protected]>---
configs/sandbox_noinst_defconfig | 2 ++ test/image/Kconfig | 3 +- test/image/spl_load_fs.c | 62 ++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-)
PATCH 23/26 test: spl: Add a test for the MMC load method
In reply to Sean AndersonAdd 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.
---
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 | 66 +++++++++++++++++++++++++++++--- 6 files changed, 134 insertions(+), 5 deletions(-)
configs/sandbox_noinst_defconfig +2 -0
@@ -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
@@ -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 */ int spl_load_image_fat(struct spl_image_info *spl_image, struct spl_boot_device *bootdev,
include/test/spl.h +30 -0
@@ -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
@@ -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
@@ -368,3 +368,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 +61 -5
94 lines not on this page · raw message
Signature · 1 line
2.37.1
Re: [PATCH 23/26] test: spl: Add a test for the MMC load method
Hi Sean,
Quoted 67 lines · 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_loadwith an appropriate callback to write the image to the medium.Signed-off-by Sean Anderson <[email protected]>---
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 | 66 +++++++++++++++++++++++++++++--- 6 files changed, 134 insertions(+), 5 deletions(-)configs/sandbox_noinst_defconfig +2
-0@@ -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=yinclude/spl.h +4
-0@@ -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 */ int spl_load_image_fat(struct spl_image_info *spl_image, struct spl_boot_device *bootdev,include/test/spl.h +15
-0@@ -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
include/test/spl.h size_t create_image(void *dst, enum spl_test_image type, · line 106
Quoted 10 lines
include/test/spl.h +10
-0+* @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
Do you mean 1 ?
Re: [PATCH 23/26] test: spl: Add a test for the MMC load method
Quoted 83 lines · Simon Glass
Hi Sean,
Quoted 67 lines · 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_loadwith an appropriate callback to write the image to the medium.Signed-off-by Sean Anderson <[email protected]>---
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 | 66 +++++++++++++++++++++++++++++--- 6 files changed, 134 insertions(+), 5 deletions(-)configs/sandbox_noinst_defconfig +2
-0@@ -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=yinclude/spl.h +4
-0@@ -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 */ int spl_load_image_fat(struct spl_image_info *spl_image, struct spl_boot_device *bootdev,include/test/spl.h +15
-0@@ -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 include/test/spl.h size_t create_image(void *dst, enum spl_test_image type, · line 106
Quoted 10 lines
include/test/spl.h +10
-0+* @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 Do you mean 1 ?
Quoted 1 line
Reviewed-by Simon Glass <[email protected]>
Huh... I guess I do.
--Sean
PATCH 24/26 test: spl: Add a test for the NET load method
In reply to Sean AndersonAdd 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.
---
arch/sandbox/cpu/spl.c | 3 + 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, 271 insertions(+), 1 deletion(-) create mode 100644 test/image/spl_load_net.c
arch/sandbox/cpu/spl.c +3 -0
@@ -126,6 +126,9 @@ void spl_board_init(void) {struct sandbox_state *state =state_get_current (); + 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
@@ -12,6 +12,7 @@ enum {BOOT_DEVICE_MMC2_2 ,BOOT_DEVICE_BOARD ,BOOT_DEVICE_VBE , + BOOT_DEVICE_CPGMAC, };/**
configs/sandbox_noinst_defconfig +5 -1
@@ -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
@@ -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
@@ -4,4 +4,5 @@ obj-$(CONFIG_SPL_UT_LOAD) += 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
Re: [PATCH 24/26] test: spl: Add a test for the NET load method
Quoted 16 lines · 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_etherandnet_set_udp_headeralways 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_banksizewould be a good candidate for settig upbi_dram, but it gets called too late inboard_init_r.Signed-off-by Sean Anderson <[email protected]>---
Quoted 9 lines
arch/sandbox/cpu/spl.c | 3 + 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, 271 insertions(+), 1 deletion(-) create mode 100644 test/image/spl_load_net.c
arch/sandbox/cpu/spl.c void spl_board_init(void) · line 130
Quoted 10 lines
arch/sandbox/cpu/spl.c +2
-0@@ -126,6 +126,9 @@ void spl_board_init(void) {struct sandbox_state *state =state_get_current (); + gd->bd->bi_dram[0 ].start = gd->ram_base; + gd->bd->bi_dram[0 ].size =get_effective_memsize ();
These could use a common as to why they are needed here.
[..]
Regards,
Simon
Re: [PATCH 24/26] test: spl: Add a test for the NET load method
Quoted 37 lines · Simon Glass
Quoted 16 lines · 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_etherandnet_set_udp_headeralways 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_banksizewould be a good candidate for settig upbi_dram, but it gets called too late inboard_init_r.Signed-off-by Sean Anderson <[email protected]>---
Quoted 9 lines
arch/sandbox/cpu/spl.c | 3 + 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, 271 insertions(+), 1 deletion(-)create mode 100644
test/image/spl_load_net.cReviewed-by Simon Glass <[email protected]>Quoted 8 lines
arch/sandbox/cpu/spl.c +0
-0@@ -126,6 +126,9 @@ void spl_board_init(void) {struct sandbox_state *state =state_get_current ();
Quoted 4 lines
arch/sandbox/cpu/spl.c void spl_board_init(void) · line 130
Quoted 2 lines
arch/sandbox/cpu/spl.c +2
-0+ gd->bd->bi_dram[0 ].start = gd->ram_base; + gd->bd->bi_dram[0 ].size =get_effective_memsize ();These could use a common as to why they are needed here.
OK.
--Sean
PATCH 25/26 test: spl: Add a test for the NOR load method
In reply to Sean AndersonAdd 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, so we just include some pre-compressed 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
@@ -13,6 +13,7 @@ enum {BOOT_DEVICE_BOARD ,BOOT_DEVICE_VBE ,BOOT_DEVICE_CPGMAC , + BOOT_DEVICE_NOR, };/**
configs/sandbox_noinst_defconfig +2 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -5,4 +5,5 @@ obj-$(CONFIG_SPL_UT_LOAD) += 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
@@ -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
Re: [PATCH 25/26] test: spl: Add a test for the NOR load method
Hi Sean,
Quoted 5 lines · 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, so we just include some pre-compressed data.
How about using the in-tree compression code?
Quoted 4 lines
Signed-off-by Sean Anderson <[email protected]>---
Quoted 10 lines
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
Quoted 145 lines
arch/sandbox/include/asm/spl.h +1
-0@@ -13,6 +13,7 @@ enum {BOOT_DEVICE_BOARD ,BOOT_DEVICE_VBE ,BOOT_DEVICE_CPGMAC , + BOOT_DEVICE_NOR, };/** configs/sandbox_noinst_defconfig +2
-0@@ -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=yconfigs/sandbox_spl_defconfig +2
-0@@ -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=yinclude/configs/sandbox.h +3
-0@@ -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@@ -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@@ -5,4 +5,5 @@ obj-$(CONFIG_SPL_UT_LOAD) += 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.otest/image/spl_load.c +6
-2@@ -43,6 +43,7 @@ void *board_spl_fit_buffer_addr(ulong fit_size, int sectors, int bl_len)/* Local flags for spl_image; start from the "top" to avoid conflicts */ #define SPL_IMX_CONTAINER 0x80000000 +#define SPL_COMP_LZMA 0x40000000void generate_data (char *data,size_t size,const char *test_name) {@@ -79,7 +80,8 @@ static size_t create_legacy(void *dst, struct spl_image_info *spl_image,image_set_os (hdr, spl_image->os);image_set_arch (hdr,IH_ARCH_DEFAULT );image_set_type (hdr,IH_TYPE_FIRMWARE ); -image_set_comp (hdr,IH_COMP_NONE ); +image_set_comp (hdr, spl_image->flags &SPL_COMP_LZMA ?IH_COMP_LZMA : +IH_COMP_NONE );image_set_name (hdr, spl_image->name);image_set_hcrc (hdr,crc32 (0 , (void *)hdr,sizeof (*hdr)));@@ -252,6 +254,8 @@ size_t create_image(void *dst, enum spl_test_image type, info->flags =0 ;switch (type) { +case LEGACY_LZMA : + info->flags =SPL_COMP_LZMA ;case LEGACY :return create_legacy (dst, info, data_offset);case IMX8 :@@ -296,7 +300,7 @@ int check_image_info(struct unit_test_state *uts, struct spl_image_info *info1,ut_asserteq (info1->load_addr, info2->load_addr);if (info1->flags &SPL_IMX_CONTAINER )ut_asserteq (0 , info2->size); -else +else if (!(info1->flags &SPL_COMP_LZMA ))ut_asserteq (info1->size, info2->size); }else { ut_asserteq(info1->load_addr - sizeof(struct legacy_img_hdr),
test/image/spl_load.c SPL_IMG_TEST(spl_test_image, IMX8, 0); · line 378
Quoted 6 lines
test/image/spl_load.c +3
-0@@ -369,6 +373,246 @@ 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 ); +/* +* LZMA is too complex to generate on the fly, so let's use some data I put in +* the oven^H^H^H^H compressed earlier
How would one create this data?
test/image/spl_load.c SPL_IMG_TEST(spl_test_image, IMX8, 0); · line 387
Quoted 9 lines
test/image/spl_load.c +9
-0+*/ +static const char lzma_compressed[] = { +0x5d ,0x00 ,0x00 ,0x80 ,0x00 ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff , +0xff ,0x00 ,0x02 ,0x05 ,0x55 ,0x4e ,0x82 ,0xbc ,0xc2 ,0x42 ,0xf6 ,0x88 , +0x6c ,0x99 ,0xd6 ,0x82 ,0x48 ,0xa6 ,0x06 ,0x67 ,0xf8 ,0x46 ,0x7c ,0xe9 , +0x41 ,0x79 ,0xfe ,0x90 ,0x0b ,0x31 ,0x7b ,0x79 ,0x91 ,0xb8 ,0x5f ,0x33 , +0x11 ,0x04 ,0xc3 ,0x4f ,0xf5 ,0x71 ,0xd1 ,0xfb ,0x94 ,0x6b ,0x5f ,0x78 , +0xe2 ,0xfa ,0x6a ,0x21 ,0xb6 ,0x1d ,0x11 ,0x0e ,0x5b ,0x56 ,0x6a ,0x5b , +0xe9 ,0x56 ,0x5f ,0x8b ,0x87 ,0x61 ,0x96 ,0x6d ,0xce ,0x66 ,0xbb ,0xb6 ,
[..]
Regards,
Simon
Re: [PATCH 25/26] test: spl: Add a test for the NOR load method
Quoted 10 lines · Simon Glass
Hi Sean,
Quoted 5 lines · 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, so we just include some pre-compressed data.
How about using the in-tree compression code?
We have that for LZMA? From what I could tell we only have decompression in-tree.
Quoted 165 lines
Quoted 13 lines
Signed-off-by Sean Anderson <[email protected]>---
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(-)Quoted 1 line
create mode 100644
test/image/spl_load_nor.cReviewed-by Simon Glass <[email protected]>Quoted 148 lines
arch/sandbox/include/asm/spl.h +1
-0@@ -13,6 +13,7 @@ enum {BOOT_DEVICE_BOARD ,BOOT_DEVICE_VBE ,BOOT_DEVICE_CPGMAC , + BOOT_DEVICE_NOR, };/** configs/sandbox_noinst_defconfig +2
-0@@ -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=yconfigs/sandbox_spl_defconfig +2
-0@@ -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=yinclude/configs/sandbox.h +3
-0@@ -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@@ -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@@ -5,4 +5,5 @@ obj-$(CONFIG_SPL_UT_LOAD) += 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.otest/image/spl_load.c +6
-2@@ -43,6 +43,7 @@ void *board_spl_fit_buffer_addr(ulong fit_size, int sectors, int bl_len)/* Local flags for spl_image; start from the "top" to avoid conflicts */ #define SPL_IMX_CONTAINER 0x80000000 +#define SPL_COMP_LZMA 0x40000000void generate_data (char *data,size_t size,const char *test_name) {@@ -79,7 +80,8 @@ static size_t create_legacy(void *dst, struct spl_image_info *spl_image,image_set_os (hdr, spl_image->os);image_set_arch (hdr,IH_ARCH_DEFAULT );image_set_type (hdr,IH_TYPE_FIRMWARE ); -image_set_comp (hdr,IH_COMP_NONE ); +image_set_comp (hdr, spl_image->flags &SPL_COMP_LZMA ?IH_COMP_LZMA : +IH_COMP_NONE );image_set_name (hdr, spl_image->name);image_set_hcrc (hdr,crc32 (0 , (void *)hdr,sizeof (*hdr)));@@ -252,6 +254,8 @@ size_t create_image(void *dst, enum spl_test_image type, info->flags =0 ;switch (type) { +case LEGACY_LZMA : + info->flags =SPL_COMP_LZMA ;case LEGACY :return create_legacy (dst, info, data_offset);case IMX8 :@@ -296,7 +300,7 @@ int check_image_info(struct unit_test_state *uts, struct spl_image_info *info1,ut_asserteq (info1->load_addr, info2->load_addr);if (info1->flags &SPL_IMX_CONTAINER )ut_asserteq (0 , info2->size); -else +else if (!(info1->flags &SPL_COMP_LZMA ))ut_asserteq (info1->size, info2->size); }else { ut_asserteq(info1->load_addr - sizeof(struct legacy_img_hdr),@@ -369,6 +373,246 @@ 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 );
Quoted 5 lines
test/image/spl_load.c SPL_IMG_TEST(spl_test_image, IMX8, 0); · line 378
Quoted 3 lines
test/image/spl_load.c +3
-0+/* +* LZMA is too complex to generate on the fly, so let's use some data I put in +* the oven^H^H^H^H compressed earlier How would one create this data?
Same as test/compression.c. I modified this test to hexdump the output of generate_data(plain, plain_size, "lzma") and then piped it to lzma. I massaged the output somewhat in vim (mostly to adjust the number of columns). You could probably script this, but it was a one-off thing.
--Sean
Quoted 14 lines
test/image/spl_load.c SPL_IMG_TEST(spl_test_image, IMX8, 0); · line 387
Quoted 9 lines
test/image/spl_load.c +9
-0+*/ +static const char lzma_compressed[] = { +0x5d ,0x00 ,0x00 ,0x80 ,0x00 ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff , +0xff ,0x00 ,0x02 ,0x05 ,0x55 ,0x4e ,0x82 ,0xbc ,0xc2 ,0x42 ,0xf6 ,0x88 , +0x6c ,0x99 ,0xd6 ,0x82 ,0x48 ,0xa6 ,0x06 ,0x67 ,0xf8 ,0x46 ,0x7c ,0xe9 , +0x41 ,0x79 ,0xfe ,0x90 ,0x0b ,0x31 ,0x7b ,0x79 ,0x91 ,0xb8 ,0x5f ,0x33 , +0x11 ,0x04 ,0xc3 ,0x4f ,0xf5 ,0x71 ,0xd1 ,0xfb ,0x94 ,0x6b ,0x5f ,0x78 , +0xe2 ,0xfa ,0x6a ,0x21 ,0xb6 ,0x1d ,0x11 ,0x0e ,0x5b ,0x56 ,0x6a ,0x5b , +0xe9 ,0x56 ,0x5f ,0x8b ,0x87 ,0x61 ,0x96 ,0x6d ,0xce ,0x66 ,0xbb ,0xb6 ,[..]
Regards,
Simon
Re: [PATCH 25/26] test: spl: Add a test for the NOR load method
Hi Sean,
Quoted 11 lines · Sean Anderson
Quoted 9 lines · Simon Glass
Hi Sean,
Quoted 5 lines · 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, so we just include some pre-compressed data.
Quoted 4 lines
Quoted 1 line
How about using the in-tree compression code?
We have that for LZMA? From what I could tell we only have decompression in-tree.
Ah yes, OK.
Quoted 172 lines
Quoted 166 lines
Quoted 14 lines
Signed-off-by Sean Anderson <[email protected]>---
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(-)Quoted 1 line
create mode 100644
test/image/spl_load_nor.cReviewed-by Simon Glass <[email protected]>Quoted 148 lines
arch/sandbox/include/asm/spl.h +1
-0@@ -13,6 +13,7 @@ enum {BOOT_DEVICE_BOARD ,BOOT_DEVICE_VBE ,BOOT_DEVICE_CPGMAC , + BOOT_DEVICE_NOR, };/** configs/sandbox_noinst_defconfig +2
-0@@ -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=yconfigs/sandbox_spl_defconfig +2
-0@@ -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=yinclude/configs/sandbox.h +3
-0@@ -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@@ -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@@ -5,4 +5,5 @@ obj-$(CONFIG_SPL_UT_LOAD) += 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.otest/image/spl_load.c +6
-2@@ -43,6 +43,7 @@ void *board_spl_fit_buffer_addr(ulong fit_size, int sectors, int bl_len)/* Local flags for spl_image; start from the "top" to avoid conflicts */ #define SPL_IMX_CONTAINER 0x80000000 +#define SPL_COMP_LZMA 0x40000000void generate_data (char *data,size_t size,const char *test_name) {@@ -79,7 +80,8 @@ static size_t create_legacy(void *dst, struct spl_image_info *spl_image,image_set_os (hdr, spl_image->os);image_set_arch (hdr,IH_ARCH_DEFAULT );image_set_type (hdr,IH_TYPE_FIRMWARE ); -image_set_comp (hdr,IH_COMP_NONE ); +image_set_comp (hdr, spl_image->flags &SPL_COMP_LZMA ?IH_COMP_LZMA : +IH_COMP_NONE );image_set_name (hdr, spl_image->name);image_set_hcrc (hdr,crc32 (0 , (void *)hdr,sizeof (*hdr)));@@ -252,6 +254,8 @@ size_t create_image(void *dst, enum spl_test_image type, info->flags =0 ;switch (type) { +case LEGACY_LZMA : + info->flags =SPL_COMP_LZMA ;case LEGACY :return create_legacy (dst, info, data_offset);case IMX8 :@@ -296,7 +300,7 @@ int check_image_info(struct unit_test_state *uts, struct spl_image_info *info1,ut_asserteq (info1->load_addr, info2->load_addr);if (info1->flags &SPL_IMX_CONTAINER )ut_asserteq (0 , info2->size); -else +else if (!(info1->flags &SPL_COMP_LZMA ))ut_asserteq (info1->size, info2->size); }else { ut_asserteq(info1->load_addr - sizeof(struct legacy_img_hdr),@@ -369,6 +373,246 @@ 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 );Quoted 5 lines
test/image/spl_load.c SPL_IMG_TEST(spl_test_image, IMX8, 0); · line 378
Quoted 3 lines
test/image/spl_load.c +3
-0+/* +* LZMA is too complex to generate on the fly, so let's use some data I put in +* the oven^H^H^H^H compressed earlier How would one create this data?
Quoted 4 lines
Same as
test/compression.c. I modified this test to hexdump the output ofgenerate_data(plain, plain_size, "lzma")and then piped it to lzma. I massaged the output somewhat in vim (mostly to adjust the number of columns). You could probably script this, but it was a one-off thing.
OK thanks.
Quoted 14 lines
--Sean
Quoted 11 lines
Quoted 9 lines
test/image/spl_load.c +9
-0+*/ +static const char lzma_compressed[] = { +0x5d ,0x00 ,0x00 ,0x80 ,0x00 ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff , +0xff ,0x00 ,0x02 ,0x05 ,0x55 ,0x4e ,0x82 ,0xbc ,0xc2 ,0x42 ,0xf6 ,0x88 , +0x6c ,0x99 ,0xd6 ,0x82 ,0x48 ,0xa6 ,0x06 ,0x67 ,0xf8 ,0x46 ,0x7c ,0xe9 , +0x41 ,0x79 ,0xfe ,0x90 ,0x0b ,0x31 ,0x7b ,0x79 ,0x91 ,0xb8 ,0x5f ,0x33 , +0x11 ,0x04 ,0xc3 ,0x4f ,0xf5 ,0x71 ,0xd1 ,0xfb ,0x94 ,0x6b ,0x5f ,0x78 , +0xe2 ,0xfa ,0x6a ,0x21 ,0xb6 ,0x1d ,0x11 ,0x0e ,0x5b ,0x56 ,0x6a ,0x5b , +0xe9 ,0x56 ,0x5f ,0x8b ,0x87 ,0x61 ,0x96 ,0x6d ,0xce ,0x66 ,0xbb ,0xb6 ,[..]
Regards,
Simon
PATCH 26/26 test: spl: Add a test for the SPI load method
In reply to Sean AndersonAdd 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.
---
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
@@ -14,6 +14,7 @@ enum {BOOT_DEVICE_VBE ,BOOT_DEVICE_CPGMAC ,BOOT_DEVICE_NOR , + BOOT_DEVICE_SPI, };/**
configs/sandbox_noinst_defconfig +6 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -10,6 +10,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
@@ -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
Re: [PATCH 26/26] test: spl: Add a test for the SPI load method
Quoted 9 lines · Sean Anderson
Add test for the SPI load method. This one is pretty straightforward. We can't enable
FIT_EXTERNALwithLOAD_FIT_FULLbecausespl_spi_load_imagedoesn't know the total image size and has to guess fromfdt_totalsize. This doesn't include external data, so loading it will fail.Signed-off-by Sean Anderson <[email protected]>---
Quoted 10 lines
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
Quoted 25 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_fitorfs_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:
Quoted 7 lines
- 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 themselvesMostly-passing CI at [4]; I have since fixed the typo/missing cast.
CI run for the series as-sent:
https://source.denx.de/u-boot/custodians/u-boot-clk/-/pipelines/18092
(hopefully by the time you read this it will have passed)
--Sean
Hi Sean,
Quoted 12 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:
Quoted 10 lines
- 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_fitorfs_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 makes sense to me. Also the code to generate the images is relatively small.
Quoted 37 lines
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 themselvesMostly-passing CI at [4]; I have since fixed the typo/missing cast.
[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/18091Sean Anderson (26):
spl: legacy: Fix referencing_image_binary_end
spl: nor: Don't allocate header on stack
spl: fit: Fix entry point forSPL_LOAD_FIT_FULL
arm: imx: Fix i.MX8 container load address
arm: imx: Add newlines after error messages
arm: imx: Add function to validate i.MX8 containers
arm: imx: Check header before callingspl_load_imx_containerMove i.MX8 container image loading support to common/spl
spl: Allow enablingSPL_OF_REALandSPL_OF_PLATDATAat the same time
lib: acpi: Fix linking SPL when ACPIGEN is enabled
fs: ext4: Fix building ext4 in SPL if write is enabled
fs: Compile in sandbox filesystem in SPL if it is enabled
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: Don't cache devices whenUNIT_TESTis enabled
spl: Usemap_sysmemwhere appropriate
test: spl: Split tests up and use some configs
Quoted 9 lines
test: spl: Fix
spl_test_loadnot 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 forspl_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
Yeoman's work, that.
Regards,
Simon