MLK-18703: crypto: caam: Add TRNG init function call
authorAymen Sghaier <aymen.sghaier@nxp.com>
Tue, 3 Jul 2018 08:14:37 +0000 (10:14 +0200)
committerYe Li <ye.li@nxp.com>
Wed, 28 Apr 2021 20:41:04 +0000 (13:41 -0700)
 Call the TRNG init function at the end of arch_cpu_init()
 Concerned SoCs are: i.MX6, i.MX7 and i.MX8M

Signed-off-by: Aymen Sghaier <aymen.sghaier@nxp.com>
(cherry picked from commit 996329904c0304a7bfbc6cda8287ab93de77870d)
(cherry picked from commit 5dd4441081f2af6f198a4d43eb1a3e543d986306)
(cherry picked from commit 6427f23dce038ddd995b41ef2300c6d6131ea9a2)

arch/arm/Kconfig
arch/arm/mach-imx/Kconfig
arch/arm/mach-imx/Makefile
arch/arm/mach-imx/imx8m/soc.c
arch/arm/mach-imx/misc.c
arch/arm/mach-imx/mx6/soc.c
arch/arm/mach-imx/mx7/soc.c
arch/arm/mach-imx/mx7ulp/soc.c
include/fsl_caam.h

index 76adf7f..0a1ed38 100644 (file)
@@ -845,6 +845,7 @@ config ARCH_IMX8M
        select DM
        select SUPPORT_SPL
        imply CMD_DM
+       select IMX_SEC_INIT if HAS_CAAM
 
 config ARCH_IMXRT
        bool "NXP i.MXRT platform"
@@ -882,6 +883,7 @@ config ARCH_MX7ULP
        select SYS_FSL_SEC_COMPAT_4
        select SYS_FSL_SEC_LE
        select ROM_UNIFIED_SECTIONS
+       select IMX_SEC_INIT if HAS_CAAM
        imply MXC_GPIO
        imply SYS_THUMB_BUILD
 
@@ -893,6 +895,7 @@ config ARCH_MX7
        select SYS_FSL_SEC_COMPAT_4
        select SYS_FSL_SEC_LE
        imply BOARD_EARLY_INIT_F
+       select IMX_SEC_INIT if HAS_CAAM
        imply MXC_GPIO
        imply SYS_THUMB_BUILD
 
@@ -902,6 +905,7 @@ config ARCH_MX6
        select SYS_FSL_HAS_SEC
        select SYS_FSL_SEC_COMPAT_4
        select SYS_FSL_SEC_LE
+       select IMX_SEC_INIT if HAS_CAAM
        imply MXC_GPIO
        imply SYS_THUMB_BUILD
 
index ca06c1e..2cc78e6 100644 (file)
@@ -13,6 +13,17 @@ config SYSCOUNTER_TIMER
 config GPT_TIMER
        bool
 
+config FSL_CAAM_KB
+       bool
+
+config IMX_SEC_INIT
+       bool
+       help
+               In most of i.MX board with CAAM this option is used
+               to init RNG from U-Boot
+       select FSL_CAAM_KB
+       select SPL_CRYPTO_SUPPORT if SPL
+
 config IMX_RDC
        bool "i.MX Resource domain controller driver"
        depends on ARCH_MX6 || ARCH_MX7
index 63b3549..aa1056a 100644 (file)
@@ -28,7 +28,7 @@ endif
 obj-$(CONFIG_GPT_TIMER) += timer.o
 obj-$(CONFIG_SYS_I2C_MXC) += i2c-mxv7.o
 endif
-ifeq ($(SOC),$(filter $(SOC),mx7 mx6 mxs imx8m imx8 imxrt))
+ifeq ($(SOC),$(filter $(SOC),mx7 mx6 mxs mx7ulp imx8m imx8 imxrt))
 obj-y  += misc.o
 obj-$(CONFIG_SPL_BUILD)        += spl.o
 endif
