Skip to contentSkip to conversation

tools: imximage: use 'new style' header length for imximage v1

PATCH Superseded Martin Kaiser 2 participants 7 messages Sep 26, 2016 – Jan 27, 2017 Arm i.MX and Layerscape

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: imximage: use 'new style' header length for imximage v1

From: Martin Kaiser <[email protected]>

We can use the same mechanism for the imximage v1 header length calculations that we're using for v2. Doing so, we can share more code between v1 and v2.

Additionally, *header_size_ptr in imximage_set_header() will then have the correct value for both v1 and v2.

---

I discovered the problem when I tried to use csf_ptr with imximage v1 (as part of a private modification).

*csf_ptr = params->ep + *header_size_ptr - imximage_init_loadsize;
         = params->ep + sbuf->st_size +
                     imximage_ivt_offset - imximage_init_loadsize;
         = params->ep + padded data file size + alloc_len -
                     (imximage_init_loadsize - imximage_ivt_offset);

This works only if
alloc_len == imximage_init_loadsize - imximage_ivt_offset, not if alloc_len is always 4096.

 tools/imximage.c |   43 ++++++++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 23 deletions(-)
tools/imximage.c +20 -23
index 092d550..e280da6 100644
@@ -291,8 +291,7 @@ static void set_imx_hdr_v1(struct imx_header *imxhdr, uint32_t dcd_len,
 	/* Set magic number */
 	fhdr_v1->app_code_barker = APP_CODE_BARKER;
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	hdr_base = entry_point - 4096;
+	hdr_base = entry_point - imximage_init_loadsize + flash_offset;
 	fhdr_v1->app_dest_ptr = hdr_base - flash_offset;
 	fhdr_v1->app_code_jump_vector = entry_point;
 
@@ -649,6 +648,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
 {
 	struct imx_header *imxhdr = (struct imx_header *)ptr;
 	uint32_t dcd_len;
+	uint32_t imx_hdr_size;
 
 	/*
 	 * In order to not change the old imx cfg file
@@ -664,12 +664,13 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
 	/* Parse dcd configuration file */
 	dcd_len = parse_cfg_file(imxhdr, params->imagename);
 
-	if (imximage_version == IMXIMAGE_V2) {
-		if (imximage_init_loadsize < imximage_ivt_offset +
-			sizeof(imx_header_v2_t))
-				imximage_init_loadsize = imximage_ivt_offset +
-					sizeof(imx_header_v2_t);
-	}
+	if (imximage_version == IMXIMAGE_V1)
+		imx_hdr_size = sizeof(imx_header_v1_t);
+	else
+		imx_hdr_size = sizeof(imx_header_v2_t);
+
+	if (imximage_init_loadsize < imximage_ivt_offset + imx_hdr_size)
+		imximage_init_loadsize = imximage_ivt_offset + imx_hdr_size;
 
 	/* Set the imx header */
 	(*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_ivt_offset);
@@ -722,6 +723,7 @@ static int imximage_generate(struct image_tool_params *params,
 	struct stat sbuf;
 	char *datafile = params->datafile;
 	uint32_t pad_len;
+	uint32_t imx_hdr_size;
 
 	memset(&imximage_header, 0, sizeof(imximage_header));
 
@@ -739,16 +741,15 @@ static int imximage_generate(struct image_tool_params *params,
 	/* Parse dcd configuration file */
 	parse_cfg_file(&imximage_header, params->imagename);
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	if (imximage_version == IMXIMAGE_V1) {
-		alloc_len = 4096;
-	} else {
-		if (imximage_init_loadsize < imximage_ivt_offset +
-			sizeof(imx_header_v2_t))
-				imximage_init_loadsize = imximage_ivt_offset +
-					sizeof(imx_header_v2_t);
-		alloc_len = imximage_init_loadsize - imximage_ivt_offset;
-	}
+	if (imximage_version == IMXIMAGE_V1)
+		imx_hdr_size = sizeof(imx_header_v1_t);
+	else
+		imx_hdr_size = sizeof(imx_header_v2_t);
+
+	if (imximage_init_loadsize < imximage_ivt_offset + imx_hdr_size)
+		imximage_init_loadsize = imximage_ivt_offset + imx_hdr_size;
+
+	alloc_len = imximage_init_loadsize - imximage_ivt_offset;
 
 	if (alloc_len < sizeof(struct imx_header)) {
 		fprintf(stderr, "%s: header error\n",
@@ -779,11 +780,7 @@ static int imximage_generate(struct image_tool_params *params,
 
 	pad_len = ROUND(sbuf.st_size, 4096) - sbuf.st_size;
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	if (imximage_version == IMXIMAGE_V1)
-		return 0;
-	else
-		return pad_len;
+	return pad_len;
 }
 
 
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH RESEND 1/1 tools: imximage: use 'new style' header length for imximage v1

From: Martin Kaiser <[email protected]>

We can use the same mechanism for the imximage v1 header length calculations that we're using for v2. Doing so, we can share more code between v1 and v2.

Additionally, *header_size_ptr in imximage_set_header() will then have the correct value for both v1 and v2.

---

I discovered the problem when I tried to use csf_ptr with imximage v1 (as part of a private modification).

*csf_ptr = params->ep + *header_size_ptr - imximage_init_loadsize;
         = params->ep + sbuf->st_size +
                     imximage_ivt_offset - imximage_init_loadsize;
         = params->ep + padded data file size + alloc_len -
                     (imximage_init_loadsize - imximage_ivt_offset);

This works only if
alloc_len == imximage_init_loadsize - imximage_ivt_offset, not if alloc_len is always 4096.

 tools/imximage.c |   43 ++++++++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 23 deletions(-)

Resending this patch after one month of silence. Is there anything I can do to get this reviewed? My tests haven't shown any problems so far.

tools/imximage.c +20 -23
index 092d550..e280da6 100644
@@ -291,8 +291,7 @@ static void set_imx_hdr_v1(struct imx_header *imxhdr, uint32_t dcd_len,
 	/* Set magic number */
 	fhdr_v1->app_code_barker = APP_CODE_BARKER;
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	hdr_base = entry_point - 4096;
+	hdr_base = entry_point - imximage_init_loadsize + flash_offset;
 	fhdr_v1->app_dest_ptr = hdr_base - flash_offset;
 	fhdr_v1->app_code_jump_vector = entry_point;
 
@@ -649,6 +648,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
 {
 	struct imx_header *imxhdr = (struct imx_header *)ptr;
 	uint32_t dcd_len;
+	uint32_t imx_hdr_size;
 
 	/*
 	 * In order to not change the old imx cfg file
@@ -664,12 +664,13 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
 	/* Parse dcd configuration file */
 	dcd_len = parse_cfg_file(imxhdr, params->imagename);
 
-	if (imximage_version == IMXIMAGE_V2) {
-		if (imximage_init_loadsize < imximage_ivt_offset +
-			sizeof(imx_header_v2_t))
-				imximage_init_loadsize = imximage_ivt_offset +
-					sizeof(imx_header_v2_t);
-	}
+	if (imximage_version == IMXIMAGE_V1)
+		imx_hdr_size = sizeof(imx_header_v1_t);
+	else
+		imx_hdr_size = sizeof(imx_header_v2_t);
+
+	if (imximage_init_loadsize < imximage_ivt_offset + imx_hdr_size)
+		imximage_init_loadsize = imximage_ivt_offset + imx_hdr_size;
 
 	/* Set the imx header */
 	(*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_ivt_offset);
@@ -722,6 +723,7 @@ static int imximage_generate(struct image_tool_params *params,
 	struct stat sbuf;
 	char *datafile = params->datafile;
 	uint32_t pad_len;
+	uint32_t imx_hdr_size;
 
 	memset(&imximage_header, 0, sizeof(imximage_header));
 
@@ -739,16 +741,15 @@ static int imximage_generate(struct image_tool_params *params,
 	/* Parse dcd configuration file */
 	parse_cfg_file(&imximage_header, params->imagename);
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	if (imximage_version == IMXIMAGE_V1) {
-		alloc_len = 4096;
-	} else {
-		if (imximage_init_loadsize < imximage_ivt_offset +
-			sizeof(imx_header_v2_t))
-				imximage_init_loadsize = imximage_ivt_offset +
-					sizeof(imx_header_v2_t);
-		alloc_len = imximage_init_loadsize - imximage_ivt_offset;
-	}
+	if (imximage_version == IMXIMAGE_V1)
+		imx_hdr_size = sizeof(imx_header_v1_t);
+	else
+		imx_hdr_size = sizeof(imx_header_v2_t);
+
+	if (imximage_init_loadsize < imximage_ivt_offset + imx_hdr_size)
+		imximage_init_loadsize = imximage_ivt_offset + imx_hdr_size;
+
+	alloc_len = imximage_init_loadsize - imximage_ivt_offset;
 
 	if (alloc_len < sizeof(struct imx_header)) {
 		fprintf(stderr, "%s: header error\n",
@@ -779,11 +780,7 @@ static int imximage_generate(struct image_tool_params *params,
 
 	pad_len = ROUND(sbuf.st_size, 4096) - sbuf.st_size;
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	if (imximage_version == IMXIMAGE_V1)
-		return 0;
-	else
-		return pad_len;
+	return pad_len;
 }
 
 
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH RESEND 1/1 tools: imximage: use 'new style' header length for imximage v1

Thus wrote Martin Kaiser (lists at kaiser.cx):

Quoted 2 lines

Resending this patch after one month of silence. Is there anything I can do to get this reviewed? My tests haven't shown any problems so far.

I just saw that the patch doesn't apply to master any more. I'll check this and send an updated version.

Sorry for the noise,

Martin

#3 lore raw

PATCH 1/1 tools: imximage: refactor header length calculations for imximage v1

In reply to Martin Kaiser

From: Martin Kaiser <[email protected]>

We can use the same header length calculations for both imximage v1 and v2. This addresses TODO comments about imximage v1 in the current code.

With this patch applied, *header_size_ptr in imximage_set_header() will have the correct value for both imximage v1 and v2. This is necessary for people wanting to add proprietary data behind the created imximage.

---

I discovered the problem when I tried to use csf_ptr with imximage v1 (as part of a private modification).

*csf_ptr = params->ep + *header_size_ptr - imximage_init_loadsize;
         = params->ep + sbuf->st_size +
                     imximage_ivt_offset - imximage_init_loadsize;
         = params->ep + padded data file size + alloc_len -
                     (imximage_init_loadsize - imximage_ivt_offset);

This works only if
alloc_len == imximage_init_loadsize - imximage_ivt_offset, not if alloc_len is always 4096.

I updated the patch to apply against master and reworded the commit message. Thanks in advance for reviewing it.

 tools/imximage.c |   38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)
tools/imximage.c +16 -22
index c9e42ec..72ca143 100644
@@ -301,8 +301,7 @@ static void set_imx_hdr_v1(struct imx_header *imxhdr, uint32_t dcd_len,
 	/* Set magic number */
 	fhdr_v1->app_code_barker = APP_CODE_BARKER;
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	hdr_base = entry_point - 4096;
+	hdr_base = entry_point - imximage_init_loadsize + flash_offset;
 	fhdr_v1->app_dest_ptr = hdr_base - flash_offset;
 	fhdr_v1->app_code_jump_vector = entry_point;
 
@@ -825,18 +824,19 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
 	/* Parse dcd configuration file */
 	dcd_len = parse_cfg_file(imxhdr, params->imagename);
 
-	if (imximage_version == IMXIMAGE_V2) {
+	if (imximage_version == IMXIMAGE_V1)
+		header_size = sizeof(flash_header_v1_t);
+	else {
 		header_size = sizeof(flash_header_v2_t) + sizeof(boot_data_t);
 		if (!plugin_image)
 			header_size += sizeof(dcd_v2_t);
 		else
 			header_size += MAX_PLUGIN_CODE_SIZE;
-
-		if (imximage_init_loadsize < imximage_ivt_offset + header_size)
-				imximage_init_loadsize = imximage_ivt_offset +
-					header_size;
 	}
 
+	if (imximage_init_loadsize < imximage_ivt_offset + header_size)
+			imximage_init_loadsize = imximage_ivt_offset + header_size;
+
 	/* Set the imx header */
 	(*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_ivt_offset);
 
@@ -905,23 +905,21 @@ static int imximage_generate(struct image_tool_params *params,
 	/* Parse dcd configuration file */
 	parse_cfg_file(&imximage_header, params->imagename);
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	if (imximage_version == IMXIMAGE_V1) {
-		alloc_len = 4096;
-		header_size = 4096;
-	} else {
+	if (imximage_version == IMXIMAGE_V1)
+		header_size = sizeof(imx_header_v1_t);
+	else {
 		header_size = sizeof(flash_header_v2_t) + sizeof(boot_data_t);
 		if (!plugin_image)
 			header_size += sizeof(dcd_v2_t);
 		else
 			header_size += MAX_PLUGIN_CODE_SIZE;
-
-		if (imximage_init_loadsize < imximage_ivt_offset + header_size)
-				imximage_init_loadsize = imximage_ivt_offset +
-					header_size;
-		alloc_len = imximage_init_loadsize - imximage_ivt_offset;
 	}
 
+	if (imximage_init_loadsize < imximage_ivt_offset + header_size)
+			imximage_init_loadsize = imximage_ivt_offset + header_size;
+
+	alloc_len = imximage_init_loadsize - imximage_ivt_offset;
+
 	if (alloc_len < header_size) {
 		fprintf(stderr, "%s: header error\n",
 			params->cmdname);
@@ -951,11 +949,7 @@ static int imximage_generate(struct image_tool_params *params,
 
 	pad_len = ROUND(sbuf.st_size, 4096) - sbuf.st_size;
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	if (imximage_version == IMXIMAGE_V1)
-		return 0;
-	else
-		return pad_len;
+	return pad_len;
 }
 
 
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH RESEND 1/1 tools: imximage: refactor header length calculations for imximage v1

In reply to Martin Kaiser

From: Martin Kaiser <[email protected]>

We can use the same header length calculations for both imximage v1 and v2. This addresses TODO comments about imximage v1 in the current code.

With this patch applied, *header_size_ptr in imximage_set_header() will have the correct value for both imximage v1 and v2. This is necessary for people wanting to add proprietary data behind the created imximage.

Cc sbabic at denx.de

---

I discovered the problem when I tried to use csf_ptr with imximage v1 (as part of a private modification).

*csf_ptr = params->ep + *header_size_ptr - imximage_init_loadsize;
         = params->ep + sbuf->st_size +
                     imximage_ivt_offset - imximage_init_loadsize;
         = params->ep + padded data file size + alloc_len -
                     (imximage_init_loadsize - imximage_ivt_offset);

This works only if
alloc_len == imximage_init_loadsize - imximage_ivt_offset, not if alloc_len is always 4096.

I rebased my tree to make sure that the patch still applies against current master. I'd really appreciate any feedback, this has been pending since September.

 tools/imximage.c |   38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)
tools/imximage.c +16 -22
index 2cd8d88..0c43196 100644
@@ -300,8 +300,7 @@ static void set_imx_hdr_v1(struct imx_header *imxhdr, uint32_t dcd_len,
 	/* Set magic number */
 	fhdr_v1->app_code_barker = APP_CODE_BARKER;
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	hdr_base = entry_point - 4096;
+	hdr_base = entry_point - imximage_init_loadsize + flash_offset;
 	fhdr_v1->app_dest_ptr = hdr_base - flash_offset;
 	fhdr_v1->app_code_jump_vector = entry_point;
 
@@ -833,18 +832,19 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
 	/* Parse dcd configuration file */
 	dcd_len = parse_cfg_file(imxhdr, params->imagename);
 
-	if (imximage_version == IMXIMAGE_V2) {
+	if (imximage_version == IMXIMAGE_V1)
+		header_size = sizeof(flash_header_v1_t);
+	else {
 		header_size = sizeof(flash_header_v2_t) + sizeof(boot_data_t);
 		if (!plugin_image)
 			header_size += sizeof(dcd_v2_t);
 		else
 			header_size += MAX_PLUGIN_CODE_SIZE;
-
-		if (imximage_init_loadsize < imximage_ivt_offset + header_size)
-				imximage_init_loadsize = imximage_ivt_offset +
-					header_size;
 	}
 
+	if (imximage_init_loadsize < imximage_ivt_offset + header_size)
+			imximage_init_loadsize = imximage_ivt_offset + header_size;
+
 	/* Set the imx header */
 	(*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_ivt_offset);
 
@@ -913,23 +913,21 @@ static int imximage_generate(struct image_tool_params *params,
 	/* Parse dcd configuration file */
 	parse_cfg_file(&imximage_header, params->imagename);
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	if (imximage_version == IMXIMAGE_V1) {
-		alloc_len = 4096;
-		header_size = 4096;
-	} else {
+	if (imximage_version == IMXIMAGE_V1)
+		header_size = sizeof(imx_header_v1_t);
+	else {
 		header_size = sizeof(flash_header_v2_t) + sizeof(boot_data_t);
 		if (!plugin_image)
 			header_size += sizeof(dcd_v2_t);
 		else
 			header_size += MAX_PLUGIN_CODE_SIZE;
-
-		if (imximage_init_loadsize < imximage_ivt_offset + header_size)
-				imximage_init_loadsize = imximage_ivt_offset +
-					header_size;
-		alloc_len = imximage_init_loadsize - imximage_ivt_offset;
 	}
 
+	if (imximage_init_loadsize < imximage_ivt_offset + header_size)
+			imximage_init_loadsize = imximage_ivt_offset + header_size;
+
+	alloc_len = imximage_init_loadsize - imximage_ivt_offset;
+
 	if (alloc_len < header_size) {
 		fprintf(stderr, "%s: header error\n",
 			params->cmdname);
@@ -959,11 +957,7 @@ static int imximage_generate(struct image_tool_params *params,
 
 	pad_len = ROUND(sbuf.st_size, 4096) - sbuf.st_size;
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	if (imximage_version == IMXIMAGE_V1)
-		return 0;
-	else
-		return pad_len;
+	return pad_len;
 }
 
 
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH RESEND 1/1 tools: imximage: refactor header length calculations for imximage v1

Hi Martin,

Quoted 5 lines · Martin Kaiser

From: Martin Kaiser <[email protected]>

We can use the same header length calculations for both imximage v1 and v2. This addresses TODO comments about imximage v1 in the current code.

I see, absoulutely a good idea.

Quoted 17 lines

With this patch applied, *header_size_ptr in imximage_set_header() will have the correct value for both imximage v1 and v2. This is necessary for people wanting to add proprietary data behind the created imximage.

Cc sbabic at denx.de

---

I discovered the problem when I tried to use csf_ptr with imximage v1 (as part of a private modification).

*csf_ptr = params->ep + *header_size_ptr - imximage_init_loadsize;
         = params->ep + sbuf->st_size +
                     imximage_ivt_offset - imximage_init_loadsize;
         = params->ep + padded data file size + alloc_len -
                     (imximage_init_loadsize - imximage_ivt_offset);
Quoted 4 lines

This works only if
alloc_len == imximage_init_loadsize - imximage_ivt_offset, not if alloc_len is always 4096.

I remember that this was a "reasonable" value that initially avoided overlapping. But it was not computed.

Quoted 79 lines

I rebased my tree to make sure that the patch still applies against current master. I'd really appreciate any feedback, this has been pending since September.

 tools/imximage.c |   38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)
tools/imximage.c +15 -17
index 2cd8d88..0c43196 100644
@@ -300,8 +300,7 @@ static void set_imx_hdr_v1(struct imx_header *imxhdr, uint32_t dcd_len,
 	/* Set magic number */
 	fhdr_v1->app_code_barker = APP_CODE_BARKER;
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	hdr_base = entry_point - 4096;
+	hdr_base = entry_point - imximage_init_loadsize + flash_offset;
 	fhdr_v1->app_dest_ptr = hdr_base - flash_offset;
 	fhdr_v1->app_code_jump_vector = entry_point;
 
@@ -833,18 +832,19 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
 	/* Parse dcd configuration file */
 	dcd_len = parse_cfg_file(imxhdr, params->imagename);
 
-	if (imximage_version == IMXIMAGE_V2) {
+	if (imximage_version == IMXIMAGE_V1)
+		header_size = sizeof(flash_header_v1_t);
+	else {
 		header_size = sizeof(flash_header_v2_t) + sizeof(boot_data_t);
 		if (!plugin_image)
 			header_size += sizeof(dcd_v2_t);
 		else
 			header_size += MAX_PLUGIN_CODE_SIZE;
-
-		if (imximage_init_loadsize < imximage_ivt_offset + header_size)
-				imximage_init_loadsize = imximage_ivt_offset +
-					header_size;
 	}
 
+	if (imximage_init_loadsize < imximage_ivt_offset + header_size)
+			imximage_init_loadsize = imximage_ivt_offset + header_size;
+
 	/* Set the imx header */
 	(*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_ivt_offset);
 
@@ -913,23 +913,21 @@ static int imximage_generate(struct image_tool_params *params,
 	/* Parse dcd configuration file */
 	parse_cfg_file(&imximage_header, params->imagename);
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	if (imximage_version == IMXIMAGE_V1) {
-		alloc_len = 4096;
-		header_size = 4096;
-	} else {
+	if (imximage_version == IMXIMAGE_V1)
+		header_size = sizeof(imx_header_v1_t);
+	else {
 		header_size = sizeof(flash_header_v2_t) + sizeof(boot_data_t);
 		if (!plugin_image)
 			header_size += sizeof(dcd_v2_t);
 		else
 			header_size += MAX_PLUGIN_CODE_SIZE;
-
-		if (imximage_init_loadsize < imximage_ivt_offset + header_size)
-				imximage_init_loadsize = imximage_ivt_offset +
-					header_size;
-		alloc_len = imximage_init_loadsize - imximage_ivt_offset;
 	}
 
+	if (imximage_init_loadsize < imximage_ivt_offset + header_size)
+			imximage_init_loadsize = imximage_ivt_offset + header_size;
+
+	alloc_len = imximage_init_loadsize - imximage_ivt_offset;
+
 	if (alloc_len < header_size) {
 		fprintf(stderr, "%s: header error\n",
 			params->cmdname);

tools/imximage.c static int imximage_generate(struct image_tool_params *params, · line 961

Quoted 10 lines
tools/imximage.c +1 -5
@@ -959,11 +957,7 @@ static int imximage_generate(struct image_tool_params *params,
 
 	pad_len = ROUND(sbuf.st_size, 4096) - sbuf.st_size;
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	if (imximage_version == IMXIMAGE_V1)
-		return 0;
-	else
-		return pad_len;
+	return pad_len;
 }

IMHO it is ok and it was pending since a lot of time. I merge it.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#6 lore raw

PATCH RESEND 1/1 tools: imximage: refactor header length calculations for imximage v1

In reply to Martin Kaiser
Quoted 108 lines · Martin Kaiser

From: Martin Kaiser <[email protected]>

We can use the same header length calculations for both imximage v1 and v2. This addresses TODO comments about imximage v1 in the current code.

With this patch applied, *header_size_ptr in imximage_set_header() will have the correct value for both imximage v1 and v2. This is necessary for people wanting to add proprietary data behind the created imximage.

Cc sbabic at denx.de

---

I discovered the problem when I tried to use csf_ptr with imximage v1 (as part of a private modification).

*csf_ptr = params->ep + *header_size_ptr - imximage_init_loadsize;
         = params->ep + sbuf->st_size +
                     imximage_ivt_offset - imximage_init_loadsize;
         = params->ep + padded data file size + alloc_len -
                     (imximage_init_loadsize - imximage_ivt_offset);

This works only if
alloc_len == imximage_init_loadsize - imximage_ivt_offset, not if alloc_len is always 4096.

I rebased my tree to make sure that the patch still applies against current master. I'd really appreciate any feedback, this has been pending since September.

 tools/imximage.c |   38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)
tools/imximage.c +15 -17
index 2cd8d88..0c43196 100644
@@ -300,8 +300,7 @@ static void set_imx_hdr_v1(struct imx_header *imxhdr, uint32_t dcd_len,
 	/* Set magic number */
 	fhdr_v1->app_code_barker = APP_CODE_BARKER;
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	hdr_base = entry_point - 4096;
+	hdr_base = entry_point - imximage_init_loadsize + flash_offset;
 	fhdr_v1->app_dest_ptr = hdr_base - flash_offset;
 	fhdr_v1->app_code_jump_vector = entry_point;
 
@@ -833,18 +832,19 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
 	/* Parse dcd configuration file */
 	dcd_len = parse_cfg_file(imxhdr, params->imagename);
 
-	if (imximage_version == IMXIMAGE_V2) {
+	if (imximage_version == IMXIMAGE_V1)
+		header_size = sizeof(flash_header_v1_t);
+	else {
 		header_size = sizeof(flash_header_v2_t) + sizeof(boot_data_t);
 		if (!plugin_image)
 			header_size += sizeof(dcd_v2_t);
 		else
 			header_size += MAX_PLUGIN_CODE_SIZE;
-
-		if (imximage_init_loadsize < imximage_ivt_offset + header_size)
-				imximage_init_loadsize = imximage_ivt_offset +
-					header_size;
 	}
 
+	if (imximage_init_loadsize < imximage_ivt_offset + header_size)
+			imximage_init_loadsize = imximage_ivt_offset + header_size;
+
 	/* Set the imx header */
 	(*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_ivt_offset);
 
@@ -913,23 +913,21 @@ static int imximage_generate(struct image_tool_params *params,
 	/* Parse dcd configuration file */
 	parse_cfg_file(&imximage_header, params->imagename);
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	if (imximage_version == IMXIMAGE_V1) {
-		alloc_len = 4096;
-		header_size = 4096;
-	} else {
+	if (imximage_version == IMXIMAGE_V1)
+		header_size = sizeof(imx_header_v1_t);
+	else {
 		header_size = sizeof(flash_header_v2_t) + sizeof(boot_data_t);
 		if (!plugin_image)
 			header_size += sizeof(dcd_v2_t);
 		else
 			header_size += MAX_PLUGIN_CODE_SIZE;
-
-		if (imximage_init_loadsize < imximage_ivt_offset + header_size)
-				imximage_init_loadsize = imximage_ivt_offset +
-					header_size;
-		alloc_len = imximage_init_loadsize - imximage_ivt_offset;
 	}
 
+	if (imximage_init_loadsize < imximage_ivt_offset + header_size)
+			imximage_init_loadsize = imximage_ivt_offset + header_size;
+
+	alloc_len = imximage_init_loadsize - imximage_ivt_offset;
+
 	if (alloc_len < header_size) {
 		fprintf(stderr, "%s: header error\n",
 			params->cmdname);
@@ -959,11 +957,7 @@ static int imximage_generate(struct image_tool_params *params,
 
 	pad_len = ROUND(sbuf.st_size, 4096) - sbuf.st_size;

tools/imximage.c static int imximage_generate(struct image_tool_params *params, · line 963

Quoted 10 lines
tools/imximage.c +1 -5
 
-	/* TODO: check i.MX image V1 handling, for now use 'old' style */
-	if (imximage_version == IMXIMAGE_V1)
-		return 0;
-	else
-		return pad_len;
+	return pad_len;
 }
 
 

Applied to u-boot-imx, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================