All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 00/25] spl: Use common function for loading/parsing images
@ 2023-11-06  2:25 Sean Anderson
  2023-11-06  2:25 ` [PATCH v6 01/25] spl: blk_fs: Fix uninitialized return value when we can't get a blk_desc Sean Anderson
                   ` (25 more replies)
  0 siblings, 26 replies; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson, Dario Binacchi, Fabio Estevam, Jaehoon Chung,
	Jagan Teki, Joe Hershberger, Mayuresh Chitale, Michael Trimarchi,
	Michal Simek, Nathan Barrett-Morrison, Peng Fan, Ramon Fried,
	Stefano Babic, Vignesh R, uboot-imx

This series adds support for loading all image types (Legacy (with and without
LZMA), FIT (with and without LOAD_FIT_FULL), and i.MX) to the MMC, SPI, NOR,
NET, FAT, EXT, NVMe, and semihosting load methods. It does this by introducing a
helper function which handles the minutiae of invoking the proper parsing
function, and reading the rest of the image.

Hopefully, this will make it easier for load methods to support all image types
that U-Boot supports, without having undocumented unsupported image types. I
applied this to several loaders which were invoking spl_load_simple_fit and/or
spl_parse_image_header, but I did not use it with others (e.g. DFU/RAM) which
had complications in the mix.

This series is organized roughly into two parts. Patches up to "spl: Add generic
spl_load function" are all setup or size-reduction oriented. Later patches
generally convert various load functions to spl_load.

bloat-o-meter results (for CONFIG_SPL only) at [1]. Size growth has been the
bigegst challenge to preparing this series. I have used every trick I can think
of to reduce bloat. Some SAMA boards no longer fit, but I have a plan to fix
them [2].

This is bar far the largest and most-difficult revision of this series to-date.
There are probably still things which can reduce the size, but I have been
working on this series for the better part of two months and I think it is a
good idea to get some feedback. Because of the SAMA bloat, this series will not
pass CI, so I expect to do a v7 before this is ready to apply. Feel free,
however, to apply patches in the first half (especially the fixes).

This version of the series is better-tested than ever before, thanks to some new
unit tests. However, things like the i.MX ROMAPI are untested. NAND should also
be tested more-widely, for reasons listed in the commit message. I encourage you
try this series out on your favorite board.

This series depends on [3]. (Almost passing) CI at [4].

[1] https://gist.github.com/Forty-Bot/5bfe88676dd3c2aec6ebc23abb08e06f
    This includes some changes to am335x_evm_spiboot and am65x_evm_r5_usbdfu
    which have since been undone.
[2] https://lore.kernel.org/u-boot/20231105022742.632175-1-seanga2@gmail.com/
[3] https://lore.kernel.org/u-boot/20231104203753.1579217-1-seanga2@gmail.com/
[4] https://source.denx.de/u-boot/custodians/u-boot-clk/-/pipelines/18447

Changes in v6:
- Fix uninitialized return value when we can't get a blk_desc
- Don't close fd before spl_load_simple_fit
- Remove NULL assignments in spl_load_info
- Remove dev from spl_load_info
- Take advantage of bl_len's power-of-twoness
- Refactor spl_load_info->read to use units of bytes
- Remove filename from spl_load_info
- Only support bl_len when we have to
- Remove spl_nand_legacy_read
- Split off LZMA decompression into its own function
- Support testing LEGACY_LZMA filesystem images
- Use pseudo-LTO for spl_load
- Align reads to bl_len
- Add SYS_MMCSD_RAW_MODE to help determine whether SPL_MMC loads
  anything directly.
- Convert nand to spl_load
- Fix LZMA support
- Fix load address
- Fix invalid return from spl_blk_load_image
- Fix soft reset after loading from SPI
- Explicitly initialize load_info members to reduce text size
- Rebase on u-boot/next
- Add option to disable DMA alignment for FAT

Changes in v5:
- Make SHOW_ERRORS depend on LIBCOMMON
- Load the header in spl_load as well
- Don't bother trying to DMA-align the buffer, since we can't really fix
  it.
- Convert NVMe to spl_load

Changes in v4:
- Fix format specifiers in debug prints
- Reword/fix some of the doc comments for spl_load
- Rebase on u-boot/master

Changes in v3:
- Fix using ffs instead of fls
- Fix using not initializing bl_len when info->filename was NULL
- Fix failing on success

Changes in v2:
- Use reverse-xmas-tree style for locals in spl_simple_read. This is not
  complete, since overhead depends on bl_mask.
- Convert semihosting as well
- Consolidate spi_load_image_os into spl_spi_load_image

Sean Anderson (25):
  spl: blk_fs: Fix uninitialized return value when we can't get a
    blk_desc
  arm: Disable SPL_FS_FAT when it isn't used
  spl: Make SHOW_ERRORS depend on LIBCOMMON
  spl: semihosting: Don't close fd before spl_load_simple_fit
  spl: Remove NULL assignments in spl_load_info
  spl: Remove dev from spl_load_info
  spl: Take advantage of bl_len's power-of-twoness
  spl: Refactor spl_load_info->read to use units of bytes
  spl: Remove filename from spl_load_info
  spl: Only support bl_len when we have to
  spl: nand: Remove spl_nand_legacy_read
  spl: legacy: Split off LZMA decompression into its own function
  test: spl: Support testing LEGACY_LZMA filesystem images
  spl: Add generic spl_load function
  spl: Convert ext to use spl_load
  spl: Convert fat to spl_load
  spl: Convert mmc to spl_load
  spl: Convert nand to spl_load
  spl: Convert net to spl_load
  spl: Convert nor to spl_load
  spl: Convert NVMe to spl_load
  spl: Convert semihosting to spl_load
  spl: Convert spi to spl_load
  spl: spi: Consolidate spi_load_image_os into spl_spi_load_image
  spl: fat: Add option to disable DMA alignment

 arch/arm/mach-imx/spl_imx_romapi.c        |  24 ++--
 arch/arm/mach-sunxi/spl_spi_sunxi.c       |   5 +-
 common/spl/Kconfig                        |  37 +++++-
 common/spl/spl.c                          |  13 +-
 common/spl/spl_blk_fs.c                   |  73 +++--------
 common/spl/spl_ext.c                      |  36 +++---
 common/spl/spl_fat.c                      |  62 ++++------
 common/spl/spl_fit.c                      |  74 ++++-------
 common/spl/spl_imx_container.c            |  55 ++++-----
 common/spl/spl_legacy.c                   | 110 ++++-------------
 common/spl/spl_mmc.c                      | 101 ++-------------
 common/spl/spl_nand.c                     | 104 ++++------------
 common/spl/spl_net.c                      |  29 +----
 common/spl/spl_nor.c                      |  42 ++-----
 common/spl/spl_ram.c                      |   2 +-
 common/spl/spl_semihosting.c              |  65 ++--------
 common/spl/spl_spi.c                      | 130 ++++---------------
 common/spl/spl_ymodem.c                   |   4 +-
 configs/am335x_evm_spiboot_defconfig      |   2 +-
 configs/am65x_evm_r5_usbdfu_defconfig     |   1 -
 configs/xilinx_zynqmp_mini_qspi_defconfig |   3 +
 configs/zynq_cse_nand_defconfig           |   3 +
 configs/zynq_cse_nor_defconfig            |   3 +
 configs/zynq_cse_qspi_defconfig           |   3 +
 drivers/usb/gadget/f_sdp.c                |  10 +-
 include/spl.h                             |  60 +++++++--
 include/spl_load.h                        | 144 ++++++++++++++++++++++
 include/test/spl.h                        |   4 +
 test/image/Kconfig                        |   1 +
 test/image/spl_load.c                     |  13 +-
 test/image/spl_load_fs.c                  |  32 +++--
 test/image/spl_load_nand.c                |   2 +
 test/image/spl_load_net.c                 |   2 +
 test/image/spl_load_nor.c                 |   2 +
 test/image/spl_load_os.c                  |  16 ++-
 test/image/spl_load_spi.c                 |   1 +
 36 files changed, 536 insertions(+), 732 deletions(-)
 create mode 100644 include/spl_load.h

-- 
2.37.1


^ permalink raw reply	[flat|nested] 62+ messages in thread

* [PATCH v6 01/25] spl: blk_fs: Fix uninitialized return value when we can't get a blk_desc
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:23   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 02/25] arm: Disable SPL_FS_FAT when it isn't used Sean Anderson
                   ` (24 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson, Mayuresh Chitale

Initialize ret to avoid returning garbage if blk_get_devnum_by_uclass_id
fails.

Fixes: 8ce6a2e1757 ("spl: blk: Support loading images from fs")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 common/spl/spl_blk_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
index 63825d620d1..144c8a65b5d 100644
--- a/common/spl/spl_blk_fs.c
+++ b/common/spl/spl_blk_fs.c
@@ -50,7 +50,7 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
 	struct blk_desc *blk_desc;
 	loff_t actlen, filesize;
 	struct blk_dev dev;
-	int ret;
+	int ret = -ENODEV;
 
 	blk_desc = blk_get_devnum_by_uclass_id(uclass_id, devnum);
 	if (!blk_desc) {
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 02/25] arm: Disable SPL_FS_FAT when it isn't used
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
  2023-11-06  2:25 ` [PATCH v6 01/25] spl: blk_fs: Fix uninitialized return value when we can't get a blk_desc Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-06  6:58   ` Michal Simek
  2023-11-06  2:25 ` [PATCH v6 03/25] spl: Make SHOW_ERRORS depend on LIBCOMMON Sean Anderson
                   ` (23 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson, Michal Simek

Several boards enable SPL_FS_FAT and SPL_LIBDISK_SUPPORT when they can't be
used (as there is no block device support enabled). Disable these configs.
The list of boards was generated with the following command:

    $ tools/qconfig.py -f SPL SPL_FS_FAT ~SPL_MMC ~SPL_BLK_FS ~SPL_SATA \
                          ~SPL_USB_STORAGE ~ENV_IS_IN_FAT ~EFI

LIBDISK was left enabled for the am* boards, since it seems to result in
actual size reduction, indicating that partitions are being used for
something.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

(no changes since v1)

 configs/am335x_evm_spiboot_defconfig      | 2 +-
 configs/am65x_evm_r5_usbdfu_defconfig     | 1 -
 configs/xilinx_zynqmp_mini_qspi_defconfig | 3 +++
 configs/zynq_cse_nand_defconfig           | 3 +++
 configs/zynq_cse_nor_defconfig            | 3 +++
 configs/zynq_cse_qspi_defconfig           | 3 +++
 6 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/configs/am335x_evm_spiboot_defconfig b/configs/am335x_evm_spiboot_defconfig
index b5b11fb62c8..fff5265e56a 100644
--- a/configs/am335x_evm_spiboot_defconfig
+++ b/configs/am335x_evm_spiboot_defconfig
@@ -13,6 +13,7 @@ CONFIG_CLOCK_SYNTHESIZER=y
 # CONFIG_OF_LIBFDT_OVERLAY is not set
 # CONFIG_SPL_MMC is not set
 CONFIG_SPL=y
+# CONFIG_SPL_FS_FAT is not set
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_TIMESTAMP=y
@@ -27,7 +28,6 @@ CONFIG_SPL_SYS_MALLOC=y
 CONFIG_SPL_SYS_MALLOC_SIZE=0x800000
 CONFIG_SPL_FIT_IMAGE_TINY=y
 # CONFIG_SPL_FS_EXT4 is not set
-CONFIG_SPL_FS_LOAD_PAYLOAD_NAME="u-boot.img"
 CONFIG_SPL_MTD=y
 # CONFIG_SPL_NAND_SUPPORT is not set
 CONFIG_SPL_DM_SPI_FLASH=y
diff --git a/configs/am65x_evm_r5_usbdfu_defconfig b/configs/am65x_evm_r5_usbdfu_defconfig
index f610b2dd94e..6b0bb120d10 100644
--- a/configs/am65x_evm_r5_usbdfu_defconfig
+++ b/configs/am65x_evm_r5_usbdfu_defconfig
@@ -21,7 +21,6 @@ CONFIG_SPL_DRIVERS_MISC=y
 CONFIG_SPL_STACK_R_ADDR=0x82000000
 CONFIG_SPL_SIZE_LIMIT=0x7ec00
 CONFIG_SPL_SIZE_LIMIT_PROVIDE_STACK=0x2000
-CONFIG_SPL_FS_FAT=y
 CONFIG_SPL_LIBDISK_SUPPORT=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SPL_LOAD_FIT=y
diff --git a/configs/xilinx_zynqmp_mini_qspi_defconfig b/configs/xilinx_zynqmp_mini_qspi_defconfig
index a1adfb9e5d1..8b92e1c7358 100644
--- a/configs/xilinx_zynqmp_mini_qspi_defconfig
+++ b/configs/xilinx_zynqmp_mini_qspi_defconfig
@@ -11,6 +11,8 @@ CONFIG_ENV_SIZE=0x80
 CONFIG_DEFAULT_DEVICE_TREE="zynqmp-mini-qspi"
 CONFIG_SPL_STACK=0xfffffffc
 CONFIG_SPL=y
+# CONFIG_SPL_FS_FAT is not set
+# CONFIG_SPL_LIBDISK_SUPPORT is not set
 CONFIG_SYS_MEM_RSVD_FOR_MMU=y
 CONFIG_ZYNQMP_NO_DDR=y
 # CONFIG_PSCI_RESET is not set
@@ -89,6 +91,7 @@ CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_ARM_DCC=y
 CONFIG_SPI=y
 CONFIG_ZYNQMP_GQSPI=y
+CONFIG_FS_FAT=y
 # CONFIG_FAT_WRITE is not set
 CONFIG_PANIC_HANG=y
 # CONFIG_GZIP is not set
diff --git a/configs/zynq_cse_nand_defconfig b/configs/zynq_cse_nand_defconfig
index 19f653f40d0..01f5c090d5e 100644
--- a/configs/zynq_cse_nand_defconfig
+++ b/configs/zynq_cse_nand_defconfig
@@ -13,6 +13,8 @@ CONFIG_DEFAULT_DEVICE_TREE="zynq-cse-nand"
 CONFIG_SPL_STACK_R_ADDR=0x200000
 CONFIG_SPL_STACK=0xfffffe00
 CONFIG_SPL=y
+# CONFIG_SPL_FS_FAT is not set
+# CONFIG_SPL_LIBDISK_SUPPORT is not set
 CONFIG_SYS_LOAD_ADDR=0x0
 CONFIG_REMAKE_ELF=y
 CONFIG_SYS_CUSTOM_LDSCRIPT=y
@@ -78,6 +80,7 @@ CONFIG_MTD_RAW_NAND=y
 CONFIG_NAND_ZYNQ=y
 CONFIG_SYS_NAND_ONFI_DETECTION=y
 CONFIG_ARM_DCC=y
+CONFIG_FS_FAT=y
 CONFIG_SYS_TIMER_COUNTS_DOWN=y
 # CONFIG_GZIP is not set
 # CONFIG_LMB is not set
diff --git a/configs/zynq_cse_nor_defconfig b/configs/zynq_cse_nor_defconfig
index 64df1f0b83e..7b32ffd3501 100644
--- a/configs/zynq_cse_nor_defconfig
+++ b/configs/zynq_cse_nor_defconfig
@@ -13,6 +13,8 @@ CONFIG_DEFAULT_DEVICE_TREE="zynq-cse-nor"
 CONFIG_SPL_STACK_R_ADDR=0x200000
 CONFIG_SPL_STACK=0xfffffe00
 CONFIG_SPL=y
+# CONFIG_SPL_FS_FAT is not set
+# CONFIG_SPL_LIBDISK_SUPPORT is not set
 CONFIG_SYS_LOAD_ADDR=0x0
 CONFIG_REMAKE_ELF=y
 CONFIG_SYS_CUSTOM_LDSCRIPT=y
@@ -81,6 +83,7 @@ CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y
 CONFIG_SYS_FLASH_CFI=y
 CONFIG_SYS_FLASH_QUIET_TEST=y
 CONFIG_ARM_DCC=y
+CONFIG_FS_FAT=y
 CONFIG_SYS_TIMER_COUNTS_DOWN=y
 # CONFIG_GZIP is not set
 # CONFIG_LMB is not set
diff --git a/configs/zynq_cse_qspi_defconfig b/configs/zynq_cse_qspi_defconfig
index 9368fb4ffbc..b4561c50e9a 100644
--- a/configs/zynq_cse_qspi_defconfig
+++ b/configs/zynq_cse_qspi_defconfig
@@ -16,6 +16,8 @@ CONFIG_SPL_STACK=0xfffffe00
 CONFIG_SPL=y
 CONFIG_DEBUG_UART_BASE=0x0
 CONFIG_DEBUG_UART_CLOCK=0
+# CONFIG_SPL_FS_FAT is not set
+# CONFIG_SPL_LIBDISK_SUPPORT is not set
 # CONFIG_ZYNQ_DDRC_INIT is not set
 # CONFIG_CMD_ZYNQ is not set
 CONFIG_SYS_LOAD_ADDR=0x0
@@ -90,6 +92,7 @@ CONFIG_SPI_FLASH_WINBOND=y
 # CONFIG_SPI_FLASH_USE_4K_SECTORS is not set
 CONFIG_ARM_DCC=y
 CONFIG_ZYNQ_QSPI=y
+CONFIG_FS_FAT=y
 CONFIG_SYS_TIMER_COUNTS_DOWN=y
 # CONFIG_GZIP is not set
 # CONFIG_LMB is not set
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 03/25] spl: Make SHOW_ERRORS depend on LIBCOMMON
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
  2023-11-06  2:25 ` [PATCH v6 01/25] spl: blk_fs: Fix uninitialized return value when we can't get a blk_desc Sean Anderson
  2023-11-06  2:25 ` [PATCH v6 02/25] arm: Disable SPL_FS_FAT when it isn't used Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:23   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 04/25] spl: semihosting: Don't close fd before spl_load_simple_fit Sean Anderson
                   ` (22 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

The purpose of SHOW_ERRORS is to print extra information. Make it depend
on LIBCOMMON to avoid having to check for two configs.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
---

(no changes since v5)

Changes in v5:
- New

 common/spl/Kconfig | 1 +
 common/spl/spl.c   | 3 +--
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 00332cf243a..e929f1bbae1 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -183,6 +183,7 @@ config SPL_SYS_REPORT_STACK_F_USAGE
 
 config SPL_SHOW_ERRORS
 	bool "Show more information when something goes wrong"
+	depends on SPL_LIBCOMMON_SUPPORT
 	help
 	  This enabled more verbose error messages and checking when something
 	  goes wrong in SPL. For example, it shows the error code when U-Boot
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 732d90d39e6..7ce38ce46d4 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -718,8 +718,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	ret = boot_from_devices(&spl_image, spl_boot_list,
 				ARRAY_SIZE(spl_boot_list));
 	if (ret) {
-		if (CONFIG_IS_ENABLED(SHOW_ERRORS) &&
-		    CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT))
+		if (CONFIG_IS_ENABLED(SHOW_ERRORS))
 			printf(SPL_TPL_PROMPT "failed to boot from all boot devices (err=%d)\n",
 			       ret);
 		else
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 04/25] spl: semihosting: Don't close fd before spl_load_simple_fit
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (2 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 03/25] spl: Make SHOW_ERRORS depend on LIBCOMMON Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:23   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 05/25] spl: Remove NULL assignments in spl_load_info Sean Anderson
                   ` (21 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

On real hardware, semihosting calls tends to have a large constant
overhead (on the order of tens of milliseconds). Reduce the number of
calls by one by reusing the existing fd in smh_fit_read, and closing it
at the end of spl_smh_load_image.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 common/spl/spl_semihosting.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c
index f7dd289286d..8f11c29913f 100644
--- a/common/spl/spl_semihosting.c
+++ b/common/spl/spl_semihosting.c
@@ -24,18 +24,14 @@ static int smh_read_full(long fd, void *memp, size_t len)
 static ulong smh_fit_read(struct spl_load_info *load, ulong file_offset,
 			  ulong size, void *buf)
 {
-	long fd;
+	long fd = *(long *)load->priv;
 	ulong ret;
 
-	fd = smh_open(load->filename, MODE_READ | MODE_BINARY);
-	if (fd < 0) {
-		log_debug("could not open %s: %ld\n", load->filename, fd);
+	if (smh_seek(fd, file_offset))
 		return 0;
-	}
+
 	ret = smh_read(fd, buf, size);
-	smh_close(fd);
-
-	return ret;
+	return ret < 0 ? 0 : ret;
 }
 
 static int spl_smh_load_image(struct spl_image_info *spl_image,
@@ -73,11 +69,11 @@ static int spl_smh_load_image(struct spl_image_info *spl_image,
 		debug("Found FIT\n");
 		load.read = smh_fit_read;
 		load.bl_len = 1;
-		load.filename = filename;
-		load.priv = NULL;
-		smh_close(fd);
+		load.filename = NULL;
+		load.priv = &fd;
 
-		return spl_load_simple_fit(spl_image, &load, 0, header);
+		ret = spl_load_simple_fit(spl_image, &load, 0, header);
+		goto out;
 	}
 
 	ret = spl_parse_image_header(spl_image, bootdev, header);
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 05/25] spl: Remove NULL assignments in spl_load_info
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (3 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 04/25] spl: semihosting: Don't close fd before spl_load_simple_fit Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:23   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 06/25] spl: Remove dev from spl_load_info Sean Anderson
                   ` (20 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

Remove NULL assignments to fields in spl_load_info when .load doesn't
reference these fields. This can result in more efficient code. filename
must stay even if it is unused, since load_simple_fit uses it.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 arch/arm/mach-sunxi/spl_spi_sunxi.c | 2 --
 common/spl/spl_fat.c                | 1 -
 common/spl/spl_mmc.c                | 2 --
 common/spl/spl_nand.c               | 4 ----
 common/spl/spl_spi.c                | 2 --
 common/spl/spl_ymodem.c             | 1 -
 6 files changed, 12 deletions(-)

diff --git a/arch/arm/mach-sunxi/spl_spi_sunxi.c b/arch/arm/mach-sunxi/spl_spi_sunxi.c
index c2410dd7bb1..896aba69c32 100644
--- a/arch/arm/mach-sunxi/spl_spi_sunxi.c
+++ b/arch/arm/mach-sunxi/spl_spi_sunxi.c
@@ -354,8 +354,6 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		debug("Found FIT image\n");
-		load.dev = NULL;
-		load.priv = NULL;
 		load.filename = NULL;
 		load.bl_len = 1;
 		load.read = spi_load_read;
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 014074f85be..6172e7bcd48 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -99,7 +99,6 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
 		load.read = spl_fit_read;
 		load.bl_len = 1;
 		load.filename = (void *)filename;
-		load.priv = NULL;
 
 		return spl_load_simple_fit(spl_image, &load, 0, header);
 	} else {
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 82689da1401..6d9137c32e0 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -106,7 +106,6 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		load.dev = mmc;
-		load.priv = NULL;
 		load.filename = NULL;
 		load.bl_len = mmc->read_bl_len;
 		load.read = h_spl_load_read;
@@ -116,7 +115,6 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		load.dev = mmc;
-		load.priv = NULL;
 		load.filename = NULL;
 		load.bl_len = mmc->read_bl_len;
 		load.read = h_spl_load_read;
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index b8cd6403ba4..9a5a5ffa04a 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -91,7 +91,6 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		debug("Found FIT\n");
-		load.dev = NULL;
 		load.priv = &offset;
 		load.filename = NULL;
 		load.bl_len = bl_len;
@@ -101,7 +100,6 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		   valid_container_hdr((void *)header)) {
 		struct spl_load_info load;
 
-		load.dev = NULL;
 		load.priv = &offset;
 		load.filename = NULL;
 		load.bl_len = bl_len;
@@ -112,8 +110,6 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		debug("Found legacy image\n");
-		load.dev = NULL;
-		load.priv = NULL;
 		load.filename = NULL;
 		load.bl_len = IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1;
 		load.read = spl_nand_legacy_read;
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index 3ac4b1b5091..d83d70f2f33 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -152,7 +152,6 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 
 			debug("Found FIT\n");
 			load.dev = flash;
-			load.priv = NULL;
 			load.filename = NULL;
 			load.bl_len = 1;
 			load.read = spl_spi_fit_read;
@@ -164,7 +163,6 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 			struct spl_load_info load;
 
 			load.dev = flash;
-			load.priv = NULL;
 			load.filename = NULL;
 			load.bl_len = 1;
 			load.read = spl_spi_fit_read;
diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c
index 038b4438457..8616cb3e915 100644
--- a/common/spl/spl_ymodem.c
+++ b/common/spl/spl_ymodem.c
@@ -134,7 +134,6 @@ int spl_ymodem_load_image(struct spl_image_info *spl_image,
 		struct ymodem_fit_info info;
 
 		debug("Found FIT\n");
-		load.dev = NULL;
 		load.priv = (void *)&info;
 		load.filename = NULL;
 		load.bl_len = 1;
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 06/25] spl: Remove dev from spl_load_info
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (4 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 05/25] spl: Remove NULL assignments in spl_load_info Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:23   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 07/25] spl: Take advantage of bl_len's power-of-twoness Sean Anderson
                   ` (19 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

dev and priv server the same purpose, and are never set at the same time.
Remove dev and convert all users to priv. While we're at it, reorder bl_len
to be last for better alignment.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 common/spl/spl_mmc.c       | 6 +++---
 common/spl/spl_spi.c       | 6 +++---
 drivers/usb/gadget/f_sdp.c | 6 +++---
 include/spl.h              | 4 +---
 4 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 6d9137c32e0..3d7551a7dae 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -65,7 +65,7 @@ static int mmc_load_legacy(struct spl_image_info *spl_image,
 static ulong h_spl_load_read(struct spl_load_info *load, ulong sector,
 			     ulong count, void *buf)
 {
-	struct mmc *mmc = load->dev;
+	struct mmc *mmc = load->priv;
 
 	return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf);
 }
@@ -105,7 +105,7 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		debug("Found FIT\n");
-		load.dev = mmc;
+		load.priv = mmc;
 		load.filename = NULL;
 		load.bl_len = mmc->read_bl_len;
 		load.read = h_spl_load_read;
@@ -114,7 +114,7 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
 		   valid_container_hdr((void *)header)) {
 		struct spl_load_info load;
 
-		load.dev = mmc;
+		load.priv = mmc;
 		load.filename = NULL;
 		load.bl_len = mmc->read_bl_len;
 		load.read = h_spl_load_read;
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index d83d70f2f33..af7a28e7c25 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -59,7 +59,7 @@ static int spi_load_image_os(struct spl_image_info *spl_image,
 static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector,
 			      ulong count, void *buf)
 {
-	struct spi_flash *flash = load->dev;
+	struct spi_flash *flash = load->priv;
 	ulong ret;
 
 	ret = spi_flash_read(flash, sector, count, buf);
@@ -151,7 +151,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 			struct spl_load_info load;
 
 			debug("Found FIT\n");
-			load.dev = flash;
+			load.priv = flash;
 			load.filename = NULL;
 			load.bl_len = 1;
 			load.read = spl_spi_fit_read;
@@ -162,7 +162,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 			   valid_container_hdr((void *)header)) {
 			struct spl_load_info load;
 
-			load.dev = flash;
+			load.priv = flash;
 			load.filename = NULL;
 			load.bl_len = 1;
 			load.read = spl_spi_fit_read;
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index ee9384fb37e..1b16b7eb452 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -744,7 +744,7 @@ static ulong sdp_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 *)(load->dev + sector), count);
+	memcpy(buf, (void *)(load->priv + sector), count);
 	return count;
 }
 
@@ -844,7 +844,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
 				struct spl_load_info load;
 
 				debug("Found FIT\n");
