aboutsummaryrefslogtreecommitdiff
path: root/common/spl/spl_fat.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2023-11-16 12:55:48 -0500
committerTom Rini <trini@konsulko.com>2023-11-16 12:55:48 -0500
commit964999f871b13c3de78a14586ea6057c1ec08755 (patch)
tree6d6e07757ba598794975bcf5d36ecbfdba14a8bf /common/spl/spl_fat.c
parentd7b44e43b5dbafb74c86799471125e8fd5132bc3 (diff)
parentcd6fea4ae43dde9b75d0478ea57c24e508204765 (diff)
downloadu-boot-WIP/16Nov2023-next.zip
u-boot-WIP/16Nov2023-next.tar.gz
u-boot-WIP/16Nov2023-next.tar.bz2
Merge patch series "spl: Use common function for loading/parsing images"WIP/16Nov2023-next
To quote the author: 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. [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. This was ran for v6. [2] https://lore.kernel.org/u-boot/20231105022742.632175-1-seanga2@gmail.com/
Diffstat (limited to 'common/spl/spl_fat.c')
-rw-r--r--common/spl/spl_fat.c62
1 files changed, 22 insertions, 40 deletions
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 014074f..a52f9e1 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>
@@ -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)
@@ -66,59 +66,41 @@ 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;
- load.bl_len = 1;
- load.filename = (void *)filename;
- load.priv = NULL;
-
- 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;
+ 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);
+
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)