diff mbox

[U-Boot,V3,08/32] imximage: make header variable length

Message ID 1349315254-21151-9-git-send-email-troy.kisky@boundarydevices.com
State Changes Requested
Delegated to: Stefano Babic
Headers show

Commit Message

Troy Kisky Oct. 4, 2012, 1:47 a.m. UTC
This makes the dcd table options as well for v2.
Also, the header offset is no longer
right before the code starts.

Before this patch we have
000000 402000d1 17800000 00000000 177ffc2c
000010 177ffc20 177ffc00 00000000 00000000
000020 177ff800 00042b58 00000000 402803d2
000030 042403cc a8050e02 30000000 b0050e02
... more DCD table
000340 cf0000f0 18000e02 7f007f00 1c000e02
000350 7f007f00 00000000 00000000 00000000
000360 00000000 00000000 00000000 00000000
*
0003f0 00000000 00000000 00000000 00000400
000400 ea000014 e59ff014 e59ff014 e59ff014

Notice offset 3fc contains 0x400. This
is the header offset. There is no reason
for this to be in the file, and I have
removed it.

After this patch we have
000000 402000d1 17800000 00000000 177ffcd8
000010 177ffccc 177ffcac 00000000 00000000
000020 177ff8ac 000426ac 00000000 402803d2
000030 042403cc a8050e02 30000000 b0050e02
... more DCD table
000340 cf0000f0 18000e02 7f007f00 1c000e02
000350 7f007f00 ea000014 e59ff014 e59ff014
000360 e59ff014 e59ff014 e59ff014 e59ff014

Notice the zeros between 0x354 and 0x3fb have
been removed.

Signed-off-by: Troy Kisky <troy.kisky@boundarydevices.com>

---

v3: other patches split from this one
---
 tools/imximage.c |   61 +++++++++++++++++++++++++++++++++++++-----------------
 tools/imximage.h |    4 ++--
 2 files changed, 44 insertions(+), 21 deletions(-)

Comments

Stefano Babic Oct. 20, 2012, 3:52 p.m. UTC | #1
Am 04/10/2012 03:47, schrieb Troy Kisky:
> This makes the dcd table options as well for v2.
> Also, the header offset is no longer
> right before the code starts.
> 
> Before this patch we have
> 000000 402000d1 17800000 00000000 177ffc2c
> 000010 177ffc20 177ffc00 00000000 00000000
> 000020 177ff800 00042b58 00000000 402803d2
> 000030 042403cc a8050e02 30000000 b0050e02
> ... more DCD table
> 000340 cf0000f0 18000e02 7f007f00 1c000e02
> 000350 7f007f00 00000000 00000000 00000000
> 000360 00000000 00000000 00000000 00000000
> *
> 0003f0 00000000 00000000 00000000 00000400
> 000400 ea000014 e59ff014 e59ff014 e59ff014
> 
> Notice offset 3fc contains 0x400. This
> is the header offset. There is no reason
> for this to be in the file, and I have
> removed it.
> 
> After this patch we have
> 000000 402000d1 17800000 00000000 177ffcd8
> 000010 177ffccc 177ffcac 00000000 00000000
> 000020 177ff8ac 000426ac 00000000 402803d2
> 000030 042403cc a8050e02 30000000 b0050e02
> ... more DCD table
> 000340 cf0000f0 18000e02 7f007f00 1c000e02
> 000350 7f007f00 ea000014 e59ff014 e59ff014
> 000360 e59ff014 e59ff014 e59ff014 e59ff014
> 
> Notice the zeros between 0x354 and 0x3fb have
> been removed.
> 
> Signed-off-by: Troy Kisky <troy.kisky@boundarydevices.com>
> 
> ---


Hi Troy,

my test with this patch was not successful. I have tested it on a
mx53loco, and the board cannot boot. It stops after printing the RAM size:


U-Boot 2012.10-00226-g673b6b8 (Oct 20 2012 - 17:40:07)

Board: MX53 LOCO
I2C:   ready
DRAM:  1 GiB

Everything works fine without the patch (patches 1-7 already applied,
too). I wanted to test on V1 SOCs, too, but I stopped after seeing that
on a MX53 is not working.

