blob: fdb8b479ea014b3d172481c94045c29c9c97fcaa [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>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Tom Rini28591df2012-08-13 12:03:19 -070013#include <spl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000015#include <asm/omap_common.h>
16#include <asm/arch/omap.h>
Tom Rinia0b9fa52012-08-14 10:25:15 -070017#include <asm/arch/mmc_host_def.h>
Ilya Yanok741c57f2012-11-06 13:06:28 +000018#include <asm/arch/sys_proto.h>
Tom Rini303bfe82013-10-01 12:32:04 -040019#include <watchdog.h>
Dmitry Lifshitz29211a02014-12-15 16:02:58 +020020#include <scsi.h>
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020021#include <i2c.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000022
SRICHARAN R3f30b0a2013-04-24 00:41:24 +000023DECLARE_GLOBAL_DATA_PTR;
Chandan Nath77a73fe2012-01-09 20:38:59 +000024
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020025__weak u32 omap_sys_boot_device(void)
26{
27 return BOOT_DEVICE_NONE;
28}
29
Tom Rini51df26c2013-05-31 12:31:59 -040030void save_omap_boot_params(void)
31{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020032 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
33 struct omap_boot_parameters *omap_boot_params;
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +020034 int sys_boot_device = 0;
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020035 u32 boot_device;
36 u32 boot_mode;
Tom Rini51df26c2013-05-31 12:31:59 -040037
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020038 if ((boot_params < NON_SECURE_SRAM_START) ||
39 (boot_params > NON_SECURE_SRAM_END))
Tom Rini51df26c2013-05-31 12:31:59 -040040 return;
41
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020042 omap_boot_params = (struct omap_boot_parameters *)boot_params;
Stefan Roese0f3a4802014-11-12 11:57:33 +010043
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020044 boot_device = omap_boot_params->boot_device;
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020045 boot_mode = MMCSD_MODE_UNDEFINED;
46
47 /* Boot device */
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020048
49#ifdef BOOT_DEVICE_NAND_I2C
Stefan Roese0f3a4802014-11-12 11:57:33 +010050 /*
51 * Re-map NAND&I2C boot-device to the "normal" NAND boot-device.
52 * Otherwise the SPL boot IF can't handle this device correctly.
53 * Somehow booting with Hynix 4GBit NAND H27U4G8 on Siemens
54 * Draco leads to this boot-device passed to SPL from the BootROM.
55 */
56 if (boot_device == BOOT_DEVICE_NAND_I2C)
57 boot_device = BOOT_DEVICE_NAND;
58#endif
Paul Kocialkowskib16d6d52015-07-15 16:02:21 +020059#ifdef BOOT_DEVICE_QSPI_4
Tom Rini560ef452014-04-03 07:52:56 -040060 /*
61 * We get different values for QSPI_1 and QSPI_4 being used, but
62 * don't actually care about this difference. Rather than
63 * mangle the later code, if we're coming in as QSPI_4 just
64 * change to the QSPI_1 value.
65 */
Paul Kocialkowskib16d6d52015-07-15 16:02:21 +020066 if (boot_device == BOOT_DEVICE_QSPI_4)
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020067 boot_device = BOOT_DEVICE_SPI;
68#endif
Tom Rinid00abb12017-06-15 13:57:00 -040069#ifdef CONFIG_TI816X
70 /*
71 * On PG2.0 and later TI816x the values we get when booting are not the
72 * same as on PG1.0, which is what the defines are based on. Update
73 * them as needed.
74 */
75 if (get_cpu_rev() != 1) {
76 if (boot_device == 0x05) {
77 omap_boot_params->boot_device = BOOT_DEVICE_NAND;
78 boot_device = BOOT_DEVICE_NAND;
79 }
80 if (boot_device == 0x08) {
81 omap_boot_params->boot_device = BOOT_DEVICE_MMC1;
82 boot_device = BOOT_DEVICE_MMC1;
83 }
84 }
85#endif
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020086 /*
87 * When booting from peripheral booting, the boot device is not usable
88 * as-is (unless there is support for it), so the boot device is instead
89 * figured out using the SYS_BOOT pins.
90 */
91 switch (boot_device) {
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +020092#if defined(BOOT_DEVICE_UART) && !defined(CONFIG_SPL_YMODEM_SUPPORT)
93 case BOOT_DEVICE_UART:
94 sys_boot_device = 1;
95 break;
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020096#endif
Abel Vesa5ea11ba52019-02-01 16:40:07 +000097#if defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_STORAGE)
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +020098 case BOOT_DEVICE_USB:
99 sys_boot_device = 1;
100 break;
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200101#endif
Faiz Abbasc01553b2018-02-16 21:17:44 +0530102#if defined(BOOT_DEVICE_USBETH) && !defined(CONFIG_SPL_USB_ETHER)
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +0200103 case BOOT_DEVICE_USBETH:
104 sys_boot_device = 1;
105 break;
106#endif
Simon Glasse5cd9a42021-07-10 21:14:26 -0600107#if defined(BOOT_DEVICE_CPGMAC) && !defined(CONFIG_SPL_ETH)
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +0200108 case BOOT_DEVICE_CPGMAC:
109 sys_boot_device = 1;
110 break;
111#endif
Andrew F. Davis6d932e62019-01-17 13:43:02 -0600112#if defined(BOOT_DEVICE_DFU) && !defined(CONFIG_SPL_DFU)
B, Ravi2fb19df2016-07-28 17:39:17 +0530113 case BOOT_DEVICE_DFU:
114 sys_boot_device = 1;
115 break;
116#endif
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +0200117 }
118
119 if (sys_boot_device) {
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200120 boot_device = omap_sys_boot_device();
121
122 /* MMC raw mode will fallback to FS mode. */
123 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
124 (boot_device <= MMC_BOOT_DEVICES_END))
125 boot_mode = MMCSD_MODE_RAW;
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200126 }
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200127
128 gd->arch.omap_boot_device = boot_device;
129
130 /* Boot mode */
131
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200132#ifdef CONFIG_OMAP34XX
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200133 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
134 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200135 switch (boot_device) {
136 case BOOT_DEVICE_MMC1:
Tom Rini9266bf42016-05-02 10:52:51 -0400137 boot_mode = MMCSD_MODE_FS;
138 break;
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200139 case BOOT_DEVICE_MMC2:
140 boot_mode = MMCSD_MODE_RAW;
141 break;
142 }
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200143 }
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200144#else
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200145 /*
146 * If the boot device was dynamically changed and doesn't match what
147 * the bootrom initially booted, we cannot use the boot device
148 * descriptor to figure out the boot mode.
149 */
150 if ((boot_device == omap_boot_params->boot_device) &&
151 (boot_device >= MMC_BOOT_DEVICES_START) &&
152 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200153 boot_params = omap_boot_params->boot_device_descriptor;
154 if ((boot_params < NON_SECURE_SRAM_START) ||
155 (boot_params > NON_SECURE_SRAM_END))
156 return;
157
158 boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET));
159 if ((boot_params < NON_SECURE_SRAM_START) ||
160 (boot_params > NON_SECURE_SRAM_END))
161 return;
162
163 boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET));
164
165 if (boot_mode != MMCSD_MODE_FS &&
166 boot_mode != MMCSD_MODE_RAW)
167#ifdef CONFIG_SUPPORT_EMMC_BOOT
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200168 boot_mode = MMCSD_MODE_EMMCBOOT;
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200169#else
170 boot_mode = MMCSD_MODE_UNDEFINED;
171#endif
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200172 }
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200173#endif
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200174
175 gd->arch.omap_boot_mode = boot_mode;
176
177#if !defined(CONFIG_TI814X) && !defined(CONFIG_TI816X) && \
178 !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX)
179
180 /* CH flags */
181
182 gd->arch.omap_ch_flags = omap_boot_params->ch_flags;
Tom Rini560ef452014-04-03 07:52:56 -0400183#endif
Tom Rini51df26c2013-05-31 12:31:59 -0400184}
185
Chandan Nath77a73fe2012-01-09 20:38:59 +0000186#ifdef CONFIG_SPL_BUILD
Tom Rini0be93ff2012-08-13 12:53:23 -0700187u32 spl_boot_device(void)
Chandan Nath77a73fe2012-01-09 20:38:59 +0000188{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200189 return gd->arch.omap_boot_device;
Chandan Nath77a73fe2012-01-09 20:38:59 +0000190}
191
Harald Seiler0bf7ab12020-04-15 11:33:30 +0200192u32 spl_mmc_boot_mode(const u32 boot_device)
Chandan Nath77a73fe2012-01-09 20:38:59 +0000193{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200194 return gd->arch.omap_boot_mode;
Chandan Nath77a73fe2012-01-09 20:38:59 +0000195}
Tom Rinia0b9fa52012-08-14 10:25:15 -0700196
Tom Rini9e0c2602012-08-14 12:26:08 -0700197void spl_board_init(void)
198{
Tom Rinic95d6c42014-12-19 16:53:24 -0500199 /* Prepare console output */
200 preloader_console_init();
Samuel Hollandb03e6662020-05-07 18:08:10 -0500201
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200202#if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
Tom Rini9e0c2602012-08-14 12:26:08 -0700203 gpmc_init();
204#endif
Simon Glassbccfc2e2021-07-10 21:14:36 -0600205#if defined(CONFIG_SPL_I2C) && !CONFIG_IS_ENABLED(DM_I2C)
Tom Rinia7a9bc02021-08-18 23:12:29 -0400206 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200207#endif
Simon Glass762b9972021-07-10 21:14:27 -0600208#if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW)
Ilya Yanok87b82cc2013-02-05 11:36:25 +0000209 arch_misc_init();
210#endif
Suniel Mahesh370d4912019-07-31 21:54:07 +0530211#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
Tom Rini303bfe82013-10-01 12:32:04 -0400212 hw_watchdog_init();
213#endif
Tom Riniac8fdf92013-08-30 16:28:44 -0400214#ifdef CONFIG_AM33XX
215 am33xx_spl_board_init();
216#endif
Tom Rini9e0c2602012-08-14 12:26:08 -0700217}
218
SRICHARAN R3f30b0a2013-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 Kocialkowskid5b76242015-07-15 16:02:19 +0200225 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
226
Andre Przywara6c526072017-01-02 11:48:31 +0000227 debug("image entry point: 0x%lX\n", spl_image->entry_point);
SRICHARAN R3f30b0a2013-04-24 00:41:24 +0000228 /* Pass the saved boot_params from rom code */
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200229 image_entry((u32 *)boot_params);
SRICHARAN R3f30b0a2013-04-24 00:41:24 +0000230}
Chandan Nath77a73fe2012-01-09 20:38:59 +0000231#endif
Dmitry Lifshitz29211a02014-12-15 16:02:58 +0200232
233#ifdef CONFIG_SCSI_AHCI_PLAT
234void arch_preboot_os(void)
235{
Scott Wood16519a32015-04-17 09:19:01 -0500236 ahci_reset((void __iomem *)DWC_AHSATA_BASE);
Dmitry Lifshitz29211a02014-12-15 16:02:58 +0200237}
238#endif