diff options
author | Marek BehĂșn <marek.behun@nic.cz> | 2021-09-25 00:07:01 +0300 |
---|---|---|
committer | Stefan Roese <sr@denx.de> | 2021-10-01 12:07:13 +0300 |
commit | fe2fd73d5557cc0bc6e671aa426ca1d53c4caee9 (patch) | |
tree | c8e0f3c0b8cb3ca85591dee064a438fb157050df /tools/kwboot.c | |
parent | acb0b38d6a2acd47cfef34ae002b3cd8be4fa16a (diff) | |
download | u-boot-fe2fd73d5557cc0bc6e671aa426ca1d53c4caee9.tar.xz |
tools: kwbimage: Refactor kwbimage header size determination
Add functions kwbheader_size() and kwbheader_size_for_csum().
Refactor code determining header size to use these functions.
Refactor header checksum determining function.
Remove stuff that is not needed anymore.
This simplifies the code a little and fixes one instance of validating
header size meant for checksum instead of whole header size.
Signed-off-by: Marek BehĂșn <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'tools/kwboot.c')
-rw-r--r-- | tools/kwboot.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/tools/kwboot.c b/tools/kwboot.c index e47bf94e89..e60f7c5b7a 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -583,10 +583,7 @@ kwboot_xmodem(int tty, const void *_img, size_t size) int rc, pnum; size_t hdrsz; - if (kwbimage_version(img) == 0) - hdrsz = KWBHEADER_V0_SIZE((struct main_hdr_v0 *)img); - else - hdrsz = KWBHEADER_V1_SIZE((struct main_hdr_v1 *)img); + hdrsz = kwbheader_size(img); kwboot_printv("Waiting 2s and flushing tty\n"); sleep(2); /* flush isn't effective without it */ @@ -746,9 +743,13 @@ out: } static uint8_t -kwboot_img_csum8(void *_data, size_t size) +kwboot_hdr_csum8(const void *hdr) { - uint8_t *data = _data, csum; + const uint8_t *data = hdr; + uint8_t csum; + size_t size; + + size = kwbheader_size_for_csum(hdr); for (csum = 0; size-- > 0; data++) csum += *data; @@ -794,17 +795,14 @@ kwboot_img_patch_hdr(void *img, size_t size) goto out; } - if (image_ver == 0) - hdrsz = sizeof(*hdr); - else - hdrsz = KWBHEADER_V1_SIZE(hdr); + hdrsz = kwbheader_size(hdr); if (size < hdrsz) { errno = EINVAL; goto out; } - csum = kwboot_img_csum8(hdr, hdrsz) - hdr->checksum; + csum = kwboot_hdr_csum8(hdr) - hdr->checksum; if (csum != hdr->checksum) { errno = EINVAL; goto out; @@ -860,7 +858,7 @@ kwboot_img_patch_hdr(void *img, size_t size) hdr->blockid = IBR_HDR_UART_ID; } - hdr->checksum = kwboot_img_csum8(hdr, hdrsz) - csum; + hdr->checksum = kwboot_hdr_csum8(hdr) - csum; rc = 0; out: |