* [PATCH] pbl: export pbl_verify_piggy function
@ 2026-01-05 8:36 Ahmad Fatoum
2026-01-05 13:16 ` Ahmad Fatoum
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2026-01-05 8:36 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] pbl: export pbl_verify_piggy function
2026-01-05 8:36 [PATCH] pbl: export pbl_verify_piggy function Ahmad Fatoum
@ 2026-01-05 13:16 ` Ahmad Fatoum
0 siblings, 0 replies; 2+ messages in thread
From: Ahmad Fatoum @ 2026-01-05 13:16 UTC (permalink / raw)
To: Ahmad Fatoum, barebox
Hi,
On 1/5/26 9:36 AM, Ahmad Fatoum wrote:
> 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>
Please dismiss. I like the way of decompressing and fixing up in place more.
Cheers,
Ahmad
> ---
> 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);
> }
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-05 13:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-05 8:36 [PATCH] pbl: export pbl_verify_piggy function Ahmad Fatoum
2026-01-05 13:16 ` Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox