aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2021-10-25 15:13:01 +0200
committerStefan Roese <sr@denx.de>2021-11-03 06:45:27 +0100
commite511cc3b1ad8ced8e18464edf22f5b8a83ec1cb3 (patch)
tree1be7aa70fb317c5073cd70805b776570acee4a18
parented792c2938331a68f4b271a6d4d0250057449608 (diff)
downloadu-boot-e511cc3b1ad8ced8e18464edf22f5b8a83ec1cb3.zip
u-boot-e511cc3b1ad8ced8e18464edf22f5b8a83ec1cb3.tar.gz
u-boot-e511cc3b1ad8ced8e18464edf22f5b8a83ec1cb3.tar.bz2
tools: kwboot: Do not modify kwbimage header before increasing its size
This ensures that kwboot_img_grow_hdr() function still sees valid kwbimage header. 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>
-rw-r--r--tools/kwboot.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/kwboot.c b/tools/kwboot.c
index adec4ec..bb75553 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1352,17 +1352,18 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz)
uint32_t num_args;
uint32_t offset;
uint32_t ohdrsz;
+ uint8_t *prev_ext;
if (hdr->ext & 0x1) {
for_each_opt_hdr_v1 (ohdr, img)
if (opt_hdr_v1_next(ohdr) == NULL)
break;
- *opt_hdr_v1_ext(ohdr) |= 1;
- ohdr = opt_hdr_v1_next(ohdr);
+ prev_ext = opt_hdr_v1_ext(ohdr);
+ ohdr = _opt_hdr_v1_next(ohdr);
} else {
- hdr->ext |= 1;
ohdr = (void *)(hdr + 1);
+ prev_ext = &hdr->ext;
}
/*
@@ -1377,6 +1378,8 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz)
ohdrsz = sizeof(*ohdr) + 4 + 4 * num_args + binsz + 4;
kwboot_img_grow_hdr(hdr, size, ohdrsz);
+ *prev_ext |= 1;
+
ohdr->headertype = OPT_HDR_V1_BINARY_TYPE;
ohdr->headersz_msb = ohdrsz >> 16;
ohdr->headersz_lsb = cpu_to_le16(ohdrsz & 0xffff);