The patchset fixes some issue in the generation of the imx image
Subsystems (2)
cover The patchset fixes some issue in the generation of the imx image
(header for Freescale's i.MX processors) to allow the usage of Freescale's tools to sign the u-boot image and provide a secure boot.
This has nothing to do with the Secure Boot extensions implemented by Simon Glass, that can be in any case used to boot later a secure image. Freescale's secure boot ensures that a signed bootloader
is started only if it is verified with a key that is burned into the iMX fuses. Documentation about the Freescale's secure process can be read from the AN4591, available on the Freescale's Website.
The patchset allows to add to the imx Header the CSF (command Sequence File) generated by the tools provided by Freescale. The CSF is then simply concatenated to the u-boot image, making a signed bootloader, that the processor can verify if the fuses for the keys are burned. The processor (i.MX53 / i.MX6x) will not start a bootloader that cannot be verified - further infos how to configure the SOC to verify the bootloader can be found in the User Manual of the specific SOC.
Next step is to verify the kernel, that can be still done using Simon's patches for verified boot (CONFIG_OF_CONTROL must be set in the board configuarion file).
Stefano Babic (7):
tools: imx_header should not include flash_offset
tools: rename mximage_flash_offset to imximage_ivt_offset
tools: dynamically allocate imx_header in imximage
tools: add variable padding of data image in mkimage
tools: add padding of data image file for imximage
tools: add support for setting the CSF into imximage
imx: add status reporting for HAB status
arch/arm/cpu/armv7/mx6/Makefile | 2 +- arch/arm/cpu/armv7/mx6/hab.c | 127 ++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/hab.h | 80 ++++++++++++++ arch/arm/include/asm/arch-mx6/imx-regs.h | 8 +- doc/README.imximage | 18 +++- doc/README.mxc_hab | 48 +++++++++ tools/imximage.c | 168 +++++++++++++++++++++++++++--- tools/imximage.h | 20 +++- tools/mkimage.c | 24 ++++- tools/mkimage.h | 5 +- 10 files changed, 471 insertions(+), 29 deletions(-) create mode 100644 arch/arm/cpu/armv7/mx6/hab.c create mode 100644 arch/arm/include/asm/arch-mx6/hab.h create mode 100644 doc/README.mxc_hab
Signature · 1 line
1.7.9.5
PATCH 1/7 tools: imx_header should not include flash_offset
Doing a make distclean; make mx6qsabresd_config; make
and hexdump -C u-boot.imx | less
...
00000360 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| *
000003f0 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 |................|
^^^^^^^^^^^
00000400 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| *
00001000 13 00 00 ea 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 |...?.?.?.?.?.?.?|
...
shows the flash_offset value being written into the final generated image, wich is not correct.
Instead create flash_offset as static variable such that the generated image is "clean".
00000360 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| *
00001000 13 00 00 ea 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 |...?.?.?.?.?.?.?|
--- tools/imximage.c | 15 ++++++++------- tools/imximage.h | 1 - 2 files changed, 8 insertions(+), 8 deletions(-)
tools/imximage.c +8 -7
@@ -68,6 +68,7 @@ static table_entry_t imximage_versions[] = {static struct imx_header imximage_header;static uint32_t imximage_version; +static uint32_t imximage_flash_offset;static set_dcd_val_t set_dcd_val;static set_dcd_rst_t set_dcd_rst;
@@ -343,9 +344,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, + imximage_flash_offset =get_table_entry_id (imximage_bootops,"imximage boot option" , token); -if (imxhdr->flash_offset ==-1 ) { +if (imximage_flash_offset ==-1 ) {fprintf (stderr,"Error: %s[%d] -Invalid boot device" "(%s)\n" , name, lineno, token);exit (EXIT_FAILURE );
@@ -354,7 +355,7 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token, cmd_ver_first =0 ;break ;case CMD_BOOT_OFFSET : - imxhdr->flash_offset =get_cfg_value (token, name, lineno); + imximage_flash_offset =get_cfg_value (token, name, lineno);if (unlikely (cmd_ver_first !=1 )) cmd_ver_first =0 ;break ;
@@ -455,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 (imximage_flash_offset ==FLASH_OFFSET_UNDEFINED ) {fprintf (stderr,"Error: No BOOT_FROM tag in %s\n" , name);exit (EXIT_FAILURE ); }
@@ -513,14 +514,14 @@ 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 ; + imximage_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); + (*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_flash_offset);/* * ROM bug alert
@@ -531,7 +532,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,* * The remaining fraction of a block bytes would not be loaded! */ - *header_size_ptr =ROUND (sbuf->st_size + imxhdr->flash_offset,4096 ); + *header_size_ptr =ROUND (sbuf->st_size + imximage_flash_offset,4096 ); }int imximage_check_params (struct mkimage_params *params)
tools/imximage.h +0 -1
@@ -163,7 +163,6 @@ struct imx_header {imx_header_v1_t hdr_v1;imx_header_v2_t hdr_v2; } header; -uint32_t flash_offset; } __attribute__((aligned(4096))); typedef void (*set_dcd_val_t)(struct imx_header *imxhdr,
Signature · 1 line
1.7.9.5
PATCH 2/7 tools: rename mximage_flash_offset to imximage_ivt_offset
In reply to Stefano BabicThis better reflects the naming from the Reference Manual as well as fits better since "flash" is not really applicabe for SATA.
--- tools/imximage.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
tools/imximage.c +9 -8
@@ -68,7 +68,8 @@ static table_entry_t imximage_versions[] = {static struct imx_header imximage_header;static uint32_t imximage_version; -static uint32_t imximage_flash_offset; +/* Image Vector Table Offset */ +static uint32_t imximage_ivt_offset;static set_dcd_val_t set_dcd_val;static set_dcd_rst_t set_dcd_rst;
@@ -344,9 +345,9 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,set_hdr_func (imxhdr);break ;case CMD_BOOT_FROM : - imximage_flash_offset =get_table_entry_id (imximage_bootops, + imximage_ivt_offset =get_table_entry_id (imximage_bootops,"imximage boot option" , token); -if (imximage_flash_offset ==-1 ) { +if (imximage_ivt_offset ==-1 ) {fprintf (stderr,"Error: %s[%d] -Invalid boot device" "(%s)\n" , name, lineno, token);exit (EXIT_FAILURE );
@@ -355,7 +356,7 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token, cmd_ver_first =0 ;break ;case CMD_BOOT_OFFSET : - imximage_flash_offset =get_cfg_value (token, name, lineno); + imximage_ivt_offset =get_cfg_value (token, name, lineno);if (unlikely (cmd_ver_first !=1 )) cmd_ver_first =0 ;break ;
@@ -456,7 +457,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 (imximage_flash_offset ==FLASH_OFFSET_UNDEFINED ) { +if (imximage_ivt_offset ==FLASH_OFFSET_UNDEFINED ) {fprintf (stderr,"Error: No BOOT_FROM tag in %s\n" , name);exit (EXIT_FAILURE ); }
@@ -514,14 +515,14 @@ 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 */ - imximage_flash_offset =FLASH_OFFSET_UNDEFINED ; + imximage_ivt_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, imximage_flash_offset); + (*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_ivt_offset);/* * ROM bug alert
@@ -532,7 +533,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,* * The remaining fraction of a block bytes would not be loaded! */ - *header_size_ptr =ROUND (sbuf->st_size + imximage_flash_offset,4096 ); + *header_size_ptr =ROUND (sbuf->st_size + imximage_ivt_offset,4096 ); }int imximage_check_params (struct mkimage_params *params)
Signature · 1 line
1.7.9.5
PATCH 3/7 tools: dynamically allocate imx_header in imximage
In reply to Stefano BabicChange to dynamically allocate the imx_header to correctly allocate the IVT, Boot Data and DCD at correct locations depending on the boot media.
Also check that the Image Vector Table Offset + IVT + Boot Data + DCD <= Initial Load Region Size.
Previously struct imx_header was always 4096 bytes and was not dealing correctly with the Image Vector Table Offset.
Now, the memory allocation looks for e.g. SD boot like this
Storage u-boot.imx RAM
Device
00000000 177ff000 <--------------
| 00000400 00000000 d1 00 20 40 IVT.header 177ff400 <------- | 00000404 00000004 00 00 80 17 IVT.entry 177ff404 ----------- | 00000408 00000008 00 00 00 00 IVT.reserved1 177ff408 | | | 0000040C 0000000C 2c f4 7f 17 IVT.dcd 177ff40C ------ | | | 00000410 00000010 20 f4 7f 17 IVT.boot 177ff410 ---- | | | | 00000414 00000014 00 f4 7f 17 IVT.self 177ff414 -------- | | 00000418 00000018 00 00 00 00 IVT.csf 177ff418 | | | | 0000041C 0000001C 00 00 00 00 IVT.reserved2 177ff41C | | | | 00000420 00000020 00 f0 7f 17 BootData.start 177ff420 <--- | | --- 00000424 00000024 00 60 03 00 BootData.length 177ff424 | | 00000428 00000028 00 00 00 00 BootData.plugin 177ff428 | | 0000042C 0000002C d2 03 30 40 DCD.header 177ff42C <----- | ... |
00001000 00000c00 13 00 00 ea U-Boot Start 17800000 <----------
While at it also remove the unused #define HEADER_OFFSET.
--- tools/imximage.c | 44 +++++++++++++++++++++++++++++++++++++------- tools/imximage.h | 16 +++++++++++++--- 2 files changed, 50 insertions(+), 10 deletions(-)
tools/imximage.c +37 -7
@@ -47,7 +47,7 @@ static table_entry_t imximage_cmds[] = {* Supported Boot options for configuration file * this is needed to set the correct flash offset */ -static table_entry_t imximage_bootops[] = { +static table_entry_t imximage_boot_offset[] = { {FLASH_OFFSET_ONENAND ,"onenand" ,"OneNAND Flash" ,}, {FLASH_OFFSET_NAND ,"nand" ,"NAND Flash" , }, {FLASH_OFFSET_NOR ,"nor" ,"NOR Flash" , },
@@ -58,6 +58,20 @@ static table_entry_t imximage_bootops[] = { };/* +* Supported Boot options for configuration file +* this is needed to determine the initial load size +*/ +static table_entry_t imximage_boot_loadsize[] = { + {FLASH_LOADSIZE_ONENAND ,"onenand" ,"OneNAND Flash" ,}, + {FLASH_LOADSIZE_NAND ,"nand" ,"NAND Flash" , }, + {FLASH_LOADSIZE_NOR ,"nor" ,"NOR Flash" , }, + {FLASH_LOADSIZE_SATA ,"sata" ,"SATA Disk" , }, + {FLASH_LOADSIZE_SD ,"sd" ,"SD Card" , }, + {FLASH_LOADSIZE_SPI ,"spi" ,"SPI Flash" , }, + {-1 ,"" ,"Invalid" , }, +}; + +/* * IMXIMAGE version definition for i.MX chips */ static table_entry_t imximage_versions[] = {
@@ -70,6 +84,8 @@ static struct imx_header imximage_header;static uint32_t imximage_version;/* Image Vector Table Offset */ static uint32_t imximage_ivt_offset; +/* Initial Load Region Size */ +static uint32_t imximage_init_loadsize;static set_dcd_val_t set_dcd_val;static set_dcd_rst_t set_dcd_rst;
@@ -211,7 +227,9 @@ 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 ); +/* TODO: check i.MX image V1 handling, for now use 'old' style */ +/* hdr_base = entry_point - imximage_init_loadsize + flash_offset; */ + hdr_base = entry_point -4096 ; fhdr_v1->app_dest_ptr = hdr_base - flash_offset; fhdr_v1->app_code_jump_vector = entry_point;
@@ -238,12 +256,13 @@ 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 ); - + hdr_base = entry_point - imximage_init_loadsize + + flash_offset; + fhdr_v2->self = hdr_base; fhdr_v2->dcd_ptr = hdr_base + offsetof(imx_header_v2_t , dcd_table); fhdr_v2->boot_data_ptr = hdr_base + offsetof(imx_header_v2_t , boot_data); - hdr_v2->boot_data.start = hdr_base - flash_offset; + hdr_v2->boot_data.start = entry_point - imximage_init_loadsize;/* Security feature are not supported */ fhdr_v2->csf =0 ;
@@ -345,13 +364,24 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,set_hdr_func (imxhdr);break ;case CMD_BOOT_FROM : - imximage_ivt_offset =get_table_entry_id (imximage_bootops, + imximage_ivt_offset =get_table_entry_id (imximage_boot_offset,"imximage boot option" , token);if (imximage_ivt_offset ==-1 ) {fprintf (stderr,"Error: %s[%d] -Invalid boot device" "(%s)\n" , name, lineno, token);exit (EXIT_FAILURE ); } + + imximage_init_loadsize = +get_table_entry_id (imximage_boot_loadsize, +"imximage boot option" , token); + +if (imximage_init_loadsize ==-1 ) { +fprintf (stderr, +"Error: %s[%d] -Invalid boot device(%s)\n" , + name, lineno, token); +exit (EXIT_FAILURE ); + }if (unlikely (cmd_ver_first !=1 )) cmd_ver_first =0 ;break ;
@@ -533,7 +563,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,* * The remaining fraction of a block bytes would not be loaded! */ - *header_size_ptr =ROUND (sbuf->st_size + imximage_ivt_offset,4096 ); + *header_size_ptr =ROUND (sbuf->st_size,4096 ); }int imximage_check_params (struct mkimage_params *params)
tools/imximage.h +13 -3
@@ -29,14 +29,14 @@#define APP_CODE_BARKER 0xB1#define DCD_BARKER 0xB17219E9 -#define HEADER_OFFSET 0x400 -/* * NOTE: This file must be kept in sync with arch/arm/include/asm/\ * imx-common/imximage.cfg because tools/imximage.c can not * cross-include headers from arch/arm/ and vice-versa. */ #define CMD_DATA_STR "DATA" + +/* Initial Vector Table Offset */ #define FLASH_OFFSET_UNDEFINED 0xFFFFFFFF#define FLASH_OFFSET_STANDARD 0x400#define FLASH_OFFSET_NAND FLASH_OFFSET_STANDARD
@@ -46,6 +46,16 @@#define FLASH_OFFSET_NOR 0x1000#define FLASH_OFFSET_SATA FLASH_OFFSET_STANDARD +/* Initial Load Region Size */ +#define FLASH_LOADSIZE_UNDEFINED 0xFFFFFFFF +#define FLASH_LOADSIZE_STANDARD 0x1000 +#define FLASH_LOADSIZE_NAND FLASH_LOADSIZE_STANDARD +#define FLASH_LOADSIZE_SD FLASH_LOADSIZE_STANDARD +#define FLASH_LOADSIZE_SPI FLASH_LOADSIZE_STANDARD +#define FLASH_LOADSIZE_ONENAND 0x400 +#define FLASH_LOADSIZE_NOR 0x0/* entire image */ +#define FLASH_LOADSIZE_SATA FLASH_LOADSIZE_STANDARD +#define IVT_HEADER_TAG 0xD1#define IVT_VERSION 0x40#define DCD_HEADER_TAG 0xD2
@@ -163,7 +173,7 @@ struct imx_header {imx_header_v1_t hdr_v1;imx_header_v2_t hdr_v2; } header; -} __attribute__((aligned(4096))); +}; typedef void (*set_dcd_val_t)(struct imx_header *imxhdr, char *name, int lineno,
Signature · 1 line
1.7.9.5
PATCH 3/7 tools: dynamically allocate imx_header in imximage
Dear Stefano Babic,
Quoted 85 lines
Change to dynamically allocate the
imx_headerto correctly allocate the IVT, Boot Data and DCD at correct locations depending on the boot media.Also check that the Image Vector Table Offset + IVT + Boot Data + DCD <= Initial Load Region Size.
Previously struct
imx_headerwas always 4096 bytes and was not dealing correctly with the Image Vector Table Offset.Now, the memory allocation looks for e.g. SD boot like this
Storage u-boot.imx RAM
Device00000000
177ff000<--------------00000400 00000000 d1 00 20 40 IVT.header 177ff400 <------- | 00000404 00000004 00 00 80 17 IVT.entry 177ff404 ----------- | 00000408 00000008 00 00 00 00 IVT.reserved1 177ff408 | | | 0000040C 0000000C 2c f4 7f 17 IVT.dcd 177ff40C ------ | | | 00000410 00000010 20 f4 7f 17 IVT.boot 177ff410 ---- | | | | 00000414 00000014 00 f4 7f 17 IVT.self 177ff414 -------- | | 00000418 00000018 00 00 00 00 IVT.csf 177ff418 | | | | 0000041C 0000001C 00 00 00 00 IVT.reserved2 177ff41C | | | | 00000420 00000020 00 f0 7f 17 BootData.start 177ff420 <--- | | --- 00000424 00000024 00 60 03 00 BootData.length 177ff424 | | 00000428 00000028 00 00 00 00 BootData.plugin 177ff428 | | 0000042C 0000002C d2 03 30 40 DCD.header 177ff42C <----- |... |
0000100000000c0013 00 00 ea U-Boot Start 17800000 <----------While at it also remove the unused #define
HEADER_OFFSET.Signed-off-by Stefano Babic <[email protected]>--- tools/imximage.c | 44 +++++++++++++++++++++++++++++++++++++------- tools/imximage.h | 16 +++++++++++++--- 2 files changed, 50 insertions(+), 10 deletions(-)tools/imximage.c +17
-1@@ -47,7 +47,7 @@ static table_entry_t imximage_cmds[] = {* Supported Boot options for configuration file * this is needed to set the correct flash offset */ -static table_entry_t imximage_bootops[] = { +static table_entry_t imximage_boot_offset[] = { {FLASH_OFFSET_ONENAND ,"onenand" ,"OneNAND Flash" ,}, {FLASH_OFFSET_NAND ,"nand" ,"NAND Flash" , }, {FLASH_OFFSET_NOR ,"nor" ,"NOR Flash" , },@@ -58,6 +58,20 @@ static table_entry_t imximage_bootops[] = { };/* +* Supported Boot options for configuration file +* this is needed to determine the initial load size +*/ +static table_entry_t imximage_boot_loadsize[] = { + {FLASH_LOADSIZE_ONENAND ,"onenand" ,"OneNAND Flash" ,}, + {FLASH_LOADSIZE_NAND ,"nand" ,"NAND Flash" , }, + {FLASH_LOADSIZE_NOR ,"nor" ,"NOR Flash" , }, + {FLASH_LOADSIZE_SATA ,"sata" ,"SATA Disk" , }, + {FLASH_LOADSIZE_SD ,"sd" ,"SD Card" , }, + {FLASH_LOADSIZE_SPI ,"spi" ,"SPI Flash" , }, + {-1 ,"" ,"Invalid" , }, +}; + +/* * IMXIMAGE version definition for i.MX chips */ static table_entry_t imximage_versions[] = {@@ -70,6 +84,8 @@ static struct imx_header imximage_header;static uint32_t imximage_version;/* Image Vector Table Offset */ static uint32_t imximage_ivt_offset; +/* Initial Load Region Size */ +static uint32_t imximage_init_loadsize;static set_dcd_val_t set_dcd_val;static set_dcd_rst_t set_dcd_rst;@@ -211,7 +227,9 @@ static void set_imx_hdr_v1(struct imx_header *imxhdr,
uint32_tdcd_len, /* Set magic number */
tools/imximage.c static void set_imx_hdr_v1(struct imx_header *imxhdr, uint32_t dcd_len, · line 231
Quoted 5 lines
tools/imximage.c +2
-1fhdr_v1->app_code_barker =APP_CODE_BARKER ; - hdr_base = entry_point -sizeof (struct imx_header ); +/* TODO: check i.MX image V1 handling, for now use 'old' style */ +/* hdr_base = entry_point - imximage_init_loadsize + flash_offset; */
The above line should probably be removed.
[...]
tools/imximage.c struct imx_header { · line 176
Quoted 6 lines
tools/imximage.c +1
-1@@ -163,7 +173,7 @@ struct imx_header {imx_header_v1_t hdr_v1;imx_header_v2_t hdr_v2; } header; -} __attribute__((aligned(4096))); +};
What about the alignment, is it preserved?
Best regards,
Marek Vasut
PATCH 4/7 tools: add variable padding of data image in mkimage
In reply to Stefano BabicUse previously unused return value of function vrec_header to return a padding size to generic mkimage. This padding size is used in copy_files to pad with zeros after copying the data image.
--- tools/mkimage.c | 24 +++++++++++++++++++++--- tools/mkimage.h | 5 ++++- 2 files changed, 25 insertions(+), 4 deletions(-)
tools/mkimage.c +21 -3
@@ -150,6 +150,7 @@ main (int argc, char **argv)char *ptr;int retval =0 ;struct image_type_params *tparams =NULL ; +int pad_len =0 ;/* Init Freescale PBL Boot image generation/list support */ init_pbl_image_type ();
@@ -404,7 +405,7 @@ NXTARG: ;* allocate memory for the header itself. */ if (tparams->vrec_header) - tparams->vrec_header (¶ms, tparams); + pad_len = tparams->vrec_header (¶ms, tparams);else memset (tparams->hdr,0 , tparams->header_size);
@@ -476,7 +477,7 @@ NXTARG: ;/* PBL has special Image format, implements its' own */ pbl_load_uboot (ifd, ¶ms); }else { -copy_file (ifd, params.datafile,0 ); +copy_file (ifd, params.datafile, pad_len); } }
@@ -550,10 +551,19 @@ copy_file (int ifd, const char *datafile, int pad)unsigned char *ptr;int tail;int zero =0 ; +uint8_t zeros[4096 ];int offset =0 ;int size;struct image_type_params *tparams =mkimage_get_type (params.type); +if (pad >=sizeof (zeros)) { +fprintf (stderr,"%s: Can't pad to %d\n" , + params.cmdname, pad); +exit (EXIT_FAILURE ); + } + +memset (zeros,0 ,sizeof (zeros)); +if (params.vflag) {fprintf (stderr,"Adding Image %s\n" , datafile); }
@@ -611,7 +621,8 @@ copy_file (int ifd, const char *datafile, int pad)exit (EXIT_FAILURE ); } -if (pad && ((tail = size %4 ) !=0 )) { + tail = size %4 ; +if ((pad ==1 ) && (tail !=0 )) {if (write (ifd, (char *)&zero,4 -tail) !=4 -tail) { fprintf (stderr, "%s: Write error on %s: %s\n",
@@ -619,6 +630,13 @@ copy_file (int ifd, const char *datafile, int pad) strerror(errno));exit (EXIT_FAILURE ); } + }else if (pad >1 ) { +if (write (ifd, (char *)&zeros, pad) != pad) { +fprintf (stderr,"%s: Write error on %s: %s\n" , + params.cmdname, params.imagefile, +strerror (errno)); +exit (EXIT_FAILURE ); + } } (void )munmap ((void *)ptr, sbuf.st_size);
tools/mkimage.h +4 -1
@@ -145,7 +145,10 @@ struct image_type_params {/* * This callback function will be executed for variable size record * It is expected to build this header in memory and return its length -* and a pointer to it +* and a pointer to it by using image_type_params.header_size and +* image_type_params.hdr. The return value shall indicate if an +* additional padding should be used when copying the data image +* by returning the padding length. */ int (*vrec_header) (struct mkimage_params *,struct image_type_params *);
Signature · 1 line
1.7.9.5
PATCH 5/7 tools: add padding of data image file for imximage
In reply to Stefano BabicImplement function vrec_header to be able to pad the final data image file according the what has been calculated for boot_data.length.
--- tools/imximage.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-)
tools/imximage.c +80 -2
@@ -588,18 +588,96 @@ int imximage_check_params(struct mkimage_params *params) (params->xflag) || !(strlen (params->imagename)); } +static int imximage_generate (struct mkimage_params *params, +struct image_type_params *tparams) +{ +struct imx_header *imxhdr; +size_t alloc_len; +int dfd; +struct stat sbuf; +char *datafile = params->datafile; +uint32_t pad_len; + +memset (&imximage_header,0 ,sizeof (imximage_header)); + +/* +* In order to not change the old imx cfg file +* by adding VERSION command into it, here need +* 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 */ + imximage_ivt_offset =FLASH_OFFSET_UNDEFINED ; + imximage_csf_size =0 ; +set_hdr_func (imxhdr); + +/* 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 + alloc_len = imximage_init_loadsize - imximage_ivt_offset; + +if (alloc_len <sizeof (struct imx_header )) { +fprintf (stderr,"%s: header error\n" , + params->cmdname); +exit (EXIT_FAILURE ); + } + + imxhdr =malloc (alloc_len); + +if (!imxhdr) { +fprintf (stderr,"%s: malloc return failure: %s\n" , + params->cmdname,strerror (errno)); +exit (EXIT_FAILURE ); + } + +memset (imxhdr,0 , alloc_len); + + tparams->header_size = alloc_len; + tparams->hdr = imxhdr; + +/* determine data image file length */ + dfd =open (datafile,O_RDONLY |O_BINARY ); +if (dfd <0 ) { +fprintf (stderr,"%s: Can't open %s: %s\n" , + params->cmdname, datafile,strerror (errno)); +exit (EXIT_FAILURE ); + } + +if (fstat (dfd, &sbuf) <0 ) { +fprintf (stderr,"%s: Can't stat %s: %s\n" , + params->cmdname, datafile,strerror (errno)); +exit (EXIT_FAILURE ); + } + + pad_len =ROUND (sbuf.st_size,4096 ) - sbuf.st_size; + +close (dfd); + +/* TODO: check i.MX image V1 handling, for now use 'old' style */ +if (imximage_version ==IMXIMAGE_V1 ) +return 0 ; +else +return pad_len; +} + +/* * imximage parameters */ static struct image_type_params imximage_params = { .name ="Freescale i.MX Boot Image support" , - .header_size =sizeof (struct imx_header ), - .hdr = (void *)&imximage_header, + .header_size =0 , + .hdr =NULL , .check_image_type = imximage_check_image_types, .verify_header = imximage_verify_header, .print_header = imximage_print_header, .set_header = imximage_set_header, .check_params = imximage_check_params, + .vrec_header = imximage_generate, };void init_imx_image_type (void )
Signature · 1 line
1.7.9.5
PATCH 6/7 tools: add support for setting the CSF into imximage
In reply to Stefano BabicAdd support for setting the CSF (Command Sequence File) pointer which is used for HAB (High Assurance Boot) in the imximage by adding e.g.
CSF 0x2000
in the imximage.cfg file.
This will set the CSF pointer accordingly just after the padded data image area. The boot_data.length is adjusted with the value from the imximage.cfg config file.
The resulting u-boot.imx can be signed with the FSL HAB tooling. The generated CSF block needs to be appended to the u-boot.imx.
--- doc/README.imximage | 18 +++++++++++++++--- doc/README.mxc_hab | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/imximage.c | 30 +++++++++++++++++++++++++++++- tools/imximage.h | 3 ++- 4 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 doc/README.mxc_hab
doc/README.imximage +15 -3
@@ -15,9 +15,6 @@ Booting from NOR flash does not require to use this image type. For more details refer Chapter 2 - System Boot and section 2.14 (flash header description) of the processor's manual. -This implementation does not use at the moment the secure boot feature -of the processor. The image is generated disabling all security fields. - Command syntax: -------------- ./tools/mkimage -l <mx u-boot_file>
@@ -86,6 +83,21 @@ Configuration command line syntax: Example: BOOT_FROM spi + CSF value + + Total size of CSF (Command Sequence File) + used for Secure Boot/ High Assurance Boot + (HAB). + + Using this command will populate the IVT + (Initial Vector Table) CSF pointer and adjust + the length fields only. The CSF itself needs + to be generated with Freescale tools and + 'manually' appended to the u-boot.imx file. + + Example: + CSF 0x2000 + DATA type address value type: word=4, halfword=2, byte=1
doc/README.mxc_hab new file +48 -0
48 lines not on this page · raw message
tools/imximage.c +29 -1
@@ -39,6 +39,7 @@ static table_entry_t imximage_cmds[] = { {CMD_BOOT_FROM, "BOOT_FROM", "boot command", }, {CMD_BOOT_OFFSET, "BOOT_OFFSET", "Boot offset", }, {CMD_DATA, "DATA", "Reg Write Data", }, + {CMD_CSF, "CSF", "Command Sequence File", }, {CMD_IMAGE_VERSION, "IMAGE_VERSION", "image version", }, {-1, "", "", }, };
@@ -86,12 +87,14 @@ static uint32_t imximage_version;static uint32_t imximage_ivt_offset;/* Initial Load Region Size */ static uint32_t imximage_init_loadsize; +static uint32_t imximage_csf_size;static set_dcd_val_t set_dcd_val;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 *csf_ptr;static uint32_t get_cfg_value (char *token,char *name,int linenr) {
@@ -264,9 +267,10 @@ static void set_imx_hdr_v2(struct imx_header *imxhdr, uint32_t dcd_len, + offsetof(imx_header_v2_t , boot_data); hdr_v2->boot_data.start = entry_point - imximage_init_loadsize; -/* Security feature are not supported */ fhdr_v2->csf =0 ; + header_size_ptr = &hdr_v2->boot_data.size; + csf_ptr = &fhdr_v2->csf; }static void set_hdr_func (struct imx_header *imxhdr)
@@ -343,6 +347,12 @@ static void print_hdr_v2(struct imx_header *imx_hdr)genimg_print_size (hdr_v2->boot_data.size);printf ("Load Address: %08x\n" , (uint32_t )fhdr_v2->boot_data_ptr);printf ("Entry Point: %08x\n" , (uint32_t )fhdr_v2->entry); +if (fhdr_v2->csf) { +printf ("HAB Blocks: %08x %08x %08x\n" , + (uint32_t )fhdr_v2->self,0 , + hdr_v2->boot_data.size - imximage_ivt_offset - + imximage_csf_size); + } } static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,
@@ -396,6 +406,17 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,if (unlikely (cmd_ver_first !=1 )) cmd_ver_first =0 ;break ; +case CMD_CSF : +if (imximage_version !=2 ) { +fprintf (stderr,"Error: %s[%d] - " +"CSF only supported for IMAGE_VERSION 2(%s)\n" , + name, lineno, token); +exit (EXIT_FAILURE ); + } + imximage_csf_size =get_cfg_value (token, name, lineno); +if (unlikely (cmd_ver_first !=1 )) + cmd_ver_first =0 ; +break ; } }
@@ -546,6 +567,7 @@ 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 */ imximage_ivt_offset =FLASH_OFFSET_UNDEFINED ; + imximage_csf_size =0 ;set_hdr_func (imxhdr);/* Parse dcd configuration file */
@@ -564,6 +586,12 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,* The remaining fraction of a block bytes would not be loaded! */ *header_size_ptr =ROUND (sbuf->st_size,4096 ); + +if (csf_ptr && imximage_csf_size) { + *csf_ptr = params->ep - imximage_init_loadsize + + *header_size_ptr; + *header_size_ptr += imximage_csf_size; + } }int imximage_check_params (struct mkimage_params *params)
tools/imximage.h +2 -1
@@ -68,7 +68,8 @@ enum imximage_cmd {CMD_IMAGE_VERSION ,CMD_BOOT_FROM ,CMD_BOOT_OFFSET , -CMD_DATA +CMD_DATA , + CMD_CSF, }; enum imximage_fld_types {
Signature · 1 line
1.7.9.5
PATCH 6/7 tools: add support for setting the CSF into imximage
Dear Stefano Babic,
Quoted 3 lines · In message <[email protected]> you wrote:
Add support for setting the CSF (Command Sequence File) pointer which is used for HAB (High Assurance Boot) in the imximage by adding e.g.
This patch throws a checkpatch error that needs to be fixed:
WARNING: quoted string split across lines
#265: FILE: tools/imximage.c:412:
+ fprintf(stderr, "Error: %s[%d] - "
+ "CSF only supported for IMAGE_VERSION 2(%s)\n",
Best regards,
Wolfgang Denk
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-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "You're just jealous." "What, of an overgrown puppy with a single- figure IQ?" - Terry Pratchett, _Moving Pictures_
PATCH 6/7 tools: add support for setting the CSF into imximage
Hi Wolfgang,
tools/imximage.c static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token, · line 412
Quoted 13 lines · Wolfgang Denk
Dear Stefano Babic,
Quoted 3 lines · In message <[email protected]> you wrote:
Add support for setting the CSF (Command Sequence File) pointer which is used for HAB (High Assurance Boot) in the imximage by adding e.g.
This patch throws a checkpatch error that needs to be fixed:
WARNING: quoted string split across lines
#265: FILE:tools/imximage.c:412:tools/imximage.c +2
-0+ fprintf(stderr, "Error: %s[%d] - " + "CSF only supported for IMAGE_VERSION 2(%s)\n",
Fixed in V2.
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH 7/7 imx: add status reporting for HAB status
In reply to Stefano BabicAdd functions to report the HAB (High Assurance Boot) status of e.g. i.MX6 CPUs.
This is taken from
git://git.freescale.com/imx/uboot-imx.git branch imx_v2009.08_3.0.35_4.0.0 cpu/arm_cortexa8/mx6/generic.c include/asm-arm/arch-mx6/mx6_secure.h
--- arch/arm/cpu/armv7/mx6/Makefile | 2 +- arch/arm/cpu/armv7/mx6/hab.c | 127 ++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/hab.h | 80 +++++++++++++++++++ arch/arm/include/asm/arch-mx6/imx-regs.h | 8 +- 4 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 arch/arm/cpu/armv7/mx6/hab.c create mode 100644 arch/arm/include/asm/arch-mx6/hab.h
arch/arm/cpu/armv7/mx6/Makefile +1 -1
@@ -27,7 +27,7 @@ include $(TOPDIR)/config.mk LIB = $(obj)lib$(SOC).o -COBJS = soc.o clock.o +COBJS = soc.o clock.o hab.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS))
arch/arm/cpu/armv7/mx6/hab.c new file +127 -0
127 lines not on this page · raw message
arch/arm/include/asm/arch-mx6/hab.h new file +80 -0
80 lines not on this page · raw message
arch/arm/include/asm/arch-mx6/imx-regs.h +7 -1
@@ -468,7 +468,13 @@ struct fuse_bank0_regs {u32 uid_low;u32 rsvd1[3 ];u32 uid_high; -u32 rsvd2[0x17 ]; +u32 rsvd2[3 ]; +u32 rsvd3[4 ]; +u32 rsvd4[4 ]; +u32 rsvd5[4 ]; +u32 cfg5; +u32 rsvd6[3 ]; +u32 rsvd7[4 ]; };struct fuse_bank4_regs {
Signature · 1 line
1.7.9.5
Fabio Estevam
reviewerPATCH 7/7 imx: add status reporting for HAB status
Hi Stefano,
arch/arm/cpu/armv7/mx6/Makefile include $(TOPDIR)/config.mk · line 28
Quoted 5 lines · Stefano Babic
arch/arm/cpu/armv7/mx6/Makefile +0
-0@@ -27,7 +27,7 @@ include $(TOPDIR)/config.mk LIB = $(obj)lib$(SOC).o
Whole series looks good.
Only a minor comment:
arch/arm/cpu/armv7/mx6/Makefile include $(TOPDIR)/config.mk · line 30
Quoted 2 lines
arch/arm/cpu/armv7/mx6/Makefile +1
-1-COBJS = soc.o clock.o +COBJS = soc.o clock.o hab.o
What about:
COBJS-y += soc.o clock.o
COBJS-$(CONFIG_SECURE_BOOT) += hab.o
Quoted 24 lines
arch/arm/cpu/armv7/mx6/Makefile +0
-0SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS))arch/arm/cpu/armv7/mx6/hab.c new file +15
-0@@ -0,0 +1,127 @@ +/* +* Copyright (C) 2010-2013 Freescale Semiconductor, Inc. +* +* 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.
arch/arm/cpu/armv7/mx6/hab.c line 25
Quoted 10 lines
arch/arm/cpu/armv7/mx6/hab.c new file +10
-0+* +* 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 +*/ + +#include <common.h> +#include <asm/io.h> +#if defined(CONFIG_SECURE_BOOT )
,and then you remove this 'if defined' ?
PATCH 7/7 imx: add status reporting for HAB status
Hi Fabio,
Quoted 14 lines · Fabio Estevam
Hi Stefano,
arch/arm/cpu/armv7/mx6/Makefile include $(TOPDIR)/config.mk · line 28
Quoted 5 lines · Stefano Babic
arch/arm/cpu/armv7/mx6/Makefile +0
-0@@ -27,7 +27,7 @@ include $(TOPDIR)/config.mk LIB = $(obj)lib$(SOC).oWhole series looks good.
Only a minor comment:
Quoted 7 lines
arch/arm/cpu/armv7/mx6/Makefile include $(TOPDIR)/config.mk · line 30
Quoted 2 lines
arch/arm/cpu/armv7/mx6/Makefile +1
-1-COBJS = soc.o clock.o +COBJS = soc.o clock.o hab.oWhat about:
COBJS-y += soc.o clock.o
COBJS-$(CONFIG_SECURE_BOOT) += hab.o
Correct, fix in V2.
Quoted 3 lines
,and then you remove this 'if defined' ?
Agree.
Best regards,
Stefano
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH 7/7 imx: add status reporting for HAB status
In reply to Stefano BabicDear Stefano Babic,
Quoted 84 lines
Add functions to report the HAB (High Assurance Boot) status of e.g. i.MX6 CPUs.
This is taken from
git://git.freescale.com/imx/uboot-imx.gitbranch imx_v2009.08_3.0.35_4.0.0cpu/arm_cortexa8/mx6/generic.cinclude/asm-arm/arch-mx6/mx6_secure.hSigned-off-by Stefano Babic <[email protected]>--- arch/arm/cpu/armv7/mx6/Makefile | 2 +- arch/arm/cpu/armv7/mx6/hab.c | 127 ++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/hab.h | 80 +++++++++++++++++++ arch/arm/include/asm/arch-mx6/imx-regs.h | 8 +- 4 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 arch/arm/cpu/armv7/mx6/hab.c create mode 100644 arch/arm/include/asm/arch-mx6/hab.h(quoted diff) +0
-0b/arch/arm/cpu/armv7/mx6/Makefile index 4f9ca68..7c18f43 100644
arch/arm/cpu/armv7/mx6/Makefile +1
-1@@ -27,7 +27,7 @@ include $(TOPDIR)/config.mk LIB = $(obj)lib$(SOC).o -COBJS = soc.o clock.o +COBJS = soc.o clock.o hab.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS))arch/arm/cpu/armv7/mx6/hab.c new file +30
-0@@ -0,0 +1,127 @@ +/* +* Copyright (C) 2010-2013 Freescale Semiconductor, Inc. +* +* 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 +*/ + +#include <common.h> +#include <asm/io.h> +#if defined(CONFIG_SECURE_BOOT ) +#include <asm/arch/hab.h> + +#ifdef CONFIG_SECURE_BOOT +/* -------- start of HAB API updates ------------*/ +#define hab_rvt_report_event ((hab_rvt_report_event_t*)HAB_RVT_REPORT_EVENT) +#define
hab_rvt_report_status((hab_rvt_report_status_t*)HAB_RVT_REPORT_STATUS) +#definehab_rvt_authenticate_image\arch/arm/cpu/armv7/mx6/hab.c new file +13
-0+ ((hab_rvt_authenticate_image_t *)HAB_RVT_AUTHENTICATE_IMAGE) +#define hab_rvt_entry ((hab_rvt_entry_t *)HAB_RVT_ENTRY) +#define hab_rvt_exit ((hab_rvt_exit_t *)HAB_RVT_EXIT) +#define hab_rvt_clock_init HAB_RVT_CLOCK_INIT + + +bool is_hab_enabled (void ) +{ +struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR ; +struct fuse_bank *bank = &ocotp->bank[0 ]; +struct fuse_bank0_regs *fuse = + (struct fuse_bank0_regs *)bank->fuse_regs; +uint32_t reg =readl (&fuse->cfg5);
arch/arm/cpu/armv7/mx6/hab.c line 55
Quoted 10 lines
arch/arm/cpu/armv7/mx6/hab.c new file +10
-0+ +return (reg &0x2 ) ==0x2 ; +} + + +void display_event (uint8_t *event_data,size_t bytes) +{ +uint32_t i; + +if ((event_data) && (bytes >0 )) {
if (!<cond>)
return;
<The loop goes here>
Quoted 13 lines
arch/arm/cpu/armv7/mx6/hab.c new file +13
-0+for (i =0 ; i < bytes; i++) { +if (i ==0 ) +printf ("\t0x%02x" , event_data[i]); +else if ((i %8 ) ==0 ) +printf ("\n\t0x%02x" , event_data[i]); +else +printf (" 0x%02x" , event_data[i]); + } + } +} + +int get_hab_status (void ) +{
arch/arm/cpu/armv7/mx6/hab.c line 78
Quoted 10 lines
arch/arm/cpu/armv7/mx6/hab.c new file +10
-0+uint32_t index =0 ;/* Loop index */ +uint8_t event_data[128 ];/* Event data buffer */ +size_t bytes =sizeof (event_data);/* Event size in bytes */ +hab_config_t config =0 ; +hab_state_t state =0 ; + +if (is_hab_enabled ()) +printf ("\nSecure boot enabled\n" ); +else +printf ("\nSecure boot disabled\n" );
Use puts() instead of printf() with no args.
Otherwise very nice ;-)
Best regards,
Marek Vasut
PATCH 7/7 imx: add status reporting for HAB status
Hi Marek,
Quoted 10 lines · Marek Vasut
arch/arm/cpu/armv7/mx6/hab.c line 55
Quoted 5 lines
arch/arm/cpu/armv7/mx6/hab.c new file +5
-0+void display_event (uint8_t *event_data,size_t bytes) +{ +uint32_t i; + +if ((event_data) && (bytes >0 )) {if (!<cond>)
return;<The loop goes here>
Fix in V2, thanks.
Quoted 7 lines
arch/arm/cpu/armv7/mx6/hab.c line 78
Quoted 4 lines
arch/arm/cpu/armv7/mx6/hab.c new file +4
-0+if (is_hab_enabled ()) +printf ("\nSecure boot enabled\n" ); +else +printf ("\nSecure boot disabled\n" );Use
puts()instead ofprintf()with no args.
Right, and I will fix also other similar cases in this file.
Regards,
Stefano
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
cover The patchset fixes some issue in the generation of the imx image
In reply to Stefano BabicQuoted 18 lines · Stefano Babic
(header for Freescale's i.MX processors) to allow the usage of Freescale's tools to sign the u-boot image and provide a secure boot.
This has nothing to do with the Secure Boot extensions implemented by Simon Glass, that can be in any case used to boot later a secure image. Freescale's secure boot ensures that a signed bootloader
is started only if it is verified with a key that is burned into the iMX fuses. Documentation about the Freescale's secure process can be read from the AN4591, available on the Freescale's Website.The patchset allows to add to the imx Header the CSF (command Sequence File) generated by the tools provided by Freescale. The CSF is then simply concatenated to the u-boot image, making a signed bootloader, that the processor can verify if the fuses for the keys are burned. The processor (i.MX53 / i.MX6x) will not start a bootloader that cannot be verified - further infos how to configure the SOC to verify the bootloader can be found in the User Manual of the specific SOC.
Quoted 2 lines
Next step is to verify the kernel, that can be still done using Simon's patches for verified boot (
CONFIG_OF_CONTROLmust be set in the board configuarion file).
I didn't yet test or reviewed the patchset (will do) but I must to say a big Thank you :-) Awesome!
--
Otavio Salvador O.S. Systems
http://www.ossystems.com.br http://projetos.ossystems.com.br
Mobile: +55 (53) 9981-7854 Mobile: +1 (347) 903-9750
cover The patchset fixes some issue in the generation of the imx image
Quoted 10 lines · Otavio Salvador
Quoted 5 lines · Stefano Babic
<snip>
Next step is to verify the kernel, that can be still done using Simon's patches for verified boot (
CONFIG_OF_CONTROLmust be set in the board configuarion file).I didn't yet test or reviewed the patchset (will do) but I must to say a big Thank you :-) Awesome!
+1
cover The patchset fixes some issue in the generation of the imx image
In reply to Stefano BabicThanks Stefano,
Quoted 18 lines · Stefano Babic
(header for Freescale's i.MX processors) to allow the usage of Freescale's tools to sign the u-boot image and provide a secure boot.
This has nothing to do with the Secure Boot extensions implemented by Simon Glass, that can be in any case used to boot later a secure image. Freescale's secure boot ensures that a signed bootloader
is started only if it is verified with a key that is burned into the iMX fuses. Documentation about the Freescale's secure process can be read from the AN4591, available on the Freescale's Website.The patchset allows to add to the imx Header the CSF (command Sequence File) generated by the tools provided by Freescale. The CSF is then simply concatenated to the u-boot image, making a signed bootloader, that the processor can verify if the fuses for the keys are burned. The processor (i.MX53 / i.MX6x) will not start a bootloader that cannot be verified - further infos how to configure the SOC to verify the bootloader can be found in the User Manual of the specific SOC.
Quoted 3 lines
Next step is to verify the kernel, that can be still done using Simon's patches for verified boot (
CONFIG_OF_CONTROLmust be set in the board configuarion file).
I compile-tested the series against all of our boards (boundary/boundary/* and board/freescale/mx6qsabrelite).
Run-time tests (without signing) against nitrogen6s (solo) and nitrogen6q (quad). Both ran without a hitch.
Now we need to get configured for signing and burn some fuses!
v2 cover The patchset fixes some issue in the generation of the imx image
In reply to Stefano Babic(header for Freescale's i.MX processors) to allow the usage of Freescale's tools to sign the u-boot image and provide a secure boot.
This has nothing to do with the Secure Boot extensions implemented by Simon Glass, that can be in any case used to boot later a secure image. Freescale's secure boot ensures that a signed bootloader
is started only if it is verified with a key that is burned into the iMX fuses. Documentation about the Freescale's secure process can be read from the AN4591, available on the Freescale's Website.
The patchset allows to add to the imx Header the CSF (command Sequence File) generated by the tools provided by Freescale. The CSF is then simply concatenated to the u-boot image, making a signed bootloader, that the processor can verify if the fuses for the keys are burned. The processor (i.MX53 / i.MX6x) will not start a bootloader that cannot be verified - further infos how to configure the SOC to verify the bootloader can be found in the User Manual of the specific SOC.
Next step is to verify the kernel, that can be still done using Simon's patches for verified boot (CONFIG_OF_CONTROL must be set in the board configuarion file).
Changes in v2:
- drop dead code (Marek Vasut)
- Fix errors when SECURE_BOOT is selected due to enum
- simplify display_event code (Marek Vasut)
- compile hab code only if SECURE_BOOT is set (Fabio Estevam)
- update licence with SPDX line according to new rules.
Stefano Babic (7):
tools: imx_header should not include flash_offset
tools: rename mximage_flash_offset to imximage_ivt_offset
tools: dynamically allocate imx_header in imximage
tools: add variable padding of data image in mkimage
tools: add padding of data image file for imximage
tools: add support for setting the CSF into imximage
imx: add status reporting for HAB status
arch/arm/cpu/armv7/mx6/Makefile | 7 +- arch/arm/cpu/armv7/mx6/hab.c | 104 ++++++++++++++++++ arch/arm/include/asm/arch-mx6/hab.h | 67 ++++++++++++ arch/arm/include/asm/arch-mx6/imx-regs.h | 8 +- doc/README.imximage | 18 +++- doc/README.mxc_hab | 48 +++++++++ tools/imximage.c | 174 +++++++++++++++++++++++++++--- tools/imximage.h | 20 +++- tools/mkimage.c | 24 ++++- tools/mkimage.h | 5 +- 10 files changed, 444 insertions(+), 31 deletions(-) create mode 100644 arch/arm/cpu/armv7/mx6/hab.c create mode 100644 arch/arm/include/asm/arch-mx6/hab.h create mode 100644 doc/README.mxc_hab
Signature · 1 line
1.7.9.5
PATCH v2 1/7 tools: imx_header should not include flash_offset
Doing a make distclean; make mx6qsabresd_config; make
and hexdump -C u-boot.imx | less
...
00000360 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| *
000003f0 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 |................|
^^^^^^^^^^^
00000400 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| *
00001000 13 00 00 ea 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 |...?.?.?.?.?.?.?|
...
shows the flash_offset value being written into the final generated image, wich is not correct.
Instead create flash_offset as static variable such that the generated image is "clean".
00000360 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| *
00001000 13 00 00 ea 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 |...?.?.?.?.?.?.?|
---
Changes in v2: None
tools/imximage.c | 15 ++++++++------- tools/imximage.h | 1 - 2 files changed, 8 insertions(+), 8 deletions(-)
tools/imximage.c +8 -7
@@ -52,6 +52,7 @@ static table_entry_t imximage_versions[] = {static struct imx_header imximage_header;static uint32_t imximage_version; +static uint32_t imximage_flash_offset;static set_dcd_val_t set_dcd_val;static set_dcd_rst_t set_dcd_rst;
@@ -327,9 +328,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, + imximage_flash_offset =get_table_entry_id (imximage_bootops,"imximage boot option" , token); -if (imxhdr->flash_offset ==-1 ) { +if (imximage_flash_offset ==-1 ) {fprintf (stderr,"Error: %s[%d] -Invalid boot device" "(%s)\n" , name, lineno, token);exit (EXIT_FAILURE );
@@ -338,7 +339,7 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token, cmd_ver_first =0 ;break ;case CMD_BOOT_OFFSET : - imxhdr->flash_offset =get_cfg_value (token, name, lineno); + imximage_flash_offset =get_cfg_value (token, name, lineno);if (unlikely (cmd_ver_first !=1 )) cmd_ver_first =0 ;break ;
@@ -439,7 +440,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 (imximage_flash_offset ==FLASH_OFFSET_UNDEFINED ) {fprintf (stderr,"Error: No BOOT_FROM tag in %s\n" , name);exit (EXIT_FAILURE ); }
@@ -497,14 +498,14 @@ 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 ; + imximage_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); + (*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_flash_offset);/* * ROM bug alert
@@ -515,7 +516,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,* * The remaining fraction of a block bytes would not be loaded! */ - *header_size_ptr =ROUND (sbuf->st_size + imxhdr->flash_offset,4096 ); + *header_size_ptr =ROUND (sbuf->st_size + imximage_flash_offset,4096 ); }int imximage_check_params (struct mkimage_params *params)
tools/imximage.h +0 -1
@@ -147,7 +147,6 @@ struct imx_header {imx_header_v1_t hdr_v1;imx_header_v2_t hdr_v2; } header; -uint32_t flash_offset; } __attribute__((aligned(4096))); typedef void (*set_dcd_val_t)(struct imx_header *imxhdr,
Signature · 1 line
1.7.9.5
PATCH v2 2/7 tools: rename mximage_flash_offset to imximage_ivt_offset
In reply to Stefano BabicThis better reflects the naming from the Reference Manual as well as fits better since "flash" is not really applicabe for SATA.
---
Changes in v2: None
tools/imximage.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
tools/imximage.c +9 -8
@@ -52,7 +52,8 @@ static table_entry_t imximage_versions[] = {static struct imx_header imximage_header;static uint32_t imximage_version; -static uint32_t imximage_flash_offset; +/* Image Vector Table Offset */ +static uint32_t imximage_ivt_offset;static set_dcd_val_t set_dcd_val;static set_dcd_rst_t set_dcd_rst;
@@ -328,9 +329,9 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,set_hdr_func (imxhdr);break ;case CMD_BOOT_FROM : - imximage_flash_offset =get_table_entry_id (imximage_bootops, + imximage_ivt_offset =get_table_entry_id (imximage_bootops,"imximage boot option" , token); -if (imximage_flash_offset ==-1 ) { +if (imximage_ivt_offset ==-1 ) {fprintf (stderr,"Error: %s[%d] -Invalid boot device" "(%s)\n" , name, lineno, token);exit (EXIT_FAILURE );
@@ -339,7 +340,7 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token, cmd_ver_first =0 ;break ;case CMD_BOOT_OFFSET : - imximage_flash_offset =get_cfg_value (token, name, lineno); + imximage_ivt_offset =get_cfg_value (token, name, lineno);if (unlikely (cmd_ver_first !=1 )) cmd_ver_first =0 ;break ;
@@ -440,7 +441,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 (imximage_flash_offset ==FLASH_OFFSET_UNDEFINED ) { +if (imximage_ivt_offset ==FLASH_OFFSET_UNDEFINED ) {fprintf (stderr,"Error: No BOOT_FROM tag in %s\n" , name);exit (EXIT_FAILURE ); }
@@ -498,14 +499,14 @@ 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 */ - imximage_flash_offset =FLASH_OFFSET_UNDEFINED ; + imximage_ivt_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, imximage_flash_offset); + (*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_ivt_offset);/* * ROM bug alert
@@ -516,7 +517,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,* * The remaining fraction of a block bytes would not be loaded! */ - *header_size_ptr =ROUND (sbuf->st_size + imximage_flash_offset,4096 ); + *header_size_ptr =ROUND (sbuf->st_size + imximage_ivt_offset,4096 ); }int imximage_check_params (struct mkimage_params *params)
Signature · 1 line
1.7.9.5
PATCH v2 3/7 tools: dynamically allocate imx_header in imximage
In reply to Stefano BabicChange to dynamically allocate the imx_header to correctly allocate the IVT, Boot Data and DCD at correct locations depending on the boot media.
Also check that the Image Vector Table Offset + IVT + Boot Data + DCD <= Initial Load Region Size.
Previously struct imx_header was always 4096 bytes and was not dealing correctly with the Image Vector Table Offset.
Now, the memory allocation looks for e.g. SD boot like this
Storage u-boot.imx RAM
Device
00000000 177ff000 <--------------
| 00000400 00000000 d1 00 20 40 IVT.header 177ff400 <------- | 00000404 00000004 00 00 80 17 IVT.entry 177ff404 ----------- | 00000408 00000008 00 00 00 00 IVT.reserved1 177ff408 | | | 0000040C 0000000C 2c f4 7f 17 IVT.dcd 177ff40C ------ | | | 00000410 00000010 20 f4 7f 17 IVT.boot 177ff410 ---- | | | | 00000414 00000014 00 f4 7f 17 IVT.self 177ff414 -------- | | 00000418 00000018 00 00 00 00 IVT.csf 177ff418 | | | | 0000041C 0000001C 00 00 00 00 IVT.reserved2 177ff41C | | | | 00000420 00000020 00 f0 7f 17 BootData.start 177ff420 <--- | | --- 00000424 00000024 00 60 03 00 BootData.length 177ff424 | | 00000428 00000028 00 00 00 00 BootData.plugin 177ff428 | | 0000042C 0000002C d2 03 30 40 DCD.header 177ff42C <----- | ... |
00001000 00000c00 13 00 00 ea U-Boot Start 17800000 <----------
While at it also remove the unused #define HEADER_OFFSET.
---
Changes in v2:
- drop dead code (Marek Vasut)
tools/imximage.c | 43 ++++++++++++++++++++++++++++++++++++------- tools/imximage.h | 16 +++++++++++++--- 2 files changed, 49 insertions(+), 10 deletions(-)
tools/imximage.c +36 -7
@@ -31,7 +31,7 @@ static table_entry_t imximage_cmds[] = {* Supported Boot options for configuration file * this is needed to set the correct flash offset */ -static table_entry_t imximage_bootops[] = { +static table_entry_t imximage_boot_offset[] = { {FLASH_OFFSET_ONENAND ,"onenand" ,"OneNAND Flash" ,}, {FLASH_OFFSET_NAND ,"nand" ,"NAND Flash" , }, {FLASH_OFFSET_NOR ,"nor" ,"NOR Flash" , },
@@ -42,6 +42,20 @@ static table_entry_t imximage_bootops[] = { };/* +* Supported Boot options for configuration file +* this is needed to determine the initial load size +*/ +static table_entry_t imximage_boot_loadsize[] = { + {FLASH_LOADSIZE_ONENAND ,"onenand" ,"OneNAND Flash" ,}, + {FLASH_LOADSIZE_NAND ,"nand" ,"NAND Flash" , }, + {FLASH_LOADSIZE_NOR ,"nor" ,"NOR Flash" , }, + {FLASH_LOADSIZE_SATA ,"sata" ,"SATA Disk" , }, + {FLASH_LOADSIZE_SD ,"sd" ,"SD Card" , }, + {FLASH_LOADSIZE_SPI ,"spi" ,"SPI Flash" , }, + {-1 ,"" ,"Invalid" , }, +}; + +/* * IMXIMAGE version definition for i.MX chips */ static table_entry_t imximage_versions[] = {
@@ -54,6 +68,8 @@ static struct imx_header imximage_header;static uint32_t imximage_version;/* Image Vector Table Offset */ static uint32_t imximage_ivt_offset; +/* Initial Load Region Size */ +static uint32_t imximage_init_loadsize;static set_dcd_val_t set_dcd_val;static set_dcd_rst_t set_dcd_rst;
@@ -195,7 +211,8 @@ 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 ); +/* TODO: check i.MX image V1 handling, for now use 'old' style */ + hdr_base = entry_point -4096 ; fhdr_v1->app_dest_ptr = hdr_base - flash_offset; fhdr_v1->app_code_jump_vector = entry_point;
@@ -222,12 +239,13 @@ 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 ); - + hdr_base = entry_point - imximage_init_loadsize + + flash_offset; + fhdr_v2->self = hdr_base; fhdr_v2->dcd_ptr = hdr_base + offsetof(imx_header_v2_t , dcd_table); fhdr_v2->boot_data_ptr = hdr_base + offsetof(imx_header_v2_t , boot_data); - hdr_v2->boot_data.start = hdr_base - flash_offset; + hdr_v2->boot_data.start = entry_point - imximage_init_loadsize;/* Security feature are not supported */ fhdr_v2->csf =0 ;
@@ -329,13 +347,24 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,set_hdr_func (imxhdr);break ;case CMD_BOOT_FROM : - imximage_ivt_offset =get_table_entry_id (imximage_bootops, + imximage_ivt_offset =get_table_entry_id (imximage_boot_offset,"imximage boot option" , token);if (imximage_ivt_offset ==-1 ) {fprintf (stderr,"Error: %s[%d] -Invalid boot device" "(%s)\n" , name, lineno, token);exit (EXIT_FAILURE ); } + + imximage_init_loadsize = +get_table_entry_id (imximage_boot_loadsize, +"imximage boot option" , token); + +if (imximage_init_loadsize ==-1 ) { +fprintf (stderr, +"Error: %s[%d] -Invalid boot device(%s)\n" , + name, lineno, token); +exit (EXIT_FAILURE ); + }if (unlikely (cmd_ver_first !=1 )) cmd_ver_first =0 ;break ;
@@ -517,7 +546,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,* * The remaining fraction of a block bytes would not be loaded! */ - *header_size_ptr =ROUND (sbuf->st_size + imximage_ivt_offset,4096 ); + *header_size_ptr =ROUND (sbuf->st_size,4096 ); }int imximage_check_params (struct mkimage_params *params)
tools/imximage.h +13 -3
@@ -13,14 +13,14 @@#define APP_CODE_BARKER 0xB1#define DCD_BARKER 0xB17219E9 -#define HEADER_OFFSET 0x400 -/* * NOTE: This file must be kept in sync with arch/arm/include/asm/\ * imx-common/imximage.cfg because tools/imximage.c can not * cross-include headers from arch/arm/ and vice-versa. */ #define CMD_DATA_STR "DATA" + +/* Initial Vector Table Offset */ #define FLASH_OFFSET_UNDEFINED 0xFFFFFFFF#define FLASH_OFFSET_STANDARD 0x400#define FLASH_OFFSET_NAND FLASH_OFFSET_STANDARD
@@ -30,6 +30,16 @@#define FLASH_OFFSET_NOR 0x1000#define FLASH_OFFSET_SATA FLASH_OFFSET_STANDARD +/* Initial Load Region Size */ +#define FLASH_LOADSIZE_UNDEFINED 0xFFFFFFFF +#define FLASH_LOADSIZE_STANDARD 0x1000 +#define FLASH_LOADSIZE_NAND FLASH_LOADSIZE_STANDARD +#define FLASH_LOADSIZE_SD FLASH_LOADSIZE_STANDARD +#define FLASH_LOADSIZE_SPI FLASH_LOADSIZE_STANDARD +#define FLASH_LOADSIZE_ONENAND 0x400 +#define FLASH_LOADSIZE_NOR 0x0/* entire image */ +#define FLASH_LOADSIZE_SATA FLASH_LOADSIZE_STANDARD +#define IVT_HEADER_TAG 0xD1#define IVT_VERSION 0x40#define DCD_HEADER_TAG 0xD2
@@ -147,7 +157,7 @@ struct imx_header {imx_header_v1_t hdr_v1;imx_header_v2_t hdr_v2; } header; -} __attribute__((aligned(4096))); +}; typedef void (*set_dcd_val_t)(struct imx_header *imxhdr, char *name, int lineno,
Signature · 1 line
1.7.9.5
PATCH v2 4/7 tools: add variable padding of data image in mkimage
In reply to Stefano BabicUse previously unused return value of function vrec_header to return a padding size to generic mkimage. This padding size is used in copy_files to pad with zeros after copying the data image.
---
Changes in v2: None
tools/mkimage.c | 24 +++++++++++++++++++++--- tools/mkimage.h | 5 ++++- 2 files changed, 25 insertions(+), 4 deletions(-)
tools/mkimage.c +21 -3
@@ -137,6 +137,7 @@ main (int argc, char **argv)char *ptr;int retval =0 ;struct image_type_params *tparams =NULL ; +int pad_len =0 ;/* Init Freescale PBL Boot image generation/list support */ init_pbl_image_type ();
@@ -391,7 +392,7 @@ NXTARG: ;* allocate memory for the header itself. */ if (tparams->vrec_header) - tparams->vrec_header (¶ms, tparams); + pad_len = tparams->vrec_header (¶ms, tparams);else memset (tparams->hdr,0 , tparams->header_size);
@@ -463,7 +464,7 @@ NXTARG: ;/* PBL has special Image format, implements its' own */ pbl_load_uboot (ifd, ¶ms); }else { -copy_file (ifd, params.datafile,0 ); +copy_file (ifd, params.datafile, pad_len); } }
@@ -537,10 +538,19 @@ copy_file (int ifd, const char *datafile, int pad)unsigned char *ptr;int tail;int zero =0 ; +uint8_t zeros[4096 ];int offset =0 ;int size;struct image_type_params *tparams =mkimage_get_type (params.type); +if (pad >=sizeof (zeros)) { +fprintf (stderr,"%s: Can't pad to %d\n" , + params.cmdname, pad); +exit (EXIT_FAILURE ); + } + +memset (zeros,0 ,sizeof (zeros)); +if (params.vflag) {fprintf (stderr,"Adding Image %s\n" , datafile); }
@@ -598,7 +608,8 @@ copy_file (int ifd, const char *datafile, int pad)exit (EXIT_FAILURE ); } -if (pad && ((tail = size %4 ) !=0 )) { + tail = size %4 ; +if ((pad ==1 ) && (tail !=0 )) {if (write (ifd, (char *)&zero,4 -tail) !=4 -tail) { fprintf (stderr, "%s: Write error on %s: %s\n",
@@ -606,6 +617,13 @@ copy_file (int ifd, const char *datafile, int pad) strerror(errno));exit (EXIT_FAILURE ); } + }else if (pad >1 ) { +if (write (ifd, (char *)&zeros, pad) != pad) { +fprintf (stderr,"%s: Write error on %s: %s\n" , + params.cmdname, params.imagefile, +strerror (errno)); +exit (EXIT_FAILURE ); + } } (void )munmap ((void *)ptr, sbuf.st_size);
tools/mkimage.h +4 -1
@@ -132,7 +132,10 @@ struct image_type_params {/* * This callback function will be executed for variable size record * It is expected to build this header in memory and return its length -* and a pointer to it +* and a pointer to it by using image_type_params.header_size and +* image_type_params.hdr. The return value shall indicate if an +* additional padding should be used when copying the data image +* by returning the padding length. */ int (*vrec_header) (struct mkimage_params *,struct image_type_params *);
Signature · 1 line
1.7.9.5
PATCH v2 5/7 tools: add padding of data image file for imximage
In reply to Stefano BabicImplement function vrec_header to be able to pad the final data image file according the what has been calculated for boot_data.length.
---
Changes in v2: None
tools/imximage.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-)
tools/imximage.c +80 -2
@@ -571,18 +571,96 @@ int imximage_check_params(struct mkimage_params *params) (params->xflag) || !(strlen (params->imagename)); } +static int imximage_generate (struct mkimage_params *params, +struct image_type_params *tparams) +{ +struct imx_header *imxhdr; +size_t alloc_len; +int dfd; +struct stat sbuf; +char *datafile = params->datafile; +uint32_t pad_len; + +memset (&imximage_header,0 ,sizeof (imximage_header)); + +/* +* In order to not change the old imx cfg file +* by adding VERSION command into it, here need +* 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 */ + imximage_ivt_offset =FLASH_OFFSET_UNDEFINED ; + imximage_csf_size =0 ; +set_hdr_func (imxhdr); + +/* 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 + alloc_len = imximage_init_loadsize - imximage_ivt_offset; + +if (alloc_len <sizeof (struct imx_header )) { +fprintf (stderr,"%s: header error\n" , + params->cmdname); +exit (EXIT_FAILURE ); + } + + imxhdr =malloc (alloc_len); + +if (!imxhdr) { +fprintf (stderr,"%s: malloc return failure: %s\n" , + params->cmdname,strerror (errno)); +exit (EXIT_FAILURE ); + } + +memset (imxhdr,0 , alloc_len); + + tparams->header_size = alloc_len; + tparams->hdr = imxhdr; + +/* determine data image file length */ + dfd =open (datafile,O_RDONLY |O_BINARY ); +if (dfd <0 ) { +fprintf (stderr,"%s: Can't open %s: %s\n" , + params->cmdname, datafile,strerror (errno)); +exit (EXIT_FAILURE ); + } + +if (fstat (dfd, &sbuf) <0 ) { +fprintf (stderr,"%s: Can't stat %s: %s\n" , + params->cmdname, datafile,strerror (errno)); +exit (EXIT_FAILURE ); + } + + pad_len =ROUND (sbuf.st_size,4096 ) - sbuf.st_size; + +close (dfd); + +/* TODO: check i.MX image V1 handling, for now use 'old' style */ +if (imximage_version ==IMXIMAGE_V1 ) +return 0 ; +else +return pad_len; +} + +/* * imximage parameters */ static struct image_type_params imximage_params = { .name ="Freescale i.MX Boot Image support" , - .header_size =sizeof (struct imx_header ), - .hdr = (void *)&imximage_header, + .header_size =0 , + .hdr =NULL , .check_image_type = imximage_check_image_types, .verify_header = imximage_verify_header, .print_header = imximage_print_header, .set_header = imximage_set_header, .check_params = imximage_check_params, + .vrec_header = imximage_generate, };void init_imx_image_type (void )
Signature · 1 line
1.7.9.5
PATCH v2 5/7 tools: add padding of data image file for imximage
Dear Stefano Babic,
Quoted 6 lines
Implement function
vrec_headerto be able to pad the final data image file according the what has been calculated for boot_data.length.Signed-off-by Stefano Babic <[email protected]>---
[...]
tools/imximage.c int imximage_check_params(struct mkimage_params *params) · line 625
Quoted 12 lines
tools/imximage.c +12
-0+if (!imxhdr) { +fprintf (stderr,"%s: malloc return failure: %s\n" , + params->cmdname,strerror (errno)); +exit (EXIT_FAILURE ); + } + +memset (imxhdr,0 , alloc_len); + + tparams->header_size = alloc_len; + tparams->hdr = imxhdr; + +/* determine data image file length */
Why dont you just call stat(2) here instead of the open+fstat+close combo?
Quoted 8 lines
tools/imximage.c +8
-0+ dfd =open (datafile,O_RDONLY |O_BINARY ); +if (dfd <0 ) { +fprintf (stderr,"%s: Can't open %s: %s\n" , + params->cmdname, datafile,strerror (errno)); +exit (EXIT_FAILURE ); + } + +if (fstat (dfd, &sbuf) <0 ) {
tools/imximage.c int imximage_check_params(struct mkimage_params *params) · line 643
Quoted 10 lines
tools/imximage.c +10
-0+fprintf (stderr,"%s: Can't stat %s: %s\n" , + params->cmdname, datafile,strerror (errno)); +exit (EXIT_FAILURE ); + } + + pad_len =ROUND (sbuf.st_size,4096 ) - sbuf.st_size; + +close (dfd); + +/* TODO: check i.MX image V1 handling, for now use 'old' style */
[...]
Best regards,
Marek Vasut
PATCH v2 5/7 tools: add padding of data image file for imximage
Hi Marek,
Quoted 11 lines · Marek Vasut
Dear Stefano Babic,
Quoted 6 lines
Implement function
vrec_headerto be able to pad the final data image file according the what has been calculated for boot_data.length.Signed-off-by Stefano Babic <[email protected]>---
[...]
Quoted 14 lines
tools/imximage.c int imximage_check_params(struct mkimage_params *params) · line 625
Quoted 12 lines
tools/imximage.c +12
-0+if (!imxhdr) { +fprintf (stderr,"%s: malloc return failure: %s\n" , + params->cmdname,strerror (errno)); +exit (EXIT_FAILURE ); + } + +memset (imxhdr,0 , alloc_len); + + tparams->header_size = alloc_len; + tparams->hdr = imxhdr; + +/* determine data image file length */ Why dont you just call stat(2) here instead of the open+fstat+close combo?
Thanks, replaced in V3.
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH v2 6/7 tools: add support for setting the CSF into imximage
In reply to Stefano BabicAdd support for setting the CSF (Command Sequence File) pointer which is used for HAB (High Assurance Boot) in the imximage by adding e.g.
CSF 0x2000
in the imximage.cfg file.
This will set the CSF pointer accordingly just after the padded data image area. The boot_data.length is adjusted with the value from the imximage.cfg config file.
The resulting u-boot.imx can be signed with the FSL HAB tooling. The generated CSF block needs to be appended to the u-boot.imx.
Series-changes : 2
- checkpatch warning
- do not output HAB values when csf values are not defined by cfg
---
Changes in v2: None
doc/README.imximage | 18 +++++++++++++++--- doc/README.mxc_hab | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/imximage.c | 41 ++++++++++++++++++++++++++++++++++++++--- tools/imximage.h | 3 ++- 4 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 doc/README.mxc_hab
doc/README.imximage +15 -3
@@ -15,9 +15,6 @@ Booting from NOR flash does not require to use this image type. For more details refer Chapter 2 - System Boot and section 2.14 (flash header description) of the processor's manual. -This implementation does not use at the moment the secure boot feature -of the processor. The image is generated disabling all security fields. - Command syntax: -------------- ./tools/mkimage -l <mx u-boot_file>
@@ -86,6 +83,21 @@ Configuration command line syntax: Example: BOOT_FROM spi + CSF value + + Total size of CSF (Command Sequence File) + used for Secure Boot/ High Assurance Boot + (HAB). + + Using this command will populate the IVT + (Initial Vector Table) CSF pointer and adjust + the length fields only. The CSF itself needs + to be generated with Freescale tools and + 'manually' appended to the u-boot.imx file. + + Example: + CSF 0x2000 + DATA type address value type: word=4, halfword=2, byte=1
doc/README.mxc_hab new file +48 -0
48 lines not on this page · raw message
tools/imximage.c +38 -3
97 lines not on this page · raw message
tools/imximage.h +2 -1
@@ -52,7 +52,8 @@ enum imximage_cmd {CMD_IMAGE_VERSION ,CMD_BOOT_FROM ,CMD_BOOT_OFFSET , -CMD_DATA +CMD_DATA , + CMD_CSF, }; enum imximage_fld_types {
Signature · 1 line
1.7.9.5
PATCH v2 6/7 tools: add support for setting the CSF into imximage
Am 12.08.13 16:39, schrieb Stefano Babic:
doc/README.imximage Configuration command line syntax: · line 93
Quoted 10 lines
doc/README.imximage +8
-0BOOT_FROM spi + CSF value + + Total size of CSF (Command Sequence File) + used for Secure Boot/ High Assurance Boot + (HAB). + + Using this command will populate the IVT + (Initial Vector Table) CSF pointer and adjust
^^^^^^^^^^^^^^^^^^^^
Isn't that "Image Vector Table"?
Regards,
Bernhard
PATCH v2 7/7 imx: add status reporting for HAB status
In reply to Stefano BabicAdd functions to report the HAB (High Assurance Boot) status of e.g. i.MX6 CPUs.
This is taken from
git://git.freescale.com/imx/uboot-imx.git branch imx_v2009.08_3.0.35_4.0.0 cpu/arm_cortexa8/mx6/generic.c include/asm-arm/arch-mx6/mx6_secure.h
---
Changes in v2:
- Fix errors when SECURE_BOOT is selected due to enum
- simplify display_event code (Marek Vasut)
- compile hab code only if SECURE_BOOT is set (Fabio Estevam)
- update licence with SPDX line according to new rules.
arch/arm/cpu/armv7/mx6/Makefile | 7 +- arch/arm/cpu/armv7/mx6/hab.c | 104 ++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/hab.h | 67 +++++++++++++++++++ arch/arm/include/asm/arch-mx6/imx-regs.h | 8 ++- 4 files changed, 182 insertions(+), 4 deletions(-) create mode 100644 arch/arm/cpu/armv7/mx6/hab.c create mode 100644 arch/arm/include/asm/arch-mx6/hab.h
arch/arm/cpu/armv7/mx6/Makefile +4 -3
@@ -11,10 +11,11 @@ include $(TOPDIR)/config.mk LIB = $(obj)lib$(SOC).o -COBJS = soc.o clock.o +COBJS-y = soc.o clock.o +COBJS-$(CONFIG_SECURE_BOOT) += hab.o -SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS)) +SRCS := $(SOBJS:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS-y)) all: $(obj).depend $(LIB)
arch/arm/cpu/armv7/mx6/hab.c new file +104 -0
104 lines not on this page · raw message
arch/arm/include/asm/arch-mx6/hab.h new file +67 -0
67 lines not on this page · raw message
arch/arm/include/asm/arch-mx6/imx-regs.h +7 -1
@@ -456,7 +456,13 @@ struct fuse_bank0_regs {u32 uid_low;u32 rsvd1[3 ];u32 uid_high; -u32 rsvd2[0x17 ]; +u32 rsvd2[3 ]; +u32 rsvd3[4 ]; +u32 rsvd4[4 ]; +u32 rsvd5[4 ]; +u32 cfg5; +u32 rsvd6[3 ]; +u32 rsvd7[4 ]; };struct fuse_bank4_regs {
Signature · 1 line
1.7.9.5
PATCH v2 7/7 imx: add status reporting for HAB status
Hi,
Am 12.08.13 16:39, schrieb Stefano Babic:
arch/arm/cpu/armv7/mx6/hab.c line 29
Quoted 11 lines
arch/arm/cpu/armv7/mx6/hab.c new file +11
-0+ +bool is_hab_enabled (void ) +{ +struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR ; +struct fuse_bank *bank = &ocotp->bank[0 ]; +struct fuse_bank0_regs *fuse = + (struct fuse_bank0_regs *)bank->fuse_regs; +uint32_t reg =readl (&fuse->cfg5); + +return (reg &0x2 ) ==0x2 ; +}
With the exception of that function and the required structure definitions, the whole code also works with i.MX53 (tested with LOCO board), too. Also AN4581 [1] that describes HAB doesn't differentiate between i.MX53 and i.MX6 in that case as they both use HAB v4.
I think you have more experience how to organize the code (I added a few symlinks and modified only the Makefile, but I guess that symlink are not the best solution).
Regards,
Bernhard
[1] http://cache.freescale.com/files/32bit/doc/app_note/AN4581.pdf
v2 cover The patchset fixes some issue in the generation of the imx image
In reply to Stefano BabicOn Mon, Aug 12, 2013 at 11:39 AM, Stefano Babic <[email protected]> wrote:
...
Quoted 7 lines
The patchset allows to add to the imx Header the CSF (command Sequence File) generated by the tools provided by Freescale. The CSF is then simply concatenated to the u-boot image, making a signed bootloader, that the processor can verify if the fuses for the keys are burned. The processor (i.MX53 / i.MX6x) will not start a bootloader that cannot be verified - further infos how to configure the SOC to verify the bootloader can be found in the User Manual of the specific SOC.
...
Couldn't a brief 'how-to' to be added to the README and also the pointers to the documents where this is documented?
Signature · 3 lines
Otavio Salvador O.S. Systems http://www.ossystems.com.br http://projetos.ossystems.com.br Mobile: +55 (53) 9981-7854 Mobile: +1 (347) 903-9750
v2 cover The patchset fixes some issue in the generation of the imx image
Hio Otavio,
Quoted 9 lines · Otavio Salvador
On Mon, Aug 12, 2013 at 11:39 AM, Stefano Babic <[email protected]> wrote:
...Quoted 7 lines
The patchset allows to add to the imx Header the CSF (command Sequence File) generated by the tools provided by Freescale. The CSF is then simply concatenated to the u-boot image, making a signed bootloader, that the processor can verify if the fuses for the keys are burned. The processor (i.MX53 / i.MX6x) will not start a bootloader that cannot be verified - further infos how to configure the SOC to verify the bootloader can be found in the User Manual of the specific SOC.
Quoted 3 lines
...
Couldn't a brief 'how-to' to be added to the README
I do not thnk so, because it will be a duplication of documentation already provided by the manufacturer.
Quoted 2 lines
and also the
pointers to the documents where this is documented?
Maybe I should point out in which document this stuff is covered. Freescale can move the link (I find a link for each processor on the Freescale's website). Something like "can be found in the "High Assurance Boot Version Application Priogramming Interface Reference Manual" as part of the Freescale Code Signing Tool, available on the manufacturer's website ?"
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
v2 cover The patchset fixes some issue in the generation of the imx image
Quoted 12 lines · Stefano Babic
Hio Otavio,
Quoted 9 lines · Otavio Salvador
On Mon, Aug 12, 2013 at 11:39 AM, Stefano Babic <[email protected]> wrote:
...Quoted 7 lines
The patchset allows to add to the imx Header the CSF (command Sequence File) generated by the tools provided by Freescale. The CSF is then simply concatenated to the u-boot image, making a signed bootloader, that the processor can verify if the fuses for the keys are burned. The processor (i.MX53 / i.MX6x) will not start a bootloader that cannot be verified - further infos how to configure the SOC to verify the bootloader can be found in the User Manual of the specific SOC.
Quoted 6 lines
Quoted 3 lines
...
Couldn't a brief 'how-to' to be added to the README
I do not thnk so, because it will be a duplication of documentation already provided by the manufacturer.
Yes; ok.
Quoted 9 lines
Quoted 2 lines
and also the
pointers to the documents where this is documented?Maybe I should point out in which document this stuff is covered. Freescale can move the link (I find a link for each processor on the Freescale's website). Something like "can be found in the "High Assurance Boot Version Application Priogramming Interface Reference Manual" as part of the Freescale Code Signing Tool, available on the manufacturer's website ?"
Yes; this would help people to find it.
Signature · 3 lines
Otavio Salvador O.S. Systems http://www.ossystems.com.br http://code.ossystems.com.br Mobile: +55 (53) 9981-7854 Mobile: +1 (347) 903-9750
v2 cover The patchset fixes some issue in the generation of the imx image
In reply to Stefano BabicQuoted 9 lines · Stefano Babic
(header for Freescale's i.MX processors) to allow the usage of Freescale's tools to sign the u-boot image and provide a secure boot.
This has nothing to do with the Secure Boot extensions implemented by Simon Glass, that can be in any case used to boot later a secure image. Freescale's secure boot ensures that a signed bootloader
is started only if it is verified with a key that is burned into the iMX fuses. Documentation about the Freescale's secure process can be read from the AN4591, available on the Freescale's Website.
Where does Marek's patch fall in here exactly? Should he be based on top of yours, yours on his? It should all go via u-boot-imx, so you'll have to do the merging anyhow :) And on that note, things seem as sane as they're likley going to be, with the caveat of what you've already said you'll v3.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130819/7e3e599b/attachment.pgp>
v2 cover The patchset fixes some issue in the generation of the imx image
Hi Tom,
Quoted 14 lines · Tom Rini
Quoted 11 lines · Stefano Babic
(header for Freescale's i.MX processors) to allow the usage of Freescale's tools to sign the u-boot image and provide a secure boot.
This has nothing to do with the Secure Boot extensions implemented by Simon Glass, that can be in any case used to boot later a secure image. Freescale's secure boot ensures that a signed bootloader is started only if it is verified with a key that is burned into the iMX fuses. Documentation about the Freescale's secure process can be read from the AN4591, available on the Freescale's Website.
Quoted 1 line
Where does Marek's patch fall in here exactly?
Marek's patch is intended to add support for mxs based processor (mx23 / mx28) and it is quite parallel to mine and I think Marek will replace Freescale's own tool elftosb.
Quoted 2 lines
Should he be based on top of yours, yours on his? It should all go via u-boot-imx, so you'll have to do the merging anyhow :)
I agree - I will do the merge with Marek's patch ;-).
If there are some conflicts (I have not yet tried), I will solve them directly with Marek.
Best regards,
Stefano
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
v2 cover The patchset fixes some issue in the generation of the imx image
Quoted 17 lines · Stefano Babic
Hi Tom,
Quoted 14 lines · Tom Rini
Quoted 11 lines · Stefano Babic
(header for Freescale's i.MX processors) to allow the usage of Freescale's tools to sign the u-boot image and provide a secure boot.
This has nothing to do with the Secure Boot extensions implemented by Simon Glass, that can be in any case used to boot later a secure image. Freescale's secure boot ensures that a signed bootloader is started only if it is verified with a key that is burned into the iMX fuses. Documentation about the Freescale's secure process can be read from the AN4591, available on the Freescale's Website.
Quoted 5 lines
Quoted 1 line
Where does Marek's patch fall in here exactly?
Marek's patch is intended to add support for mxs based processor (mx23 / mx28) and it is quite parallel to mine and I think Marek will replace Freescale's own tool elftosb.
But, for clarity, there's not a whole bunch of common code that could be used here, and these i.MXes are different from those i.MXes?
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130819/bcb7b305/attachment.pgp>
v2 cover The patchset fixes some issue in the generation of the imx image
Dear Tom Rini,
Quoted 17 lines · Stefano Babic
Quoted 16 lines
Hi Tom,
Quoted 13 lines · Tom Rini
Quoted 11 lines · Stefano Babic
(header for Freescale's i.MX processors) to allow the usage of Freescale's tools to sign the u-boot image and provide a secure boot.
This has nothing to do with the Secure Boot extensions implemented by Simon Glass, that can be in any case used to boot later a secure image. Freescale's secure boot ensures that a signed bootloader is started only if it is verified with a key that is burned into the iMX fuses. Documentation about the Freescale's secure process can be read from the AN4591, available on the Freescale's Website.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Where does Marek's patch fall in here exactly?
Marek's patch is intended to add support for mxs based processor (mx23 / mx28) and it is quite parallel to mine and I think Marek will replace Freescale's own tool elftosb.
But, for clarity, there's not a whole bunch of common code that could be used here, and these i.MXes are different from those i.MXes?
MX23/28 and the rest of IMX use the same "HAB" thing, but due to differences in their bootrom (MXS is sigmatel design, IMX is freescale), it's done differently on both MXS and IMX. Thus we need two implementations :-( IIRC there is HABv3 on IMX and HABv4 on MXS, no ?
Best regards,
Marek Vasut
v2 cover The patchset fixes some issue in the generation of the imx image
Quoted 25 lines · Marek Vasut
Dear Tom Rini,
Quoted 23 lines · Stefano Babic
Quoted 21 lines
Hi Tom,
Quoted 13 lines · Tom Rini
Quoted 11 lines · Stefano Babic
(header for Freescale's i.MX processors) to allow the usage of Freescale's tools to sign the u-boot image and provide a secure boot.
This has nothing to do with the Secure Boot extensions implemented by Simon Glass, that can be in any case used to boot later a secure image. Freescale's secure boot ensures that a signed bootloader is started only if it is verified with a key that is burned into the iMX fuses. Documentation about the Freescale's secure process can be read from the AN4591, available on the Freescale's Website.
Quoted 1 line
Where does Marek's patch fall in here exactly?
Marek's patch is intended to add support for mxs based processor (mx23 / mx28) and it is quite parallel to mine and I think Marek will replace Freescale's own tool elftosb.
Quoted 8 lines
Quoted 2 lines
But, for clarity, there's not a whole bunch of common code that could be used here, and these i.MXes are different from those i.MXes?
MX23/28 and the rest of IMX use the same "HAB" thing, but due to differences in their bootrom (MXS is sigmatel design, IMX is freescale), it's done differently on both MXS and IMX. Thus we need two implementations :-( IIRC there is HABv3 on IMX and HABv4 on MXS, no ?
OK, thanks.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130819/dc3cb69c/attachment.pgp>
v3 cover The patchset fixes some issue in the generation of the imx image
In reply to Stefano Babic(header for Freescale's i.MX processors) to allow the usage of Freescale's tools to sign the u-boot image and provide a secure boot.
This has nothing to do with the Secure Boot extensions implemented by Simon Glass, that can be in any case used to boot later a secure image. Freescale's secure boot ensures that a signed bootloader
is started only if it is verified with a key that is burned into the iMX fuses. Documentation about the Freescale's secure process can be read from the AN4591, available on the Freescale's Website.
The patchset allows to add to the imx Header the CSF (command Sequence File) generated by the tools provided by Freescale. The CSF is then simply concatenated to the u-boot image, making a signed bootloader, that the processor can verify if the fuses for the keys are burned. The processor (i.MX53 / i.MX6x) will not start a bootloader that cannot be verified - further infos how to configure the SOC to verify the bootloader can be found in the User Manual of the specific SOC.
Next step is to verify the kernel, that can be still done using Simon's patches for verified boot (CONFIG_OF_CONTROL must be set in the board configuarion file).
Changes in v3:
- uses stat instead of open / fstat / close (Marek Vasut)
- add info in the README where to find description of signing process in the Freescale Website (Otavio Salvador)
Changes in v2:
- drop dead code (Marek Vasut)
- checkpatch warning
- do not output HAB values when csf values are not defined by cfg
- Fix errors when SECURE_BOOT is selected due to enum
- simplify display_event code (Marek Vasut)
- compile hab code only if SECURE_BOOT is set (Fabio Estevam)
- update licence with SPDX line according to new rules.
Stefano Babic (7):
tools: imx_header should not include flash_offset
tools: rename mximage_flash_offset to imximage_ivt_offset
tools: dynamically allocate imx_header in imximage
tools: add variable padding of data image in mkimage
tools: add padding of data image file for imximage
tools: add support for setting the CSF into imximage
imx: add status reporting for HAB status
arch/arm/cpu/armv7/mx6/Makefile | 7 +- arch/arm/cpu/armv7/mx6/hab.c | 104 +++++++++++++++++++ arch/arm/include/asm/arch-mx6/hab.h | 67 ++++++++++++ arch/arm/include/asm/arch-mx6/imx-regs.h | 8 +- doc/README.imximage | 30 +++++- doc/README.mxc_hab | 48 +++++++++ tools/imximage.c | 166 +++++++++++++++++++++++++++--- tools/imximage.h | 20 +++- tools/mkimage.c | 24 ++++- tools/mkimage.h | 5 +- 10 files changed, 448 insertions(+), 31 deletions(-) create mode 100644 arch/arm/cpu/armv7/mx6/hab.c create mode 100644 arch/arm/include/asm/arch-mx6/hab.h create mode 100644 doc/README.mxc_hab
Signature · 1 line
1.7.9.5
PATCH v3 1/7 tools: imx_header should not include flash_offset
Doing a make distclean; make mx6qsabresd_config; make
and hexdump -C u-boot.imx | less
...
00000360 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| *
000003f0 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 |................|
^^^^^^^^^^^
00000400 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| *
00001000 13 00 00 ea 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 |...?.?.?.?.?.?.?|
...
shows the flash_offset value being written into the final generated image, wich is not correct.
Instead create flash_offset as static variable such that the generated image is "clean".
00000360 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| *
00001000 13 00 00 ea 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 |...?.?.?.?.?.?.?|
---
Changes in v3: None
Changes in v2: None
tools/imximage.c | 15 ++++++++------- tools/imximage.h | 1 - 2 files changed, 8 insertions(+), 8 deletions(-)
tools/imximage.c +8 -7
@@ -52,6 +52,7 @@ static table_entry_t imximage_versions[] = {static struct imx_header imximage_header;static uint32_t imximage_version; +static uint32_t imximage_flash_offset;static set_dcd_val_t set_dcd_val;static set_dcd_rst_t set_dcd_rst;
@@ -327,9 +328,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, + imximage_flash_offset =get_table_entry_id (imximage_bootops,"imximage boot option" , token); -if (imxhdr->flash_offset ==-1 ) { +if (imximage_flash_offset ==-1 ) {fprintf (stderr,"Error: %s[%d] -Invalid boot device" "(%s)\n" , name, lineno, token);exit (EXIT_FAILURE );
@@ -338,7 +339,7 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token, cmd_ver_first =0 ;break ;case CMD_BOOT_OFFSET : - imxhdr->flash_offset =get_cfg_value (token, name, lineno); + imximage_flash_offset =get_cfg_value (token, name, lineno);if (unlikely (cmd_ver_first !=1 )) cmd_ver_first =0 ;break ;
@@ -439,7 +440,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 (imximage_flash_offset ==FLASH_OFFSET_UNDEFINED ) {fprintf (stderr,"Error: No BOOT_FROM tag in %s\n" , name);exit (EXIT_FAILURE ); }
@@ -497,14 +498,14 @@ 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 ; + imximage_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); + (*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_flash_offset);/* * ROM bug alert
@@ -515,7 +516,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,* * The remaining fraction of a block bytes would not be loaded! */ - *header_size_ptr =ROUND (sbuf->st_size + imxhdr->flash_offset,4096 ); + *header_size_ptr =ROUND (sbuf->st_size + imximage_flash_offset,4096 ); }int imximage_check_params (struct mkimage_params *params)
tools/imximage.h +0 -1
@@ -147,7 +147,6 @@ struct imx_header {imx_header_v1_t hdr_v1;imx_header_v2_t hdr_v2; } header; -uint32_t flash_offset; } __attribute__((aligned(4096))); typedef void (*set_dcd_val_t)(struct imx_header *imxhdr,
Signature · 1 line
1.7.9.5
PATCH v3 2/7 tools: rename mximage_flash_offset to imximage_ivt_offset
In reply to Stefano BabicThis better reflects the naming from the Reference Manual as well as fits better since "flash" is not really applicabe for SATA.
---
Changes in v3: None
Changes in v2: None
tools/imximage.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
tools/imximage.c +9 -8
@@ -52,7 +52,8 @@ static table_entry_t imximage_versions[] = {static struct imx_header imximage_header;static uint32_t imximage_version; -static uint32_t imximage_flash_offset; +/* Image Vector Table Offset */ +static uint32_t imximage_ivt_offset;static set_dcd_val_t set_dcd_val;static set_dcd_rst_t set_dcd_rst;
@@ -328,9 +329,9 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,set_hdr_func (imxhdr);break ;case CMD_BOOT_FROM : - imximage_flash_offset =get_table_entry_id (imximage_bootops, + imximage_ivt_offset =get_table_entry_id (imximage_bootops,"imximage boot option" , token); -if (imximage_flash_offset ==-1 ) { +if (imximage_ivt_offset ==-1 ) {fprintf (stderr,"Error: %s[%d] -Invalid boot device" "(%s)\n" , name, lineno, token);exit (EXIT_FAILURE );
@@ -339,7 +340,7 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token, cmd_ver_first =0 ;break ;case CMD_BOOT_OFFSET : - imximage_flash_offset =get_cfg_value (token, name, lineno); + imximage_ivt_offset =get_cfg_value (token, name, lineno);if (unlikely (cmd_ver_first !=1 )) cmd_ver_first =0 ;break ;
@@ -440,7 +441,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 (imximage_flash_offset ==FLASH_OFFSET_UNDEFINED ) { +if (imximage_ivt_offset ==FLASH_OFFSET_UNDEFINED ) {fprintf (stderr,"Error: No BOOT_FROM tag in %s\n" , name);exit (EXIT_FAILURE ); }
@@ -498,14 +499,14 @@ 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 */ - imximage_flash_offset =FLASH_OFFSET_UNDEFINED ; + imximage_ivt_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, imximage_flash_offset); + (*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_ivt_offset);/* * ROM bug alert
@@ -516,7 +517,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,* * The remaining fraction of a block bytes would not be loaded! */ - *header_size_ptr =ROUND (sbuf->st_size + imximage_flash_offset,4096 ); + *header_size_ptr =ROUND (sbuf->st_size + imximage_ivt_offset,4096 ); }int imximage_check_params (struct mkimage_params *params)
Signature · 1 line
1.7.9.5
PATCH v3 3/7 tools: dynamically allocate imx_header in imximage
In reply to Stefano BabicChange to dynamically allocate the imx_header to correctly allocate the IVT, Boot Data and DCD at correct locations depending on the boot media.
Also check that the Image Vector Table Offset + IVT + Boot Data + DCD <= Initial Load Region Size.
Previously struct imx_header was always 4096 bytes and was not dealing correctly with the Image Vector Table Offset.
Now, the memory allocation looks for e.g. SD boot like this
Storage u-boot.imx RAM
Device
00000000 177ff000 <--------------
| 00000400 00000000 d1 00 20 40 IVT.header 177ff400 <------- | 00000404 00000004 00 00 80 17 IVT.entry 177ff404 ----------- | 00000408 00000008 00 00 00 00 IVT.reserved1 177ff408 | | | 0000040C 0000000C 2c f4 7f 17 IVT.dcd 177ff40C ------ | | | 00000410 00000010 20 f4 7f 17 IVT.boot 177ff410 ---- | | | | 00000414 00000014 00 f4 7f 17 IVT.self 177ff414 -------- | | 00000418 00000018 00 00 00 00 IVT.csf 177ff418 | | | | 0000041C 0000001C 00 00 00 00 IVT.reserved2 177ff41C | | | | 00000420 00000020 00 f0 7f 17 BootData.start 177ff420 <--- | | --- 00000424 00000024 00 60 03 00 BootData.length 177ff424 | | 00000428 00000028 00 00 00 00 BootData.plugin 177ff428 | | 0000042C 0000002C d2 03 30 40 DCD.header 177ff42C <----- | ... |
00001000 00000c00 13 00 00 ea U-Boot Start 17800000 <----------
While at it also remove the unused #define HEADER_OFFSET.
---
Changes in v3: None
Changes in v2:
- drop dead code (Marek Vasut)
tools/imximage.c | 43 ++++++++++++++++++++++++++++++++++++------- tools/imximage.h | 16 +++++++++++++--- 2 files changed, 49 insertions(+), 10 deletions(-)
tools/imximage.c +36 -7
@@ -31,7 +31,7 @@ static table_entry_t imximage_cmds[] = {* Supported Boot options for configuration file * this is needed to set the correct flash offset */ -static table_entry_t imximage_bootops[] = { +static table_entry_t imximage_boot_offset[] = { {FLASH_OFFSET_ONENAND ,"onenand" ,"OneNAND Flash" ,}, {FLASH_OFFSET_NAND ,"nand" ,"NAND Flash" , }, {FLASH_OFFSET_NOR ,"nor" ,"NOR Flash" , },
@@ -42,6 +42,20 @@ static table_entry_t imximage_bootops[] = { };/* +* Supported Boot options for configuration file +* this is needed to determine the initial load size +*/ +static table_entry_t imximage_boot_loadsize[] = { + {FLASH_LOADSIZE_ONENAND ,"onenand" ,"OneNAND Flash" ,}, + {FLASH_LOADSIZE_NAND ,"nand" ,"NAND Flash" , }, + {FLASH_LOADSIZE_NOR ,"nor" ,"NOR Flash" , }, + {FLASH_LOADSIZE_SATA ,"sata" ,"SATA Disk" , }, + {FLASH_LOADSIZE_SD ,"sd" ,"SD Card" , }, + {FLASH_LOADSIZE_SPI ,"spi" ,"SPI Flash" , }, + {-1 ,"" ,"Invalid" , }, +}; + +/* * IMXIMAGE version definition for i.MX chips */ static table_entry_t imximage_versions[] = {
@@ -54,6 +68,8 @@ static struct imx_header imximage_header;static uint32_t imximage_version;/* Image Vector Table Offset */ static uint32_t imximage_ivt_offset; +/* Initial Load Region Size */ +static uint32_t imximage_init_loadsize;static set_dcd_val_t set_dcd_val;static set_dcd_rst_t set_dcd_rst;
@@ -195,7 +211,8 @@ 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 ); +/* TODO: check i.MX image V1 handling, for now use 'old' style */ + hdr_base = entry_point -4096 ; fhdr_v1->app_dest_ptr = hdr_base - flash_offset; fhdr_v1->app_code_jump_vector = entry_point;
@@ -222,12 +239,13 @@ 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 ); - + hdr_base = entry_point - imximage_init_loadsize + + flash_offset; + fhdr_v2->self = hdr_base; fhdr_v2->dcd_ptr = hdr_base + offsetof(imx_header_v2_t , dcd_table); fhdr_v2->boot_data_ptr = hdr_base + offsetof(imx_header_v2_t , boot_data); - hdr_v2->boot_data.start = hdr_base - flash_offset; + hdr_v2->boot_data.start = entry_point - imximage_init_loadsize;/* Security feature are not supported */ fhdr_v2->csf =0 ;
@@ -329,13 +347,24 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,set_hdr_func (imxhdr);break ;case CMD_BOOT_FROM : - imximage_ivt_offset =get_table_entry_id (imximage_bootops, + imximage_ivt_offset =get_table_entry_id (imximage_boot_offset,"imximage boot option" , token);if (imximage_ivt_offset ==-1 ) {fprintf (stderr,"Error: %s[%d] -Invalid boot device" "(%s)\n" , name, lineno, token);exit (EXIT_FAILURE ); } + + imximage_init_loadsize = +get_table_entry_id (imximage_boot_loadsize, +"imximage boot option" , token); + +if (imximage_init_loadsize ==-1 ) { +fprintf (stderr, +"Error: %s[%d] -Invalid boot device(%s)\n" , + name, lineno, token); +exit (EXIT_FAILURE ); + }if (unlikely (cmd_ver_first !=1 )) cmd_ver_first =0 ;break ;
@@ -517,7 +546,7 @@ static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,* * The remaining fraction of a block bytes would not be loaded! */ - *header_size_ptr =ROUND (sbuf->st_size + imximage_ivt_offset,4096 ); + *header_size_ptr =ROUND (sbuf->st_size,4096 ); }int imximage_check_params (struct mkimage_params *params)
tools/imximage.h +13 -3
@@ -13,14 +13,14 @@#define APP_CODE_BARKER 0xB1#define DCD_BARKER 0xB17219E9 -#define HEADER_OFFSET 0x400 -/* * NOTE: This file must be kept in sync with arch/arm/include/asm/\ * imx-common/imximage.cfg because tools/imximage.c can not * cross-include headers from arch/arm/ and vice-versa. */ #define CMD_DATA_STR "DATA" + +/* Initial Vector Table Offset */ #define FLASH_OFFSET_UNDEFINED 0xFFFFFFFF#define FLASH_OFFSET_STANDARD 0x400#define FLASH_OFFSET_NAND FLASH_OFFSET_STANDARD
@@ -30,6 +30,16 @@#define FLASH_OFFSET_NOR 0x1000#define FLASH_OFFSET_SATA FLASH_OFFSET_STANDARD +/* Initial Load Region Size */ +#define FLASH_LOADSIZE_UNDEFINED 0xFFFFFFFF +#define FLASH_LOADSIZE_STANDARD 0x1000 +#define FLASH_LOADSIZE_NAND FLASH_LOADSIZE_STANDARD +#define FLASH_LOADSIZE_SD FLASH_LOADSIZE_STANDARD +#define FLASH_LOADSIZE_SPI FLASH_LOADSIZE_STANDARD +#define FLASH_LOADSIZE_ONENAND 0x400 +#define FLASH_LOADSIZE_NOR 0x0/* entire image */ +#define FLASH_LOADSIZE_SATA FLASH_LOADSIZE_STANDARD +#define IVT_HEADER_TAG 0xD1#define IVT_VERSION 0x40#define DCD_HEADER_TAG 0xD2
@@ -147,7 +157,7 @@ struct imx_header {imx_header_v1_t hdr_v1;imx_header_v2_t hdr_v2; } header; -} __attribute__((aligned(4096))); +}; typedef void (*set_dcd_val_t)(struct imx_header *imxhdr, char *name, int lineno,
Signature · 1 line
1.7.9.5
PATCH v3 4/7 tools: add variable padding of data image in mkimage
In reply to Stefano BabicUse previously unused return value of function vrec_header to return a padding size to generic mkimage. This padding size is used in copy_files to pad with zeros after copying the data image.
---
Changes in v3: None
Changes in v2: None
tools/mkimage.c | 24 +++++++++++++++++++++--- tools/mkimage.h | 5 ++++- 2 files changed, 25 insertions(+), 4 deletions(-)
tools/mkimage.c +21 -3
@@ -137,6 +137,7 @@ main (int argc, char **argv)char *ptr;int retval =0 ;struct image_type_params *tparams =NULL ; +int pad_len =0 ;/* Init Freescale PBL Boot image generation/list support */ init_pbl_image_type ();
@@ -391,7 +392,7 @@ NXTARG: ;* allocate memory for the header itself. */ if (tparams->vrec_header) - tparams->vrec_header (¶ms, tparams); + pad_len = tparams->vrec_header (¶ms, tparams);else memset (tparams->hdr,0 , tparams->header_size);
@@ -463,7 +464,7 @@ NXTARG: ;/* PBL has special Image format, implements its' own */ pbl_load_uboot (ifd, ¶ms); }else { -copy_file (ifd, params.datafile,0 ); +copy_file (ifd, params.datafile, pad_len); } }
@@ -537,10 +538,19 @@ copy_file (int ifd, const char *datafile, int pad)unsigned char *ptr;int tail;int zero =0 ; +uint8_t zeros[4096 ];int offset =0 ;int size;struct image_type_params *tparams =mkimage_get_type (params.type); +if (pad >=sizeof (zeros)) { +fprintf (stderr,"%s: Can't pad to %d\n" , + params.cmdname, pad); +exit (EXIT_FAILURE ); + } + +memset (zeros,0 ,sizeof (zeros)); +if (params.vflag) {fprintf (stderr,"Adding Image %s\n" , datafile); }
@@ -598,7 +608,8 @@ copy_file (int ifd, const char *datafile, int pad)exit (EXIT_FAILURE ); } -if (pad && ((tail = size %4 ) !=0 )) { + tail = size %4 ; +if ((pad ==1 ) && (tail !=0 )) {if (write (ifd, (char *)&zero,4 -tail) !=4 -tail) { fprintf (stderr, "%s: Write error on %s: %s\n",
@@ -606,6 +617,13 @@ copy_file (int ifd, const char *datafile, int pad) strerror(errno));exit (EXIT_FAILURE ); } + }else if (pad >1 ) { +if (write (ifd, (char *)&zeros, pad) != pad) { +fprintf (stderr,"%s: Write error on %s: %s\n" , + params.cmdname, params.imagefile, +strerror (errno)); +exit (EXIT_FAILURE ); + } } (void )munmap ((void *)ptr, sbuf.st_size);
tools/mkimage.h +4 -1
@@ -132,7 +132,10 @@ struct image_type_params {/* * This callback function will be executed for variable size record * It is expected to build this header in memory and return its length -* and a pointer to it +* and a pointer to it by using image_type_params.header_size and +* image_type_params.hdr. The return value shall indicate if an +* additional padding should be used when copying the data image +* by returning the padding length. */ int (*vrec_header) (struct mkimage_params *,struct image_type_params *);
Signature · 1 line
1.7.9.5
PATCH v3 5/7 tools: add padding of data image file for imximage
In reply to Stefano BabicImplement function vrec_header to be able to pad the final data image file according the what has been calculated for boot_data.length.
---
Changes in v3:
- uses stat instead of open / fstat / close (Marek Vasut)
Changes in v2: None
tools/imximage.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-)
tools/imximage.c +72 -2
@@ -571,18 +571,88 @@ int imximage_check_params(struct mkimage_params *params) (params->xflag) || !(strlen (params->imagename)); } +static int imximage_generate (struct mkimage_params *params, +struct image_type_params *tparams) +{ +struct imx_header *imxhdr; +size_t alloc_len; +int dfd; +struct stat sbuf; +char *datafile = params->datafile; +uint32_t pad_len; + +memset (&imximage_header,0 ,sizeof (imximage_header)); + +/* +* In order to not change the old imx cfg file +* by adding VERSION command into it, here need +* 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 */ + imximage_ivt_offset =FLASH_OFFSET_UNDEFINED ; + imximage_csf_size =0 ; +set_hdr_func (imxhdr); + +/* 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 + alloc_len = imximage_init_loadsize - imximage_ivt_offset; + +if (alloc_len <sizeof (struct imx_header )) { +fprintf (stderr,"%s: header error\n" , + params->cmdname); +exit (EXIT_FAILURE ); + } + + imxhdr =malloc (alloc_len); + +if (!imxhdr) { +fprintf (stderr,"%s: malloc return failure: %s\n" , + params->cmdname,strerror (errno)); +exit (EXIT_FAILURE ); + } + +memset (imxhdr,0 , alloc_len); + + tparams->header_size = alloc_len; + tparams->hdr = imxhdr; + +/* determine data image file length */ + +if (stat (datafile, &sbuf) <0 ) { +fprintf (stderr,"%s: Can't stat %s: %s\n" , + params->cmdname, datafile,strerror (errno)); +exit (EXIT_FAILURE ); + } + + 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; +} + +/* * imximage parameters */ static struct image_type_params imximage_params = { .name ="Freescale i.MX Boot Image support" , - .header_size =sizeof (struct imx_header ), - .hdr = (void *)&imximage_header, + .header_size =0 , + .hdr =NULL , .check_image_type = imximage_check_image_types, .verify_header = imximage_verify_header, .print_header = imximage_print_header, .set_header = imximage_set_header, .check_params = imximage_check_params, + .vrec_header = imximage_generate, };void init_imx_image_type (void )
Signature · 1 line
1.7.9.5
PATCH v4 5/7 tools: add padding of data image file for imximage
Implement function vrec_header to be able to pad the final data image file according the what has been calculated for boot_data.length.
---
Changes in v4:
- fix crash when imximage_init_loadsize is not set
Found during regression tests with boards ima3-mx53 and m53evk (Stefano Babic)
Changes in v3:
- uses stat instead of open / fstat / close (Marek Vasut)
Changes in v2: None
tools/imximage.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 3 deletions(-)
tools/imximage.c +85 -3
@@ -365,6 +365,13 @@ static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token, name, lineno, token);exit (EXIT_FAILURE ); } + +/* +* The SOC loads from the storage starting at address 0 +* then ensures that the load size contains the offset +*/ +if (imximage_init_loadsize < imximage_ivt_offset) + imximage_init_loadsize = imximage_ivt_offset;if (unlikely (cmd_ver_first !=1 )) cmd_ver_first =0 ;break ;
@@ -439,7 +446,8 @@ static uint32_t parse_cfg_file(struct imx_header *imxhdr, char *name)exit (EXIT_FAILURE ); } -/* Very simple parsing, line starting with # are comments +/* +* Very simple parsing, line starting with # are comments * and are dropped */ while ((getline (&line, &len, fd)) >0 ) {
@@ -571,18 +579,92 @@ int imximage_check_params(struct mkimage_params *params) (params->xflag) || !(strlen (params->imagename)); } +static int imximage_generate (struct mkimage_params *params, +struct image_type_params *tparams) +{ +struct imx_header *imxhdr; +size_t alloc_len; +struct stat sbuf; +char *datafile = params->datafile; +uint32_t pad_len; + +memset (&imximage_header,0 ,sizeof (imximage_header)); + +/* +* In order to not change the old imx cfg file +* by adding VERSION command into it, here need +* 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 */ + imximage_ivt_offset =FLASH_OFFSET_UNDEFINED ; + imximage_csf_size =0 ; +set_hdr_func (imxhdr); + +/* 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 (alloc_len <sizeof (struct imx_header )) { +fprintf (stderr,"%s: header error\n" , + params->cmdname); +exit (EXIT_FAILURE ); + } + + imxhdr =malloc (alloc_len); + +if (!imxhdr) { +fprintf (stderr,"%s: malloc return failure: %s\n" , + params->cmdname,strerror (errno)); +exit (EXIT_FAILURE ); + } + +memset (imxhdr,0 , alloc_len); + + tparams->header_size = alloc_len; + tparams->hdr = imxhdr; + +/* determine data image file length */ + +if (stat (datafile, &sbuf) <0 ) { +fprintf (stderr,"%s: Can't stat %s: %s\n" , + params->cmdname, datafile,strerror (errno)); +exit (EXIT_FAILURE ); + } + + 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; +} + +/* * imximage parameters */ static struct image_type_params imximage_params = { .name ="Freescale i.MX Boot Image support" , - .header_size =sizeof (struct imx_header ), - .hdr = (void *)&imximage_header, + .header_size =0 , + .hdr =NULL , .check_image_type = imximage_check_image_types, .verify_header = imximage_verify_header, .print_header = imximage_print_header, .set_header = imximage_set_header, .check_params = imximage_check_params, + .vrec_header = imximage_generate, };void init_imx_image_type (void )
Signature · 1 line
1.7.9.5
PATCH v4 5/7 tools: add padding of data image file for imximage
Quoted 19 lines · Stefano Babic
Implement function
vrec_headerto be able to pad the final data image file according the what has been calculated for boot_data.length.Signed-off-by Stefano Babic <[email protected]>---
Changes in v4:
- fix crash whenimximage_init_loadsizeis not set
Found during regression tests with boards ima3-mx53 and m53evk (Stefano Babic)Changes in v3:
- uses stat instead of open / fstat / close (Marek Vasut)Changes in v2: None
tools/imximage.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 3 deletions(-)
<snip>
Quoted 11 lines
tools/imximage.c +11
-0+static int imximage_generate (struct mkimage_params *params, +struct image_type_params *tparams) +{ +struct imx_header *imxhdr; +size_t alloc_len; +struct stat sbuf; +char *datafile = params->datafile; +uint32_t pad_len; + +memset (&imximage_header,0 ,sizeof (imximage_header)); +
tools/imximage.c int imximage_check_params(struct mkimage_params *params) · line 602
Quoted 10 lines
tools/imximage.c +10
-0+/* +* In order to not change the old imx cfg file +* by adding VERSION command into it, here need +* 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 */ + imximage_ivt_offset =FLASH_OFFSET_UNDEFINED ; + imximage_csf_size =0 ; +set_hdr_func (imxhdr);
Doesn't this line has compiling warning for you?
imximage.c: In function ?imximage_generate?:
imximage.c:634: warning: ?imxhdr? is used uninitialized in this function
York
PATCH v4 5/7 tools: add padding of data image file for imximage
Hi York,
Quoted 24 lines · York Sun
Quoted 11 lines
tools/imximage.c +11
-0+static int imximage_generate (struct mkimage_params *params, +struct image_type_params *tparams) +{ +struct imx_header *imxhdr; +size_t alloc_len; +struct stat sbuf; +char *datafile = params->datafile; +uint32_t pad_len; + +memset (&imximage_header,0 ,sizeof (imximage_header)); +tools/imximage.c int imximage_check_params(struct mkimage_params *params) · line 602
Quoted 10 lines
tools/imximage.c +10
-0+/* +* In order to not change the old imx cfg file +* by adding VERSION command into it, here need +* 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 */ + imximage_ivt_offset =FLASH_OFFSET_UNDEFINED ; + imximage_csf_size =0 ; +set_hdr_func (imxhdr);Doesn't this line has compiling warning for you?
Quoted 2 lines
imximage.c: In function ?imximage_generate?:
imximage.c:634: warning: ?imxhdr? is used uninitialized in this function
I see the issue, but I hadn't warnings, gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5). Which gcc version do you have ?
Anyway, set_hdr_func() does not use parameters anymore. It can be converted to set_hdr_func(void) and we get rid of warnings.
Stefano
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH v4 5/7 tools: add padding of data image file for imximage
Quoted 28 lines · Stefano Babic
Hi York,
Quoted 24 lines · York Sun
Quoted 11 lines
tools/imximage.c +11
-0+static int imximage_generate (struct mkimage_params *params, +struct image_type_params *tparams) +{ +struct imx_header *imxhdr; +size_t alloc_len; +struct stat sbuf; +char *datafile = params->datafile; +uint32_t pad_len; + +memset (&imximage_header,0 ,sizeof (imximage_header)); +tools/imximage.c int imximage_check_params(struct mkimage_params *params) · line 602
Quoted 10 lines
tools/imximage.c +10
-0+/* +* In order to not change the old imx cfg file +* by adding VERSION command into it, here need +* 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 */ + imximage_ivt_offset =FLASH_OFFSET_UNDEFINED ; + imximage_csf_size =0 ; +set_hdr_func (imxhdr);Doesn't this line has compiling warning for you?
Quoted 9 lines
Quoted 2 lines
imximage.c: In function ?imximage_generate?:
imximage.c:634: warning: ?imxhdr? is used uninitialized in this functionI see the issue, but I hadn't warnings, gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5). Which gcc version do you have ?
Anyway,
set_hdr_func()does not use parameters anymore. It can be converted toset_hdr_func(void)and we get rid of warnings.
I have gcc version 4.6.2 and 4.7.2.
York
PATCH v3 6/7 tools: add support for setting the CSF into imximage
In reply to Stefano BabicAdd support for setting the CSF (Command Sequence File) pointer which is used for HAB (High Assurance Boot) in the imximage by adding e.g.
CSF 0x2000
in the imximage.cfg file.
This will set the CSF pointer accordingly just after the padded data image area. The boot_data.length is adjusted with the value from the imximage.cfg config file.
The resulting u-boot.imx can be signed with the FSL HAB tooling. The generated CSF block needs to be appended to the u-boot.imx.
---
Changes in v3:
- add info in the README where to find description of signing process in the Freescale Website (Otavio Salvador)
Changes in v2:
- checkpatch warning
- do not output HAB values when csf values are not defined by cfg
doc/README.imximage | 30 +++++++++++++++++++++++++++--- doc/README.mxc_hab | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/imximage.c | 41 ++++++++++++++++++++++++++++++++++++++--- tools/imximage.h | 3 ++- 4 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 doc/README.mxc_hab
doc/README.imximage +27 -3
@@ -15,9 +15,6 @@ Booting from NOR flash does not require to use this image type. For more details refer Chapter 2 - System Boot and section 2.14 (flash header description) of the processor's manual. -This implementation does not use at the moment the secure boot feature -of the processor. The image is generated disabling all security fields. - Command syntax: -------------- ./tools/mkimage -l <mx u-boot_file>
@@ -86,6 +83,33 @@ Configuration command line syntax: Example: BOOT_FROM spi + CSF value + + Total size of CSF (Command Sequence File) + used for Secure Boot/ High Assurance Boot + (HAB). + + Using this command will populate the IVT + (Initial Vector Table) CSF pointer and adjust + the length fields only. The CSF itself needs + to be generated with Freescale tools and + 'manually' appended to the u-boot.imx file. + + The CSF is then simply concatenated + to the u-boot image, making a signed bootloader, + that the processor can verify + if the fuses for the keys are burned. + + Further infos how to configure the SOC to verify + the bootloader can be found in the "High + Assurance Boot Version Application Programming + Interface Reference Manual" as part of the + Freescale Code Signing Tool, available on the + manufacturer's website. + + Example: + CSF 0x2000 + DATA type address value type: word=4, halfword=2, byte=1
doc/README.mxc_hab new file +48 -0
48 lines not on this page · raw message
tools/imximage.c +38 -3
97 lines not on this page · raw message
tools/imximage.h +2 -1
@@ -52,7 +52,8 @@ enum imximage_cmd {CMD_IMAGE_VERSION ,CMD_BOOT_FROM ,CMD_BOOT_OFFSET , -CMD_DATA +CMD_DATA , + CMD_CSF, }; enum imximage_fld_types {
Signature · 1 line
1.7.9.5
PATCH v3 7/7 imx: add status reporting for HAB status
In reply to Stefano BabicAdd functions to report the HAB (High Assurance Boot) status of e.g. i.MX6 CPUs.
This is taken from
git://git.freescale.com/imx/uboot-imx.git branch imx_v2009.08_3.0.35_4.0.0 cpu/arm_cortexa8/mx6/generic.c include/asm-arm/arch-mx6/mx6_secure.h
---
Changes in v3: None
Changes in v2:
- Fix errors when SECURE_BOOT is selected due to enum
- simplify display_event code (Marek Vasut)
- compile hab code only if SECURE_BOOT is set (Fabio Estevam)
- update licence with SPDX line according to new rules.
arch/arm/cpu/armv7/mx6/Makefile | 7 +- arch/arm/cpu/armv7/mx6/hab.c | 104 ++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/hab.h | 67 +++++++++++++++++++ arch/arm/include/asm/arch-mx6/imx-regs.h | 8 ++- 4 files changed, 182 insertions(+), 4 deletions(-) create mode 100644 arch/arm/cpu/armv7/mx6/hab.c create mode 100644 arch/arm/include/asm/arch-mx6/hab.h
arch/arm/cpu/armv7/mx6/Makefile +4 -3
@@ -11,10 +11,11 @@ include $(TOPDIR)/config.mk LIB = $(obj)lib$(SOC).o -COBJS = soc.o clock.o +COBJS-y = soc.o clock.o +COBJS-$(CONFIG_SECURE_BOOT) += hab.o -SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS)) +SRCS := $(SOBJS:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS-y)) all: $(obj).depend $(LIB)
arch/arm/cpu/armv7/mx6/hab.c new file +104 -0
104 lines not on this page · raw message
arch/arm/include/asm/arch-mx6/hab.h new file +67 -0
67 lines not on this page · raw message
arch/arm/include/asm/arch-mx6/imx-regs.h +7 -1
@@ -456,7 +456,13 @@ struct fuse_bank0_regs {u32 uid_low;u32 rsvd1[3 ];u32 uid_high; -u32 rsvd2[0x17 ]; +u32 rsvd2[3 ]; +u32 rsvd3[4 ]; +u32 rsvd4[4 ]; +u32 rsvd5[4 ]; +u32 cfg5; +u32 rsvd6[3 ]; +u32 rsvd7[4 ]; };struct fuse_bank4_regs {
Signature · 1 line
1.7.9.5