]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - board/freescale/common/fsl_chain_of_trust.c
armv7: ls1021a: Drop macro CONFIG_LS102XA
[people/ms/u-boot.git] / board / freescale / common / fsl_chain_of_trust.c
index ecfcc8253a88b5a5700678cbbedeb83c26bbdc4b..aad1b93d140552a14d6b2b2b05ad9b830bd91bac 100644 (file)
@@ -6,9 +6,23 @@
 
 #include <common.h>
 #include <fsl_validate.h>
+#include <fsl_secboot_err.h>
 #include <fsl_sfp.h>
+#include <dm/root.h>
 
-#ifdef CONFIG_LS102XA
+#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_FRAMEWORK)
+#include <spl.h>
+#endif
+
+#ifdef CONFIG_ADDR_MAP
+#include <asm/mmu.h>
+#endif
+
+#ifdef CONFIG_FSL_CORENET
+#include <asm/fsl_pamu.h>
+#endif
+
+#ifdef CONFIG_ARCH_LS1021A
 #include <asm/arch/immap_ls102xa.h>
 #endif
 
@@ -52,6 +66,7 @@ int fsl_check_boot_mode_secure(void)
        return 0;
 }
 
+#ifndef CONFIG_SPL_BUILD
 int fsl_setenv_chain_of_trust(void)
 {
        /* Check Boot Mode
@@ -68,3 +83,76 @@ int fsl_setenv_chain_of_trust(void)
        setenv("bootcmd", CONFIG_CHAIN_BOOT_CMD);
        return 0;
 }
+#endif
+
+#ifdef CONFIG_SPL_BUILD
+void spl_validate_uboot(uint32_t hdr_addr, uintptr_t img_addr)
+{
+       int res;
+
+       /*
+        * Check Boot Mode
+        * If Boot Mode is Non-Secure, skip validation
+        */
+       if (fsl_check_boot_mode_secure() == 0)
+               return;
+
+       printf("SPL: Validating U-Boot image\n");
+
+#ifdef CONFIG_ADDR_MAP
+       init_addr_map();
+#endif
+
+#ifdef CONFIG_FSL_CORENET
+       if (pamu_init() < 0)
+               fsl_secboot_handle_error(ERROR_ESBC_PAMU_INIT);
+#endif
+
+#ifdef CONFIG_FSL_CAAM
+       if (sec_init() < 0)
+               fsl_secboot_handle_error(ERROR_ESBC_SEC_INIT);
+#endif
+
+/*
+ * dm_init_and_scan() is called as part of common SPL framework, so no
+ * need to call it again but in case of powerpc platforms which currently
+ * do not use common SPL framework, so need to call this function here.
+ */
+#if defined(CONFIG_SPL_DM) && (!defined(CONFIG_SPL_FRAMEWORK))
+       dm_init_and_scan(true);
+#endif
+       res = fsl_secboot_validate(hdr_addr, CONFIG_SPL_UBOOT_KEY_HASH,
+                                  &img_addr);
+
+       if (res == 0)
+               printf("SPL: Validation of U-boot successful\n");
+}
+
+#ifdef CONFIG_SPL_FRAMEWORK
+/* Override weak funtion defined in SPL framework to enable validation
+ * of main u-boot image before jumping to u-boot image.
+ */
+void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
+{
+       typedef void __noreturn (*image_entry_noargs_t)(void);
+       uint32_t hdr_addr;
+
+       image_entry_noargs_t image_entry =
+               (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
+
+       hdr_addr = (spl_image->entry_point + spl_image->size -
+                       CONFIG_U_BOOT_HDR_SIZE);
+       spl_validate_uboot(hdr_addr, (uintptr_t)spl_image->entry_point);
+       /*
+        * In case of failure in validation, spl_validate_uboot would
+        * not return back in case of Production environment with ITS=1.
+        * Thus U-Boot will not start.
+        * In Development environment (ITS=0 and SB_EN=1), the function
+        * may return back in case of non-fatal failures.
+        */
+
+       debug("image entry point: 0x%lX\n", spl_image->entry_point);
+       image_entry();
+}
+#endif /* ifdef CONFIG_SPL_FRAMEWORK */
+#endif /* ifdef CONFIG_SPL_BUILD */