From: Pali Rohár Date: Thu, 23 Mar 2023 19:57:52 +0000 (+0100) Subject: tools: kwboot: Fix invalid UART kwbimage v1 headersz X-Git-Tag: baikal/mips/sdk6.2~4^2~3^2~175^2~24^2~4 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=94e3df5843149ace304316f704d2f512cf9fcd23;p=uboot.git tools: kwboot: Fix invalid UART kwbimage v1 headersz Ensure that UART aligned header size is always stored into kwbimage v1 header. It is needed for proper UART booting. Calculation of headersz field was broken in commit a075a68b1344 ("tools: kwboot: Calculate real used space in kwbimage header when calling kwboot_img_grow_hdr()") which introduced optimization of kwboot_img_grow_hdr() function. Fixes: a075a68b1344 ("tools: kwboot: Calculate real used space in kwbimage header when calling kwboot_img_grow_hdr()") Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese --- diff --git a/tools/kwboot.c b/tools/kwboot.c index 7c666486f3..ef108c8395 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -2168,6 +2168,17 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) kwboot_printv("Aligning image header to Xmodem block size\n"); kwboot_img_grow_hdr(img, size, grow); + hdrsz += grow; + + /* + * kwbimage v1 contains header size field and for UART type it + * must be set to the aligned xmodem header size because BootROM + * rounds header size down to xmodem block size. + */ + if (kwbimage_version(img) == 1) { + hdr->headersz_msb = hdrsz >> 16; + hdr->headersz_lsb = cpu_to_le16(hdrsz & 0xffff); + } } hdr->checksum = kwboot_hdr_csum8(hdr) - csum;