Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 2 | /* |
| 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 Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Dmitry Lifshitz | 29211a0 | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 11 | #include <ahci.h> |
Tom Rini | 28591df | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 12 | #include <spl.h> |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 13 | #include <asm/omap_common.h> |
| 14 | #include <asm/arch/omap.h> |
Tom Rini | a0b9fa5 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 15 | #include <asm/arch/mmc_host_def.h> |
Ilya Yanok | 741c57f | 2012-11-06 13:06:28 +0000 | [diff] [blame] | 16 | #include <asm/arch/sys_proto.h> |
Tom Rini | 303bfe8 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 17 | #include <watchdog.h> |
Dmitry Lifshitz | 29211a0 | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 18 | #include <scsi.h> |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 19 | #include <i2c.h> |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 20 | |
SRICHARAN R | 3f30b0a | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 21 | DECLARE_GLOBAL_DATA_PTR; |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 22 | |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 23 | __weak u32 omap_sys_boot_device(void) |
| 24 | { |
| 25 | return BOOT_DEVICE_NONE; |
| 26 | } |
| 27 | |
Tom Rini | 51df26c | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 28 | void save_omap_boot_params(void) |
| 29 | { |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 30 | u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS); |
| 31 | struct omap_boot_parameters *omap_boot_params; |
Paul Kocialkowski | dd15fab | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 32 | int sys_boot_device = 0; |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 33 | u32 boot_device; |
| 34 | u32 boot_mode; |
Tom Rini | 51df26c | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 35 | |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 36 | if ((boot_params < NON_SECURE_SRAM_START) || |
| 37 | (boot_params > NON_SECURE_SRAM_END)) |
Tom Rini | 51df26c | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 38 | return; |
| 39 | |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 40 | omap_boot_params = (struct omap_boot_parameters *)boot_params; |
Stefan Roese | 0f3a480 | 2014-11-12 11:57:33 +0100 | [diff] [blame] | 41 | |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 42 | boot_device = omap_boot_params->boot_device; |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 43 | boot_mode = MMCSD_MODE_UNDEFINED; |
| 44 | |
| 45 | /* Boot device */ |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 46 | |
| 47 | #ifdef BOOT_DEVICE_NAND_I2C |
Stefan Roese | 0f3a480 | 2014-11-12 11:57:33 +0100 | [diff] [blame] | 48 | /* |
| 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 Kocialkowski | b16d6d5 | 2015-07-15 16:02:21 +0200 | [diff] [blame] | 57 | #ifdef BOOT_DEVICE_QSPI_4 |
Tom Rini | 560ef45 | 2014-04-03 07:52:56 -0400 | [diff] [blame] | 58 | /* |
| 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 Kocialkowski | b16d6d5 | 2015-07-15 16:02:21 +0200 | [diff] [blame] | 64 | if (boot_device == BOOT_DEVICE_QSPI_4) |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 65 | boot_device = BOOT_DEVICE_SPI; |
| 66 | #endif |
Tom Rini | d00abb1 | 2017-06-15 13:57:00 -0400 | [diff] [blame] | 67 | #ifdef CONFIG_TI816X |
| 68 | /* |
| 69 | * On PG2.0 and later TI816x the values we get when booting are not the |
| 70 | * same as on PG1.0, which is what the defines are based on. Update |
| 71 | * them as needed. |
| 72 | */ |
| 73 | if (get_cpu_rev() != 1) { |
| 74 | if (boot_device == 0x05) { |
| 75 | omap_boot_params->boot_device = BOOT_DEVICE_NAND; |
| 76 | boot_device = BOOT_DEVICE_NAND; |
| 77 | } |
| 78 | if (boot_device == 0x08) { |
| 79 | omap_boot_params->boot_device = BOOT_DEVICE_MMC1; |
| 80 | boot_device = BOOT_DEVICE_MMC1; |
| 81 | } |
| 82 | } |
| 83 | #endif |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 84 | /* |
| 85 | * When booting from peripheral booting, the boot device is not usable |
| 86 | * as-is (unless there is support for it), so the boot device is instead |
| 87 | * figured out using the SYS_BOOT pins. |
| 88 | */ |
| 89 | switch (boot_device) { |
Paul Kocialkowski | dd15fab | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 90 | #if defined(BOOT_DEVICE_UART) && !defined(CONFIG_SPL_YMODEM_SUPPORT) |
| 91 | case BOOT_DEVICE_UART: |
| 92 | sys_boot_device = 1; |
| 93 | break; |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 94 | #endif |
Abel Vesa | 5ea11ba5 | 2019-02-01 16:40:07 +0000 | [diff] [blame] | 95 | #if defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_STORAGE) |
Paul Kocialkowski | dd15fab | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 96 | case BOOT_DEVICE_USB: |
| 97 | sys_boot_device = 1; |
| 98 | break; |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 99 | #endif |
Faiz Abbas | c01553b | 2018-02-16 21:17:44 +0530 | [diff] [blame] | 100 | #if defined(BOOT_DEVICE_USBETH) && !defined(CONFIG_SPL_USB_ETHER) |
Paul Kocialkowski | dd15fab | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 101 | case BOOT_DEVICE_USBETH: |
| 102 | sys_boot_device = 1; |
| 103 | break; |
| 104 | #endif |
| 105 | #if defined(BOOT_DEVICE_CPGMAC) && !defined(CONFIG_SPL_ETH_SUPPORT) |
| 106 | case BOOT_DEVICE_CPGMAC: |
| 107 | sys_boot_device = 1; |
| 108 | break; |
| 109 | #endif |
Andrew F. Davis | 6d932e6 | 2019-01-17 13:43:02 -0600 | [diff] [blame] | 110 | #if defined(BOOT_DEVICE_DFU) && !defined(CONFIG_SPL_DFU) |
B, Ravi | 2fb19df | 2016-07-28 17:39:17 +0530 | [diff] [blame] | 111 | case BOOT_DEVICE_DFU: |
| 112 | sys_boot_device = 1; |
| 113 | break; |
| 114 | #endif |
Paul Kocialkowski | dd15fab | 2015-08-27 10:46:09 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | if (sys_boot_device) { |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 118 | boot_device = omap_sys_boot_device(); |
| 119 | |
| 120 | /* MMC raw mode will fallback to FS mode. */ |
| 121 | if ((boot_device >= MMC_BOOT_DEVICES_START) && |
| 122 | (boot_device <= MMC_BOOT_DEVICES_END)) |
| 123 | boot_mode = MMCSD_MODE_RAW; |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 124 | } |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 125 | |
| 126 | gd->arch.omap_boot_device = boot_device; |
| 127 | |
| 128 | /* Boot mode */ |
| 129 | |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 130 | #ifdef CONFIG_OMAP34XX |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 131 | if ((boot_device >= MMC_BOOT_DEVICES_START) && |
| 132 | (boot_device <= MMC_BOOT_DEVICES_END)) { |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 133 | switch (boot_device) { |
| 134 | case BOOT_DEVICE_MMC1: |
Tom Rini | 9266bf4 | 2016-05-02 10:52:51 -0400 | [diff] [blame] | 135 | boot_mode = MMCSD_MODE_FS; |
| 136 | break; |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 137 | case BOOT_DEVICE_MMC2: |
| 138 | boot_mode = MMCSD_MODE_RAW; |
| 139 | break; |
| 140 | } |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 141 | } |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 142 | #else |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 143 | /* |
| 144 | * If the boot device was dynamically changed and doesn't match what |
| 145 | * the bootrom initially booted, we cannot use the boot device |
| 146 | * descriptor to figure out the boot mode. |
| 147 | */ |
| 148 | if ((boot_device == omap_boot_params->boot_device) && |
| 149 | (boot_device >= MMC_BOOT_DEVICES_START) && |
| 150 | (boot_device <= MMC_BOOT_DEVICES_END)) { |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 151 | boot_params = omap_boot_params->boot_device_descriptor; |
| 152 | if ((boot_params < NON_SECURE_SRAM_START) || |
| 153 | (boot_params > NON_SECURE_SRAM_END)) |
| 154 | return; |
| 155 | |
| 156 | boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET)); |
| 157 | if ((boot_params < NON_SECURE_SRAM_START) || |
| 158 | (boot_params > NON_SECURE_SRAM_END)) |
| 159 | return; |
| 160 | |
| 161 | boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET)); |
| 162 | |
| 163 | if (boot_mode != MMCSD_MODE_FS && |
| 164 | boot_mode != MMCSD_MODE_RAW) |
| 165 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 166 | boot_mode = MMCSD_MODE_EMMCBOOT; |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 167 | #else |
| 168 | boot_mode = MMCSD_MODE_UNDEFINED; |
| 169 | #endif |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 170 | } |
Paul Kocialkowski | 062fbb6 | 2015-07-15 16:02:23 +0200 | [diff] [blame] | 171 | #endif |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 172 | |
| 173 | gd->arch.omap_boot_mode = boot_mode; |
| 174 | |
| 175 | #if !defined(CONFIG_TI814X) && !defined(CONFIG_TI816X) && \ |
| 176 | !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX) |
| 177 | |
| 178 | /* CH flags */ |
| 179 | |
| 180 | gd->arch.omap_ch_flags = omap_boot_params->ch_flags; |
Tom Rini | 560ef45 | 2014-04-03 07:52:56 -0400 | [diff] [blame] | 181 | #endif |
Tom Rini | 51df26c | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 182 | } |
| 183 | |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 184 | #ifdef CONFIG_SPL_BUILD |
Tom Rini | 0be93ff | 2012-08-13 12:53:23 -0700 | [diff] [blame] | 185 | u32 spl_boot_device(void) |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 186 | { |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 187 | return gd->arch.omap_boot_device; |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Marek Vasut | 64d64bb | 2016-05-14 23:42:07 +0200 | [diff] [blame] | 190 | u32 spl_boot_mode(const u32 boot_device) |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 191 | { |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 192 | return gd->arch.omap_boot_mode; |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 193 | } |
Tom Rini | a0b9fa5 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 194 | |
Tom Rini | 9e0c260 | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 195 | void spl_board_init(void) |
| 196 | { |
Alex Kiernan | b09f892 | 2018-04-19 04:32:51 +0000 | [diff] [blame] | 197 | #ifdef CONFIG_SPL_SERIAL_SUPPORT |
Tom Rini | c95d6c4 | 2014-12-19 16:53:24 -0500 | [diff] [blame] | 198 | /* Prepare console output */ |
| 199 | preloader_console_init(); |
Alex Kiernan | b09f892 | 2018-04-19 04:32:51 +0000 | [diff] [blame] | 200 | #endif |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 201 | #if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT) |
Tom Rini | 9e0c260 | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 202 | gpmc_init(); |
| 203 | #endif |
Adam Ford | 494b968 | 2018-08-20 20:34:00 -0500 | [diff] [blame] | 204 | #if defined(CONFIG_SPL_I2C_SUPPORT) && !defined(CONFIG_DM_I2C) |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 205 | i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE); |
| 206 | #endif |
Ilya Yanok | 87b82cc | 2013-02-05 11:36:25 +0000 | [diff] [blame] | 207 | #if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT) |
| 208 | arch_misc_init(); |
| 209 | #endif |
Suniel Mahesh | 370d491 | 2019-07-31 21:54:07 +0530 | [diff] [blame] | 210 | #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) |
Tom Rini | 303bfe8 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 211 | hw_watchdog_init(); |
| 212 | #endif |
Tom Rini | ac8fdf9 | 2013-08-30 16:28:44 -0400 | [diff] [blame] | 213 | #ifdef CONFIG_AM33XX |
| 214 | am33xx_spl_board_init(); |
| 215 | #endif |
Tom Rini | 9e0c260 | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 216 | } |
| 217 | |
SRICHARAN R | 3f30b0a | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 218 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 219 | { |
| 220 | typedef void __noreturn (*image_entry_noargs_t)(u32 *); |
| 221 | image_entry_noargs_t image_entry = |
| 222 | (image_entry_noargs_t) spl_image->entry_point; |
| 223 | |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 224 | u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS); |
| 225 | |
Andre Przywara | 6c52607 | 2017-01-02 11:48:31 +0000 | [diff] [blame] | 226 | debug("image entry point: 0x%lX\n", spl_image->entry_point); |
SRICHARAN R | 3f30b0a | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 227 | /* Pass the saved boot_params from rom code */ |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 228 | image_entry((u32 *)boot_params); |
SRICHARAN R | 3f30b0a | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 229 | } |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 230 | #endif |
Dmitry Lifshitz | 29211a0 | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 231 | |
| 232 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 233 | void arch_preboot_os(void) |
| 234 | { |
Scott Wood | 16519a3 | 2015-04-17 09:19:01 -0500 | [diff] [blame] | 235 | ahci_reset((void __iomem *)DWC_AHSATA_BASE); |
Dmitry Lifshitz | 29211a0 | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 236 | } |
| 237 | #endif |