blob: 734fa9d9e6f78e0c13914411c095f4c26738eef3 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Chandan Nath8a8f0842012-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 Nath8a8f0842012-01-09 20:38:59 +00008 */
9
10#include <common.h>
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +020011#include <ahci.h>
Tom Rini47f7bca2012-08-13 12:03:19 -070012#include <spl.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000013#include <asm/omap_common.h>
14#include <asm/arch/omap.h>
Tom Rinif0881252012-08-14 10:25:15 -070015#include <asm/arch/mmc_host_def.h>
Ilya Yanok1befaff2012-11-06 13:06:28 +000016#include <asm/arch/sys_proto.h>
Tom Rini68439182013-10-01 12:32:04 -040017#include <watchdog.h>
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +020018#include <scsi.h>
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020019#include <i2c.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000020
SRICHARAN R4a0eb752013-04-24 00:41:24 +000021DECLARE_GLOBAL_DATA_PTR;
Chandan Nath8a8f0842012-01-09 20:38:59 +000022
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020023__weak u32 omap_sys_boot_device(void)
24{
25 return BOOT_DEVICE_NONE;
26}
27
Tom Rini4596dcc2013-05-31 12:31:59 -040028void save_omap_boot_params(void)
29{
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020030 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
31 struct omap_boot_parameters *omap_boot_params;
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +020032 int sys_boot_device = 0;
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020033 u32 boot_device;
34 u32 boot_mode;
Tom Rini4596dcc2013-05-31 12:31:59 -040035
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020036 if ((boot_params < NON_SECURE_SRAM_START) ||
37 (boot_params > NON_SECURE_SRAM_END))
Tom Rini4596dcc2013-05-31 12:31:59 -040038 return;
39
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020040 omap_boot_params = (struct omap_boot_parameters *)boot_params;
Stefan Roesee49631a2014-11-12 11:57:33 +010041
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020042 boot_device = omap_boot_params->boot_device;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020043 boot_mode = MMCSD_MODE_UNDEFINED;
44
45 /* Boot device */
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020046
47#ifdef BOOT_DEVICE_NAND_I2C
Stefan Roesee49631a2014-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 Kocialkowskidf844772015-07-15 16:02:21 +020057#ifdef BOOT_DEVICE_QSPI_4
Tom Rini79b079f2014-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 Kocialkowskidf844772015-07-15 16:02:21 +020064 if (boot_device == BOOT_DEVICE_QSPI_4)
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020065 boot_device = BOOT_DEVICE_SPI;
66#endif
Tom Rini207f9812017-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 Kocialkowskied19bda2015-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 Kocialkowski8ceb34a2015-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 Kocialkowskied19bda2015-07-15 16:02:23 +020094#endif
Abel Vesa79536012019-02-01 16:40:07 +000095#if defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_STORAGE)
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +020096 case BOOT_DEVICE_USB:
97 sys_boot_device = 1;
98 break;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020099#endif
Faiz Abbasb432b1e2018-02-16 21:17:44 +0530100#if defined(BOOT_DEVICE_USBETH) && !defined(CONFIG_SPL_USB_ETHER)
Paul Kocialkowski8ceb34a2015-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. Davis6536ca42019-01-17 13:43:02 -0600110#if defined(BOOT_DEVICE_DFU) && !defined(CONFIG_SPL_DFU)
B, Ravi6f8387f2016-07-28 17:39:17 +0530111 case BOOT_DEVICE_DFU:
112 sys_boot_device = 1;
113 break;
114#endif
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +0200115 }
116
117 if (sys_boot_device) {
Paul Kocialkowskied19bda2015-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 Kocialkowskied19bda2015-07-15 16:02:23 +0200124 }
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200125
126 gd->arch.omap_boot_device = boot_device;
127
128 /* Boot mode */
129
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200130#ifdef CONFIG_OMAP34XX
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200131 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
132 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200133 switch (boot_device) {
134 case BOOT_DEVICE_MMC1:
Tom Rini821c89d2016-05-02 10:52:51 -0400135 boot_mode = MMCSD_MODE_FS;
136 break;
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200137 case BOOT_DEVICE_MMC2:
138 boot_mode = MMCSD_MODE_RAW;
139 break;
140 }
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200141 }
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200142#else
Paul Kocialkowskied19bda2015-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 Kocialkowski60c7c302015-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 Kocialkowskied19bda2015-07-15 16:02:23 +0200166 boot_mode = MMCSD_MODE_EMMCBOOT;
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200167#else
168 boot_mode = MMCSD_MODE_UNDEFINED;
169#endif
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200170 }
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200171#endif
Paul Kocialkowski60c7c302015-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 Rini79b079f2014-04-03 07:52:56 -0400181#endif
Tom Rini4596dcc2013-05-31 12:31:59 -0400182}
183
Chandan Nath8a8f0842012-01-09 20:38:59 +0000184#ifdef CONFIG_SPL_BUILD
Tom Rini8e1b8362012-08-13 12:53:23 -0700185u32 spl_boot_device(void)
Chandan Nath8a8f0842012-01-09 20:38:59 +0000186{
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200187 return gd->arch.omap_boot_device;
Chandan Nath8a8f0842012-01-09 20:38:59 +0000188}
189
Marek Vasut2b1cdaf2016-05-14 23:42:07 +0200190u32 spl_boot_mode(const u32 boot_device)
Chandan Nath8a8f0842012-01-09 20:38:59 +0000191{
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200192 return gd->arch.omap_boot_mode;
Chandan Nath8a8f0842012-01-09 20:38:59 +0000193}
Tom Rinif0881252012-08-14 10:25:15 -0700194
Tom Rinid7cb93b2012-08-14 12:26:08 -0700195void spl_board_init(void)
196{
Alex Kiernan117a0e02018-04-19 04:32:51 +0000197#ifdef CONFIG_SPL_SERIAL_SUPPORT
Tom Rinia6b541b2014-12-19 16:53:24 -0500198 /* Prepare console output */
199 preloader_console_init();
Alex Kiernan117a0e02018-04-19 04:32:51 +0000200#endif
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200201#if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
Tom Rinid7cb93b2012-08-14 12:26:08 -0700202 gpmc_init();
203#endif
Adam Ford66814612018-08-20 20:34:00 -0500204#if defined(CONFIG_SPL_I2C_SUPPORT) && !defined(CONFIG_DM_I2C)
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200205 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
206#endif
Ilya Yanokda07c212013-02-05 11:36:25 +0000207#if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
208 arch_misc_init();
209#endif
Suniel Mahesh6912f2a2019-07-31 21:54:07 +0530210#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
Tom Rini68439182013-10-01 12:32:04 -0400211 hw_watchdog_init();
212#endif
Tom Rini6a0d8032013-08-30 16:28:44 -0400213#ifdef CONFIG_AM33XX
214 am33xx_spl_board_init();
215#endif
Tom Rinid7cb93b2012-08-14 12:26:08 -0700216}
217
SRICHARAN R4a0eb752013-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 Kocialkowski60c7c302015-07-15 16:02:19 +0200224 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
225
Andre Przywara11e14792017-01-02 11:48:31 +0000226 debug("image entry point: 0x%lX\n", spl_image->entry_point);
SRICHARAN R4a0eb752013-04-24 00:41:24 +0000227 /* Pass the saved boot_params from rom code */
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200228 image_entry((u32 *)boot_params);
SRICHARAN R4a0eb752013-04-24 00:41:24 +0000229}
Chandan Nath8a8f0842012-01-09 20:38:59 +0000230#endif
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +0200231
232#ifdef CONFIG_SCSI_AHCI_PLAT
233void arch_preboot_os(void)
234{
Scott Wood9efaca32015-04-17 09:19:01 -0500235 ahci_reset((void __iomem *)DWC_AHSATA_BASE);
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +0200236}
237#endif