diff mbox series

[u-boot-marvell,v2,03/20] tools: kwbimage: Fix generating image with multiple DATA_DELAY commands

Message ID 20220112172054.5961-4-pali@kernel.org
State Accepted
Commit d737d5d2c1e9aaea830c1cc469091ed9c13b2b2a
Delegated to: Stefan Roese
Headers show
Series tools: kwbimage: Load address fixes | expand

Commit Message

Pali Rohár Jan. 12, 2022, 5:20 p.m. UTC
Register set header consists of sequence of DATA commands followed by
exactly one DATA_DELAY command. Thus if we are generating image with
multiple DATA_DELAY commands, we need to create more register set headers.

Fix calculation of image size with multiple DATA_DELAY commands and
correctly set pointer to struct register_set_hdr_v1 when initializing new
register set header.

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

Comments

Stefan Roese Jan. 13, 2022, 6:31 a.m. UTC | #1
On 1/12/22 18:20, Pali Rohár wrote:
> Register set header consists of sequence of DATA commands followed by
> exactly one DATA_DELAY command. Thus if we are generating image with
> multiple DATA_DELAY commands, we need to create more register set headers.
> 
> Fix calculation of image size with multiple DATA_DELAY commands and
> correctly set pointer to struct register_set_hdr_v1 when initializing new
> register set header.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Reviewed-by: Marek Behún <marek.behun@nic.cz>

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

Thanks,
Stefan

> ---
>   tools/kwbimage.c | 18 +++++++++++++++---
>   1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> index 552fef9e9aeb..6ee3d0aaa86c 100644
> --- a/tools/kwbimage.c
> +++ b/tools/kwbimage.c
> @@ -993,7 +993,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,
>   
>   static size_t image_headersz_v1(int *hasext)
>   {
> -	struct image_cfg_element *binarye;
> +	struct image_cfg_element *binarye, *e;
>   	unsigned int count;
>   	size_t headersz;
>   	int cfgi;
> @@ -1010,7 +1010,18 @@ static size_t image_headersz_v1(int *hasext)
>   			*hasext = 1;
>   	}
>   
> -	count = image_count_options(IMAGE_CFG_DATA);
> +	count = 0;
> +	for (cfgi = 0; cfgi < cfgn; cfgi++) {
> +		e = &image_cfg[cfgi];
> +
> +		if (e->type == IMAGE_CFG_DATA)
> +			count++;
> +
> +		if (e->type == IMAGE_CFG_DATA_DELAY) {
> +			headersz += sizeof(struct register_set_hdr_v1) + 8 * count + 4;
> +			count = 0;
> +		}
> +	}
>   	if (count > 0)
>   		headersz += sizeof(struct register_set_hdr_v1) + 8 * count + 4;
>   
> @@ -1368,12 +1379,13 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
>   	}
>   
>   	datai = 0;
> -	register_set_hdr = (struct register_set_hdr_v1 *)cur;
>   	for (cfgi = 0; cfgi < cfgn; cfgi++) {
>   		e = &image_cfg[cfgi];
>   		if (e->type != IMAGE_CFG_DATA &&
>   		    e->type != IMAGE_CFG_DATA_DELAY)
>   			continue;
> +		if (datai == 0)
> +			register_set_hdr = (struct register_set_hdr_v1 *)cur;
>   		if (e->type == IMAGE_CFG_DATA_DELAY) {
>   			finish_register_set_header_v1(&cur, &next_ext, register_set_hdr,
>   						      &datai, e->regdata_delay);
> 

Viele Grüße,
Stefan Roese
diff mbox series

Patch

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 552fef9e9aeb..6ee3d0aaa86c 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -993,7 +993,7 @@  static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,
 
 static size_t image_headersz_v1(int *hasext)
 {
-	struct image_cfg_element *binarye;
+	struct image_cfg_element *binarye, *e;
 	unsigned int count;
 	size_t headersz;
 	int cfgi;
@@ -1010,7 +1010,18 @@  static size_t image_headersz_v1(int *hasext)
 			*hasext = 1;
 	}
 
-	count = image_count_options(IMAGE_CFG_DATA);
+	count = 0;
+	for (cfgi = 0; cfgi < cfgn; cfgi++) {
+		e = &image_cfg[cfgi];
+
+		if (e->type == IMAGE_CFG_DATA)
+			count++;
+
+		if (e->type == IMAGE_CFG_DATA_DELAY) {
+			headersz += sizeof(struct register_set_hdr_v1) + 8 * count + 4;
+			count = 0;
+		}
+	}
 	if (count > 0)
 		headersz += sizeof(struct register_set_hdr_v1) + 8 * count + 4;
 
@@ -1368,12 +1379,13 @@  static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
 	}
 
 	datai = 0;
-	register_set_hdr = (struct register_set_hdr_v1 *)cur;
 	for (cfgi = 0; cfgi < cfgn; cfgi++) {
 		e = &image_cfg[cfgi];
 		if (e->type != IMAGE_CFG_DATA &&
 		    e->type != IMAGE_CFG_DATA_DELAY)
 			continue;
+		if (datai == 0)
+			register_set_hdr = (struct register_set_hdr_v1 *)cur;
 		if (e->type == IMAGE_CFG_DATA_DELAY) {
 			finish_register_set_header_v1(&cur, &next_ext, register_set_hdr,
 						      &datai, e->regdata_delay);