1 /*
2 * Copyright (C) 2014 Gateworks Corporation
3 * Copyright (C) 2011-2012 Freescale Semiconductor, Inc.
4 *
5 * Author: Tim Harvey <tharvey@gateworks.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10 #include <common.h>
11 #include <asm/io.h>
12 #include <asm/arch/imx-regs.h>
13 #include <asm/arch/sys_proto.h>
14 #include <asm/spl.h>
15 #include <spl.h>
16 #include <asm/mach-imx/hab.h>
17 #include <g_dnl.h>
18
19 DECLARE_GLOBAL_DATA_PTR;
20
21 #if defined(CONFIG_MX6)
22 /* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 register */
spl_boot_device(void)23 u32 spl_boot_device(void)
24 {
25 unsigned int bmode = readl(&src_base->sbmr2);
26 u32 reg = imx6_src_get_boot_mode();
27
28 /*
29 * Check for BMODE if serial downloader is enabled
30 * BOOT_MODE - see IMX6DQRM Table 8-1
31 */
32 if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
33 return BOOT_DEVICE_BOARD;
34
35 /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
36 switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
37 /* EIM: See 8.5.1, Table 8-9 */
38 case IMX6_BMODE_EMI:
39 /* BOOT_CFG1[3]: NOR/OneNAND Selection */
40 switch ((reg & IMX6_BMODE_EMI_MASK) >> IMX6_BMODE_EMI_SHIFT) {
41 case IMX6_BMODE_ONENAND:
42 return BOOT_DEVICE_ONENAND;
43 case IMX6_BMODE_NOR:
44 return BOOT_DEVICE_NOR;
45 break;
46 }
47 /* Reserved: Used to force Serial Downloader */
48 case IMX6_BMODE_RESERVED:
49 return BOOT_DEVICE_BOARD;
50 /* SATA: See 8.5.4, Table 8-20 */
51 #if !defined(CONFIG_MX6UL) && !defined(CONFIG_MX6ULL)
52 case IMX6_BMODE_SATA:
53 return BOOT_DEVICE_SATA;
54 #endif
55 /* Serial ROM: See 8.5.5.1, Table 8-22 */
56 case IMX6_BMODE_SERIAL_ROM:
57 /* BOOT_CFG4[2:0] */
58 switch ((reg & IMX6_BMODE_SERIAL_ROM_MASK) >>
59 IMX6_BMODE_SERIAL_ROM_SHIFT) {
60 case IMX6_BMODE_ECSPI1:
61 case IMX6_BMODE_ECSPI2:
62 case IMX6_BMODE_ECSPI3:
63 case IMX6_BMODE_ECSPI4:
64 case IMX6_BMODE_ECSPI5:
65 return BOOT_DEVICE_SPI;
66 case IMX6_BMODE_I2C1:
67 case IMX6_BMODE_I2C2:
68 case IMX6_BMODE_I2C3:
69 return BOOT_DEVICE_I2C;
70 }
71 break;
72 /* SD/eSD: 8.5.3, Table 8-15 */
73 case IMX6_BMODE_SD:
74 case IMX6_BMODE_ESD:
75 return BOOT_DEVICE_MMC1;
76 /* MMC/eMMC: 8.5.3 */
77 case IMX6_BMODE_MMC:
78 case IMX6_BMODE_EMMC:
79 return BOOT_DEVICE_MMC1;
80 /* NAND Flash: 8.5.2, Table 8-10 */
81 case IMX6_BMODE_NAND:
82 return BOOT_DEVICE_NAND;
83 }
84 return BOOT_DEVICE_NONE;
85 }
86
87 #ifdef CONFIG_SPL_USB_GADGET
g_dnl_bind_fixup(struct usb_device_descriptor * dev,const char * name)88 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
89 {
90 put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM + 0xfff, &dev->idProduct);
91
92 return 0;
93 }
94 #endif
95 #endif
96
97 #if defined(CONFIG_SPL_MMC_SUPPORT)
98 /* called from spl_mmc to see type of boot mode for storage (RAW or FAT) */
spl_boot_mode(const u32 boot_device)99 u32 spl_boot_mode(const u32 boot_device)
100 {
101 switch (spl_boot_device()) {
102 /* for MMC return either RAW or FAT mode */
103 case BOOT_DEVICE_MMC1:
104 case BOOT_DEVICE_MMC2:
105 #if defined(CONFIG_SPL_FAT_SUPPORT)
106 return MMCSD_MODE_FS;
107 #elif defined(CONFIG_SUPPORT_EMMC_BOOT)
108 return MMCSD_MODE_EMMCBOOT;
109 #else
110 return MMCSD_MODE_RAW;
111 #endif
112 break;
113 default:
114 puts("spl: ERROR: unsupported device\n");
115 hang();
116 }
117 }
118 #endif
119
120 #if defined(CONFIG_SECURE_BOOT)
121
jump_to_image_no_args(struct spl_image_info * spl_image)122 __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
123 {
124 typedef void __noreturn (*image_entry_noargs_t)(void);
125
126 image_entry_noargs_t image_entry =
127 (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
128
129 debug("image entry point: 0x%lX\n", spl_image->entry_point);
130
131 /* HAB looks for the CSF at the end of the authenticated data therefore,
132 * we need to subtract the size of the CSF from the actual filesize */
133 if (authenticate_image(spl_image->load_addr,
134 spl_image->size - CONFIG_CSF_SIZE)) {
135 image_entry();
136 } else {
137 puts("spl: ERROR: image authentication unsuccessful\n");
138 hang();
139 }
140 }
141
142 #endif
143
144 #if defined(CONFIG_MX6) && defined(CONFIG_SPL_OS_BOOT)
dram_init_banksize(void)145 int dram_init_banksize(void)
146 {
147 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
148 gd->bd->bi_dram[0].size = imx_ddr_size();
149
150 return 0;
151 }
152 #endif
153