-				load.dev = header;
+				load.priv = header;
 				load.bl_len = 1;
 				load.read = sdp_load_read;
 				spl_load_simple_fit(spl_image, &load, 0,
@@ -857,7 +857,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
 			    valid_container_hdr((void *)header)) {
 				struct spl_load_info load;
 
-				load.dev = header;
+				load.priv = header;
 				load.bl_len = 1;
 				load.read = sdp_load_read;
 				spl_load_imx_container(spl_image, &load, 0);
diff --git a/include/spl.h b/include/spl.h
index 8ff20adc28e..951e136b9ea 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -285,16 +285,13 @@ static inline void *spl_image_fdt_addr(struct spl_image_info *info)
 /**
  * Information required to load data from a device
  *
- * @dev: Pointer to the device, e.g. struct mmc *
  * @priv: Private data for the device
  * @bl_len: Block length for reading in bytes
  * @filename: Name of the fit image file.
  * @read: Function to call to read from the device
  */
 struct spl_load_info {
-	void *dev;
 	void *priv;
-	int bl_len;
 	const char *filename;
 	/**
 	 * read() - Read from device
@@ -307,6 +304,7 @@ struct spl_load_info {
 	 */
 	ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
 		      void *buf);
+	int bl_len;
 };
 
 /*
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 07/25] spl: Take advantage of bl_len's power-of-twoness
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (5 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 06/25] spl: Remove dev from spl_load_info Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:23   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes Sean Anderson
                   ` (18 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson, Fabio Estevam, Stefano Babic, uboot-imx

bl_len must be a power of two, so we can use ALIGN instead of roundup and
similar tricks to avoid divisions.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 common/spl/spl_fit.c           | 2 +-
 common/spl/spl_imx_container.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 70d8d5942d9..6084ead0919 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -194,7 +194,7 @@ static int get_aligned_image_overhead(struct spl_load_info *info, int offset)
 	if (info->filename)
 		return offset & (ARCH_DMA_MINALIGN - 1);
 
-	return offset % info->bl_len;
+	return offset & (info->bl_len - 1);
 }
 
 static int get_aligned_image_size(struct spl_load_info *info, int data_size,
diff --git a/common/spl/spl_imx_container.c b/common/spl/spl_imx_container.c
index 127802f5cb7..1cc51782766 100644
--- a/common/spl/spl_imx_container.c
+++ b/common/spl/spl_imx_container.c
@@ -33,13 +33,13 @@ static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image,
 	images = (struct boot_img_t *)((u8 *)container +
 				       sizeof(struct container_hdr));
 
-	if (images[image_index].offset % info->bl_len) {
+	if (!IS_ALIGNED(images[image_index].offset, info->bl_len)) {
 		printf("%s: image%d offset not aligned to %u\n",
 		       __func__, image_index, info->bl_len);
 		return NULL;
 	}
 
-	sectors = roundup(images[image_index].size, info->bl_len) /
+	sectors = ALIGN(images[image_index].size, info->bl_len) /
 		info->bl_len;
 	sector = images[image_index].offset / info->bl_len +
 		container_sector;
@@ -69,7 +69,7 @@ static int read_auth_container(struct spl_image_info *spl_image,
 	u32 sectors;
 	int i, size, ret = 0;
 
-	size = roundup(CONTAINER_HDR_ALIGNMENT, info->bl_len);
+	size = ALIGN(CONTAINER_HDR_ALIGNMENT, info->bl_len);
 	sectors = size / info->bl_len;
 
 	/*
@@ -103,7 +103,7 @@ static int read_auth_container(struct spl_image_info *spl_image,
 	debug("Container length %u\n", length);
 
 	if (length > CONTAINER_HDR_ALIGNMENT) {
-		size = roundup(length, info->bl_len);
+		size = ALIGN(length, info->bl_len);
 		sectors = size / info->bl_len;
 
 		free(container);
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (6 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 07/25] spl: Take advantage of bl_len's power-of-twoness Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-06 12:35   ` Xavier Drudis Ferran
  2023-11-06  2:25 ` [PATCH v6 09/25] spl: Remove filename from spl_load_info Sean Anderson
                   ` (17 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson, Fabio Estevam, Stefano Babic, uboot-imx

Simplify things a bit for callers of spl_load_info->read by refactoring it
to use units of bytes instead of bl_len. This generally simplifies the
logic, as MMC is the only loader which actually works in sectors. It will
also allow further refactoring to remove the special-case handling of
filename.  spl_load_legacy_img already works in units of bytes (oops) so it
doesn't need to be changed.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 arch/arm/mach-imx/spl_imx_romapi.c | 16 +++-------
 common/spl/spl_fit.c               | 51 +++++++++++++++---------------
 common/spl/spl_imx_container.c     | 45 +++++++++++---------------
 common/spl/spl_mmc.c               | 24 ++++++++------
 common/spl/spl_nand.c              |  8 ++---
 include/spl.h                      | 16 ++++++----
 test/image/spl_load_os.c           | 13 ++++----
 7 files changed, 80 insertions(+), 93 deletions(-)

diff --git a/arch/arm/mach-imx/spl_imx_romapi.c b/arch/arm/mach-imx/spl_imx_romapi.c
index 93d48e56aca..d7f6cb4b5ba 100644
--- a/arch/arm/mach-imx/spl_imx_romapi.c
+++ b/arch/arm/mach-imx/spl_imx_romapi.c
@@ -53,16 +53,10 @@ static int is_boot_from_stream_device(u32 boot)
 }
 
 static ulong spl_romapi_read_seekable(struct spl_load_info *load,
-				      ulong sector, ulong count,
+				      ulong offset, ulong byte,
 				      void *buf)
 {
-	u32 pagesize = *(u32 *)load->priv;
-	ulong byte = count * pagesize;
-	u32 offset;
-
-	offset = sector * pagesize;
-
-	return spl_romapi_raw_seekable_read(offset, byte, buf) / pagesize;
+	return spl_romapi_raw_seekable_read(offset, byte, buf);
 }
 
 static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image,
@@ -109,8 +103,7 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image,
 		memset(&load, 0, sizeof(load));
 		load.bl_len = pagesize;
 		load.read = spl_romapi_read_seekable;
-		load.priv = &pagesize;
-		return spl_load_simple_fit(spl_image, &load, offset / pagesize, header);
+		return spl_load_simple_fit(spl_image, &load, offset, header);
 	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
 		   valid_container_hdr((void *)header)) {
 		struct spl_load_info load;
@@ -118,9 +111,8 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image,
 		memset(&load, 0, sizeof(load));
 		load.bl_len = pagesize;
 		load.read = spl_romapi_read_seekable;
-		load.priv = &pagesize;
 
-		ret = spl_load_imx_container(spl_image, &load, offset / pagesize);
+		ret = spl_load_imx_container(spl_image, &load, offset);
 	} else {
 		/* TODO */
 		puts("Can't support legacy image\n");
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 6084ead0919..ce7ef0efd0d 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -180,7 +180,7 @@ static int get_aligned_image_offset(struct spl_load_info *info, int offset)
 	if (info->filename)
 		return offset & ~(ARCH_DMA_MINALIGN - 1);
 
-	return offset / info->bl_len;
+	return ALIGN_DOWN(offset, info->bl_len);
 }
 
 static int get_aligned_image_overhead(struct spl_load_info *info, int offset)
@@ -205,7 +205,7 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size,
 	if (info->filename)
 		return data_size;
 
-	return (data_size + info->bl_len - 1) / info->bl_len;
+	return ALIGN(data_size, info->bl_len);
 }
 
 /**
@@ -222,7 +222,7 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size,
  *
  * Return:	0 on success or a negative error number.
  */
-static int load_simple_fit(struct spl_load_info *info, ulong sector,
+static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,
 			   const struct spl_fit_info *ctx, int node,
 			   struct spl_image_info *image_info)
 {
@@ -234,7 +234,6 @@ static int load_simple_fit(struct spl_load_info *info, ulong sector,
 	void *load_ptr;
 	void *src;
 	ulong overhead;
-	int nr_sectors;
 	uint8_t image_comp = -1, type = -1;
 	const void *data;
 	const void *fit = ctx->fit;
@@ -291,11 +290,12 @@ static int load_simple_fit(struct spl_load_info *info, ulong sector,
 		length = len;
 
 		overhead = get_aligned_image_overhead(info, offset);
-		nr_sectors = get_aligned_image_size(info, length, offset);
+		size = get_aligned_image_size(info, length, offset);
 
 		if (info->read(info,
-			       sector + get_aligned_image_offset(info, offset),
-			       nr_sectors, src_ptr) != nr_sectors)
+			       fit_offset +
+			       get_aligned_image_offset(info, offset), size,
+			       src_ptr) != size)
 			return -EIO;
 
 		debug("External data: dst=%p, offset=%x, size=%lx\n",
@@ -380,7 +380,7 @@ __weak int board_spl_fit_append_fdt_skip(const char *name)
 }
 
 static int spl_fit_append_fdt(struct spl_image_info *spl_image,
-			      struct spl_load_info *info, ulong sector,
+			      struct spl_load_info *info, ulong offset,
 			      const struct spl_fit_info *ctx)
 {
 	struct spl_image_info image_info;
@@ -414,7 +414,7 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 		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);
+		ret = load_simple_fit(info, offset, ctx, node, &image_info);
 		if (ret < 0)
 			return ret;
 
@@ -465,7 +465,7 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 					      __func__);
 			}
 			image_info.load_addr = (ulong)tmpbuffer;
-			ret = load_simple_fit(info, sector, ctx, node,
+			ret = load_simple_fit(info, offset, ctx, node,
 					      &image_info);
 			if (ret < 0)
 				break;
@@ -642,7 +642,7 @@ static int spl_fit_upload_fpga(struct spl_fit_info *ctx, int node,
 }
 
 static int spl_fit_load_fpga(struct spl_fit_info *ctx,
-			     struct spl_load_info *info, ulong sector)
+			     struct spl_load_info *info, ulong offset)
 {
 	int node, ret;
 
@@ -657,7 +657,7 @@ static int spl_fit_load_fpga(struct spl_fit_info *ctx,
 	warn_deprecated("'fpga' property in config node. Use 'loadables'");
 
 	/* Load the image and set up the fpga_image structure */
-	ret = load_simple_fit(info, sector, ctx, node, &fpga_image);
+	ret = load_simple_fit(info, offset, ctx, node, &fpga_image);
 	if (ret) {
 		printf("%s: Cannot load the FPGA: %i\n", __func__, ret);
 		return ret;
@@ -667,11 +667,10 @@ static int spl_fit_load_fpga(struct spl_fit_info *ctx,
 }
 
 static int spl_simple_fit_read(struct spl_fit_info *ctx,
-			       struct spl_load_info *info, ulong sector,
+			       struct spl_load_info *info, ulong offset,
 			       const void *fit_header)
 {
 	unsigned long count, size;
-	int sectors;
 	void *buf;
 
 	/*
@@ -690,13 +689,13 @@ static int spl_simple_fit_read(struct spl_fit_info *ctx,
 	 * For FIT with data embedded, data is loaded as part of FIT image.
 	 * For FIT with external data, data is not loaded in this step.
 	 */
-	sectors = get_aligned_image_size(info, size, 0);
-	buf = board_spl_fit_buffer_addr(size, sectors, info->bl_len);
+	size = get_aligned_image_size(info, size, 0);
+	buf = board_spl_fit_buffer_addr(size, size, 1);
 
-	count = info->read(info, sector, sectors, buf);
+	count = info->read(info, offset, size, buf);
 	ctx->fit = buf;
-	debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu, size=0x%lx\n",
-	      sector, sectors, buf, count, size);
+	debug("fit read offset %lx, size=%lu, dst=%p, count=%lu\n",
+	      offset, size, buf, count);
 
 	return (count == 0) ? -EIO : 0;
 }
@@ -728,7 +727,7 @@ static int spl_simple_fit_parse(struct spl_fit_info *ctx)
 }
 
 int spl_load_simple_fit(struct spl_image_info *spl_image,
-			struct spl_load_info *info, ulong sector, void *fit)
+			struct spl_load_info *info, ulong offset, void *fit)
 {
 	struct spl_image_info image_info;
 	struct spl_fit_info ctx;
@@ -737,7 +736,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 	int index = 0;
 	int firmware_node;
 
-	ret = spl_simple_fit_read(&ctx, info, sector, fit);
+	ret = spl_simple_fit_read(&ctx, info, offset, fit);
 	if (ret < 0)
 		return ret;
 
@@ -752,7 +751,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 		return ret;
 
 	if (IS_ENABLED(CONFIG_SPL_FPGA))
-		spl_fit_load_fpga(&ctx, info, sector);
+		spl_fit_load_fpga(&ctx, info, offset);
 
 	/*
 	 * Find the U-Boot image using the following search order:
@@ -782,7 +781,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 	}
 
 	/* Load the image and set up the spl_image structure */
-	ret = load_simple_fit(info, sector, &ctx, node, spl_image);
+	ret = load_simple_fit(info, offset, &ctx, node, spl_image);
 	if (ret)
 		return ret;
 
@@ -800,7 +799,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 	 * We allow this to fail, as the U-Boot image might embed its FDT.
 	 */
 	if (os_takes_devicetree(spl_image->os)) {
-		ret = spl_fit_append_fdt(spl_image, info, sector, &ctx);
+		ret = spl_fit_append_fdt(spl_image, info, offset, &ctx);
 		if (ret < 0 && spl_image->os != IH_OS_U_BOOT)
 			return ret;
 	}
@@ -823,7 +822,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 			continue;
 
 		image_info.load_addr = 0;
-		ret = load_simple_fit(info, sector, &ctx, node, &image_info);
+		ret = load_simple_fit(info, offset, &ctx, node, &image_info);
 		if (ret < 0) {
 			printf("%s: can't load image loadables index %d (ret = %d)\n",
 			       __func__, index, ret);
@@ -837,7 +836,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 			debug("Loadable is %s\n", genimg_get_os_name(os_type));
 
 		if (os_takes_devicetree(os_type)) {
-			spl_fit_append_fdt(&image_info, info, sector, &ctx);
+			spl_fit_append_fdt(&image_info, info, offset, &ctx);
 			spl_image->fdt_addr = image_info.fdt_addr;
 		}
 
diff --git a/common/spl/spl_imx_container.c b/common/spl/spl_imx_container.c
index 1cc51782766..ad89a99fb23 100644
--- a/common/spl/spl_imx_container.c
+++ b/common/spl/spl_imx_container.c
@@ -19,11 +19,10 @@ static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image,
 					  struct spl_load_info *info,
 					  struct container_hdr *container,
 					  int image_index,
-					  u32 container_sector)
+					  ulong container_offset)
 {
 	struct boot_img_t *images;
-	ulong sector;
-	u32 sectors;
+	ulong offset, overhead, size;
 
 	if (image_index > container->num_images) {
 		debug("Invalid image number\n");
@@ -39,16 +38,14 @@ static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image,
 		return NULL;
 	}
 
-	sectors = ALIGN(images[image_index].size, info->bl_len) /
-		info->bl_len;
-	sector = images[image_index].offset / info->bl_len +
-		container_sector;
+	size = ALIGN(images[image_index].size, info->bl_len);
+	offset = images[image_index].offset + container_offset;
 
-	debug("%s: container: %p sector: %lu sectors: %u\n", __func__,
-	      container, sector, sectors);
-	if (info->read(info, sector, sectors,
-		       map_sysmem(images[image_index].dst,
-				  images[image_index].size)) != sectors) {
+	debug("%s: container: %p offset: %lu size: %lu\n", __func__,
+	      container, offset, size);
+	if (info->read(info, offset, size,
+		       map_sysmem(images[image_index].dst - overhead,
+				  images[image_index].size)) != size) {
 		printf("%s wrong\n", __func__);
 		return NULL;
 	}
@@ -62,15 +59,13 @@ static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image,
 }
 
 static int read_auth_container(struct spl_image_info *spl_image,
-			       struct spl_load_info *info, ulong sector)
+			       struct spl_load_info *info, ulong offset)
 {
 	struct container_hdr *container = NULL;
 	u16 length;
-	u32 sectors;
 	int i, size, ret = 0;
 
 	size = ALIGN(CONTAINER_HDR_ALIGNMENT, info->bl_len);
-	sectors = size / info->bl_len;
 
 	/*
 	 * It will not override the ATF code, so safe to use it here,
@@ -80,9 +75,9 @@ static int read_auth_container(struct spl_image_info *spl_image,
 	if (!container)
 		return -ENOMEM;
 
-	debug("%s: container: %p sector: %lu sectors: %u\n", __func__,
-	      container, sector, sectors);
-	if (info->read(info, sector, sectors, container) != sectors) {
+	debug("%s: container: %p offset: %lu size: %u\n", __func__,
+	      container, offset, size);
+	if (info->read(info, offset, size, container) != size) {
 		ret = -EIO;
 		goto end;
 	}
@@ -104,17 +99,15 @@ static int read_auth_container(struct spl_image_info *spl_image,
 
 	if (length > CONTAINER_HDR_ALIGNMENT) {
 		size = ALIGN(length, info->bl_len);
-		sectors = size / info->bl_len;
 
 		free(container);
 		container = malloc(size);
 		if (!container)
 			return -ENOMEM;
 
-		debug("%s: container: %p sector: %lu sectors: %u\n",
-		      __func__, container, sector, sectors);
-		if (info->read(info, sector, sectors, container) !=
-		    sectors) {
+		debug("%s: container: %p offset: %lu size: %u\n",
+		      __func__, container, offset, size);
+		if (info->read(info, offset, size, container) != size) {
 			ret = -EIO;
 			goto end;
 		}
@@ -129,7 +122,7 @@ static int read_auth_container(struct spl_image_info *spl_image,
 	for (i = 0; i < container->num_images; i++) {
 		struct boot_img_t *image = read_auth_image(spl_image, info,
 							   container, i,
-							   sector);
+							   offset);
 
 		if (!image) {
 			ret = -EINVAL;
@@ -154,7 +147,7 @@ end:
 }
 
 int spl_load_imx_container(struct spl_image_info *spl_image,
-			   struct spl_load_info *info, ulong sector)
+			   struct spl_load_info *info, ulong offset)
 {
-	return read_auth_container(spl_image, info, sector);
+	return read_auth_container(spl_image, info, offset);
 }
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 3d7551a7dae..9f41ea648ce 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -62,12 +62,14 @@ static int mmc_load_legacy(struct spl_image_info *spl_image,
 	return 0;
 }
 
-static ulong h_spl_load_read(struct spl_load_info *load, ulong sector,
-			     ulong count, void *buf)
+static ulong h_spl_load_read(struct spl_load_info *load, ulong off,
+			     ulong size, void *buf)
 {
-	struct mmc *mmc = load->priv;
+	struct blk_desc *bd = load->priv;
+	lbaint_t sector = off >> bd->log2blksz;
+	lbaint_t count = size >> bd->log2blksz;
 
-	return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf);
+	return blk_dread(bd, sector, count, buf) << bd->log2blksz;
 }
 
 static __maybe_unused unsigned long spl_mmc_raw_uboot_offset(int part)
@@ -105,21 +107,23 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		debug("Found FIT\n");
-		load.priv = mmc;
+		load.priv = bd;
 		load.filename = NULL;
-		load.bl_len = mmc->read_bl_len;
+		load.bl_len = bd->blksz;
 		load.read = h_spl_load_read;
-		ret = spl_load_simple_fit(spl_image, &load, sector, header);
+		ret = spl_load_simple_fit(spl_image, &load,
+					  sector << bd->log2blksz, header);
 	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
 		   valid_container_hdr((void *)header)) {
 		struct spl_load_info load;
 
-		load.priv = mmc;
+		load.priv = bd;
 		load.filename = NULL;
-		load.bl_len = mmc->read_bl_len;
+		load.bl_len = bd->blksz;
 		load.read = h_spl_load_read;
 
-		ret = spl_load_imx_container(spl_image, &load, sector);
+		ret = spl_load_imx_container(spl_image, &load,
+					     sector << bd->log2blksz);
 	} else {
 		ret = mmc_load_legacy(spl_image, bootdev, mmc, sector, header);
 	}
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 9a5a5ffa04a..1fcc89fa660 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -49,14 +49,12 @@ static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
 	ulong sector;
 
 	sector = *(int *)load->priv;
-	offs *= load->bl_len;
-	size *= load->bl_len;
 	offs = sector + nand_spl_adjust_offset(sector, offs - sector);
 	err = nand_spl_load_image(offs, size, dst);
 	if (err)
 		return 0;
 
-	return size / load->bl_len;
+	return size;
 }
 
 static ulong spl_nand_legacy_read(struct spl_load_info *load, ulong offs,
@@ -95,7 +93,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		load.filename = NULL;
 		load.bl_len = bl_len;
 		load.read = spl_nand_fit_read;
-		return spl_load_simple_fit(spl_image, &load, offset / bl_len, header);
+		return spl_load_simple_fit(spl_image, &load, offset, header);
 	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
 		   valid_container_hdr((void *)header)) {
 		struct spl_load_info load;
@@ -104,7 +102,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		load.filename = NULL;
 		load.bl_len = bl_len;
 		load.read = spl_nand_fit_read;
-		return spl_load_imx_container(spl_image, &load, offset / bl_len);
+		return spl_load_imx_container(spl_image, &load, offset);
 	} else if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT) &&
 		   image_get_magic(header) == IH_MAGIC) {
 		struct spl_load_info load;
diff --git a/include/spl.h b/include/spl.h
index 951e136b9ea..ecfc50e0095 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -297,10 +297,10 @@ struct spl_load_info {
 	 * read() - Read from device
 	 *
 	 * @load: Information about the load state
-	 * @sector: Sector number to read from (each @load->bl_len bytes)
-	 * @count: Number of sectors to read
+	 * @offset: Offset to read from in bytes, in multiples of @load->bl_len
+	 * @count: Number of bytes to read, in multiples of @load->bl_len
 	 * @buf: Buffer to read into
-	 * @return number of sectors read, 0 on error
+	 * @return number of bytes read, 0 on error
 	 */
 	ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
 		      void *buf);
@@ -368,7 +368,8 @@ void *spl_load_simple_fit_fix_load(const void *fit);
  * spl_load_simple_fit() - Loads a fit image from a device.
  * @spl_image:	Image description to set up
  * @info:	Structure containing the information required to load data.
- * @sector:	Sector number where FIT image is located in the device
+ * @offset:	Offset where FIT image is located in the device. Must be aligned
+ *              to the device's bl_len.
  * @fdt:	Pointer to the copied FIT header.
  *
  * Reads the FIT image @sector in the device. Loads u-boot image to
@@ -376,7 +377,7 @@ void *spl_load_simple_fit_fix_load(const void *fit);
  * Returns 0 on success.
  */
 int spl_load_simple_fit(struct spl_image_info *spl_image,
-			struct spl_load_info *info, ulong sector, void *fdt);
+			struct spl_load_info *info, ulong offset, void *fdt);
 
 #define SPL_COPY_PAYLOAD_ONLY	1
 #define SPL_FIT_FOUND		2
@@ -402,13 +403,14 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
  * spl_load_imx_container() - Loads a imx container image from a device.
  * @spl_image:	Image description to set up
  * @info:	Structure containing the information required to load data.
- * @sector:	Sector number where container image is located in the device
+ * @sector:	Offset where container image is located in the device. Must be
+ *              aligned to the device block size.
  *
  * Reads the container image @sector in the device. Loads u-boot image to
  * specified load address.
  */
 int spl_load_imx_container(struct spl_image_info *spl_image,
-			   struct spl_load_info *info, ulong sector);
+			   struct spl_load_info *info, ulong offset);
 
 /* SPL common functions */
 void preloader_console_init(void);
diff --git a/test/image/spl_load_os.c b/test/image/spl_load_os.c
index 49edf152d78..794cfad4e70 100644
--- a/test/image/spl_load_os.c
+++ b/test/image/spl_load_os.c
@@ -16,14 +16,13 @@ struct text_ctx {
 	int fd;
 };
 
-static ulong read_fit_image(struct spl_load_info *load, ulong sector,
-			    ulong count, void *buf)
+static ulong read_fit_image(struct spl_load_info *load, ulong offset,
+			    ulong size, void *buf)
 {
 	struct text_ctx *text_ctx = load->priv;
-	off_t offset, ret;
+	off_t ret;
 	ssize_t res;
 
-	offset = sector * load->bl_len;
 	ret = os_lseek(text_ctx->fd, offset, OS_SEEK_SET);
 	if (ret != offset) {
 		printf("Failed to seek to %zx, got %zx (errno=%d)\n", offset,
@@ -31,14 +30,14 @@ static ulong read_fit_image(struct spl_load_info *load, ulong sector,
 		return 0;
 	}
 
-	res = os_read(text_ctx->fd, buf, count * load->bl_len);
+	res = os_read(text_ctx->fd, buf, size);
 	if (res == -1) {
 		printf("Failed to read %lx bytes, got %ld (errno=%d)\n",
-		       count * load->bl_len, res, errno);
+		       size, res, errno);
 		return 0;
 	}
 
-	return count;
+	return size;
 }
 
 static int spl_test_load(struct unit_test_state *uts)
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 09/25] spl: Remove filename from spl_load_info
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (7 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:23   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 10/25] spl: Only support bl_len when we have to Sean Anderson
                   ` (16 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

For filesystems, filename serves the same purpose as priv. However,
spl_load_fit_image also uses it to determine whether to use a DMA-aligned
buffer. This is beneficial for FAT, which uses a bounce-buffer if the
destination is not DMA-aligned. Remove this logic, and instead achieve it
by setting bl_len to ARCH_DMA_MINALIGN. With this done, we can remove
filename entirely.

One wrinkle bears mentioning: because filesystems are not block-based, we
may read less than the size passed to spl_load_info.read. This can happen
if the file size is not DMA-aligned. This is fine as long as we read the
amount we originally wanted to. Modify the conditions for callers of
spl_load_info.read to check against the original, unaligned size to avoid
failing spuriously.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 arch/arm/mach-sunxi/spl_spi_sunxi.c |  1 -
 common/spl/spl_blk_fs.c             | 10 ++++++----
 common/spl/spl_fat.c                |  6 +++---
 common/spl/spl_fit.c                | 23 +----------------------
 common/spl/spl_imx_container.c      |  8 +++++---
 common/spl/spl_mmc.c                |  2 --
 common/spl/spl_nand.c               |  3 ---
 common/spl/spl_semihosting.c        |  1 -
 common/spl/spl_spi.c                |  2 --
 common/spl/spl_ymodem.c             |  1 -
 include/spl.h                       |  2 --
 test/image/spl_load_os.c            |  1 -
 12 files changed, 15 insertions(+), 45 deletions(-)

diff --git a/arch/arm/mach-sunxi/spl_spi_sunxi.c b/arch/arm/mach-sunxi/spl_spi_sunxi.c
index 896aba69c32..5e7fba0c8e4 100644
--- a/arch/arm/mach-sunxi/spl_spi_sunxi.c
+++ b/arch/arm/mach-sunxi/spl_spi_sunxi.c
@@ -354,7 +354,6 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		debug("Found FIT image\n");
-		load.filename = NULL;
 		load.bl_len = 1;
 		load.read = spi_load_read;
 		ret = spl_load_simple_fit(spl_image, &load,
diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
index 144c8a65b5d..4975ce4d6ec 100644
--- a/common/spl/spl_blk_fs.c
+++ b/common/spl/spl_blk_fs.c
@@ -9,10 +9,12 @@
 #include <spl.h>
 #include <image.h>
 #include <fs.h>
+#include <asm/cache.h>
 #include <asm/io.h>
 
 struct blk_dev {
 	const char *ifname;
+	const char *filename;
 	char dev_part_str[8];
 };
 
@@ -30,11 +32,11 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
 		return ret;
 	}
 
-	ret = fs_read(load->filename, virt_to_phys(buf), file_offset, size,
+	ret = fs_read(dev->filename, virt_to_phys(buf), file_offset, size,
 		      &actlen);
 	if (ret < 0) {
 		printf("spl: error reading image %s. Err - %d\n",
-		       load->filename, ret);
+		       dev->filename, ret);
 		return ret;
 	}
 
@@ -85,9 +87,9 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		load.read = spl_fit_read;
-		load.bl_len = 1;
-		load.filename = (void *)filename;
+		load.bl_len = ARCH_DMA_MINALIGN;
 		load.priv = &dev;
+		dev.filename = filename;
 
 		return spl_load_simple_fit(spl_image, &load, 0, header);
 	}
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 6172e7bcd48..8a2c4e3af49 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -51,7 +51,7 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
 {
 	loff_t actread;
 	int ret;
-	char *filename = (char *)load->filename;
+	char *filename = load->priv;
 
 	ret = fat_read_file(filename, buf, file_offset, size, &actread);
 	if (ret)
@@ -97,8 +97,8 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		load.read = spl_fit_read;
-		load.bl_len = 1;
-		load.filename = (void *)filename;
+		load.bl_len = ARCH_DMA_MINALIGN;
+		load.priv = (void *)filename;
 
 		return spl_load_simple_fit(spl_image, &load, 0, header);
 	} else {
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index ce7ef0efd0d..0df4e6d1484 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -14,7 +14,6 @@
 #include <mapmem.h>
 #include <spl.h>
 #include <sysinfo.h>
-#include <asm/cache.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
 #include <linux/libfdt.h>
@@ -172,28 +171,11 @@ static int spl_fit_get_image_node(const struct spl_fit_info *ctx,
 
 static int get_aligned_image_offset(struct spl_load_info *info, int offset)
 {
-	/*
-	 * If it is a FS read, get the first address before offset which is
-	 * aligned to ARCH_DMA_MINALIGN. If it is raw read return the
-	 * block number to which offset belongs.
-	 */
-	if (info->filename)
-		return offset & ~(ARCH_DMA_MINALIGN - 1);
-
 	return ALIGN_DOWN(offset, info->bl_len);
 }
 
 static int get_aligned_image_overhead(struct spl_load_info *info, int offset)
 {
-	/*
-	 * If it is a FS read, get the difference between the offset and
-	 * the first address before offset which is aligned to
-	 * ARCH_DMA_MINALIGN. If it is raw read return the offset within the
-	 * block.
-	 */
-	if (info->filename)
-		return offset & (ARCH_DMA_MINALIGN - 1);
-
 	return offset & (info->bl_len - 1);
 }
 
@@ -202,9 +184,6 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size,
 {
 	data_size = data_size + get_aligned_image_overhead(info, offset);
 
-	if (info->filename)
-		return data_size;
-
 	return ALIGN(data_size, info->bl_len);
 }
 
@@ -295,7 +274,7 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,
 		if (info->read(info,
 			       fit_offset +
 			       get_aligned_image_offset(info, offset), size,
-			       src_ptr) != size)
+			       src_ptr) < length)
 			return -EIO;
 
 		debug("External data: dst=%p, offset=%x, size=%lx\n",
diff --git a/common/spl/spl_imx_container.c b/common/spl/spl_imx_container.c
index ad89a99fb23..7cd674f835f 100644
--- a/common/spl/spl_imx_container.c
+++ b/common/spl/spl_imx_container.c
@@ -45,7 +45,8 @@ static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image,
 	      container, offset, size);
 	if (info->read(info, offset, size,
 		       map_sysmem(images[image_index].dst - overhead,
-				  images[image_index].size)) != size) {
+				  images[image_index].size)) <
+	    images[image_index].size) {
 		printf("%s wrong\n", __func__);
 		return NULL;
 	}
@@ -77,7 +78,8 @@ static int read_auth_container(struct spl_image_info *spl_image,
 
 	debug("%s: container: %p offset: %lu size: %u\n", __func__,
 	      container, offset, size);
-	if (info->read(info, offset, size, container) != size) {
+	if (info->read(info, offset, size, container) <
+	    CONTAINER_HDR_ALIGNMENT) {
 		ret = -EIO;
 		goto end;
 	}
@@ -107,7 +109,7 @@ static int read_auth_container(struct spl_image_info *spl_image,
 
 		debug("%s: container: %p offset: %lu size: %u\n",
 		      __func__, container, offset, size);
-		if (info->read(info, offset, size, container) != size) {
+		if (info->read(info, offset, size, container) < length) {
 			ret = -EIO;
 			goto end;
 		}
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 9f41ea648ce..8c4ffe743d5 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -108,7 +108,6 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		load.priv = bd;
-		load.filename = NULL;
 		load.bl_len = bd->blksz;
 		load.read = h_spl_load_read;
 		ret = spl_load_simple_fit(spl_image, &load,
@@ -118,7 +117,6 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		load.priv = bd;
-		load.filename = NULL;
 		load.bl_len = bd->blksz;
 		load.read = h_spl_load_read;
 
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 1fcc89fa660..45d7c5f6cfb 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -90,7 +90,6 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		load.priv = &offset;
-		load.filename = NULL;
 		load.bl_len = bl_len;
 		load.read = spl_nand_fit_read;
 		return spl_load_simple_fit(spl_image, &load, offset, header);
@@ -99,7 +98,6 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		load.priv = &offset;
-		load.filename = NULL;
 		load.bl_len = bl_len;
 		load.read = spl_nand_fit_read;
 		return spl_load_imx_container(spl_image, &load, offset);
@@ -108,7 +106,6 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		debug("Found legacy image\n");
-		load.filename = NULL;
 		load.bl_len = IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1;
 		load.read = spl_nand_legacy_read;
 
diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c
index 8f11c29913f..24a3d9fd1c9 100644
--- a/common/spl/spl_semihosting.c
+++ b/common/spl/spl_semihosting.c
@@ -69,7 +69,6 @@ static int spl_smh_load_image(struct spl_image_info *spl_image,
 		debug("Found FIT\n");
 		load.read = smh_fit_read;
 		load.bl_len = 1;
-		load.filename = NULL;
 		load.priv = &fd;
 
 		ret = spl_load_simple_fit(spl_image, &load, 0, header);
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index af7a28e7c25..373caea322a 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -152,7 +152,6 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 
 			debug("Found FIT\n");
 			load.priv = flash;
-			load.filename = NULL;
 			load.bl_len = 1;
 			load.read = spl_spi_fit_read;
 			err = spl_load_simple_fit(spl_image, &load,
@@ -163,7 +162,6 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 			struct spl_load_info load;
 
 			load.priv = flash;
-			load.filename = NULL;
 			load.bl_len = 1;
 			load.read = spl_spi_fit_read;
 
diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c
index 8616cb3e915..3f92b9b0036 100644
--- a/common/spl/spl_ymodem.c
+++ b/common/spl/spl_ymodem.c
@@ -135,7 +135,6 @@ int spl_ymodem_load_image(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		load.priv = (void *)&info;
-		load.filename = NULL;
 		load.bl_len = 1;
 		info.buf = buf;
 		info.image_read = BUF_SIZE;
diff --git a/include/spl.h b/include/spl.h
index ecfc50e0095..1021bab3f30 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -287,12 +287,10 @@ static inline void *spl_image_fdt_addr(struct spl_image_info *info)
  *
  * @priv: Private data for the device
  * @bl_len: Block length for reading in bytes
- * @filename: Name of the fit image file.
  * @read: Function to call to read from the device
  */
 struct spl_load_info {
 	void *priv;
-	const char *filename;
 	/**
 	 * read() - Read from device
 	 *
diff --git a/test/image/spl_load_os.c b/test/image/spl_load_os.c
index 794cfad4e70..f46df907c63 100644
--- a/test/image/spl_load_os.c
+++ b/test/image/spl_load_os.c
@@ -57,7 +57,6 @@ static int spl_test_load(struct unit_test_state *uts)
 	ret = sandbox_find_next_phase(fname, sizeof(fname), true);
 	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));
 
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 10/25] spl: Only support bl_len when we have to
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (8 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 09/25] spl: Remove filename from spl_load_info Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:23   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 11/25] spl: nand: Remove spl_nand_legacy_read Sean Anderson
                   ` (15 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

Aligning addresses and sizes causes overhead which is unnecessary when we
are not loading from block devices. Remove bl_len when it is not needed.

For example, on iot2050 we save 144 bytes with this patch (once the rest of
this series is applied):

add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-144 (-144)
Function                                     old     new   delta
spl_load_simple_fit                          920     904     -16
load_simple_fit                              496     444     -52
spl_spi_load_image                           384     308     -76
Total: Before=87431, After=87287, chg -0.16%

We use panic() instead of BUILD_BUG_ON in spl_set_bl_len because we still
need to be able to compile it for things like mmc_load_image_raw_sector,
even if that function will not be used.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 arch/arm/mach-imx/spl_imx_romapi.c  |  8 ++++----
 arch/arm/mach-sunxi/spl_spi_sunxi.c |  2 +-
 common/spl/Kconfig                  | 14 +++++++++++++-
 common/spl/spl_blk_fs.c             |  2 +-
 common/spl/spl_fat.c                |  2 +-
 common/spl/spl_fit.c                |  6 +++---
 common/spl/spl_imx_container.c      | 10 +++++-----
 common/spl/spl_legacy.c             |  4 ++--
 common/spl/spl_mmc.c                |  4 ++--
 common/spl/spl_nand.c               |  6 +++---
 common/spl/spl_net.c                |  2 +-
 common/spl/spl_nor.c                |  8 ++++----
 common/spl/spl_ram.c                |  2 +-
 common/spl/spl_semihosting.c        |  2 +-
 common/spl/spl_spi.c                |  4 ++--
 common/spl/spl_ymodem.c             |  2 +-
 drivers/usb/gadget/f_sdp.c          |  4 ++--
 include/spl.h                       | 25 +++++++++++++++++++++++++
 test/image/Kconfig                  |  1 +
 test/image/spl_load.c               |  9 ++++-----
 test/image/spl_load_os.c            |  2 +-
 21 files changed, 78 insertions(+), 41 deletions(-)

diff --git a/arch/arm/mach-imx/spl_imx_romapi.c b/arch/arm/mach-imx/spl_imx_romapi.c
index d7f6cb4b5ba..9f0968cdf71 100644
--- a/arch/arm/mach-imx/spl_imx_romapi.c
+++ b/arch/arm/mach-imx/spl_imx_romapi.c
@@ -101,7 +101,7 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		memset(&load, 0, sizeof(load));
-		load.bl_len = pagesize;
+		spl_set_bl_len(&load, pagesize);
 		load.read = spl_romapi_read_seekable;
 		return spl_load_simple_fit(spl_image, &load, offset, header);
 	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
@@ -109,7 +109,7 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		memset(&load, 0, sizeof(load));
-		load.bl_len = pagesize;
+		spl_set_bl_len(&load, pagesize);
 		load.read = spl_romapi_read_seekable;
 
 		ret = spl_load_imx_container(spl_image, &load, offset);
@@ -334,7 +334,7 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image,
 		ss.pagesize = pagesize;
 
 		memset(&load, 0, sizeof(load));
-		load.bl_len = 1;
+		spl_set_bl_len(&load, 1);
 		load.read = spl_romapi_read_stream;
 		load.priv = &ss;
 
@@ -358,7 +358,7 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image,
 		printf("ROM download failure %d\n", imagesize);
 
 	memset(&load, 0, sizeof(load));
-	load.bl_len = 1;
+	spl_set_bl_len(&load, 1);
 	load.read = spl_ram_load_read;
 
 	if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER))
