1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2014 Gateworks Corporation
4 * Copyright (C) 2011-2012 Freescale Semiconductor, Inc.
6 * Author: Tim Harvey <tharvey@gateworks.com>
13 #include <asm/global_data.h>
15 #include <asm/arch/imx-regs.h>
16 #include <asm/arch/sys_proto.h>
19 #include <asm/mach-imx/hab.h>
20 #include <asm/mach-imx/boot_mode.h>
22 #include <linux/libfdt.h>
25 DECLARE_GLOBAL_DATA_PTR;
27 __weak int spl_board_boot_device(enum boot_device boot_dev_spl)
29 switch (boot_dev_spl) {
30 #if defined(CONFIG_MX7)
37 return BOOT_DEVICE_MMC1;
38 #elif defined(CONFIG_IMX8)
40 return BOOT_DEVICE_MMC1;
42 return BOOT_DEVICE_MMC2_2;
44 return BOOT_DEVICE_MMC1;
46 return BOOT_DEVICE_SPI;
47 #elif defined(CONFIG_IMX8M)
50 return BOOT_DEVICE_MMC1;
53 return BOOT_DEVICE_MMC2;
56 return BOOT_DEVICE_NAND;
58 return BOOT_DEVICE_SPI;
60 return BOOT_DEVICE_NOR;
62 return BOOT_DEVICE_BOARD;
64 return BOOT_DEVICE_NONE;
68 #if defined(CONFIG_MX6)
69 /* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 register */
70 u32 spl_boot_device(void)
72 unsigned int bmode = readl(&src_base->sbmr2);
73 u32 reg = imx6_src_get_boot_mode();
76 * Check for BMODE if serial downloader is enabled
77 * BOOT_MODE - see IMX6DQRM Table 8-1
79 if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
80 return BOOT_DEVICE_BOARD;
83 * The above method does not detect that the boot ROM used
84 * serial downloader in case the boot ROM decided to use the
85 * serial downloader as a fall back (primary boot source failed).
87 * Infer that the boot ROM used the USB serial downloader by
88 * checking whether the USB PHY is currently active... This
89 * assumes that SPL did not (yet) initialize the USB PHY...
91 if (is_usbotg_phy_active())
92 return BOOT_DEVICE_BOARD;
94 /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
95 switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
96 /* EIM: See 8.5.1, Table 8-9 */
98 /* BOOT_CFG1[3]: NOR/OneNAND Selection */
99 switch ((reg & IMX6_BMODE_EIM_MASK) >> IMX6_BMODE_EIM_SHIFT) {
100 case IMX6_BMODE_ONENAND:
101 return BOOT_DEVICE_ONENAND;
103 return BOOT_DEVICE_NOR;
106 /* Reserved: Used to force Serial Downloader */
107 case IMX6_BMODE_RESERVED:
108 return BOOT_DEVICE_BOARD;
109 /* SATA: See 8.5.4, Table 8-20 */
110 #if !defined(CONFIG_MX6UL) && !defined(CONFIG_MX6ULL)
111 case IMX6_BMODE_SATA:
112 return BOOT_DEVICE_SATA;
114 /* Serial ROM: See 8.5.5.1, Table 8-22 */
115 case IMX6_BMODE_SERIAL_ROM:
117 switch ((reg & IMX6_BMODE_SERIAL_ROM_MASK) >>
118 IMX6_BMODE_SERIAL_ROM_SHIFT) {
119 case IMX6_BMODE_ECSPI1:
120 case IMX6_BMODE_ECSPI2:
121 case IMX6_BMODE_ECSPI3:
122 case IMX6_BMODE_ECSPI4:
123 case IMX6_BMODE_ECSPI5:
124 return BOOT_DEVICE_SPI;
125 case IMX6_BMODE_I2C1:
126 case IMX6_BMODE_I2C2:
127 case IMX6_BMODE_I2C3:
128 return BOOT_DEVICE_I2C;
131 /* SD/eSD: 8.5.3, Table 8-15 */
134 return BOOT_DEVICE_MMC1;
135 /* MMC/eMMC: 8.5.3 */
137 case IMX6_BMODE_EMMC:
138 return BOOT_DEVICE_MMC1;
139 /* NAND Flash: 8.5.2, Table 8-10 */
140 case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX:
141 return BOOT_DEVICE_NAND;
142 #if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
144 case IMX6_BMODE_QSPI:
145 return BOOT_DEVICE_SPI;
148 return BOOT_DEVICE_NONE;
151 #elif defined(CONFIG_MX7) || defined(CONFIG_IMX8M) || defined(CONFIG_IMX8) || defined(CONFIG_IMX9)
152 /* Translate iMX7/i.MX8M boot device to the SPL boot device enumeration */
153 u32 spl_boot_device(void)
155 #if defined(CONFIG_MX7)
156 unsigned int bmode = readl(&src_base->sbmr2);
159 * Check for BMODE if serial downloader is enabled
160 * BOOT_MODE - see IMX7DRM Table 6-24
162 if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
163 return BOOT_DEVICE_BOARD;
166 * The above method does not detect that the boot ROM used
167 * serial downloader in case the boot ROM decided to use the
168 * serial downloader as a fall back (primary boot source failed).
170 * Infer that the boot ROM used the USB serial downloader by
171 * checking whether the USB PHY is currently active... This
172 * assumes that SPL did not (yet) initialize the USB PHY...
174 if (is_boot_from_usb())
175 return BOOT_DEVICE_BOARD;
178 enum boot_device boot_device_spl = get_boot_device();
180 return spl_board_boot_device(boot_device_spl);
182 #endif /* CONFIG_MX7 || CONFIG_IMX8M || CONFIG_IMX8 */
184 #ifdef CONFIG_SPL_USB_GADGET
185 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
187 put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM + 0xfff, &dev->idProduct);
192 #define SDPV_BCD_DEVICE 0x500
193 int g_dnl_get_board_bcd_device_number(int gcnum)
195 return SDPV_BCD_DEVICE;
199 #if defined(CONFIG_SPL_MMC)
200 /* called from spl_mmc to see type of boot mode for storage (RAW or FAT) */
201 u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
203 #if defined(CONFIG_MX7) || defined(CONFIG_IMX8M) || defined(CONFIG_IMX8)
204 switch (get_boot_device()) {
205 /* for MMC return either RAW or FAT mode */
209 if (IS_ENABLED(CONFIG_SPL_FS_FAT))
210 return MMCSD_MODE_FS;
212 return MMCSD_MODE_RAW;
216 if (IS_ENABLED(CONFIG_SPL_FS_FAT))
217 return MMCSD_MODE_FS;
218 else if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT))
219 return MMCSD_MODE_EMMCBOOT;
221 return MMCSD_MODE_RAW;
223 puts("spl: ERROR: unsupported device\n");
227 switch (boot_device) {
228 /* for MMC return either RAW or FAT mode */
229 case BOOT_DEVICE_MMC1:
230 case BOOT_DEVICE_MMC2:
231 case BOOT_DEVICE_MMC2_2:
232 if (IS_ENABLED(CONFIG_SPL_FS_FAT))
233 return MMCSD_MODE_FS;
234 else if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT))
235 return MMCSD_MODE_EMMCBOOT;
237 return MMCSD_MODE_RAW;
239 puts("spl: ERROR: unsupported device\n");
246 #if defined(CONFIG_IMX_HAB)
249 * +------------+ 0x0 (DDR_UIMAGE_START) -
251 * +------------+ 0x40 |
258 * . | > Stuff to be authenticated ----+
266 * +------------+ Align to ALIGN_SIZE | |
268 * +------------+ + IVT_SIZE - |
270 * | CSF DATA | <---------------------------------------------------------+
276 * +------------+ + CSF_PAD_SIZE
279 __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
281 typedef void __noreturn (*image_entry_noargs_t)(void);
284 image_entry_noargs_t image_entry =
285 (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
287 debug("image entry point: 0x%lX\n", spl_image->entry_point);
289 if (spl_image->flags & SPL_FIT_FOUND) {
293 * HAB looks for the CSF at the end of the authenticated
294 * data therefore, we need to subtract the size of the
295 * CSF from the actual filesize
297 offset = spl_image->size - CONFIG_CSF_SIZE;
298 if (!imx_hab_authenticate_image(spl_image->load_addr,
300 CSF_PAD_SIZE, offset)) {
303 panic("spl: ERROR: image authentication fail\n");
308 #if !defined(CONFIG_SPL_FIT_SIGNATURE)
309 ulong board_spl_fit_size_align(ulong size)
312 * HAB authenticate_image requests the IVT offset is
316 size = ALIGN(size, 0x1000);
317 size += CONFIG_CSF_SIZE;
319 if (size > CONFIG_SYS_BOOTM_LEN)
320 panic("spl: ERROR: image too big\n");
326 void *board_spl_fit_buffer_addr(ulong fit_size, int sectors, int bl_len)
328 #if defined(CONFIG_SPL_LOAD_FIT_ADDRESS)
329 return (void *)CONFIG_SPL_LOAD_FIT_ADDRESS;
331 return (void *)(CONFIG_TEXT_BASE + CONFIG_SYS_BOOTM_LEN);
335 * read the address where the IVT header must sit
336 * from IVT image header, loaded from SPL into
337 * an malloced buffer and copy the IVT header
340 void *spl_load_simple_fit_fix_load(const void *fit)
343 unsigned long offset;
347 offset = ALIGN(fdt_totalsize(fit), 0x1000);
348 size = ALIGN(fdt_totalsize(fit), 4);
349 size = board_spl_fit_size_align(size);
351 ivt = (struct ivt *)tmp;
353 debug("%s: ivt: %p offset: %lx size: %lx\n", __func__, ivt, offset, size);
354 debug("%s: ivt self: %x\n", __func__, ivt->self);
356 if (imx_hab_authenticate_image((uintptr_t)fit, (uintptr_t)ivt, offset))
357 panic("spl: ERROR: image authentication unsuccessful\n");
361 #endif /* CONFIG_IMX_HAB */
363 #if defined(CONFIG_MX6) && defined(CONFIG_SPL_OS_BOOT)
364 int dram_init_banksize(void)
366 gd->bd->bi_dram[0].start = CFG_SYS_SDRAM_BASE;
367 gd->bd->bi_dram[0].size = imx_ddr_size();