[PATCH v5 00/11] spl: Use common function for loading/parsing images

Sean Anderson sean.anderson at seco.com
Tue Aug 1 00:42:52 CEST 2023


This series adds support for loading all image types (Legacy, FIT (with
and without LOAD_FIT_FULL), and i.MX) to the MMC, SPI, NOR, NET, FAT,
and EXT 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.

In order to meet size requirements for some boards, the first two
patches of this series are general size-reduction changes. The ffs/fls
change in particular should reduce code size across the board. The
malloc change also has the potential to reduce code size. I've left it
disabled by default, but maybe we can reverse that in the future.

Here's some bloat-o-meter for j7200_evm_a72_defconfig with ext4 support
enabed:

add/remove: 2/1 grow/shrink: 1/5 up/down: 444/-584 (-140)
Function                                     old     new   delta
spl_load                                       -     216    +216
spl_simple_read                                -     184    +184
spl_fit_read                                  60     104     +44
file_fat_read                                 40       -     -40
spl_nor_load_image                           120      76     -44
spl_load_image_ext                           364     296     -68
spl_load_image_fat                           320     200    -120
spl_spi_load_image                           304     176    -128
spl_mmc_load                                 716     532    -184
Total: Before=233618, After=233478, chg -0.06%

For most boards with a few load methods, this series should break even.
However, in the worst case this series will add around 100 bytes.

I have only tested a few loaders. Please try booting your favorite board
with NOR/SPI flash or SPI falcon mode.

On sama5d27_wlsom1_ek_mmc_defconfig, 100 bytes is too much, so this
series depends on [1] to fit everything in. CI run at [2].

[1] https://lore.kernel.org/u-boot/20230731223327.109865-1-sean.anderson@seco.com/
[2] https://source.denx.de/u-boot/custodians/u-boot-clk/-/pipelines/17116

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 (11):
  spl: Make SHOW_ERRORS depend on LIBCOMMON
  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 net to spl_load
  spl: Convert NVMe to spl_load
  spl: Convert nor 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

 common/spl/Kconfig           |   1 +
 common/spl/spl.c             |  86 +++++++++++++++++++++++++-
 common/spl/spl_blk_fs.c      |  68 ++++-----------------
 common/spl/spl_ext.c         |  34 ++++++-----
 common/spl/spl_fat.c         |  55 ++++++-----------
 common/spl/spl_mmc.c         |  91 +++-------------------------
 common/spl/spl_net.c         |  25 ++------
 common/spl/spl_nor.c         |  41 +++----------
 common/spl/spl_semihosting.c |  43 +++++--------
 common/spl/spl_spi.c         | 113 +++++------------------------------
 include/spl.h                |  27 ++++++++-
 11 files changed, 209 insertions(+), 375 deletions(-)

-- 
2.40.1



More information about the U-Boot mailing list