[U-Boot] [PATCH 3/3] imximage: Add MX53 boot image support

Jason Liu r64343 at freescale.com
Wed Dec 22 14:23:51 CET 2010


This patch add the MX53 boot image support

This patch has been tested on Freescale MX53EVK board.

Signed-off-by: Jason Liu <r64343 at freescale.com>
---
 board/freescale/mx53evk/config.mk    |   25 ++++++++
 board/freescale/mx53evk/imximage.cfg |  108 ++++++++++++++++++++++++++++++++++
 tools/imximage.c                     |  101 +++++++++++++++++++++++++++++--
 tools/imximage.h                     |   75 ++++++++++++++++++++---
 4 files changed, 293 insertions(+), 16 deletions(-)

diff --git a/board/freescale/mx53evk/config.mk b/board/freescale/mx53evk/config.mk
new file mode 100755
index 0000000..0153165
--- /dev/null
+++ b/board/freescale/mx53evk/config.mk
@@ -0,0 +1,25 @@
+#
+# Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
+IMX_CONFIG = $(SRCTREE)/board/$(BOARDDIR)/imximage.cfg
+ALL += $(obj)u-boot.imx
+
diff --git a/board/freescale/mx53evk/imximage.cfg b/board/freescale/mx53evk/imximage.cfg
new file mode 100644
index 0000000..c86e061
--- /dev/null
+++ b/board/freescale/mx53evk/imximage.cfg
@@ -0,0 +1,108 @@
+#
+# (C Copyright 2009
+# Stefano Babic DENX Software Engineering sbabic at denx.de.
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not write to the Free Software
+# Foundation Inc. 51 Franklin Street Fifth Floor Boston,
+# MA 02110-1301 USA
+#
+# Refer docs/README.imxmage for more details about how-to configure
+# and create imximage boot image
+#
+# The syntax is taken as close as possible with the kwbimage
+
+# Boot Device : one of
+# spi, sd (the board has no nand neither onenand)
+
+BOOT_FROM	sd
+
+# Device Configuration Data (DCD)
+#
+# Each entry must have the format:
+# Addr-type           Address        Value
+#
+# where:
+#	Addr-type register length (1,2 or 4 bytes)
+#	Address	  absolute address of the register
+#	value	  value to be stored in the register
+
+# Setting IOMUXC
+DATA 4 0x53fa8554 0x00200000
+DATA 4 0x53fa8560 0x00200000
+DATA 4 0x53fa8594 0x00200000
+DATA 4 0x53fa8584 0x00200000
+DATA 4 0x53fa8558 0x00200040
+DATA 4 0x53fa8568 0x00200040
+DATA 4 0x53fa8590 0x00200040
+DATA 4 0x53fa857c 0x00200040
+DATA 4 0x53fa8564 0x00200040
+DATA 4 0x53fa8580 0x00200040
+DATA 4 0x53fa8570 0x00200000
+DATA 4 0x53fa8578 0x00200000
+DATA 4 0x53fa872c 0x00200000
+DATA 4 0x53fa8728 0x00200000
+DATA 4 0x53fa871c 0x00200000
+DATA 4 0x53fa8718 0x00200000
+DATA 4 0x53fa8574 0x00280000
+DATA 4 0x53fa8588 0x00280000
+DATA 4 0x53fa86f0 0x00280000
+DATA 4 0x53fa8720 0x00280000
+DATA 4 0x53fa86fc 0x00000000
+DATA 4 0x53fa86f4 0x00000200
+DATA 4 0x53fa8714 0x00000000
+DATA 4 0x53fa8724 0x06000000
+DATA 4 0x63fd9088 0x34333936
+DATA 4 0x63fd9090 0x49434942
+DATA 4 0x63fd90F8 0x00000800
+DATA 4 0x63fd907c 0x01350138
+DATA 4 0x63fd9080 0x01380139
+DATA 4 0x63fd9018 0x00001710
+DATA 4 0x63fd9000 0xc4110000
+DATA 4 0x63fd900C 0x4d5122d2
+DATA 4 0x63fd9010 0x92d18a22
+DATA 4 0x63fd9014 0x00c70092
+DATA 4 0x63fd902c 0x000026d2
+DATA 4 0x63fd9030 0x009f000e
+DATA 4 0x63fd9008 0x12272000
+DATA 4 0x63fd9004 0x00030012
+DATA 4 0x63fd901c 0x04008010
+DATA 4 0x63fd901c 0x00008032
+DATA 4 0x63fd901c 0x00008033
+DATA 4 0x63fd901c 0x00008031
+DATA 4 0x63fd901c 0x0b5280b0
+DATA 4 0x63fd901c 0x04008010
+DATA 4 0x63fd901c 0x00008020
+DATA 4 0x63fd901c 0x00008020
+DATA 4 0x63fd901c 0x0a528030
+DATA 4 0x63fd901c 0x03c68031
+DATA 4 0x63fd901c 0x00448031
+DATA 4 0x63fd901c 0x04008018
+DATA 4 0x63fd901c 0x0000803a
+DATA 4 0x63fd901c 0x0000803b
+DATA 4 0x63fd901c 0x00008039
+DATA 4 0x63fd901c 0x0b528138
+DATA 4 0x63fd901c 0x04008018
+DATA 4 0x63fd901c 0x00008028
+DATA 4 0x63fd901c 0x00008028
+DATA 4 0x63fd901c 0x0a528038
+DATA 4 0x63fd901c 0x03c68039
+DATA 4 0x63fd901c 0x00448039
+DATA 4 0x63fd9020 0x00005800
+DATA 4 0x63fd9058 0x00033335
+DATA 4 0x63fd901c 0x00000000
+DATA 4 0x63fd9040 0x04b80003
+DATA 4 0x53fa8004 0x00194005
diff --git a/tools/imximage.c b/tools/imximage.c
index 39f89c2..884feff 100644
--- a/tools/imximage.c
+++ b/tools/imximage.c
@@ -82,7 +82,7 @@ static int imximage_check_image_types(uint8_t type)
 static int imximage_verify_header(unsigned char *ptr, int image_size,
 			struct mkimage_params *params)
 {
-
+#ifdef CONFIG_MX51
 	struct imx_header *imx_hdr = (struct imx_header *) ptr;
 	flash_header_t *hdr = &imx_hdr->fhdr;
 
@@ -92,18 +92,19 @@ static int imximage_verify_header(unsigned char *ptr, int image_size,
 
 	if (imx_hdr->dcd_table.preamble.barker != DCD_BARKER)
 		return -FDT_ERR_BADSTRUCTURE;
-
+#endif
 	return 0;
 }
 
+#if defined(CONFIG_MX51)
 static void imximage_print_header(const void *ptr)
 {
 	struct imx_header *imx_hdr = (struct imx_header *) ptr;
 	flash_header_t *hdr = &imx_hdr->fhdr;
 	uint32_t size;
 	uint32_t length;
-	dcd_t *dcd = &imx_hdr->dcd_table;
 
+	dcd_t *dcd = &imx_hdr->dcd_table;
 	size = imx_hdr->dcd_table.preamble.length;
 	if (size > (MAX_HW_CFG_SIZE * sizeof(dcd_type_addr_data_t))) {
 		fprintf(stderr,
@@ -121,6 +122,32 @@ static void imximage_print_header(const void *ptr)
 	printf("Load Address: %08x\n", (unsigned int)hdr->app_dest_ptr);
 	printf("Entry Point:  %08x\n", (unsigned int)hdr->app_code_jump_vector);
 }
+#endif
+
+#if defined(CONFIG_MX53)
+static void imximage_print_header(const void *ptr)
+{
+	uint32_t size;
+	struct imx_header *imx_hdr = (struct imx_header *) ptr;
+	flash_header_t *hdr = &imx_hdr->fhdr;
+	dcd_t *dcd = &imx_hdr->dcd_table;
+
+	size = be16_to_cpu(dcd->header.length) - 8;
+	if (size > (MAX_HW_CFG_SIZE * sizeof(dcd_addr_data_t))) {
+		fprintf(stderr,
+			"Error: Image corrupt DCD size %d exceed maximum %d\n",
+			(uint32_t)(size / sizeof(dcd_addr_data_t)),
+			MAX_HW_CFG_SIZE);
+		exit(EXIT_FAILURE);
+	}
+
+	printf("Image Type:   Freescale IMX Boot Image\n");
+	printf("Data Size:    ");
+	genimg_print_size(imx_hdr->boot_data.size);
+	printf("Load Address: %08x\n", (unsigned int)hdr->boot_data_ptr);
+	printf("Entry Point:  %08x\n", (unsigned int)hdr->entry);
+}
+#endif
 
 static uint32_t imximage_parse_cfg_file(struct imx_header *imxhdr, char *name)
 {
@@ -206,7 +233,9 @@ static uint32_t imximage_parse_cfg_file(struct imx_header *imxhdr, char *name)
 							name, lineno, value);
 						exit(EXIT_FAILURE);
 					}
+				#ifdef CONFIG_MX51
 					dcd->addr_data[dcd_len].type = value;
+				#endif
 					break;
 				}
 
@@ -215,12 +244,21 @@ static uint32_t imximage_parse_cfg_file(struct imx_header *imxhdr, char *name)
 					dcd->addr_data[dcd_len].addr =
 						get_cfg_value(token,
 							name, lineno);
+			#ifdef CONFIG_MX53
+				dcd->addr_data[dcd_len].addr =
+				cpu_to_be32(dcd->addr_data[dcd_len].addr);
+			#endif
 				break;
 			case CFG_REG_VALUE:
 				if (cmd == CMD_DATA) {
 					dcd->addr_data[dcd_len].value =
 						get_cfg_value(token,
 							name, lineno);
+				#ifdef CONFIG_MX53
+					dcd->addr_data[dcd_len].value =
+					cpu_to_be32(
+						dcd->addr_data[dcd_len].value);
+				#endif
 					dcd_len++;
 				}
 				break;
@@ -234,13 +272,24 @@ static uint32_t imximage_parse_cfg_file(struct imx_header *imxhdr, char *name)
 				name, lineno, MAX_HW_CFG_SIZE);
 		}
 	}