Best regards,
Stefano Babic
Troy Kisky Nov. 28, 2012, 1:31 a.m. UTC | #2
This series make the file imximage.c easier to read, as well
as produces a slightly smaller file.


Only the 1st two patches are different from version 3. The
1st is a new patch which addresses an mx53 ROM bug. The 2nd
is slight changes due to rebase on 1st.



Troy Kisky (11):
  imximage: mx53 needs transfer length a multiple of 512
  imximage: make header variable length
  imximage: remove static imximage_version
  imximage: prepare to move static variables to struct data_src
  imximage: change parameters for set_dcd_val/set_imx_hdr
  imximage: move set_imx_hdr to struct data_src
  imximage: move set_dcd_val to struct data_src
  imximage: enable word writes for version2 header
  tools: add parse_helper file
  imximage: use parse_helper functions
  parse_helper: add expression evaluation

 tools/Makefile       |    2 +
 tools/imximage.c     |  437 ++++++++++++++++++++++----------------------------
 tools/imximage.h     |   37 ++---
 tools/parse_helper.c |  325 +++++++++++++++++++++++++++++++++++++
 tools/parse_helper.h |   28 ++++
 5 files changed, 564 insertions(+), 265 deletions(-)
 create mode 100644 tools/parse_helper.c
 create mode 100644 tools/parse_helper.h
Wolfgang Denk Nov. 28, 2012, 9:30 a.m. UTC | #3
Dear Troy Kisky,

In message <1354066303-29762-1-git-send-email-troy.kisky@boundarydevices.com> you wrote:
> 
> This series make the file imximage.c easier to read, as well
> as produces a slightly smaller file.
> 
> 
> Only the 1st two patches are different from version 3. The
> 1st is a new patch which addresses an mx53 ROM bug. The 2nd
> is slight changes due to rebase on 1st.

Would it make sense to use this opportunity to integrate this tool
into mkimage ?

Best regards,

Wolfgang Denk
Troy Kisky Nov. 28, 2012, 6:29 p.m. UTC | #4
On 11/28/2012 2:30 AM, Wolfgang Denk wrote:
> Dear Troy Kisky,
>
> In message <1354066303-29762-1-git-send-email-troy.kisky@boundarydevices.com> you wrote:
>> This series make the file imximage.c easier to read, as well
>> as produces a slightly smaller file.
>>
>>
>> Only the 1st two patches are different from version 3. The
>> 1st is a new patch which addresses an mx53 ROM bug. The 2nd
>> is slight changes due to rebase on 1st.
> Would it make sense to use this opportunity to integrate this tool
> into mkimage ?
>
> Best regards,
>
> Wolfgang Denk
>
I did not mean to imply that it wasn't already in mkimage, but I can see
that interpretation. It is part of mkimage.

Troy
diff mbox

Patch

diff --git a/tools/imximage.c b/tools/imximage.c
index 63f88b6..1365b1e 100644
--- a/tools/imximage.c
+++ b/tools/imximage.c
@@ -65,7 +65,6 @@  static table_entry_t imximage_versions[] = {
 	{-1,            "",     " (Invalid)",                 },
 };
 
-static struct imx_header imximage_header;
 static uint32_t imximage_version;
 
 static set_dcd_val_t set_dcd_val;
@@ -73,6 +72,9 @@  static set_dcd_rst_t set_dcd_rst;
 static set_imx_hdr_t set_imx_hdr;
 static uint32_t max_dcd_entries;
 static uint32_t *header_size_ptr;
