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> |
Tom Rini | 47f7bca | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 13 | #include <spl.h> |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 14 | #include <asm/omap_common.h> |
| 15 | #include <asm/arch/omap.h> |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 16 | #include <asm/arch/mmc_host_def.h> |
Ilya Yanok | 1befaff | 2012-11-06 13:06:28 +0000 | [diff] [blame] | 17 | #include <asm/arch/sys_proto.h> |
Tom Rini | 6843918 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 18 | #include <watchdog.h> |
Dmitry Lifshitz | 87791ad | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 19 | #include <scsi.h> |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 20 | |
SRICHARAN R | 4a0eb75 | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 21 | DECLARE_GLOBAL_DATA_PTR; |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 22 | |
Tom Rini | 4596dcc | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 23 | void save_omap_boot_params(void) |
| 24 | { |
| 25 | u32 rom_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS); |
| 26 | u8 boot_device; |
| 27 | u32 dev_desc, dev_data; |
| 28 | |
| 29 | if ((rom_params < NON_SECURE_SRAM_START) || |
| 30 | (rom_params > NON_SECURE_SRAM_END)) |
| 31 | return; |
| 32 | |
| 33 | /* |
| 34 | * rom_params can be type casted to omap_boot_parameters and |
| 35 | * used. But it not correct to assume that romcode structure |
| 36 | * encoding would be same as u-boot. So use the defined offsets. |
| 37 | */ |
Stefan Roese | e49631a | 2014-11-12 11:57:33 +0100 | [diff] [blame] | 38 | boot_device = *((u8 *)(rom_params + BOOT_DEVICE_OFFSET)); |
| 39 | |
| 40 | #if defined(BOOT_DEVICE_NAND_I2C) |
| 41 | /* |
| 42 | * Re-map NAND&I2C boot-device to the "normal" NAND boot-device. |
| 43 | * Otherwise the SPL boot IF can't handle this device correctly. |
| 44 | * Somehow booting with Hynix 4GBit NAND H27U4G8 on Siemens |
| 45 | * Draco leads to this boot-device passed to SPL from the BootROM. |
| 46 | */ |
| 47 | if (boot_device == BOOT_DEVICE_NAND_I2C) |
| 48 | boot_device = BOOT_DEVICE_NAND; |
| 49 | #endif |
| 50 | gd->arch.omap_boot_params.omap_bootdevice = boot_device; |
Tom Rini | 4596dcc | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 51 | |
| 52 | gd->arch.omap_boot_params.ch_flags = |
| 53 | *((u8 *)(rom_params + CH_FLAGS_OFFSET)); |
| 54 | |
| 55 | if ((boot_device >= MMC_BOOT_DEVICES_START) && |
| 56 | (boot_device <= MMC_BOOT_DEVICES_END)) { |
Lokesh Vutla | 5718040 | 2013-07-30 11:36:31 +0530 | [diff] [blame] | 57 | #if !defined(CONFIG_AM33XX) && !defined(CONFIG_TI81XX) && \ |
| 58 | !defined(CONFIG_AM43XX) |
Tom Rini | 4596dcc | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 59 | if ((omap_hw_init_context() == |
| 60 | OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)) { |
| 61 | gd->arch.omap_boot_params.omap_bootmode = |
| 62 | *((u8 *)(rom_params + BOOT_MODE_OFFSET)); |
| 63 | } else |
| 64 | #endif |
| 65 | { |
| 66 | dev_desc = *((u32 *)(rom_params + DEV_DESC_PTR_OFFSET)); |
| 67 | dev_data = *((u32 *)(dev_desc + DEV_DATA_PTR_OFFSET)); |
| 68 | gd->arch.omap_boot_params.omap_bootmode = |
| 69 | *((u32 *)(dev_data + BOOT_MODE_OFFSET)); |
| 70 | } |
| 71 | } |
Tom Rini | 79b079f | 2014-04-03 07:52:56 -0400 | [diff] [blame] | 72 | |
Felipe Balbi | d11ac4b | 2014-11-06 08:28:51 -0600 | [diff] [blame] | 73 | #if defined(CONFIG_DRA7XX) || defined(CONFIG_AM57XX) |
Tom Rini | 79b079f | 2014-04-03 07:52:56 -0400 | [diff] [blame] | 74 | /* |
| 75 | * We get different values for QSPI_1 and QSPI_4 being used, but |
| 76 | * don't actually care about this difference. Rather than |
| 77 | * mangle the later code, if we're coming in as QSPI_4 just |
| 78 | * change to the QSPI_1 value. |
| 79 | */ |
| 80 | if (gd->arch.omap_boot_params.omap_bootdevice == 11) |
| 81 | gd->arch.omap_boot_params.omap_bootdevice = BOOT_DEVICE_SPI; |
| 82 | #endif |
Tom Rini | 4596dcc | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 83 | } |
| 84 | |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 85 | #ifdef CONFIG_SPL_BUILD |
Tom Rini | 8e1b836 | 2012-08-13 12:53:23 -0700 | [diff] [blame] | 86 | u32 spl_boot_device(void) |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 87 | { |
SRICHARAN R | 4a0eb75 | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 88 | return (u32) (gd->arch.omap_boot_params.omap_bootdevice); |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Tom Rini | 37189a1 | 2012-08-14 09:19:44 -0700 | [diff] [blame] | 91 | u32 spl_boot_mode(void) |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 92 | { |
Tom Rini | 7dbe63b | 2014-02-05 10:24:18 -0500 | [diff] [blame] | 93 | u32 val = gd->arch.omap_boot_params.omap_bootmode; |
| 94 | |
| 95 | if (val == MMCSD_MODE_RAW) |
| 96 | return MMCSD_MODE_RAW; |
Guillaume GARDET | 205b4f3 | 2014-10-15 17:53:11 +0200 | [diff] [blame] | 97 | else if (val == MMCSD_MODE_FS) |
| 98 | return MMCSD_MODE_FS; |
Tom Rini | 7dbe63b | 2014-02-05 10:24:18 -0500 | [diff] [blame] | 99 | else |
| 100 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
| 101 | return MMCSD_MODE_EMMCBOOT; |
| 102 | #else |
| 103 | return MMCSD_MODE_UNDEFINED; |
| 104 | #endif |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 105 | } |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 106 | |
Tom Rini | d7cb93b | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 107 | void spl_board_init(void) |
| 108 | { |
Tom Rini | a6b541b | 2014-12-19 16:53:24 -0500 | [diff] [blame] | 109 | /* |
| 110 | * Save the boot parameters passed from romcode. |
| 111 | * We cannot delay the saving further than this, |
| 112 | * to prevent overwrites. |
| 113 | */ |
| 114 | save_omap_boot_params(); |
| 115 | |
| 116 | /* Prepare console output */ |
| 117 | preloader_console_init(); |
| 118 | |
Tom Rini | d7cb93b | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 119 | #ifdef CONFIG_SPL_NAND_SUPPORT |
| 120 | gpmc_init(); |
| 121 | #endif |
Ilya Yanok | da07c21 | 2013-02-05 11:36:25 +0000 | [diff] [blame] | 122 | #if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT) |
| 123 | arch_misc_init(); |
| 124 | #endif |
Tom Rini | 6843918 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 125 | #if defined(CONFIG_HW_WATCHDOG) |
| 126 | hw_watchdog_init(); |
| 127 | #endif |
Tom Rini | 6a0d803 | 2013-08-30 16:28:44 -0400 | [diff] [blame] | 128 | #ifdef CONFIG_AM33XX |
| 129 | am33xx_spl_board_init(); |
| 130 | #endif |
Tom Rini | d7cb93b | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 133 | int board_mmc_init(bd_t *bis) |
| 134 | { |
| 135 | switch (spl_boot_device()) { |
| 136 | case BOOT_DEVICE_MMC1: |
Nikita Kiryanov | e3913f5 | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 137 | omap_mmc_init(0, 0, 0, -1, -1); |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 138 | break; |
| 139 | case BOOT_DEVICE_MMC2: |
| 140 | case BOOT_DEVICE_MMC2_2: |
Nikita Kiryanov | e3913f5 | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 141 | omap_mmc_init(1, 0, 0, -1, -1); |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 142 | break; |
| 143 | } |
| 144 | return 0; |
| 145 | } |
SRICHARAN R | 4a0eb75 | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 146 | |
| 147 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 148 | { |
| 149 | typedef void __noreturn (*image_entry_noargs_t)(u32 *); |
| 150 | image_entry_noargs_t image_entry = |
| 151 | (image_entry_noargs_t) spl_image->entry_point; |
| 152 | |
| 153 | debug("image entry point: 0x%X\n", spl_image->entry_point); |
| 154 | /* Pass the saved boot_params from rom code */ |
| 155 | image_entry((u32 *)&gd->arch.omap_boot_params); |
| 156 | } |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 157 | #endif |
Dmitry Lifshitz | 87791ad | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 158 | |
| 159 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 160 | void arch_preboot_os(void) |
| 161 | { |
Scott Wood | 9efaca3 | 2015-04-17 09:19:01 -0500 | [diff] [blame] | 162 | ahci_reset((void __iomem *)DWC_AHSATA_BASE); |
Dmitry Lifshitz | 87791ad | 2014-12-15 16:02:58 +0200 | [diff] [blame] | 163 | } |
| 164 | #endif |
Dileep Katta | ecd8557 | 2015-03-27 23:06:57 +0530 | [diff] [blame] | 165 | |
| 166 | #if defined(CONFIG_CMD_FASTBOOT) && !defined(CONFIG_ENV_IS_NOWHERE) |
| 167 | int fb_set_reboot_flag(void) |
| 168 | { |
| 169 | printf("Setting reboot to fastboot flag ...\n"); |
| 170 | setenv("dofastboot", "1"); |
| 171 | saveenv(); |
| 172 | return 0; |
| 173 | } |
| 174 | #endif |