+#if defined(CONFIG_MX51)
 	dcd->preamble.barker = DCD_BARKER;
 	dcd->preamble.length = dcd_len * sizeof(dcd_type_addr_data_t);
+#elif defined(CONFIG_MX53)
+	dcd->header.tag = DCD_HEADER_TAG; /* 0xD2 */
+	dcd->header.length = cpu_to_be16(
+			dcd_len * sizeof(dcd_addr_data_t) + 8);
+	dcd->header.version = DCD_VERSION; /* 0x40 */
+	dcd->write_dcd_command.tag = DCD_COMMAND_TAG; /* 0xCC */
+	dcd->write_dcd_command.length = cpu_to_be16(
+			dcd_len * sizeof(dcd_addr_data_t) + 4);
+	dcd->write_dcd_command.param = DCD_COMMAND_PARAM; /* 0x4 */
+
+#endif
 	fclose(fd);
-
 	return dcd_len;
 }
-
+#ifdef CONFIG_MX51
 static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
 				struct mkimage_params *params)
 {
@@ -282,6 +331,46 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
 	fhdr->super_root_key = 0;
 
 }
+#endif
+
+#ifdef CONFIG_MX53
+static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
+				struct mkimage_params *params)
+{
+	struct imx_header *hdr = (struct imx_header *)ptr;
+	flash_header_t *fhdr = &hdr->fhdr;
+	int dcd_len;
+
+	/* Set default offset */
+	hdr->flash_offset = FLASH_OFFSET_STANDARD;
+
+	/* Set magic number */
+	fhdr->header.tag = IVT_HEADER_TAG; /* 0xD1 */
+	fhdr->header.length = cpu_to_be16(sizeof(flash_header_t));
+	fhdr->header.version = IVT_VERSION; /* 0x40 */
+
+	/* Parse dcd configuration file */
+	dcd_len = imximage_parse_cfg_file(hdr, params->imagename);
+
+	fhdr->entry = params->ep;
+	fhdr->reserved1 = fhdr->reserved2 = 0;
+	fhdr->self = params->ep - sizeof(struct imx_header);
+
+	fhdr->dcd_ptr = fhdr->self +
+			offsetof(struct imx_header, dcd_table);
+
+	fhdr->boot_data_ptr = fhdr->self +
+			offsetof(struct imx_header, boot_data);
+
+	hdr->boot_data.start = fhdr->self - hdr->flash_offset;
+	hdr->boot_data.size = sbuf->st_size +
+			hdr->flash_offset +
+			sizeof(struct imx_header);
+
+	/* Security feature are not supported */
+	fhdr->csf = 0;
+}
+#endif
 
 int imximage_check_params(struct mkimage_params *params)
 {
@@ -309,7 +398,7 @@ int imximage_check_params(struct mkimage_params *params)
  * imximage parameters
  */
 static struct image_type_params imximage_params = {
-	.name		= "Freescale i.MX 51 Boot Image support",
+	.name		= "Freescale i.MX 5x Boot Image support",
 	.header_size	= sizeof(struct imx_header),
 	.hdr		= (void *)&imximage_header,
 	.check_image_type = imximage_check_image_types,
diff --git a/tools/imximage.h b/tools/imximage.h
index b4d926d..3a0e588 100644
--- a/tools/imximage.h
+++ b/tools/imximage.h
@@ -24,12 +24,17 @@
 #ifndef _IMXIMAGE_H_
 #define _IMXIMAGE_H_
 
+#include <config.h>
+
+#if defined(CONFIG_MX53)
+#define MAX_HW_CFG_SIZE 121     /* Max number of registers imx can set */
+#elif defined(CONFIG_MX51)
 #define MAX_HW_CFG_SIZE 60	/* Max number of registers imx can set */
-#define MAX_EXP_SIZE	4
 #define APP_CODE_BARKER	0xB1
 #define DCD_BARKER	0xB17219E9
-#define HEADER_OFFSET	0x400
+#endif
 
+#define HEADER_OFFSET	0x400
 
 #define CMD_DATA_STR	"DATA"
 #define FLASH_OFFSET_STANDARD	0x400
@@ -38,6 +43,15 @@
 #define FLASH_OFFSET_SPI	FLASH_OFFSET_STANDARD
 #define FLASH_OFFSET_ONENAND	0x100
 
+#if defined(CONFIG_MX53)
+#define IVT_HEADER_TAG 0xD1
+#define IVT_VERSION 0x40
+#define DCD_HEADER_TAG 0xD2
+#define DCD_COMMAND_TAG 0xCC
+#define DCD_VERSION 0x40
+#define DCD_COMMAND_PARAM 0x4
+#endif
+
 enum imximage_cmd {
 	CMD_INVALID,
 	CMD_BOOT_FROM,
@@ -52,14 +66,7 @@ enum imximage_fld_types {
 	CFG_REG_VALUE
 };
 
-typedef struct {
-	uint8_t rsa_exponent[MAX_EXP_SIZE];	 /* RSA public exponent */
-	uint8_t *rsa_modulus;			 /* RSA modulus pointer */
-	uint16_t exponent_size;			 /* Exponent size (bytes) */
-	uint16_t modulus_size;			 /* Modulus size (bytes) */
-	uint8_t init_flag;			 /* key initialized */
-} hab_rsa_public_key;
-
+#ifdef CONFIG_MX51
 typedef struct {
 	uint32_t type; /* Type of pointer (byte, halfword, word, wait/read) */
 	uint32_t addr; /* Address to write to */
@@ -101,5 +108,53 @@ struct reg_config {
 	uint32_t raddr;
 	uint32_t rdata;
 };
+#else
+typedef struct {
+	uint32_t addr;
+	uint32_t value;
+} dcd_addr_data_t;
+
+typedef struct {
+	uint8_t tag;
+	uint16_t length;
+	uint8_t version;
+} __attribute__((packed)) ivt_header_t;
+
+typedef struct {
+	uint8_t tag;
+	uint16_t length;
+	uint8_t param;
+} __attribute__((packed)) write_dcd_command_t;
+
+typedef struct {
+	ivt_header_t header;
+	write_dcd_command_t write_dcd_command;
+	dcd_addr_data_t addr_data[MAX_HW_CFG_SIZE];
+} dcd_t;
+
+typedef struct {
+	uint32_t start;
+	uint32_t size;
+	uint32_t plugin;
+} boot_data_t;
+
+typedef struct {
+	ivt_header_t header;
+	uint32_t entry;
+	uint32_t reserved1;
+	uint32_t dcd_ptr;
+	uint32_t boot_data_ptr;
+	uint32_t self;
+	uint32_t csf;
+	uint32_t reserved2;
+} flash_header_t;
+
+struct imx_header {
+	flash_header_t fhdr;
+	boot_data_t boot_data;
+	dcd_t dcd_table;
+	uint32_t flash_offset;
+};
+#endif
 
 #endif /* _IMXIMAGE_H_ */
-- 
1.7.0.4




More information about the U-Boot mailing list