diff --git a/arch/arm/mach-sunxi/spl_spi_sunxi.c b/arch/arm/mach-sunxi/spl_spi_sunxi.c
index 5e7fba0c8e4..267cb0b1aba 100644
--- a/arch/arm/mach-sunxi/spl_spi_sunxi.c
+++ b/arch/arm/mach-sunxi/spl_spi_sunxi.c
@@ -354,7 +354,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		debug("Found FIT image\n");
-		load.bl_len = 1;
+		spl_set_bl_len(&load, 1);
 		load.read = spi_load_read;
 		ret = spl_load_simple_fit(spl_image, &load,
 					  load_offset, header);
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index e929f1bbae1..0bc57d5fedb 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -280,8 +280,15 @@ config SPL_BOARD_INIT
 	  spl_board_init() from board_init_r(). This function should be
 	  provided by the board.
 
+config SPL_LOAD_BLOCK
+	bool
+	help
+	  Support loading images from block devices. This adds a bl_len member
+	  to struct spl_load_info.
+
 config SPL_BOOTROM_SUPPORT
 	bool "Support returning to the BOOTROM"
+	select SPL_LOAD_BLOCK if MACH_IMX
 	help
 	  Some platforms (e.g. the Rockchip RK3368) provide support in their
 	  ROM for loading the next boot-stage after performing basic setup
@@ -482,6 +489,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
 		     ARCH_AT91 || ARCH_ZYNQ || ARCH_KEYSTONE || OMAP34XX || \
 		     OMAP44XX || OMAP54XX || AM33XX || AM43XX || \
 		     TARGET_SIFIVE_UNLEASHED || TARGET_SIFIVE_UNMATCHED
+	select SPL_LOAD_BLOCK if SPL_MMC
 	help
 	  Use sector number for specifying U-Boot location on MMC/SD in
 	  raw mode.
@@ -518,6 +526,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET
 
 config SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
 	bool "MMC Raw mode: by partition"
+	select SPL_LOAD_BLOCK if SPL_MMC
 	help
 	  Use a partition for loading U-Boot when using MMC/SD in raw mode.
 
@@ -678,6 +687,7 @@ config SPL_FS_SQUASHFS
 config SPL_FS_FAT
 	bool "Support FAT filesystems"
 	select FS_FAT
+	select SPL_LOAD_BLOCK
 	help
 	  Enable support for FAT and VFAT filesystems with SPL. This
 	  permits U-Boot (or Linux in Falcon mode) to be loaded from a FAT
@@ -877,6 +887,7 @@ config SPL_MUSB_NEW
 
 config SPL_NAND_SUPPORT
 	bool "Support NAND flash"
+	select SPL_LOAD_BLOCK
 	help
 	  Enable support for NAND (Negative AND) flash in SPL. NAND flash
 	  can be used to allow SPL to load U-Boot from supported devices.
@@ -1102,6 +1113,7 @@ config SYS_OS_BASE
 config SPL_FALCON_BOOT_MMCSD
 	bool "Enable Falcon boot from MMC or SD media"
 	depends on SPL_OS_BOOT && SPL_MMC
+	select SPL_LOAD_BLOCK
 	help
 	  Select this if the Falcon mode OS image mode is on MMC or SD media.
 
@@ -1260,9 +1272,9 @@ config SPL_SATA_RAW_U_BOOT_SECTOR
 config SPL_NVME
 	bool "NVM Express device support"
 	depends on BLK
-	select HAVE_BLOCK_DEVICE
 	select FS_LOADER
 	select SPL_BLK_FS
+	select SPL_LOAD_BLOCK
 	help
 	  This option enables support for NVM Express devices.
 	  It supports basic functions of NVMe (read/write).
diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
index 4975ce4d6ec..53b8e1b11b4 100644
--- a/common/spl/spl_blk_fs.c
+++ b/common/spl/spl_blk_fs.c
@@ -87,7 +87,7 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		load.read = spl_fit_read;
-		load.bl_len = ARCH_DMA_MINALIGN;
+		spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
 		load.priv = &dev;
 		dev.filename = filename;
 
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 8a2c4e3af49..a0c34eba48f 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -97,7 +97,7 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		load.read = spl_fit_read;
-		load.bl_len = ARCH_DMA_MINALIGN;
+		spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
 		load.priv = (void *)filename;
 
 		return spl_load_simple_fit(spl_image, &load, 0, header);
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 0df4e6d1484..872df0c0fe8 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -171,12 +171,12 @@ static int spl_fit_get_image_node(const struct spl_fit_info *ctx,
 
 static int get_aligned_image_offset(struct spl_load_info *info, int offset)
 {
-	return ALIGN_DOWN(offset, info->bl_len);
+	return ALIGN_DOWN(offset, spl_get_bl_len(info));
 }
 
 static int get_aligned_image_overhead(struct spl_load_info *info, int offset)
 {
-	return offset & (info->bl_len - 1);
+	return offset & (spl_get_bl_len(info) - 1);
 }
 
 static int get_aligned_image_size(struct spl_load_info *info, int data_size,
@@ -184,7 +184,7 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size,
 {
 	data_size = data_size + get_aligned_image_overhead(info, offset);
 
-	return ALIGN(data_size, info->bl_len);
+	return ALIGN(data_size, spl_get_bl_len(info));
 }
 
 /**
diff --git a/common/spl/spl_imx_container.c b/common/spl/spl_imx_container.c
index 7cd674f835f..b4ea9241d68 100644
--- a/common/spl/spl_imx_container.c
+++ b/common/spl/spl_imx_container.c
@@ -32,13 +32,13 @@ static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image,
 	images = (struct boot_img_t *)((u8 *)container +
 				       sizeof(struct container_hdr));
 
-	if (!IS_ALIGNED(images[image_index].offset, info->bl_len)) {
+	if (!IS_ALIGNED(images[image_index].offset, spl_get_bl_len(info))) {
 		printf("%s: image%d offset not aligned to %u\n",
-		       __func__, image_index, info->bl_len);
+		       __func__, image_index, spl_get_bl_len(info));
 		return NULL;
 	}
 
-	size = ALIGN(images[image_index].size, info->bl_len);
+	size = ALIGN(images[image_index].size, spl_get_bl_len(info));
 	offset = images[image_index].offset + container_offset;
 
 	debug("%s: container: %p offset: %lu size: %lu\n", __func__,
@@ -66,7 +66,7 @@ static int read_auth_container(struct spl_image_info *spl_image,
 	u16 length;
 	int i, size, ret = 0;
 
-	size = ALIGN(CONTAINER_HDR_ALIGNMENT, info->bl_len);
+	size = ALIGN(CONTAINER_HDR_ALIGNMENT, spl_get_bl_len(info));
 
 	/*
 	 * It will not override the ATF code, so safe to use it here,
@@ -100,7 +100,7 @@ static int read_auth_container(struct spl_image_info *spl_image,
 	debug("Container length %u\n", length);
 
 	if (length > CONTAINER_HDR_ALIGNMENT) {
-		size = ALIGN(length, info->bl_len);
+		size = ALIGN(length, spl_get_bl_len(info));
 
 		free(container);
 		container = malloc(size);
diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
index 9189576b774..75d9d822337 100644
--- a/common/spl/spl_legacy.c
+++ b/common/spl/spl_legacy.c
@@ -139,9 +139,9 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
 		lzma_len = LZMA_LEN;
 
 		/* dataptr points to compressed payload  */
-		dataptr = ALIGN_DOWN(sizeof(*hdr), load->bl_len);
+		dataptr = ALIGN_DOWN(sizeof(*hdr), spl_get_bl_len(load));
 		overhead = sizeof(*hdr) - dataptr;
-		size = ALIGN(spl_image->size + overhead, load->bl_len);
+		size = ALIGN(spl_image->size + overhead, spl_get_bl_len(load));
 		dataptr += offset;
 
 		debug("LZMA: Decompressing %08lx to %08lx\n",
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 8c4ffe743d5..91272c03d3f 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -108,7 +108,7 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		load.priv = bd;
-		load.bl_len = bd->blksz;
+		spl_set_bl_len(&load, bd->blksz);
 		load.read = h_spl_load_read;
 		ret = spl_load_simple_fit(spl_image, &load,
 					  sector << bd->log2blksz, header);
@@ -117,7 +117,7 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		load.priv = bd;
-		load.bl_len = bd->blksz;
+		spl_set_bl_len(&load, bd->blksz);
 		load.read = h_spl_load_read;
 
 		ret = spl_load_imx_container(spl_image, &load,
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 45d7c5f6cfb..281211b7f24 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -90,7 +90,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		load.priv = &offset;
-		load.bl_len = bl_len;
+		spl_set_bl_len(&load, bl_len);
 		load.read = spl_nand_fit_read;
 		return spl_load_simple_fit(spl_image, &load, offset, header);
 	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
@@ -98,7 +98,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		load.priv = &offset;
-		load.bl_len = bl_len;
+		spl_set_bl_len(&load, bl_len);
 		load.read = spl_nand_fit_read;
 		return spl_load_imx_container(spl_image, &load, offset);
 	} else if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT) &&
@@ -106,7 +106,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		debug("Found legacy image\n");
-		load.bl_len = IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1;
+		spl_set_bl_len(&load, IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1);
 		load.read = spl_nand_legacy_read;
 
 		return spl_load_legacy_img(spl_image, bootdev, &load, offset, header);
diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c
index f01d4df8bc6..47994e28165 100644
--- a/common/spl/spl_net.c
+++ b/common/spl/spl_net.c
@@ -54,7 +54,7 @@ static int spl_net_load_image(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		debug("Found FIT\n");
-		load.bl_len = 1;
+		spl_set_bl_len(&load, 1);
 		load.read = spl_net_load_read;
 		rv = spl_load_simple_fit(spl_image, &load, 0, header);
 	} else {
diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c
index 236b0718283..aad230db4d3 100644
--- a/common/spl/spl_nor.c
+++ b/common/spl/spl_nor.c
@@ -49,7 +49,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 			int ret;
 
 			debug("Found FIT\n");
-			load.bl_len = 1;
+			spl_set_bl_len(&load, 1);
 			load.read = spl_nor_load_read;
 
 			ret = spl_load_simple_fit(spl_image, &load,
@@ -97,7 +97,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 #ifdef CONFIG_SPL_LOAD_FIT
 	if (image_get_magic(header) == FDT_MAGIC) {
 		debug("Found FIT format U-Boot\n");
-		load.bl_len = 1;
+		spl_set_bl_len(&load, 1);
 		load.read = spl_nor_load_read;
 		return spl_load_simple_fit(spl_image, &load,
 					   spl_nor_get_uboot_base(),
@@ -106,7 +106,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 #endif
 	if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
 	    valid_container_hdr((void *)header)) {
-		load.bl_len = 1;
+		spl_set_bl_len(&load, 1);
 		load.read = spl_nor_load_read;
 		return spl_load_imx_container(spl_image, &load,
 					      spl_nor_get_uboot_base());
@@ -114,7 +114,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 
 	/* Legacy image handling */
 	if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT)) {
-		load.bl_len = 1;
+		spl_set_bl_len(&load, 1);
 		load.read = spl_nor_load_read;
 		return spl_load_legacy_img(spl_image, bootdev, &load,
 					   spl_nor_get_uboot_base(),
diff --git a/common/spl/spl_ram.c b/common/spl/spl_ram.c
index 4158ed1c32d..8aeda237be1 100644
--- a/common/spl/spl_ram.c
+++ b/common/spl/spl_ram.c
@@ -70,7 +70,7 @@ static int spl_ram_load_image(struct spl_image_info *spl_image,
 		struct spl_load_info load;
 
 		debug("Found FIT\n");
-		load.bl_len = 1;
+		spl_set_bl_len(&load, 1);
 		load.read = spl_ram_load_read;
 		ret = spl_load_simple_fit(spl_image, &load, 0, header);
 	} else {
diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c
index 24a3d9fd1c9..9b0610b8fc8 100644
--- a/common/spl/spl_semihosting.c
+++ b/common/spl/spl_semihosting.c
@@ -68,7 +68,7 @@ static int spl_smh_load_image(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		load.read = smh_fit_read;
-		load.bl_len = 1;
+		spl_set_bl_len(&load, 1);
 		load.priv = &fd;
 
 		ret = spl_load_simple_fit(spl_image, &load, 0, header);
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index 373caea322a..3e08ac7c1a2 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -152,7 +152,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 
 			debug("Found FIT\n");
 			load.priv = flash;
-			load.bl_len = 1;
+			spl_set_bl_len(&load, 1);
 			load.read = spl_spi_fit_read;
 			err = spl_load_simple_fit(spl_image, &load,
 						  payload_offs,
@@ -162,7 +162,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 			struct spl_load_info load;
 
 			load.priv = flash;
-			load.bl_len = 1;
+			spl_set_bl_len(&load, 1);
 			load.read = spl_spi_fit_read;
 
 			err = spl_load_imx_container(spl_image, &load,
diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c
index 3f92b9b0036..1faaa2c938d 100644
--- a/common/spl/spl_ymodem.c
+++ b/common/spl/spl_ymodem.c
@@ -135,7 +135,7 @@ int spl_ymodem_load_image(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		load.priv = (void *)&info;
-		load.bl_len = 1;
+		spl_set_bl_len(&load, 1);
 		info.buf = buf;
 		info.image_read = BUF_SIZE;
 		load.read = ymodem_read_fit;
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index 1b16b7eb452..ca2760c00d0 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -845,7 +845,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
 
 				debug("Found FIT\n");
 				load.priv = header;
-				load.bl_len = 1;
+				spl_set_bl_len(&load, 1);
 				load.read = sdp_load_read;
 				spl_load_simple_fit(spl_image, &load, 0,
 						    header);
@@ -858,7 +858,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
 				struct spl_load_info load;
 
 				load.priv = header;
-				load.bl_len = 1;
+				spl_set_bl_len(&load, 1);
 				load.read = sdp_load_read;
 				spl_load_imx_container(spl_image, &load, 0);
 				return SDP_EXIT;
diff --git a/include/spl.h b/include/spl.h
index 1021bab3f30..4c421664a9d 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -302,9 +302,34 @@ struct spl_load_info {
 	 */
 	ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
 		      void *buf);
+#if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK)
 	int bl_len;
 };
 
+static inline int spl_get_bl_len(struct spl_load_info *info)
+{
+	return info->bl_len;
+}
+
+static inline void spl_set_bl_len(struct spl_load_info *info, int bl_len)
+{
+	info->bl_len = bl_len;
+}
+#else
+};
+
+static inline int spl_get_bl_len(struct spl_load_info *info)
+{
+	return 1;
+}
+
+static inline void spl_set_bl_len(struct spl_load_info *info, int bl_len)
+{
+	if (bl_len != 1)
+		panic("CONFIG_SPL_LOAD_BLOCK not enabled");
+}
+#endif
+
 /*
  * We need to know the position of U-Boot in memory so we can jump to it. We
  * allow any U-Boot binary to be used (u-boot.bin, u-boot-nodtb.bin,
diff --git a/test/image/Kconfig b/test/image/Kconfig
index 6f0bb81f835..45b6e8c52e6 100644
--- a/test/image/Kconfig
+++ b/test/image/Kconfig
@@ -52,6 +52,7 @@ config SPL_UT_LOAD_SPI
 config SPL_UT_LOAD_OS
 	bool "Test loading from the host OS"
 	depends on SANDBOX && SPL_LOAD_FIT
+	select SPL_LOAD_BLOCK
 	default y
 	help
 	  Smoke test to ensure that loading U-boot works in sandbox.
diff --git a/test/image/spl_load.c b/test/image/spl_load.c
index ab4c14d6491..35ceed67756 100644
--- a/test/image/spl_load.c
+++ b/test/image/spl_load.c
@@ -342,12 +342,11 @@ static int spl_test_image(struct unit_test_state *uts, const char *test_name,
 		if (check_image_info(uts, &info_write, &info_read))
 			return CMD_RET_FAILURE;
 	} else {
-		struct spl_load_info load = {
-			.bl_len = 1,
-			.priv = img,
-			.read = spl_test_read,
-		};
+		struct spl_load_info load;
 
+		spl_set_bl_len(&load, 1);
+		load.priv = img;
+		load.read = spl_test_read;
 		if (type == IMX8)
 			ut_assertok(spl_load_imx_container(&info_read, &load,
 							   0));
diff --git a/test/image/spl_load_os.c b/test/image/spl_load_os.c
index f46df907c63..26228a8a4a9 100644
--- a/test/image/spl_load_os.c
+++ b/test/image/spl_load_os.c
@@ -51,7 +51,7 @@ static int spl_test_load(struct unit_test_state *uts)
 	int fd;
 
 	memset(&load, '\0', sizeof(load));
-	load.bl_len = 512;
+	spl_set_bl_len(&load, 512);
 	load.read = read_fit_image;
 
 	ret = sandbox_find_next_phase(fname, sizeof(fname), true);
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 11/25] spl: nand: Remove spl_nand_legacy_read
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (9 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 10/25] spl: Only support bl_len when we have to Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:23   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 12/25] spl: legacy: Split off LZMA decompression into its own function Sean Anderson
                   ` (14 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson, Dario Binacchi, Michael Trimarchi

Now that spl_nand_fit_read works in units of bytes, it can be combined with
spl_nand_legacy_read. Rename the resulting function spl_nand_read, since it
is no longer FIT-specific.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 common/spl/spl_nand.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 281211b7f24..91fa7674f17 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -42,29 +42,22 @@ static int spl_nand_load_image(struct spl_image_info *spl_image,
 }
 #else
 
-static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
-			       ulong size, void *dst)
+__weak u32 nand_spl_adjust_offset(u32 sector, u32 offs)
+{
+	return offs;
+}
+
+static ulong spl_nand_read(struct spl_load_info *load, ulong offs, ulong size,
+			   void *dst)
 {
 	int err;
 	ulong sector;
 
-	sector = *(int *)load->priv;
-	offs = sector + nand_spl_adjust_offset(sector, offs - sector);
-	err = nand_spl_load_image(offs, size, dst);
-	if (err)
-		return 0;
-
-	return size;
-}
-
-static ulong spl_nand_legacy_read(struct spl_load_info *load, ulong offs,
-				  ulong size, void *dst)
-{
-	int err;
-
 	debug("%s: offs %lx, size %lx, dst %p\n",
 	      __func__, offs, size, dst);
 
+	sector = *(int *)load->priv;
+	offs = sector + nand_spl_adjust_offset(sector, offs - sector);
 	err = nand_spl_load_image(offs, size, dst);
 	if (err)
 		return 0;
@@ -91,7 +84,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		debug("Found FIT\n");
 		load.priv = &offset;
 		spl_set_bl_len(&load, bl_len);
-		load.read = spl_nand_fit_read;
+		load.read = spl_nand_read;
 		return spl_load_simple_fit(spl_image, &load, offset, header);
 	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
 		   valid_container_hdr((void *)header)) {
@@ -99,16 +92,16 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 
 		load.priv = &offset;
 		spl_set_bl_len(&load, bl_len);
-		load.read = spl_nand_fit_read;
+		load.read = spl_nand_read;
 		return spl_load_imx_container(spl_image, &load, offset);
 	} else if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT) &&
 		   image_get_magic(header) == IH_MAGIC) {
 		struct spl_load_info load;
 
 		debug("Found legacy image\n");
+		load.priv = &offset;
 		spl_set_bl_len(&load, IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1);
-		load.read = spl_nand_legacy_read;
-
+		load.read = spl_nand_read;
 		return spl_load_legacy_img(spl_image, bootdev, &load, offset, header);
 	} else {
 		err = spl_parse_image_header(spl_image, bootdev, header);
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 12/25] spl: legacy: Split off LZMA decompression into its own function
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (10 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 11/25] spl: nand: Remove spl_nand_legacy_read Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:23   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 13/25] test: spl: Support testing LEGACY_LZMA filesystem images Sean Anderson
                   ` (13 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

To allow for easier reuse of this functionality, split it off into its
own function.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 common/spl/spl_legacy.c | 73 ++++++++++++++++++++++-------------------
 include/spl.h           | 13 ++++++++
 2 files changed, 52 insertions(+), 34 deletions(-)

diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
index 75d9d822337..a561939b4f0 100644
--- a/common/spl/spl_legacy.c
+++ b/common/spl/spl_legacy.c
@@ -82,6 +82,43 @@ int spl_parse_legacy_header(struct spl_image_info *spl_image,
 	return 0;
 }
 
+int spl_load_legacy_lzma(struct spl_image_info *spl_image,
+			 struct spl_load_info *load, ulong offset)
+{
+	SizeT lzma_len = LZMA_LEN;
+	void *src;
+	ulong dataptr, overhead, size;
+	int ret;
+
+	/* dataptr points to compressed payload  */
+	dataptr = ALIGN_DOWN(sizeof(struct legacy_img_hdr),
+			     spl_get_bl_len(load));
+	overhead = sizeof(struct legacy_img_hdr) - dataptr;
+	size = ALIGN(spl_image->size + overhead, spl_get_bl_len(load));
+	dataptr += offset;
+
+	debug("LZMA: Decompressing %08lx to %08lx\n",
+	      dataptr, spl_image->load_addr);
+	src = malloc(size);
+	if (!src) {
+		printf("Unable to allocate %d bytes for LZMA\n",
+		       spl_image->size);
+		return -ENOMEM;
+	}
+
+	load->read(load, dataptr, size, src);
+	ret = lzmaBuffToBuffDecompress(map_sysmem(spl_image->load_addr,
+						  spl_image->size), &lzma_len,
+				       src + overhead, spl_image->size);
+	if (ret) {
+		printf("LZMA decompression error: %d\n", ret);
+		return ret;
+	}
+
+	spl_image->size = lzma_len;
+	return 0;
+}
+
 /*
  * This function is added explicitly to avoid code size increase, when
  * no compression method is enabled. The compiler will optimize the
@@ -101,8 +138,6 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
 			struct spl_load_info *load, ulong offset,
 			struct legacy_img_hdr *hdr)
 {
-	__maybe_unused SizeT lzma_len;
-	__maybe_unused void *src;
 	ulong dataptr;
 	int ret;
 
@@ -133,39 +168,9 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
 			   map_sysmem(spl_image->load_addr, spl_image->size));
 		break;
 
-	case IH_COMP_LZMA: {
-		ulong overhead, size;
+	case IH_COMP_LZMA:
+		return spl_load_legacy_lzma(spl_image, load, offset);
 
-		lzma_len = LZMA_LEN;
-
-		/* dataptr points to compressed payload  */
-		dataptr = ALIGN_DOWN(sizeof(*hdr), spl_get_bl_len(load));
-		overhead = sizeof(*hdr) - dataptr;
-		size = ALIGN(spl_image->size + overhead, spl_get_bl_len(load));
-		dataptr += offset;
-
-		debug("LZMA: Decompressing %08lx to %08lx\n",
-		      dataptr, spl_image->load_addr);
-		src = malloc(size);
-		if (!src) {
-			printf("Unable to allocate %d bytes for LZMA\n",
-			       spl_image->size);
-			return -ENOMEM;
-		}
-
-		load->read(load, dataptr, size, src);
-		ret = lzmaBuffToBuffDecompress(map_sysmem(spl_image->load_addr,
-							  spl_image->size),
-					       &lzma_len, src + overhead,
-					       spl_image->size);
-		if (ret) {
-			printf("LZMA decompression error: %d\n", ret);
-			return ret;
-		}
-
-		spl_image->size = lzma_len;
-		break;
-	}
 	default:
 		debug("Compression method %s is not supported\n",
 		      genimg_get_comp_short_name(image_get_comp(hdr)));
diff --git a/include/spl.h b/include/spl.h
index 4c421664a9d..d8d2cf43eeb 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -405,6 +405,19 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 #define SPL_COPY_PAYLOAD_ONLY	1
 #define SPL_FIT_FOUND		2
 
+/**
+ * spl_load_legacy_lzma() - Load an LZMA-compressed legacy image
+ * @spl_image:	Image description (already set up)
+ * @load:	Structure containing the information required to load data.
+ * @offset:	Pointer to image
+ *
+ * Load/decompress an LZMA-compressed legacy image from the device.
+ *
+ * Return: 0 on success, or a negative error on failure
+ */
+int spl_load_legacy_lzma(struct spl_image_info *spl_image,
+			 struct spl_load_info *load, ulong offset);
+
 /**
  * spl_load_legacy_img() - Loads a legacy image from a device.
  * @spl_image:	Image description to set up
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 13/25] test: spl: Support testing LEGACY_LZMA filesystem images
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (11 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 12/25] spl: legacy: Split off LZMA decompression into its own function Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:23   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 14/25] spl: Add generic spl_load function Sean Anderson
                   ` (12 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

These will soon be supported, so we need to be able to test it. Export the
lzma data and generally use the same process in spl_test_mmc_fs as
do_spl_test_load.  If we end up needing this in third place in the future,
it would probably be good to refactor things out.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 include/test/spl.h       |  4 ++++
 test/image/spl_load.c    |  4 +++-
 test/image/spl_load_fs.c | 23 ++++++++++++++++++-----
 3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/include/test/spl.h b/include/test/spl.h
index c1f64658502..a2a5f33e328 100644
--- a/include/test/spl.h
+++ b/include/test/spl.h
@@ -81,6 +81,10 @@ 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);
 
+/* Some compressed data and it size */
+extern const char lzma_compressed[];
+extern const size_t lzma_compressed_size;
+
 /**
  * typedef write_image_t - Callback for writing an image
  * @uts: Current unit test state
diff --git a/test/image/spl_load.c b/test/image/spl_load.c
index 35ceed67756..e1036eff28c 100644
--- a/test/image/spl_load.c
+++ b/test/image/spl_load.c
@@ -374,7 +374,7 @@ 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
  */
-static const char lzma_compressed[] = {
+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,
@@ -610,6 +610,8 @@ static const char lzma_compressed[] = {
 	0x1e, 0xff, 0xff, 0x80, 0x8e, 0x00, 0x00
 };
 
+const size_t lzma_compressed_size = sizeof(lzma_compressed);
+
 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))
diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
index 297ab08a820..59d0244d44b 100644
--- a/test/image/spl_load_fs.c
+++ b/test/image/spl_load_fs.c
@@ -320,10 +320,11 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, const char *test_name,
 	const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
 	struct blk_desc *dev_desc;
 	size_t fs_size, fs_data, img_size, img_data,
-	       data_size = SPL_TEST_DATA_SIZE;
+	       plain_size = SPL_TEST_DATA_SIZE;
 	struct spl_image_info info_write = {
 		.name = test_name,
-		.size = data_size,
+		.size = type == LEGACY_LZMA ? lzma_compressed_size :
+					      plain_size,
 	}, info_read = { };
 	struct disk_partition part = {
 		.start = 1,
@@ -335,7 +336,7 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, const char *test_name,
 		.boot_device = loader->boot_device,
 	};
 	void *fs;
-	char *data;
+	char *data, *plain;
 
 	img_size = create_image(NULL, type, &info_write, &img_data);
 	ut_assert(img_size);
@@ -345,7 +346,15 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, const char *test_name,
 	ut_assertnonnull(fs);
 
 	data = fs + fs_data + img_data;
-	generate_data(data, data_size, test_name);
+	if (type == LEGACY_LZMA) {
+		plain = malloc(plain_size);
+		ut_assertnonnull(plain);
+		generate_data(plain, plain_size, "lzma");
+		memcpy(data, lzma_compressed, lzma_compressed_size);
+	} else {
+		plain = data;
+		generate_data(plain, plain_size, test_name);
+	}
 	ut_asserteq(img_size, create_image(fs + fs_data, type, &info_write,
 					   NULL));
 	ut_asserteq(fs_size, create_fs(fs, img_size, filename, NULL));
@@ -366,8 +375,12 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, const char *test_name,
 		ut_assertok(loader->load_image(&info_read, &bootdev));
 	if (check_image_info(uts, &info_write, &info_read))
 		return CMD_RET_FAILURE;
-	ut_asserteq_mem(data, phys_to_virt(info_write.load_addr), data_size);
+	if (type == LEGACY_LZMA)
+		ut_asserteq(plain_size, info_read.size);
+	ut_asserteq_mem(plain, phys_to_virt(info_write.load_addr), plain_size);
 
+	if (type == LEGACY_LZMA)
+		free(plain);
 	free(fs);
 	return 0;
 }
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 14/25] spl: Add generic spl_load function
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (12 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 13/25] test: spl: Support testing LEGACY_LZMA filesystem images Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:23   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 15/25] spl: Convert ext to use spl_load Sean Anderson
                   ` (11 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

Implementers of SPL_LOAD_IMAGE_METHOD have to correctly determine what
type of image is being loaded and then call the appropriate image load
function correctly. This is tricky, because some image load functions
expect the whole image to already be loaded (CONFIG_SPL_LOAD_FIT_FULL),
some will load the image automatically using spl_load_info.read()
(CONFIG_SPL_LOAD_FIT/CONFIG_SPL_LOAD_IMX_CONTAINER), and some just parse
the header and expect the caller to do the actual loading afterwards
(legacy/raw images). Load methods often only support a subset of the
above methods, meaning that not all image types can be used with all
load methods. Further, the code to invoke these functions is
duplicated between different load functions.

To address this problem, this commit introduces a "spl_load" function.
It aims to handle image detection and correct invocation of each of the
parse/load functions.

Although this function generally results in a size reduction with
several users, it tends to bloat boards with only a single user.
This is generally because programmers open-coding the contents of this
function can make optimizations based on the specific loader. For
example, NOR flash is memory-mapped, so it never bothers calling
load->read. The compiler can't really make these optimizations across
translation units. LTO solves this, but it is only available on some
arches. To address this, perform "pseudo-LTO" by inlining spl_load when
there are one or fewer users. At the moment, there are no users, so
define SPL_LOAD_USERS to be 0.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- Use pseudo-LTO for spl_load
- Align reads to bl_len

Changes in v5:
- Load the header in spl_load as well
- Don't bother trying to DMA-align the buffer, since we can't really fix
  it.

Changes in v4:
- Fix format specifiers in debug prints
- Reword/fix some of the doc comments for spl_load

Changes in v3:
- Fix using ffs instead of fls
- Fix using not initializing bl_len when info->filename was NULL

Changes in v2:
- Use reverse-xmas-tree style for locals in spl_simple_read. This is not
  complete, since overhead depends on bl_mask.

 common/spl/spl.c   |  10 ++++
 include/spl_load.h | 135 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 145 insertions(+)
 create mode 100644 include/spl_load.h

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 7ce38ce46d4..3ce5bfeec8b 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -19,6 +19,7 @@
 #include <mapmem.h>
 #include <serial.h>
 #include <spl.h>
+#include <spl_load.h>
 #include <system-constants.h>
 #include <asm/global_data.h>
 #include <asm-generic/gpio.h>
@@ -352,6 +353,15 @@ int spl_parse_image_header(struct spl_image_info *spl_image,
 	return 0;
 }
 
+#if SPL_LOAD_USERS > 1
+int spl_load(struct spl_image_info *spl_image,
+	     const struct spl_boot_device *bootdev, struct spl_load_info *info,
+	     size_t size, size_t offset)
+{
+	return _spl_load(spl_image, bootdev, info, size, offset);
+}
+#endif
+
 __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
 {
 	typedef void __noreturn (*image_entry_noargs_t)(void);
diff --git a/include/spl_load.h b/include/spl_load.h
new file mode 100644
index 00000000000..406f8b577b2
--- /dev/null
+++ b/include/spl_load.h
@@ -0,0 +1,135 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) Sean Anderson <seanga2@gmail.com>
+ */
+#ifndef	_SPL_LOAD_H_
+#define	_SPL_LOAD_H_
+
+#include <image.h>
+#include <imx_container.h>
+#include <mapmem.h>
+#include <spl.h>
+
+static inline int _spl_load(struct spl_image_info *spl_image,
+			    const struct spl_boot_device *bootdev,
+			    struct spl_load_info *info, size_t size,
+			    size_t offset)
+{
+	struct legacy_img_hdr *header =
+		spl_get_load_buffer(-sizeof(*header), sizeof(*header));
+	ulong base_offset, image_offset, overhead;
+	int read, ret;
+
+	read = info->read(info, offset, ALIGN(sizeof(*header),
+					      spl_get_bl_len(info)), header);
+	if (read < sizeof(*header))
+		return -EIO;
+
+	if (image_get_magic(header) == FDT_MAGIC) {
+		if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)) {
+			void *buf;
+
+			/*
+			 * In order to support verifying images in the FIT, we
+			 * need to load the whole FIT into memory. Try and
+			 * guess how much we need to load by using the total
+			 * size. This will fail for FITs with external data,
+			 * but there's not much we can do about that.
+			 */
+			if (!size)
+				size = round_up(fdt_totalsize(header), 4);
+			buf = map_sysmem(CONFIG_SYS_LOAD_ADDR, size);
+			read = info->read(info, offset,
+					  ALIGN(size, spl_get_bl_len(info)),
+					  buf);
+			if (read < size)
+				return -EIO;
+
+			return spl_parse_image_header(spl_image, bootdev, buf);
+		}
+
+		if (IS_ENABLED(CONFIG_SPL_LOAD_FIT))
+			return spl_load_simple_fit(spl_image, info, offset,
+						   header);
+	}
+
+	if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+	    valid_container_hdr((void *)header))
+		return spl_load_imx_container(spl_image, info, offset);
+
+	if (IS_ENABLED(CONFIG_SPL_LZMA) &&
+	    image_get_magic(header) == IH_MAGIC &&
+	    image_get_comp(header) == IH_COMP_LZMA) {
+		spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
+		ret = spl_parse_image_header(spl_image, bootdev, header);
+		if (ret)
+			return ret;
+
+		return spl_load_legacy_lzma(spl_image, info, offset);
+	}
+
+	ret = spl_parse_image_header(spl_image, bootdev, header);
+	if (ret)
+		return ret;
+
+	base_offset = spl_image->offset;
+	/* Only NOR sets this flag. */
+	if (IS_ENABLED(CONFIG_SPL_NOR_SUPPORT) &&
+	    spl_image->flags & SPL_COPY_PAYLOAD_ONLY)
+		base_offset += sizeof(*header);
+	image_offset = ALIGN_DOWN(base_offset, spl_get_bl_len(info));
+	overhead = base_offset - image_offset;
+	size = ALIGN(spl_image->size + overhead, spl_get_bl_len(info));
+
+	read = info->read(info, offset + image_offset, size,
+			  map_sysmem(spl_image->load_addr - overhead, size));
+	return read < spl_image->size ? -EIO : 0;
+}
+
+/*
+ * Although spl_load results in size reduction for callers, this is generally
+ * not enough to counteract the bloat if there is only one caller. The core
+ * problem is that the compiler can't optimize across translation units. The
+ * general solution to this is CONFIG_LTO, but that is not available on all
+ * architectures. Perform a pseudo-LTO just for this function by declaring it
+ * inline if there is one caller, and extern otherwise.
+ */
+#define SPL_LOAD_USERS \
+	0
+
+#if SPL_LOAD_USERS > 1
+/**
+ * spl_load() - Parse a header and load the image
+ * @spl_image: Image data which will be filled in by this function
+ * @bootdev: The device to load from
+ * @info: Describes how to load additional information from @bootdev. At the
+ *        minimum, read() and bl_len must be populated.
+ * @size: The size of the image, in bytes, if it is known in advance. Some boot
+ *        devices (such as filesystems) know how big an image is before parsing
+ *        the header. If 0, then the size will be determined from the header.
+ * @offset: The offset from the start of @bootdev, in bytes. This should have
+ *          the offset @header was loaded from. It will be added to any offsets
+ *          passed to @info->read().
+ *
+ * This function determines the image type (FIT, legacy, i.MX, raw, etc), calls
+ * the appropriate parsing function, determines the load address, and the loads
+ * the image from storage. It is designed to replace ad-hoc image loading which
+ * may not support all image types (especially when config options are
+ * involved).
+ *
+ * Return: 0 on success, or a negative error on failure
+ */
+int spl_load(struct spl_image_info *spl_image,
+	     const struct spl_boot_device *bootdev, struct spl_load_info *info,
+	     size_t size, size_t offset);
+#else
+static inline int spl_load(struct spl_image_info *spl_image,
+			   const struct spl_boot_device *bootdev,
+			   struct spl_load_info *info, size_t size,
+			   size_t offset)
+{
+	return _spl_load(spl_image, bootdev, info, size, offset);
+}
+#endif
+
+#endif /* _SPL_LOAD_H_ */
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 15/25] spl: Convert ext to use spl_load
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (13 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 14/25] spl: Add generic spl_load function Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:24   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 16/25] spl: Convert fat to spl_load Sean Anderson
                   ` (10 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

This converts the ext load method to use spl_load. As a consequence, it
also adds support for FIT and IMX images.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- Explicitly initialize load_info members

Changes in v5:
- Rework to load header in spl_load

 common/spl/spl_ext.c     | 36 ++++++++++++++++++------------------
 include/spl_load.h       |  1 +
 test/image/spl_load_fs.c |  9 ++++++---
 3 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c
index af836ca15b8..d280b69c387 100644
--- a/common/spl/spl_ext.c
+++ b/common/spl/spl_ext.c
@@ -2,25 +2,35 @@
 
 #include <common.h>
 #include <env.h>
-#include <mapmem.h>
 #include <part.h>
 #include <spl.h>
+#include <spl_load.h>
 #include <asm/u-boot.h>
 #include <ext4fs.h>
 #include <errno.h>
 #include <image.h>
 
+static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
+			  ulong size, void *buf)
+{
+	int ret;
+	loff_t actlen;
+
+	ret = ext4fs_read(buf, file_offset, size, &actlen);
+	if (ret)
+		return ret;
+	return actlen;
+}
+
 int spl_load_image_ext(struct spl_image_info *spl_image,
 		       struct spl_boot_device *bootdev,
 		       struct blk_desc *block_dev, int partition,
 		       const char *filename)
 {
 	s32 err;
-	struct legacy_img_hdr *header;
-	loff_t filelen, actlen;
+	loff_t filelen;
 	struct disk_partition part_info = {};
-
-	header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
+	struct spl_load_info load;
 
 	if (part_get_info(block_dev, partition, &part_info)) {
 		printf("spl: no partition table found\n");
@@ -42,20 +52,10 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
 		puts("spl: ext4fs_open failed\n");
 		goto end;
 	}
-	err = ext4fs_read((char *)header, 0, sizeof(struct legacy_img_hdr), &actlen);
-	if (err < 0) {
-		puts("spl: ext4fs_read failed\n");
-		goto end;
-	}
 
-	err = spl_parse_image_header(spl_image, bootdev, header);
-	if (err < 0) {
-		puts("spl: ext: failed to parse image header\n");
-		goto end;
-	}
-
-	err = ext4fs_read(map_sysmem(spl_image->load_addr, filelen), 0, filelen,
-			  &actlen);
+	spl_set_bl_len(&load, 1);
+	load.read = spl_fit_read;
+	err = spl_load(spl_image, bootdev, &load, filelen, 0);
 
 end:
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
diff --git a/include/spl_load.h b/include/spl_load.h
index 406f8b577b2..65aa6bb4493 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -95,6 +95,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
  * inline if there is one caller, and extern otherwise.
  */
 #define SPL_LOAD_USERS \
+	IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
 	0
 
 #if SPL_LOAD_USERS > 1
diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
index 59d0244d44b..01559e98c4f 100644
--- a/test/image/spl_load_fs.c
+++ b/test/image/spl_load_fs.c
@@ -422,20 +422,23 @@ static int spl_test_mmc(struct unit_test_state *uts, const char *test_name,
 	spl_mmc_clear_cache();
 	spl_fat_force_reregister();
 
-	if (type == LEGACY &&
-	    spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
+	if (spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
 		return CMD_RET_FAILURE;
 
-	if (type != IMX8 &&
+	if (type != IMX8 && type != LEGACY_LZMA &&
 	    spl_test_mmc_fs(uts, test_name, type, create_fat, false))
 		return CMD_RET_FAILURE;
 
+	if (type == LEGACY_LZMA)
+		return 0;
+
 	return do_spl_test_load(uts, test_name, type,
 				SPL_LOAD_IMAGE_GET(0, BOOT_DEVICE_MMC1,
 						   spl_mmc_load_image),
 				spl_test_mmc_write_image);
 }
 SPL_IMG_TEST(spl_test_mmc, LEGACY, DM_FLAGS);
+SPL_IMG_TEST(spl_test_mmc, LEGACY_LZMA, DM_FLAGS);
 SPL_IMG_TEST(spl_test_mmc, IMX8, DM_FLAGS);
 SPL_IMG_TEST(spl_test_mmc, FIT_EXTERNAL, DM_FLAGS);
 SPL_IMG_TEST(spl_test_mmc, FIT_INTERNAL, DM_FLAGS);
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 16/25] spl: Convert fat to spl_load
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (14 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 15/25] spl: Convert ext to use spl_load Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:24   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 17/25] spl: Convert mmc " Sean Anderson
                   ` (9 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

This converts the fat loader to use spl_load. Some platforms are very
tight on space, so we take care to only include the code we really need.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

(no changes since v5)

Changes in v5:
- Rework to load header in spl_load

Changes in v3:
- Fix failing on success

 common/spl/spl_fat.c     | 56 +++++++++++++---------------------------
 include/spl_load.h       |  1 +
 test/image/spl_load_fs.c |  3 +--
 3 files changed, 20 insertions(+), 40 deletions(-)

diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index a0c34eba48f..569f2b32928 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -11,8 +11,8 @@
 #include <common.h>
 #include <env.h>
 #include <log.h>
-#include <mapmem.h>
 #include <spl.h>
+#include <spl_load.h>
 #include <asm/u-boot.h>
 #include <fat.h>
 #include <errno.h>
@@ -66,58 +66,38 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
 		       const char *filename)
 {
 	int err;
-	struct legacy_img_hdr *header;
+	loff_t size;
+	struct spl_load_info load;
 
 	err = spl_register_fat_device(block_dev, partition);
 	if (err)
 		goto end;
 
-	header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
-
-	err = file_fat_read(filename, header, sizeof(struct legacy_img_hdr));
-	if (err <= 0)
-		goto end;
-
-	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
-	    image_get_magic(header) == FDT_MAGIC) {
-		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,
-					     map_sysmem(CONFIG_SYS_LOAD_ADDR,
-							err));
-		if (err == -EAGAIN)
-			return err;
-		if (err == 0)
-			err = 1;
-	} else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-	    image_get_magic(header) == FDT_MAGIC) {
-		struct spl_load_info load;
-
-		debug("Found FIT\n");
-		load.read = spl_fit_read;
-		spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
-		load.priv = (void *)filename;
-
-		return spl_load_simple_fit(spl_image, &load, 0, header);
-	} else {
-		err = spl_parse_image_header(spl_image, bootdev, header);
+	/*
+	 * Avoid pulling in this function for other image types since we are
+	 * very short on space on some boards.
+	 */
+	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)) {
+		err = fat_size(filename, &size);
 		if (err)
 			goto end;
-
-		err = file_fat_read(filename, map_sysmem(spl_image->load_addr,
-							 spl_image->size), 0);
+	} else {
+		size = 0;
 	}
 
+	load.read = spl_fit_read;
+	spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
+	load.priv = (void *)filename;
+	err = spl_load(spl_image, bootdev, &load, size, 0);
+
 end:
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-	if (err <= 0)
+	if (err < 0)
 		printf("%s: error reading image %s, err - %d\n",
 		       __func__, filename, err);
 #endif
 
-	return (err <= 0);
+	return err;
 }
 
 #if CONFIG_IS_ENABLED(OS_BOOT)
diff --git a/include/spl_load.h b/include/spl_load.h
index 65aa6bb4493..5e0460d956d 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -96,6 +96,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
  */
 #define SPL_LOAD_USERS \
 	IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
+	IS_ENABLED(CONFIG_SPL_FS_FAT) + \
 	0
 
 #if SPL_LOAD_USERS > 1
diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
index 01559e98c4f..333df2dfb53 100644
--- a/test/image/spl_load_fs.c
+++ b/test/image/spl_load_fs.c
@@ -425,8 +425,7 @@ static int spl_test_mmc(struct unit_test_state *uts, const char *test_name,
 	if (spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
 		return CMD_RET_FAILURE;
 
-	if (type != IMX8 && type != LEGACY_LZMA &&
-	    spl_test_mmc_fs(uts, test_name, type, create_fat, false))
+	if (spl_test_mmc_fs(uts, test_name, type, create_fat, false))
 		return CMD_RET_FAILURE;
 
 	if (type == LEGACY_LZMA)
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 17/25] spl: Convert mmc to spl_load
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (15 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 16/25] spl: Convert fat to spl_load Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:24   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 18/25] spl: Convert nand " Sean Anderson
                   ` (8 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson, Jaehoon Chung, Peng Fan

This converts the mmc loader to spl_load. Legacy images are handled by
spl_load (via spl_parse_image_header), so mmc_load_legacy can be
omitted. To accurately determine whether mmc_load_image_raw_sector is used
(which might not be the case if SYS_MMCSD_FS_BOOT is enabled), we introduce
a helper config SYS_MMCSD_RAW_MODE. This ensures we can inline spl_load
correctly when a board only boots from filesystems. We still need to check
for SPL_MMC, since some boards enable configure raw mode even without MMC
support.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- Add SYS_MMCSD_RAW_MODE to help determine whether SPL_MMC loads
  anything directly.
- Explicitly initialize load_info members

Changes in v5:
- Rework to load header in spl_load

 common/spl/Kconfig       |  8 ++++
 common/spl/spl_mmc.c     | 89 ++++------------------------------------
 include/spl_load.h       |  1 +
 test/image/spl_load_fs.c |  3 --
 4 files changed, 16 insertions(+), 85 deletions(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 0bc57d5fedb..b93526904eb 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -481,6 +481,11 @@ config SPL_DISPLAY_PRINT
 	  banner ("U-Boot SPL ..."). This function should be provided by
 	  the board.
 
+config SPL_SYS_MMCSD_RAW_MODE
+	bool
+	help
+	  Support booting from an MMC without a filesystem.
+
 config SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
 	bool "MMC raw mode: by sector"
 	default y if ARCH_SUNXI || ARCH_DAVINCI || ARCH_UNIPHIER || \
@@ -490,6 +495,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
 		     OMAP44XX || OMAP54XX || AM33XX || AM43XX || \
 		     TARGET_SIFIVE_UNLEASHED || TARGET_SIFIVE_UNMATCHED
 	select SPL_LOAD_BLOCK if SPL_MMC
+	select SPL_SYS_MMCSD_RAW_MODE if SPL_MMC
 	help
 	  Use sector number for specifying U-Boot location on MMC/SD in
 	  raw mode.
@@ -527,6 +533,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET
 config SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
 	bool "MMC Raw mode: by partition"
 	select SPL_LOAD_BLOCK if SPL_MMC
+	select SPL_SYS_MMCSD_RAW_MODE if SPL_MMC
 	help
 	  Use a partition for loading U-Boot when using MMC/SD in raw mode.
 
@@ -1114,6 +1121,7 @@ config SPL_FALCON_BOOT_MMCSD
 	bool "Enable Falcon boot from MMC or SD media"
 	depends on SPL_OS_BOOT && SPL_MMC
 	select SPL_LOAD_BLOCK
+	select SPL_SYS_MMCSD_RAW_MODE
 	help
 	  Select this if the Falcon mode OS image mode is on MMC or SD media.
 
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 91272c03d3f..3d032bb27ce 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -8,9 +8,9 @@
 #include <common.h>
 #include <dm.h>
 #include <log.h>
-#include <mapmem.h>
 #include <part.h>
 #include <spl.h>
+#include <spl_load.h>
 #include <linux/compiler.h>
 #include <errno.h>
 #include <asm/u-boot.h>
@@ -19,49 +19,6 @@
 #include <image.h>
 #include <imx_container.h>
 
-static int mmc_load_legacy(struct spl_image_info *spl_image,
-			   struct spl_boot_device *bootdev,
-			   struct mmc *mmc,
-			   ulong sector, struct legacy_img_hdr *header)
-{
-	u32 image_offset_sectors;
-	u32 image_size_sectors;
-	unsigned long count;
-	u32 image_offset;
-	int ret;
-
-	ret = spl_parse_image_header(spl_image, bootdev, header);
-	if (ret)
-		return ret;
-
-	/* convert offset to sectors - round down */
-	image_offset_sectors = spl_image->offset / mmc->read_bl_len;
-	/* calculate remaining offset */
-	image_offset = spl_image->offset % mmc->read_bl_len;
-
-	/* convert size to sectors - round up */
-	image_size_sectors = (spl_image->size + mmc->read_bl_len - 1) /
-			     mmc->read_bl_len;
-
-	/* Read the header too to avoid extra memcpy */
-	count = blk_dread(mmc_get_blk_desc(mmc),
-			  sector + image_offset_sectors,
-			  image_size_sectors,
-			  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)
-		return -EIO;
-
-	if (image_offset)
-		memmove((void *)(ulong)spl_image->load_addr,
-			(void *)(ulong)spl_image->load_addr + image_offset,
-			spl_image->size);
-
-	return 0;
-}
-
 static ulong h_spl_load_read(struct spl_load_info *load, ulong off,
 			     ulong size, void *buf)
 {
@@ -87,46 +44,14 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
 			      struct spl_boot_device *bootdev,
 			      struct mmc *mmc, unsigned long sector)
 {
-	unsigned long count;
-	struct legacy_img_hdr *header;
+	int ret;
 	struct blk_desc *bd = mmc_get_blk_desc(mmc);
-	int ret = 0;
+	struct spl_load_info load;
 
-	header = spl_get_load_buffer(-sizeof(*header), bd->blksz);
-
-	/* read image header to find the image size & load address */
-	count = blk_dread(bd, sector, 1, header);
-	debug("hdr read sector %lx, count=%lu\n", sector, count);
-	if (count == 0) {
-		ret = -EIO;
-		goto end;
-	}
-
-	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-	    image_get_magic(header) == FDT_MAGIC) {
-		struct spl_load_info load;
-
-		debug("Found FIT\n");
-		load.priv = bd;
-		spl_set_bl_len(&load, bd->blksz);
-		load.read = h_spl_load_read;
-		ret = spl_load_simple_fit(spl_image, &load,
-					  sector << bd->log2blksz, header);
-	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
-		   valid_container_hdr((void *)header)) {
-		struct spl_load_info load;
-
-		load.priv = bd;
-		spl_set_bl_len(&load, bd->blksz);
-		load.read = h_spl_load_read;
-
-		ret = spl_load_imx_container(spl_image, &load,
-					     sector << bd->log2blksz);
-	} else {
-		ret = mmc_load_legacy(spl_image, bootdev, mmc, sector, header);
-	}
-
-end:
+	load.priv = bd;
+	spl_set_bl_len(&load, bd->blksz);
+	load.read = h_spl_load_read;
+	ret = spl_load(spl_image, bootdev, &load, 0, sector << bd->log2blksz);
 	if (ret) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
 		puts("mmc_load_image_raw_sector: mmc block read error\n");
diff --git a/include/spl_load.h b/include/spl_load.h
index 5e0460d956d..d55a47ae7d7 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -97,6 +97,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
 #define SPL_LOAD_USERS \
 	IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
 	IS_ENABLED(CONFIG_SPL_FS_FAT) + \
+	IS_ENABLED(CONFIG_SPL_SYS_MMCSD_RAW_MODE) + \
 	0
 
 #if SPL_LOAD_USERS > 1
diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
index 333df2dfb53..67c19da95e7 100644
--- a/test/image/spl_load_fs.c
+++ b/test/image/spl_load_fs.c
@@ -428,9 +428,6 @@ static int spl_test_mmc(struct unit_test_state *uts, const char *test_name,
 	if (spl_test_mmc_fs(uts, test_name, type, create_fat, false))
 		return CMD_RET_FAILURE;
 
-	if (type == LEGACY_LZMA)
-		return 0;
-
 	return do_spl_test_load(uts, test_name, type,
 				SPL_LOAD_IMAGE_GET(0, BOOT_DEVICE_MMC1,
 						   spl_mmc_load_image),
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 18/25] spl: Convert nand to spl_load
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (16 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 17/25] spl: Convert mmc " Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:24   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 19/25] spl: Convert net " Sean Anderson
                   ` (7 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson, Dario Binacchi, Michael Trimarchi

This converts the nand load method to use spl_load. nand_page_size may not
be valid until after nand_spl_load_image is called (see e.g. fsl_ifc_spl),
so we set bl_len in spl_nand_read. Since spl_load reads the header for us,
we can remove that argument from spl_nand_load_element.

There are two possible regressions which could result from this commit.
First, we ask for a negative address from spl_get_load_buffer. That is,
instead of

	header = spl_get_load_buffer(0, sizeof(*header));

we do

	header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));

this could cause a problem if spl_get_load_buffer does not return valid
memory for negative offsets. Second, we now set bl_len for legacy images.
This can cause memory up to a bl_len - 1 before the image load address to
be written, which might not have been the case before. If this turns out to
be a problem, we can add an option for a bounce buffer.

We can't load FITs with external data with SPL_LOAD_FIT_FULL, so disable the
test in that case. No boards enable SPL_NAND_SUPPORT and SPL_LOAD_FIT_FULL, so
this is not a regression.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 common/spl/spl_nand.c      | 70 +++++++++-----------------------------
 include/spl_load.h         |  1 +
 test/image/spl_load_nand.c |  2 ++
 3 files changed, 19 insertions(+), 54 deletions(-)

diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 91fa7674f17..3b0a1524238 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -10,6 +10,7 @@
 #include <imx_container.h>
 #include <log.h>
 #include <spl.h>
+#include <spl_load.h>
 #include <asm/io.h>
 #include <mapmem.h>
 #include <nand.h>
@@ -59,6 +60,7 @@ static ulong spl_nand_read(struct spl_load_info *load, ulong offs, ulong size,
 	sector = *(int *)load->priv;
 	offs = sector + nand_spl_adjust_offset(sector, offs - sector);
 	err = nand_spl_load_image(offs, size, dst);
+	spl_set_bl_len(load, nand_page_size());
 	if (err)
 		return 0;
 
@@ -66,60 +68,20 @@ static ulong spl_nand_read(struct spl_load_info *load, ulong offs, ulong size,
 }
 
 static int spl_nand_load_element(struct spl_image_info *spl_image,
-				 struct spl_boot_device *bootdev,
-				 int offset, struct legacy_img_hdr *header)
+				 struct spl_boot_device *bootdev, int offset)
 {
-	int bl_len;
-	int err;
+	struct spl_load_info load;
 
-	err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
-	if (err)
-		return err;
-
-	bl_len = nand_page_size();
-	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-	    image_get_magic(header) == FDT_MAGIC) {
-		struct spl_load_info load;
-
-		debug("Found FIT\n");
-		load.priv = &offset;
-		spl_set_bl_len(&load, bl_len);
-		load.read = spl_nand_read;
-		return spl_load_simple_fit(spl_image, &load, offset, header);
-	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
-		   valid_container_hdr((void *)header)) {
-		struct spl_load_info load;
-
-		load.priv = &offset;
-		spl_set_bl_len(&load, bl_len);
-		load.read = spl_nand_read;
-		return spl_load_imx_container(spl_image, &load, offset);
-	} else if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT) &&
-		   image_get_magic(header) == IH_MAGIC) {
-		struct spl_load_info load;
-
-		debug("Found legacy image\n");
-		load.priv = &offset;
-		spl_set_bl_len(&load, IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1);
-		load.read = spl_nand_read;
-		return spl_load_legacy_img(spl_image, bootdev, &load, offset, header);
-	} else {
-		err = spl_parse_image_header(spl_image, bootdev, header);
-		if (err)
-			return err;
-		return nand_spl_load_image(offset, spl_image->size,
-					   map_sysmem(spl_image->load_addr,
-						      spl_image->size));
-	}
+	load.priv = &offset;
+	spl_set_bl_len(&load, 1);
+	load.read = spl_nand_read;
+	return spl_load(spl_image, bootdev, &load, 0, offset);
 }
 
 static int spl_nand_load_image(struct spl_image_info *spl_image,
 			       struct spl_boot_device *bootdev)
 {
 	int err;
-	struct legacy_img_hdr *header;
-	int *src __attribute__((unused));
-	int *dst __attribute__((unused));
 
 #ifdef CONFIG_SPL_NAND_SOFTECC
 	debug("spl: nand - using sw ecc\n");
@@ -128,10 +90,12 @@ static int spl_nand_load_image(struct spl_image_info *spl_image,
 #endif
 	nand_init();
 
-	header = spl_get_load_buffer(0, sizeof(*header));
-
 #if CONFIG_IS_ENABLED(OS_BOOT)
 	if (!spl_start_uboot()) {
+		int *src, *dst;
+		struct legacy_img_hdr *header =
+			spl_get_load_buffer(0, sizeof(*header));
+
 		/*
 		 * load parameter image
 		 * load to temp position since nand_spl_load_image reads
@@ -174,20 +138,18 @@ static int spl_nand_load_image(struct spl_image_info *spl_image,
 	}
 #endif
 #ifdef CONFIG_NAND_ENV_DST
-	spl_nand_load_element(spl_image, bootdev, CONFIG_ENV_OFFSET, header);
+	spl_nand_load_element(spl_image, bootdev, CONFIG_ENV_OFFSET);
 #ifdef CONFIG_ENV_OFFSET_REDUND
-	spl_nand_load_element(spl_image, bootdev, CONFIG_ENV_OFFSET_REDUND, header);
+	spl_nand_load_element(spl_image, bootdev, CONFIG_ENV_OFFSET_REDUND);
 #endif
 #endif
 	/* Load u-boot */
-	err = spl_nand_load_element(spl_image, bootdev, spl_nand_get_uboot_raw_page(),
-				    header);
+	err = spl_nand_load_element(spl_image, bootdev, spl_nand_get_uboot_raw_page());
 #ifdef CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
 #if CONFIG_SYS_NAND_U_BOOT_OFFS != CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
 	if (err)
 		err = spl_nand_load_element(spl_image, bootdev,
-					    CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND,
-					    header);
+					    CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND);
 #endif
 #endif
 	nand_deselect();
diff --git a/include/spl_load.h b/include/spl_load.h
index d55a47ae7d7..38294a21ad0 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -98,6 +98,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
 	IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
 	IS_ENABLED(CONFIG_SPL_FS_FAT) + \
 	IS_ENABLED(CONFIG_SPL_SYS_MMCSD_RAW_MODE) + \
+	(IS_ENABLED(CONFIG_SPL_NAND_SUPPORT) && !IS_ENABLED(CONFIG_SPL_UBI)) + \
 	0
 
 #if SPL_LOAD_USERS > 1
diff --git a/test/image/spl_load_nand.c b/test/image/spl_load_nand.c
index 30179de98e7..ec242207948 100644
--- a/test/image/spl_load_nand.c
+++ b/test/image/spl_load_nand.c
@@ -51,4 +51,6 @@ SPL_IMG_TEST(spl_test_nand, LEGACY, DM_FLAGS);
 SPL_IMG_TEST(spl_test_nand, LEGACY_LZMA, DM_FLAGS);
 SPL_IMG_TEST(spl_test_nand, IMX8, DM_FLAGS);
 SPL_IMG_TEST(spl_test_nand, FIT_INTERNAL, DM_FLAGS);
+#if !IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)
 SPL_IMG_TEST(spl_test_nand, FIT_EXTERNAL, DM_FLAGS);
+#endif
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 19/25] spl: Convert net to spl_load
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (17 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 18/25] spl: Convert nand " Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:24   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 20/25] spl: Convert nor " Sean Anderson
                   ` (6 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson, Joe Hershberger, Ramon Fried

This converts the net load method to use spl_load. As a result, it also
adds support for LOAD_FIT_FULL and IMX images.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- Explicitly initialize load_info members

Changes in v5:
- Rework to load header in spl_load

 common/spl/spl_net.c      | 29 +++++------------------------
 include/spl_load.h        |  1 +
 test/image/spl_load_net.c |  2 ++
 3 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c
index 47994e28165..898f9df705a 100644
--- a/common/spl/spl_net.c
+++ b/common/spl/spl_net.c
@@ -11,8 +11,8 @@
 #include <errno.h>
 #include <image.h>
 #include <log.h>
-#include <mapmem.h>
 #include <spl.h>
+#include <spl_load.h>
 #include <net.h>
 #include <linux/libfdt.h>
 
@@ -29,8 +29,7 @@ static ulong spl_net_load_read(struct spl_load_info *load, ulong sector,
 static int spl_net_load_image(struct spl_image_info *spl_image,
 			      struct spl_boot_device *bootdev)
 {
-	struct legacy_img_hdr *header = map_sysmem(image_load_addr,
-						   sizeof(*header));
+	struct spl_load_info load;
 	int rv;
 
 	env_init();
@@ -49,27 +48,9 @@ static int spl_net_load_image(struct spl_image_info *spl_image,
 		return rv;
 	}
 
-	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-	    image_get_magic(header) == FDT_MAGIC) {
-		struct spl_load_info load;
-
-		debug("Found FIT\n");
-		spl_set_bl_len(&load, 1);
-		load.read = spl_net_load_read;
-		rv = spl_load_simple_fit(spl_image, &load, 0, header);
-	} else {
-		debug("Legacy image\n");
-
-		rv = spl_parse_image_header(spl_image, bootdev, header);
-		if (rv)
-			return rv;
-
-		memcpy(map_sysmem(spl_image->load_addr, spl_image->size),
-		       map_sysmem(image_load_addr, spl_image->size),
-		       spl_image->size);
-	}
-
-	return rv;
+	spl_set_bl_len(&load, 1);
+	load.read = spl_net_load_read;
+	return spl_load(spl_image, bootdev, &load, 0, 0);
 }
 #endif
 
diff --git a/include/spl_load.h b/include/spl_load.h
index 38294a21ad0..4777f84ac6b 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -99,6 +99,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
 	IS_ENABLED(CONFIG_SPL_FS_FAT) + \
 	IS_ENABLED(CONFIG_SPL_SYS_MMCSD_RAW_MODE) + \
 	(IS_ENABLED(CONFIG_SPL_NAND_SUPPORT) && !IS_ENABLED(CONFIG_SPL_UBI)) + \
+	IS_ENABLED(CONFIG_SPL_NET) + \
 	0
 
 #if SPL_LOAD_USERS > 1
diff --git a/test/image/spl_load_net.c b/test/image/spl_load_net.c
index f570cef163f..9d067a7a592 100644
--- a/test/image/spl_load_net.c
+++ b/test/image/spl_load_net.c
@@ -248,5 +248,7 @@ static int spl_test_net(struct unit_test_state *uts, const char *test_name,
 	return ret;
 }
 SPL_IMG_TEST(spl_test_net, LEGACY, DM_FLAGS);
+SPL_IMG_TEST(spl_test_net, LEGACY_LZMA, DM_FLAGS);
+SPL_IMG_TEST(spl_test_net, IMX8, DM_FLAGS);
 SPL_IMG_TEST(spl_test_net, FIT_INTERNAL, DM_FLAGS);
 SPL_IMG_TEST(spl_test_net, FIT_EXTERNAL, DM_FLAGS);
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 20/25] spl: Convert nor to spl_load
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (18 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 19/25] spl: Convert net " Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:24   ` Simon Glass
  2023-11-06  2:25 ` [PATCH v6 21/25] spl: Convert NVMe " Sean Anderson
                   ` (5 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

This converts the nor load method to use spl_load. As a result it also
adds support for LOAD_FIT_FULL. Since this is the last caller of
spl_load_legacy_img, it has been removed.

We can't load FITs with external data with SPL_LOAD_FIT_FULL, so disable the
test in that case. No boards enable SPL_NOR_SUPPORT and SPL_LOAD_FIT_FULL, so
this is not a regression.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- Fix LZMA support
- Fix load address
- Explicitly initialize load_info members

Changes in v5:
- Rework to load header in spl_load

 common/spl/spl_legacy.c   | 61 ---------------------------------------
 common/spl/spl_nor.c      | 40 +++++--------------------
 include/spl_load.h        |  1 +
 test/image/spl_load_nor.c |  2 ++
 4 files changed, 10 insertions(+), 94 deletions(-)

diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
index a561939b4f0..08687ca8f6c 100644
--- a/common/spl/spl_legacy.c
+++ b/common/spl/spl_legacy.c
@@ -118,64 +118,3 @@ int spl_load_legacy_lzma(struct spl_image_info *spl_image,
 	spl_image->size = lzma_len;
 	return 0;
 }
-
-/*
- * This function is added explicitly to avoid code size increase, when
- * no compression method is enabled. The compiler will optimize the
- * following switch/case statement in spl_load_legacy_img() away due to
- * Dead Code Elimination.
- */
-static inline int spl_image_get_comp(const struct legacy_img_hdr *hdr)
-{
-	if (IS_ENABLED(CONFIG_SPL_LZMA))
-		return image_get_comp(hdr);
-
-	return IH_COMP_NONE;
-}
-
-int spl_load_legacy_img(struct spl_image_info *spl_image,
-			struct spl_boot_device *bootdev,
-			struct spl_load_info *load, ulong offset,
-			struct legacy_img_hdr *hdr)
-{
-	ulong dataptr;
-	int ret;
-
-	/*
-	 * If the payload is compressed, the decompressed data should be
-	 * directly write to its load address.
-	 */
-	if (spl_image_get_comp(hdr) != IH_COMP_NONE)
-		spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
-
-	ret = spl_parse_image_header(spl_image, bootdev, hdr);
-	if (ret)
-		return ret;
-
-	/* Read image */
-	switch (spl_image_get_comp(hdr)) {
-	case IH_COMP_NONE:
-		dataptr = offset;
-
-		/*
-		 * Image header will be skipped only if SPL_COPY_PAYLOAD_ONLY
-		 * is set
-		 */
-		if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY)
-			dataptr += sizeof(*hdr);
-
-		load->read(load, dataptr, spl_image->size,
-			   map_sysmem(spl_image->load_addr, spl_image->size));
-		break;
-
-	case IH_COMP_LZMA:
-		return spl_load_legacy_lzma(spl_image, load, offset);
-
-	default:
-		debug("Compression method %s is not supported\n",
-		      genimg_get_comp_short_name(image_get_comp(hdr)));
-		return -EINVAL;
-	}
-
-	return 0;
-}
diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c
index aad230db4d3..70745114efe 100644
--- a/common/spl/spl_nor.c
+++ b/common/spl/spl_nor.c
@@ -7,8 +7,8 @@
 #include <image.h>
 #include <imx_container.h>
 #include <log.h>
-#include <mapmem.h>
 #include <spl.h>
+#include <spl_load.h>
 
 static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
 			       ulong count, void *buf)
@@ -28,8 +28,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)
 {
-	struct legacy_img_hdr *header;
-	__maybe_unused struct spl_load_info load;
+	struct spl_load_info load;
 
 	/*
 	 * Loading of the payload to SDRAM is done with skipping of
@@ -43,7 +42,8 @@ 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 = (void *)CONFIG_SYS_OS_BASE;
+		const struct legacy_img_hdr *header =
+			(const struct legacy_img_hdr *)CONFIG_SYS_OS_BASE;
 #ifdef CONFIG_SPL_LOAD_FIT
 		if (image_get_magic(header) == FDT_MAGIC) {
 			int ret;
@@ -93,34 +93,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
 	 */
-	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");
-		spl_set_bl_len(&load, 1);
-		load.read = spl_nor_load_read;
-		return spl_load_simple_fit(spl_image, &load,
-					   spl_nor_get_uboot_base(),
-					   (void *)header);
-	}
-#endif
-	if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
-	    valid_container_hdr((void *)header)) {
-		spl_set_bl_len(&load, 1);
-		load.read = spl_nor_load_read;
-		return spl_load_imx_container(spl_image, &load,
-					      spl_nor_get_uboot_base());
-	}
-
-	/* Legacy image handling */
-	if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT)) {
-		spl_set_bl_len(&load, 1);
-		load.read = spl_nor_load_read;
-		return spl_load_legacy_img(spl_image, bootdev, &load,
-					   spl_nor_get_uboot_base(),
-					   header);
-	}
-
-	return -EINVAL;
+	spl_set_bl_len(&load, 1);
+	load.read = spl_nor_load_read;
+	return spl_load(spl_image, bootdev, &load, 0, spl_nor_get_uboot_base());
 }
 SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);
diff --git a/include/spl_load.h b/include/spl_load.h
index 4777f84ac6b..b48f80324bb 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -100,6 +100,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
 	IS_ENABLED(CONFIG_SPL_SYS_MMCSD_RAW_MODE) + \
 	(IS_ENABLED(CONFIG_SPL_NAND_SUPPORT) && !IS_ENABLED(CONFIG_SPL_UBI)) + \
 	IS_ENABLED(CONFIG_SPL_NET) + \
+	IS_ENABLED(CONFIG_SPL_NOR_SUPPORT) + \
 	0
 
 #if SPL_LOAD_USERS > 1
diff --git a/test/image/spl_load_nor.c b/test/image/spl_load_nor.c
index a62bb60d253..de5686343b9 100644
--- a/test/image/spl_load_nor.c
+++ b/test/image/spl_load_nor.c
@@ -36,4 +36,6 @@ 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);
+#if !IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)
 SPL_IMG_TEST(spl_test_nor, FIT_EXTERNAL, 0);
