Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 1 | /* |
| 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 Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Dmitry Lifshitz | 29211a0 | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 12 | #include <ahci.h> |
Tom Rini | 28591df | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 13 | #include <spl.h> |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 14 | #include <asm/omap_common.h> |
| 15 | #include <asm/arch/omap.h> |
Tom Rini | a0b9fa5 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 16 | #include <asm/arch/mmc_host_def.h> |
Ilya Yanok | 741c57f | 2012-11-06 13:06:28 +0000 | [diff] [blame] | 17 | #include <asm/arch/sys_proto.h> |
Tom Rini | 303bfe8 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 18 | #include <watchdog.h> |
Dmitry Lifshitz | 29211a0 | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 19 | #include <scsi.h> |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 20 | #include <i2c.h> |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 21 | |
SRICHARAN R | 3f30b0a | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 23 | |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 24 | __weak u32 omap_sys_boot_device(void) |
| 25 | { |
| 26 | return BOOT_DEVICE_NONE; |
| 27 | } |
| 28 | |
Tom Rini | 51df26c | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 29 | void save_omap_boot_params(void) |
| 30 | { |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 31 | u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS); |
| 32 | struct omap_boot_parameters *omap_boot_params; |
Paul Kocialkowski | dd15fab | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 33 | int sys_boot_device = 0; |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 34 | u32 boot_device; |
| 35 | u32 boot_mode; |
Tom Rini | 51df26c | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 36 | |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 37 | if ((boot_params < NON_SECURE_SRAM_START) || |
| 38 | (boot_params > NON_SECURE_SRAM_END)) |
Tom Rini | 51df26c | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 39 | return; |
| 40 | |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 41 | omap_boot_params = (struct omap_boot_parameters *)boot_params; |
Stefan Roese | 0f3a480 | 2014-11-12 11:57:33 +0100 | [diff] [blame] | 42 | |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 43 | boot_device = omap_boot_params->boot_device; |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 44 | boot_mode = MMCSD_MODE_UNDEFINED; |
| 45 | |
| 46 | /* Boot device */ |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 47 | |
| 48 | #ifdef BOOT_DEVICE_NAND_I2C |
Stefan Roese | 0f3a480 | 2014-11-12 11:57:33 +0100 | [diff] [blame] | 49 | /* |
| 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 Kocialkowski | b16d6d5 | 2015-07-15 16:02:21 +0200 | [diff] [blame] | 58 | #ifdef BOOT_DEVICE_QSPI_4 |
Tom Rini | 560ef45 | 2014-04-03 07:52:56 -0400 | [diff] [blame] | 59 | /* |
| 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 Kocialkowski | b16d6d5 | 2015-07-15 16:02:21 +0200 | [diff] [blame] | 65 | if (boot_device == BOOT_DEVICE_QSPI_4) |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 66 | boot_device = BOOT_DEVICE_SPI; |
| 67 | #endif |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 68 | /* |
| 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 Kocialkowski | dd15fab | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 74 | #if defined(BOOT_DEVICE_UART) && !defined(CONFIG_SPL_YMODEM_SUPPORT) |
| 75 | case BOOT_DEVICE_UART: |
| 76 | sys_boot_device = 1; |
| 77 | break; |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 78 | #endif |
Paul Kocialkowski | dd15fab | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 79 | #if defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_SUPPORT) |
| 80 | case BOOT_DEVICE_USB: |
| 81 | sys_boot_device = 1; |
| 82 | break; |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 83 | #endif |
Paul Kocialkowski | dd15fab | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 84 | #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 |
B, Ravi | 2fb19df | 2016-07-28 17:39:17 +0530 | [diff] [blame] | 94 | #if defined(BOOT_DEVICE_DFU) && !defined(CONFIG_SPL_DFU_SUPPORT) |
| 95 | case BOOT_DEVICE_DFU: |
| 96 | sys_boot_device = 1; |
| 97 | break; |
| 98 | #endif |
Paul Kocialkowski | dd15fab | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | if (sys_boot_device) { |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 102 | boot_device = omap_sys_boot_device(); |
| 103 | |
| 104 | /* MMC raw mode will fallback to FS mode. */ |
| 105 | if ((boot_device >= MMC_BOOT_DEVICES_START) && |
| 106 | (boot_device <= MMC_BOOT_DEVICES_END)) |
| 107 | boot_mode = MMCSD_MODE_RAW; |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 108 | } |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 109 | |
| 110 | gd->arch.omap_boot_device = boot_device; |
| 111 | |
| 112 | /* Boot mode */ |
| 113 | |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 114 | #ifdef CONFIG_OMAP34XX |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 115 | if ((boot_device >= MMC_BOOT_DEVICES_START) && |
| 116 | (boot_device <= MMC_BOOT_DEVICES_END)) { |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 117 | switch (boot_device) { |
| 118 | case BOOT_DEVICE_MMC1: |
Tom Rini | 9266bf4 | 2016-05-02 10:52:51 -0400 | [diff] [blame] | 119 | boot_mode = MMCSD_MODE_FS; |
| 120 | break; |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 121 | case BOOT_DEVICE_MMC2: |
| 122 | boot_mode = MMCSD_MODE_RAW; |
| 123 | break; |
| 124 | } |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 125 | } |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 126 | #else |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 127 | /* |
| 128 | * If the boot device was dynamically changed and doesn't match what |
| 129 | * the bootrom initially booted, we cannot use the boot device |
| 130 | * descriptor to figure out the boot mode. |
| 131 | */ |
| 132 | if ((boot_device == omap_boot_params->boot_device) && |
| 133 | (boot_device >= MMC_BOOT_DEVICES_START) && |
| 134 | (boot_device <= MMC_BOOT_DEVICES_END)) { |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 135 | boot_params = omap_boot_params->boot_device_descriptor; |
| 136 | if ((boot_params < NON_SECURE_SRAM_START) || |
| 137 | (boot_params > NON_SECURE_SRAM_END)) |
| 138 | return; |
| 139 | |
| 140 | boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET)); |
| 141 | if ((boot_params < NON_SECURE_SRAM_START) || |
| 142 | (boot_params > NON_SECURE_SRAM_END)) |
| 143 | return; |
| 144 | |
| 145 | boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET)); |
| 146 | |
| 147 | if (boot_mode != MMCSD_MODE_FS && |
| 148 | boot_mode != MMCSD_MODE_RAW) |
| 149 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 150 | boot_mode = MMCSD_MODE_EMMCBOOT; |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 151 | #else |
| 152 | boot_mode = MMCSD_MODE_UNDEFINED; |
| 153 | #endif |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 154 | } |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 155 | #endif |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 156 | |
| 157 | gd->arch.omap_boot_mode = boot_mode; |
| 158 | |
| 159 | #if !defined(CONFIG_TI814X) && !defined(CONFIG_TI816X) && \ |
| 160 | !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX) |
| 161 | |
| 162 | /* CH flags */ |
| 163 | |
| 164 | gd->arch.omap_ch_flags = omap_boot_params->ch_flags; |
Tom Rini | 560ef45 | 2014-04-03 07:52:56 -0400 | [diff] [blame] | 165 | #endif |
Tom Rini | 51df26c | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 166 | } |
| 167 | |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 168 | #ifdef CONFIG_SPL_BUILD |
Tom Rini | 0be93ff | 2012-08-13 12:53:23 -0700 | [diff] [blame] | 169 | u32 spl_boot_device(void) |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 170 | { |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 171 | return gd->arch.omap_boot_device; |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Marek Vasut | 64d64bb | 2016-05-14 23:42:07 +0200 | [diff] [blame] | 174 | u32 spl_boot_mode(const u32 boot_device) |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 175 | { |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 176 | return gd->arch.omap_boot_mode; |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 177 | } |
Tom Rini | a0b9fa5 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 178 | |
Tom Rini | 9e0c260 | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 179 | void spl_board_init(void) |
| 180 | { |
Tom Rini | c95d6c4 | 2014-12-19 16:53:24 -0500 | [diff] [blame] | 181 | /* |
| 182 | * Save the boot parameters passed from romcode. |
| 183 | * We cannot delay the saving further than this, |
| 184 | * to prevent overwrites. |
| 185 | */ |
| 186 | save_omap_boot_params(); |
| 187 | |
| 188 | /* Prepare console output */ |
| 189 | preloader_console_init(); |
| 190 | |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 191 | #if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT) |
Tom Rini | 9e0c260 | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 192 | gpmc_init(); |
| 193 | #endif |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 194 | #ifdef CONFIG_SPL_I2C_SUPPORT |
| 195 | i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE); |
| 196 | #endif |
Ilya Yanok | 87b82cc | 2013-02-05 11:36:25 +0000 | [diff] [blame] | 197 | #if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT) |
| 198 | arch_misc_init(); |
| 199 | #endif |
Tom Rini | 303bfe8 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 200 | #if defined(CONFIG_HW_WATCHDOG) |
| 201 | hw_watchdog_init(); |
| 202 | #endif |
Tom Rini | ac8fdf9 | 2013-08-30 16:28:44 -0400 | [diff] [blame] | 203 | #ifdef CONFIG_AM33XX |
| 204 | am33xx_spl_board_init(); |
| 205 | #endif |
Tom Rini | 9e0c260 | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Heiko Schocher | d17112a | 2016-06-07 08:31:23 +0200 | [diff] [blame] | 208 | __weak int board_mmc_init(bd_t *bis) |
Tom Rini | a0b9fa5 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 209 | { |
| 210 | switch (spl_boot_device()) { |
| 211 | case BOOT_DEVICE_MMC1: |
Nikita Kiryanov | 4be9dbc | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 212 | omap_mmc_init(0, 0, 0, -1, -1); |
Tom Rini | a0b9fa5 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 213 | break; |
| 214 | case BOOT_DEVICE_MMC2: |
| 215 | case BOOT_DEVICE_MMC2_2: |
Tom Rini | 4458858 | 2015-12-14 11:08:38 -0500 | [diff] [blame] | 216 | omap_mmc_init(0, 0, 0, -1, -1); |
Nikita Kiryanov | 4be9dbc | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 217 | omap_mmc_init(1, 0, 0, -1, -1); |
Tom Rini | a0b9fa5 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 218 | break; |
| 219 | } |
| 220 | return 0; |
| 221 | } |
SRICHARAN R | 3f30b0a | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 222 | |
| 223 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 224 | { |
| 225 | typedef void __noreturn (*image_entry_noargs_t)(u32 *); |
| 226 | image_entry_noargs_t image_entry = |
| 227 | (image_entry_noargs_t) spl_image->entry_point; |
| 228 | |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 229 | u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS); |
| 230 | |
SRICHARAN R | 3f30b0a | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 231 | debug("image entry point: 0x%X\n", spl_image->entry_point); |
| 232 | /* Pass the saved boot_params from rom code */ |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 233 | image_entry((u32 *)boot_params); |
SRICHARAN R | 3f30b0a | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 234 | } |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 235 | #endif |
Dmitry Lifshitz | 29211a0 | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 236 | |
| 237 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 238 | void arch_preboot_os(void) |
| 239 | { |
Scott Wood | 16519a3 | 2015-04-17 09:19:01 -0500 | [diff] [blame] | 240 | ahci_reset((void __iomem *)DWC_AHSATA_BASE); |
Dmitry Lifshitz | 29211a0 | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 241 | } |
| 242 | #endif |
Dileep Katta | f1a5e71 | 2015-03-27 23:06:57 +0530 | [diff] [blame] | 243 | |
Paul Kocialkowski | d55acc0 | 2015-06-12 19:56:59 +0200 | [diff] [blame] | 244 | #if defined(CONFIG_USB_FUNCTION_FASTBOOT) && !defined(CONFIG_ENV_IS_NOWHERE) |
Dileep Katta | f1a5e71 | 2015-03-27 23:06:57 +0530 | [diff] [blame] | 245 | int fb_set_reboot_flag(void) |
| 246 | { |
| 247 | printf("Setting reboot to fastboot flag ...\n"); |
| 248 | setenv("dofastboot", "1"); |
| 249 | saveenv(); |
| 250 | return 0; |
| 251 | } |
| 252 | #endif |