+static uint32_t g_flash_offset;
+
+static struct image_type_params imximage_params;
 
 static uint32_t get_cfg_value(char *token, char *name,  int linenr)
 {
@@ -102,8 +104,7 @@  static uint32_t detect_imximage_version(struct imx_header *imx_hdr)
 		return IMXIMAGE_V1;
 
 	/* Try to detect V2 */
-	if ((fhdr_v2->header.tag == IVT_HEADER_TAG) &&
-		(hdr_v2->dcd_table.header.tag == DCD_HEADER_TAG))
+	if (fhdr_v2->header.tag == IVT_HEADER_TAG)
 		return IMXIMAGE_V2;
 
 	return IMXIMAGE_VER_INVALID;
@@ -195,7 +196,7 @@  static void set_dcd_rst_v2(struct imx_header *imxhdr, uint32_t dcd_len,
 	dcd_v2->write_dcd_command.param = DCD_COMMAND_PARAM;
 }
 
-static void set_imx_hdr_v1(struct imx_header *imxhdr, uint32_t dcd_len,
+static int set_imx_hdr_v1(struct imx_header *imxhdr, uint32_t dcd_len,
 		uint32_t entry_point, uint32_t flash_offset)
 {
 	imx_header_v1_t *hdr_v1 = &imxhdr->header.hdr_v1;
@@ -208,7 +209,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;
 
-	hdr_base = entry_point - sizeof(struct imx_header);
+	hdr_base = entry_point - header_length;
 	fhdr_v1->app_dest_ptr = hdr_base - flash_offset;
 	fhdr_v1->app_code_jump_vector = entry_point;
 
@@ -219,14 +220,18 @@  static void set_imx_hdr_v1(struct imx_header *imxhdr, uint32_t dcd_len,
 	fhdr_v1->app_code_csf = 0;
 	fhdr_v1->super_root_key = 0;
 	header_size_ptr = (uint32_t *)(((char *)imxhdr) + header_length - 4);
+	return header_length;
 }
 
-static void set_imx_hdr_v2(struct imx_header *imxhdr, uint32_t dcd_len,
+static int set_imx_hdr_v2(struct imx_header *imxhdr, uint32_t dcd_len,
 		uint32_t entry_point, uint32_t flash_offset)
 {
 	imx_header_v2_t *hdr_v2 = &imxhdr->header.hdr_v2;
 	flash_header_v2_t *fhdr_v2 = &hdr_v2->fhdr;
 	uint32_t hdr_base;
+	uint32_t header_length = (dcd_len) ?
+		(char *)&hdr_v2->dcd_table.addr_data[dcd_len] - ((char*)imxhdr)
+		: offsetof(imx_header_v2_t, dcd_table);
 
 	/* Set magic number */
 	fhdr_v2->header.tag = IVT_HEADER_TAG; /* 0xD1 */
@@ -235,9 +240,10 @@  static void set_imx_hdr_v2(struct imx_header *imxhdr, uint32_t dcd_len,
 
 	fhdr_v2->entry = entry_point;
 	fhdr_v2->reserved1 = fhdr_v2->reserved2 = 0;
-	fhdr_v2->self = hdr_base = entry_point - sizeof(struct imx_header);
+	fhdr_v2->self = hdr_base = entry_point - header_length;
 
-	fhdr_v2->dcd_ptr = hdr_base + offsetof(imx_header_v2_t, dcd_table);
+	fhdr_v2->dcd_ptr = (dcd_len) ? hdr_base
+			+ offsetof(imx_header_v2_t, dcd_table) : 0;
 	fhdr_v2->boot_data_ptr = hdr_base
 			+ offsetof(imx_header_v2_t, boot_data);
 	hdr_v2->boot_data.start = hdr_base - flash_offset;
@@ -245,6 +251,7 @@  static void set_imx_hdr_v2(struct imx_header *imxhdr, uint32_t dcd_len,
 	/* Security feature are not supported */
 	fhdr_v2->csf = 0;
 	header_size_ptr = &hdr_v2->boot_data.size;
+	return header_length;
 }
 
 static void set_hdr_func(struct imx_header *imxhdr)
@@ -342,9 +349,9 @@  static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,
 		set_hdr_func(imxhdr);
 		break;
 	case CMD_BOOT_FROM:
-		imxhdr->flash_offset = get_table_entry_id(imximage_bootops,
+		g_flash_offset = get_table_entry_id(imximage_bootops,
 					"imximage boot option", token);
-		if (imxhdr->flash_offset == -1) {
+		if (g_flash_offset == -1) {
 			fprintf(stderr, "Error: %s[%d] -Invalid boot device"
 				"(%s)\n", name, lineno, token);
 			exit(EXIT_FAILURE);
@@ -449,7 +456,7 @@  static uint32_t parse_cfg_file(struct imx_header *imxhdr, char *name)
 	fclose(fd);
 
 	/* Exit if there is no BOOT_FROM field specifying the flash_offset */
-	if (imxhdr->flash_offset == FLASH_OFFSET_UNDEFINED) {
+	if (g_flash_offset == FLASH_OFFSET_UNDEFINED) {
 		fprintf(stderr, "Error: No BOOT_FROM tag in %s\n", name);
 		exit(EXIT_FAILURE);
 	}
@@ -494,12 +501,17 @@  static void imximage_print_header(const void *ptr)
 	}
 }
 
-static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
-				struct mkimage_params *params)
+int imximage_vrec_header(struct mkimage_params *params,
+		struct image_type_params *tparams)
 {
-	struct imx_header *imxhdr = (struct imx_header *)ptr;
+	struct imx_header *imxhdr;
 	uint32_t dcd_len;
 
+	imxhdr = calloc(1, MAX_HEADER_SIZE);
+	if (!imxhdr) {
+		fprintf(stderr, "Error: out of memory\n");
+		exit(EXIT_FAILURE);
+	}
 	/*
 	 * In order to not change the old imx cfg file
 	 * by adding VERSION command into it, here need
@@ -507,15 +519,27 @@  static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
 	 */
 	imximage_version = IMXIMAGE_V1;
 	/* Be able to detect if the cfg file has no BOOT_FROM tag */
-	imxhdr->flash_offset = FLASH_OFFSET_UNDEFINED;
+	g_flash_offset = FLASH_OFFSET_UNDEFINED;
 	set_hdr_func(imxhdr);
 
 	/* Parse dcd configuration file */
 	dcd_len = parse_cfg_file(imxhdr, params->imagename);
 
 	/* Set the imx header */
-	(*set_imx_hdr)(imxhdr, dcd_len, params->ep, imxhdr->flash_offset);
-	*header_size_ptr = sbuf->st_size + imxhdr->flash_offset;
+	imximage_params.header_size = (*set_imx_hdr)(imxhdr, dcd_len,
+			params->ep, g_flash_offset);
+	imximage_params.hdr = imxhdr;
+	return 0;
+}
+
+static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
+				struct mkimage_params *params)
+{
+	/* Set the size in header */
+	uint32_t offset = (char *)header_size_ptr - (char *)imximage_params.hdr;
+	uint32_t *p = (uint32_t *)((char *)ptr + offset);
+
+	*p = sbuf->st_size + g_flash_offset;
 }
 
 int imximage_check_params(struct mkimage_params *params)
@@ -545,8 +569,7 @@  int imximage_check_params(struct mkimage_params *params)
  */
 static struct image_type_params imximage_params = {
 	.name		= "Freescale i.MX 5x Boot Image support",
-	.header_size	= sizeof(struct imx_header),
-	.hdr		= (void *)&imximage_header,
+	.vrec_header	= imximage_vrec_header,
 	.check_image_type = imximage_check_image_types,
 	.verify_header	= imximage_verify_header,
 	.print_header	= imximage_print_header,
diff --git a/tools/imximage.h b/tools/imximage.h
index 42b6090..0f39447 100644
--- a/tools/imximage.h
+++ b/tools/imximage.h
@@ -30,6 +30,7 @@ 
 #define DCD_BARKER	0xB17219E9
 
 #define HEADER_OFFSET	0x400
+#define MAX_HEADER_SIZE	(16 << 10)
 
 #define CMD_DATA_STR	"DATA"
 #define FLASH_OFFSET_UNDEFINED	0xFFFFFFFF
@@ -156,7 +157,6 @@  struct imx_header {
 		imx_header_v1_t hdr_v1;
 		imx_header_v2_t hdr_v2;
 	} header;
-	uint32_t flash_offset;
 };
 
 typedef void (*set_dcd_val_t)(struct imx_header *imxhdr,
@@ -168,7 +168,7 @@  typedef void (*set_dcd_rst_t)(struct imx_header *imxhdr,
 					uint32_t dcd_len,
 					char *name, int lineno);
 
-typedef void (*set_imx_hdr_t)(struct imx_header *imxhdr, uint32_t dcd_len,
+typedef int (*set_imx_hdr_t)(struct imx_header *imxhdr, uint32_t dcd_len,
 		uint32_t entry_point, uint32_t flash_offset);
 
 #endif /* _IMXIMAGE_H_ */