summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-08-22 09:56:23 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-08-23 10:10:05 +0200
commit1cf0d514db41bd3729c14253a62f33e74ef1a43e (patch)
treef14cf66ac6e05745e5e36f55406d3e360e4b0d01
parent5f04e5e03e941c8cae4f42f670abba847bfbcf9d (diff)
downloadbarebox-1cf0d514db41bd3729c14253a62f33e74ef1a43e.tar.gz
pbl: Move piggy verification into pbl_barebox_uncompress()
piggy verification is a direct prerequisite of uncompressing the piggydata, so move the verification there. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
-rw-r--r--arch/arm/cpu/uncompress.c17
-rw-r--r--include/pbl.h2
-rw-r--r--pbl/decomp.c35
3 files changed, 27 insertions, 27 deletions
diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
index 9cc3b35..4f16af2 100644
--- a/arch/arm/cpu/uncompress.c
+++ b/arch/arm/cpu/uncompress.c
@@ -42,18 +42,14 @@ unsigned long free_mem_end_ptr;
extern unsigned char input_data[];
extern unsigned char input_data_end[];
-extern unsigned char sha_sum[];
-extern unsigned char sha_sum_end[];
-
void __noreturn barebox_multi_pbl_start(unsigned long membase,
unsigned long memsize, void *boarddata)
{
- uint32_t pg_len, uncompressed_len, pbl_hash_len;
+ uint32_t pg_len, uncompressed_len;
void __noreturn (*barebox)(unsigned long, unsigned long, void *);
unsigned long endmem = membase + memsize;
unsigned long barebox_base;
void *pg_start, *pg_end;
- void *pbl_hash_start, *pbl_hash_end;
unsigned long pc = get_pc();
pg_start = input_data + global_variable_offset();
@@ -96,17 +92,6 @@ void __noreturn barebox_multi_pbl_start(unsigned long membase,
pr_debug("uncompressing barebox binary at 0x%p (size 0x%08x) to 0x%08lx (uncompressed size: 0x%08x)\n",
pg_start, pg_len, barebox_base, uncompressed_len);
- 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(pg_start, pg_len, pbl_hash_start,
- pbl_hash_len) != 0) {
- putc_ll('!');
- panic("hash mismatch, refusing to decompress");
- }
- }
-
pbl_barebox_uncompress((void*)barebox_base, pg_start, pg_len);
sync_caches_for_execution();
diff --git a/include/pbl.h b/include/pbl.h
index 1917a76..787bd82 100644
--- a/include/pbl.h
+++ b/include/pbl.h
@@ -11,8 +11,6 @@ extern unsigned long free_mem_ptr;
extern unsigned long free_mem_end_ptr;
void pbl_barebox_uncompress(void *dest, void *compressed_start, unsigned int len);
-int pbl_barebox_verify(void *compressed_start, unsigned int len, void *hash,
- unsigned int hash_len);
#ifdef __PBL__
#define IN_PBL 1
diff --git a/pbl/decomp.c b/pbl/decomp.c
index ef713a6..1e0ef81 100644
--- a/pbl/decomp.c
+++ b/pbl/decomp.c
@@ -51,16 +51,11 @@ static void noinline errorfn(char *error)
while (1);
}
-void pbl_barebox_uncompress(void *dest, void *compressed_start, unsigned int len)
-{
- decompress((void *)compressed_start,
- len,
- NULL, NULL,
- dest, NULL, errorfn);
-}
+extern unsigned char sha_sum[];
+extern unsigned char sha_sum_end[];
-int pbl_barebox_verify(void *compressed_start, unsigned int len, void *hash,
- unsigned int hash_len)
+static int pbl_barebox_verify(void *compressed_start, unsigned int len, void *hash,
+ unsigned int hash_len)
{
struct sha256_state sha_state = { 0 };
struct digest d = { .ctx = &sha_state };
@@ -93,3 +88,25 @@ int pbl_barebox_verify(void *compressed_start, unsigned int len, void *hash,
return memcmp(hash, computed_hash, SHA256_DIGEST_SIZE);
}
+
+void pbl_barebox_uncompress(void *dest, 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");
+ }
+ }
+
+ decompress((void *)compressed_start,
+ len,
+ NULL, NULL,
+ dest, NULL, errorfn);
+}