]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - arch/arm/mach-imx/hab.c
imx: hab: Keep CAAM clock enabled after authenticating additional images
[people/ms/u-boot.git] / arch / arm / mach-imx / hab.c
index d917ac3af9a6a69697b9abe884416f907a6e4274..1e6b31da7a0d773c5fbfe8405c1e44cb7241068c 100644 (file)
        ((hab_rvt_exit_t *)HAB_RVT_EXIT)                        \
 )
 
+static inline void hab_rvt_failsafe_new(void)
+{
+}
+
+#define hab_rvt_failsafe_p                             \
+(                                                      \
+       (is_mx6dqp()) ?                                 \
+       ((hab_rvt_failsafe_t *)hab_rvt_failsafe_new) :  \
+       (is_mx6dq() && (soc_rev() >= CHIP_REV_1_5)) ?   \
+       ((hab_rvt_failsafe_t *)hab_rvt_failsafe_new) :  \
+       (is_mx6sdl() && (soc_rev() >= CHIP_REV_1_2)) ?  \
+       ((hab_rvt_failsafe_t *)hab_rvt_failsafe_new) :  \
+       ((hab_rvt_failsafe_t *)HAB_RVT_FAILSAFE)        \
+)
+
 static inline enum hab_status hab_rvt_check_target_new(enum hab_target target,
                                                       const void *start,
                                                       size_t bytes)
@@ -96,8 +111,6 @@ static inline enum hab_status hab_rvt_check_target_new(enum hab_target target,
        (is_soc_type(MXC_SOC_MX7ULP) ? 0x80000000 :     \
         (is_soc_type(MXC_SOC_MX7) ? 0x2000000 : 0x2))
 
-static bool imx_hab_is_enabled(void);
-
 static int ivt_header_error(const char *err_str, struct ivt_header *ivt_hdr)
 {
        printf("%s magic=0x%x length=0x%02x version=0x%x\n", err_str,
@@ -401,6 +414,22 @@ static int do_authenticate_image(cmd_tbl_t *cmdtp, int flag, int argc,
        return rcode;
 }
 
+static int do_hab_failsafe(cmd_tbl_t *cmdtp, int flag, int argc,
+                          char * const argv[])
+{
+       hab_rvt_failsafe_t *hab_rvt_failsafe;
+
+       if (argc != 1) {
+               cmd_usage(cmdtp);
+               return 1;
+       }
+
+       hab_rvt_failsafe = hab_rvt_failsafe_p;
+       hab_rvt_failsafe();
+
+       return 0;
+}
+
 U_BOOT_CMD(
                hab_status, CONFIG_SYS_MAXARGS, 1, do_hab_status,
                "display HAB status",
@@ -416,10 +445,15 @@ U_BOOT_CMD(
                "ivt_offset - hex offset of IVT in the image"
          );
 
+U_BOOT_CMD(
+               hab_failsafe, CONFIG_SYS_MAXARGS, 1, do_hab_failsafe,
+               "run BootROM failsafe routine",
+               ""
+         );
 
 #endif /* !defined(CONFIG_SPL_BUILD) */
 
-static bool imx_hab_is_enabled(void)
+bool imx_hab_is_enabled(void)
 {
        struct imx_sec_config_fuse_t *fuse =
                (struct imx_sec_config_fuse_t *)&imx_sec_config_fuse;
@@ -458,7 +492,7 @@ int imx_hab_authenticate_image(uint32_t ddr_start, uint32_t image_size,
 
        if (!imx_hab_is_enabled()) {
                puts("hab fuse not enabled\n");
-               return result;
+               return 0;
        }
 
        printf("\nAuthenticate image from DDR location 0x%x...\n",
@@ -473,13 +507,13 @@ int imx_hab_authenticate_image(uint32_t ddr_start, uint32_t image_size,
 
        /* Verify IVT header bugging out on error */
        if (verify_ivt_header(ivt_hdr))
-               goto hab_caam_clock_disable;
+               goto hab_authentication_exit;
 
        /* Verify IVT body */
        if (ivt->self != ivt_addr) {
                printf("ivt->self 0x%08x pointer is 0x%08x\n",
                       ivt->self, ivt_addr);
-               goto hab_caam_clock_disable;
+               goto hab_authentication_exit;
        }
 
        start = ddr_start;
@@ -557,8 +591,7 @@ hab_exit_failure_print_status:
        get_hab_status();
 #endif
 
-hab_caam_clock_disable:
-       hab_caam_clock_enable(0);
+hab_authentication_exit:
 
        if (load_addr != 0)
                result = 0;