blob: 57917da25cf21ccf5a6848dbf9f94b9747f4622a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Chandan Nath8a8f0842012-01-09 20:38:59 +00002/*
3 * boot-common.c
4 *
5 * Common bootmode functions for omap based boards
6 *
Nishanth Menona94a4072023-11-01 15:56:03 -05007 * Copyright (C) 2011, Texas Instruments, Incorporated - https://www.ti.com/
Chandan Nath8a8f0842012-01-09 20:38:59 +00008 */
9
10#include <common.h>
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +020011#include <ahci.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Keerthy01979092022-01-27 13:16:52 +010013#include <dm/uclass.h>
14#include <fs_loader.h>
Tom Rini47f7bca2012-08-13 12:03:19 -070015#include <spl.h>
Simon Glass401d1c42020-10-30 21:38:53 -060016#include <asm/global_data.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000017#include <asm/omap_common.h>
Andrew Davis1eaffe32022-10-20 12:12:19 -050018#include <asm/omap_sec_common.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000019#include <asm/arch/omap.h>
Tom Rinif0881252012-08-14 10:25:15 -070020#include <asm/arch/mmc_host_def.h>
Ilya Yanok1befaff2012-11-06 13:06:28 +000021#include <asm/arch/sys_proto.h>
Tom Rini68439182013-10-01 12:32:04 -040022#include <watchdog.h>
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +020023#include <scsi.h>
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020024#include <i2c.h>
Keerthy01979092022-01-27 13:16:52 +010025#include <remoteproc.h>
Andrew Davis1eaffe32022-10-20 12:12:19 -050026#include <image.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000027
SRICHARAN R4a0eb752013-04-24 00:41:24 +000028DECLARE_GLOBAL_DATA_PTR;
Chandan Nath8a8f0842012-01-09 20:38:59 +000029
Keerthy01979092022-01-27 13:16:52 +010030#define IPU1_LOAD_ADDR (0xa17ff000)
31#define MAX_REMOTECORE_BIN_SIZE (8 * 0x100000)
32#define IPU2_LOAD_ADDR (IPU1_LOAD_ADDR + MAX_REMOTECORE_BIN_SIZE)
33
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020034__weak u32 omap_sys_boot_device(void)
35{
36 return BOOT_DEVICE_NONE;
37}
38
Tom Rini4596dcc2013-05-31 12:31:59 -040039void save_omap_boot_params(void)
40{
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020041 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
42 struct omap_boot_parameters *omap_boot_params;
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +020043 int sys_boot_device = 0;
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020044 u32 boot_device;
45 u32 boot_mode;
Tom Rini4596dcc2013-05-31 12:31:59 -040046
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020047 if ((boot_params < NON_SECURE_SRAM_START) ||
48 (boot_params > NON_SECURE_SRAM_END))
Tom Rini4596dcc2013-05-31 12:31:59 -040049 return;
50
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020051 omap_boot_params = (struct omap_boot_parameters *)boot_params;
Stefan Roesee49631a2014-11-12 11:57:33 +010052
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020053 boot_device = omap_boot_params->boot_device;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020054 boot_mode = MMCSD_MODE_UNDEFINED;
55
56 /* Boot device */
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020057
58#ifdef BOOT_DEVICE_NAND_I2C
Stefan Roesee49631a2014-11-12 11:57:33 +010059 /*
60 * Re-map NAND&I2C boot-device to the "normal" NAND boot-device.
61 * Otherwise the SPL boot IF can't handle this device correctly.
62 * Somehow booting with Hynix 4GBit NAND H27U4G8 on Siemens
63 * Draco leads to this boot-device passed to SPL from the BootROM.
64 */
65 if (boot_device == BOOT_DEVICE_NAND_I2C)
66 boot_device = BOOT_DEVICE_NAND;
67#endif
Paul Kocialkowskidf844772015-07-15 16:02:21 +020068#ifdef BOOT_DEVICE_QSPI_4
Tom Rini79b079f2014-04-03 07:52:56 -040069 /*
70 * We get different values for QSPI_1 and QSPI_4 being used, but
71 * don't actually care about this difference. Rather than
72 * mangle the later code, if we're coming in as QSPI_4 just
73 * change to the QSPI_1 value.
74 */
Paul Kocialkowskidf844772015-07-15 16:02:21 +020075 if (boot_device == BOOT_DEVICE_QSPI_4)
Paul Kocialkowski60c7c302015-07-15 16:02:19 +020076 boot_device = BOOT_DEVICE_SPI;
77#endif
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020078 /*
79 * When booting from peripheral booting, the boot device is not usable
80 * as-is (unless there is support for it), so the boot device is instead
81 * figured out using the SYS_BOOT pins.
82 */
83 switch (boot_device) {
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +020084#if defined(BOOT_DEVICE_UART) && !defined(CONFIG_SPL_YMODEM_SUPPORT)
85 case BOOT_DEVICE_UART:
86 sys_boot_device = 1;
87 break;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020088#endif
Abel Vesa79536012019-02-01 16:40:07 +000089#if defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_STORAGE)
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +020090 case BOOT_DEVICE_USB:
91 sys_boot_device = 1;
92 break;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +020093#endif
Faiz Abbasb432b1e2018-02-16 21:17:44 +053094#if defined(BOOT_DEVICE_USBETH) && !defined(CONFIG_SPL_USB_ETHER)
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +020095 case BOOT_DEVICE_USBETH:
96 sys_boot_device = 1;
97 break;
98#endif
Simon Glassf2d7a362021-07-10 21:14:26 -060099#if defined(BOOT_DEVICE_CPGMAC) && !defined(CONFIG_SPL_ETH)
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +0200100 case BOOT_DEVICE_CPGMAC:
101 sys_boot_device = 1;
102 break;
103#endif
Andrew F. Davis6536ca42019-01-17 13:43:02 -0600104#if defined(BOOT_DEVICE_DFU) && !defined(CONFIG_SPL_DFU)
B, Ravi6f8387f2016-07-28 17:39:17 +0530105 case BOOT_DEVICE_DFU:
106 sys_boot_device = 1;
107 break;
108#endif
Paul Kocialkowski8ceb34a2015-08-27 10:46:09 +0200109 }
110
111 if (sys_boot_device) {
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200112 boot_device = omap_sys_boot_device();
113
114 /* MMC raw mode will fallback to FS mode. */
115 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
116 (boot_device <= MMC_BOOT_DEVICES_END))
117 boot_mode = MMCSD_MODE_RAW;
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200118 }
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200119
120 gd->arch.omap_boot_device = boot_device;
121
122 /* Boot mode */
123
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200124#ifdef CONFIG_OMAP34XX
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200125 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
126 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200127 switch (boot_device) {
128 case BOOT_DEVICE_MMC1:
Tom Rini821c89d2016-05-02 10:52:51 -0400129 boot_mode = MMCSD_MODE_FS;
130 break;
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200131 case BOOT_DEVICE_MMC2:
132 boot_mode = MMCSD_MODE_RAW;
133 break;
134 }
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200135 }
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200136#else
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200137 /*
138 * If the boot device was dynamically changed and doesn't match what
139 * the bootrom initially booted, we cannot use the boot device
140 * descriptor to figure out the boot mode.
141 */
142 if ((boot_device == omap_boot_params->boot_device) &&
143 (boot_device >= MMC_BOOT_DEVICES_START) &&
144 (boot_device <= MMC_BOOT_DEVICES_END)) {
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200145 boot_params = omap_boot_params->boot_device_descriptor;
146 if ((boot_params < NON_SECURE_SRAM_START) ||
147 (boot_params > NON_SECURE_SRAM_END))
148 return;
149
150 boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET));
151 if ((boot_params < NON_SECURE_SRAM_START) ||
152 (boot_params > NON_SECURE_SRAM_END))
153 return;
154
155 boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET));
156
157 if (boot_mode != MMCSD_MODE_FS &&
158 boot_mode != MMCSD_MODE_RAW)
159#ifdef CONFIG_SUPPORT_EMMC_BOOT
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200160 boot_mode = MMCSD_MODE_EMMCBOOT;
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200161#else
162 boot_mode = MMCSD_MODE_UNDEFINED;
163#endif
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200164 }
Paul Kocialkowskied19bda2015-07-15 16:02:23 +0200165#endif
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200166
167 gd->arch.omap_boot_mode = boot_mode;
168
Tom Rini41e289b2023-05-11 14:07:24 -0400169#if !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX)
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200170
171 /* CH flags */
172
173 gd->arch.omap_ch_flags = omap_boot_params->ch_flags;
Tom Rini79b079f2014-04-03 07:52:56 -0400174#endif
Tom Rini4596dcc2013-05-31 12:31:59 -0400175}
176
Chandan Nath8a8f0842012-01-09 20:38:59 +0000177#ifdef CONFIG_SPL_BUILD
Tom Rini8e1b8362012-08-13 12:53:23 -0700178u32 spl_boot_device(void)
Chandan Nath8a8f0842012-01-09 20:38:59 +0000179{
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200180 return gd->arch.omap_boot_device;
Chandan Nath8a8f0842012-01-09 20:38:59 +0000181}
182
Andre Przywara59073572021-07-12 11:06:49 +0100183u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
Chandan Nath8a8f0842012-01-09 20:38:59 +0000184{
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200185 return gd->arch.omap_boot_mode;
Chandan Nath8a8f0842012-01-09 20:38:59 +0000186}
Tom Rinif0881252012-08-14 10:25:15 -0700187
Keerthy01979092022-01-27 13:16:52 +0100188int load_firmware(char *name_fw, u32 *loadaddr)
189{
190 struct udevice *fsdev;
191 int size = 0;
192
193 if (!IS_ENABLED(CONFIG_FS_LOADER))
194 return 0;
195
196 if (!*loadaddr)
197 return 0;
198
Sean Anderson0998a202022-12-29 11:52:59 -0500199 if (!get_fs_loader(&fsdev)) {
Keerthy01979092022-01-27 13:16:52 +0100200 size = request_firmware_into_buf(fsdev, name_fw,
201 (void *)*loadaddr, 0, 0);
202 }
203
204 return size;
205}
206
207void spl_boot_ipu(void)
208{
209 int ret, size;
210 u32 loadaddr = IPU1_LOAD_ADDR;
211
212 if (!IS_ENABLED(CONFIG_SPL_BUILD) ||
213 !IS_ENABLED(CONFIG_REMOTEPROC_TI_IPU))
214 return;
215
216 size = load_firmware("dra7-ipu1-fw.xem4", &loadaddr);
217 if (size <= 0) {
218 pr_err("Firmware loading failed\n");
219 goto skip_ipu1;
220 }
221
222 enable_ipu1_clocks();
223 ret = rproc_dev_init(0);
224 if (ret) {
225 debug("%s: IPU1 failed to initialize on rproc (%d)\n",
226 __func__, ret);
227 goto skip_ipu1;
228 }
229
230 ret = rproc_load(0, IPU1_LOAD_ADDR, 0x2000000);
231 if (ret) {
232 debug("%s: IPU1 failed to load on rproc (%d)\n", __func__,
233 ret);
234 goto skip_ipu1;
235 }
236
237 debug("Starting IPU1...\n");
238
239 ret = rproc_start(0);
240 if (ret)
241 debug("%s: IPU1 failed to start (%d)\n", __func__, ret);
242
243skip_ipu1:
244 loadaddr = IPU2_LOAD_ADDR;
245 size = load_firmware("dra7-ipu2-fw.xem4", &loadaddr);
246 if (size <= 0) {
247 pr_err("Firmware loading failed for ipu2\n");
248 return;
249 }
250
251 enable_ipu2_clocks();
252 ret = rproc_dev_init(1);
253 if (ret) {
254 debug("%s: IPU2 failed to initialize on rproc (%d)\n", __func__,
255 ret);
256 return;
257 }
258
259 ret = rproc_load(1, IPU2_LOAD_ADDR, 0x2000000);
260 if (ret) {
261 debug("%s: IPU2 failed to load on rproc (%d)\n", __func__,
262 ret);
263 return;
264 }
265
266 debug("Starting IPU2...\n");
267
268 ret = rproc_start(1);
269 if (ret)
270 debug("%s: IPU2 failed to start (%d)\n", __func__, ret);
271}
272
Tom Rinid7cb93b2012-08-14 12:26:08 -0700273void spl_board_init(void)
274{
Tom Rinia6b541b2014-12-19 16:53:24 -0500275 /* Prepare console output */
276 preloader_console_init();
Samuel Holland3988be52020-05-07 18:08:10 -0500277
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200278#if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
Tom Rinid7cb93b2012-08-14 12:26:08 -0700279 gpmc_init();
280#endif
Simon Glass975e7cf2021-07-10 21:14:36 -0600281#if defined(CONFIG_SPL_I2C) && !CONFIG_IS_ENABLED(DM_I2C)
Tom Rini14376b82021-08-18 23:12:29 -0400282 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200283#endif
Simon Glass89ddb0b2021-07-10 21:14:27 -0600284#if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW)
Ilya Yanokda07c212013-02-05 11:36:25 +0000285 arch_misc_init();
286#endif
Suniel Mahesh6912f2a2019-07-31 21:54:07 +0530287#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
Tom Rini68439182013-10-01 12:32:04 -0400288 hw_watchdog_init();
289#endif
Tom Rini6a0d8032013-08-30 16:28:44 -0400290#ifdef CONFIG_AM33XX
291 am33xx_spl_board_init();
292#endif
Keerthy01979092022-01-27 13:16:52 +0100293 if (IS_ENABLED(CONFIG_SPL_BUILD) &&
294 IS_ENABLED(CONFIG_REMOTEPROC_TI_IPU))
295 spl_boot_ipu();
Tom Rinid7cb93b2012-08-14 12:26:08 -0700296}
297
SRICHARAN R4a0eb752013-04-24 00:41:24 +0000298void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
299{
300 typedef void __noreturn (*image_entry_noargs_t)(u32 *);
301 image_entry_noargs_t image_entry =
302 (image_entry_noargs_t) spl_image->entry_point;
303
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200304 u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
305
Andre Przywara11e14792017-01-02 11:48:31 +0000306 debug("image entry point: 0x%lX\n", spl_image->entry_point);
SRICHARAN R4a0eb752013-04-24 00:41:24 +0000307 /* Pass the saved boot_params from rom code */
Paul Kocialkowski60c7c302015-07-15 16:02:19 +0200308 image_entry((u32 *)boot_params);
SRICHARAN R4a0eb752013-04-24 00:41:24 +0000309}
Chandan Nath8a8f0842012-01-09 20:38:59 +0000310#endif
Dmitry Lifshitz87791ad2014-12-15 16:02:58 +0200311
Andrew Davis1eaffe32022-10-20 12:12:19 -0500312#ifdef CONFIG_TI_SECURE_DEVICE
313void board_fit_image_post_process(const void *fit, int node, void **p_image,
314 size_t *p_size)
315{
316 secure_boot_verify_image(p_image, p_size);
317}
318
319static void tee_image_process(ulong tee_image, size_t tee_size)
320{
321 secure_tee_install((u32)tee_image);
322}
323U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, tee_image_process);
324#endif