Commit 5dd4441081f2af6f198a4d43eb1a3e543d986306

Authored by Aymen Sghaier
Committed by Ye Li
1 parent 20bd91de9f

MLK-18703: crypto: caam: Add TRNG init function call

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)

Showing 8 changed files with 58 additions and 1 deletions Side-by-side Diff

... ... @@ -710,6 +710,7 @@
710 710 select DM
711 711 select SUPPORT_SPL
712 712 imply CMD_DM
  713 + select IMX_SEC_INIT if HAS_CAAM
713 714  
714 715 config ARCH_MX23
715 716 bool "NXP i.MX23 family"
... ... @@ -740,6 +741,7 @@
740 741 select SYS_FSL_SEC_LE
741 742 select ROM_UNIFIED_SECTIONS
742 743 imply MXC_GPIO
  744 + select IMX_SEC_INIT if HAS_CAAM
743 745  
744 746 config ARCH_MX7
745 747 bool "Freescale MX7"
... ... @@ -749,6 +751,7 @@
749 751 select SYS_FSL_HAS_SEC if SECURE_BOOT
750 752 select SYS_FSL_SEC_COMPAT_4
751 753 select SYS_FSL_SEC_LE
  754 + select IMX_SEC_INIT if HAS_CAAM
752 755 imply MXC_GPIO
753 756  
754 757 config ARCH_MX6
... ... @@ -757,6 +760,7 @@
757 760 select SYS_FSL_HAS_SEC if SECURE_BOOT
758 761 select SYS_FSL_SEC_COMPAT_4
759 762 select SYS_FSL_SEC_LE
  763 + select IMX_SEC_INIT if HAS_CAAM
760 764 select SYS_THUMB_BUILD if SPL
761 765 imply MXC_GPIO
762 766  
arch/arm/mach-imx/Kconfig
... ... @@ -13,6 +13,17 @@
13 13 config GPT_TIMER
14 14 bool
15 15  
  16 +config FSL_CAAM_KB
  17 + bool
  18 +
  19 +config IMX_SEC_INIT
  20 + bool
  21 + help
  22 + In most of i.MX board with CAAM this option is used
  23 + to init RNG from U-Boot
  24 + select FSL_CAAM_KB
  25 + select SPL_CRYPTO_SUPPORT if SPL
  26 +
16 27 config IMX_RDC
17 28 bool "i.MX Resource domain controller driver"
18 29 depends on ARCH_MX6 || ARCH_MX7
arch/arm/mach-imx/imx8m/soc.c
... ... @@ -19,6 +19,9 @@
19 19 #include <fsl_wdog.h>
20 20 #include <imx_sip.h>
21 21 #include <generated/version_autogenerated.h>
  22 +#ifdef CONFIG_IMX_SEC_INIT
  23 +#include <fsl_caam.h>
  24 +#endif
22 25  
23 26 DECLARE_GLOBAL_DATA_PTR;
24 27  
... ... @@ -202,6 +205,11 @@
202 205 clock_init();
203 206 imx_set_wdog_powerdown(false);
204 207 }
  208 +
  209 +#ifdef CONFIG_IMX_SEC_INIT
  210 + /* Secure init function such RNG */
  211 + imx_sec_init();
  212 +#endif
205 213  
206 214 return 0;
207 215 }
arch/arm/mach-imx/misc.c
1 1 // SPDX-License-Identifier: GPL-2.0+
2 2 /*
3 3 * Copyright 2013 Stefan Roese <sr@denx.de>
  4 + * Copyright 2018 NXP
4 5 */
5 6  
6 7 #include <common.h>
... ... @@ -8,6 +9,7 @@
8 9 #include <linux/errno.h>
9 10 #include <asm/io.h>
10 11 #include <asm/mach-imx/regs-common.h>
  12 +#include <fsl_caam.h>
11 13  
12 14 DECLARE_GLOBAL_DATA_PTR;
13 15  
... ... @@ -102,5 +104,12 @@
102 104 lmb_reserve(lmb, sp, bank_end - sp);
103 105 break;
104 106 }
  107 +}
  108 +
  109 +void imx_sec_init(void)
  110 +{
  111 +#if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_SPL)
  112 + caam_open();
  113 +#endif
105 114 }
arch/arm/mach-imx/mx6/soc.c
... ... @@ -22,6 +22,9 @@
22 22 #include <dm.h>
23 23 #include <imx_thermal.h>
24 24 #include <mmc.h>
  25 +#ifdef CONFIG_IMX_SEC_INIT
  26 +#include <fsl_caam.h>
  27 +#endif
25 28  
26 29 enum ldo_reg {
27 30 LDO_ARM,
... ... @@ -441,6 +444,11 @@
441 444 setbits_le32(&ccm->cscdr1, MXC_CCM_CSCDR1_UART_CLK_SEL);
442 445  
443 446 init_src();
  447 +
  448 +#ifdef CONFIG_IMX_SEC_INIT
  449 + /* Secure init function such RNG */
  450 + imx_sec_init();
  451 +#endif
444 452  
445 453 return 0;
446 454 }
arch/arm/mach-imx/mx7/soc.c
1 1 // SPDX-License-Identifier: GPL-2.0+
2 2 /*
3   - * Copyright (C) 2015 Freescale Semiconductor, Inc.
  3 + * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
  4 + * Copyright 2017-2018 NXP
4 5 */
5 6  
6 7 #include <common.h>
... ... @@ -49,6 +50,9 @@
49 50 #define BM_GPC_PGC_ACK_SEL_A7_DUMMY_PDN_ACK 0x8000
50 51  
51 52 #define BM_GPC_PGC_CORE_PUPSCR 0x7fff80
  53 +#ifdef CONFIG_IMX_SEC_INIT
  54 +#include <fsl_caam.h>
  55 +#endif
52 56  
53 57 #if defined(CONFIG_IMX_THERMAL)
54 58 static const struct imx_thermal_plat imx7_thermal_plat = {
... ... @@ -284,6 +288,10 @@
284 288 init_snvs();
285 289  
286 290 imx_gpcv2_init();
  291 +#ifdef CONFIG_IMX_SEC_INIT
  292 + /* Secure init function such RNG */
  293 + imx_sec_init();
  294 +#endif
287 295  
288 296 return 0;
289 297 }
arch/arm/mach-imx/mx7ulp/soc.c
... ... @@ -7,6 +7,9 @@
7 7 #include <asm/arch/imx-regs.h>
8 8 #include <asm/arch/sys_proto.h>
9 9 #include <asm/mach-imx/hab.h>
  10 +#ifdef CONFIG_IMX_SEC_INIT
  11 +#include <fsl_caam.h>
  12 +#endif
10 13  
11 14 static char *get_reset_cause(char *);
12 15  
... ... @@ -50,6 +53,11 @@
50 53  
51 54 int arch_cpu_init(void)
52 55 {
  56 +#ifdef CONFIG_IMX_SEC_INIT
  57 + /* Secure init function such RNG */
  58 + imx_sec_init();
  59 +#endif
  60 +
53 61 return 0;
54 62 }
55 63  
... ... @@ -50,6 +50,7 @@
50 50 //!
51 51 ////////////////////////////////////////////////////////////////////////////////
52 52 void caam_open(void);
  53 +void imx_sec_init(void);
53 54  
54 55 ////////////////////////////////////////////////////////////////////////////////
55 56 //! @brief Generate a blob of a secure key.