blob: cb18908867dd06d2494a2ef8dce9776313dfe663 [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>
Tom Rini47f7bca2012-08-13 12:03:19 -070012#include <spl.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000013#include <asm/omap_common.h>
14#include <asm/arch/omap.h>
Tom Rinif0881252012-08-14 10:25:15 -070015#include <asm/arch/mmc_host_def.h>
Ilya Yanok1befaff2012-11-06 13:06:28 +000016#include <asm/arch/sys_proto.h>
Tom Rini68439182013-10-01 12:32:04 -040017#include <watchdog.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000018
SRICHARAN R4a0eb752013-04-24 00:41:24 +000019DECLARE_GLOBAL_DATA_PTR;
Chandan Nath8a8f0842012-01-09 20:38:59 +000020
Tom Rini4596dcc2013-05-31 12:31:59 -040021void save_omap_boot_params(void)
22{
23 u32 rom_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
24 u8 boot_device;
25 u32 dev_desc, dev_data;
26
27 if ((rom_params < NON_SECURE_SRAM_START) ||
28 (rom_params > NON_SECURE_SRAM_END))
29 return;
30
31 /*
32 * rom_params can be type casted to omap_boot_parameters and
33 * used. But it not correct to assume that romcode structure
34 * encoding would be same as u-boot. So use the defined offsets.
35 */
Stefan Roesee49631a2014-11-12 11:57:33 +010036 boot_device = *((u8 *)(rom_params + BOOT_DEVICE_OFFSET));
37
38#if defined(BOOT_DEVICE_NAND_I2C)
39 /*
40 * Re-map NAND&I2C boot-device to the "normal" NAND boot-device.
41 * Otherwise the SPL boot IF can't handle this device correctly.
42 * Somehow booting with Hynix 4GBit NAND H27U4G8 on Siemens
43 * Draco leads to this boot-device passed to SPL from the BootROM.
44 */
45 if (boot_device == BOOT_DEVICE_NAND_I2C)
46 boot_device = BOOT_DEVICE_NAND;
47#endif
48 gd->arch.omap_boot_params.omap_bootdevice = boot_device;
Tom Rini4596dcc2013-05-31 12:31:59 -040049
50 gd->arch.omap_boot_params.ch_flags =
51 *((u8 *)(rom_params + CH_FLAGS_OFFSET));
52
53 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
54 (boot_device <= MMC_BOOT_DEVICES_END)) {
Lokesh Vutla57180402013-07-30 11:36:31 +053055#if !defined(CONFIG_AM33XX) && !defined(CONFIG_TI81XX) && \
56 !defined(CONFIG_AM43XX)
Tom Rini4596dcc2013-05-31 12:31:59 -040057 if ((omap_hw_init_context() ==
58 OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)) {
59 gd->arch.omap_boot_params.omap_bootmode =
60 *((u8 *)(rom_params + BOOT_MODE_OFFSET));
61 } else
62#endif
63 {
64 dev_desc = *((u32 *)(rom_params + DEV_DESC_PTR_OFFSET));
65 dev_data = *((u32 *)(dev_desc + DEV_DATA_PTR_OFFSET));
66 gd->arch.omap_boot_params.omap_bootmode =
67 *((u32 *)(dev_data + BOOT_MODE_OFFSET));
68 }
69 }
Tom Rini79b079f2014-04-03 07:52:56 -040070
Felipe Balbid11ac4b2014-11-06 08:28:51 -060071#if defined(CONFIG_DRA7XX) || defined(CONFIG_AM57XX)
Tom Rini79b079f2014-04-03 07:52:56 -040072 /*
73 * We get different values for QSPI_1 and QSPI_4 being used, but
74 * don't actually care about this difference. Rather than
75 * mangle the later code, if we're coming in as QSPI_4 just
76 * change to the QSPI_1 value.
77 */
78 if (gd->arch.omap_boot_params.omap_bootdevice == 11)
79 gd->arch.omap_boot_params.omap_bootdevice = BOOT_DEVICE_SPI;
80#endif
Tom Rini4596dcc2013-05-31 12:31:59 -040081}
82
Chandan Nath8a8f0842012-01-09 20:38:59 +000083#ifdef CONFIG_SPL_BUILD
Tom Rini8e1b8362012-08-13 12:53:23 -070084u32 spl_boot_device(void)
Chandan Nath8a8f0842012-01-09 20:38:59 +000085{
SRICHARAN R4a0eb752013-04-24 00:41:24 +000086 return (u32) (gd->arch.omap_boot_params.omap_bootdevice);
Chandan Nath8a8f0842012-01-09 20:38:59 +000087}
88
Tom Rini37189a12012-08-14 09:19:44 -070089u32 spl_boot_mode(void)
Chandan Nath8a8f0842012-01-09 20:38:59 +000090{
Tom Rini7dbe63b2014-02-05 10:24:18 -050091 u32 val = gd->arch.omap_boot_params.omap_bootmode;
92
93 if (val == MMCSD_MODE_RAW)
94 return MMCSD_MODE_RAW;
Guillaume GARDET205b4f32014-10-15 17:53:11 +020095 else if (val == MMCSD_MODE_FS)
96 return MMCSD_MODE_FS;
Tom Rini7dbe63b2014-02-05 10:24:18 -050097 else
98#ifdef CONFIG_SUPPORT_EMMC_BOOT
99 return MMCSD_MODE_EMMCBOOT;
100#else
101 return MMCSD_MODE_UNDEFINED;
102#endif
Chandan Nath8a8f0842012-01-09 20:38:59 +0000103}
Tom Rinif0881252012-08-14 10:25:15 -0700104
Tom Rinid7cb93b2012-08-14 12:26:08 -0700105void spl_board_init(void)
106{
107#ifdef CONFIG_SPL_NAND_SUPPORT
108 gpmc_init();
109#endif
Ilya Yanokda07c212013-02-05 11:36:25 +0000110#if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
111 arch_misc_init();
112#endif
Tom Rini68439182013-10-01 12:32:04 -0400113#if defined(CONFIG_HW_WATCHDOG)
114 hw_watchdog_init();
115#endif
Tom Rini6a0d8032013-08-30 16:28:44 -0400116#ifdef CONFIG_AM33XX
117 am33xx_spl_board_init();
118#endif
Tom Rinid7cb93b2012-08-14 12:26:08 -0700119}
120
Tom Rinif0881252012-08-14 10:25:15 -0700121int board_mmc_init(bd_t *bis)
122{
123 switch (spl_boot_device()) {
124 case BOOT_DEVICE_MMC1:
Nikita Kiryanove3913f52012-12-03 02:19:47 +0000125 omap_mmc_init(0, 0, 0, -1, -1);
Tom Rinif0881252012-08-14 10:25:15 -0700126 break;
127 case BOOT_DEVICE_MMC2:
128 case BOOT_DEVICE_MMC2_2:
Nikita Kiryanove3913f52012-12-03 02:19:47 +0000129 omap_mmc_init(1, 0, 0, -1, -1);
Tom Rinif0881252012-08-14 10:25:15 -0700130 break;
131 }
132 return 0;
133}
SRICHARAN R4a0eb752013-04-24 00:41:24 +0000134
135void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
136{
137 typedef void __noreturn (*image_entry_noargs_t)(u32 *);
138 image_entry_noargs_t image_entry =
139 (image_entry_noargs_t) spl_image->entry_point;
140
141 debug("image entry point: 0x%X\n", spl_image->entry_point);
142 /* Pass the saved boot_params from rom code */
143 image_entry((u32 *)&gd->arch.omap_boot_params);
144}
Chandan Nath8a8f0842012-01-09 20:38:59 +0000145#endif