hab.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * Copyright (C) 2010-2015 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <config.h>
  8. #include <fuse.h>
  9. #include <asm/io.h>
  10. #include <asm/system.h>
  11. #include <asm/arch/clock.h>
  12. #include <asm/arch/sys_proto.h>
  13. #include <asm/mach-imx/hab.h>
  14. #define ALIGN_SIZE 0x1000
  15. #define MX6DQ_PU_IROM_MMU_EN_VAR 0x009024a8
  16. #define MX6DLS_PU_IROM_MMU_EN_VAR 0x00901dd0
  17. #define MX6SL_PU_IROM_MMU_EN_VAR 0x00900a18
  18. #define IS_HAB_ENABLED_BIT \
  19. (is_soc_type(MXC_SOC_MX7ULP) ? 0x80000000 : \
  20. (is_soc_type(MXC_SOC_MX7) ? 0x2000000 : 0x2))
  21. static int ivt_header_error(const char *err_str, struct ivt_header *ivt_hdr)
  22. {
  23. printf("%s magic=0x%x length=0x%02x version=0x%x\n", err_str,
  24. ivt_hdr->magic, ivt_hdr->length, ivt_hdr->version);
  25. return 1;
  26. }
  27. static int verify_ivt_header(struct ivt_header *ivt_hdr)
  28. {
  29. int result = 0;
  30. if (ivt_hdr->magic != IVT_HEADER_MAGIC)
  31. result = ivt_header_error("bad magic", ivt_hdr);
  32. if (be16_to_cpu(ivt_hdr->length) != IVT_TOTAL_LENGTH)
  33. result = ivt_header_error("bad length", ivt_hdr);
  34. if (ivt_hdr->version != IVT_HEADER_V1 &&
  35. ivt_hdr->version != IVT_HEADER_V2)
  36. result = ivt_header_error("bad version", ivt_hdr);
  37. return result;
  38. }
  39. #if !defined(CONFIG_SPL_BUILD)
  40. #define MAX_RECORD_BYTES (8*1024) /* 4 kbytes */
  41. struct record {
  42. uint8_t tag; /* Tag */
  43. uint8_t len[2]; /* Length */
  44. uint8_t par; /* Version */
  45. uint8_t contents[MAX_RECORD_BYTES];/* Record Data */
  46. bool any_rec_flag;
  47. };
  48. static char *rsn_str[] = {
  49. "RSN = HAB_RSN_ANY (0x00)\n",
  50. "RSN = HAB_ENG_FAIL (0x30)\n",
  51. "RSN = HAB_INV_ADDRESS (0x22)\n",
  52. "RSN = HAB_INV_ASSERTION (0x0C)\n",
  53. "RSN = HAB_INV_CALL (0x28)\n",
  54. "RSN = HAB_INV_CERTIFICATE (0x21)\n",
  55. "RSN = HAB_INV_COMMAND (0x06)\n",
  56. "RSN = HAB_INV_CSF (0x11)\n",
  57. "RSN = HAB_INV_DCD (0x27)\n",
  58. "RSN = HAB_INV_INDEX (0x0F)\n",
  59. "RSN = HAB_INV_IVT (0x05)\n",
  60. "RSN = HAB_INV_KEY (0x1D)\n",
  61. "RSN = HAB_INV_RETURN (0x1E)\n",
  62. "RSN = HAB_INV_SIGNATURE (0x18)\n",
  63. "RSN = HAB_INV_SIZE (0x17)\n",
  64. "RSN = HAB_MEM_FAIL (0x2E)\n",
  65. "RSN = HAB_OVR_COUNT (0x2B)\n",
  66. "RSN = HAB_OVR_STORAGE (0x2D)\n",
  67. "RSN = HAB_UNS_ALGORITHM (0x12)\n",
  68. "RSN = HAB_UNS_COMMAND (0x03)\n",
  69. "RSN = HAB_UNS_ENGINE (0x0A)\n",
  70. "RSN = HAB_UNS_ITEM (0x24)\n",
  71. "RSN = HAB_UNS_KEY (0x1B)\n",
  72. "RSN = HAB_UNS_PROTOCOL (0x14)\n",
  73. "RSN = HAB_UNS_STATE (0x09)\n",
  74. "RSN = INVALID\n",
  75. NULL
  76. };
  77. static char *sts_str[] = {
  78. "STS = HAB_SUCCESS (0xF0)\n",
  79. "STS = HAB_FAILURE (0x33)\n",
  80. "STS = HAB_WARNING (0x69)\n",
  81. "STS = INVALID\n",
  82. NULL
  83. };
  84. static char *eng_str[] = {
  85. "ENG = HAB_ENG_ANY (0x00)\n",
  86. "ENG = HAB_ENG_SCC (0x03)\n",
  87. "ENG = HAB_ENG_RTIC (0x05)\n",
  88. "ENG = HAB_ENG_SAHARA (0x06)\n",
  89. "ENG = HAB_ENG_CSU (0x0A)\n",
  90. "ENG = HAB_ENG_SRTC (0x0C)\n",
  91. "ENG = HAB_ENG_DCP (0x1B)\n",
  92. "ENG = HAB_ENG_CAAM (0x1D)\n",
  93. "ENG = HAB_ENG_SNVS (0x1E)\n",
  94. "ENG = HAB_ENG_OCOTP (0x21)\n",
  95. "ENG = HAB_ENG_DTCP (0x22)\n",
  96. "ENG = HAB_ENG_ROM (0x36)\n",
  97. "ENG = HAB_ENG_HDCP (0x24)\n",
  98. "ENG = HAB_ENG_RTL (0x77)\n",
  99. "ENG = HAB_ENG_SW (0xFF)\n",
  100. "ENG = INVALID\n",
  101. NULL
  102. };
  103. static char *ctx_str[] = {
  104. "CTX = HAB_CTX_ANY(0x00)\n",
  105. "CTX = HAB_CTX_FAB (0xFF)\n",
  106. "CTX = HAB_CTX_ENTRY (0xE1)\n",
  107. "CTX = HAB_CTX_TARGET (0x33)\n",
  108. "CTX = HAB_CTX_AUTHENTICATE (0x0A)\n",
  109. "CTX = HAB_CTX_DCD (0xDD)\n",
  110. "CTX = HAB_CTX_CSF (0xCF)\n",
  111. "CTX = HAB_CTX_COMMAND (0xC0)\n",
  112. "CTX = HAB_CTX_AUT_DAT (0xDB)\n",
  113. "CTX = HAB_CTX_ASSERT (0xA0)\n",
  114. "CTX = HAB_CTX_EXIT (0xEE)\n",
  115. "CTX = INVALID\n",
  116. NULL
  117. };
  118. static uint8_t hab_statuses[5] = {
  119. HAB_STS_ANY,
  120. HAB_FAILURE,
  121. HAB_WARNING,
  122. HAB_SUCCESS,
  123. -1
  124. };
  125. static uint8_t hab_reasons[26] = {
  126. HAB_RSN_ANY,
  127. HAB_ENG_FAIL,
  128. HAB_INV_ADDRESS,
  129. HAB_INV_ASSERTION,
  130. HAB_INV_CALL,
  131. HAB_INV_CERTIFICATE,
  132. HAB_INV_COMMAND,
  133. HAB_INV_CSF,
  134. HAB_INV_DCD,
  135. HAB_INV_INDEX,
  136. HAB_INV_IVT,
  137. HAB_INV_KEY,
  138. HAB_INV_RETURN,
  139. HAB_INV_SIGNATURE,
  140. HAB_INV_SIZE,
  141. HAB_MEM_FAIL,
  142. HAB_OVR_COUNT,
  143. HAB_OVR_STORAGE,
  144. HAB_UNS_ALGORITHM,
  145. HAB_UNS_COMMAND,
  146. HAB_UNS_ENGINE,
  147. HAB_UNS_ITEM,
  148. HAB_UNS_KEY,
  149. HAB_UNS_PROTOCOL,
  150. HAB_UNS_STATE,
  151. -1
  152. };
  153. static uint8_t hab_contexts[12] = {
  154. HAB_CTX_ANY,
  155. HAB_CTX_FAB,
  156. HAB_CTX_ENTRY,
  157. HAB_CTX_TARGET,
  158. HAB_CTX_AUTHENTICATE,
  159. HAB_CTX_DCD,
  160. HAB_CTX_CSF,
  161. HAB_CTX_COMMAND,
  162. HAB_CTX_AUT_DAT,
  163. HAB_CTX_ASSERT,
  164. HAB_CTX_EXIT,
  165. -1
  166. };
  167. static uint8_t hab_engines[16] = {
  168. HAB_ENG_ANY,
  169. HAB_ENG_SCC,
  170. HAB_ENG_RTIC,
  171. HAB_ENG_SAHARA,
  172. HAB_ENG_CSU,
  173. HAB_ENG_SRTC,
  174. HAB_ENG_DCP,
  175. HAB_ENG_CAAM,
  176. HAB_ENG_SNVS,
  177. HAB_ENG_OCOTP,
  178. HAB_ENG_DTCP,
  179. HAB_ENG_ROM,
  180. HAB_ENG_HDCP,
  181. HAB_ENG_RTL,
  182. HAB_ENG_SW,
  183. -1
  184. };
  185. static inline uint8_t get_idx(uint8_t *list, uint8_t tgt)
  186. {
  187. uint8_t idx = 0;
  188. uint8_t element = list[idx];
  189. while (element != -1) {
  190. if (element == tgt)
  191. return idx;
  192. element = list[++idx];
  193. }
  194. return -1;
  195. }
  196. static void process_event_record(uint8_t *event_data, size_t bytes)
  197. {
  198. struct record *rec = (struct record *)event_data;
  199. printf("\n\n%s", sts_str[get_idx(hab_statuses, rec->contents[0])]);
  200. printf("%s", rsn_str[get_idx(hab_reasons, rec->contents[1])]);
  201. printf("%s", ctx_str[get_idx(hab_contexts, rec->contents[2])]);
  202. printf("%s", eng_str[get_idx(hab_engines, rec->contents[3])]);
  203. }
  204. static void display_event(uint8_t *event_data, size_t bytes)
  205. {
  206. uint32_t i;
  207. if (!(event_data && bytes > 0))
  208. return;
  209. for (i = 0; i < bytes; i++) {
  210. if (i == 0)
  211. printf("\t0x%02x", event_data[i]);
  212. else if ((i % 8) == 0)
  213. printf("\n\t0x%02x", event_data[i]);
  214. else
  215. printf(" 0x%02x", event_data[i]);
  216. }
  217. process_event_record(event_data, bytes);
  218. }
  219. static int get_hab_status(void)
  220. {
  221. uint32_t index = 0; /* Loop index */
  222. uint8_t event_data[128]; /* Event data buffer */
  223. size_t bytes = sizeof(event_data); /* Event size in bytes */
  224. enum hab_config config = 0;
  225. enum hab_state state = 0;
  226. hab_rvt_report_event_t *hab_rvt_report_event;
  227. hab_rvt_report_status_t *hab_rvt_report_status;
  228. hab_rvt_report_event = (hab_rvt_report_event_t *)HAB_RVT_REPORT_EVENT;
  229. hab_rvt_report_status =
  230. (hab_rvt_report_status_t *)HAB_RVT_REPORT_STATUS;
  231. if (imx_hab_is_enabled())
  232. puts("\nSecure boot enabled\n");
  233. else
  234. puts("\nSecure boot disabled\n");
  235. /* Check HAB status */
  236. if (hab_rvt_report_status(&config, &state) != HAB_SUCCESS) {
  237. printf("\nHAB Configuration: 0x%02x, HAB State: 0x%02x\n",
  238. config, state);
  239. /* Display HAB Error events */
  240. while (hab_rvt_report_event(HAB_FAILURE, index, event_data,
  241. &bytes) == HAB_SUCCESS) {
  242. puts("\n");
  243. printf("--------- HAB Event %d -----------------\n",
  244. index + 1);
  245. puts("event data:\n");
  246. display_event(event_data, bytes);
  247. puts("\n");
  248. bytes = sizeof(event_data);
  249. index++;
  250. }
  251. }
  252. /* Display message if no HAB events are found */
  253. else {
  254. printf("\nHAB Configuration: 0x%02x, HAB State: 0x%02x\n",
  255. config, state);
  256. puts("No HAB Events Found!\n\n");
  257. }
  258. return 0;
  259. }
  260. static int do_hab_status(cmd_tbl_t *cmdtp, int flag, int argc,
  261. char * const argv[])
  262. {
  263. if ((argc != 1)) {
  264. cmd_usage(cmdtp);
  265. return 1;
  266. }
  267. get_hab_status();
  268. return 0;
  269. }
  270. static int do_authenticate_image(cmd_tbl_t *cmdtp, int flag, int argc,
  271. char * const argv[])
  272. {
  273. ulong addr, length, ivt_offset;
  274. int rcode = 0;
  275. if (argc < 4)
  276. return CMD_RET_USAGE;
  277. addr = simple_strtoul(argv[1], NULL, 16);
  278. length = simple_strtoul(argv[2], NULL, 16);
  279. ivt_offset = simple_strtoul(argv[3], NULL, 16);
  280. rcode = imx_hab_authenticate_image(addr, length, ivt_offset);
  281. if (rcode == 0)
  282. rcode = CMD_RET_SUCCESS;
  283. else
  284. rcode = CMD_RET_FAILURE;
  285. return rcode;
  286. }
  287. static int do_hab_failsafe(cmd_tbl_t *cmdtp, int flag, int argc,
  288. char * const argv[])
  289. {
  290. hab_rvt_failsafe_t *hab_rvt_failsafe;
  291. if (argc != 1) {
  292. cmd_usage(cmdtp);
  293. return 1;
  294. }
  295. hab_rvt_failsafe = (hab_rvt_failsafe_t *)HAB_RVT_FAILSAFE;
  296. hab_rvt_failsafe();
  297. return 0;
  298. }
  299. static int do_authenticate_image_or_failover(cmd_tbl_t *cmdtp, int flag,
  300. int argc, char * const argv[])
  301. {
  302. int ret = CMD_RET_FAILURE;
  303. if (argc != 4) {
  304. ret = CMD_RET_USAGE;
  305. goto error;
  306. }
  307. if (!imx_hab_is_enabled()) {
  308. printf("error: secure boot disabled\n");
  309. goto error;
  310. }
  311. if (do_authenticate_image(NULL, flag, argc, argv) != CMD_RET_SUCCESS) {
  312. fprintf(stderr, "authentication fail -> %s %s %s %s\n",
  313. argv[0], argv[1], argv[2], argv[3]);
  314. do_hab_failsafe(0, 0, 1, NULL);
  315. };
  316. ret = CMD_RET_SUCCESS;
  317. error:
  318. return ret;
  319. }
  320. U_BOOT_CMD(
  321. hab_status, CONFIG_SYS_MAXARGS, 1, do_hab_status,
  322. "display HAB status",
  323. ""
  324. );
  325. U_BOOT_CMD(
  326. hab_auth_img, 4, 0, do_authenticate_image,
  327. "authenticate image via HAB",
  328. "addr length ivt_offset\n"
  329. "addr - image hex address\n"
  330. "length - image hex length\n"
  331. "ivt_offset - hex offset of IVT in the image"
  332. );
  333. U_BOOT_CMD(
  334. hab_failsafe, CONFIG_SYS_MAXARGS, 1, do_hab_failsafe,
  335. "run BootROM failsafe routine",
  336. ""
  337. );
  338. U_BOOT_CMD(
  339. hab_auth_img_or_fail, 4, 0,
  340. do_authenticate_image_or_failover,
  341. "authenticate image via HAB on failure drop to USB BootROM mode",
  342. "addr length ivt_offset\n"
  343. "addr - image hex address\n"
  344. "length - image hex length\n"
  345. "ivt_offset - hex offset of IVT in the image"
  346. );
  347. #endif /* !defined(CONFIG_SPL_BUILD) */
  348. /* Get CSF Header length */
  349. static int get_hab_hdr_len(struct hab_hdr *hdr)
  350. {
  351. return (size_t)((hdr->len[0] << 8) + (hdr->len[1]));
  352. }
  353. /* Check whether addr lies between start and
  354. * end and is within the length of the image
  355. */
  356. static int chk_bounds(u8 *addr, size_t bytes, u8 *start, u8 *end)
  357. {
  358. size_t csf_size = (size_t)((end + 1) - addr);
  359. return (addr && (addr >= start) && (addr <= end) &&
  360. (csf_size >= bytes));
  361. }
  362. /* Get Length of each command in CSF */
  363. static int get_csf_cmd_hdr_len(u8 *csf_hdr)
  364. {
  365. if (*csf_hdr == HAB_CMD_HDR)
  366. return sizeof(struct hab_hdr);
  367. return get_hab_hdr_len((struct hab_hdr *)csf_hdr);
  368. }
  369. /* Check if CSF is valid */
  370. static bool csf_is_valid(struct ivt *ivt, ulong start_addr, size_t bytes)
  371. {
  372. u8 *start = (u8 *)start_addr;
  373. u8 *csf_hdr;
  374. u8 *end;
  375. size_t csf_hdr_len;
  376. size_t cmd_hdr_len;
  377. size_t offset = 0;
  378. if (bytes != 0)
  379. end = start + bytes - 1;
  380. else
  381. end = start;
  382. /* Verify if CSF pointer content is zero */
  383. if (!ivt->csf) {
  384. puts("Error: CSF pointer is NULL\n");
  385. return false;
  386. }
  387. csf_hdr = (u8 *)ivt->csf;
  388. /* Verify if CSF Header exist */
  389. if (*csf_hdr != HAB_CMD_HDR) {
  390. puts("Error: CSF header command not found\n");
  391. return false;
  392. }
  393. csf_hdr_len = get_hab_hdr_len((struct hab_hdr *)csf_hdr);
  394. /* Check if the CSF lies within the image bounds */
  395. if (!chk_bounds(csf_hdr, csf_hdr_len, start, end)) {
  396. puts("Error: CSF lies outside the image bounds\n");
  397. return false;
  398. }
  399. do {
  400. struct hab_hdr *cmd;
  401. cmd = (struct hab_hdr *)&csf_hdr[offset];
  402. switch (cmd->tag) {
  403. case (HAB_CMD_WRT_DAT):
  404. puts("Error: Deprecated write command found\n");
  405. return false;
  406. case (HAB_CMD_CHK_DAT):
  407. puts("Error: Deprecated check command found\n");
  408. return false;
  409. case (HAB_CMD_SET):
  410. if (cmd->par == HAB_PAR_MID) {
  411. puts("Error: Deprecated Set MID command found\n");
  412. return false;
  413. }
  414. default:
  415. break;
  416. }
  417. cmd_hdr_len = get_csf_cmd_hdr_len(&csf_hdr[offset]);
  418. if (!cmd_hdr_len) {
  419. puts("Error: Invalid command length\n");
  420. return false;
  421. }
  422. offset += cmd_hdr_len;
  423. } while (offset < csf_hdr_len);
  424. return true;
  425. }
  426. bool imx_hab_is_enabled(void)
  427. {
  428. struct imx_sec_config_fuse_t *fuse =
  429. (struct imx_sec_config_fuse_t *)&imx_sec_config_fuse;
  430. uint32_t reg;
  431. int ret;
  432. ret = fuse_read(fuse->bank, fuse->word, &reg);
  433. if (ret) {
  434. puts("\nSecure boot fuse read error\n");
  435. return ret;
  436. }
  437. return (reg & IS_HAB_ENABLED_BIT) == IS_HAB_ENABLED_BIT;
  438. }
  439. int imx_hab_authenticate_image(uint32_t ddr_start, uint32_t image_size,
  440. uint32_t ivt_offset)
  441. {
  442. uint32_t load_addr = 0;
  443. size_t bytes;
  444. uint32_t ivt_addr = 0;
  445. int result = 1;
  446. ulong start;
  447. hab_rvt_authenticate_image_t *hab_rvt_authenticate_image;
  448. hab_rvt_entry_t *hab_rvt_entry;
  449. hab_rvt_exit_t *hab_rvt_exit;
  450. hab_rvt_check_target_t *hab_rvt_check_target;
  451. struct ivt *ivt;
  452. struct ivt_header *ivt_hdr;
  453. enum hab_status status;
  454. hab_rvt_authenticate_image =
  455. (hab_rvt_authenticate_image_t *)HAB_RVT_AUTHENTICATE_IMAGE;
  456. hab_rvt_entry = (hab_rvt_entry_t *)HAB_RVT_ENTRY;
  457. hab_rvt_exit = (hab_rvt_exit_t *)HAB_RVT_EXIT;
  458. hab_rvt_check_target = (hab_rvt_check_target_t *)HAB_RVT_CHECK_TARGET;
  459. if (!imx_hab_is_enabled()) {
  460. puts("hab fuse not enabled\n");
  461. return 0;
  462. }
  463. printf("\nAuthenticate image from DDR location 0x%x...\n",
  464. ddr_start);
  465. hab_caam_clock_enable(1);
  466. /* Calculate IVT address header */
  467. ivt_addr = ddr_start + ivt_offset;
  468. ivt = (struct ivt *)ivt_addr;
  469. ivt_hdr = &ivt->hdr;
  470. /* Verify IVT header bugging out on error */
  471. if (verify_ivt_header(ivt_hdr))
  472. goto hab_authentication_exit;
  473. /* Verify IVT body */
  474. if (ivt->self != ivt_addr) {
  475. printf("ivt->self 0x%08x pointer is 0x%08x\n",
  476. ivt->self, ivt_addr);
  477. goto hab_authentication_exit;
  478. }
  479. /* Verify if IVT DCD pointer is NULL */
  480. if (ivt->dcd) {
  481. puts("Error: DCD pointer must be NULL\n");
  482. goto hab_authentication_exit;
  483. }
  484. start = ddr_start;
  485. bytes = image_size;
  486. /* Verify CSF */
  487. if (!csf_is_valid(ivt, start, bytes))
  488. goto hab_authentication_exit;
  489. if (hab_rvt_entry() != HAB_SUCCESS) {
  490. puts("hab entry function fail\n");
  491. goto hab_exit_failure_print_status;
  492. }
  493. status = hab_rvt_check_target(HAB_TGT_MEMORY, (void *)ddr_start, bytes);
  494. if (status != HAB_SUCCESS) {
  495. printf("HAB check target 0x%08x-0x%08x fail\n",
  496. ddr_start, ddr_start + bytes);
  497. goto hab_exit_failure_print_status;
  498. }
  499. #ifdef DEBUG
  500. printf("\nivt_offset = 0x%x, ivt addr = 0x%x\n", ivt_offset, ivt_addr);
  501. printf("ivt entry = 0x%08x, dcd = 0x%08x, csf = 0x%08x\n", ivt->entry,
  502. ivt->dcd, ivt->csf);
  503. puts("Dumping IVT\n");
  504. print_buffer(ivt_addr, (void *)(ivt_addr), 4, 0x8, 0);
  505. puts("Dumping CSF Header\n");
  506. print_buffer(ivt->csf, (void *)(ivt->csf), 4, 0x10, 0);
  507. #if !defined(CONFIG_SPL_BUILD)
  508. get_hab_status();
  509. #endif
  510. puts("\nCalling authenticate_image in ROM\n");
  511. printf("\tivt_offset = 0x%x\n", ivt_offset);
  512. printf("\tstart = 0x%08lx\n", start);
  513. printf("\tbytes = 0x%x\n", bytes);
  514. #endif
  515. /*
  516. * If the MMU is enabled, we have to notify the ROM
  517. * code, or it won't flush the caches when needed.
  518. * This is done, by setting the "pu_irom_mmu_enabled"
  519. * word to 1. You can find its address by looking in
  520. * the ROM map. This is critical for
  521. * authenticate_image(). If MMU is enabled, without
  522. * setting this bit, authentication will fail and may
  523. * crash.
  524. */
  525. /* Check MMU enabled */
  526. if (is_soc_type(MXC_SOC_MX6) && get_cr() & CR_M) {
  527. if (is_mx6dq()) {
  528. /*
  529. * This won't work on Rev 1.0.0 of
  530. * i.MX6Q/D, since their ROM doesn't
  531. * do cache flushes. don't think any
  532. * exist, so we ignore them.
  533. */
  534. if (!is_mx6dqp())
  535. writel(1, MX6DQ_PU_IROM_MMU_EN_VAR);
  536. } else if (is_mx6sdl()) {
  537. writel(1, MX6DLS_PU_IROM_MMU_EN_VAR);
  538. } else if (is_mx6sl()) {
  539. writel(1, MX6SL_PU_IROM_MMU_EN_VAR);
  540. }
  541. }
  542. load_addr = (uint32_t)hab_rvt_authenticate_image(
  543. HAB_CID_UBOOT,
  544. ivt_offset, (void **)&start,
  545. (size_t *)&bytes, NULL);
  546. if (hab_rvt_exit() != HAB_SUCCESS) {
  547. puts("hab exit function fail\n");
  548. load_addr = 0;
  549. }
  550. hab_exit_failure_print_status:
  551. #if !defined(CONFIG_SPL_BUILD)
  552. get_hab_status();
  553. #endif
  554. hab_authentication_exit:
  555. if (load_addr != 0)
  556. result = 0;
  557. return result;
  558. }