Chandan Nath | 8a8f084 | 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 | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Dmitry Lifshitz | 87791ad | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 12 | #include <ahci.h> |
Simon Glass | 0151009 | 2017-08-03 12:22:08 -0600 | [diff] [blame] | 13 | #include <environment.h> |
Tom Rini | 47f7bca | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 14 | #include <spl.h> |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 15 | #include <asm/omap_common.h> |
| 16 | #include <asm/arch/omap.h> |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 17 | #include <asm/arch/mmc_host_def.h> |
Ilya Yanok | 1befaff | 2012-11-06 13:06:28 +0000 | [diff] [blame] | 18 | #include <asm/arch/sys_proto.h> |
Tom Rini | 6843918 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 19 | #include <watchdog.h> |
Dmitry Lifshitz | 87791ad | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 20 | #include <scsi.h> |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 21 | #include <i2c.h> |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 22 | |
SRICHARAN R | 4a0eb75 | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 23 | DECLARE_GLOBAL_DATA_PTR; |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 24 | |
Paul Kocialkowski | ed19bda | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 25 | __weak u32 omap_sys_boot_device(void) |
| 26 | { |
| 27 | return BOOT_DEVICE_NONE; |
| 28 | } |
| 29 | |
Tom Rini | 4596dcc | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 30 | void save_omap_boot_params(void) |
| 31 | { |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 32 | u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS); |
| 33 | struct omap_boot_parameters *omap_boot_params; |
Paul Kocialkowski | 8ceb34a | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 34 | int sys_boot_device = 0; |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 35 | u32 boot_device; |
| 36 | u32 boot_mode; |
Tom Rini | 4596dcc | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 37 | |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 38 | if ((boot_params < NON_SECURE_SRAM_START) || |
| 39 | (boot_params > NON_SECURE_SRAM_END)) |
Tom Rini | 4596dcc | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 40 | return; |
| 41 | |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 42 | omap_boot_params = (struct omap_boot_parameters *)boot_params; |
Stefan Roese | e49631a | 2014-11-12 11:57:33 +0100 | [diff] [blame] | 43 | |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 44 | boot_device = omap_boot_params->boot_device; |
Paul Kocialkowski | ed19bda | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 45 | boot_mode = MMCSD_MODE_UNDEFINED; |
| 46 | |
| 47 | /* Boot device */ |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 48 | |
| 49 | #ifdef BOOT_DEVICE_NAND_I2C |
Stefan Roese | e49631a | 2014-11-12 11:57:33 +0100 | [diff] [blame] | 50 | /* |
| 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 Kocialkowski | df84477 | 2015-07-15 16:02:21 +0200 | [diff] [blame] | 59 | #ifdef BOOT_DEVICE_QSPI_4 |
Tom Rini | 79b079f | 2014-04-03 07:52:56 -0400 | [diff] [blame] | 60 | /* |
| 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 Kocialkowski | df84477 | 2015-07-15 16:02:21 +0200 | [diff] [blame] | 66 | if (boot_device == BOOT_DEVICE_QSPI_4) |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 67 | boot_device = BOOT_DEVICE_SPI; |
| 68 | #endif |
Tom Rini | 207f981 | 2017-06-15 13:57:00 -0400 | [diff] [blame] | 69 | #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 Kocialkowski | ed19bda | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 86 | /* |
| 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 Kocialkowski | 8ceb34a | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 92 | #if defined(BOOT_DEVICE_UART) && !defined(CONFIG_SPL_YMODEM_SUPPORT) |
| 93 | case BOOT_DEVICE_UART: |
| 94 | sys_boot_device = 1; |
| 95 | break; |
Paul Kocialkowski | ed19bda | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 96 | #endif |
Paul Kocialkowski | 8ceb34a | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 97 | #if defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_SUPPORT) |
| 98 | case BOOT_DEVICE_USB: |
| 99 | sys_boot_device = 1; |
| 100 | break; |
Paul Kocialkowski | ed19bda | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 101 | #endif |
Paul Kocialkowski | 8ceb34a | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 102 | #if defined(BOOT_DEVICE_USBETH) && !defined(CONFIG_SPL_USBETH_SUPPORT) |
| 103 | case BOOT_DEVICE_USBETH: |
| 104 | sys_boot_device = 1; |
| 105 | break; |
| 106 | #endif |
| 107 | #if defined(BOOT_DEVICE_CPGMAC) && !defined(CONFIG_SPL_ETH_SUPPORT) |
| 108 | case BOOT_DEVICE_CPGMAC: |
| 109 | sys_boot_device = 1; |
| 110 | break; |
| 111 | #endif |
B, Ravi | 6f8387f | 2016-07-28 17:39:17 +0530 | [diff] [blame] | 112 | #if defined(BOOT_DEVICE_DFU) && !defined(CONFIG_SPL_DFU_SUPPORT) |
| 113 | case BOOT_DEVICE_DFU: |
| 114 | sys_boot_device = 1; |
| 115 | break; |
| 116 | #endif |
Paul Kocialkowski | 8ceb34a | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | if (sys_boot_device) { |
Paul Kocialkowski | ed19bda | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 120 | 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 Kocialkowski | ed19bda | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 126 | } |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 127 | |
| 128 | gd->arch.omap_boot_device = boot_device; |
| 129 | |
| 130 | /* Boot mode */ |
| 131 | |
Paul Kocialkowski | ed19bda | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 132 | #ifdef CONFIG_OMAP34XX |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 133 | if ((boot_device >= MMC_BOOT_DEVICES_START) && |
| 134 | (boot_device <= MMC_BOOT_DEVICES_END)) { |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 135 | switch (boot_device) { |
| 136 | case BOOT_DEVICE_MMC1: |
Tom Rini | 821c89d | 2016-05-02 10:52:51 -0400 | [diff] [blame] | 137 | boot_mode = MMCSD_MODE_FS; |
| 138 | break; |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 139 | case BOOT_DEVICE_MMC2: |
| 140 | boot_mode = MMCSD_MODE_RAW; |
| 141 | break; |
| 142 | } |
Paul Kocialkowski | ed19bda | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 143 | } |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 144 | #else |
Paul Kocialkowski | ed19bda | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 145 | /* |
| 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 Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 153 | 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 Kocialkowski | ed19bda | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 168 | boot_mode = MMCSD_MODE_EMMCBOOT; |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 169 | #else |
| 170 | boot_mode = MMCSD_MODE_UNDEFINED; |
| 171 | #endif |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 172 | } |
Paul Kocialkowski | ed19bda | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 173 | #endif |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 174 | |
| 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 Rini | 79b079f | 2014-04-03 07:52:56 -0400 | [diff] [blame] | 183 | #endif |
Tom Rini | 4596dcc | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 184 | } |
| 185 | |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 186 | #ifdef CONFIG_SPL_BUILD |
Tom Rini | 8e1b836 | 2012-08-13 12:53:23 -0700 | [diff] [blame] | 187 | u32 spl_boot_device(void) |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 188 | { |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 189 | return gd->arch.omap_boot_device; |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Marek Vasut | 2b1cdaf | 2016-05-14 23:42:07 +0200 | [diff] [blame] | 192 | u32 spl_boot_mode(const u32 boot_device) |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 193 | { |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 194 | return gd->arch.omap_boot_mode; |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 195 | } |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 196 | |
Tom Rini | d7cb93b | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 197 | void spl_board_init(void) |
| 198 | { |
Tom Rini | a6b541b | 2014-12-19 16:53:24 -0500 | [diff] [blame] | 199 | /* Prepare console output */ |
| 200 | preloader_console_init(); |
| 201 | |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 202 | #if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT) |
Tom Rini | d7cb93b | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 203 | gpmc_init(); |
| 204 | #endif |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 205 | #ifdef CONFIG_SPL_I2C_SUPPORT |
| 206 | i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE); |
| 207 | #endif |
Ilya Yanok | da07c21 | 2013-02-05 11:36:25 +0000 | [diff] [blame] | 208 | #if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT) |
| 209 | arch_misc_init(); |
| 210 | #endif |
Tom Rini | 6843918 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 211 | #if defined(CONFIG_HW_WATCHDOG) |
| 212 | hw_watchdog_init(); |
| 213 | #endif |
Tom Rini | 6a0d803 | 2013-08-30 16:28:44 -0400 | [diff] [blame] | 214 | #ifdef CONFIG_AM33XX |
| 215 | am33xx_spl_board_init(); |
| 216 | #endif |
Tom Rini | d7cb93b | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 217 | } |
| 218 | |
SRICHARAN R | 4a0eb75 | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 219 | void __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 Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 225 | u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS); |
| 226 | |
Andre Przywara | 11e1479 | 2017-01-02 11:48:31 +0000 | [diff] [blame] | 227 | debug("image entry point: 0x%lX\n", spl_image->entry_point); |
SRICHARAN R | 4a0eb75 | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 228 | /* Pass the saved boot_params from rom code */ |
Paul Kocialkowski | 60c7c30 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 229 | image_entry((u32 *)boot_params); |
SRICHARAN R | 4a0eb75 | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 230 | } |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 231 | #endif |
Dmitry Lifshitz | 87791ad | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 232 | |
| 233 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 234 | void arch_preboot_os(void) |
| 235 | { |
Scott Wood | 9efaca3 | 2015-04-17 09:19:01 -0500 | [diff] [blame] | 236 | ahci_reset((void __iomem *)DWC_AHSATA_BASE); |
Dmitry Lifshitz | 87791ad | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 237 | } |
| 238 | #endif |
Dileep Katta | ecd8557 | 2015-03-27 23:06:57 +0530 | [diff] [blame] | 239 | |
Paul Kocialkowski | 17da3c0 | 2015-06-12 19:56:59 +0200 | [diff] [blame] | 240 | #if defined(CONFIG_USB_FUNCTION_FASTBOOT) && !defined(CONFIG_ENV_IS_NOWHERE) |
Dileep Katta | ecd8557 | 2015-03-27 23:06:57 +0530 | [diff] [blame] | 241 | int fb_set_reboot_flag(void) |
| 242 | { |
| 243 | printf("Setting reboot to fastboot flag ...\n"); |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 244 | env_set("dofastboot", "1"); |
Simon Glass | 0151009 | 2017-08-03 12:22:08 -0600 | [diff] [blame] | 245 | env_save(); |
Dileep Katta | ecd8557 | 2015-03-27 23:06:57 +0530 | [diff] [blame] | 246 | return 0; |
| 247 | } |
| 248 | #endif |