+#endif
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 21/25] spl: Convert NVMe to spl_load
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (19 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 20/25] spl: Convert nor " Sean Anderson
@ 2023-11-06  2:25 ` Sean Anderson
  2023-11-08  4:24   ` Simon Glass
  2023-11-06  2:26 ` [PATCH v6 22/25] spl: Convert semihosting " Sean Anderson
                   ` (4 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:25 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson, Mayuresh Chitale

This converts the blk load method (used exclusively by NVMe) to use
spl_load. As a consequence, it also adds support for LOAD_FIT_FULL and
IMX images.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- Fix invalid return from spl_blk_load_image
- Explicitly initialize load_info members

Changes in v5:
- New

 common/spl/spl_blk_fs.c  | 66 +++++++---------------------------------
 include/spl_load.h       |  1 +
 test/image/spl_load_fs.c |  2 ++
 3 files changed, 14 insertions(+), 55 deletions(-)

diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
index 53b8e1b11b4..ac267ab979b 100644
--- a/common/spl/spl_blk_fs.c
+++ b/common/spl/spl_blk_fs.c
@@ -7,6 +7,7 @@
 
 #include <common.h>
 #include <spl.h>
+#include <spl_load.h>
 #include <image.h>
 #include <fs.h>
 #include <asm/cache.h>
@@ -48,11 +49,11 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
 		       enum uclass_id uclass_id, int devnum, int partnum)
 {
 	const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
-	struct legacy_img_hdr *header;
 	struct blk_desc *blk_desc;
-	loff_t actlen, filesize;
+	loff_t filesize;
 	struct blk_dev dev;
-	int ret = -ENODEV;
+	struct spl_load_info load;
+	int ret;
 
 	blk_desc = blk_get_devnum_by_uclass_id(uclass_id, devnum);
 	if (!blk_desc) {
@@ -61,8 +62,8 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
 	}
 
 	blk_show_device(uclass_id, devnum);
-	header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
 
+	dev.filename = filename;
 	dev.ifname = blk_get_uclass_name(uclass_id);
 	snprintf(dev.dev_part_str, sizeof(dev.dev_part_str) - 1, "%x:%x",
 		 devnum, partnum);
@@ -70,63 +71,18 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
 	if (ret) {
 		printf("spl: unable to set blk_dev %s %s. Err - %d\n",
 		       dev.ifname, dev.dev_part_str, ret);
-		goto out;
-	}
-
-	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,
-		       ret);
-		goto out;
-	}
-
-	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-	    image_get_magic(header) == FDT_MAGIC) {
-		struct spl_load_info load;
-
-		debug("Found FIT\n");
-		load.read = spl_fit_read;
-		spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
-		load.priv = &dev;
-		dev.filename = filename;
-
-		return spl_load_simple_fit(spl_image, &load, 0, header);
-	}
-
-	ret = spl_parse_image_header(spl_image, bootdev, header);
-	if (ret) {
-		printf("spl: unable to parse image header. Err - %d\n",
-		       ret);
-		goto out;
-	}
-
-	ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY);
-	if (ret) {
-		printf("spl: unable to set blk_dev %s %s. Err - %d\n",
-		       dev.ifname, dev.dev_part_str, ret);
-		goto out;
+		return ret;
 	}
 
 	ret = fs_size(filename, &filesize);
 	if (ret) {
 		printf("spl: unable to get file size: %s. Err - %d\n",
 		       filename, ret);
-		goto out;
+		return ret;
 	}
 
-	ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY);
-	if (ret) {
-		printf("spl: unable to set blk_dev %s %s. Err - %d\n",
-		       dev.ifname, dev.dev_part_str, ret);
-		goto out;
-	}
-
-	ret = fs_read(filename, (ulong)spl_image->load_addr, 0, filesize,
-		      &actlen);
-	if (ret)
-		printf("spl: unable to read file %s. Err - %d\n",
-		       filename, ret);
-out:
-	return ret;
+	load.read = spl_fit_read;
+	spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
+	load.priv = &dev;
+	return spl_load(spl_image, bootdev, &load, filesize, 0);
 }
diff --git a/include/spl_load.h b/include/spl_load.h
index b48f80324bb..2618109cee0 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -95,6 +95,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
  * inline if there is one caller, and extern otherwise.
  */
 #define SPL_LOAD_USERS \
+	IS_ENABLED(CONFIG_SPL_BLK_FS) + \
 	IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
 	IS_ENABLED(CONFIG_SPL_FS_FAT) + \
 	IS_ENABLED(CONFIG_SPL_SYS_MMCSD_RAW_MODE) + \
diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
index 67c19da95e7..5f1de5486f4 100644
--- a/test/image/spl_load_fs.c
+++ b/test/image/spl_load_fs.c
@@ -395,6 +395,8 @@ static int spl_test_blk(struct unit_test_state *uts, const char *test_name,
 	return spl_test_mmc_fs(uts, test_name, type, create_ext2, true);
 }
 SPL_IMG_TEST(spl_test_blk, LEGACY, DM_FLAGS);
+SPL_IMG_TEST(spl_test_blk, LEGACY_LZMA, DM_FLAGS);
+SPL_IMG_TEST(spl_test_blk, IMX8, DM_FLAGS);
 SPL_IMG_TEST(spl_test_blk, FIT_EXTERNAL, DM_FLAGS);
 SPL_IMG_TEST(spl_test_blk, FIT_INTERNAL, DM_FLAGS);
 
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 22/25] spl: Convert semihosting to spl_load
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (20 preceding siblings ...)
  2023-11-06  2:25 ` [PATCH v6 21/25] spl: Convert NVMe " Sean Anderson
@ 2023-11-06  2:26 ` Sean Anderson
  2023-11-06  2:26 ` [PATCH v6 23/25] spl: Convert spi " Sean Anderson
                   ` (3 subsequent siblings)
  25 siblings, 0 replies; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:26 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

This converts the semihosting load method to use spl_load. As a result, it
also adds support for LOAD_FIT_FULL and IMX images.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- Explicitly initialize load_info members

Changes in v5:
- Rework to load header in spl_load

Changes in v2:
- New

 common/spl/spl_semihosting.c | 52 +++++-------------------------------
 include/spl_load.h           |  1 +
 2 files changed, 7 insertions(+), 46 deletions(-)

diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c
index 9b0610b8fc8..941fa911040 100644
--- a/common/spl/spl_semihosting.c
+++ b/common/spl/spl_semihosting.c
@@ -8,18 +8,7 @@
 #include <log.h>
 #include <semihosting.h>
 #include <spl.h>
-
-static int smh_read_full(long fd, void *memp, size_t len)
-{
-	long read;
-
-	read = smh_read(fd, memp, len);
-	if (read < 0)
-		return read;
-	if (read != len)
-		return -EIO;
-	return 0;
-}
+#include <spl_load.h>
 
 static ulong smh_fit_read(struct spl_load_info *load, ulong file_offset,
 			  ulong size, void *buf)
@@ -40,8 +29,7 @@ static int spl_smh_load_image(struct spl_image_info *spl_image,
 	const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
 	int ret;
 	long fd, len;
-	struct legacy_img_hdr *header =
-		spl_get_load_buffer(-sizeof(*header), sizeof(*header));
+	struct spl_load_info load;
 
 	fd = smh_open(filename, MODE_READ | MODE_BINARY);
 	if (fd < 0) {
@@ -56,38 +44,10 @@ static int spl_smh_load_image(struct spl_image_info *spl_image,
 	}
 	len = ret;
 
-	ret = smh_read_full(fd, header, sizeof(struct legacy_img_hdr));
-	if (ret) {
-		log_debug("could not read image header: %d\n", ret);
-		goto out;
-	}
-
-	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-	    image_get_magic(header) == FDT_MAGIC) {
-		struct spl_load_info load;
-
-		debug("Found FIT\n");
-		load.read = smh_fit_read;
-		spl_set_bl_len(&load, 1);
-		load.priv = &fd;
-
-		ret = spl_load_simple_fit(spl_image, &load, 0, header);
-		goto out;
-	}
-
-	ret = spl_parse_image_header(spl_image, bootdev, header);
-	if (ret) {
-		log_debug("failed to parse image header: %d\n", ret);
-		goto out;
-	}
-
-	ret = smh_seek(fd, 0);
-	if (ret) {
-		log_debug("could not seek to start of image: %d\n", ret);
-		goto out;
-	}
-
-	ret = smh_read_full(fd, (void *)spl_image->load_addr, len);
+	load.read = smh_fit_read;
+	spl_set_bl_len(&load, 1);
+	load.priv = &fd;
+	ret = spl_load(spl_image, bootdev, &load, len, 0);
 	if (ret)
 		log_debug("could not read %s: %d\n", filename, ret);
 out:
diff --git a/include/spl_load.h b/include/spl_load.h
index 2618109cee0..2a20e866cd8 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -102,6 +102,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
 	(IS_ENABLED(CONFIG_SPL_NAND_SUPPORT) && !IS_ENABLED(CONFIG_SPL_UBI)) + \
 	IS_ENABLED(CONFIG_SPL_NET) + \
 	IS_ENABLED(CONFIG_SPL_NOR_SUPPORT) + \
+	IS_ENABLED(CONFIG_SPL_SEMIHOSTING) + \
 	0
 
 #if SPL_LOAD_USERS > 1
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 23/25] spl: Convert spi to spl_load
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (21 preceding siblings ...)
  2023-11-06  2:26 ` [PATCH v6 22/25] spl: Convert semihosting " Sean Anderson
@ 2023-11-06  2:26 ` Sean Anderson
  2023-11-08  4:24   ` Simon Glass
  2023-11-06  2:26 ` [PATCH v6 24/25] spl: spi: Consolidate spi_load_image_os into spl_spi_load_image Sean Anderson
                   ` (2 subsequent siblings)
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:26 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson, Jagan Teki, Vignesh R

This converts the spi load method to use spl_load. The address used for
LOAD_FIT_FULL may be different, but there are no in-tree users of that
config. Since payload_offs is only used without OS_BOOT, we defer its
initialization.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- Fix soft reset after loading from SPI

Changes in v5:
- Rework to load header in spl_load

 common/spl/spl_spi.c      | 80 +++++++--------------------------------
 include/spl_load.h        |  1 +
 test/image/spl_load_spi.c |  1 +
 3 files changed, 15 insertions(+), 67 deletions(-)

diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index 3e08ac7c1a2..f49e534b749 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -12,11 +12,11 @@
 #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 <spl_load.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
 #include <dm/ofnode.h>
@@ -95,9 +95,9 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 	int err = 0;
 	unsigned int payload_offs;
 	struct spi_flash *flash;
-	struct legacy_img_hdr *header;
 	unsigned int sf_bus = spl_spi_boot_bus();
 	unsigned int sf_cs = spl_spi_boot_cs();
+	struct spl_load_info load;
 
 	/*
 	 * Load U-Boot image from SPI flash into RAM
@@ -112,77 +112,23 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 		return -ENODEV;
 	}
 
+#if CONFIG_IS_ENABLED(OS_BOOT)
+	if (!spl_start_uboot() && !spi_load_image_os(spl_image, bootdev, flash, header))
+		return 0;
+#endif
+
 	payload_offs = spl_spi_get_uboot_offs(flash);
-
-	header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
-
 	if (CONFIG_IS_ENABLED(OF_REAL)) {
 		payload_offs = ofnode_conf_read_int("u-boot,spl-payload-offset",
 						    payload_offs);
 	}
 
-#if CONFIG_IS_ENABLED(OS_BOOT)
-	if (spl_start_uboot() || spi_load_image_os(spl_image, bootdev, flash, header))
-#endif
-	{
-		/* Load u-boot, mkimage header is 64 bytes. */
-		err = spi_flash_read(flash, payload_offs, sizeof(*header),
-				     (void *)header);
-		if (err) {
-			debug("%s: Failed to read from SPI flash (err=%d)\n",
-			      __func__, err);
-			return err;
-		}
-
-		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,
-					     size,
-					     map_sysmem(CONFIG_SYS_LOAD_ADDR,
-							size));
-			if (err)
-				return err;
-			err = spl_parse_image_header(spl_image, bootdev,
-					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;
-
-			debug("Found FIT\n");
-			load.priv = flash;
-			spl_set_bl_len(&load, 1);
-			load.read = spl_spi_fit_read;
-			err = spl_load_simple_fit(spl_image, &load,
-						  payload_offs,
-						  header);
-		} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
-			   valid_container_hdr((void *)header)) {
-			struct spl_load_info load;
-
-			load.priv = flash;
-			spl_set_bl_len(&load, 1);
-			load.read = spl_spi_fit_read;
-
-			err = spl_load_imx_container(spl_image, &load,
-						     payload_offs);
-		} else {
-			err = spl_parse_image_header(spl_image, bootdev, header);
-			if (err)
-				return err;
-			err = spi_flash_read(flash, payload_offs + spl_image->offset,
-					     spl_image->size,
-					     map_sysmem(spl_image->load_addr,
-							spl_image->size));
-		}
-		if (IS_ENABLED(CONFIG_SPI_FLASH_SOFT_RESET)) {
-			err = spi_nor_remove(flash);
-			if (err)
-				return err;
-		}
-	}
-
+	load.priv = flash;
+	spl_set_bl_len(&load, 1);
+	load.read = spl_spi_fit_read;
+	err = spl_load(spl_image, bootdev, &load, 0, payload_offs);
+	if (IS_ENABLED(CONFIG_SPI_FLASH_SOFT_RESET))
+		err = spi_nor_remove(flash);
 	return err;
 }
 /* Use priorty 1 so that boards can override this */
diff --git a/include/spl_load.h b/include/spl_load.h
index 2a20e866cd8..1c2b296c0a2 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -103,6 +103,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
 	IS_ENABLED(CONFIG_SPL_NET) + \
 	IS_ENABLED(CONFIG_SPL_NOR_SUPPORT) + \
 	IS_ENABLED(CONFIG_SPL_SEMIHOSTING) + \
+	IS_ENABLED(CONFIG_SPL_SPI_LOAD) + \
 	0
 
 #if SPL_LOAD_USERS > 1
diff --git a/test/image/spl_load_spi.c b/test/image/spl_load_spi.c
index 8f9b6e0139b..54a95465e23 100644
--- a/test/image/spl_load_spi.c
+++ b/test/image/spl_load_spi.c
@@ -34,6 +34,7 @@ static int spl_test_spi(struct unit_test_state *uts, const char *test_name,
 				spl_test_spi_write_image);
 }
 SPL_IMG_TEST(spl_test_spi, LEGACY, DM_FLAGS);
+SPL_IMG_TEST(spl_test_spi, LEGACY_LZMA, DM_FLAGS);
 SPL_IMG_TEST(spl_test_spi, IMX8, DM_FLAGS);
 SPL_IMG_TEST(spl_test_spi, FIT_INTERNAL, DM_FLAGS);
 #if !IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 24/25] spl: spi: Consolidate spi_load_image_os into spl_spi_load_image
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (22 preceding siblings ...)
  2023-11-06  2:26 ` [PATCH v6 23/25] spl: Convert spi " Sean Anderson
@ 2023-11-06  2:26 ` Sean Anderson
  2023-11-08  4:24   ` Simon Glass
  2023-11-06  2:26 ` [PATCH v6 25/25] spl: fat: Add option to disable DMA alignment Sean Anderson
  2023-11-06  7:49 ` [PATCH v6 00/25] spl: Use common function for loading/parsing images Pali Rohár
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:26 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson, Jagan Teki, Nathan Barrett-Morrison, Vignesh R

spi_load_image_os performs almost the same steps as the non-falcon-boot
path of spl_spi_load_image. The load address is different, and it also
loads a device tree, but that's it. Refactor the boot process so that
they can both use the same load function.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

(no changes since v5)

Changes in v5:
- Rework to load header in spl_load

Changes in v2:
- New

 common/spl/spl_spi.c | 54 ++++++++++++--------------------------------
 1 file changed, 14 insertions(+), 40 deletions(-)

diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index f49e534b749..89de73c726c 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -21,41 +21,6 @@
 #include <asm/io.h>
 #include <dm/ofnode.h>
 
-#if CONFIG_IS_ENABLED(OS_BOOT)
-/*
- * Load the kernel, check for a valid header we can parse, and if found load
- * the kernel and then device tree.
- */
-static int spi_load_image_os(struct spl_image_info *spl_image,
-			     struct spl_boot_device *bootdev,
-			     struct spi_flash *flash,
-			     struct legacy_img_hdr *header)
-{
-	int err;
-
-	/* Read for a header, parse or error out. */
-	spi_flash_read(flash, CFG_SYS_SPI_KERNEL_OFFS, sizeof(*header),
-		       (void *)header);
-
-	if (image_get_magic(header) != IH_MAGIC)
-		return -1;
-
-	err = spl_parse_image_header(spl_image, bootdev, header);
-	if (err)
-		return err;
-
-	spi_flash_read(flash, CFG_SYS_SPI_KERNEL_OFFS,
-		       spl_image->size, (void *)spl_image->load_addr);
-
-	/* Read device tree. */
-	spi_flash_read(flash, CFG_SYS_SPI_ARGS_OFFS,
-		       CFG_SYS_SPI_ARGS_SIZE,
-		       (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR);
-
-	return 0;
-}
-#endif
-
 static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector,
 			      ulong count, void *buf)
 {
@@ -112,9 +77,21 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 		return -ENODEV;
 	}
 
