mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] pbl: export pbl_verify_piggy function
Date: Mon,  5 Jan 2026 09:36:39 +0100	[thread overview]
Message-ID: <20260105083640.3257482-1-a.fatoum@barebox.org> (raw)

To support barebox proper being an ELF binary, we will want to verify it
all at once and then decompress the segments one by one.

Export the necessary API to prepare for this.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 include/pbl.h |  3 +++
 pbl/decomp.c  | 42 ++++++++++++++++++++++++++++--------------
 2 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/include/pbl.h b/include/pbl.h
index b330010562c4..6fe868e14abc 100644
--- a/include/pbl.h
+++ b/include/pbl.h
@@ -14,7 +14,10 @@
 extern unsigned long free_mem_ptr;
 extern unsigned long free_mem_end_ptr;
 
+void pbl_verify_piggy(void *compressed_start, unsigned int len);
 void pbl_barebox_uncompress(void *dest, void *compressed_start, unsigned int len);
+long pbl_barebox_uncompress_noverify(void *dest, void *compressed_start,
+				     unsigned int len);
 
 void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsize);
 int fdt_fixup_mem(void *fdt, unsigned long membase[], unsigned long memsize[], size_t num);
diff --git a/pbl/decomp.c b/pbl/decomp.c
index ebdf81ddfbe5..ba722acdd174 100644
--- a/pbl/decomp.c
+++ b/pbl/decomp.c
@@ -89,24 +89,38 @@ int pbl_barebox_verify(const void *compressed_start, unsigned int len,
 	return memcmp(hash, computed_hash, SHA256_DIGEST_SIZE);
 }
 
-void pbl_barebox_uncompress(void *dest, void *compressed_start, unsigned int len)
+void pbl_verify_piggy(void *compressed_start, unsigned int len)
 {
 	uint32_t pbl_hash_len;
 	void *pbl_hash_start, *pbl_hash_end;
 
-	if (IS_ENABLED(CONFIG_PBL_VERIFY_PIGGY)) {
-		pbl_hash_start = sha_sum;
-		pbl_hash_end = sha_sum_end;
-		pbl_hash_len = pbl_hash_end - pbl_hash_start;
-		if (pbl_barebox_verify(compressed_start, len, pbl_hash_start,
-				       pbl_hash_len) != 0) {
-			putc_ll('!');
-			panic("hash mismatch, refusing to decompress");
-		}
+	if (!IS_ENABLED(CONFIG_PBL_VERIFY_PIGGY)) {
+		pr_debug("Verifying piggybacked barebox proper disabled\n");
+		return;
 	}
 
-	decompress((void *)compressed_start,
-			len,
-			NULL, NULL,
-			dest, NULL, errorfn);
+	pbl_hash_start = sha_sum;
+	pbl_hash_end = sha_sum_end;
+	pbl_hash_len = pbl_hash_end - pbl_hash_start;
+	if (pbl_barebox_verify(compressed_start, len, pbl_hash_start,
+			       pbl_hash_len) != 0) {
+		putc_ll('!');
+		panic("hash mismatch, refusing to decompress");
+	}
+}
+
+
+long pbl_barebox_uncompress_noverify(void *dest, void *compressed_start,
+				     unsigned int len)
+{
+	long pos;
+	return decompress((void *)compressed_start,
+			  len, NULL, NULL,
+			  dest, &pos, errorfn) ?: pos;
+}
+
+void pbl_barebox_uncompress(void *dest, void *compressed_start, unsigned int len)
+{
+	pbl_verify_piggy(compressed_start, len);
+	pbl_barebox_uncompress_noverify(dest, compressed_start, len);
 }
-- 
2.47.3




             reply	other threads:[~2026-01-05  8:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05  8:36 Ahmad Fatoum [this message]
2026-01-05 13:16 ` Ahmad Fatoum

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=20260105083640.3257482-1-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --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