aboutsummaryrefslogtreecommitdiff
path: root/common/spl/spl_imx_container.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 13:49:14 -0500
commit6c1608b1ffb372d4dabf1b879e68428712353709 (patch)
tree7138fe8610ed51df94cc27753e9d09b5379ad7a5 /common/spl/spl_imx_container.c
parent5e6a112e1187ebc570b8befd1dd6eef3a64dec39 (diff)
parent54a8d845be4f236a5eb7c93d927ff16cb3efb5fe (diff)
downloadu-boot-6c1608b1ffb372d4dabf1b879e68428712353709.zip
u-boot-6c1608b1ffb372d4dabf1b879e68428712353709.tar.gz
u-boot-6c1608b1ffb372d4dabf1b879e68428712353709.tar.bz2
Merge patch series "spl: Use common function for loading/parsing images"
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_imx_container.c')
-rw-r--r--common/spl/spl_imx_container.c55
1 files changed, 25 insertions, 30 deletions
diff --git a/common/spl/spl_imx_container.c b/common/spl/spl_imx_container.c
index 127802f..b4ea924 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");
@@ -33,22 +32,21 @@ 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, 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;
}
- sectors = roundup(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, spl_get_bl_len(info));
+ 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)) <
+ images[image_index].size) {
printf("%s wrong\n", __func__);
return NULL;
}
@@ -62,15 +60,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 = roundup(CONTAINER_HDR_ALIGNMENT, info->bl_len);
- sectors = size / 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,
@@ -80,9 +76,10 @@ 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) <
+ CONTAINER_HDR_ALIGNMENT) {
ret = -EIO;
goto end;
}
@@ -103,18 +100,16 @@ 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);
- sectors = size / info->bl_len;
+ size = ALIGN(length, spl_get_bl_len(info));
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) < length) {
ret = -EIO;
goto end;
}
@@ -129,7 +124,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 +149,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);
}