From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 06/16] uimage: add offset parameter to uimage_load
Date: Thu, 12 Mar 2026 15:44:49 +0100 [thread overview]
Message-ID: <20260312144505.2159816-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260312144505.2159816-1-a.fatoum@pengutronix.de>
The loadable API allows users to specify an offset at which reading
should start. In preparation for wrapping the uImage loading as
loadable, extend uimage_load to allow specifying a start offset.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/bootm-uimage.c | 4 ++--
common/uimage.c | 39 ++++++++++++++++++++++++++++++++++-----
include/image.h | 2 +-
3 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/common/bootm-uimage.c b/common/bootm-uimage.c
index b32ed5b0e95f..a1cb39d3ecd8 100644
--- a/common/bootm-uimage.c
+++ b/common/bootm-uimage.c
@@ -30,7 +30,7 @@ int bootm_load_uimage_os(struct image_data *data, unsigned long load_address)
num = uimage_part_num(data->os_part);
data->os_res = uimage_load_to_sdram(data->os_uimage,
- num, load_address);
+ num, load_address, 0);
if (!data->os_res)
return -ENOMEM;
@@ -91,7 +91,7 @@ bootm_load_uimage_initrd(struct image_data *data, unsigned long load_address)
num = uimage_part_num(data->initrd_part);
res = uimage_load_to_sdram(data->initrd_uimage,
- num, load_address);
+ num, load_address, 0);
if (!res)
return ERR_PTR(-ENOMEM);
diff --git a/common/uimage.c b/common/uimage.c
index d34205572510..510f91a26bee 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -338,10 +338,24 @@ EXPORT_SYMBOL(uimage_load);
static void *uimage_buf;
static size_t uimage_size;
+static size_t uimage_skip;
static struct resource *uimage_resource;
static long uimage_sdram_flush(void *buf, unsigned long len)
{
+ unsigned long skip_now = 0;
+
+ /* Skip the first uimage_skip bytes of decompressed data */
+ if (uimage_skip > 0) {
+ skip_now = min_t(unsigned long, uimage_skip, len);
+ buf += skip_now;
+ len -= skip_now;
+ uimage_skip -= skip_now;
+
+ if (len == 0)
+ return skip_now;
+ }
+
if (uimage_size + len > resource_size(uimage_resource)) {
resource_size_t start = uimage_resource->start;
resource_size_t size = resource_size(uimage_resource) + len;
@@ -362,27 +376,42 @@ static long uimage_sdram_flush(void *buf, unsigned long len)
uimage_size += len;
- return len;
+ return len + skip_now;
}
/*
* Load an uImage to a dynamically allocated sdram resource.
* the resource must be freed afterwards with release_sdram_region
+ *
+ * @handle: uImage handle
+ * @image_no: image number within the uImage
+ * @load_address: address to load the image to
+ * @offset: offset in bytes to skip from the beginning of the decompressed data
+ *
+ * Returns: SDRAM resource on success, NULL on error
*/
struct resource *uimage_load_to_sdram(struct uimage_handle *handle,
- int image_no, unsigned long load_address)
+ int image_no, unsigned long load_address, loff_t offset)
{
int ret;
- ssize_t size;
+ ssize_t total_size;
+ size_t size;
resource_size_t start = (resource_size_t)load_address;
uimage_buf = (void *)load_address;
uimage_size = 0;
+ uimage_skip = offset;
- size = uimage_get_size(handle, image_no);
- if (size < 0)
+ total_size = uimage_get_size(handle, image_no);
+ if (total_size < 0)
return NULL;
+ if (offset > total_size)
+ return NULL;
+
+ /* Allocate for the data after offset: size = total_size - offset */
+ size = total_size - offset;
+
uimage_resource = request_sdram_region("uimage",
start, size, MEMTYPE_LOADER_CODE,
MEMATTRS_RWX);
diff --git a/include/image.h b/include/image.h
index 769523d6fcaf..b37e04f54bae 100644
--- a/include/image.h
+++ b/include/image.h
@@ -304,7 +304,7 @@ int uimage_load(struct uimage_handle *handle, unsigned int image_no,
void uimage_print_contents(struct uimage_handle *handle);
ssize_t uimage_get_size(struct uimage_handle *handle, unsigned int image_no);
struct resource *uimage_load_to_sdram(struct uimage_handle *handle,
- int image_no, unsigned long load_address);
+ int image_no, unsigned long load_address, loff_t offset);
void *uimage_load_to_buf(struct uimage_handle *handle, int image_no,
size_t *size);
#define MAX_MULTI_IMAGE_COUNT 16
--
2.47.3
next prev parent reply other threads:[~2026-03-12 14:45 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 14:44 [PATCH 01/16] lib: add lazy loadable infrastructure for deferred boot component loading Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 02/16] bootm: split preparatory step from handler invocation Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 03/16] boot: add bootm_boot wrapper that takes struct bootentry Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 04/16] bootchooser: pass along " Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 05/16] bootm: switch plain file names case to loadable API Ahmad Fatoum
2026-03-12 14:44 ` Ahmad Fatoum [this message]
2026-03-12 14:44 ` [PATCH 07/16] bootm: uimage: switch " Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 08/16] bootm: fit: switch to new " Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 09/16] bootm: stash initial OS address/entry in image_data Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 10/16] bootm: support multiple entries for bootm.initrd Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 11/16] bootm: implement plain and FIT bootm.image override Ahmad Fatoum
2026-03-18 9:01 ` Sascha Hauer
2026-03-18 9:17 ` Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 12/16] bootm: overrides: add support for overlays Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 13/16] test: py: add test for initrd concatenation Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 14/16] defaultenv: base: add new devboot script Ahmad Fatoum
2026-03-18 9:50 ` Sascha Hauer
2026-03-18 10:50 ` Ahmad Fatoum
2026-03-18 14:49 ` Sascha Hauer
2026-03-12 14:44 ` [PATCH 15/16] Documentation: user: devboot: add section on forwarding build dirs Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 16/16] libfile: remove file_to_sdram Ahmad Fatoum
2026-03-18 10:06 ` [PATCH 01/16] lib: add lazy loadable infrastructure for deferred boot component loading Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260312144505.2159816-6-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox