mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 1/2] bootm: fit: open FIT images only once per loadable
Date: Thu, 01 Oct 2026 09:11:20 +0200	[thread overview]
Message-ID: <20261001-fit-cache-fixes-v1-1-568bd214e5b0@pengutronix.de> (raw)
In-Reply-To: <20261001-fit-cache-fixes-v1-0-568bd214e5b0@pengutronix.de>

Since commit c3d383e958f3 ("bootm: fit: switch to new loadable API")
the FIT loadable calls fit_open_image() on every access. bootm accesses
the kernel loadable twice: in bootm_open_fit() to detect the kernel type
from its header and in the image handler to copy it to its load address.
Each call hashes the image again, which takes about 40 ms for a 12 MB
kernel on an RK3588.

Cache data and size in the loadable, so the image is verified and
decompressed only on first use. The data is owned by the FIT handle,
which the loadable holds a reference to until it is released.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/bootm-fit.c | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/common/bootm-fit.c b/common/bootm-fit.c
index f7742b8717..68bede1300 100644
--- a/common/bootm-fit.c
+++ b/common/bootm-fit.c
@@ -194,23 +194,38 @@ struct fit_loadable_priv {
 	struct device_node *config;
 	const char *image_name;
 	int index;
+	const void *data;
+	unsigned long size;
 };
 
+/*
+ * fit_loadable_open() - verify and decompress the image on first use
+ * @priv: FIT loadable private data
+ *
+ * The result is cached, so hashing and decompression happen only once.
+ * The data is owned by the FIT handle, which we hold a reference to.
+ */
+static int fit_loadable_open(struct fit_loadable_priv *priv)
+{
+	if (priv->data)
+		return 0;
+
+	return fit_open_image(priv->fit, priv->config, priv->image_name,
+			      priv->index, &priv->data, &priv->size);
+}
+
 static int fit_loadable_get_info(struct loadable *l, struct loadable_info *info)
 {
 	struct fit_loadable_priv *priv = l->priv;
-	const void *data;
-	unsigned long size;
 	int ret;
 
 	/* Open image to get size */
-	ret = fit_open_image(priv->fit, priv->config, priv->image_name,
-			     priv->index, &data, &size);
+	ret = fit_loadable_open(priv);
 	if (ret)
 		return ret;
 
 	/* TODO: This will trigger an uncompression currently.. */
-	info->final_size = size;
+	info->final_size = priv->size;
 
 	return 0;
 }
@@ -218,17 +233,14 @@ static int fit_loadable_get_info(struct loadable *l, struct loadable_info *info)
 static const void *fit_loadable_mmap(struct loadable *l, size_t *size)
 {
 	struct fit_loadable_priv *priv = l->priv;
-	const void *data;
-	unsigned long image_size;
 	int ret;
 
-	ret = fit_open_image(priv->fit, priv->config, priv->image_name,
-			     priv->index, &data, &image_size);
+	ret = fit_loadable_open(priv);
 	if (ret)
 		return MAP_FAILED;
 
-	*size = image_size;
-	return data;
+	*size = priv->size;
+	return priv->data;
 }
 
 /**
@@ -264,11 +276,13 @@ static ssize_t fit_loadable_extract_into_buf(struct loadable *l, void *load_addr
 	/* TODO: optimize, so it decompresses directly to load address */
 
 	/* Open image to get data */
-	ret = fit_open_image(priv->fit, priv->config, priv->image_name,
-			     priv->index, &data, &size);
+	ret = fit_loadable_open(priv);
 	if (ret)
 		return ret;
 
+	data = priv->data;
+	size = priv->size;
+
 	/* Check if buffer is large enough */
 	if (offset > size)
 		return 0;

-- 
2.47.3




  reply	other threads:[~2026-10-01  7:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01  7:11 [PATCH 0/2] FIT: Do not hash image data twice Sascha Hauer
2026-10-01  7:11 ` Sascha Hauer [this message]
2026-10-01  7:11 ` [PATCH 2/2] FIT: do not cache uncompressed data 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=20261001-fit-cache-fixes-v1-1-568bd214e5b0@pengutronix.de \
    --to=s.hauer@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