[PATCH u-boot-mvebu 07/31] tools: kwbimage: Fix check for v0 extended header checksum

Stefan Roese sr at denx.de
Thu Jul 15 10:36:25 CEST 2021


On 08.07.21 19:30, Marek Behún wrote:
> From: Pali Rohár <pali at kernel.org>
> 
> 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 at kernel.org>
> Reviewed-by: Marek Behún <marek.behun at nic.cz>

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

Thanks,
Stefan

> ---
>   tools/kwbimage.c | 18 +++++++++++-------
>   1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> index c08fb678d4..5192edb330 100644
> --- a/tools/kwbimage.c
> +++ b/tools/kwbimage.c
> @@ -1653,15 +1653,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;
> 


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