[PATCH u-boot-marvell 11/13] tools: kwboot: Calculate real used space in kwbimage header when calling kwboot_img_grow_hdr()

Stefan Roese sr at denx.de
Tue Oct 26 07:48:20 CEST 2021


On 25.10.21 15:13, Marek Behún wrote:
> From: Pali Rohár <pali at kernel.org>
> 
> Size of the header stored in kwbimage may be larger than real used size in
> the kwbimage header. If there is unused space in kwbimage header then use
> it for growing it. So update code to calculate used space of kwbimage
> header.
> 
> Signed-off-by: Pali Rohár <pali at kernel.org>
> Reviewed-by: Marek Behún <marek.behun at nic.cz>

Reviewed-by: Stefan Roese <sr at denx.de>

Thanks,
Stefan

> ---
>   tools/kwboot.c | 17 ++++++++++++++---
>   1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/kwboot.c b/tools/kwboot.c
> index bb7555369c..5d7cb7a774 100644
> --- a/tools/kwboot.c
> +++ b/tools/kwboot.c
> @@ -1318,11 +1318,20 @@ kwboot_img_grow_hdr(void *img, size_t *size, size_t grow)
>   {
>   	uint32_t hdrsz, datasz, srcaddr;
>   	struct main_hdr_v1 *hdr = img;
> +	struct opt_hdr_v1 *ohdr;
>   	uint8_t *data;
>   
>   	srcaddr = le32_to_cpu(hdr->srcaddr);
>   
> -	hdrsz = kwbheader_size(img);
> +	/* calculate real used space in kwbimage header */
> +	if (kwbimage_version(img) == 0) {
> +		hdrsz = kwbheader_size(img);
> +	} else {
> +		hdrsz = sizeof(*hdr);
> +		for_each_opt_hdr_v1 (ohdr, hdr)
> +			hdrsz += opt_hdr_v1_size(ohdr);
> +	}
> +
>   	data = (uint8_t *)img + srcaddr;
>   	datasz = *size - srcaddr;
>   
> @@ -1339,8 +1348,10 @@ kwboot_img_grow_hdr(void *img, size_t *size, size_t grow)
>   
>   	if (kwbimage_version(img) == 1) {
>   		hdrsz += grow;
> -		hdr->headersz_msb = hdrsz >> 16;
> -		hdr->headersz_lsb = cpu_to_le16(hdrsz & 0xffff);
> +		if (hdrsz > kwbheader_size(img)) {
> +			hdr->headersz_msb = hdrsz >> 16;
> +			hdr->headersz_lsb = cpu_to_le16(hdrsz & 0xffff);
> +		}
>   	}
>   }
>   
> 


Viele Grüße,
Stefan

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de


More information about the U-Boot mailing list