summaryrefslogtreecommitdiff
path: root/tools/kwbimage.c
diff options
context:
space:
mode:
authorBaruch Siach <baruch@tkos.co.il>2017-07-04 20:23:40 +0300
committerStefan Roese <sr@denx.de>2017-07-12 06:57:55 +0200
commitdb7cd4ed33d6724937c747a7339810b77d6989da (patch)
tree4bfe8c408df50fc8b345726871dd31bc5b8a45fe /tools/kwbimage.c
parent37d108b64fabc625ae829bc6ee419c163d523c3b (diff)
downloadu-boot-db7cd4ed33d6724937c747a7339810b77d6989da.tar.gz
tools/kwbimage: fix v1 header verification
The verify_header callback in kwbimage.c only verifies v0 headers checksum. Running 'mkimage -l' on a v1 image gives the following misleading output: GP Header: Size ae000000 LoadAddr 34160600 Implement support for v1 headers. For that, factor out the header checksum code to a separate main_hdr_checksum_ok() routine. This routine relies on the fact that the checksum field offset is the same in both v0 and v1 headers. With this patch applied 'mkimage -l' correctly identifies the image: Image Type: MVEBU Boot from sdio Image Image version:1 Data Size: 398904 Bytes = 389.55 KiB = 0.38 MiB Load Address: 007fffc0 Entry Point: 00800000 Signed-off-by: Baruch Siach <baruch@tkos.co.il> Signed-off-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'tools/kwbimage.c')
-rw-r--r--tools/kwbimage.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 5830549d26..ccecf87185 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -290,6 +290,33 @@ static uint8_t image_checksum8(void *start, uint32_t len)
return csum;
}
+size_t kwbimage_header_size(unsigned char *ptr)
+{
+ if (image_version((void *)ptr) == 0)
+ return sizeof(struct main_hdr_v0);
+ else
+ return KWBHEADER_V1_SIZE((struct main_hdr_v1 *)ptr);
+}
+
+/*
+ * Verify checksum over a complete header that includes the checksum field.
+ * Return 1 when OK, otherwise 0.
+ */
+static int main_hdr_checksum_ok(void *hdr)
+{
+ /* Offsets of checksum in v0 and v1 headers are the same */
+ struct main_hdr_v0 *main_hdr = (struct main_hdr_v0 *)hdr;
+ uint8_t checksum;
+
+ checksum = image_checksum8(hdr, kwbimage_header_size(hdr));
+ /* Calculated checksum includes the header checksum field. Compensate
+ * for that.
+ */
+ checksum -= main_hdr->checksum;
+
+ return checksum == main_hdr->checksum;
+}
+
static uint32_t image_checksum32(void *start, uint32_t len)
{
uint32_t csum = 0;
@@ -1587,14 +1614,9 @@ static int kwbimage_check_image_types(uint8_t type)
static int kwbimage_verify_header(unsigned char *ptr, int image_size,
struct image_tool_params *params)
{
- struct main_hdr_v0 *main_hdr;
uint8_t checksum;
- main_hdr = (struct main_hdr_v0 *)ptr;
- checksum = image_checksum8(ptr,
- sizeof(struct main_hdr_v0)
- - sizeof(uint8_t));
- if (checksum != main_hdr->checksum)
+ if (!main_hdr_checksum_ok(ptr))
return -FDT_ERR_BADSTRUCTURE;
/* Only version 0 extended header has checksum */