[PATCH u-boot-marvell 09/13] tools: kwboot: Simplify code for aligning image header

Stefan Roese sr at denx.de
Tue Oct 26 07:45:58 CEST 2021


On 25.10.21 15:13, Marek Behún wrote:
> From: Pali Rohár <pali at kernel.org>
> 
> Expression (hdrsz % KWBOOT_XM_BLKSZ) is non-zero therefore expression
> (KWBOOT_XM_BLKSZ - hdrsz % KWBOOT_XM_BLKSZ) is always less than value
> KWBOOT_XM_BLKSZ. So there is no need to add another modulo. Also rename
> variable `offset` to `grow` which better describes what is stored in
> this variable.
> 
> 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 | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/kwboot.c b/tools/kwboot.c
> index 7fd28aa754..adec4ec97d 100644
> --- a/tools/kwboot.c
> +++ b/tools/kwboot.c
> @@ -1563,8 +1563,7 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
>   	}
>   
>   	if (hdrsz % KWBOOT_XM_BLKSZ) {
> -		size_t offset = (KWBOOT_XM_BLKSZ - hdrsz % KWBOOT_XM_BLKSZ) %
> -				KWBOOT_XM_BLKSZ;
> +		size_t grow = KWBOOT_XM_BLKSZ - hdrsz % KWBOOT_XM_BLKSZ;
>   
>   		if (is_secure) {
>   			fprintf(stderr, "Cannot align image with secure header\n");
> @@ -1572,7 +1571,7 @@ 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, offset);
> +		kwboot_img_grow_hdr(img, size, grow);
>   	}
>   
>   	hdr->checksum = kwboot_hdr_csum8(hdr) - csum;
> 


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