+	load.priv = flash;
+	spl_set_bl_len(&load, 1);
+	load.read = spl_spi_fit_read;
+
 #if CONFIG_IS_ENABLED(OS_BOOT)
-	if (!spl_start_uboot() && !spi_load_image_os(spl_image, bootdev, flash, header))
-		return 0;
+	if (spl_start_uboot()) {
+		int err = spl_load(spl_image, bootdev, &load, 0,
+				   CFG_SYS_SPI_KERNEL_OFFS);
+
+		if (!err)
+			/* Read device tree. */
+			return spi_flash_read(flash, CFG_SYS_SPI_ARGS_OFFS,
+					      CFG_SYS_SPI_ARGS_SIZE,
+					      (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR);
+	}
 #endif
 
 	payload_offs = spl_spi_get_uboot_offs(flash);
@@ -123,9 +100,6 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 						    payload_offs);
 	}
 
-	load.priv = flash;
-	spl_set_bl_len(&load, 1);
-	load.read = spl_spi_fit_read;
 	err = spl_load(spl_image, bootdev, &load, 0, payload_offs);
 	if (IS_ENABLED(CONFIG_SPI_FLASH_SOFT_RESET))
 		err = spi_nor_remove(flash);
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH v6 25/25] spl: fat: Add option to disable DMA alignment
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (23 preceding siblings ...)
  2023-11-06  2:26 ` [PATCH v6 24/25] spl: spi: Consolidate spi_load_image_os into spl_spi_load_image Sean Anderson
@ 2023-11-06  2:26 ` Sean Anderson
  2023-11-08  4:24   ` Simon Glass
  2023-11-06  7:49 ` [PATCH v6 00/25] spl: Use common function for loading/parsing images Pali Rohár
  25 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06  2:26 UTC (permalink / raw)
  To: Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Sean Anderson

If we don't DMA-align buffers we pass to FAT, it will align them itself.
This behaviour likely should be deprecated in favor of
CONFIG_BOUNCE_BUFFER, but that's a task for another series. For the
meantime, don't bother aligning the buffer unless we had been doing so in
the past.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- New

 common/spl/Kconfig      | 18 ++++++++++++++++--
 common/spl/spl_blk_fs.c |  5 ++++-
 common/spl/spl_fat.c    |  5 ++++-
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index b93526904eb..fc284a5bffc 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -694,13 +694,28 @@ config SPL_FS_SQUASHFS
 config SPL_FS_FAT
 	bool "Support FAT filesystems"
 	select FS_FAT
-	select SPL_LOAD_BLOCK
 	help
 	  Enable support for FAT and VFAT filesystems with SPL. This
 	  permits U-Boot (or Linux in Falcon mode) to be loaded from a FAT
 	  filesystem from within SPL. Support for the underlying block
 	  device (e.g. MMC or USB) must be enabled separately.
 
+config SPL_FS_FAT_DMA_ALIGN
+	bool "Use DMA-aligned buffers with FAT"
+	depends on SPL_FS_FAT
+	select SPL_LOAD_BLOCK
+	default y if SPL_LOAD_FIT
+	help
+	  The FAT filesystem driver tries to ensure that the reads it issues to
+	  the block subsystem use DMA-aligned buffers. If the supplied buffer is
+	  not DMA-aligned, the FAT driver will use a bounce-buffer and read
+	  block-by-block. This is separate from the bounce-buffer used by the
+	  block subsystem (CONFIG_BOUNCE_BUFFER).
+
+	  Enable this config to align buffers passed to the FAT filesystem
+	  driver. This will speed up reads, but will increase the size of U-Boot
+	  by around 60 bytes.
+
 config SPL_FS_LOAD_PAYLOAD_NAME
 	string "File to load for U-Boot from the filesystem"
 	depends on SPL_FS_EXT4 || SPL_FS_FAT || SPL_FS_SQUASHFS || SPL_SEMIHOSTING
@@ -1282,7 +1297,6 @@ config SPL_NVME
 	depends on BLK
 	select FS_LOADER
 	select SPL_BLK_FS
-	select SPL_LOAD_BLOCK
 	help
 	  This option enables support for NVM Express devices.
 	  It supports basic functions of NVMe (read/write).
diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
index ac267ab979b..04eac6f306b 100644
--- a/common/spl/spl_blk_fs.c
+++ b/common/spl/spl_blk_fs.c
@@ -82,7 +82,10 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
 	}
 
 	load.read = spl_fit_read;
-	spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
+	if (IS_ENABLED(CONFIG_SPL_FS_FAT_DMA_ALIGN))
+		spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
+	else
+		spl_set_bl_len(&load, 1);
 	load.priv = &dev;
 	return spl_load(spl_image, bootdev, &load, filesize, 0);
 }
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 569f2b32928..a52f9e178e6 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -86,7 +86,10 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
 	}
 
 	load.read = spl_fit_read;
-	spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
+	if (IS_ENABLED(CONFIG_SPL_FS_FAT_DMA_ALIGN))
+		spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
+	else
+		spl_set_bl_len(&load, 1);
 	load.priv = (void *)filename;
 	err = spl_load(spl_image, bootdev, &load, size, 0);
 
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 02/25] arm: Disable SPL_FS_FAT when it isn't used
  2023-11-06  2:25 ` [PATCH v6 02/25] arm: Disable SPL_FS_FAT when it isn't used Sean Anderson
@ 2023-11-06  6:58   ` Michal Simek
  0 siblings, 0 replies; 62+ messages in thread
From: Michal Simek @ 2023-11-06  6:58 UTC (permalink / raw)
  To: Sean Anderson, Tom Rini, u-boot
  Cc: Simon Glass, Heinrich Schuchardt, Marek Behún, Marek Vasut,
	Xavier Drudis Ferran, Stefan Roese, Pali Rohár



On 11/6/23 03:25, Sean Anderson wrote:
> Several boards enable SPL_FS_FAT and SPL_LIBDISK_SUPPORT when they can't be
> used (as there is no block device support enabled). Disable these configs.
> The list of boards was generated with the following command:
> 
>      $ tools/qconfig.py -f SPL SPL_FS_FAT ~SPL_MMC ~SPL_BLK_FS ~SPL_SATA \
>                            ~SPL_USB_STORAGE ~ENV_IS_IN_FAT ~EFI
> 
> LIBDISK was left enabled for the am* boards, since it seems to result in
> actual size reduction, indicating that partitions are being used for
> something.
> 
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
> 
> (no changes since v1)
> 
>   configs/am335x_evm_spiboot_defconfig      | 2 +-
>   configs/am65x_evm_r5_usbdfu_defconfig     | 1 -
>   configs/xilinx_zynqmp_mini_qspi_defconfig | 3 +++
>   configs/zynq_cse_nand_defconfig           | 3 +++
>   configs/zynq_cse_nor_defconfig            | 3 +++
>   configs/zynq_cse_qspi_defconfig           | 3 +++
>   6 files changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/configs/am335x_evm_spiboot_defconfig b/configs/am335x_evm_spiboot_defconfig
> index b5b11fb62c8..fff5265e56a 100644
> --- a/configs/am335x_evm_spiboot_defconfig
> +++ b/configs/am335x_evm_spiboot_defconfig
> @@ -13,6 +13,7 @@ CONFIG_CLOCK_SYNTHESIZER=y
>   # CONFIG_OF_LIBFDT_OVERLAY is not set
>   # CONFIG_SPL_MMC is not set
>   CONFIG_SPL=y
> +# CONFIG_SPL_FS_FAT is not set
>   CONFIG_SPL_SPI_FLASH_SUPPORT=y
>   CONFIG_SPL_SPI=y
>   CONFIG_TIMESTAMP=y
> @@ -27,7 +28,6 @@ CONFIG_SPL_SYS_MALLOC=y
>   CONFIG_SPL_SYS_MALLOC_SIZE=0x800000
>   CONFIG_SPL_FIT_IMAGE_TINY=y
>   # CONFIG_SPL_FS_EXT4 is not set
> -CONFIG_SPL_FS_LOAD_PAYLOAD_NAME="u-boot.img"
>   CONFIG_SPL_MTD=y
>   # CONFIG_SPL_NAND_SUPPORT is not set
>   CONFIG_SPL_DM_SPI_FLASH=y
> diff --git a/configs/am65x_evm_r5_usbdfu_defconfig b/configs/am65x_evm_r5_usbdfu_defconfig
> index f610b2dd94e..6b0bb120d10 100644
> --- a/configs/am65x_evm_r5_usbdfu_defconfig
> +++ b/configs/am65x_evm_r5_usbdfu_defconfig
> @@ -21,7 +21,6 @@ CONFIG_SPL_DRIVERS_MISC=y
>   CONFIG_SPL_STACK_R_ADDR=0x82000000
>   CONFIG_SPL_SIZE_LIMIT=0x7ec00
>   CONFIG_SPL_SIZE_LIMIT_PROVIDE_STACK=0x2000
> -CONFIG_SPL_FS_FAT=y
>   CONFIG_SPL_LIBDISK_SUPPORT=y
>   # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
>   CONFIG_SPL_LOAD_FIT=y
> diff --git a/configs/xilinx_zynqmp_mini_qspi_defconfig b/configs/xilinx_zynqmp_mini_qspi_defconfig
> index a1adfb9e5d1..8b92e1c7358 100644
> --- a/configs/xilinx_zynqmp_mini_qspi_defconfig
> +++ b/configs/xilinx_zynqmp_mini_qspi_defconfig
> @@ -11,6 +11,8 @@ CONFIG_ENV_SIZE=0x80
>   CONFIG_DEFAULT_DEVICE_TREE="zynqmp-mini-qspi"
>   CONFIG_SPL_STACK=0xfffffffc
>   CONFIG_SPL=y
> +# CONFIG_SPL_FS_FAT is not set
> +# CONFIG_SPL_LIBDISK_SUPPORT is not set
>   CONFIG_SYS_MEM_RSVD_FOR_MMU=y
>   CONFIG_ZYNQMP_NO_DDR=y
>   # CONFIG_PSCI_RESET is not set
> @@ -89,6 +91,7 @@ CONFIG_SPI_FLASH_WINBOND=y
>   CONFIG_ARM_DCC=y
>   CONFIG_SPI=y
>   CONFIG_ZYNQMP_GQSPI=y
> +CONFIG_FS_FAT=y

This can be also removed and also for zynq_cse boards below.
There is no need to have FAT support.

Thanks,
Michal

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 00/25] spl: Use common function for loading/parsing images
  2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
                   ` (24 preceding siblings ...)
  2023-11-06  2:26 ` [PATCH v6 25/25] spl: fat: Add option to disable DMA alignment Sean Anderson
@ 2023-11-06  7:49 ` Pali Rohár
  2023-11-06  9:18   ` Heinrich Schuchardt
  2023-11-06 10:12   ` Marek Behún
  25 siblings, 2 replies; 62+ messages in thread
From: Pali Rohár @ 2023-11-06  7:49 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Simon Glass, Heinrich Schuchardt,
	Marek Behún, Marek Vasut

What you are doing is the worst thing in the world. You have been
ignoring all my changes which I have been sending for one year, then you
wrote me that I'm not competent to do any kind of programming, later you
wrote that you would ignore all my requests and stop responding to any
questions, then you have removed all my code from u-boot and showed me
as the worst person in the world.

But seems that this is not enough for you. You have to continue
attacking on me, and making everything even worse.

WHAT YOU WANT FROM ME NOW???? WHY YOU ARE CONTACTING ME??? IS NOT IT
ENOUGH WHAT YOU HAVE TO ME?? Or you do think that I forgot what you have
been doing with me last years? Speak up!

On Sunday 05 November 2023 21:25:38 Sean Anderson wrote:
> This series adds support for loading all image types (Legacy (with and without
> LZMA), FIT (with and without LOAD_FIT_FULL), and i.MX) to the MMC, SPI, NOR,
> NET, FAT, EXT, NVMe, and semihosting load methods. It does this by introducing a
> helper function which handles the minutiae of invoking the proper parsing
> function, and reading the rest of the image.
> 
> Hopefully, this will make it easier for load methods to support all image types
> that U-Boot supports, without having undocumented unsupported image types. I
> applied this to several loaders which were invoking spl_load_simple_fit and/or
> spl_parse_image_header, but I did not use it with others (e.g. DFU/RAM) which
> had complications in the mix.
> 
> This series is organized roughly into two parts. Patches up to "spl: Add generic
> spl_load function" are all setup or size-reduction oriented. Later patches
> generally convert various load functions to spl_load.
> 
> bloat-o-meter results (for CONFIG_SPL only) at [1]. Size growth has been the
> bigegst challenge to preparing this series. I have used every trick I can think
> of to reduce bloat. Some SAMA boards no longer fit, but I have a plan to fix
> them [2].
> 
> This is bar far the largest and most-difficult revision of this series to-date.
> There are probably still things which can reduce the size, but I have been
> working on this series for the better part of two months and I think it is a
> good idea to get some feedback. Because of the SAMA bloat, this series will not
> pass CI, so I expect to do a v7 before this is ready to apply. Feel free,
> however, to apply patches in the first half (especially the fixes).
> 
> This version of the series is better-tested than ever before, thanks to some new
> unit tests. However, things like the i.MX ROMAPI are untested. NAND should also
> be tested more-widely, for reasons listed in the commit message. I encourage you
> try this series out on your favorite board.
> 
> This series depends on [3]. (Almost passing) CI at [4].
> 
> [1] https://gist.github.com/Forty-Bot/5bfe88676dd3c2aec6ebc23abb08e06f
>     This includes some changes to am335x_evm_spiboot and am65x_evm_r5_usbdfu
>     which have since been undone.
> [2] https://lore.kernel.org/u-boot/20231105022742.632175-1-seanga2@gmail.com/
> [3] https://lore.kernel.org/u-boot/20231104203753.1579217-1-seanga2@gmail.com/
> [4] https://source.denx.de/u-boot/custodians/u-boot-clk/-/pipelines/18447
> 
> Changes in v6:
> - Fix uninitialized return value when we can't get a blk_desc
> - Don't close fd before spl_load_simple_fit
> - Remove NULL assignments in spl_load_info
> - Remove dev from spl_load_info
> - Take advantage of bl_len's power-of-twoness
> - Refactor spl_load_info->read to use units of bytes
> - Remove filename from spl_load_info
> - Only support bl_len when we have to
> - Remove spl_nand_legacy_read
> - Split off LZMA decompression into its own function
> - Support testing LEGACY_LZMA filesystem images
> - Use pseudo-LTO for spl_load
> - Align reads to bl_len
> - Add SYS_MMCSD_RAW_MODE to help determine whether SPL_MMC loads
>   anything directly.
> - Convert nand to spl_load
> - Fix LZMA support
> - Fix load address
> - Fix invalid return from spl_blk_load_image
> - Fix soft reset after loading from SPI
> - Explicitly initialize load_info members to reduce text size
> - Rebase on u-boot/next
> - Add option to disable DMA alignment for FAT
> 
> Changes in v5:
> - Make SHOW_ERRORS depend on LIBCOMMON
> - Load the header in spl_load as well
> - Don't bother trying to DMA-align the buffer, since we can't really fix
>   it.
> - Convert NVMe to spl_load
> 
> Changes in v4:
> - Fix format specifiers in debug prints
> - Reword/fix some of the doc comments for spl_load
> - Rebase on u-boot/master
> 
> Changes in v3:
> - Fix using ffs instead of fls
> - Fix using not initializing bl_len when info->filename was NULL
> - Fix failing on success
> 
> Changes in v2:
> - Use reverse-xmas-tree style for locals in spl_simple_read. This is not
>   complete, since overhead depends on bl_mask.
> - Convert semihosting as well
> - Consolidate spi_load_image_os into spl_spi_load_image
> 
> Sean Anderson (25):
>   spl: blk_fs: Fix uninitialized return value when we can't get a
>     blk_desc
>   arm: Disable SPL_FS_FAT when it isn't used
>   spl: Make SHOW_ERRORS depend on LIBCOMMON
>   spl: semihosting: Don't close fd before spl_load_simple_fit
>   spl: Remove NULL assignments in spl_load_info
>   spl: Remove dev from spl_load_info
>   spl: Take advantage of bl_len's power-of-twoness
>   spl: Refactor spl_load_info->read to use units of bytes
>   spl: Remove filename from spl_load_info
>   spl: Only support bl_len when we have to
>   spl: nand: Remove spl_nand_legacy_read
>   spl: legacy: Split off LZMA decompression into its own function
>   test: spl: Support testing LEGACY_LZMA filesystem images
>   spl: Add generic spl_load function
>   spl: Convert ext to use spl_load
>   spl: Convert fat to spl_load
>   spl: Convert mmc to spl_load
>   spl: Convert nand to spl_load
>   spl: Convert net to spl_load
>   spl: Convert nor to spl_load
>   spl: Convert NVMe to spl_load
>   spl: Convert semihosting to spl_load
>   spl: Convert spi to spl_load
>   spl: spi: Consolidate spi_load_image_os into spl_spi_load_image
>   spl: fat: Add option to disable DMA alignment
> 
>  arch/arm/mach-imx/spl_imx_romapi.c        |  24 ++--
>  arch/arm/mach-sunxi/spl_spi_sunxi.c       |   5 +-
>  common/spl/Kconfig                        |  37 +++++-
>  common/spl/spl.c                          |  13 +-
>  common/spl/spl_blk_fs.c                   |  73 +++--------
>  common/spl/spl_ext.c                      |  36 +++---
>  common/spl/spl_fat.c                      |  62 ++++------
>  common/spl/spl_fit.c                      |  74 ++++-------
>  common/spl/spl_imx_container.c            |  55 ++++-----
>  common/spl/spl_legacy.c                   | 110 ++++-------------
>  common/spl/spl_mmc.c                      | 101 ++-------------
>  common/spl/spl_nand.c                     | 104 ++++------------
>  common/spl/spl_net.c                      |  29 +----
>  common/spl/spl_nor.c                      |  42 ++-----
>  common/spl/spl_ram.c                      |   2 +-
>  common/spl/spl_semihosting.c              |  65 ++--------
>  common/spl/spl_spi.c                      | 130 ++++---------------
>  common/spl/spl_ymodem.c                   |   4 +-
>  configs/am335x_evm_spiboot_defconfig      |   2 +-
>  configs/am65x_evm_r5_usbdfu_defconfig     |   1 -
>  configs/xilinx_zynqmp_mini_qspi_defconfig |   3 +
>  configs/zynq_cse_nand_defconfig           |   3 +
>  configs/zynq_cse_nor_defconfig            |   3 +
>  configs/zynq_cse_qspi_defconfig           |   3 +
>  drivers/usb/gadget/f_sdp.c                |  10 +-
>  include/spl.h                             |  60 +++++++--
>  include/spl_load.h                        | 144 ++++++++++++++++++++++
>  include/test/spl.h                        |   4 +
>  test/image/Kconfig                        |   1 +
>  test/image/spl_load.c                     |  13 +-
>  test/image/spl_load_fs.c                  |  32 +++--
>  test/image/spl_load_nand.c                |   2 +
>  test/image/spl_load_net.c                 |   2 +
>  test/image/spl_load_nor.c                 |   2 +
>  test/image/spl_load_os.c                  |  16 ++-
>  test/image/spl_load_spi.c                 |   1 +
>  36 files changed, 536 insertions(+), 732 deletions(-)
>  create mode 100644 include/spl_load.h
> 
> -- 
> 2.37.1
> 

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 00/25] spl: Use common function for loading/parsing images
  2023-11-06  7:49 ` [PATCH v6 00/25] spl: Use common function for loading/parsing images Pali Rohár
@ 2023-11-06  9:18   ` Heinrich Schuchardt
  2023-11-06 10:12   ` Marek Behún
  1 sibling, 0 replies; 62+ messages in thread
From: Heinrich Schuchardt @ 2023-11-06  9:18 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Simon Glass, Marek Behún, Marek Vasut

On 11/5/23 23:49, Pali Rohár wrote:
> What you are doing is the worst thing in the world. You have been
> ignoring all my changes which I have been sending for one year, then you
> wrote me that I'm not competent to do any kind of programming, later you
> wrote that you would ignore all my requests and stop responding to any
> questions, then you have removed all my code from u-boot and showed me
> as the worst person in the world.
>
> But seems that this is not enough for you. You have to continue
> attacking on me, and making everything even worse.
>
> WHAT YOU WANT FROM ME NOW???? WHY YOU ARE CONTACTING ME??? IS NOT IT
> ENOUGH WHAT YOU HAVE TO ME?? Or you do think that I forgot what you have
> been doing with me last years? Speak up!

I have created a patch for .mailmap to avoid sending Pali any further
"unsolicited" mail.

[PATCH 1/1] .mailmap: map Pali Rohár
https://lists.denx.de/pipermail/u-boot/2023-November/536392.html

Best regards

Heinrich

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 00/25] spl: Use common function for loading/parsing images
  2023-11-06  7:49 ` [PATCH v6 00/25] spl: Use common function for loading/parsing images Pali Rohár
  2023-11-06  9:18   ` Heinrich Schuchardt
