[PATCH u-boot-mvebu v2 14/41] tools: kwbimage: Fix calculating size of binary header
Stefan Roese
sr at denx.de
Wed Jul 21 11:32:05 CEST 2021
On 19.07.21 14:20, Marek Behún wrote:
> From: Pali Rohár <pali at kernel.org>
>
> Binary header consist of:
> * 1 byte for header type
> * 3 bytes for header size
> * 1 byte for number of arguments
> * 3 reserved bytes
> * N*4 bytes for arguments
> * M bytes (aligned to 4 bytes) for executable data
> * 1 byte for information about next header
> * 3 reserved bytes
>
> The first four bytes are specified as
> sizeof(struct opt_hdr_v1)
> and the remaining bytes as
> ALIGN(s.st_size, 4) + (binarye->binary.nargs + 2) * sizeof(uint32_t)
>
> 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 | 11 ++---------
> 1 file changed, 2 insertions(+), 9 deletions(-)
>
> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> index 2d4574af7d..6c9f93ae8b 100644
> --- a/tools/kwbimage.c
> +++ b/tools/kwbimage.c
> @@ -984,7 +984,7 @@ static size_t image_headersz_v1(int *hasext)
> }
>
> headersz += sizeof(struct opt_hdr_v1) +
> - s.st_size +
> + ALIGN(s.st_size, 4) +
> (binarye->binary.nargs + 2) * sizeof(uint32_t);
> if (hasext)
> *hasext = 1;
> @@ -1051,14 +1051,7 @@ int add_binary_header_v1(uint8_t *cur)
>
> binhdrsz = sizeof(struct opt_hdr_v1) +
> (binarye->binary.nargs + 2) * sizeof(uint32_t) +
> - s.st_size;
> -
> - /*
> - * The size includes the binary image size, rounded
> - * up to a 4-byte boundary. Plus 4 bytes for the
> - * next-header byte and 3-byte alignment at the end.
> - */
> - binhdrsz = ALIGN(binhdrsz, 4) + 4;
> + ALIGN(s.st_size, 4);
> hdr->headersz_lsb = cpu_to_le16(binhdrsz & 0xFFFF);
> hdr->headersz_msb = (binhdrsz & 0xFFFF0000) >> 16;
>
>
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