[U-Boot] [PATCH] imximage: Check the IVT offset in the correct location

Fabio Estevam festevam at gmail.com
Thu Mar 8 20:40:33 UTC 2018


From: Fabio Estevam <fabio.estevam at nxp.com>

Sometimes imximage throws the following error:

  CFGS    board/freescale/vf610twr/imximage.cfg.cfgtmp
  CFGS    board/freescale/vf610twr/imximage.cfg.cfgtmp
  MKIMAGE u-boot-dtb.imx
Error: No BOOT_FROM tag in board/freescale/vf610twr/imximage.cfg.cfgtmp
arch/arm/mach-imx/Makefile:100: recipe for target 'u-boot-dtb.imx' failed

This problem happens because imximage_ivt_offset is being checked
at un unsafe point, and in some cases it can be checked prior to
its assignment.

Fix this issue by only checking imximage_ivt_offset after its
assignment has really occurred.

Introduce a check_ivt_offset() function to help on this task.

Reported-by: Breno Lima <breno.lima at nxp.com>
Reported-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
Signed-off-by: Fabio Estevam <fabio.estevam at nxp.com>
---
 tools/imximage.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/tools/imximage.c b/tools/imximage.c
index eb7e682..26339ee 100644
--- a/tools/imximage.c
+++ b/tools/imximage.c
@@ -592,6 +592,15 @@ static void copy_plugin_code(struct imx_header *imxhdr, char *plugin_file)
 	imxhdr->header.hdr_v2.boot_data.plugin = 1;
 }
 
+static void check_ivt_offset(uint32_t offset)
+{
+	/* Exit if there is no field specifying the flash_offset */
+	if (offset == FLASH_OFFSET_UNDEFINED) {
+		fprintf(stderr, "Error: No boot offset specified");
+		exit(EXIT_FAILURE);
+	}
+}
+
 static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,
 				char *name, int lineno, int fld, int dcd_len)
 {
@@ -613,6 +622,7 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,
 	case CMD_BOOT_FROM:
 		imximage_ivt_offset = get_table_entry_id(imximage_boot_offset,
 					"imximage boot option", token);
+		check_ivt_offset(imximage_ivt_offset);
 		if (imximage_ivt_offset == -1) {
 			fprintf(stderr, "Error: %s[%d] -Invalid boot device"
 				"(%s)\n", name, lineno, token);
@@ -641,6 +651,7 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,
 		break;
 	case CMD_BOOT_OFFSET:
 		imximage_ivt_offset = get_cfg_value(token, name, lineno);
+		check_ivt_offset(imximage_ivt_offset);
 		if (unlikely(cmd_ver_first != 1))
 			cmd_ver_first = 0;
 		break;
@@ -777,11 +788,6 @@ static uint32_t parse_cfg_file(struct imx_header *imxhdr, char *name)
 	(*set_dcd_rst)(imxhdr, dcd_len, name, lineno);
 	fclose(fd);
 
-	/* Exit if there is no BOOT_FROM field specifying the flash_offset */
-	if (imximage_ivt_offset == FLASH_OFFSET_UNDEFINED) {
-		fprintf(stderr, "Error: No BOOT_FROM tag in %s\n", name);
-		exit(EXIT_FAILURE);
-	}
 	return dcd_len;
 }
 
-- 
2.7.4



More information about the U-Boot mailing list