diff options
author | Pali Rohár <pali@kernel.org> | 2021-07-23 11:14:01 +0200 |
---|---|---|
committer | Stefan Roese <sr@denx.de> | 2021-07-31 09:49:31 +0200 |
commit | fe2c0e259b88b3cfae8adfad543effa837f3a9bc (patch) | |
tree | 3965efbd8377c2d4515e1c6f3cb02b55eaad77cc /tools | |
parent | 4efbf1c3273788b83dd1f7646d26ce9950e4b4dc (diff) | |
download | u-boot-fe2c0e259b88b3cfae8adfad543effa837f3a9bc.tar.gz u-boot-fe2c0e259b88b3cfae8adfad543effa837f3a9bc.tar.bz2 u-boot-fe2c0e259b88b3cfae8adfad543effa837f3a9bc.zip |
tools: kwbimage: Fix check for v0 extended header checksum
Extended header checksum for v0 image is present only in the case when
extended header is present. Skip checksum validation if extended header
is not present.
Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
Reviewed-by: Chris Packham <judge.packham@gmail.com>
Tested-by: Chris Packham <judge.packham@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/kwbimage.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 724459fb8e..4d9d818538 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1655,15 +1655,19 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, /* Only version 0 extended header has checksum */ if (image_version((void *)ptr) == 0) { - struct ext_hdr_v0 *ext_hdr; + struct main_hdr_v0 *mhdr = (struct main_hdr_v0 *)ptr; - ext_hdr = (struct ext_hdr_v0 *) + if (mhdr->ext & 0x1) { + struct ext_hdr_v0 *ext_hdr; + + ext_hdr = (struct ext_hdr_v0 *) (ptr + sizeof(struct main_hdr_v0)); - checksum = image_checksum8(ext_hdr, - sizeof(struct ext_hdr_v0) - - sizeof(uint8_t)); - if (checksum != ext_hdr->checksum) - return -FDT_ERR_BADSTRUCTURE; + checksum = image_checksum8(ext_hdr, + sizeof(struct ext_hdr_v0) + - sizeof(uint8_t)); + if (checksum != ext_hdr->checksum) + return -FDT_ERR_BADSTRUCTURE; + } } return 0; |