]> git.sur5r.net Git - u-boot/blob - arch/arm/cpu/armv7/omap-common/boot-common.c
omap-common: Boot device define instead of hardcoded value
[u-boot] / arch / arm / cpu / armv7 / omap-common / boot-common.c
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  *
8  * SPDX-License-Identifier:     GPL-2.0+
9  */
10
11 #include <common.h>
12 #include <ahci.h>
13 #include <spl.h>
14 #include <asm/omap_common.h>
15 #include <asm/arch/omap.h>
16 #include <asm/arch/mmc_host_def.h>
17 #include <asm/arch/sys_proto.h>
18 #include <watchdog.h>
19 #include <scsi.h>
20 #include <i2c.h>
21
22 DECLARE_GLOBAL_DATA_PTR;
23
24 void save_omap_boot_params(void)
25 {
26         u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
27         struct omap_boot_parameters *omap_boot_params;
28         u32 boot_device;
29         u32 boot_mode;
30
31         if ((boot_params < NON_SECURE_SRAM_START) ||
32             (boot_params > NON_SECURE_SRAM_END))
33                 return;
34
35         omap_boot_params = (struct omap_boot_parameters *)boot_params;
36
37         /* Boot device */
38
39         boot_device = omap_boot_params->boot_device;
40
41 #ifdef BOOT_DEVICE_NAND_I2C
42         /*
43          * Re-map NAND&I2C boot-device to the "normal" NAND boot-device.
44          * Otherwise the SPL boot IF can't handle this device correctly.
45          * Somehow booting with Hynix 4GBit NAND H27U4G8 on Siemens
46          * Draco leads to this boot-device passed to SPL from the BootROM.
47          */
48         if (boot_device == BOOT_DEVICE_NAND_I2C)
49                 boot_device = BOOT_DEVICE_NAND;
50 #endif
51 #ifdef BOOT_DEVICE_QSPI_4
52         /*
53          * We get different values for QSPI_1 and QSPI_4 being used, but
54          * don't actually care about this difference.  Rather than
55          * mangle the later code, if we're coming in as QSPI_4 just
56          * change to the QSPI_1 value.
57          */
58         if (boot_device == BOOT_DEVICE_QSPI_4)
59                 boot_device = BOOT_DEVICE_SPI;
60 #endif
61
62         gd->arch.omap_boot_device = boot_device;
63
64         /* Boot mode */
65
66         boot_mode = MMCSD_MODE_UNDEFINED;
67
68         if ((boot_device >= MMC_BOOT_DEVICES_START) &&
69             (boot_device <= MMC_BOOT_DEVICES_END)) {
70 #ifdef CONFIG_OMAP34XX
71                 switch (boot_device) {
72                 case BOOT_DEVICE_MMC1:
73                         boot_mode = MMCSD_MODE_FS;
74                         break;
75                 case BOOT_DEVICE_MMC2:
76                         boot_mode = MMCSD_MODE_RAW;
77                         break;
78                 }
79 #else
80                 boot_params = omap_boot_params->boot_device_descriptor;
81                 if ((boot_params < NON_SECURE_SRAM_START) ||
82                     (boot_params > NON_SECURE_SRAM_END))
83                         return;
84
85                 boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET));
86                 if ((boot_params < NON_SECURE_SRAM_START) ||
87                     (boot_params > NON_SECURE_SRAM_END))
88                         return;
89
90                 boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET));
91
92                 if (boot_mode != MMCSD_MODE_FS &&
93                     boot_mode != MMCSD_MODE_RAW)
94 #ifdef CONFIG_SUPPORT_EMMC_BOOT
95                         boot_mode = MMCSD_MODE_EMMCBOOT
96 #else
97                         boot_mode = MMCSD_MODE_UNDEFINED;
98 #endif
99 #endif
100         }
101
102         gd->arch.omap_boot_mode = boot_mode;
103
104 #if !defined(CONFIG_TI814X) && !defined(CONFIG_TI816X) && \
105     !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX)
106
107         /* CH flags */
108
109         gd->arch.omap_ch_flags = omap_boot_params->ch_flags;
110 #endif
111 }
112
113 #ifdef CONFIG_SPL_BUILD
114 u32 spl_boot_device(void)
115 {
116         return gd->arch.omap_boot_device;
117 }
118
119 u32 spl_boot_mode(void)
120 {
121         return gd->arch.omap_boot_mode;
122 }
123
124 void spl_board_init(void)
125 {
126         /*
127          * Save the boot parameters passed from romcode.
128          * We cannot delay the saving further than this,
129          * to prevent overwrites.
130          */
131         save_omap_boot_params();
132
133         /* Prepare console output */
134         preloader_console_init();
135
136 #if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
137         gpmc_init();
138 #endif
139 #ifdef CONFIG_SPL_I2C_SUPPORT
140         i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
141 #endif
142 #if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
143         arch_misc_init();
144 #endif
145 #if defined(CONFIG_HW_WATCHDOG)
146         hw_watchdog_init();
147 #endif
148 #ifdef CONFIG_AM33XX
149         am33xx_spl_board_init();
150 #endif
151 }
152
153 int board_mmc_init(bd_t *bis)
154 {
155         switch (spl_boot_device()) {
156         case BOOT_DEVICE_MMC1:
157                 omap_mmc_init(0, 0, 0, -1, -1);
158                 break;
159         case BOOT_DEVICE_MMC2:
160         case BOOT_DEVICE_MMC2_2:
161                 omap_mmc_init(1, 0, 0, -1, -1);
162                 break;
163         }
164         return 0;
165 }
166
167 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
168 {
169         typedef void __noreturn (*image_entry_noargs_t)(u32 *);
170         image_entry_noargs_t image_entry =
171                         (image_entry_noargs_t) spl_image->entry_point;
172
173         u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
174
175         debug("image entry point: 0x%X\n", spl_image->entry_point);
176         /* Pass the saved boot_params from rom code */
177         image_entry((u32 *)boot_params);
178 }
179 #endif
180
181 #ifdef CONFIG_SCSI_AHCI_PLAT
182 void arch_preboot_os(void)
183 {
184         ahci_reset((void __iomem *)DWC_AHSATA_BASE);
185 }
186 #endif
187
188 #if defined(CONFIG_USB_FUNCTION_FASTBOOT) && !defined(CONFIG_ENV_IS_NOWHERE)
189 int fb_set_reboot_flag(void)
190 {
191         printf("Setting reboot to fastboot flag ...\n");
192         setenv("dofastboot", "1");
193         saveenv();
194         return 0;
195 }
196 #endif