hab.c 15 KB

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