1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2010-2015 Freescale Semiconductor, Inc.
13 #include <asm/global_data.h>
14 #include <asm/system.h>
15 #include <asm/arch/clock.h>
16 #include <asm/arch/sys_proto.h>
17 #include <asm/mach-imx/hab.h>
18 #include <linux/arm-smccc.h>
20 DECLARE_GLOBAL_DATA_PTR;
22 #define ALIGN_SIZE 0x1000
23 #define MX6DQ_PU_IROM_MMU_EN_VAR 0x009024a8
24 #define MX6DLS_PU_IROM_MMU_EN_VAR 0x00901dd0
25 #define MX6SL_PU_IROM_MMU_EN_VAR 0x00901c60
26 #define IS_HAB_ENABLED_BIT \
27 (is_soc_type(MXC_SOC_MX7ULP) ? 0x80000000 : \
28 ((is_soc_type(MXC_SOC_MX7) || is_soc_type(MXC_SOC_IMX8M)) ? 0x2000000 : 0x2))
31 #define HAB_M4_PERSISTENT_START ((soc_rev() >= CHIP_REV_2_0) ? 0x20008040 : \
33 #define HAB_M4_PERSISTENT_BYTES 0xB80
36 static int ivt_header_error(const char *err_str, struct ivt_header *ivt_hdr)
38 printf("%s magic=0x%x length=0x%02x version=0x%x\n", err_str,
39 ivt_hdr->magic, ivt_hdr->length, ivt_hdr->version);
44 static int verify_ivt_header(struct ivt_header *ivt_hdr)
48 if (ivt_hdr->magic != IVT_HEADER_MAGIC)
49 result = ivt_header_error("bad magic", ivt_hdr);
51 if (be16_to_cpu(ivt_hdr->length) != IVT_TOTAL_LENGTH)
52 result = ivt_header_error("bad length", ivt_hdr);
54 if ((ivt_hdr->version & HAB_MAJ_MASK) != HAB_MAJ_VER)
55 result = ivt_header_error("bad version", ivt_hdr);
61 #define FSL_SIP_HAB 0xC2000007
62 #define FSL_SIP_HAB_AUTHENTICATE 0x00
63 #define FSL_SIP_HAB_ENTRY 0x01
64 #define FSL_SIP_HAB_EXIT 0x02
65 #define FSL_SIP_HAB_REPORT_EVENT 0x03
66 #define FSL_SIP_HAB_REPORT_STATUS 0x04
67 #define FSL_SIP_HAB_FAILSAFE 0x05
68 #define FSL_SIP_HAB_CHECK_TARGET 0x06
69 static volatile gd_t *gd_save;
72 static inline void save_gd(void)
79 static inline void restore_gd(void)
83 * Make will already error that reserving x18 is not supported at the
84 * time of writing, clang: error: unknown argument: '-ffixed-x18'
86 __asm__ volatile("mov x18, %0\n" : : "r" (gd_save));
90 enum hab_status hab_rvt_report_event(enum hab_status status, u32 index,
91 u8 *event, size_t *bytes)
94 hab_rvt_report_event_t *hab_rvt_report_event_func;
95 struct arm_smccc_res res __maybe_unused;
97 hab_rvt_report_event_func = (hab_rvt_report_event_t *)HAB_RVT_REPORT_EVENT;
98 #if defined(CONFIG_ARM64)
99 if (current_el() != 3) {
101 arm_smccc_smc(FSL_SIP_HAB, FSL_SIP_HAB_REPORT_EVENT, (unsigned long)index,
102 (unsigned long)event, (unsigned long)bytes, 0, 0, 0, &res);
103 return (enum hab_status)res.a0;
108 ret = hab_rvt_report_event_func(status, index, event, bytes);
115 enum hab_status hab_rvt_report_status(enum hab_config *config, enum hab_state *state)
118 hab_rvt_report_status_t *hab_rvt_report_status_func;
119 struct arm_smccc_res res __maybe_unused;
121 hab_rvt_report_status_func = (hab_rvt_report_status_t *)HAB_RVT_REPORT_STATUS;
122 #if defined(CONFIG_ARM64)
123 if (current_el() != 3) {
125 arm_smccc_smc(FSL_SIP_HAB, FSL_SIP_HAB_REPORT_STATUS, (unsigned long)config,
126 (unsigned long)state, 0, 0, 0, 0, &res);
127 return (enum hab_status)res.a0;
132 ret = hab_rvt_report_status_func(config, state);
138 enum hab_status hab_rvt_entry(void)
141 hab_rvt_entry_t *hab_rvt_entry_func;
142 struct arm_smccc_res res __maybe_unused;
144 hab_rvt_entry_func = (hab_rvt_entry_t *)HAB_RVT_ENTRY;
145 #if defined(CONFIG_ARM64)
146 if (current_el() != 3) {
148 arm_smccc_smc(FSL_SIP_HAB, FSL_SIP_HAB_ENTRY, 0, 0, 0, 0, 0, 0, &res);
149 return (enum hab_status)res.a0;
154 ret = hab_rvt_entry_func();
160 enum hab_status hab_rvt_exit(void)
163 hab_rvt_exit_t *hab_rvt_exit_func;
164 struct arm_smccc_res res __maybe_unused;
166 hab_rvt_exit_func = (hab_rvt_exit_t *)HAB_RVT_EXIT;
167 #if defined(CONFIG_ARM64)
168 if (current_el() != 3) {
170 arm_smccc_smc(FSL_SIP_HAB, FSL_SIP_HAB_EXIT, 0, 0, 0, 0, 0, 0, &res);
171 return (enum hab_status)res.a0;
176 ret = hab_rvt_exit_func();
182 void hab_rvt_failsafe(void)
184 hab_rvt_failsafe_t *hab_rvt_failsafe_func;
186 hab_rvt_failsafe_func = (hab_rvt_failsafe_t *)HAB_RVT_FAILSAFE;
187 #if defined(CONFIG_ARM64)
188 if (current_el() != 3) {
190 arm_smccc_smc(FSL_SIP_HAB, FSL_SIP_HAB_FAILSAFE, 0, 0, 0, 0, 0, 0, NULL);
196 hab_rvt_failsafe_func();
200 enum hab_status hab_rvt_check_target(enum hab_target type, const void *start,
204 hab_rvt_check_target_t *hab_rvt_check_target_func;
205 struct arm_smccc_res res __maybe_unused;
207 hab_rvt_check_target_func = (hab_rvt_check_target_t *)HAB_RVT_CHECK_TARGET;
208 #if defined(CONFIG_ARM64)
209 if (current_el() != 3) {
211 arm_smccc_smc(FSL_SIP_HAB, FSL_SIP_HAB_CHECK_TARGET, (unsigned long)type,
212 (unsigned long)start, (unsigned long)bytes, 0, 0, 0, &res);
213 return (enum hab_status)res.a0;
218 ret = hab_rvt_check_target_func(type, start, bytes);
224 void *hab_rvt_authenticate_image(uint8_t cid, ptrdiff_t ivt_offset,
225 void **start, size_t *bytes, hab_loader_callback_f_t loader)
228 hab_rvt_authenticate_image_t *hab_rvt_authenticate_image_func;
229 struct arm_smccc_res res __maybe_unused;
231 hab_rvt_authenticate_image_func = (hab_rvt_authenticate_image_t *)HAB_RVT_AUTHENTICATE_IMAGE;
232 #if defined(CONFIG_ARM64)
233 if (current_el() != 3) {
235 arm_smccc_smc(FSL_SIP_HAB, FSL_SIP_HAB_AUTHENTICATE, (unsigned long)ivt_offset,
236 (unsigned long)start, (unsigned long)bytes, 0, 0, 0, &res);
237 return (void *)res.a0;
242 ret = hab_rvt_authenticate_image_func(cid, ivt_offset, start, bytes, loader);
248 #if !defined(CONFIG_SPL_BUILD)
250 #define MAX_RECORD_BYTES (8*1024) /* 4 kbytes */
253 uint8_t tag; /* Tag */
254 uint8_t len[2]; /* Length */
255 uint8_t par; /* Version */
256 uint8_t contents[MAX_RECORD_BYTES];/* Record Data */
260 static char *rsn_str[] = {
261 "RSN = HAB_RSN_ANY (0x00)\n",
262 "RSN = HAB_ENG_FAIL (0x30)\n",
263 "RSN = HAB_INV_ADDRESS (0x22)\n",
264 "RSN = HAB_INV_ASSERTION (0x0C)\n",
265 "RSN = HAB_INV_CALL (0x28)\n",
266 "RSN = HAB_INV_CERTIFICATE (0x21)\n",
267 "RSN = HAB_INV_COMMAND (0x06)\n",
268 "RSN = HAB_INV_CSF (0x11)\n",
269 "RSN = HAB_INV_DCD (0x27)\n",
270 "RSN = HAB_INV_INDEX (0x0F)\n",
271 "RSN = HAB_INV_IVT (0x05)\n",
272 "RSN = HAB_INV_KEY (0x1D)\n",
273 "RSN = HAB_INV_RETURN (0x1E)\n",
274 "RSN = HAB_INV_SIGNATURE (0x18)\n",
275 "RSN = HAB_INV_SIZE (0x17)\n",
276 "RSN = HAB_MEM_FAIL (0x2E)\n",
277 "RSN = HAB_OVR_COUNT (0x2B)\n",
278 "RSN = HAB_OVR_STORAGE (0x2D)\n",
279 "RSN = HAB_UNS_ALGORITHM (0x12)\n",
280 "RSN = HAB_UNS_COMMAND (0x03)\n",
281 "RSN = HAB_UNS_ENGINE (0x0A)\n",
282 "RSN = HAB_UNS_ITEM (0x24)\n",
283 "RSN = HAB_UNS_KEY (0x1B)\n",
284 "RSN = HAB_UNS_PROTOCOL (0x14)\n",
285 "RSN = HAB_UNS_STATE (0x09)\n",
290 static char *sts_str[] = {
291 "STS = HAB_SUCCESS (0xF0)\n",
292 "STS = HAB_FAILURE (0x33)\n",
293 "STS = HAB_WARNING (0x69)\n",
298 static char *eng_str[] = {
299 "ENG = HAB_ENG_ANY (0x00)\n",
300 "ENG = HAB_ENG_SCC (0x03)\n",
301 "ENG = HAB_ENG_RTIC (0x05)\n",
302 "ENG = HAB_ENG_SAHARA (0x06)\n",
303 "ENG = HAB_ENG_CSU (0x0A)\n",
304 "ENG = HAB_ENG_SRTC (0x0C)\n",
305 "ENG = HAB_ENG_DCP (0x1B)\n",
306 "ENG = HAB_ENG_CAAM (0x1D)\n",
307 "ENG = HAB_ENG_SNVS (0x1E)\n",
308 "ENG = HAB_ENG_OCOTP (0x21)\n",
309 "ENG = HAB_ENG_DTCP (0x22)\n",
310 "ENG = HAB_ENG_ROM (0x36)\n",
311 "ENG = HAB_ENG_HDCP (0x24)\n",
312 "ENG = HAB_ENG_RTL (0x77)\n",
313 "ENG = HAB_ENG_SW (0xFF)\n",
318 static char *ctx_str[] = {
319 "CTX = HAB_CTX_ANY(0x00)\n",
320 "CTX = HAB_CTX_FAB (0xFF)\n",
321 "CTX = HAB_CTX_ENTRY (0xE1)\n",
322 "CTX = HAB_CTX_TARGET (0x33)\n",
323 "CTX = HAB_CTX_AUTHENTICATE (0x0A)\n",
324 "CTX = HAB_CTX_DCD (0xDD)\n",
325 "CTX = HAB_CTX_CSF (0xCF)\n",
326 "CTX = HAB_CTX_COMMAND (0xC0)\n",
327 "CTX = HAB_CTX_AUT_DAT (0xDB)\n",
328 "CTX = HAB_CTX_ASSERT (0xA0)\n",
329 "CTX = HAB_CTX_EXIT (0xEE)\n",
334 static uint8_t hab_statuses[5] = {
342 static uint8_t hab_reasons[26] = {
371 static uint8_t hab_contexts[12] = {
376 HAB_CTX_AUTHENTICATE,
386 static uint8_t hab_engines[16] = {
405 static inline uint8_t get_idx(uint8_t *list, uint8_t tgt)
408 uint8_t element = list[idx];
409 while (element != -1) {
412 element = list[++idx];
417 static void process_event_record(uint8_t *event_data, size_t bytes)
419 struct record *rec = (struct record *)event_data;
421 printf("\n\n%s", sts_str[get_idx(hab_statuses, rec->contents[0])]);
422 printf("%s", rsn_str[get_idx(hab_reasons, rec->contents[1])]);
423 printf("%s", ctx_str[get_idx(hab_contexts, rec->contents[2])]);
424 printf("%s", eng_str[get_idx(hab_engines, rec->contents[3])]);
427 static void display_event(uint8_t *event_data, size_t bytes)
431 if (!(event_data && bytes > 0))
434 for (i = 0; i < bytes; i++) {
436 printf("\t0x%02x", event_data[i]);
437 else if ((i % 8) == 0)
438 printf("\n\t0x%02x", event_data[i]);
440 printf(" 0x%02x", event_data[i]);
443 process_event_record(event_data, bytes);
446 static int get_hab_status(void)
448 uint32_t index = 0; /* Loop index */
449 uint8_t event_data[128]; /* Event data buffer */
450 size_t bytes = sizeof(event_data); /* Event size in bytes */
451 enum hab_config config = 0;
452 enum hab_state state = 0;
454 if (imx_hab_is_enabled())
455 puts("\nSecure boot enabled\n");
457 puts("\nSecure boot disabled\n");
459 /* Check HAB status */
460 if (hab_rvt_report_status(&config, &state) != HAB_SUCCESS) {
461 printf("\nHAB Configuration: 0x%02x, HAB State: 0x%02x\n",
464 /* Display HAB events */
465 while (hab_rvt_report_event(HAB_STS_ANY, index, event_data,
466 &bytes) == HAB_SUCCESS) {
468 printf("--------- HAB Event %d -----------------\n",
470 puts("event data:\n");
471 display_event(event_data, bytes);
473 bytes = sizeof(event_data);
477 /* Display message if no HAB events are found */
479 printf("\nHAB Configuration: 0x%02x, HAB State: 0x%02x\n",
481 puts("No HAB Events Found!\n\n");
488 static int get_record_len(struct record *rec)
490 return (size_t)((rec->len[0] << 8) + (rec->len[1]));
493 static int get_hab_status_m4(void)
495 unsigned int index = 0;
496 uint8_t event_data[128];
497 size_t record_len, offset = 0;
498 enum hab_config config = 0;
499 enum hab_state state = 0;
501 if (imx_hab_is_enabled())
502 puts("\nSecure boot enabled\n");
504 puts("\nSecure boot disabled\n");
507 * HAB in both A7 and M4 gather the security state
508 * and configuration of the chip from
511 hab_rvt_report_status(&config, &state);
512 printf("\nHAB Configuration: 0x%02x, HAB State: 0x%02x\n",
515 struct record *rec = (struct record *)(HAB_M4_PERSISTENT_START);
517 record_len = get_record_len(rec);
519 /* Check if HAB persistent memory is valid */
520 if (rec->tag != HAB_TAG_EVT_DEF ||
521 record_len != sizeof(struct evt_def) ||
522 (rec->par & HAB_MAJ_MASK) != HAB_MAJ_VER) {
523 puts("\nERROR: Invalid HAB persistent memory\n");
527 /* Parse events in HAB M4 persistent memory region */
528 while (offset < HAB_M4_PERSISTENT_BYTES) {
529 rec = (struct record *)(HAB_M4_PERSISTENT_START + offset);
531 record_len = get_record_len(rec);
533 if (rec->tag == HAB_TAG_EVT) {
534 memcpy(&event_data, rec, record_len);
536 printf("--------- HAB Event %d -----------------\n",
538 puts("event data:\n");
539 display_event(event_data, record_len);
544 offset += record_len;
546 /* Ensure all records start on a word boundary */
547 if ((offset % 4) != 0)
548 offset = offset + (4 - (offset % 4));
552 puts("No HAB Events Found!\n\n");
558 static int do_hab_status(struct cmd_tbl *cmdtp, int flag, int argc,
567 if (strcmp("m4", argv[1]) == 0)
583 static ulong get_image_ivt_offset(ulong img_addr)
587 buf = map_sysmem(img_addr, 0);
588 switch (genimg_get_format(buf)) {
589 #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
590 case IMAGE_FORMAT_LEGACY:
591 return (image_get_image_size((image_header_t *)img_addr)
592 + 0x1000 - 1) & ~(0x1000 - 1);
595 case IMAGE_FORMAT_FIT:
596 return (fit_get_size(buf) + 0x1000 - 1) & ~(0x1000 - 1);
603 static int do_authenticate_image(struct cmd_tbl *cmdtp, int flag, int argc,
606 ulong addr, length, ivt_offset;
610 return CMD_RET_USAGE;
612 addr = simple_strtoul(argv[1], NULL, 16);
613 length = simple_strtoul(argv[2], NULL, 16);
615 ivt_offset = get_image_ivt_offset(addr);
617 ivt_offset = simple_strtoul(argv[3], NULL, 16);
619 rcode = imx_hab_authenticate_image(addr, length, ivt_offset);
621 rcode = CMD_RET_SUCCESS;
623 rcode = CMD_RET_FAILURE;
628 static int do_hab_failsafe(struct cmd_tbl *cmdtp, int flag, int argc,
641 static int do_hab_version(struct cmd_tbl *cmdtp, int flag, int argc,
644 struct hab_hdr *hdr = (struct hab_hdr *)HAB_RVT_BASE;
646 if (hdr->tag != HAB_TAG_RVT) {
647 printf("Unexpected header tag: %x\n", hdr->tag);
648 return CMD_RET_FAILURE;
651 printf("HAB version: %d.%d\n", hdr->par >> 4, hdr->par & 0xf);
656 static int do_authenticate_image_or_failover(struct cmd_tbl *cmdtp, int flag,
657 int argc, char *const argv[])
659 int ret = CMD_RET_FAILURE;
666 if (!imx_hab_is_enabled()) {
667 printf("error: secure boot disabled\n");
671 if (do_authenticate_image(NULL, flag, argc, argv) != CMD_RET_SUCCESS) {
672 fprintf(stderr, "authentication fail -> %s %s %s %s\n",
673 argv[0], argv[1], argv[2], argv[3]);
674 do_hab_failsafe(0, 0, 1, NULL);
676 ret = CMD_RET_SUCCESS;
683 hab_status, CONFIG_SYS_MAXARGS, 2, do_hab_status,
684 "display HAB status and events",
685 "hab_status - A7 HAB event and status\n"
686 "hab_status m4 - M4 HAB event and status"
690 hab_status, CONFIG_SYS_MAXARGS, 1, do_hab_status,
691 "display HAB status",
697 hab_auth_img, 4, 0, do_authenticate_image,
698 "authenticate image via HAB",
699 "addr length ivt_offset\n"
700 "addr - image hex address\n"
701 "length - image hex length\n"
702 "ivt_offset - hex offset of IVT in the image"
706 hab_failsafe, CONFIG_SYS_MAXARGS, 1, do_hab_failsafe,
707 "run BootROM failsafe routine",
712 hab_auth_img_or_fail, 4, 0,
713 do_authenticate_image_or_failover,
714 "authenticate image via HAB on failure drop to USB BootROM mode",
715 "addr length ivt_offset\n"
716 "addr - image hex address\n"
717 "length - image hex length\n"
718 "ivt_offset - hex offset of IVT in the image"
722 hab_version, 1, 0, do_hab_version,
723 "print HAB major/minor version",
727 #endif /* !defined(CONFIG_SPL_BUILD) */
729 /* Get CSF Header length */
730 static int get_hab_hdr_len(struct hab_hdr *hdr)
732 return (size_t)((hdr->len[0] << 8) + (hdr->len[1]));
735 /* Check whether addr lies between start and
736 * end and is within the length of the image
738 static int chk_bounds(u8 *addr, size_t bytes, u8 *start, u8 *end)
740 size_t csf_size = (size_t)((end + 1) - addr);
742 return (addr && (addr >= start) && (addr <= end) &&
743 (csf_size >= bytes));
746 /* Get Length of each command in CSF */
747 static int get_csf_cmd_hdr_len(u8 *csf_hdr)
749 if (*csf_hdr == HAB_CMD_HDR)
750 return sizeof(struct hab_hdr);
752 return get_hab_hdr_len((struct hab_hdr *)csf_hdr);
755 /* Check if CSF is valid */
756 static bool csf_is_valid(struct ivt *ivt, ulong start_addr, size_t bytes)
758 u8 *start = (u8 *)start_addr;
767 end = start + bytes - 1;
771 /* Verify if CSF pointer content is zero */
773 puts("Error: CSF pointer is NULL\n");
777 csf_hdr = (u8 *)(ulong)ivt->csf;
779 /* Verify if CSF Header exist */
780 if (*csf_hdr != HAB_CMD_HDR) {
781 puts("Error: CSF header command not found\n");
785 csf_hdr_len = get_hab_hdr_len((struct hab_hdr *)csf_hdr);
787 /* Check if the CSF lies within the image bounds */
788 if (!chk_bounds(csf_hdr, csf_hdr_len, start, end)) {
789 puts("Error: CSF lies outside the image bounds\n");
796 cmd = (struct hab_hdr *)&csf_hdr[offset];
799 case (HAB_CMD_WRT_DAT):
800 puts("Error: Deprecated write command found\n");
802 case (HAB_CMD_CHK_DAT):
803 puts("Error: Deprecated check command found\n");
806 if (cmd->par == HAB_PAR_MID) {
807 puts("Error: Deprecated Set MID command found\n");
814 cmd_hdr_len = get_csf_cmd_hdr_len(&csf_hdr[offset]);
816 puts("Error: Invalid command length\n");
819 offset += cmd_hdr_len;
821 } while (offset < csf_hdr_len);
827 * Validate IVT structure of the image being authenticated
829 static int validate_ivt(struct ivt *ivt_initial)
831 struct ivt_header *ivt_hdr = &ivt_initial->hdr;
833 if ((ulong)ivt_initial & 0x3) {
834 puts("Error: Image's start address is not 4 byte aligned\n");
838 /* Check IVT fields before allowing authentication */
839 if ((!verify_ivt_header(ivt_hdr)) && \
840 (ivt_initial->entry != 0x0) && \
841 (ivt_initial->reserved1 == 0x0) && \
842 (ivt_initial->self == \
843 (uint32_t)((ulong)ivt_initial & 0xffffffff)) && \
844 (ivt_initial->csf != 0x0) && \
845 (ivt_initial->reserved2 == 0x0)) {
846 /* Report boot failure if DCD pointer is found in IVT */
847 if (ivt_initial->dcd != 0x0)
848 puts("Error: DCD pointer must be 0\n");
853 puts("Error: Invalid IVT structure\n");
854 debug("\nAllowed IVT structure:\n");
855 debug("IVT HDR = 0x4X2000D1\n");
856 debug("IVT ENTRY = 0xXXXXXXXX\n");
857 debug("IVT RSV1 = 0x0\n");
858 debug("IVT DCD = 0x0\n"); /* Recommended */
859 debug("IVT BOOT_DATA = 0xXXXXXXXX\n"); /* Commonly 0x0 */
860 debug("IVT SELF = 0xXXXXXXXX\n"); /* = ddr_start + ivt_offset */
861 debug("IVT CSF = 0xXXXXXXXX\n");
862 debug("IVT RSV2 = 0x0\n");
864 /* Invalid IVT structure */
868 bool imx_hab_is_enabled(void)
870 struct imx_sec_config_fuse_t *fuse =
871 (struct imx_sec_config_fuse_t *)&imx_sec_config_fuse;
875 ret = fuse_read(fuse->bank, fuse->word, ®);
877 puts("\nSecure boot fuse read error\n");
881 return (reg & IS_HAB_ENABLED_BIT) == IS_HAB_ENABLED_BIT;
884 int imx_hab_authenticate_image(uint32_t ddr_start, uint32_t image_size,
893 enum hab_status status;
895 if (!imx_hab_is_enabled())
896 puts("hab fuse not enabled\n");
898 printf("\nAuthenticate image from DDR location 0x%x...\n",
901 hab_caam_clock_enable(1);
903 /* Calculate IVT address header */
904 ivt_addr = (ulong) (ddr_start + ivt_offset);
905 ivt = (struct ivt *)ivt_addr;
907 /* Verify IVT header bugging out on error */
908 if (!validate_ivt(ivt))
909 goto hab_authentication_exit;
915 if (!csf_is_valid(ivt, start, bytes))
916 goto hab_authentication_exit;
918 if (hab_rvt_entry() != HAB_SUCCESS) {
919 puts("hab entry function fail\n");
920 goto hab_exit_failure_print_status;
923 status = hab_rvt_check_target(HAB_TGT_MEMORY, (void *)(ulong)ddr_start, bytes);
924 if (status != HAB_SUCCESS) {
925 printf("HAB check target 0x%08x-0x%08lx fail\n",
926 ddr_start, ddr_start + (ulong)bytes);
927 goto hab_exit_failure_print_status;
930 printf("\nivt_offset = 0x%x, ivt addr = 0x%lx\n", ivt_offset, ivt_addr);
931 printf("ivt entry = 0x%08x, dcd = 0x%08x, csf = 0x%08x\n", ivt->entry,
933 puts("Dumping IVT\n");
934 print_buffer(ivt_addr, (void *)(ivt_addr), 4, 0x8, 0);
936 puts("Dumping CSF Header\n");
937 print_buffer(ivt->csf, (void *)(ivt->csf), 4, 0x10, 0);
939 #if !defined(CONFIG_SPL_BUILD)
943 puts("\nCalling authenticate_image in ROM\n");
944 printf("\tivt_offset = 0x%x\n", ivt_offset);
945 printf("\tstart = 0x%08lx\n", start);
946 printf("\tbytes = 0x%x\n", bytes);
951 * If the MMU is enabled, we have to notify the ROM
952 * code, or it won't flush the caches when needed.
953 * This is done, by setting the "pu_irom_mmu_enabled"
954 * word to 1. You can find its address by looking in
955 * the ROM map. This is critical for
956 * authenticate_image(). If MMU is enabled, without
957 * setting this bit, authentication will fail and may
960 /* Check MMU enabled */
961 if (is_soc_type(MXC_SOC_MX6) && get_cr() & CR_M) {
964 * This won't work on Rev 1.0.0 of
965 * i.MX6Q/D, since their ROM doesn't
966 * do cache flushes. don't think any
967 * exist, so we ignore them.
970 writel(1, MX6DQ_PU_IROM_MMU_EN_VAR);
971 } else if (is_mx6sdl()) {
972 writel(1, MX6DLS_PU_IROM_MMU_EN_VAR);
973 } else if (is_mx6sl()) {
974 writel(1, MX6SL_PU_IROM_MMU_EN_VAR);
979 load_addr = (ulong)hab_rvt_authenticate_image(
981 ivt_offset, (void **)&start,
982 (size_t *)&bytes, NULL);
983 if (hab_rvt_exit() != HAB_SUCCESS) {
984 puts("hab exit function fail\n");
988 hab_exit_failure_print_status:
989 #if !defined(CONFIG_SPL_BUILD)
993 hab_authentication_exit:
995 if (load_addr != 0 || !imx_hab_is_enabled())
1001 int authenticate_image(u32 ddr_start, u32 raw_image_size)
1006 ivt_offset = (raw_image_size + ALIGN_SIZE - 1) &
1008 bytes = ivt_offset + IVT_SIZE + CSF_PAD_SIZE;
1010 return imx_hab_authenticate_image(ddr_start, bytes, ivt_offset);