aboutsummaryrefslogtreecommitdiff
path: root/common/spl
diff options
context:
space:
mode:
authorSean Anderson <seanga2@gmail.com>2023-11-08 11:48:39 -0500
committerTom Rini <trini@konsulko.com>2023-11-16 13:49:14 -0500
commit33c8d01a4d20ab1f7cb59bd9860e42196d6ddb4e (patch)
treedb4239761b98a1e448e9b2bae287b8e5a8a5de06 /common/spl
parent0c6c83e6a2608421d992781bdbd33a12fa31c10d (diff)
downloadu-boot-33c8d01a4d20ab1f7cb59bd9860e42196d6ddb4e.zip
u-boot-33c8d01a4d20ab1f7cb59bd9860e42196d6ddb4e.tar.gz
u-boot-33c8d01a4d20ab1f7cb59bd9860e42196d6ddb4e.tar.bz2
spl: Take advantage of bl_len's power-of-twoness
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> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/spl')
-rw-r--r--common/spl/spl_fit.c2
-rw-r--r--common/spl/spl_imx_container.c8
2 files changed, 5 insertions, 5 deletions
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 70d8d59..6084ead 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 127802f..1cc5178 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);