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 <[email protected]>
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 |