2 * Copyright 2015 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
8 #include <fsl_validate.h>
9 #include <fsl_secboot_err.h>
13 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_FRAMEWORK)
17 #ifdef CONFIG_ADDR_MAP
21 #ifdef CONFIG_FSL_CORENET
22 #include <asm/fsl_pamu.h>
26 #include <asm/arch/immap_ls102xa.h>
29 #if defined(CONFIG_MPC85xx)
30 #define CONFIG_DCFG_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
32 #define CONFIG_DCFG_ADDR CONFIG_SYS_FSL_GUTS_ADDR
35 #ifdef CONFIG_SYS_FSL_CCSR_GUR_LE
36 #define gur_in32(a) in_le32(a)
38 #define gur_in32(a) in_be32(a)
41 /* Check the Boot Mode. If Secure, return 1 else return 0 */
42 int fsl_check_boot_mode_secure(void)
45 struct ccsr_sfp_regs *sfp_regs = (void *)(CONFIG_SYS_SFP_ADDR);
46 struct ccsr_gur __iomem *gur = (void *)(CONFIG_DCFG_ADDR);
48 val = sfp_in32(&sfp_regs->ospr) & ITS_MASK;
52 #if defined(CONFIG_FSL_CORENET) || !defined(CONFIG_MPC85xx)
53 /* For PBL based platforms check the SB_EN bit in RCWSR */
54 val = gur_in32(&gur->rcwsr[RCW_SB_EN_REG_INDEX - 1]) & RCW_SB_EN_MASK;
55 if (val == RCW_SB_EN_MASK)
59 #if defined(CONFIG_MPC85xx) && !defined(CONFIG_FSL_CORENET)
60 /* For Non-PBL Platforms, check the Device Status register 2*/
61 val = gur_in32(&gur->pordevsr2) & MPC85xx_PORDEVSR2_SBC_MASK;
62 if (val != MPC85xx_PORDEVSR2_SBC_MASK)
69 #ifndef CONFIG_SPL_BUILD
70 int fsl_setenv_chain_of_trust(void)
73 * If Boot Mode is Non-Secure, no changes are required
75 if (fsl_check_boot_mode_secure() == 0)
78 /* If Boot mode is Secure, set the environment variables
79 * bootdelay = 0 (To disable Boot Prompt)
80 * bootcmd = CONFIG_CHAIN_BOOT_CMD (Validate and execute Boot script)
82 setenv("bootdelay", "0");
83 setenv("bootcmd", CONFIG_CHAIN_BOOT_CMD);
88 #ifdef CONFIG_SPL_BUILD
89 void spl_validate_uboot(uint32_t hdr_addr, uintptr_t img_addr)
95 * If Boot Mode is Non-Secure, skip validation
97 if (fsl_check_boot_mode_secure() == 0)
100 printf("SPL: Validating U-Boot image\n");
102 #ifdef CONFIG_ADDR_MAP
106 #ifdef CONFIG_FSL_CORENET
108 fsl_secboot_handle_error(ERROR_ESBC_PAMU_INIT);
111 #ifdef CONFIG_FSL_CAAM
113 fsl_secboot_handle_error(ERROR_ESBC_SEC_INIT);
117 * dm_init_and_scan() is called as part of common SPL framework, so no
118 * need to call it again but in case of powerpc platforms which currently
119 * do not use common SPL framework, so need to call this function here.
121 #if defined(CONFIG_SPL_DM) && (!defined(CONFIG_SPL_FRAMEWORK))
122 dm_init_and_scan(true);
124 res = fsl_secboot_validate(hdr_addr, CONFIG_SPL_UBOOT_KEY_HASH,
128 printf("SPL: Validation of U-boot successful\n");
131 #ifdef CONFIG_SPL_FRAMEWORK
132 /* Override weak funtion defined in SPL framework to enable validation
133 * of main u-boot image before jumping to u-boot image.
135 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
137 typedef void __noreturn (*image_entry_noargs_t)(void);
140 image_entry_noargs_t image_entry =
141 (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
143 hdr_addr = (spl_image->entry_point + spl_image->size -
144 CONFIG_U_BOOT_HDR_SIZE);
145 spl_validate_uboot(hdr_addr, (uintptr_t)spl_image->entry_point);
147 * In case of failure in validation, spl_validate_uboot would
148 * not return back in case of Production environment with ITS=1.
149 * Thus U-Boot will not start.
150 * In Development environment (ITS=0 and SB_EN=1), the function
151 * may return back in case of non-fatal failures.
154 debug("image entry point: 0x%X\n", spl_image->entry_point);
157 #endif /* ifdef CONFIG_SPL_FRAMEWORK */
158 #endif /* ifdef CONFIG_SPL_BUILD */