index d2364ec..01e65da 100644 (file)
@@ -29,6 +29,9 @@
 #include <imx_sip.h>
 #include <linux/arm-smccc.h>
 #include <linux/bitops.h>
+#ifdef CONFIG_IMX_SEC_INIT
+#include <fsl_caam.h>
+#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -486,6 +489,11 @@ int arch_cpu_init(void)
                }
        }
 
+#ifdef CONFIG_IMX_SEC_INIT
+       /* Secure init function such RNG */
+       imx_sec_init();
+#endif
+
        if (is_imx8mq()) {
                clock_enable(CCGR_OCOTP, 1);
                if (readl(&ocotp->ctrl) & 0x200)
index d82efa7..c78cf2d 100644 (file)
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2013 Stefan Roese <sr@denx.de>
+ * Copyright 2018 NXP
  */
 
 #include <common.h>
@@ -12,6 +13,7 @@
 #include <linux/errno.h>
 #include <asm/io.h>
 #include <asm/mach-imx/regs-common.h>
+#include <fsl_caam.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -107,3 +109,10 @@ void board_lmb_reserve(struct lmb *lmb)
                break;
        }
 }
+
+void imx_sec_init(void)
+{
+#if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_SPL)
+       caam_open();
+#endif
+}
index aacfc85..c4e4df8 100644 (file)
@@ -26,6 +26,9 @@
 #include <fsl_sec.h>
 #include <imx_thermal.h>
 #include <mmc.h>
+#ifdef CONFIG_IMX_SEC_INIT
+#include <fsl_caam.h>
+#endif
 
 #define has_err007805() \
        (is_mx6sl() || is_mx6dl() || is_mx6solo() || is_mx6ull())
@@ -487,6 +490,12 @@ int arch_cpu_init(void)
        if (is_mx6dqp())
                noc_setup();
 #endif
+
+#ifdef CONFIG_IMX_SEC_INIT
+       /* Secure init function such RNG */
+       imx_sec_init();
+#endif
+
        return 0;
 }
 
index 8866891..9a66f33 100644 (file)
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright (C) 2015 Freescale Semiconductor, Inc.
+ * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
+ * Copyright 2017-2018 NXP
  */
 
 #include <common.h>
@@ -53,6 +54,9 @@
 #define BM_GPC_PGC_ACK_SEL_A7_DUMMY_PDN_ACK    0x8000
 
 #define BM_GPC_PGC_CORE_PUPSCR                 0x7fff80
+#ifdef CONFIG_IMX_SEC_INIT
+#include <fsl_caam.h>
+#endif
 
 #if defined(CONFIG_IMX_THERMAL)
 static const struct imx_thermal_plat imx7_thermal_plat = {
@@ -322,6 +326,10 @@ int arch_cpu_init(void)
        init_snvs();
 
        imx_gpcv2_init();
+#ifdef CONFIG_IMX_SEC_INIT
+       /* Secure init function such RNG */
+       imx_sec_init();
+#endif
 
        return 0;
 }
index 8dd6b4d..adced01 100644 (file)
@@ -14,6 +14,9 @@
 #include <asm/mach-imx/boot_mode.h>
 #include <asm/mach-imx/hab.h>
 #include <linux/bitops.h>
+#ifdef CONFIG_IMX_SEC_INIT
+#include <fsl_caam.h>
+#endif
 
 #define PMC0_BASE_ADDR         0x410a1000
 #define PMC0_CTRL              0x28
@@ -76,6 +79,11 @@ enum bt_mode get_boot_mode(void)
 
 int arch_cpu_init(void)
 {
+#ifdef CONFIG_IMX_SEC_INIT
+       /* Secure init function such RNG */
+       imx_sec_init();
+#endif
+
        return 0;
 }
 
index 29f5ca1..4650bf2 100644 (file)
@@ -50,6 +50,7 @@
 //!
 ////////////////////////////////////////////////////////////////////////////////
 void caam_open(void);
+void imx_sec_init(void);
 
 ////////////////////////////////////////////////////////////////////////////////
 //! @brief Generate a blob of a secure key.