blob: ed9ba7b5d3e6b2675600bc67e71b2c1da988d448 [file] [log] [blame]
Chandan Nath8a8f0842012-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 Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Chandan Nath8a8f0842012-01-09 20:38:59 +00009 */
10
11#include <common.h>
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +020012#include <ahci.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
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020068 /*
69 * When booting from peripheral booting, the boot device is not usable
70 * as-is (unless there is support for it), so the boot device is instead
71 * figured out using the SYS_BOOT pins.
72 */
73 switch (boot_device) {
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +020074#if defined(BOOT_DEVICE_UART) && !defined(CONFIG_SPL_YMODEM_SUPPORT)
75 case BOOT_DEVICE_UART:
76 sys_boot_device = 1;
77 break;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020078#endif
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +020079#if defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_SUPPORT)
80 case BOOT_DEVICE_USB:
81 sys_boot_device = 1;
82 break;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020083#endif
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +020084#if defined(BOOT_DEVICE_USBETH) && !defined(CONFIG_SPL_USBETH_SUPPORT)
85 case BOOT_DEVICE_USBETH:
86 sys_boot_device = 1;
87 break;
88#endif
89#if defined(BOOT_DEVICE_CPGMAC) && !defined(CONFIG_SPL_ETH_SUPPORT)
90 case BOOT_DEVICE_CPGMAC:
91 sys_boot_device = 1;
92 break;
93#endif
94 }
95
96 if (sys_boot_device) {
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020097 boot_device = omap_sys_boot_device();
98
99 /* MMC raw mode will fallback to FS mode. */
100 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
101 (boot_device <= MMC_BOOT_DEVICES_END))
102 boot_mode = MMCSD_MODE_RAW;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200103 }
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200104
105 gd->arch.omap_boot_device = boot_device;
106
107 /* Boot mode */
108
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200109#ifdef CONFIG_OMAP34XX
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200110 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
111 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200112 switch (boot_device) {
113 case BOOT_DEVICE_MMC1:
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200114 case BOOT_DEVICE_MMC2:
115 boot_mode = MMCSD_MODE_RAW;
116 break;
117 }
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200118 }
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200119#else
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200120 /*
121 * If the boot device was dynamically changed and doesn't match what
122 * the bootrom initially booted, we cannot use the boot device
123 * descriptor to figure out the boot mode.
124 */
125 if ((boot_device == omap_boot_params->boot_device) &&
126 (boot_device >= MMC_BOOT_DEVICES_START) &&
127 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200128 boot_params = omap_boot_params->boot_device_descriptor;
129 if ((boot_params < NON_SECURE_SRAM_START) ||
130 (boot_params > NON_SECURE_SRAM_END))
131 return;
132
133 boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET));
134 if ((boot_params < NON_SECURE_SRAM_START) ||
135 (boot_params > NON_SECURE_SRAM_END))
136 return;
137
138 boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET));
139
140 if (boot_mode != MMCSD_MODE_FS &&
141 boot_mode != MMCSD_MODE_RAW)
142#ifdef CONFIG_SUPPORT_EMMC_BOOT
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200143 boot_mode = MMCSD_MODE_EMMCBOOT;
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200144#else
145 boot_mode = MMCSD_MODE_UNDEFINED;
146#endif
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200147 }
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200148#endif
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200149
150 gd->arch.omap_boot_mode = boot_mode;
151
152#if !defined(CONFIG_TI814X) && !defined(CONFIG_TI816X) && \
153 !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX)
154
155 /* CH flags */
156
157 gd->arch.omap_ch_flags = omap_boot_params->ch_flags;
Tom Rini79b079f2014-04-03 07:52:56 -0400158#endif
Tom Rini4596dcc2013-05-31 12:31:59 -0400159}
160
Chandan Nath8a8f0842012-01-09 20:38:59 +0000161#ifdef CONFIG_SPL_BUILD
Tom Rini8e1b8362012-08-13 12:53:23 -0700162u32 spl_boot_device(void)
Chandan Nath8a8f0842012-01-09 20:38:59 +0000163{
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200164 return gd->arch.omap_boot_device;
Chandan Nath8a8f0842012-01-09 20:38:59 +0000165}
166
Tom Rini37189a12012-08-14 09:19:44 -0700167u32 spl_boot_mode(void)
Chandan Nath8a8f0842012-01-09 20:38:59 +0000168{
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200169 return gd->arch.omap_boot_mode;
Chandan Nath8a8f0842012-01-09 20:38:59 +0000170}
Tom Rinif0881252012-08-14 10:25:15 -0700171
Tom Rinid7cb93b2012-08-14 12:26:08 -0700172void spl_board_init(void)
173{
Tom Rinia6b541b2014-12-19 16:53:24 -0500174 /*
175 * Save the boot parameters passed from romcode.
176 * We cannot delay the saving further than this,
177 * to prevent overwrites.
178 */
179 save_omap_boot_params();
180
181 /* Prepare console output */
182 preloader_console_init();
183
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200184#if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
Tom Rinid7cb93b2012-08-14 12:26:08 -0700185 gpmc_init();
186#endif
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200187#ifdef CONFIG_SPL_I2C_SUPPORT
188 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
189#endif
Ilya Yanokda07c212013-02-05 11:36:25 +0000190#if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
191 arch_misc_init();
192#endif
Tom Rini68439182013-10-01 12:32:04 -0400193#if defined(CONFIG_HW_WATCHDOG)
194 hw_watchdog_init();
195#endif
Tom Rini6a0d8032013-08-30 16:28:44 -0400196#ifdef CONFIG_AM33XX
197 am33xx_spl_board_init();
198#endif
Tom Rinid7cb93b2012-08-14 12:26:08 -0700199}
200
Tom Rinif0881252012-08-14 10:25:15 -0700201int board_mmc_init(bd_t *bis)
202{
203 switch (spl_boot_device()) {
204 case BOOT_DEVICE_MMC1:
Nikita Kiryanove3913f52012-12-03 02:19:47 +0000205 omap_mmc_init(0, 0, 0, -1, -1);
Tom Rinif0881252012-08-14 10:25:15 -0700206 break;
207 case BOOT_DEVICE_MMC2:
208 case BOOT_DEVICE_MMC2_2:
Tom Rini312db9f2015-12-14 11:08:38 -0500209 omap_mmc_init(0, 0, 0, -1, -1);
Nikita Kiryanove3913f52012-12-03 02:19:47 +0000210 omap_mmc_init(1, 0, 0, -1, -1);
Tom Rinif0881252012-08-14 10:25:15 -0700211 break;
212 }
213 return 0;
214}
SRICHARAN R4a0eb752013-04-24 00:41:24 +0000215
216void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
217{
218 typedef void __noreturn (*image_entry_noargs_t)(u32 *);
219 image_entry_noargs_t image_entry =
220 (image_entry_noargs_t) spl_image->entry_point;
221
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200222 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
223
SRICHARAN R4a0eb752013-04-24 00:41:24 +0000224 debug("image entry point: 0x%X\n", spl_image->entry_point);
225 /* Pass the saved boot_params from rom code */
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200226 image_entry((u32 *)boot_params);
SRICHARAN R4a0eb752013-04-24 00:41:24 +0000227}
Chandan Nath8a8f0842012-01-09 20:38:59 +0000228#endif
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +0200229
230#ifdef CONFIG_SCSI_AHCI_PLAT
231void arch_preboot_os(void)
232{
Scott Wood9efaca32015-04-17 09:19:01 -0500233 ahci_reset((void __iomem *)DWC_AHSATA_BASE);
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +0200234}
235#endif
Dileep Kattaecd85572015-03-27 23:06:57 +0530236
Paul Kocialkowski17da3c02015-06-12 19:56:59 +0200237#if defined(CONFIG_USB_FUNCTION_FASTBOOT) && !defined(CONFIG_ENV_IS_NOWHERE)
Dileep Kattaecd85572015-03-27 23:06:57 +0530238int fb_set_reboot_flag(void)
239{
240 printf("Setting reboot to fastboot flag ...\n");
241 setenv("dofastboot", "1");
242 saveenv();
243 return 0;
244}
245#endif