blob: 7538523724316e85c9018f616a874aae2b953e02 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Chandan Nath77a73fe2012-01-09 20:38:59 +00002/*
3 * boot-common.c
4 *
5 * Common bootmode functions for omap based boards
6 *
7 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
Chandan Nath77a73fe2012-01-09 20:38:59 +00008 */
9
10#include <common.h>
Dmitry Lifshitz29211a02014-12-15 16:02:58 +020011#include <ahci.h>
Tom Rini28591df2012-08-13 12:03:19 -070012#include <spl.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000013#include <asm/omap_common.h>
14#include <asm/arch/omap.h>
Tom Rinia0b9fa52012-08-14 10:25:15 -070015#include <asm/arch/mmc_host_def.h>
Ilya Yanok741c57f2012-11-06 13:06:28 +000016#include <asm/arch/sys_proto.h>
Tom Rini303bfe82013-10-01 12:32:04 -040017#include <watchdog.h>
Dmitry Lifshitz29211a02014-12-15 16:02:58 +020018#include <scsi.h>
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020019#include <i2c.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000020
SRICHARAN R3f30b0a2013-04-24 00:41:24 +000021DECLARE_GLOBAL_DATA_PTR;
Chandan Nath77a73fe2012-01-09 20:38:59 +000022
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020023__weak u32 omap_sys_boot_device(void)
24{
25 return BOOT_DEVICE_NONE;
26}
27
Tom Rini51df26c2013-05-31 12:31:59 -040028void save_omap_boot_params(void)
29{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020030 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
31 struct omap_boot_parameters *omap_boot_params;
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +020032 int sys_boot_device = 0;
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020033 u32 boot_device;
34 u32 boot_mode;
Tom Rini51df26c2013-05-31 12:31:59 -040035
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020036 if ((boot_params < NON_SECURE_SRAM_START) ||
37 (boot_params > NON_SECURE_SRAM_END))
Tom Rini51df26c2013-05-31 12:31:59 -040038 return;
39
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020040 omap_boot_params = (struct omap_boot_parameters *)boot_params;
Stefan Roese0f3a4802014-11-12 11:57:33 +010041
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020042 boot_device = omap_boot_params->boot_device;
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020043 boot_mode = MMCSD_MODE_UNDEFINED;
44
45 /* Boot device */
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020046
47#ifdef BOOT_DEVICE_NAND_I2C
Stefan Roese0f3a4802014-11-12 11:57:33 +010048 /*
49 * Re-map NAND&I2C boot-device to the "normal" NAND boot-device.
50 * Otherwise the SPL boot IF can't handle this device correctly.
51 * Somehow booting with Hynix 4GBit NAND H27U4G8 on Siemens
52 * Draco leads to this boot-device passed to SPL from the BootROM.
53 */
54 if (boot_device == BOOT_DEVICE_NAND_I2C)
55 boot_device = BOOT_DEVICE_NAND;
56#endif
Paul Kocialkowskib16d6d52015-07-15 16:02:21 +020057#ifdef BOOT_DEVICE_QSPI_4
Tom Rini560ef452014-04-03 07:52:56 -040058 /*
59 * We get different values for QSPI_1 and QSPI_4 being used, but
60 * don't actually care about this difference. Rather than
61 * mangle the later code, if we're coming in as QSPI_4 just
62 * change to the QSPI_1 value.
63 */
Paul Kocialkowskib16d6d52015-07-15 16:02:21 +020064 if (boot_device == BOOT_DEVICE_QSPI_4)
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020065 boot_device = BOOT_DEVICE_SPI;
66#endif
Tom Rinid00abb12017-06-15 13:57:00 -040067#ifdef CONFIG_TI816X
68 /*
69 * On PG2.0 and later TI816x the values we get when booting are not the
70 * same as on PG1.0, which is what the defines are based on. Update
71 * them as needed.
72 */
73 if (get_cpu_rev() != 1) {
74 if (boot_device == 0x05) {
75 omap_boot_params->boot_device = BOOT_DEVICE_NAND;
76 boot_device = BOOT_DEVICE_NAND;
77 }
78 if (boot_device == 0x08) {
79 omap_boot_params->boot_device = BOOT_DEVICE_MMC1;
80 boot_device = BOOT_DEVICE_MMC1;
81 }
82 }
83#endif
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020084 /*
85 * When booting from peripheral booting, the boot device is not usable
86 * as-is (unless there is support for it), so the boot device is instead
87 * figured out using the SYS_BOOT pins.
88 */
89 switch (boot_device) {
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +020090#if defined(BOOT_DEVICE_UART) && !defined(CONFIG_SPL_YMODEM_SUPPORT)
91 case BOOT_DEVICE_UART:
92 sys_boot_device = 1;
93 break;
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020094#endif
Abel Vesa5ea11ba52019-02-01 16:40:07 +000095#if defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_STORAGE)
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +020096 case BOOT_DEVICE_USB:
97 sys_boot_device = 1;
98 break;
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020099#endif
Faiz Abbasc01553b2018-02-16 21:17:44 +0530100#if defined(BOOT_DEVICE_USBETH) && !defined(CONFIG_SPL_USB_ETHER)
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +0200101 case BOOT_DEVICE_USBETH:
102 sys_boot_device = 1;
103 break;
104#endif
105#if defined(BOOT_DEVICE_CPGMAC) && !defined(CONFIG_SPL_ETH_SUPPORT)
106 case BOOT_DEVICE_CPGMAC:
107 sys_boot_device = 1;
108 break;
109#endif
Andrew F. Davis6d932e62019-01-17 13:43:02 -0600110#if defined(BOOT_DEVICE_DFU) && !defined(CONFIG_SPL_DFU)
B, Ravi2fb19df2016-07-28 17:39:17 +0530111 case BOOT_DEVICE_DFU:
112 sys_boot_device = 1;
113 break;
114#endif
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +0200115 }
116
117 if (sys_boot_device) {
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200118 boot_device = omap_sys_boot_device();
119
120 /* MMC raw mode will fallback to FS mode. */
121 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
122 (boot_device <= MMC_BOOT_DEVICES_END))
123 boot_mode = MMCSD_MODE_RAW;
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200124 }
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200125
126 gd->arch.omap_boot_device = boot_device;
127
128 /* Boot mode */
129
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200130#ifdef CONFIG_OMAP34XX
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200131 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
132 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200133 switch (boot_device) {
134 case BOOT_DEVICE_MMC1:
Tom Rini9266bf42016-05-02 10:52:51 -0400135 boot_mode = MMCSD_MODE_FS;
136 break;
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200137 case BOOT_DEVICE_MMC2:
138 boot_mode = MMCSD_MODE_RAW;
139 break;
140 }
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200141 }
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200142#else
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200143 /*
144 * If the boot device was dynamically changed and doesn't match what
145 * the bootrom initially booted, we cannot use the boot device
146 * descriptor to figure out the boot mode.
147 */
148 if ((boot_device == omap_boot_params->boot_device) &&
149 (boot_device >= MMC_BOOT_DEVICES_START) &&
150 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200151 boot_params = omap_boot_params->boot_device_descriptor;
152 if ((boot_params < NON_SECURE_SRAM_START) ||
153 (boot_params > NON_SECURE_SRAM_END))
154 return;
155
156 boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET));
157 if ((boot_params < NON_SECURE_SRAM_START) ||
158 (boot_params > NON_SECURE_SRAM_END))
159 return;
160
161 boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET));
162
163 if (boot_mode != MMCSD_MODE_FS &&
164 boot_mode != MMCSD_MODE_RAW)
165#ifdef CONFIG_SUPPORT_EMMC_BOOT
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200166 boot_mode = MMCSD_MODE_EMMCBOOT;
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200167#else
168 boot_mode = MMCSD_MODE_UNDEFINED;
169#endif
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200170 }
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200171#endif
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200172
173 gd->arch.omap_boot_mode = boot_mode;
174
175#if !defined(CONFIG_TI814X) && !defined(CONFIG_TI816X) && \
176 !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX)
177
178 /* CH flags */
179
180 gd->arch.omap_ch_flags = omap_boot_params->ch_flags;
Tom Rini560ef452014-04-03 07:52:56 -0400181#endif
Tom Rini51df26c2013-05-31 12:31:59 -0400182}
183
Chandan Nath77a73fe2012-01-09 20:38:59 +0000184#ifdef CONFIG_SPL_BUILD
Tom Rini0be93ff2012-08-13 12:53:23 -0700185u32 spl_boot_device(void)
Chandan Nath77a73fe2012-01-09 20:38:59 +0000186{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200187 return gd->arch.omap_boot_device;
Chandan Nath77a73fe2012-01-09 20:38:59 +0000188}
189
Harald Seiler0bf7ab12020-04-15 11:33:30 +0200190u32 spl_mmc_boot_mode(const u32 boot_device)
Chandan Nath77a73fe2012-01-09 20:38:59 +0000191{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200192 return gd->arch.omap_boot_mode;
Chandan Nath77a73fe2012-01-09 20:38:59 +0000193}
Tom Rinia0b9fa52012-08-14 10:25:15 -0700194
Tom Rini9e0c2602012-08-14 12:26:08 -0700195void spl_board_init(void)
196{
Alex Kiernanb09f8922018-04-19 04:32:51 +0000197#ifdef CONFIG_SPL_SERIAL_SUPPORT
Tom Rinic95d6c42014-12-19 16:53:24 -0500198 /* Prepare console output */
199 preloader_console_init();
Alex Kiernanb09f8922018-04-19 04:32:51 +0000200#endif
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200201#if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
Tom Rini9e0c2602012-08-14 12:26:08 -0700202 gpmc_init();
203#endif
Adam Ford494b9682018-08-20 20:34:00 -0500204#if defined(CONFIG_SPL_I2C_SUPPORT) && !defined(CONFIG_DM_I2C)
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200205 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
206#endif
Ilya Yanok87b82cc2013-02-05 11:36:25 +0000207#if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
208 arch_misc_init();
209#endif
Suniel Mahesh370d4912019-07-31 21:54:07 +0530210#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
Tom Rini303bfe82013-10-01 12:32:04 -0400211 hw_watchdog_init();
212#endif
Tom Riniac8fdf92013-08-30 16:28:44 -0400213#ifdef CONFIG_AM33XX
214 am33xx_spl_board_init();
215#endif
Tom Rini9e0c2602012-08-14 12:26:08 -0700216}
217
SRICHARAN R3f30b0a2013-04-24 00:41:24 +0000218void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
219{
220 typedef void __noreturn (*image_entry_noargs_t)(u32 *);
221 image_entry_noargs_t image_entry =
222 (image_entry_noargs_t) spl_image->entry_point;
223
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200224 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
225
Andre Przywara6c526072017-01-02 11:48:31 +0000226 debug("image entry point: 0x%lX\n", spl_image->entry_point);
SRICHARAN R3f30b0a2013-04-24 00:41:24 +0000227 /* Pass the saved boot_params from rom code */
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200228 image_entry((u32 *)boot_params);
SRICHARAN R3f30b0a2013-04-24 00:41:24 +0000229}
Chandan Nath77a73fe2012-01-09 20:38:59 +0000230#endif
Dmitry Lifshitz29211a02014-12-15 16:02:58 +0200231
232#ifdef CONFIG_SCSI_AHCI_PLAT
233void arch_preboot_os(void)
234{
Scott Wood16519a32015-04-17 09:19:01 -0500235 ahci_reset((void __iomem *)DWC_AHSATA_BASE);
Dmitry Lifshitz29211a02014-12-15 16:02:58 +0200236}
237#endif