tools: add support for setting the CSF into imximage
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.
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.
Signed-off-by: Stefano Babic <sbabic@denx.de>
diff --git a/tools/imximage.c b/tools/imximage.c
index 26460bf..3f2dc68 100644
--- a/tools/imximage.c
+++ b/tools/imximage.c
@@ -16,6 +16,8 @@
#include <image.h>
#include "imximage.h"
+#define UNDEFINED 0xFFFFFFFF
+
/*
* Supported commands for configuration file
*/
@@ -23,6 +25,7 @@
{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, "", "", },
};
@@ -66,8 +69,13 @@
static struct imx_header imximage_header;
static uint32_t imximage_version;
-/* Image Vector Table Offset */
-static uint32_t imximage_ivt_offset;
+/*
+ * Image Vector Table Offset
+ * Initialized to a wrong not 4-bytes aligned address to
+ * check if it is was set by the cfg file.
+ */
+static uint32_t imximage_ivt_offset = UNDEFINED;
+static uint32_t imximage_csf_size = UNDEFINED;
/* Initial Load Region Size */
static uint32_t imximage_init_loadsize;
@@ -76,6 +84,7 @@
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)
{
@@ -247,9 +256,10 @@
+ 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)
@@ -326,6 +336,13 @@
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 && (imximage_ivt_offset != UNDEFINED) &&
+ (imximage_csf_size != UNDEFINED)) {
+ 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,
@@ -386,6 +403,17 @@
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 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;
}
}
@@ -537,6 +565,7 @@
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 */
@@ -555,6 +584,12 @@
* 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)
diff --git a/tools/imximage.h b/tools/imximage.h
index bb04a43..efe6a88 100644
--- a/tools/imximage.h
+++ b/tools/imximage.h
@@ -52,7 +52,8 @@
CMD_IMAGE_VERSION,
CMD_BOOT_FROM,
CMD_BOOT_OFFSET,
- CMD_DATA
+ CMD_DATA,
+ CMD_CSF,
};
enum imximage_fld_types {