blob: 5ec46fa14d5aad668f9ae3d0cddb5148a6f54e56 [file] [log] [blame]
Chandan Nath77a73fe2012-01-09 20:38:59 +00001/*
2 * boot-common.c
3 *
4 * Common bootmode functions for omap based boards
5 *
6 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Chandan Nath77a73fe2012-01-09 20:38:59 +00009 */
10
11#include <common.h>
Dmitry Lifshitz29211a02014-12-15 16:02:58 +020012#include <ahci.h>
Tom Rini28591df2012-08-13 12:03:19 -070013#include <spl.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000014#include <asm/omap_common.h>
15#include <asm/arch/omap.h>
Tom Rinia0b9fa52012-08-14 10:25:15 -070016#include <asm/arch/mmc_host_def.h>
Ilya Yanok741c57f2012-11-06 13:06:28 +000017#include <asm/arch/sys_proto.h>
Tom Rini303bfe82013-10-01 12:32:04 -040018#include <watchdog.h>
Dmitry Lifshitz29211a02014-12-15 16:02:58 +020019#include <scsi.h>
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020020#include <i2c.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000021
SRICHARAN R3f30b0a2013-04-24 00:41:24 +000022DECLARE_GLOBAL_DATA_PTR;
Chandan Nath77a73fe2012-01-09 20:38:59 +000023
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020024__weak u32 omap_sys_boot_device(void)
25{
26 return BOOT_DEVICE_NONE;
27}
28
Tom Rini51df26c2013-05-31 12:31:59 -040029void save_omap_boot_params(void)
30{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020031 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
32 struct omap_boot_parameters *omap_boot_params;
33 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
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020067#if (defined(BOOT_DEVICE_UART) && !defined(CONFIG_SPL_YMODEM_SUPPORT)) || \
68 (defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_SUPPORT)) || \
69 (defined(BOOT_DEVICE_USBETH) && !defined(CONFIG_SPL_USBETH_SUPPORT))
70 /*
71 * When booting from peripheral booting, the boot device is not usable
72 * as-is (unless there is support for it), so the boot device is instead
73 * figured out using the SYS_BOOT pins.
74 */
75 switch (boot_device) {
76#ifdef BOOT_DEVICE_UART
77 case BOOT_DEVICE_UART:
78#endif
79#ifdef BOOT_DEVICE_USB
80 case BOOT_DEVICE_USB:
81#endif
82 boot_device = omap_sys_boot_device();
83
84 /* MMC raw mode will fallback to FS mode. */
85 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
86 (boot_device <= MMC_BOOT_DEVICES_END))
87 boot_mode = MMCSD_MODE_RAW;
88
89 break;
90 }
91#endif
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020092
93 gd->arch.omap_boot_device = boot_device;
94
95 /* Boot mode */
96
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020097#ifdef CONFIG_OMAP34XX
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020098 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
99 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200100 switch (boot_device) {
101 case BOOT_DEVICE_MMC1:
102 boot_mode = MMCSD_MODE_FS;
103 break;
104 case BOOT_DEVICE_MMC2:
105 boot_mode = MMCSD_MODE_RAW;
106 break;
107 }
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200108 }
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200109#else
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200110 /*
111 * If the boot device was dynamically changed and doesn't match what
112 * the bootrom initially booted, we cannot use the boot device
113 * descriptor to figure out the boot mode.
114 */
115 if ((boot_device == omap_boot_params->boot_device) &&
116 (boot_device >= MMC_BOOT_DEVICES_START) &&
117 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200118 boot_params = omap_boot_params->boot_device_descriptor;
119 if ((boot_params < NON_SECURE_SRAM_START) ||
120 (boot_params > NON_SECURE_SRAM_END))
121 return;
122
123 boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET));
124 if ((boot_params < NON_SECURE_SRAM_START) ||
125 (boot_params > NON_SECURE_SRAM_END))
126 return;
127
128 boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET));
129
130 if (boot_mode != MMCSD_MODE_FS &&
131 boot_mode != MMCSD_MODE_RAW)
132#ifdef CONFIG_SUPPORT_EMMC_BOOT
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200133 boot_mode = MMCSD_MODE_EMMCBOOT;
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200134#else
135 boot_mode = MMCSD_MODE_UNDEFINED;
136#endif
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200137 }
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200138#endif
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200139
140 gd->arch.omap_boot_mode = boot_mode;
141
142#if !defined(CONFIG_TI814X) && !defined(CONFIG_TI816X) && \
143 !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX)
144
145 /* CH flags */
146
147 gd->arch.omap_ch_flags = omap_boot_params->ch_flags;
Tom Rini560ef452014-04-03 07:52:56 -0400148#endif
Tom Rini51df26c2013-05-31 12:31:59 -0400149}
150
Chandan Nath77a73fe2012-01-09 20:38:59 +0000151#ifdef CONFIG_SPL_BUILD
Tom Rini0be93ff2012-08-13 12:53:23 -0700152u32 spl_boot_device(void)
Chandan Nath77a73fe2012-01-09 20:38:59 +0000153{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200154 return gd->arch.omap_boot_device;
Chandan Nath77a73fe2012-01-09 20:38:59 +0000155}
156
Tom Rinia76ff952012-08-14 09:19:44 -0700157u32 spl_boot_mode(void)
Chandan Nath77a73fe2012-01-09 20:38:59 +0000158{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200159 return gd->arch.omap_boot_mode;
Chandan Nath77a73fe2012-01-09 20:38:59 +0000160}
Tom Rinia0b9fa52012-08-14 10:25:15 -0700161
Tom Rini9e0c2602012-08-14 12:26:08 -0700162void spl_board_init(void)
163{
Tom Rinic95d6c42014-12-19 16:53:24 -0500164 /*
165 * Save the boot parameters passed from romcode.
166 * We cannot delay the saving further than this,
167 * to prevent overwrites.
168 */
169 save_omap_boot_params();
170
171 /* Prepare console output */
172 preloader_console_init();
173
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200174#if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
Tom Rini9e0c2602012-08-14 12:26:08 -0700175 gpmc_init();
176#endif
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200177#ifdef CONFIG_SPL_I2C_SUPPORT
178 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
179#endif
Ilya Yanok87b82cc2013-02-05 11:36:25 +0000180#if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
181 arch_misc_init();
182#endif
Tom Rini303bfe82013-10-01 12:32:04 -0400183#if defined(CONFIG_HW_WATCHDOG)
184 hw_watchdog_init();
185#endif
Tom Riniac8fdf92013-08-30 16:28:44 -0400186#ifdef CONFIG_AM33XX
187 am33xx_spl_board_init();
188#endif
Tom Rini9e0c2602012-08-14 12:26:08 -0700189}
190
Tom Rinia0b9fa52012-08-14 10:25:15 -0700191int board_mmc_init(bd_t *bis)
192{
193 switch (spl_boot_device()) {
194 case BOOT_DEVICE_MMC1:
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +0000195 omap_mmc_init(0, 0, 0, -1, -1);
Tom Rinia0b9fa52012-08-14 10:25:15 -0700196 break;
197 case BOOT_DEVICE_MMC2:
198 case BOOT_DEVICE_MMC2_2:
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +0000199 omap_mmc_init(1, 0, 0, -1, -1);
Tom Rinia0b9fa52012-08-14 10:25:15 -0700200 break;
201 }
202 return 0;
203}
SRICHARAN R3f30b0a2013-04-24 00:41:24 +0000204
205void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
206{
207 typedef void __noreturn (*image_entry_noargs_t)(u32 *);
208 image_entry_noargs_t image_entry =
209 (image_entry_noargs_t) spl_image->entry_point;
210
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200211 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
212
SRICHARAN R3f30b0a2013-04-24 00:41:24 +0000213 debug("image entry point: 0x%X\n", spl_image->entry_point);
214 /* Pass the saved boot_params from rom code */
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200215 image_entry((u32 *)boot_params);
SRICHARAN R3f30b0a2013-04-24 00:41:24 +0000216}
Chandan Nath77a73fe2012-01-09 20:38:59 +0000217#endif
Dmitry Lifshitz29211a02014-12-15 16:02:58 +0200218
219#ifdef CONFIG_SCSI_AHCI_PLAT
220void arch_preboot_os(void)
221{
Scott Wood16519a32015-04-17 09:19:01 -0500222 ahci_reset((void __iomem *)DWC_AHSATA_BASE);
Dmitry Lifshitz29211a02014-12-15 16:02:58 +0200223}
224#endif
Dileep Kattaf1a5e712015-03-27 23:06:57 +0530225
Paul Kocialkowskid55acc02015-06-12 19:56:59 +0200226#if defined(CONFIG_USB_FUNCTION_FASTBOOT) && !defined(CONFIG_ENV_IS_NOWHERE)
Dileep Kattaf1a5e712015-03-27 23:06:57 +0530227int fb_set_reboot_flag(void)
228{
229 printf("Setting reboot to fastboot flag ...\n");
230 setenv("dofastboot", "1");
231 saveenv();
232 return 0;
233}
234#endif