blob: c8b8ac657fbff3abed5a5d1ad9be851ed97076db [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>
Simon Glass01510092017-08-03 12:22:08 -060012#include <environment.h>
Tom Rini47f7bca2012-08-13 12:03:19 -070013#include <spl.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000014#include <asm/omap_common.h>
15#include <asm/arch/omap.h>
Tom Rinif0881252012-08-14 10:25:15 -070016#include <asm/arch/mmc_host_def.h>
Ilya Yanok1befaff2012-11-06 13:06:28 +000017#include <asm/arch/sys_proto.h>
Tom Rini68439182013-10-01 12:32:04 -040018#include <watchdog.h>
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +020019#include <scsi.h>
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020020#include <i2c.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000021
SRICHARAN R4a0eb752013-04-24 00:41:24 +000022DECLARE_GLOBAL_DATA_PTR;
Chandan Nath8a8f0842012-01-09 20:38:59 +000023
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020024__weak u32 omap_sys_boot_device(void)
25{
26 return BOOT_DEVICE_NONE;
27}
28
Tom Rini4596dcc2013-05-31 12:31:59 -040029void save_omap_boot_params(void)
30{
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020031 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
32 struct omap_boot_parameters *omap_boot_params;
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +020033 int sys_boot_device = 0;
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020034 u32 boot_device;
35 u32 boot_mode;
Tom Rini4596dcc2013-05-31 12:31:59 -040036
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020037 if ((boot_params < NON_SECURE_SRAM_START) ||
38 (boot_params > NON_SECURE_SRAM_END))
Tom Rini4596dcc2013-05-31 12:31:59 -040039 return;
40
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020041 omap_boot_params = (struct omap_boot_parameters *)boot_params;
Stefan Roesee49631a2014-11-12 11:57:33 +010042
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020043 boot_device = omap_boot_params->boot_device;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020044 boot_mode = MMCSD_MODE_UNDEFINED;
45
46 /* Boot device */
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020047
48#ifdef BOOT_DEVICE_NAND_I2C
Stefan Roesee49631a2014-11-12 11:57:33 +010049 /*
50 * Re-map NAND&I2C boot-device to the "normal" NAND boot-device.
51 * Otherwise the SPL boot IF can't handle this device correctly.
52 * Somehow booting with Hynix 4GBit NAND H27U4G8 on Siemens
53 * Draco leads to this boot-device passed to SPL from the BootROM.
54 */
55 if (boot_device == BOOT_DEVICE_NAND_I2C)
56 boot_device = BOOT_DEVICE_NAND;
57#endif
Paul Kocialkowskidf844772015-07-15 16:02:21 +020058#ifdef BOOT_DEVICE_QSPI_4
Tom Rini79b079f2014-04-03 07:52:56 -040059 /*
60 * We get different values for QSPI_1 and QSPI_4 being used, but
61 * don't actually care about this difference. Rather than
62 * mangle the later code, if we're coming in as QSPI_4 just
63 * change to the QSPI_1 value.
64 */
Paul Kocialkowskidf844772015-07-15 16:02:21 +020065 if (boot_device == BOOT_DEVICE_QSPI_4)
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020066 boot_device = BOOT_DEVICE_SPI;
67#endif
Tom Rini207f9812017-06-15 13:57:00 -040068#ifdef CONFIG_TI816X
69 /*
70 * On PG2.0 and later TI816x the values we get when booting are not the
71 * same as on PG1.0, which is what the defines are based on. Update
72 * them as needed.
73 */
74 if (get_cpu_rev() != 1) {
75 if (boot_device == 0x05) {
76 omap_boot_params->boot_device = BOOT_DEVICE_NAND;
77 boot_device = BOOT_DEVICE_NAND;
78 }
79 if (boot_device == 0x08) {
80 omap_boot_params->boot_device = BOOT_DEVICE_MMC1;
81 boot_device = BOOT_DEVICE_MMC1;
82 }
83 }
84#endif
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020085 /*
86 * When booting from peripheral booting, the boot device is not usable
87 * as-is (unless there is support for it), so the boot device is instead
88 * figured out using the SYS_BOOT pins.
89 */
90 switch (boot_device) {
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +020091#if defined(BOOT_DEVICE_UART) && !defined(CONFIG_SPL_YMODEM_SUPPORT)
92 case BOOT_DEVICE_UART:
93 sys_boot_device = 1;
94 break;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020095#endif
Abel Vesa79536012019-02-01 16:40:07 +000096#if defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_STORAGE)
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +020097 case BOOT_DEVICE_USB:
98 sys_boot_device = 1;
99 break;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200100#endif
Faiz Abbasb432b1e2018-02-16 21:17:44 +0530101#if defined(BOOT_DEVICE_USBETH) && !defined(CONFIG_SPL_USB_ETHER)
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +0200102 case BOOT_DEVICE_USBETH:
103 sys_boot_device = 1;
104 break;
105#endif
106#if defined(BOOT_DEVICE_CPGMAC) && !defined(CONFIG_SPL_ETH_SUPPORT)
107 case BOOT_DEVICE_CPGMAC:
108 sys_boot_device = 1;
109 break;
110#endif
Andrew F. Davis6536ca42019-01-17 13:43:02 -0600111#if defined(BOOT_DEVICE_DFU) && !defined(CONFIG_SPL_DFU)
B, Ravi6f8387f2016-07-28 17:39:17 +0530112 case BOOT_DEVICE_DFU:
113 sys_boot_device = 1;
114 break;
115#endif
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +0200116 }
117
118 if (sys_boot_device) {
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200119 boot_device = omap_sys_boot_device();
120
121 /* MMC raw mode will fallback to FS mode. */
122 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
123 (boot_device <= MMC_BOOT_DEVICES_END))
124 boot_mode = MMCSD_MODE_RAW;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200125 }
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200126
127 gd->arch.omap_boot_device = boot_device;
128
129 /* Boot mode */
130
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200131#ifdef CONFIG_OMAP34XX
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200132 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
133 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200134 switch (boot_device) {
135 case BOOT_DEVICE_MMC1:
Tom Rini821c89d2016-05-02 10:52:51 -0400136 boot_mode = MMCSD_MODE_FS;
137 break;
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200138 case BOOT_DEVICE_MMC2:
139 boot_mode = MMCSD_MODE_RAW;
140 break;
141 }
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200142 }
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200143#else
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200144 /*
145 * If the boot device was dynamically changed and doesn't match what
146 * the bootrom initially booted, we cannot use the boot device
147 * descriptor to figure out the boot mode.
148 */
149 if ((boot_device == omap_boot_params->boot_device) &&
150 (boot_device >= MMC_BOOT_DEVICES_START) &&
151 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200152 boot_params = omap_boot_params->boot_device_descriptor;
153 if ((boot_params < NON_SECURE_SRAM_START) ||
154 (boot_params > NON_SECURE_SRAM_END))
155 return;
156
157 boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET));
158 if ((boot_params < NON_SECURE_SRAM_START) ||
159 (boot_params > NON_SECURE_SRAM_END))
160 return;
161
162 boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET));
163
164 if (boot_mode != MMCSD_MODE_FS &&
165 boot_mode != MMCSD_MODE_RAW)
166#ifdef CONFIG_SUPPORT_EMMC_BOOT
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200167 boot_mode = MMCSD_MODE_EMMCBOOT;
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200168#else
169 boot_mode = MMCSD_MODE_UNDEFINED;
170#endif
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200171 }
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200172#endif
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200173
174 gd->arch.omap_boot_mode = boot_mode;
175
176#if !defined(CONFIG_TI814X) && !defined(CONFIG_TI816X) && \
177 !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX)
178
179 /* CH flags */
180
181 gd->arch.omap_ch_flags = omap_boot_params->ch_flags;
Tom Rini79b079f2014-04-03 07:52:56 -0400182#endif
Tom Rini4596dcc2013-05-31 12:31:59 -0400183}
184
Chandan Nath8a8f0842012-01-09 20:38:59 +0000185#ifdef CONFIG_SPL_BUILD
Tom Rini8e1b8362012-08-13 12:53:23 -0700186u32 spl_boot_device(void)
Chandan Nath8a8f0842012-01-09 20:38:59 +0000187{
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200188 return gd->arch.omap_boot_device;
Chandan Nath8a8f0842012-01-09 20:38:59 +0000189}
190
Marek Vasut2b1cdaf2016-05-14 23:42:07 +0200191u32 spl_boot_mode(const u32 boot_device)
Chandan Nath8a8f0842012-01-09 20:38:59 +0000192{
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200193 return gd->arch.omap_boot_mode;
Chandan Nath8a8f0842012-01-09 20:38:59 +0000194}
Tom Rinif0881252012-08-14 10:25:15 -0700195
Tom Rinid7cb93b2012-08-14 12:26:08 -0700196void spl_board_init(void)
197{
Alex Kiernan117a0e02018-04-19 04:32:51 +0000198#ifdef CONFIG_SPL_SERIAL_SUPPORT
Tom Rinia6b541b2014-12-19 16:53:24 -0500199 /* Prepare console output */
200 preloader_console_init();
Alex Kiernan117a0e02018-04-19 04:32:51 +0000201#endif
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200202#if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
Tom Rinid7cb93b2012-08-14 12:26:08 -0700203 gpmc_init();
204#endif
Adam Ford66814612018-08-20 20:34:00 -0500205#if defined(CONFIG_SPL_I2C_SUPPORT) && !defined(CONFIG_DM_I2C)
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200206 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
207#endif
Ilya Yanokda07c212013-02-05 11:36:25 +0000208#if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
209 arch_misc_init();
210#endif
Tom Rini68439182013-10-01 12:32:04 -0400211#if defined(CONFIG_HW_WATCHDOG)
212 hw_watchdog_init();
213#endif
Tom Rini6a0d8032013-08-30 16:28:44 -0400214#ifdef CONFIG_AM33XX
215 am33xx_spl_board_init();
216#endif
Tom Rinid7cb93b2012-08-14 12:26:08 -0700217}
218
SRICHARAN R4a0eb752013-04-24 00:41:24 +0000219void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
220{
221 typedef void __noreturn (*image_entry_noargs_t)(u32 *);
222 image_entry_noargs_t image_entry =
223 (image_entry_noargs_t) spl_image->entry_point;
224
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200225 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
226
Andre Przywara11e14792017-01-02 11:48:31 +0000227 debug("image entry point: 0x%lX\n", spl_image->entry_point);
SRICHARAN R4a0eb752013-04-24 00:41:24 +0000228 /* Pass the saved boot_params from rom code */
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200229 image_entry((u32 *)boot_params);
SRICHARAN R4a0eb752013-04-24 00:41:24 +0000230}
Chandan Nath8a8f0842012-01-09 20:38:59 +0000231#endif
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +0200232
233#ifdef CONFIG_SCSI_AHCI_PLAT
234void arch_preboot_os(void)
235{
Scott Wood9efaca32015-04-17 09:19:01 -0500236 ahci_reset((void __iomem *)DWC_AHSATA_BASE);
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +0200237}
238#endif