blob: e1ea3515ac10804d6e25c915a85dceb75e705b4c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Chandan Nath77a73fe2012-01-09 20:38:59 +00002/*
3 * boot-common.c
4 *
5 * Common bootmode functions for omap based boards
6 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05007 * Copyright (C) 2011, Texas Instruments, Incorporated - https://www.ti.com/
Chandan Nath77a73fe2012-01-09 20:38:59 +00008 */
9
Dmitry Lifshitz29211a02014-12-15 16:02:58 +020010#include <ahci.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Keerthy0efb06d2022-01-27 13:16:52 +010012#include <dm/uclass.h>
13#include <fs_loader.h>
Tom Rini28591df2012-08-13 12:03:19 -070014#include <spl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000016#include <asm/omap_common.h>
Andrew Davisb3f0f832022-10-20 12:12:19 -050017#include <asm/omap_sec_common.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000018#include <asm/arch/omap.h>
Tom Rinia0b9fa52012-08-14 10:25:15 -070019#include <asm/arch/mmc_host_def.h>
Ilya Yanok741c57f2012-11-06 13:06:28 +000020#include <asm/arch/sys_proto.h>
Tom Rini303bfe82013-10-01 12:32:04 -040021#include <watchdog.h>
Dmitry Lifshitz29211a02014-12-15 16:02:58 +020022#include <scsi.h>
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020023#include <i2c.h>
Keerthy0efb06d2022-01-27 13:16:52 +010024#include <remoteproc.h>
Andrew Davisb3f0f832022-10-20 12:12:19 -050025#include <image.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000026
SRICHARAN R3f30b0a2013-04-24 00:41:24 +000027DECLARE_GLOBAL_DATA_PTR;
Chandan Nath77a73fe2012-01-09 20:38:59 +000028
Keerthy0efb06d2022-01-27 13:16:52 +010029#define IPU1_LOAD_ADDR (0xa17ff000)
30#define MAX_REMOTECORE_BIN_SIZE (8 * 0x100000)
31#define IPU2_LOAD_ADDR (IPU1_LOAD_ADDR + MAX_REMOTECORE_BIN_SIZE)
32
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020033__weak u32 omap_sys_boot_device(void)
34{
35 return BOOT_DEVICE_NONE;
36}
37
Tom Rini51df26c2013-05-31 12:31:59 -040038void save_omap_boot_params(void)
39{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020040 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
41 struct omap_boot_parameters *omap_boot_params;
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +020042 int sys_boot_device = 0;
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020043 u32 boot_device;
44 u32 boot_mode;
Tom Rini51df26c2013-05-31 12:31:59 -040045
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020046 if ((boot_params < NON_SECURE_SRAM_START) ||
47 (boot_params > NON_SECURE_SRAM_END))
Tom Rini51df26c2013-05-31 12:31:59 -040048 return;
49
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020050 omap_boot_params = (struct omap_boot_parameters *)boot_params;
Stefan Roese0f3a4802014-11-12 11:57:33 +010051
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020052 boot_device = omap_boot_params->boot_device;
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020053 boot_mode = MMCSD_MODE_UNDEFINED;
54
55 /* Boot device */
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020056
57#ifdef BOOT_DEVICE_NAND_I2C
Stefan Roese0f3a4802014-11-12 11:57:33 +010058 /*
59 * Re-map NAND&I2C boot-device to the "normal" NAND boot-device.
60 * Otherwise the SPL boot IF can't handle this device correctly.
61 * Somehow booting with Hynix 4GBit NAND H27U4G8 on Siemens
62 * Draco leads to this boot-device passed to SPL from the BootROM.
63 */
64 if (boot_device == BOOT_DEVICE_NAND_I2C)
65 boot_device = BOOT_DEVICE_NAND;
66#endif
Paul Kocialkowskib16d6d52015-07-15 16:02:21 +020067#ifdef BOOT_DEVICE_QSPI_4
Tom Rini560ef452014-04-03 07:52:56 -040068 /*
69 * We get different values for QSPI_1 and QSPI_4 being used, but
70 * don't actually care about this difference. Rather than
71 * mangle the later code, if we're coming in as QSPI_4 just
72 * change to the QSPI_1 value.
73 */
Paul Kocialkowskib16d6d52015-07-15 16:02:21 +020074 if (boot_device == BOOT_DEVICE_QSPI_4)
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020075 boot_device = BOOT_DEVICE_SPI;
76#endif
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020077 /*
78 * When booting from peripheral booting, the boot device is not usable
79 * as-is (unless there is support for it), so the boot device is instead
80 * figured out using the SYS_BOOT pins.
81 */
82 switch (boot_device) {
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +020083#if defined(BOOT_DEVICE_UART) && !defined(CONFIG_SPL_YMODEM_SUPPORT)
84 case BOOT_DEVICE_UART:
85 sys_boot_device = 1;
86 break;
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020087#endif
Abel Vesa5ea11ba52019-02-01 16:40:07 +000088#if defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_STORAGE)
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +020089 case BOOT_DEVICE_USB:
90 sys_boot_device = 1;
91 break;
Paul Kocialkowski062fbb62015-07-15 16:02:23 +020092#endif
Faiz Abbasc01553b2018-02-16 21:17:44 +053093#if defined(BOOT_DEVICE_USBETH) && !defined(CONFIG_SPL_USB_ETHER)
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +020094 case BOOT_DEVICE_USBETH:
95 sys_boot_device = 1;
96 break;
97#endif
Simon Glasse5cd9a42021-07-10 21:14:26 -060098#if defined(BOOT_DEVICE_CPGMAC) && !defined(CONFIG_SPL_ETH)
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +020099 case BOOT_DEVICE_CPGMAC:
100 sys_boot_device = 1;
101 break;
102#endif
Andrew F. Davis6d932e62019-01-17 13:43:02 -0600103#if defined(BOOT_DEVICE_DFU) && !defined(CONFIG_SPL_DFU)
B, Ravi2fb19df2016-07-28 17:39:17 +0530104 case BOOT_DEVICE_DFU:
105 sys_boot_device = 1;
106 break;
107#endif
Paul Kocialkowskidd15fab2015-08-27 10:46:09 +0200108 }
109
110 if (sys_boot_device) {
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200111 boot_device = omap_sys_boot_device();
112
113 /* MMC raw mode will fallback to FS mode. */
114 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
115 (boot_device <= MMC_BOOT_DEVICES_END))
116 boot_mode = MMCSD_MODE_RAW;
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200117 }
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200118
119 gd->arch.omap_boot_device = boot_device;
120
121 /* Boot mode */
122
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200123#ifdef CONFIG_OMAP34XX
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200124 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
125 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200126 switch (boot_device) {
127 case BOOT_DEVICE_MMC1:
Tom Rini9266bf42016-05-02 10:52:51 -0400128 boot_mode = MMCSD_MODE_FS;
129 break;
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200130 case BOOT_DEVICE_MMC2:
131 boot_mode = MMCSD_MODE_RAW;
132 break;
133 }
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200134 }
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200135#else
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200136 /*
137 * If the boot device was dynamically changed and doesn't match what
138 * the bootrom initially booted, we cannot use the boot device
139 * descriptor to figure out the boot mode.
140 */
141 if ((boot_device == omap_boot_params->boot_device) &&
142 (boot_device >= MMC_BOOT_DEVICES_START) &&
143 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200144 boot_params = omap_boot_params->boot_device_descriptor;
145 if ((boot_params < NON_SECURE_SRAM_START) ||
146 (boot_params > NON_SECURE_SRAM_END))
147 return;
148
149 boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET));
150 if ((boot_params < NON_SECURE_SRAM_START) ||
151 (boot_params > NON_SECURE_SRAM_END))
152 return;
153
154 boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET));
155
156 if (boot_mode != MMCSD_MODE_FS &&
157 boot_mode != MMCSD_MODE_RAW)
158#ifdef CONFIG_SUPPORT_EMMC_BOOT
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200159 boot_mode = MMCSD_MODE_EMMCBOOT;
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200160#else
161 boot_mode = MMCSD_MODE_UNDEFINED;
162#endif
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200163 }
Paul Kocialkowski062fbb62015-07-15 16:02:23 +0200164#endif
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200165
166 gd->arch.omap_boot_mode = boot_mode;
167
Tom Rini9fbd9ef2023-05-11 14:07:24 -0400168#if !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX)
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200169
170 /* CH flags */
171
172 gd->arch.omap_ch_flags = omap_boot_params->ch_flags;
Tom Rini560ef452014-04-03 07:52:56 -0400173#endif
Tom Rini51df26c2013-05-31 12:31:59 -0400174}
175
Chandan Nath77a73fe2012-01-09 20:38:59 +0000176#ifdef CONFIG_SPL_BUILD
Tom Rini0be93ff2012-08-13 12:53:23 -0700177u32 spl_boot_device(void)
Chandan Nath77a73fe2012-01-09 20:38:59 +0000178{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200179 return gd->arch.omap_boot_device;
Chandan Nath77a73fe2012-01-09 20:38:59 +0000180}
181
Andre Przywara3cb12ef2021-07-12 11:06:49 +0100182u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
Chandan Nath77a73fe2012-01-09 20:38:59 +0000183{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200184 return gd->arch.omap_boot_mode;
Chandan Nath77a73fe2012-01-09 20:38:59 +0000185}
Tom Rinia0b9fa52012-08-14 10:25:15 -0700186
Keerthy0efb06d2022-01-27 13:16:52 +0100187int load_firmware(char *name_fw, u32 *loadaddr)
188{
189 struct udevice *fsdev;
190 int size = 0;
191
MD Danish Anwar71c6a012024-03-14 20:03:10 +0530192 if (!CONFIG_IS_ENABLED(FS_LOADER))
Keerthy0efb06d2022-01-27 13:16:52 +0100193 return 0;
194
195 if (!*loadaddr)
196 return 0;
197
Sean Anderson5cd0cb32022-12-29 11:52:59 -0500198 if (!get_fs_loader(&fsdev)) {
Keerthy0efb06d2022-01-27 13:16:52 +0100199 size = request_firmware_into_buf(fsdev, name_fw,
200 (void *)*loadaddr, 0, 0);
201 }
202
203 return size;
204}
205
206void spl_boot_ipu(void)
207{
208 int ret, size;
209 u32 loadaddr = IPU1_LOAD_ADDR;
210
211 if (!IS_ENABLED(CONFIG_SPL_BUILD) ||
212 !IS_ENABLED(CONFIG_REMOTEPROC_TI_IPU))
213 return;
214
215 size = load_firmware("dra7-ipu1-fw.xem4", &loadaddr);
216 if (size <= 0) {
217 pr_err("Firmware loading failed\n");
218 goto skip_ipu1;
219 }
220
221 enable_ipu1_clocks();
222 ret = rproc_dev_init(0);
223 if (ret) {
224 debug("%s: IPU1 failed to initialize on rproc (%d)\n",
225 __func__, ret);
226 goto skip_ipu1;
227 }
228
229 ret = rproc_load(0, IPU1_LOAD_ADDR, 0x2000000);
230 if (ret) {
231 debug("%s: IPU1 failed to load on rproc (%d)\n", __func__,
232 ret);
233 goto skip_ipu1;
234 }
235
236 debug("Starting IPU1...\n");
237
238 ret = rproc_start(0);
239 if (ret)
240 debug("%s: IPU1 failed to start (%d)\n", __func__, ret);
241
242skip_ipu1:
243 loadaddr = IPU2_LOAD_ADDR;
244 size = load_firmware("dra7-ipu2-fw.xem4", &loadaddr);
245 if (size <= 0) {
246 pr_err("Firmware loading failed for ipu2\n");
247 return;
248 }
249
250 enable_ipu2_clocks();
251 ret = rproc_dev_init(1);
252 if (ret) {
253 debug("%s: IPU2 failed to initialize on rproc (%d)\n", __func__,
254 ret);
255 return;
256 }
257
258 ret = rproc_load(1, IPU2_LOAD_ADDR, 0x2000000);
259 if (ret) {
260 debug("%s: IPU2 failed to load on rproc (%d)\n", __func__,
261 ret);
262 return;
263 }
264
265 debug("Starting IPU2...\n");
266
267 ret = rproc_start(1);
268 if (ret)
269 debug("%s: IPU2 failed to start (%d)\n", __func__, ret);
270}
271
Tom Rini9e0c2602012-08-14 12:26:08 -0700272void spl_board_init(void)
273{
Tom Rinic95d6c42014-12-19 16:53:24 -0500274 /* Prepare console output */
275 preloader_console_init();
Samuel Hollandb03e6662020-05-07 18:08:10 -0500276
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200277#if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
Tom Rini9e0c2602012-08-14 12:26:08 -0700278 gpmc_init();
279#endif
Simon Glassbccfc2e2021-07-10 21:14:36 -0600280#if defined(CONFIG_SPL_I2C) && !CONFIG_IS_ENABLED(DM_I2C)
Tom Rinia7a9bc02021-08-18 23:12:29 -0400281 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200282#endif
Simon Glass762b9972021-07-10 21:14:27 -0600283#if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW)
Ilya Yanok87b82cc2013-02-05 11:36:25 +0000284 arch_misc_init();
285#endif
Suniel Mahesh370d4912019-07-31 21:54:07 +0530286#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
Tom Rini303bfe82013-10-01 12:32:04 -0400287 hw_watchdog_init();
288#endif
Tom Riniac8fdf92013-08-30 16:28:44 -0400289#ifdef CONFIG_AM33XX
290 am33xx_spl_board_init();
291#endif
Keerthy0efb06d2022-01-27 13:16:52 +0100292 if (IS_ENABLED(CONFIG_SPL_BUILD) &&
293 IS_ENABLED(CONFIG_REMOTEPROC_TI_IPU))
294 spl_boot_ipu();
Tom Rini9e0c2602012-08-14 12:26:08 -0700295}
296
SRICHARAN R3f30b0a2013-04-24 00:41:24 +0000297void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
298{
299 typedef void __noreturn (*image_entry_noargs_t)(u32 *);
300 image_entry_noargs_t image_entry =
301 (image_entry_noargs_t) spl_image->entry_point;
302
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200303 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
304
Andre Przywara6c526072017-01-02 11:48:31 +0000305 debug("image entry point: 0x%lX\n", spl_image->entry_point);
SRICHARAN R3f30b0a2013-04-24 00:41:24 +0000306 /* Pass the saved boot_params from rom code */
Paul Kocialkowskid5b76242015-07-15 16:02:19 +0200307 image_entry((u32 *)boot_params);
SRICHARAN R3f30b0a2013-04-24 00:41:24 +0000308}
Chandan Nath77a73fe2012-01-09 20:38:59 +0000309#endif
Dmitry Lifshitz29211a02014-12-15 16:02:58 +0200310
Andrew Davisb3f0f832022-10-20 12:12:19 -0500311#ifdef CONFIG_TI_SECURE_DEVICE
312void board_fit_image_post_process(const void *fit, int node, void **p_image,
313 size_t *p_size)
314{
315 secure_boot_verify_image(p_image, p_size);
316}
317
318static void tee_image_process(ulong tee_image, size_t tee_size)
319{
320 secure_tee_install((u32)tee_image);
321}
322U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, tee_image_process);
323#endif