@ 2023-11-06 10:12   ` Marek Behún
  1 sibling, 0 replies; 62+ messages in thread
From: Marek Behún @ 2023-11-06 10:12 UTC (permalink / raw)
  To: Pali Rohár
  Cc: Sean Anderson, Tom Rini, u-boot, Simon Glass,
	Heinrich Schuchardt, Marek Vasut

On Mon, 6 Nov 2023 08:49:05 +0100
Pali Rohár <pali@kernel.org> wrote:

> What you are doing is the worst thing in the world. You have been
> ignoring all my changes which I have been sending for one year, then you
> wrote me that I'm not competent to do any kind of programming, later you
> wrote that you would ignore all my requests and stop responding to any
> questions, then you have removed all my code from u-boot and showed me
> as the worst person in the world.

I am sorry this happened the way it did. I personally do not think that
you're not a competent programmer. On the contrary, I think that you're
a very good programmer, and that what happened has more to do with
an escalation of misunderstandings and relevant people being too busy at
unfortunate times. This naturally led to frustrations and harsh
language, which led to this unfortunate situation.

Just wanted to let you know that I am sorry about how this whole thing
played out, and that I feel partially responsible for a little bit of
it, since I also made you some promises ages ago which still are not
fulfilled :-(

I have finally managed to recruit two newbie kernel hackers into our
team. I am currently tutoring them, and one of the projects I have
in the tutoring plan is getting the work you did out into the open. It
will take some time, but my hopes are that it will be done.

Again, I am sorry. I hope you are doing well.

Marek

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes
  2023-11-06  2:25 ` [PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes Sean Anderson
@ 2023-11-06 12:35   ` Xavier Drudis Ferran
  2023-11-06 13:54     ` Sean Anderson
  0 siblings, 1 reply; 62+ messages in thread
From: Xavier Drudis Ferran @ 2023-11-06 12:35 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Simon Glass, Heinrich Schuchardt,
	Marek Behún, Marek Vasut, Xavier Drudis Ferran,
	Stefan Roese, Fabio Estevam, Stefano Babic, uboot-imx

Thanks for your work. I'm still reading... but...


El Sun, Nov 05, 2023 at 09:25:46PM -0500, Sean Anderson deia:
> diff --git a/include/spl.h b/include/spl.h
> index 951e136b9ea..ecfc50e0095 100644
> --- a/include/spl.h
> +++ b/include/spl.h
> @@ -297,10 +297,10 @@ struct spl_load_info {
>  	 * read() - Read from device
>  	 *
>  	 * @load: Information about the load state
> -	 * @sector: Sector number to read from (each @load->bl_len bytes)
> -	 * @count: Number of sectors to read
> +	 * @offset: Offset to read from in bytes, in multiples of @load->bl_len
> +	 * @count: Number of bytes to read, in multiples of @load->bl_len

I'm no native English speaker, but would it be easier to understand? :

+	 * @offset: Offset to read from in bytes, a multiple of @load->bl_len
+	 * @count: Number of bytes to read, a multiple of @load->bl_len




^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes
  2023-11-06 12:35   ` Xavier Drudis Ferran
@ 2023-11-06 13:54     ` Sean Anderson
  2023-11-07  8:49       ` Xavier Drudis Ferran
  0 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-06 13:54 UTC (permalink / raw)
  To: Xavier Drudis Ferran
  Cc: Tom Rini, u-boot, Simon Glass, Heinrich Schuchardt,
	Marek Behún, Marek Vasut, Stefan Roese, Fabio Estevam,
	Stefano Babic, uboot-imx

On 11/6/23 07:35, Xavier Drudis Ferran wrote:
> Thanks for your work. I'm still reading... but...
> 
> 
> El Sun, Nov 05, 2023 at 09:25:46PM -0500, Sean Anderson deia:
>> diff --git a/include/spl.h b/include/spl.h
>> index 951e136b9ea..ecfc50e0095 100644
>> --- a/include/spl.h
>> +++ b/include/spl.h
>> @@ -297,10 +297,10 @@ struct spl_load_info {
>>   	 * read() - Read from device
>>   	 *
>>   	 * @load: Information about the load state
>> -	 * @sector: Sector number to read from (each @load->bl_len bytes)
>> -	 * @count: Number of sectors to read
>> +	 * @offset: Offset to read from in bytes, in multiples of @load->bl_len
>> +	 * @count: Number of bytes to read, in multiples of @load->bl_len
> 
> I'm no native English speaker, but would it be easier to understand? :
> 
> +	 * @offset: Offset to read from in bytes, a multiple of @load->bl_len
> +	 * @count: Number of bytes to read, a multiple of @load->bl_len
> 
> 
> 

I think it would have to be worded

@offset: Offset to read from in bytes, as a multiple of @load->bl_len

but to me these both mean the same thing.

--Sean

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes
  2023-11-06 13:54     ` Sean Anderson
@ 2023-11-07  8:49       ` Xavier Drudis Ferran
  2023-11-08 15:59         ` Sean Anderson
  0 siblings, 1 reply; 62+ messages in thread
From: Xavier Drudis Ferran @ 2023-11-07  8:49 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Xavier Drudis Ferran, Tom Rini, u-boot, Simon Glass,
	Heinrich Schuchardt, Marek Behún, Marek Vasut, Stefan Roese,
	Fabio Estevam, Stefano Babic, uboot-imx

El Mon, Nov 06, 2023 at 08:54:03AM -0500, Sean Anderson deia:
> On 11/6/23 07:35, Xavier Drudis Ferran wrote:
> > Thanks for your work. I'm still reading... but...
> > 
> > 
> > El Sun, Nov 05, 2023 at 09:25:46PM -0500, Sean Anderson deia:
> > > diff --git a/include/spl.h b/include/spl.h
> > > index 951e136b9ea..ecfc50e0095 100644
> > > --- a/include/spl.h
> > > +++ b/include/spl.h
> > > @@ -297,10 +297,10 @@ struct spl_load_info {
> > >   	 * read() - Read from device
> > >   	 *
> > >   	 * @load: Information about the load state
> > > -	 * @sector: Sector number to read from (each @load->bl_len bytes)
> > > -	 * @count: Number of sectors to read
> > > +	 * @offset: Offset to read from in bytes, in multiples of @load->bl_len
> > > +	 * @count: Number of bytes to read, in multiples of @load->bl_len
> > 
> > I'm no native English speaker, but would it be easier to understand? :
> > 
> > +	 * @offset: Offset to read from in bytes, a multiple of @load->bl_len
> > +	 * @count: Number of bytes to read, a multiple of @load->bl_len
> > 
> > 
> > 
> 
> I think it would have to be worded
> 
> @offset: Offset to read from in bytes, as a multiple of @load->bl_len
> 
> but to me these both mean the same thing.
> 
> --Sean

Ah, OK. I doubted on whether it should be a comma or "as". Apparently
it was both.

They may mean the same, but I got confused by having "in bytes", and
"in multiples" so close.

"in bytes" means the value should be the correct answer to the
question "how many bytes" (not a number of bits, not a number of
sectors)

but "in multiples of..." doesn't mean the value should be the correct
answer to "how many of multiples". Should the value be a number of
sectors (first multiple of bl_len) a number of dozens of sectors
(another multiple of bl_len) or ...?

In the first part "in" introduces a unit of measure, but in the second
the same word introduces a constraint on a value. That was confusing
to me.

Not saying it doesn't mean the same or even that you should change it,
just elaborating why I said it.


^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 10/25] spl: Only support bl_len when we have to
  2023-11-06  2:25 ` [PATCH v6 10/25] spl: Only support bl_len when we have to Sean Anderson
@ 2023-11-08  4:23   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:23 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> Aligning addresses and sizes causes overhead which is unnecessary when we
> are not loading from block devices. Remove bl_len when it is not needed.
>
> For example, on iot2050 we save 144 bytes with this patch (once the rest of
> this series is applied):
>
> add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-144 (-144)
> Function                                     old     new   delta
> spl_load_simple_fit                          920     904     -16
> load_simple_fit                              496     444     -52
> spl_spi_load_image                           384     308     -76
> Total: Before=87431, After=87287, chg -0.16%
>
> We use panic() instead of BUILD_BUG_ON in spl_set_bl_len because we still
> need to be able to compile it for things like mmc_load_image_raw_sector,
> even if that function will not be used.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  arch/arm/mach-imx/spl_imx_romapi.c  |  8 ++++----
>  arch/arm/mach-sunxi/spl_spi_sunxi.c |  2 +-
>  common/spl/Kconfig                  | 14 +++++++++++++-
>  common/spl/spl_blk_fs.c             |  2 +-
>  common/spl/spl_fat.c                |  2 +-
>  common/spl/spl_fit.c                |  6 +++---
>  common/spl/spl_imx_container.c      | 10 +++++-----
>  common/spl/spl_legacy.c             |  4 ++--
>  common/spl/spl_mmc.c                |  4 ++--
>  common/spl/spl_nand.c               |  6 +++---
>  common/spl/spl_net.c                |  2 +-
>  common/spl/spl_nor.c                |  8 ++++----
>  common/spl/spl_ram.c                |  2 +-
>  common/spl/spl_semihosting.c        |  2 +-
>  common/spl/spl_spi.c                |  4 ++--
>  common/spl/spl_ymodem.c             |  2 +-
>  drivers/usb/gadget/f_sdp.c          |  4 ++--
>  include/spl.h                       | 25 +++++++++++++++++++++++++
>  test/image/Kconfig                  |  1 +
>  test/image/spl_load.c               |  9 ++++-----
>  test/image/spl_load_os.c            |  2 +-
>  21 files changed, 78 insertions(+), 41 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 09/25] spl: Remove filename from spl_load_info
  2023-11-06  2:25 ` [PATCH v6 09/25] spl: Remove filename from spl_load_info Sean Anderson
@ 2023-11-08  4:23   ` Simon Glass
  2023-11-08 15:34     ` Sean Anderson
  0 siblings, 1 reply; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:23 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> For filesystems, filename serves the same purpose as priv. However,
> spl_load_fit_image also uses it to determine whether to use a DMA-aligned
> buffer. This is beneficial for FAT, which uses a bounce-buffer if the
> destination is not DMA-aligned. Remove this logic, and instead achieve it
> by setting bl_len to ARCH_DMA_MINALIGN. With this done, we can remove
> filename entirely.
>
> One wrinkle bears mentioning: because filesystems are not block-based, we
> may read less than the size passed to spl_load_info.read. This can happen
> if the file size is not DMA-aligned. This is fine as long as we read the
> amount we originally wanted to. Modify the conditions for callers of
> spl_load_info.read to check against the original, unaligned size to avoid
> failing spuriously.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  arch/arm/mach-sunxi/spl_spi_sunxi.c |  1 -
>  common/spl/spl_blk_fs.c             | 10 ++++++----
>  common/spl/spl_fat.c                |  6 +++---
>  common/spl/spl_fit.c                | 23 +----------------------
>  common/spl/spl_imx_container.c      |  8 +++++---
>  common/spl/spl_mmc.c                |  2 --
>  common/spl/spl_nand.c               |  3 ---
>  common/spl/spl_semihosting.c        |  1 -
>  common/spl/spl_spi.c                |  2 --
>  common/spl/spl_ymodem.c             |  1 -
>  include/spl.h                       |  2 --
>  test/image/spl_load_os.c            |  1 -
>  12 files changed, 15 insertions(+), 45 deletions(-)

Er, I think

Reviewed-by: Simon Glass <sjg@chromium.org>

but I wonder if this patch could be split?

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 07/25] spl: Take advantage of bl_len's power-of-twoness
  2023-11-06  2:25 ` [PATCH v6 07/25] spl: Take advantage of bl_len's power-of-twoness Sean Anderson
@ 2023-11-08  4:23   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:23 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Fabio Estevam, Stefano Babic, uboot-imx

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> bl_len must be a power of two, so we can use ALIGN instead of roundup and
> similar tricks to avoid divisions.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  common/spl/spl_fit.c           | 2 +-
>  common/spl/spl_imx_container.c | 8 ++++----
>  2 files changed, 5 insertions(+), 5 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 06/25] spl: Remove dev from spl_load_info
  2023-11-06  2:25 ` [PATCH v6 06/25] spl: Remove dev from spl_load_info Sean Anderson
@ 2023-11-08  4:23   ` Simon Glass
  2023-11-08 16:19     ` Sean Anderson
  0 siblings, 1 reply; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:23 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

Hi Sean,

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> dev and priv server the same purpose, and are never set at the same time.

serve

> Remove dev and convert all users to priv. While we're at it, reorder bl_len
> to be last for better alignment.

It's a bit unfortunate to drop the device, isn't it? But then, as
before, this is self-contained so Is suppose it doesn't matter what we
store.

Reviewed-by: Simon Glass <sjg@chromium.org>

Regards,
Simon



>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  common/spl/spl_mmc.c       | 6 +++---
>  common/spl/spl_spi.c       | 6 +++---
>  drivers/usb/gadget/f_sdp.c | 6 +++---
>  include/spl.h              | 4 +---
>  4 files changed, 10 insertions(+), 12 deletions(-)
>
> diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
> index 6d9137c32e0..3d7551a7dae 100644
> --- a/common/spl/spl_mmc.c
> +++ b/common/spl/spl_mmc.c
> @@ -65,7 +65,7 @@ static int mmc_load_legacy(struct spl_image_info *spl_image,
>  static ulong h_spl_load_read(struct spl_load_info *load, ulong sector,
>                              ulong count, void *buf)
>  {
> -       struct mmc *mmc = load->dev;
> +       struct mmc *mmc = load->priv;
>
>         return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf);
>  }
> @@ -105,7 +105,7 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
>                 struct spl_load_info load;
>
>                 debug("Found FIT\n");
> -               load.dev = mmc;
> +               load.priv = mmc;
>                 load.filename = NULL;
>                 load.bl_len = mmc->read_bl_len;
>                 load.read = h_spl_load_read;
> @@ -114,7 +114,7 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
>                    valid_container_hdr((void *)header)) {
>                 struct spl_load_info load;
>
> -               load.dev = mmc;
> +               load.priv = mmc;
>                 load.filename = NULL;
>                 load.bl_len = mmc->read_bl_len;
>                 load.read = h_spl_load_read;
> diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
> index d83d70f2f33..af7a28e7c25 100644
> --- a/common/spl/spl_spi.c
> +++ b/common/spl/spl_spi.c
> @@ -59,7 +59,7 @@ static int spi_load_image_os(struct spl_image_info *spl_image,
>  static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector,
>                               ulong count, void *buf)
>  {
> -       struct spi_flash *flash = load->dev;
> +       struct spi_flash *flash = load->priv;
>         ulong ret;
>
>         ret = spi_flash_read(flash, sector, count, buf);
> @@ -151,7 +151,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
>                         struct spl_load_info load;
>
>                         debug("Found FIT\n");
> -                       load.dev = flash;
> +                       load.priv = flash;
>                         load.filename = NULL;
>                         load.bl_len = 1;
>                         load.read = spl_spi_fit_read;
> @@ -162,7 +162,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
>                            valid_container_hdr((void *)header)) {
>                         struct spl_load_info load;
>
> -                       load.dev = flash;
> +                       load.priv = flash;
>                         load.filename = NULL;
>                         load.bl_len = 1;
>                         load.read = spl_spi_fit_read;
> diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
> index ee9384fb37e..1b16b7eb452 100644
> --- a/drivers/usb/gadget/f_sdp.c
> +++ b/drivers/usb/gadget/f_sdp.c
> @@ -744,7 +744,7 @@ static ulong sdp_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 *)(load->dev + sector), count);
> +       memcpy(buf, (void *)(load->priv + sector), count);
>         return count;
>  }
>
> @@ -844,7 +844,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
>                                 struct spl_load_info load;
>
>                                 debug("Found FIT\n");
> -                               load.dev = header;
> +                               load.priv = header;
>                                 load.bl_len = 1;
>                                 load.read = sdp_load_read;
>                                 spl_load_simple_fit(spl_image, &load, 0,
> @@ -857,7 +857,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
>                             valid_container_hdr((void *)header)) {
>                                 struct spl_load_info load;
>
> -                               load.dev = header;
> +                               load.priv = header;
>                                 load.bl_len = 1;
>                                 load.read = sdp_load_read;
>                                 spl_load_imx_container(spl_image, &load, 0);
> diff --git a/include/spl.h b/include/spl.h
> index 8ff20adc28e..951e136b9ea 100644
> --- a/include/spl.h
> +++ b/include/spl.h
> @@ -285,16 +285,13 @@ static inline void *spl_image_fdt_addr(struct spl_image_info *info)
>  /**
>   * Information required to load data from a device
>   *
> - * @dev: Pointer to the device, e.g. struct mmc *
>   * @priv: Private data for the device
>   * @bl_len: Block length for reading in bytes
>   * @filename: Name of the fit image file.
>   * @read: Function to call to read from the device
>   */
>  struct spl_load_info {
> -       void *dev;
>         void *priv;
> -       int bl_len;
>         const char *filename;
>         /**
>          * read() - Read from device
> @@ -307,6 +304,7 @@ struct spl_load_info {
>          */
>         ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
>                       void *buf);
> +       int bl_len;
>  };
>
>  /*
> --
> 2.37.1
>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 05/25] spl: Remove NULL assignments in spl_load_info
  2023-11-06  2:25 ` [PATCH v6 05/25] spl: Remove NULL assignments in spl_load_info Sean Anderson
@ 2023-11-08  4:23   ` Simon Glass
  2023-11-08 15:30     ` Sean Anderson
  0 siblings, 1 reply; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:23 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

Hi Sean,

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> Remove NULL assignments to fields in spl_load_info when .load doesn't
> reference these fields. This can result in more efficient code. filename
> must stay even if it is unused, since load_simple_fit uses it.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  arch/arm/mach-sunxi/spl_spi_sunxi.c | 2 --
>  common/spl/spl_fat.c                | 1 -
>  common/spl/spl_mmc.c                | 2 --
>  common/spl/spl_nand.c               | 4 ----
>  common/spl/spl_spi.c                | 2 --
>  common/spl/spl_ymodem.c             | 1 -
>  6 files changed, 12 deletions(-)

This makes me wonder if we should have a function to clear it out
(using memset() and perhaps a bl_len parameter)? Having said that, the
info-field use is pretty self-contained with these files.

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 04/25] spl: semihosting: Don't close fd before spl_load_simple_fit
  2023-11-06  2:25 ` [PATCH v6 04/25] spl: semihosting: Don't close fd before spl_load_simple_fit Sean Anderson
@ 2023-11-08  4:23   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:23 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> On real hardware, semihosting calls tends to have a large constant
> overhead (on the order of tens of milliseconds). Reduce the number of
> calls by one by reusing the existing fd in smh_fit_read, and closing it
> at the end of spl_smh_load_image.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  common/spl/spl_semihosting.c | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 03/25] spl: Make SHOW_ERRORS depend on LIBCOMMON
  2023-11-06  2:25 ` [PATCH v6 03/25] spl: Make SHOW_ERRORS depend on LIBCOMMON Sean Anderson
@ 2023-11-08  4:23   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:23 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> The purpose of SHOW_ERRORS is to print extra information. Make it depend
> on LIBCOMMON to avoid having to check for two configs.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> ---
>
> (no changes since v5)
>
> Changes in v5:
> - New
>
>  common/spl/Kconfig | 1 +
>  common/spl/spl.c   | 3 +--
>  2 files changed, 2 insertions(+), 2 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 01/25] spl: blk_fs: Fix uninitialized return value when we can't get a blk_desc
  2023-11-06  2:25 ` [PATCH v6 01/25] spl: blk_fs: Fix uninitialized return value when we can't get a blk_desc Sean Anderson
@ 2023-11-08  4:23   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:23 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Mayuresh Chitale

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> Initialize ret to avoid returning garbage if blk_get_devnum_by_uclass_id
> fails.
>
> Fixes: 8ce6a2e1757 ("spl: blk: Support loading images from fs")
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  common/spl/spl_blk_fs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 11/25] spl: nand: Remove spl_nand_legacy_read
  2023-11-06  2:25 ` [PATCH v6 11/25] spl: nand: Remove spl_nand_legacy_read Sean Anderson
@ 2023-11-08  4:23   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:23 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Dario Binacchi, Michael Trimarchi

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> Now that spl_nand_fit_read works in units of bytes, it can be combined with
> spl_nand_legacy_read. Rename the resulting function spl_nand_read, since it
> is no longer FIT-specific.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  common/spl/spl_nand.c | 33 +++++++++++++--------------------
>  1 file changed, 13 insertions(+), 20 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 12/25] spl: legacy: Split off LZMA decompression into its own function
  2023-11-06  2:25 ` [PATCH v6 12/25] spl: legacy: Split off LZMA decompression into its own function Sean Anderson
@ 2023-11-08  4:23   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:23 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> To allow for easier reuse of this functionality, split it off into its
> own function.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  common/spl/spl_legacy.c | 73 ++++++++++++++++++++++-------------------
>  include/spl.h           | 13 ++++++++
>  2 files changed, 52 insertions(+), 34 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 13/25] test: spl: Support testing LEGACY_LZMA filesystem images
  2023-11-06  2:25 ` [PATCH v6 13/25] test: spl: Support testing LEGACY_LZMA filesystem images Sean Anderson
@ 2023-11-08  4:23   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:23 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> These will soon be supported, so we need to be able to test it. Export the
> lzma data and generally use the same process in spl_test_mmc_fs as
> do_spl_test_load.  If we end up needing this in third place in the future,
> it would probably be good to refactor things out.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  include/test/spl.h       |  4 ++++
>  test/image/spl_load.c    |  4 +++-
>  test/image/spl_load_fs.c | 23 ++++++++++++++++++-----
>  3 files changed, 25 insertions(+), 6 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 14/25] spl: Add generic spl_load function
  2023-11-06  2:25 ` [PATCH v6 14/25] spl: Add generic spl_load function Sean Anderson
@ 2023-11-08  4:23   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:23 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> Implementers of SPL_LOAD_IMAGE_METHOD have to correctly determine what
> type of image is being loaded and then call the appropriate image load
> function correctly. This is tricky, because some image load functions
> expect the whole image to already be loaded (CONFIG_SPL_LOAD_FIT_FULL),
> some will load the image automatically using spl_load_info.read()
> (CONFIG_SPL_LOAD_FIT/CONFIG_SPL_LOAD_IMX_CONTAINER), and some just parse
> the header and expect the caller to do the actual loading afterwards
> (legacy/raw images). Load methods often only support a subset of the
> above methods, meaning that not all image types can be used with all
> load methods. Further, the code to invoke these functions is
> duplicated between different load functions.
>
> To address this problem, this commit introduces a "spl_load" function.
> It aims to handle image detection and correct invocation of each of the
> parse/load functions.
>
> Although this function generally results in a size reduction with
> several users, it tends to bloat boards with only a single user.
> This is generally because programmers open-coding the contents of this
> function can make optimizations based on the specific loader. For
> example, NOR flash is memory-mapped, so it never bothers calling
> load->read. The compiler can't really make these optimizations across
> translation units. LTO solves this, but it is only available on some
> arches. To address this, perform "pseudo-LTO" by inlining spl_load when
> there are one or fewer users. At the moment, there are no users, so
> define SPL_LOAD_USERS to be 0.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - Use pseudo-LTO for spl_load
> - Align reads to bl_len
>
> Changes in v5:
> - Load the header in spl_load as well
> - Don't bother trying to DMA-align the buffer, since we can't really fix
>   it.
>
> Changes in v4:
> - Fix format specifiers in debug prints
> - Reword/fix some of the doc comments for spl_load
>
> Changes in v3:
> - Fix using ffs instead of fls
> - Fix using not initializing bl_len when info->filename was NULL
>
> Changes in v2:
> - Use reverse-xmas-tree style for locals in spl_simple_read. This is not
>   complete, since overhead depends on bl_mask.
>
>  common/spl/spl.c   |  10 ++++
>  include/spl_load.h | 135 +++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 145 insertions(+)
>  create mode 100644 include/spl_load.h
>

Reviewed-by: Simon Glass <sjg@chromium.org>

Definitely a lot of effort on code size!

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 15/25] spl: Convert ext to use spl_load
  2023-11-06  2:25 ` [PATCH v6 15/25] spl: Convert ext to use spl_load Sean Anderson
@ 2023-11-08  4:24   ` Simon Glass
  2023-11-08 15:37     ` Sean Anderson
  0 siblings, 1 reply; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:24 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

Hi Sean,

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> This converts the ext load method to use spl_load. As a consequence, it
> also adds support for FIT and IMX images.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - Explicitly initialize load_info members
>
> Changes in v5:
> - Rework to load header in spl_load
>
>  common/spl/spl_ext.c     | 36 ++++++++++++++++++------------------
>  include/spl_load.h       |  1 +
>  test/image/spl_load_fs.c |  9 ++++++---
>  3 files changed, 25 insertions(+), 21 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

but nit below

>
> diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c
> index af836ca15b8..d280b69c387 100644
> --- a/common/spl/spl_ext.c
> +++ b/common/spl/spl_ext.c
> @@ -2,25 +2,35 @@
>
>  #include <common.h>
>  #include <env.h>
> -#include <mapmem.h>
>  #include <part.h>
>  #include <spl.h>
> +#include <spl_load.h>
>  #include <asm/u-boot.h>
>  #include <ext4fs.h>
>  #include <errno.h>
>  #include <image.h>
>
> +static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
> +                         ulong size, void *buf)
> +{
> +       int ret;
> +       loff_t actlen;
> +
> +       ret = ext4fs_read(buf, file_offset, size, &actlen);
> +       if (ret)
> +               return ret;
> +       return actlen;
> +}
> +
>  int spl_load_image_ext(struct spl_image_info *spl_image,
>                        struct spl_boot_device *bootdev,
>                        struct blk_desc *block_dev, int partition,
>                        const char *filename)
>  {
>         s32 err;
> -       struct legacy_img_hdr *header;
> -       loff_t filelen, actlen;
> +       loff_t filelen;
>         struct disk_partition part_info = {};
> -
> -       header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
> +       struct spl_load_info load;
>
>         if (part_get_info(block_dev, partition, &part_info)) {
>                 printf("spl: no partition table found\n");
> @@ -42,20 +52,10 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
>                 puts("spl: ext4fs_open failed\n");
>                 goto end;
>         }
> -       err = ext4fs_read((char *)header, 0, sizeof(struct legacy_img_hdr), &actlen);
> -       if (err < 0) {
> -               puts("spl: ext4fs_read failed\n");
> -               goto end;
> -       }
>
> -       err = spl_parse_image_header(spl_image, bootdev, header);
> -       if (err < 0) {
> -               puts("spl: ext: failed to parse image header\n");
> -               goto end;
> -       }
> -
> -       err = ext4fs_read(map_sysmem(spl_image->load_addr, filelen), 0, filelen,
> -                         &actlen);
> +       spl_set_bl_len(&load, 1);
> +       load.read = spl_fit_read;
> +       err = spl_load(spl_image, bootdev, &load, filelen, 0);
>
>  end:
>  #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
> diff --git a/include/spl_load.h b/include/spl_load.h
> index 406f8b577b2..65aa6bb4493 100644
> --- a/include/spl_load.h
> +++ b/include/spl_load.h
> @@ -95,6 +95,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
>   * inline if there is one caller, and extern otherwise.
>   */
>  #define SPL_LOAD_USERS \
> +       IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
>         0
>
>  #if SPL_LOAD_USERS > 1
> diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
> index 59d0244d44b..01559e98c4f 100644
> --- a/test/image/spl_load_fs.c
> +++ b/test/image/spl_load_fs.c
> @@ -422,20 +422,23 @@ static int spl_test_mmc(struct unit_test_state *uts, const char *test_name,
>         spl_mmc_clear_cache();
>         spl_fat_force_reregister();
>
> -       if (type == LEGACY &&
> -           spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
> +       if (spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
>                 return CMD_RET_FAILURE;
>
> -       if (type != IMX8 &&
> +       if (type != IMX8 && type != LEGACY_LZMA &&
>             spl_test_mmc_fs(uts, test_name, type, create_fat, false))
>                 return CMD_RET_FAILURE;

This is not a command.

How about:

if (type != IMX8 && type != LEGACY_LZMA &&
   ut_assertok(spl_test_mmc_fs(...

>
> +       if (type == LEGACY_LZMA)
> +               return 0;
> +
>         return do_spl_test_load(uts, test_name, type,
>                                 SPL_LOAD_IMAGE_GET(0, BOOT_DEVICE_MMC1,
>                                                    spl_mmc_load_image),
>                                 spl_test_mmc_write_image);
>  }
>  SPL_IMG_TEST(spl_test_mmc, LEGACY, DM_FLAGS);
> +SPL_IMG_TEST(spl_test_mmc, LEGACY_LZMA, DM_FLAGS);
>  SPL_IMG_TEST(spl_test_mmc, IMX8, DM_FLAGS);
>  SPL_IMG_TEST(spl_test_mmc, FIT_EXTERNAL, DM_FLAGS);
>  SPL_IMG_TEST(spl_test_mmc, FIT_INTERNAL, DM_FLAGS);
> --
> 2.37.1
>

Regards,
Simon

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 16/25] spl: Convert fat to spl_load
  2023-11-06  2:25 ` [PATCH v6 16/25] spl: Convert fat to spl_load Sean Anderson
@ 2023-11-08  4:24   ` Simon Glass
  2023-11-08 15:49     ` Sean Anderson
  0 siblings, 1 reply; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:24 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

Hi Sean,

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> This converts the fat loader to use spl_load. Some platforms are very
> tight on space, so we take care to only include the code we really need.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> (no changes since v5)
>
> Changes in v5:
> - Rework to load header in spl_load
>
> Changes in v3:
> - Fix failing on success
>
>  common/spl/spl_fat.c     | 56 +++++++++++++---------------------------
>  include/spl_load.h       |  1 +
>  test/image/spl_load_fs.c |  3 +--
>  3 files changed, 20 insertions(+), 40 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

nits below

>
> diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
> index a0c34eba48f..569f2b32928 100644
> --- a/common/spl/spl_fat.c
> +++ b/common/spl/spl_fat.c
> @@ -11,8 +11,8 @@
>  #include <common.h>
>  #include <env.h>
>  #include <log.h>
> -#include <mapmem.h>
>  #include <spl.h>
> +#include <spl_load.h>
>  #include <asm/u-boot.h>
>  #include <fat.h>
>  #include <errno.h>
> @@ -66,58 +66,38 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
>                        const char *filename)
>  {
>         int err;
> -       struct legacy_img_hdr *header;
> +       loff_t size;
> +       struct spl_load_info load;
>
>         err = spl_register_fat_device(block_dev, partition);
>         if (err)
>                 goto end;
>
> -       header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
> -
> -       err = file_fat_read(filename, header, sizeof(struct legacy_img_hdr));
> -       if (err <= 0)
> -               goto end;
> -
> -       if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
> -           image_get_magic(header) == FDT_MAGIC) {
> -               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,
> -                                            map_sysmem(CONFIG_SYS_LOAD_ADDR,
> -                                                       err));
> -               if (err == -EAGAIN)
> -                       return err;
> -               if (err == 0)
> -                       err = 1;
> -       } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
> -           image_get_magic(header) == FDT_MAGIC) {
> -               struct spl_load_info load;
> -
> -               debug("Found FIT\n");
> -               load.read = spl_fit_read;
> -               spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
> -               load.priv = (void *)filename;
> -
> -               return spl_load_simple_fit(spl_image, &load, 0, header);
> -       } else {
> -               err = spl_parse_image_header(spl_image, bootdev, header);
> +       /*
> +        * Avoid pulling in this function for other image types since we are
> +        * very short on space on some boards.
> +        */
> +       if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)) {
> +               err = fat_size(filename, &size);
>                 if (err)
>                         goto end;
> -
> -               err = file_fat_read(filename, map_sysmem(spl_image->load_addr,
> -                                                        spl_image->size), 0);
> +       } else {
> +               size = 0;
>         }
>
> +       load.read = spl_fit_read;
> +       spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
> +       load.priv = (void *)filename;
> +       err = spl_load(spl_image, bootdev, &load, size, 0);
> +
>  end:
>  #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
> -       if (err <= 0)
> +       if (err < 0)
>                 printf("%s: error reading image %s, err - %d\n",
>                        __func__, filename, err);

Do we still need this sort of #ifdef? I thought printf() would melt
away without SPL_LIBCOMMON_SUPPORT? I haven't looked though. Also it
isn't related to your patch.

>  #endif
>
> -       return (err <= 0);
> +       return err;
>  }
>
>  #if CONFIG_IS_ENABLED(OS_BOOT)
> diff --git a/include/spl_load.h b/include/spl_load.h
> index 65aa6bb4493..5e0460d956d 100644
> --- a/include/spl_load.h
> +++ b/include/spl_load.h
> @@ -96,6 +96,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
>   */
>  #define SPL_LOAD_USERS \
>         IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
> +       IS_ENABLED(CONFIG_SPL_FS_FAT) + \
>         0
>
>  #if SPL_LOAD_USERS > 1
> diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
> index 01559e98c4f..333df2dfb53 100644
> --- a/test/image/spl_load_fs.c
> +++ b/test/image/spl_load_fs.c
> @@ -425,8 +425,7 @@ static int spl_test_mmc(struct unit_test_state *uts, const char *test_name,
>         if (spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
>                 return CMD_RET_FAILURE;
>
> -       if (type != IMX8 && type != LEGACY_LZMA &&
> -           spl_test_mmc_fs(uts, test_name, type, create_fat, false))
> +       if (spl_test_mmc_fs(uts, test_name, type, create_fat, false))
>                 return CMD_RET_FAILURE;
>
>         if (type == LEGACY_LZMA)
> --
> 2.37.1
>

Regards,
Simon

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 18/25] spl: Convert nand to spl_load
  2023-11-06  2:25 ` [PATCH v6 18/25] spl: Convert nand " Sean Anderson
@ 2023-11-08  4:24   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:24 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Dario Binacchi, Michael Trimarchi

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> This converts the nand load method to use spl_load. nand_page_size may not
> be valid until after nand_spl_load_image is called (see e.g. fsl_ifc_spl),
> so we set bl_len in spl_nand_read. Since spl_load reads the header for us,
> we can remove that argument from spl_nand_load_element.
>
> There are two possible regressions which could result from this commit.
> First, we ask for a negative address from spl_get_load_buffer. That is,
> instead of
>
>         header = spl_get_load_buffer(0, sizeof(*header));
>
> we do
>
>         header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
>
> this could cause a problem if spl_get_load_buffer does not return valid
> memory for negative offsets. Second, we now set bl_len for legacy images.
> This can cause memory up to a bl_len - 1 before the image load address to
> be written, which might not have been the case before. If this turns out to
> be a problem, we can add an option for a bounce buffer.
>
> We can't load FITs with external data with SPL_LOAD_FIT_FULL, so disable the
> test in that case. No boards enable SPL_NAND_SUPPORT and SPL_LOAD_FIT_FULL, so
> this is not a regression.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  common/spl/spl_nand.c      | 70 +++++++++-----------------------------
>  include/spl_load.h         |  1 +
>  test/image/spl_load_nand.c |  2 ++
>  3 files changed, 19 insertions(+), 54 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 17/25] spl: Convert mmc to spl_load
  2023-11-06  2:25 ` [PATCH v6 17/25] spl: Convert mmc " Sean Anderson
@ 2023-11-08  4:24   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:24 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Jaehoon Chung, Peng Fan

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> This converts the mmc loader to spl_load. Legacy images are handled by
> spl_load (via spl_parse_image_header), so mmc_load_legacy can be
> omitted. To accurately determine whether mmc_load_image_raw_sector is used
> (which might not be the case if SYS_MMCSD_FS_BOOT is enabled), we introduce
> a helper config SYS_MMCSD_RAW_MODE. This ensures we can inline spl_load
> correctly when a board only boots from filesystems. We still need to check
> for SPL_MMC, since some boards enable configure raw mode even without MMC
> support.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - Add SYS_MMCSD_RAW_MODE to help determine whether SPL_MMC loads
>   anything directly.
> - Explicitly initialize load_info members
>
> Changes in v5:
> - Rework to load header in spl_load
>
>  common/spl/Kconfig       |  8 ++++
>  common/spl/spl_mmc.c     | 89 ++++------------------------------------
>  include/spl_load.h       |  1 +
>  test/image/spl_load_fs.c |  3 --
>  4 files changed, 16 insertions(+), 85 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 19/25] spl: Convert net to spl_load
  2023-11-06  2:25 ` [PATCH v6 19/25] spl: Convert net " Sean Anderson
@ 2023-11-08  4:24   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:24 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Joe Hershberger, Ramon Fried

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> This converts the net load method to use spl_load. As a result, it also
> adds support for LOAD_FIT_FULL and IMX images.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - Explicitly initialize load_info members
>
> Changes in v5:
> - Rework to load header in spl_load
>
>  common/spl/spl_net.c      | 29 +++++------------------------
>  include/spl_load.h        |  1 +
>  test/image/spl_load_net.c |  2 ++
>  3 files changed, 8 insertions(+), 24 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 20/25] spl: Convert nor to spl_load
  2023-11-06  2:25 ` [PATCH v6 20/25] spl: Convert nor " Sean Anderson
@ 2023-11-08  4:24   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:24 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> This converts the nor load method to use spl_load. As a result it also
> adds support for LOAD_FIT_FULL. Since this is the last caller of
> spl_load_legacy_img, it has been removed.
>
> We can't load FITs with external data with SPL_LOAD_FIT_FULL, so disable the
> test in that case. No boards enable SPL_NOR_SUPPORT and SPL_LOAD_FIT_FULL, so
> this is not a regression.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - Fix LZMA support
> - Fix load address
> - Explicitly initialize load_info members
>
> Changes in v5:
> - Rework to load header in spl_load
>
>  common/spl/spl_legacy.c   | 61 ---------------------------------------
>  common/spl/spl_nor.c      | 40 +++++--------------------
>  include/spl_load.h        |  1 +
>  test/image/spl_load_nor.c |  2 ++
>  4 files changed, 10 insertions(+), 94 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 21/25] spl: Convert NVMe to spl_load
  2023-11-06  2:25 ` [PATCH v6 21/25] spl: Convert NVMe " Sean Anderson
@ 2023-11-08  4:24   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:24 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Mayuresh Chitale

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> This converts the blk load method (used exclusively by NVMe) to use
> spl_load. As a consequence, it also adds support for LOAD_FIT_FULL and
> IMX images.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - Fix invalid return from spl_blk_load_image
> - Explicitly initialize load_info members
>
> Changes in v5:
> - New
>
>  common/spl/spl_blk_fs.c  | 66 +++++++---------------------------------
>  include/spl_load.h       |  1 +
>  test/image/spl_load_fs.c |  2 ++
>  3 files changed, 14 insertions(+), 55 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 23/25] spl: Convert spi to spl_load
  2023-11-06  2:26 ` [PATCH v6 23/25] spl: Convert spi " Sean Anderson
@ 2023-11-08  4:24   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:24 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Jagan Teki, Vignesh R

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> This converts the spi load method to use spl_load. The address used for
> LOAD_FIT_FULL may be different, but there are no in-tree users of that
> config. Since payload_offs is only used without OS_BOOT, we defer its
> initialization.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - Fix soft reset after loading from SPI
>
> Changes in v5:
> - Rework to load header in spl_load
>
>  common/spl/spl_spi.c      | 80 +++++++--------------------------------
>  include/spl_load.h        |  1 +
>  test/image/spl_load_spi.c |  1 +
>  3 files changed, 15 insertions(+), 67 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

I am just amazed at how many times this FIT code got copied...there is
something wrong with U-Boot's development model here.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 24/25] spl: spi: Consolidate spi_load_image_os into spl_spi_load_image
  2023-11-06  2:26 ` [PATCH v6 24/25] spl: spi: Consolidate spi_load_image_os into spl_spi_load_image Sean Anderson
@ 2023-11-08  4:24   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:24 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár,
	Jagan Teki, Nathan Barrett-Morrison, Vignesh R

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> spi_load_image_os performs almost the same steps as the non-falcon-boot
> path of spl_spi_load_image. The load address is different, and it also
> loads a device tree, but that's it. Refactor the boot process so that
> they can both use the same load function.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> (no changes since v5)
>
> Changes in v5:
> - Rework to load header in spl_load
>
> Changes in v2:
> - New
>
>  common/spl/spl_spi.c | 54 ++++++++++++--------------------------------
>  1 file changed, 14 insertions(+), 40 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 25/25] spl: fat: Add option to disable DMA alignment
  2023-11-06  2:26 ` [PATCH v6 25/25] spl: fat: Add option to disable DMA alignment Sean Anderson
@ 2023-11-08  4:24   ` Simon Glass
  0 siblings, 0 replies; 62+ messages in thread
From: Simon Glass @ 2023-11-08  4:24 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>
> If we don't DMA-align buffers we pass to FAT, it will align them itself.
> This behaviour likely should be deprecated in favor of
> CONFIG_BOUNCE_BUFFER, but that's a task for another series. For the
> meantime, don't bother aligning the buffer unless we had been doing so in
> the past.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> ---
>
> Changes in v6:
> - New
>
>  common/spl/Kconfig      | 18 ++++++++++++++++--
>  common/spl/spl_blk_fs.c |  5 ++++-
>  common/spl/spl_fat.c    |  5 ++++-
>  3 files changed, 24 insertions(+), 4 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 05/25] spl: Remove NULL assignments in spl_load_info
  2023-11-08  4:23   ` Simon Glass
@ 2023-11-08 15:30     ` Sean Anderson
  0 siblings, 0 replies; 62+ messages in thread
From: Sean Anderson @ 2023-11-08 15:30 UTC (permalink / raw)
  To: Simon Glass
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

On 11/7/23 23:23, Simon Glass wrote:
> Hi Sean,
> 
> On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>>
>> Remove NULL assignments to fields in spl_load_info when .load doesn't
>> reference these fields. This can result in more efficient code. filename
>> must stay even if it is unused, since load_simple_fit uses it.
>>
>> Signed-off-by: Sean Anderson <seanga2@gmail.com>
>> ---
>>
>> Changes in v6:
>> - New
>>
>>   arch/arm/mach-sunxi/spl_spi_sunxi.c | 2 --
>>   common/spl/spl_fat.c                | 1 -
>>   common/spl/spl_mmc.c                | 2 --
>>   common/spl/spl_nand.c               | 4 ----
>>   common/spl/spl_spi.c                | 2 --
>>   common/spl/spl_ymodem.c             | 1 -
>>   6 files changed, 12 deletions(-)
> 
> This makes me wonder if we should have a function to clear it out
> (using memset() and perhaps a bl_len parameter)? Having said that, the
> info-field use is pretty self-contained with these files.
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>

It would be simpler, but this series causes bloat in other areas and this
is a very simple way to reduce text size.

--Sean

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 09/25] spl: Remove filename from spl_load_info
  2023-11-08  4:23   ` Simon Glass
@ 2023-11-08 15:34     ` Sean Anderson
  0 siblings, 0 replies; 62+ messages in thread
From: Sean Anderson @ 2023-11-08 15:34 UTC (permalink / raw)
  To: Simon Glass
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese

On 11/7/23 23:23, Simon Glass wrote:
> On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>>
>> For filesystems, filename serves the same purpose as priv. However,
>> spl_load_fit_image also uses it to determine whether to use a DMA-aligned
>> buffer. This is beneficial for FAT, which uses a bounce-buffer if the
>> destination is not DMA-aligned. Remove this logic, and instead achieve it
>> by setting bl_len to ARCH_DMA_MINALIGN. With this done, we can remove
>> filename entirely.
>>
>> One wrinkle bears mentioning: because filesystems are not block-based, we
>> may read less than the size passed to spl_load_info.read. This can happen
>> if the file size is not DMA-aligned. This is fine as long as we read the
>> amount we originally wanted to. Modify the conditions for callers of
>> spl_load_info.read to check against the original, unaligned size to avoid
>> failing spuriously.
>>
>> Signed-off-by: Sean Anderson <seanga2@gmail.com>
>> ---
>>
>> Changes in v6:
>> - New
>>
>>   arch/arm/mach-sunxi/spl_spi_sunxi.c |  1 -
>>   common/spl/spl_blk_fs.c             | 10 ++++++----
>>   common/spl/spl_fat.c                |  6 +++---
>>   common/spl/spl_fit.c                | 23 +----------------------
>>   common/spl/spl_imx_container.c      |  8 +++++---
>>   common/spl/spl_mmc.c                |  2 --
>>   common/spl/spl_nand.c               |  3 ---
>>   common/spl/spl_semihosting.c        |  1 -
>>   common/spl/spl_spi.c                |  2 --
>>   common/spl/spl_ymodem.c             |  1 -
>>   include/spl.h                       |  2 --
>>   test/image/spl_load_os.c            |  1 -
>>   12 files changed, 15 insertions(+), 45 deletions(-)
> 
> Er, I think
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> but I wonder if this patch could be split?

Into the filesystem bl_len stuff and the removal of filename? Yeah, probably.

--Sean

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 15/25] spl: Convert ext to use spl_load
  2023-11-08  4:24   ` Simon Glass
@ 2023-11-08 15:37     ` Sean Anderson
  0 siblings, 0 replies; 62+ messages in thread
From: Sean Anderson @ 2023-11-08 15:37 UTC (permalink / raw)
  To: Simon Glass
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese, Pali Rohár

On 11/7/23 23:24, Simon Glass wrote:
> Hi Sean,
> 
> On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>>
>> This converts the ext load method to use spl_load. As a consequence, it
>> also adds support for FIT and IMX images.
>>
>> Signed-off-by: Sean Anderson <seanga2@gmail.com>
>> ---
>>
>> Changes in v6:
>> - Explicitly initialize load_info members
>>
>> Changes in v5:
>> - Rework to load header in spl_load
>>
>>   common/spl/spl_ext.c     | 36 ++++++++++++++++++------------------
>>   include/spl_load.h       |  1 +
>>   test/image/spl_load_fs.c |  9 ++++++---
>>   3 files changed, 25 insertions(+), 21 deletions(-)
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> but nit below
> 
>>
>> diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c
>> index af836ca15b8..d280b69c387 100644
>> --- a/common/spl/spl_ext.c
>> +++ b/common/spl/spl_ext.c
>> @@ -2,25 +2,35 @@
>>
>>   #include <common.h>
>>   #include <env.h>
>> -#include <mapmem.h>
>>   #include <part.h>
>>   #include <spl.h>
>> +#include <spl_load.h>
>>   #include <asm/u-boot.h>
>>   #include <ext4fs.h>
>>   #include <errno.h>
>>   #include <image.h>
>>
>> +static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
>> +                         ulong size, void *buf)
>> +{
>> +       int ret;
>> +       loff_t actlen;
>> +
>> +       ret = ext4fs_read(buf, file_offset, size, &actlen);
>> +       if (ret)
>> +               return ret;
>> +       return actlen;
>> +}
>> +
>>   int spl_load_image_ext(struct spl_image_info *spl_image,
>>                         struct spl_boot_device *bootdev,
>>                         struct blk_desc *block_dev, int partition,
>>                         const char *filename)
>>   {
>>          s32 err;
>> -       struct legacy_img_hdr *header;
>> -       loff_t filelen, actlen;
>> +       loff_t filelen;
>>          struct disk_partition part_info = {};
>> -
>> -       header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
>> +       struct spl_load_info load;
>>
>>          if (part_get_info(block_dev, partition, &part_info)) {
>>                  printf("spl: no partition table found\n");
>> @@ -42,20 +52,10 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
>>                  puts("spl: ext4fs_open failed\n");
>>                  goto end;
>>          }
>> -       err = ext4fs_read((char *)header, 0, sizeof(struct legacy_img_hdr), &actlen);
>> -       if (err < 0) {
>> -               puts("spl: ext4fs_read failed\n");
>> -               goto end;
>> -       }
>>
>> -       err = spl_parse_image_header(spl_image, bootdev, header);
>> -       if (err < 0) {
>> -               puts("spl: ext: failed to parse image header\n");
>> -               goto end;
>> -       }
>> -
>> -       err = ext4fs_read(map_sysmem(spl_image->load_addr, filelen), 0, filelen,
>> -                         &actlen);
>> +       spl_set_bl_len(&load, 1);
>> +       load.read = spl_fit_read;
>> +       err = spl_load(spl_image, bootdev, &load, filelen, 0);
>>
>>   end:
>>   #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
>> diff --git a/include/spl_load.h b/include/spl_load.h
>> index 406f8b577b2..65aa6bb4493 100644
>> --- a/include/spl_load.h
>> +++ b/include/spl_load.h
>> @@ -95,6 +95,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
>>    * inline if there is one caller, and extern otherwise.
>>    */
>>   #define SPL_LOAD_USERS \
>> +       IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
>>          0
>>
>>   #if SPL_LOAD_USERS > 1
>> diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
>> index 59d0244d44b..01559e98c4f 100644
>> --- a/test/image/spl_load_fs.c
>> +++ b/test/image/spl_load_fs.c
>> @@ -422,20 +422,23 @@ static int spl_test_mmc(struct unit_test_state *uts, const char *test_name,
>>          spl_mmc_clear_cache();
>>          spl_fat_force_reregister();
>>
>> -       if (type == LEGACY &&
>> -           spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
>> +       if (spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
>>                  return CMD_RET_FAILURE;
>>
>> -       if (type != IMX8 &&
>> +       if (type != IMX8 && type != LEGACY_LZMA &&
>>              spl_test_mmc_fs(uts, test_name, type, create_fat, false))
>>                  return CMD_RET_FAILURE;
> 
> This is not a command.
> 
> How about:
> 
> if (type != IMX8 && type != LEGACY_LZMA &&
>     ut_assertok(spl_test_mmc_fs(...

There are already assertions in spl_test_mmc_fs. So if we fail here, we
already have something printed on the console.

--Sean

>>
>> +       if (type == LEGACY_LZMA)
>> +               return 0;
>> +
>>          return do_spl_test_load(uts, test_name, type,
>>                                  SPL_LOAD_IMAGE_GET(0, BOOT_DEVICE_MMC1,
>>                                                     spl_mmc_load_image),
>>                                  spl_test_mmc_write_image);
>>   }
>>   SPL_IMG_TEST(spl_test_mmc, LEGACY, DM_FLAGS);
>> +SPL_IMG_TEST(spl_test_mmc, LEGACY_LZMA, DM_FLAGS);
>>   SPL_IMG_TEST(spl_test_mmc, IMX8, DM_FLAGS);
>>   SPL_IMG_TEST(spl_test_mmc, FIT_EXTERNAL, DM_FLAGS);
>>   SPL_IMG_TEST(spl_test_mmc, FIT_INTERNAL, DM_FLAGS);
>> --
>> 2.37.1
>>
> 
> Regards,
> Simon


^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 16/25] spl: Convert fat to spl_load
  2023-11-08  4:24   ` Simon Glass
@ 2023-11-08 15:49     ` Sean Anderson
  0 siblings, 0 replies; 62+ messages in thread
From: Sean Anderson @ 2023-11-08 15:49 UTC (permalink / raw)
  To: Simon Glass
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese

On 11/7/23 23:24, Simon Glass wrote:
> Hi Sean,
> 
> On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>>
>> This converts the fat loader to use spl_load. Some platforms are very
>> tight on space, so we take care to only include the code we really need.
>>
>> Signed-off-by: Sean Anderson <seanga2@gmail.com>
>> ---
>>
>> (no changes since v5)
>>
>> Changes in v5:
>> - Rework to load header in spl_load
>>
>> Changes in v3:
>> - Fix failing on success
>>
>>   common/spl/spl_fat.c     | 56 +++++++++++++---------------------------
>>   include/spl_load.h       |  1 +
>>   test/image/spl_load_fs.c |  3 +--
>>   3 files changed, 20 insertions(+), 40 deletions(-)
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> nits below
> 
>>
>> diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
>> index a0c34eba48f..569f2b32928 100644
>> --- a/common/spl/spl_fat.c
>> +++ b/common/spl/spl_fat.c
>> @@ -11,8 +11,8 @@
>>   #include <common.h>
>>   #include <env.h>
>>   #include <log.h>
>> -#include <mapmem.h>
>>   #include <spl.h>
>> +#include <spl_load.h>
>>   #include <asm/u-boot.h>
>>   #include <fat.h>
>>   #include <errno.h>
>> @@ -66,58 +66,38 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
>>                         const char *filename)
>>   {
>>          int err;
>> -       struct legacy_img_hdr *header;
>> +       loff_t size;
>> +       struct spl_load_info load;
>>
>>          err = spl_register_fat_device(block_dev, partition);
>>          if (err)
>>                  goto end;
>>
>> -       header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
>> -
>> -       err = file_fat_read(filename, header, sizeof(struct legacy_img_hdr));
>> -       if (err <= 0)
>> -               goto end;
>> -
>> -       if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
>> -           image_get_magic(header) == FDT_MAGIC) {
>> -               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,
>> -                                            map_sysmem(CONFIG_SYS_LOAD_ADDR,
>> -                                                       err));
>> -               if (err == -EAGAIN)
>> -                       return err;
>> -               if (err == 0)
>> -                       err = 1;
>> -       } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
>> -           image_get_magic(header) == FDT_MAGIC) {
>> -               struct spl_load_info load;
>> -
>> -               debug("Found FIT\n");
>> -               load.read = spl_fit_read;
>> -               spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
>> -               load.priv = (void *)filename;
>> -
>> -               return spl_load_simple_fit(spl_image, &load, 0, header);
>> -       } else {
>> -               err = spl_parse_image_header(spl_image, bootdev, header);
>> +       /*
>> +        * Avoid pulling in this function for other image types since we are
>> +        * very short on space on some boards.
>> +        */
>> +       if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)) {
>> +               err = fat_size(filename, &size);
>>                  if (err)
>>                          goto end;
>> -
>> -               err = file_fat_read(filename, map_sysmem(spl_image->load_addr,
>> -                                                        spl_image->size), 0);
>> +       } else {
>> +               size = 0;
>>          }
>>
>> +       load.read = spl_fit_read;
>> +       spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
>> +       load.priv = (void *)filename;
>> +       err = spl_load(spl_image, bootdev, &load, size, 0);
>> +
>>   end:
>>   #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
>> -       if (err <= 0)
>> +       if (err < 0)
>>                  printf("%s: error reading image %s, err - %d\n",
>>                         __func__, filename, err);
> 
> Do we still need this sort of #ifdef? I thought printf() would melt
> away without SPL_LIBCOMMON_SUPPORT? I haven't looked though. Also it
> isn't related to your patch.

 From what I can tell, printf implementation is orthogonal to LIBCOMMON_SUPPORT.

--Sean

>>   #endif
>>
>> -       return (err <= 0);
>> +       return err;
>>   }
>>
>>   #if CONFIG_IS_ENABLED(OS_BOOT)
>> diff --git a/include/spl_load.h b/include/spl_load.h
>> index 65aa6bb4493..5e0460d956d 100644
>> --- a/include/spl_load.h
>> +++ b/include/spl_load.h
>> @@ -96,6 +96,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
>>    */
>>   #define SPL_LOAD_USERS \
>>          IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
>> +       IS_ENABLED(CONFIG_SPL_FS_FAT) + \
>>          0
>>
>>   #if SPL_LOAD_USERS > 1
>> diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
>> index 01559e98c4f..333df2dfb53 100644
>> --- a/test/image/spl_load_fs.c
>> +++ b/test/image/spl_load_fs.c
>> @@ -425,8 +425,7 @@ static int spl_test_mmc(struct unit_test_state *uts, const char *test_name,
>>          if (spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
>>                  return CMD_RET_FAILURE;
>>
>> -       if (type != IMX8 && type != LEGACY_LZMA &&
>> -           spl_test_mmc_fs(uts, test_name, type, create_fat, false))
>> +       if (spl_test_mmc_fs(uts, test_name, type, create_fat, false))
>>                  return CMD_RET_FAILURE;
>>
>>          if (type == LEGACY_LZMA)
>> --
>> 2.37.1
>>
> 
> Regards,
> Simon


^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes
  2023-11-07  8:49       ` Xavier Drudis Ferran
@ 2023-11-08 15:59         ` Sean Anderson
  2023-11-09  6:24           ` Xavier Drudis Ferran
  0 siblings, 1 reply; 62+ messages in thread
From: Sean Anderson @ 2023-11-08 15:59 UTC (permalink / raw)
  To: Xavier Drudis Ferran
  Cc: Tom Rini, u-boot, Simon Glass, Heinrich Schuchardt,
	Marek Behún, Marek Vasut, Stefan Roese, Fabio Estevam,
	Stefano Babic, uboot-imx

On 11/7/23 03:49, Xavier Drudis Ferran wrote:
> El Mon, Nov 06, 2023 at 08:54:03AM -0500, Sean Anderson deia:
>> On 11/6/23 07:35, Xavier Drudis Ferran wrote:
>>> Thanks for your work. I'm still reading... but...
>>>
>>>
>>> El Sun, Nov 05, 2023 at 09:25:46PM -0500, Sean Anderson deia:
>>>> diff --git a/include/spl.h b/include/spl.h
>>>> index 951e136b9ea..ecfc50e0095 100644
>>>> --- a/include/spl.h
>>>> +++ b/include/spl.h
>>>> @@ -297,10 +297,10 @@ struct spl_load_info {
>>>>    	 * read() - Read from device
>>>>    	 *
>>>>    	 * @load: Information about the load state
>>>> -	 * @sector: Sector number to read from (each @load->bl_len bytes)
>>>> -	 * @count: Number of sectors to read
>>>> +	 * @offset: Offset to read from in bytes, in multiples of @load->bl_len
>>>> +	 * @count: Number of bytes to read, in multiples of @load->bl_len
>>>
>>> I'm no native English speaker, but would it be easier to understand? :
>>>
>>> +	 * @offset: Offset to read from in bytes, a multiple of @load->bl_len
>>> +	 * @count: Number of bytes to read, a multiple of @load->bl_len
>>>
>>>
>>>
>>
>> I think it would have to be worded
>>
>> @offset: Offset to read from in bytes, as a multiple of @load->bl_len
>>
>> but to me these both mean the same thing.
>>
>> --Sean
> 
> Ah, OK. I doubted on whether it should be a comma or "as". Apparently
> it was both.
> 
> They may mean the same, but I got confused by having "in bytes", and
> "in multiples" so close.
> 
> "in bytes" means the value should be the correct answer to the
> question "how many bytes" (not a number of bits, not a number of
> sectors)
> 
> but "in multiples of..." doesn't mean the value should be the correct
> answer to "how many of multiples". Should the value be a number of
> sectors (first multiple of bl_len) a number of dozens of sectors
> (another multiple of bl_len) or ...?
> 
> In the first part "in" introduces a unit of measure, but in the second
> the same word introduces a constraint on a value. That was confusing
> to me.
> 
> Not saying it doesn't mean the same or even that you should change it,
> just elaborating why I said it.
> 

OK, what about

@offset: Offset to read from in bytes. This must be a multiple of @load->bl_len.

--Sean

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 06/25] spl: Remove dev from spl_load_info
  2023-11-08  4:23   ` Simon Glass
@ 2023-11-08 16:19     ` Sean Anderson
  0 siblings, 0 replies; 62+ messages in thread
From: Sean Anderson @ 2023-11-08 16:19 UTC (permalink / raw)
  To: Simon Glass
  Cc: Tom Rini, u-boot, Heinrich Schuchardt, Marek Behún,
	Marek Vasut, Xavier Drudis Ferran, Stefan Roese

On 11/7/23 23:23, Simon Glass wrote:
> Hi Sean,
> 
> On Sun, 5 Nov 2023 at 19:26, Sean Anderson <seanga2@gmail.com> wrote:
>>
>> dev and priv server the same purpose, and are never set at the same time.
> 
> serve
> 
>> Remove dev and convert all users to priv. While we're at it, reorder bl_len
>> to be last for better alignment.
> 
> It's a bit unfortunate to drop the device, isn't it? But then, as
> before, this is self-contained so Is suppose it doesn't matter what we
> store.

The original goal was to have something like

struct spl_load load = SPL_LOAD_INFO(my_load_function, my_private_data);

but I had to cut it because it was resulting in too many unnecessary assignments.

--Sean

> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> Regards,
> Simon
> 
> 
> 
>>
>> Signed-off-by: Sean Anderson <seanga2@gmail.com>
>> ---
>>
>> Changes in v6:
>> - New
>>
>>   common/spl/spl_mmc.c       | 6 +++---
>>   common/spl/spl_spi.c       | 6 +++---
>>   drivers/usb/gadget/f_sdp.c | 6 +++---
>>   include/spl.h              | 4 +---
>>   4 files changed, 10 insertions(+), 12 deletions(-)
>>
>> diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
>> index 6d9137c32e0..3d7551a7dae 100644
>> --- a/common/spl/spl_mmc.c
>> +++ b/common/spl/spl_mmc.c
>> @@ -65,7 +65,7 @@ static int mmc_load_legacy(struct spl_image_info *spl_image,
>>   static ulong h_spl_load_read(struct spl_load_info *load, ulong sector,
>>                               ulong count, void *buf)
>>   {
>> -       struct mmc *mmc = load->dev;
>> +       struct mmc *mmc = load->priv;
>>
>>          return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf);
>>   }
>> @@ -105,7 +105,7 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
>>                  struct spl_load_info load;
>>
>>                  debug("Found FIT\n");
>> -               load.dev = mmc;
>> +               load.priv = mmc;
>>                  load.filename = NULL;
>>                  load.bl_len = mmc->read_bl_len;
>>                  load.read = h_spl_load_read;
>> @@ -114,7 +114,7 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
>>                     valid_container_hdr((void *)header)) {
>>                  struct spl_load_info load;
>>
>> -               load.dev = mmc;
>> +               load.priv = mmc;
>>                  load.filename = NULL;
>>                  load.bl_len = mmc->read_bl_len;
>>                  load.read = h_spl_load_read;
>> diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
>> index d83d70f2f33..af7a28e7c25 100644
>> --- a/common/spl/spl_spi.c
>> +++ b/common/spl/spl_spi.c
>> @@ -59,7 +59,7 @@ static int spi_load_image_os(struct spl_image_info *spl_image,
>>   static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector,
>>                                ulong count, void *buf)
>>   {
>> -       struct spi_flash *flash = load->dev;
>> +       struct spi_flash *flash = load->priv;
>>          ulong ret;
>>
>>          ret = spi_flash_read(flash, sector, count, buf);
>> @@ -151,7 +151,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
>>                          struct spl_load_info load;
>>
>>                          debug("Found FIT\n");
>> -                       load.dev = flash;
>> +                       load.priv = flash;
>>                          load.filename = NULL;
>>                          load.bl_len = 1;
>>                          load.read = spl_spi_fit_read;
>> @@ -162,7 +162,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
>>                             valid_container_hdr((void *)header)) {
>>                          struct spl_load_info load;
>>
>> -                       load.dev = flash;
>> +                       load.priv = flash;
>>                          load.filename = NULL;
>>                          load.bl_len = 1;
>>                          load.read = spl_spi_fit_read;
>> diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
>> index ee9384fb37e..1b16b7eb452 100644
>> --- a/drivers/usb/gadget/f_sdp.c
>> +++ b/drivers/usb/gadget/f_sdp.c
>> @@ -744,7 +744,7 @@ static ulong sdp_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 *)(load->dev + sector), count);
>> +       memcpy(buf, (void *)(load->priv + sector), count);
>>          return count;
>>   }
>>
>> @@ -844,7 +844,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
>>                                  struct spl_load_info load;
>>
>>                                  debug("Found FIT\n");
>> -                               load.dev = header;
>> +                               load.priv = header;
>>                                  load.bl_len = 1;
>>                                  load.read = sdp_load_read;
>>                                  spl_load_simple_fit(spl_image, &load, 0,
>> @@ -857,7 +857,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
>>                              valid_container_hdr((void *)header)) {
>>                                  struct spl_load_info load;
>>
>> -                               load.dev = header;
>> +                               load.priv = header;
>>                                  load.bl_len = 1;
>>                                  load.read = sdp_load_read;
>>                                  spl_load_imx_container(spl_image, &load, 0);
>> diff --git a/include/spl.h b/include/spl.h
>> index 8ff20adc28e..951e136b9ea 100644
>> --- a/include/spl.h
>> +++ b/include/spl.h
>> @@ -285,16 +285,13 @@ static inline void *spl_image_fdt_addr(struct spl_image_info *info)
>>   /**
>>    * Information required to load data from a device
>>    *
>> - * @dev: Pointer to the device, e.g. struct mmc *
>>    * @priv: Private data for the device
>>    * @bl_len: Block length for reading in bytes
>>    * @filename: Name of the fit image file.
>>    * @read: Function to call to read from the device
>>    */
>>   struct spl_load_info {
>> -       void *dev;
>>          void *priv;
>> -       int bl_len;
>>          const char *filename;
>>          /**
>>           * read() - Read from device
>> @@ -307,6 +304,7 @@ struct spl_load_info {
>>           */
>>          ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
>>                        void *buf);
>> +       int bl_len;
>>   };
>>
>>   /*
>> --
>> 2.37.1
>>


^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes
  2023-11-08 15:59         ` Sean Anderson
@ 2023-11-09  6:24           ` Xavier Drudis Ferran
  0 siblings, 0 replies; 62+ messages in thread
From: Xavier Drudis Ferran @ 2023-11-09  6:24 UTC (permalink / raw)
  To: Sean Anderson
  Cc: Xavier Drudis Ferran, Tom Rini, u-boot, Simon Glass,
	Heinrich Schuchardt, Marek Behún, Marek Vasut, Stefan Roese,
	Fabio Estevam, Stefano Babic, uboot-imx

El Wed, Nov 08, 2023 at 10:59:13AM -0500, Sean Anderson deia:
> 
> OK, what about
> 
> @offset: Offset to read from in bytes. This must be a multiple of @load->bl_len.
> 
> --Sean

Great. Thank you.

^ permalink raw reply	[flat|nested] 62+ messages in thread

end of thread, other threads:[~2023-11-09  6:24 UTC | newest]

Thread overview: 62+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-06  2:25 [PATCH v6 00/25] spl: Use common function for loading/parsing images Sean Anderson
2023-11-06  2:25 ` [PATCH v6 01/25] spl: blk_fs: Fix uninitialized return value when we can't get a blk_desc Sean Anderson
2023-11-08  4:23   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 02/25] arm: Disable SPL_FS_FAT when it isn't used Sean Anderson
2023-11-06  6:58   ` Michal Simek
2023-11-06  2:25 ` [PATCH v6 03/25] spl: Make SHOW_ERRORS depend on LIBCOMMON Sean Anderson
2023-11-08  4:23   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 04/25] spl: semihosting: Don't close fd before spl_load_simple_fit Sean Anderson
2023-11-08  4:23   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 05/25] spl: Remove NULL assignments in spl_load_info Sean Anderson
2023-11-08  4:23   ` Simon Glass
2023-11-08 15:30     ` Sean Anderson
2023-11-06  2:25 ` [PATCH v6 06/25] spl: Remove dev from spl_load_info Sean Anderson
2023-11-08  4:23   ` Simon Glass
2023-11-08 16:19     ` Sean Anderson
2023-11-06  2:25 ` [PATCH v6 07/25] spl: Take advantage of bl_len's power-of-twoness Sean Anderson
2023-11-08  4:23   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes Sean Anderson
2023-11-06 12:35   ` Xavier Drudis Ferran
2023-11-06 13:54     ` Sean Anderson
2023-11-07  8:49       ` Xavier Drudis Ferran
2023-11-08 15:59         ` Sean Anderson
2023-11-09  6:24           ` Xavier Drudis Ferran
2023-11-06  2:25 ` [PATCH v6 09/25] spl: Remove filename from spl_load_info Sean Anderson
2023-11-08  4:23   ` Simon Glass
2023-11-08 15:34     ` Sean Anderson
2023-11-06  2:25 ` [PATCH v6 10/25] spl: Only support bl_len when we have to Sean Anderson
2023-11-08  4:23   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 11/25] spl: nand: Remove spl_nand_legacy_read Sean Anderson
2023-11-08  4:23   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 12/25] spl: legacy: Split off LZMA decompression into its own function Sean Anderson
2023-11-08  4:23   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 13/25] test: spl: Support testing LEGACY_LZMA filesystem images Sean Anderson
2023-11-08  4:23   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 14/25] spl: Add generic spl_load function Sean Anderson
2023-11-08  4:23   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 15/25] spl: Convert ext to use spl_load Sean Anderson
2023-11-08  4:24   ` Simon Glass
2023-11-08 15:37     ` Sean Anderson
2023-11-06  2:25 ` [PATCH v6 16/25] spl: Convert fat to spl_load Sean Anderson
2023-11-08  4:24   ` Simon Glass
2023-11-08 15:49     ` Sean Anderson
2023-11-06  2:25 ` [PATCH v6 17/25] spl: Convert mmc " Sean Anderson
2023-11-08  4:24   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 18/25] spl: Convert nand " Sean Anderson
2023-11-08  4:24   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 19/25] spl: Convert net " Sean Anderson
2023-11-08  4:24   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 20/25] spl: Convert nor " Sean Anderson
2023-11-08  4:24   ` Simon Glass
2023-11-06  2:25 ` [PATCH v6 21/25] spl: Convert NVMe " Sean Anderson
2023-11-08  4:24   ` Simon Glass
2023-11-06  2:26 ` [PATCH v6 22/25] spl: Convert semihosting " Sean Anderson
2023-11-06  2:26 ` [PATCH v6 23/25] spl: Convert spi " Sean Anderson
2023-11-08  4:24   ` Simon Glass
2023-11-06  2:26 ` [PATCH v6 24/25] spl: spi: Consolidate spi_load_image_os into spl_spi_load_image Sean Anderson
2023-11-08  4:24   ` Simon Glass
2023-11-06  2:26 ` [PATCH v6 25/25] spl: fat: Add option to disable DMA alignment Sean Anderson
2023-11-08  4:24   ` Simon Glass
2023-11-06  7:49 ` [PATCH v6 00/25] spl: Use common function for loading/parsing images Pali Rohár
2023-11-06  9:18   ` Heinrich Schuchardt
2023-11-06 10:12   ` Marek Behún

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.