2 * Copyright (C) 2014 Gateworks Corporation
3 * Copyright (C) 2011-2012 Freescale Semiconductor, Inc.
5 * Author: Tim Harvey <tharvey@gateworks.com>
7 * SPDX-License-Identifier: GPL-2.0+
12 #include <asm/arch/imx-regs.h>
13 #include <asm/arch/sys_proto.h>
16 #include <asm/mach-imx/hab.h>
19 DECLARE_GLOBAL_DATA_PTR;
21 #if defined(CONFIG_MX6)
22 /* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 register */
23 u32 spl_boot_device(void)
25 unsigned int bmode = readl(&src_base->sbmr2);
26 u32 reg = imx6_src_get_boot_mode();
29 * Check for BMODE if serial downloader is enabled
30 * BOOT_MODE - see IMX6DQRM Table 8-1
32 if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
33 return BOOT_DEVICE_BOARD;
36 * The above method does not detect that the boot ROM used
37 * serial downloader in case the boot ROM decided to use the
38 * serial downloader as a fall back (primary boot source failed).
40 * Infer that the boot ROM used the USB serial downloader by
41 * checking whether the USB PHY is currently active... This
42 * assumes that SPL did not (yet) initialize the USB PHY...
44 if (is_usbotg_phy_active())
45 return BOOT_DEVICE_BOARD;
47 /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
48 switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
49 /* EIM: See 8.5.1, Table 8-9 */
51 /* BOOT_CFG1[3]: NOR/OneNAND Selection */
52 switch ((reg & IMX6_BMODE_EMI_MASK) >> IMX6_BMODE_EMI_SHIFT) {
53 case IMX6_BMODE_ONENAND:
54 return BOOT_DEVICE_ONENAND;
56 return BOOT_DEVICE_NOR;
59 /* Reserved: Used to force Serial Downloader */
60 case IMX6_BMODE_RESERVED:
61 return BOOT_DEVICE_BOARD;
62 /* SATA: See 8.5.4, Table 8-20 */
63 #if !defined(CONFIG_MX6UL) && !defined(CONFIG_MX6ULL)
65 return BOOT_DEVICE_SATA;
67 /* Serial ROM: See 8.5.5.1, Table 8-22 */
68 case IMX6_BMODE_SERIAL_ROM:
70 switch ((reg & IMX6_BMODE_SERIAL_ROM_MASK) >>
71 IMX6_BMODE_SERIAL_ROM_SHIFT) {
72 case IMX6_BMODE_ECSPI1:
73 case IMX6_BMODE_ECSPI2:
74 case IMX6_BMODE_ECSPI3:
75 case IMX6_BMODE_ECSPI4:
76 case IMX6_BMODE_ECSPI5:
77 return BOOT_DEVICE_SPI;
81 return BOOT_DEVICE_I2C;
84 /* SD/eSD: 8.5.3, Table 8-15 */
87 return BOOT_DEVICE_MMC1;
91 return BOOT_DEVICE_MMC1;
92 /* NAND Flash: 8.5.2, Table 8-10 */
94 return BOOT_DEVICE_NAND;
96 return BOOT_DEVICE_NONE;
99 #ifdef CONFIG_SPL_USB_GADGET_SUPPORT
100 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
102 put_unaligned(CONFIG_G_DNL_PRODUCT_NUM + 0xfff, &dev->idProduct);
109 #if defined(CONFIG_SPL_MMC_SUPPORT)
110 /* called from spl_mmc to see type of boot mode for storage (RAW or FAT) */
111 u32 spl_boot_mode(const u32 boot_device)
113 switch (spl_boot_device()) {
114 /* for MMC return either RAW or FAT mode */
115 case BOOT_DEVICE_MMC1:
116 case BOOT_DEVICE_MMC2:
117 #if defined(CONFIG_SPL_FAT_SUPPORT)
118 return MMCSD_MODE_FS;
119 #elif defined(CONFIG_SUPPORT_EMMC_BOOT)
120 return MMCSD_MODE_EMMCBOOT;
122 return MMCSD_MODE_RAW;
126 puts("spl: ERROR: unsupported device\n");
132 #if defined(CONFIG_SECURE_BOOT)
134 __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
136 typedef void __noreturn (*image_entry_noargs_t)(void);
138 image_entry_noargs_t image_entry =
139 (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
141 debug("image entry point: 0x%lX\n", spl_image->entry_point);
143 /* HAB looks for the CSF at the end of the authenticated data therefore,
144 * we need to subtract the size of the CSF from the actual filesize */
145 if (authenticate_image(spl_image->load_addr,
146 spl_image->size - CONFIG_CSF_SIZE)) {
149 puts("spl: ERROR: image authentication unsuccessful\n");
156 #if defined(CONFIG_MX6) && defined(CONFIG_SPL_OS_BOOT)
157 int dram_init_banksize(void)
159 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
160 gd->bd->bi_dram[0].size = imx_ddr_size();