2 * Copyright 2016 NXP Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/system.h>
11 #include <asm/types.h>
12 #include <asm/arch/soc.h>
13 #ifdef CONFIG_FSL_LSCH3
14 #include <asm/arch/immap_lsch3.h>
15 #elif defined(CONFIG_FSL_LSCH2)
16 #include <asm/arch/immap_lsch2.h>
18 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
19 #include <asm/armv8/sec_firmware.h>
21 #ifdef CONFIG_CHAIN_OF_TRUST
22 #include <fsl_validate.h>
25 #ifdef CONFIG_SYS_LS_PPA_FW_IN_NAND
27 #elif defined(CONFIG_SYS_LS_PPA_FW_IN_MMC)
31 DECLARE_GLOBAL_DATA_PTR;
36 u32 *boot_loc_ptr_l, *boot_loc_ptr_h;
39 #ifdef CONFIG_CHAIN_OF_TRUST
40 uintptr_t ppa_esbc_hdr = CONFIG_SYS_LS_PPA_ESBC_ADDR;
41 uintptr_t ppa_img_addr = 0;
44 #ifdef CONFIG_SYS_LS_PPA_FW_IN_XIP
45 ppa_fit_addr = (void *)CONFIG_SYS_LS_PPA_FW_ADDR;
46 debug("%s: PPA image load from XIP\n", __func__);
47 #else /* !CONFIG_SYS_LS_PPA_FW_IN_XIP */
48 size_t fw_length, fdt_header_len = sizeof(struct fdt_header);
50 /* Copy PPA image from MMC/SD/NAND to allocated memory */
51 #ifdef CONFIG_SYS_LS_PPA_FW_IN_MMC
53 int dev = CONFIG_SYS_MMC_ENV_DEV;
54 struct fdt_header *fitp;
56 u32 blk = CONFIG_SYS_LS_PPA_FW_ADDR / 512;
58 debug("%s: PPA image load from eMMC/SD\n", __func__);
60 ret = mmc_initialize(gd->bd);
62 printf("%s: mmc_initialize() failed\n", __func__);
65 mmc = find_mmc_device(dev);
67 printf("PPA: MMC cannot find device for PPA firmware\n");
73 printf("%s: mmc_init() failed\n", __func__);
77 fitp = malloc(roundup(fdt_header_len, 512));
79 printf("PPA: malloc failed for FIT header(size 0x%zx)\n",
80 roundup(fdt_header_len, 512));
84 cnt = DIV_ROUND_UP(fdt_header_len, 512);
85 debug("%s: MMC read PPA FIT header: dev # %u, block # %u, count %u\n",
86 __func__, dev, blk, cnt);
87 ret = mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, fitp);
90 printf("MMC/SD read of PPA FIT header at offset 0x%x failed\n",
91 CONFIG_SYS_LS_PPA_FW_ADDR);
95 /* flush cache after read */
96 flush_cache((ulong)fitp, cnt * 512);
98 ret = fdt_check_header(fitp);
101 printf("%s: fdt_check_header() failed\n", __func__);
105 fw_length = fdt_totalsize(fitp);
108 fw_length = roundup(fw_length, 512);
109 ppa_fit_addr = malloc(fw_length);
111 printf("PPA: malloc failed for PPA image(size 0x%zx)\n",
116 cnt = DIV_ROUND_UP(fw_length, 512);
117 debug("%s: MMC read PPA FIT image: dev # %u, block # %u, count %u\n",
118 __func__, dev, blk, cnt);
119 ret = mmc->block_dev.block_read(&mmc->block_dev,
120 blk, cnt, ppa_fit_addr);
123 printf("MMC/SD read of PPA FIT header at offset 0x%x failed\n",
124 CONFIG_SYS_LS_PPA_FW_ADDR);
128 /* flush cache after read */
129 flush_cache((ulong)ppa_fit_addr, cnt * 512);
131 #elif defined(CONFIG_SYS_LS_PPA_FW_IN_NAND)
132 struct fdt_header fit;
134 debug("%s: PPA image load from NAND\n", __func__);
137 ret = nand_read(nand_info[0], (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
138 &fdt_header_len, (u_char *)&fit);
139 if (ret == -EUCLEAN) {
140 printf("NAND read of PPA FIT header at offset 0x%x failed\n",
141 CONFIG_SYS_LS_PPA_FW_ADDR);
145 ret = fdt_check_header(&fit);
147 printf("%s: fdt_check_header() failed\n", __func__);
151 fw_length = fdt_totalsize(&fit);
153 ppa_fit_addr = malloc(fw_length);
155 printf("PPA: malloc failed for PPA image(size 0x%zx)\n",
160 ret = nand_read(nand_info[0], (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
161 &fw_length, (u_char *)ppa_fit_addr);
162 if (ret == -EUCLEAN) {
164 printf("NAND read of PPA firmware at offset 0x%x failed\n",
165 CONFIG_SYS_LS_PPA_FW_ADDR);
169 /* flush cache after read */
170 flush_cache((ulong)ppa_fit_addr, fw_length);
172 #error "No CONFIG_SYS_LS_PPA_FW_IN_xxx defined"
177 #ifdef CONFIG_CHAIN_OF_TRUST
178 ppa_img_addr = (uintptr_t)ppa_fit_addr;
179 if (fsl_check_boot_mode_secure() != 0) {
180 ret = fsl_secboot_validate(ppa_esbc_hdr,
184 printf("PPA validation failed\n");
186 printf("PPA validation Successful\n");
190 #ifdef CONFIG_FSL_LSCH3
191 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
192 boot_loc_ptr_l = &gur->bootlocptrl;
193 boot_loc_ptr_h = &gur->bootlocptrh;
194 #elif defined(CONFIG_FSL_LSCH2)
195 struct ccsr_scfg __iomem *scfg = (void *)(CONFIG_SYS_FSL_SCFG_ADDR);
196 boot_loc_ptr_l = &scfg->scratchrw[1];
197 boot_loc_ptr_h = &scfg->scratchrw[0];
200 debug("fsl-ppa: boot_loc_ptr_l = 0x%p, boot_loc_ptr_h =0x%p\n",
201 boot_loc_ptr_l, boot_loc_ptr_h);
202 ret = sec_firmware_init(ppa_fit_addr, boot_loc_ptr_l, boot_loc_ptr_h);
204 #if defined(CONFIG_SYS_LS_PPA_FW_IN_MMC) || \
205 defined(CONFIG_SYS_LS_PPA_FW_IN_NAND)