Skip to contentSkip to conversation

imximage: Remove overwriting of flash_offset

PATCH Superseded Dirk Behme 2 participants 5 messages Feb 23, 2012 – Mar 7, 2012 Arm i.MX and Layerscape

lore
Share & tools
lore

Dirk Behme

author
#0 lore raw

PATCH v2 1/1 imximage: Remove overwriting of flash_offset

The flash header supports different flash offsets for different boot devices. E.g. parallel NOR or OneNAND use a different offset than FLASH_OFFSET_STANDARD (== 0x400).

The flash offset is correctly read from the configuration in parse_cfg_cmd(). But is then overwritten wrongly in set_imx_hdr_v1/2().

Fix this by removing this overwriting. Use the flash offset correctly read from the configuration, instead.

If there is no flash_offset read from the configuration file, i.e. the BOOT_FROM tag is missing, exit with an error message.

CC Jason Liu <[email protected]>
CC Stefano Babic <[email protected]>

---

Changes in v2:

Make the BOOT_FROM field mandatory, i.e. exit with an error message if there is no valid flash_offset set. Do the same handling in header v1 and v2, not only in v2.

Note: This is tested only for header v2.

 tools/imximage.c |   18 ++++++++++++++----
 tools/imximage.h |    1 +
 2 files changed, 15 insertions(+), 4 deletions(-)
