From 5ff3a3a98f23bb1a0dd1fb97e074ddb80337ae27 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Sun, 1 Jan 2017 19:46:01 +0100 Subject: imxtools/sbtools: various fixes Change bug() macro, fix memory leaks, always use -h for help, fix usage(), fix comment, remove useless macro Change-Id: I30554b5e07e6f2845560a570808603cf8c4da5ad --- utils/imxtools/sbtools/sb.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'utils/imxtools/sbtools/sb.c') diff --git a/utils/imxtools/sbtools/sb.c b/utils/imxtools/sbtools/sb.c index ff8e0da3ee..cbeacf9c3f 100644 --- a/utils/imxtools/sbtools/sb.c +++ b/utils/imxtools/sbtools/sb.c @@ -802,7 +802,11 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo if(memcmp(hdr_sha1, computed_sha1, 20) == 0) printf(RED, " Ok\n"); else + { printf(RED, " Failed\n"); + if(!(flags & SB_IGNORE_SHA1)) + fatal(SB_FORMAT_ERROR, "Bad header checksum\n"); + } printf(GREEN, " Flags: "); printf(YELLOW, "%x\n", sb_header->flags); printf(GREEN, " Total file size : "); @@ -1045,7 +1049,7 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo printf(OFF, "%s", indent); uint8_t checksum = instruction_checksum(hdr); if(checksum != hdr->checksum) - printf(GREY, "[Bad checksum']"); + printf(GREY, "[Bad checksum]"); if(hdr->opcode == SB_INST_NOP) { @@ -1093,6 +1097,14 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo printf(RED, " (Encrypted)"); printf(OFF, "\n"); + /* skip it if we cannot decrypt it */ + if(encrypted && !valid_key) + { + printf(GREY, " Skipping section content (no valid key)\n"); + offset += size; + continue; + } + /* save it */ byte *sec = xmalloc(size); if(encrypted) @@ -1161,7 +1173,7 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo else if(flags & SB_IGNORE_SHA1) { /* some weird images produced by some buggy tools have wrong SHA-1, - * this probably gone unnoticed because the bootloader ignores the SH1-1 + * this probably gone unnoticed because the bootloader ignores the SHA-1 * anyway */ printf(RED, " Failed\n"); cprintf(u, true, GREY, "Warning: SHA-1 mismatch ignored per flags\n"); -- cgit v1.2.3