1 /*
2  * Copyright 2016 NXP Semiconductor, Inc.
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 #include <common.h>
7 #include <config.h>
8 #include <errno.h>
9 #include <asm/system.h>
10 #include <asm/types.h>
11 #include <asm/arch/soc.h>
12 #ifdef CONFIG_FSL_LSCH3
13 #include <asm/arch/immap_lsch3.h>
14 #elif defined(CONFIG_FSL_LSCH2)
15 #include <asm/arch/immap_lsch2.h>
16 #endif
17 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
18 #include <asm/armv8/sec_firmware.h>
19 #endif
20 #ifdef CONFIG_CHAIN_OF_TRUST
21 #include <fsl_validate.h>
22 #endif
23 
24 int ppa_init(void)
25 {
26 	const void *ppa_fit_addr;
27 	u32 *boot_loc_ptr_l, *boot_loc_ptr_h;
28 	int ret;
29 
30 #ifdef CONFIG_CHAIN_OF_TRUST
31 	uintptr_t ppa_esbc_hdr = CONFIG_SYS_LS_PPA_ESBC_ADDR;
32 	uintptr_t ppa_img_addr = 0;
33 #endif
34 
35 #ifdef CONFIG_SYS_LS_PPA_FW_IN_XIP
36 	ppa_fit_addr = (void *)CONFIG_SYS_LS_PPA_FW_ADDR;
37 #else
38 #error "No CONFIG_SYS_LS_PPA_FW_IN_xxx defined"
39 #endif
40 
41 #ifdef CONFIG_CHAIN_OF_TRUST
42 	ppa_img_addr = (uintptr_t)ppa_fit_addr;
43 	if (fsl_check_boot_mode_secure() != 0) {
44 		ret = fsl_secboot_validate(ppa_esbc_hdr,
45 					   CONFIG_PPA_KEY_HASH,
46 					   &ppa_img_addr);
47 		if (ret != 0)
48 			printf("PPA validation failed\n");
49 		else
50 			printf("PPA validation Successful\n");
51 	}
52 #endif
53 
54 #ifdef CONFIG_FSL_LSCH3
55 	struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
56 	boot_loc_ptr_l = &gur->bootlocptrl;
57 	boot_loc_ptr_h = &gur->bootlocptrh;
58 #elif defined(CONFIG_FSL_LSCH2)
59 	struct ccsr_scfg __iomem *scfg = (void *)(CONFIG_SYS_FSL_SCFG_ADDR);
60 	boot_loc_ptr_l = &scfg->scratchrw[1];
61 	boot_loc_ptr_h = &scfg->scratchrw[0];
62 #endif
63 
64 	debug("fsl-ppa: boot_loc_ptr_l = 0x%p, boot_loc_ptr_h =0x%p\n",
65 	      boot_loc_ptr_l, boot_loc_ptr_h);
66 	ret = sec_firmware_init(ppa_fit_addr, boot_loc_ptr_l, boot_loc_ptr_h);
67 
68 	return ret;
69 }
70