tools/imximage.c +14 -4
index 1e0f5d4..03a7716 100644
@@ -216,8 +216,12 @@ static void set_imx_hdr_v1(struct imx_header *imxhdr, uint32_t dcd_len,
 	dcd_v1_t *dcd_v1 = &hdr_v1->dcd_table;
 	uint32_t base_offset;
 
-	/* Set default offset */
-	imxhdr->flash_offset = FLASH_OFFSET_STANDARD;
+	/* Exit if there is no BOOT_FROM field specifying the flash_offset */
+	if(imxhdr->flash_offset == FLASH_OFFSET_UNDEFINED) {
+		fprintf(stderr, "Error: Header v1: No BOOT_FROM tag in %s\n",
+			params->imagename);
+		exit(EXIT_FAILURE);
+	}
 
 	/* Set magic number */
 	fhdr_v1->app_code_barker = APP_CODE_BARKER;
@@ -253,8 +257,12 @@ static void set_imx_hdr_v2(struct imx_header *imxhdr, uint32_t dcd_len,
 	imx_header_v2_t *hdr_v2 = &imxhdr->header.hdr_v2;
 	flash_header_v2_t *fhdr_v2 = &hdr_v2->fhdr;
 
-	/* Set default offset */
-	imxhdr->flash_offset = FLASH_OFFSET_STANDARD;
+	/* Exit if there is no BOOT_FROM field specifying the flash_offset */
+	if(imxhdr->flash_offset == FLASH_OFFSET_UNDEFINED) {
+		fprintf(stderr, "Error: Header v2: No BOOT_FROM tag in %s\n",
+			params->imagename);
+		exit(EXIT_FAILURE);
+	}
 
 	/* Set magic number */
 	fhdr_v2->header.tag = IVT_HEADER_TAG; /* 0xD1 */
@@ -525,6 +533,8 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
 	 * set up function ptr group to V1 by default.
 	 */
 	imximage_version = IMXIMAGE_V1;
+	/* Be able to detect if the cfg file has no BOOT_FROM tag */
+	imxhdr->flash_offset = FLASH_OFFSET_UNDEFINED;
 	set_hdr_func(imxhdr);
 
 	/* Parse dcd configuration file */
tools/imximage.h +1 -0
index d784a8d..34f293d 100644
@@ -32,6 +32,7 @@
 #define HEADER_OFFSET	0x400
 
 #define CMD_DATA_STR	"DATA"
+#define FLASH_OFFSET_UNDEFINED	0xFFFFFFFF
 #define FLASH_OFFSET_STANDARD	0x400
 #define FLASH_OFFSET_NAND	FLASH_OFFSET_STANDARD
 #define FLASH_OFFSET_SD		FLASH_OFFSET_STANDARD
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH v2 1/1 imximage: Remove overwriting of flash_offset

Quoted 10 lines · Dirk Behme

The flash header supports different flash offsets for different boot devices. E.g. parallel NOR or OneNAND use a different offset than FLASH_OFFSET_STANDARD (== 0x400).

The flash offset is correctly read from the configuration in parse_cfg_cmd(). But is then overwritten wrongly in set_imx_hdr_v1/2().

Fix this by removing this overwriting. Use the flash offset correctly read from the configuration, instead.

Quoted 7 lines

If there is no flash_offset read from the configuration file, i.e. the BOOT_FROM tag is missing, exit with an error message.

CC Jason Liu <[email protected]>
CC Stefano Babic <[email protected]>

---

Tested on ima-mx53 with MX53 (header V2), booting from NOR.

Dirk,

apart this patch that fixes in any case a wrong offset in header, I have investigated in more detail this issue. The bug sets a wrong value in the boot_data.start field that inform the processor which is the start address of the image to be copied into the RAM. All other fields are still correct.

However, if we boot from NOR we have a XIP device and we do not need this first copy into the RAM. We could skip it if we set CONFIG_SYS_TEXT_BASE to point to a region in the NOR flash, as it is usually done when booting from NOR (see for example PowerPc boards). I understand that this is the reason why my board has always booted, while yours not. Is it right ? Where do you set CONFIG_SYS_TEXT_BASE ?

As optimization, we could also avoid that the processor starts to copy the image by setting boot_data.size=0 in the header when NOR device is set, but only if we are sure that no copy into RAM is required.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
author
#2 lore raw

PATCH v2 1/1 imximage: Remove overwriting of flash_offset

Quoted 32 lines · Stefano Babic
Quoted 10 lines · Dirk Behme

The flash header supports different flash offsets for different boot devices. E.g. parallel NOR or OneNAND use a different offset than FLASH_OFFSET_STANDARD (== 0x400).

The flash offset is correctly read from the configuration in parse_cfg_cmd(). But is then overwritten wrongly in set_imx_hdr_v1/2().

Fix this by removing this overwriting. Use the flash offset correctly read from the configuration, instead.

Quoted 7 lines

If there is no flash_offset read from the configuration file, i.e. the BOOT_FROM tag is missing, exit with an error message.

CC Jason Liu <[email protected]>
CC Stefano Babic <[email protected]>

---

Tested on ima-mx53 with MX53 (header V2), booting from NOR.

Dirk,

apart this patch that fixes in any case a wrong offset in header, I have investigated in more detail this issue. The bug sets a wrong value in the boot_data.start field that inform the processor which is the start address of the image to be copied into the RAM. All other fields are still correct.

Quoted 6 lines

However, if we boot from NOR we have a XIP device and we do not need this first copy into the RAM. We could skip it if we set CONFIG_SYS_TEXT_BASE to point to a region in the NOR flash, as it is usually done when booting from NOR (see for example PowerPc boards). I understand that this is the reason why my board has always booted, while yours not. Is it right ?

Ah, XIP. Yes, this does make sense! :)

Quoted 1 line

Where do you set CONFIG_SYS_TEXT_BASE ?

To main memory, i.e. no XIP.

We just took the configuration as it is in mainline and normally is used to start from SD card: Initialize the main memory using the DCD data. And then copy the image to main memory, e.g. 0x17800000, and jump to it. And this jump fails if boot_data.start is wrong.

Many thanks for this update!

Best regards

Dirk

#3 lore raw

PATCH v2 1/1 imximage: Remove overwriting of flash_offset

In reply to Dirk Behme
Quoted 10 lines · Dirk Behme

The flash header supports different flash offsets for different boot devices. E.g. parallel NOR or OneNAND use a different offset than FLASH_OFFSET_STANDARD (== 0x400).

The flash offset is correctly read from the configuration in parse_cfg_cmd(). But is then overwritten wrongly in set_imx_hdr_v1/2().

Fix this by removing this overwriting. Use the flash offset correctly read from the configuration, instead.

Quoted 7 lines

If there is no flash_offset read from the configuration file, i.e. the BOOT_FROM tag is missing, exit with an error message.

CC Jason Liu <[email protected]>
CC Stefano Babic <[email protected]>

---

Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#4 lore raw

PATCH v2 1/1 imximage: Remove overwriting of flash_offset

In reply to Dirk Behme
Quoted 10 lines · Dirk Behme

The flash header supports different flash offsets for different boot devices. E.g. parallel NOR or OneNAND use a different offset than FLASH_OFFSET_STANDARD (== 0x400).

The flash offset is correctly read from the configuration in parse_cfg_cmd(). But is then overwritten wrongly in set_imx_hdr_v1/2().

Fix this by removing this overwriting. Use the flash offset correctly read from the configuration, instead.

Quoted 7 lines

If there is no flash_offset read from the configuration file, i.e. the BOOT_FROM tag is missing, exit with an error message.

CC Jason Liu <[email protected]>
CC Stefano Babic <[email protected]>

---

Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================