diff mbox series

[u-boot-marvell,10/11] tools: kwbimage: Properly calculate and align kwbimage v0 header size

Message ID 20211108171251.25382-11-kabel@kernel.org
State Accepted
Commit 851114be1a63d1004fc59e4c9e75bf93aed1adb7
Delegated to: Stefan Roese
Headers show
Series Another kwbimage series | expand

Commit Message

Marek Behún Nov. 8, 2021, 5:12 p.m. UTC
From: Pali Rohár <pali@kernel.org>

Kwbimage v0 has similar alignment requirements as v1.

Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 tools/kwbimage.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

Comments

Stefan Roese Nov. 10, 2021, 8:30 a.m. UTC | #1
On 08.11.21 18:12, Marek Behún wrote:
> From: Pali Rohár <pali@kernel.org>
> 
> Kwbimage v0 has similar alignment requirements as v1.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Signed-off-by: Marek Behún <marek.behun@nic.cz>

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

Thanks,
Stefan

> ---
>   tools/kwbimage.c | 24 ++++++++++++++++--------
>   1 file changed, 16 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> index 114b313b4d..952023c14c 100644
> --- a/tools/kwbimage.c
> +++ b/tools/kwbimage.c
> @@ -879,6 +879,20 @@ static size_t image_headersz_align(size_t headersz, uint8_t blockid)
>   		return headersz;
>   }
>   
> +static size_t image_headersz_v0(int *hasext)
> +{
> +	size_t headersz;
> +
> +	headersz = sizeof(struct main_hdr_v0);
> +	if (image_count_options(IMAGE_CFG_DATA) > 0) {
> +		headersz += sizeof(struct ext_hdr_v0);
> +		if (hasext)
> +			*hasext = 1;
> +	}
> +
> +	return image_headersz_align(headersz, image_get_bootfrom());
> +}
> +
>   static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,
>   			     int payloadsz)
>   {
> @@ -892,12 +906,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,
>   	 * Calculate the size of the header and the size of the
>   	 * payload
>   	 */
> -	headersz  = sizeof(struct main_hdr_v0);
> -
> -	if (image_count_options(IMAGE_CFG_DATA) > 0) {
> -		has_ext = 1;
> -		headersz += sizeof(struct ext_hdr_v0);
> -	}
> +	headersz = image_headersz_v0(&has_ext);
>   
>   	image = malloc(headersz);
>   	if (!image) {
> @@ -1854,8 +1863,7 @@ static int kwbimage_generate(struct image_tool_params *params,
>   		 */
>   	case -1:
>   	case 0:
> -		alloc_len = sizeof(struct main_hdr_v0) +
> -			sizeof(struct ext_hdr_v0);
> +		alloc_len = image_headersz_v0(NULL);
>   		break;
>   
>   	case 1:
> 

Viele Grüße,
Stefan Roese
diff mbox series

Patch

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 114b313b4d..952023c14c 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -879,6 +879,20 @@  static size_t image_headersz_align(size_t headersz, uint8_t blockid)
 		return headersz;
 }
 
+static size_t image_headersz_v0(int *hasext)
+{
+	size_t headersz;
+
+	headersz = sizeof(struct main_hdr_v0);
+	if (image_count_options(IMAGE_CFG_DATA) > 0) {
+		headersz += sizeof(struct ext_hdr_v0);
+		if (hasext)
+			*hasext = 1;
+	}
+
+	return image_headersz_align(headersz, image_get_bootfrom());
+}
+
 static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,
 			     int payloadsz)
 {
@@ -892,12 +906,7 @@  static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,
 	 * Calculate the size of the header and the size of the
 	 * payload
 	 */
-	headersz  = sizeof(struct main_hdr_v0);
-
-	if (image_count_options(IMAGE_CFG_DATA) > 0) {
-		has_ext = 1;
-		headersz += sizeof(struct ext_hdr_v0);
-	}
+	headersz = image_headersz_v0(&has_ext);
 
 	image = malloc(headersz);
 	if (!image) {
@@ -1854,8 +1863,7 @@  static int kwbimage_generate(struct image_tool_params *params,
 		 */
 	case -1:
 	case 0:
-		alloc_len = sizeof(struct main_hdr_v0) +
-			sizeof(struct ext_hdr_v0);
+		alloc_len = image_headersz_v0(NULL);
 		break;
 
 	case 1: