blob: a9079fceac8d6a7d8f88999306ad4f90feb45526 [file] [log] [blame]
Tim Harvey354a7e32014-06-02 16:13:20 -07001/*
2 * Copyright (C) 2014 Gateworks Corporation
3 * Copyright (C) 2011-2012 Freescale Semiconductor, Inc.
4 *
5 * Author: Tim Harvey <tharvey@gateworks.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <common.h>
11#include <asm/io.h>
12#include <asm/arch/imx-regs.h>
Jagan Tekie5f970b2017-02-24 15:45:12 +053013#include <asm/arch/sys_proto.h>
Tim Harvey354a7e32014-06-02 16:13:20 -070014#include <asm/spl.h>
15#include <spl.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020016#include <asm/mach-imx/hab.h>
Uri Mashiach5dd46892017-09-24 09:00:24 +030017#include <asm/mach-imx/boot_mode.h>
Fabio Estevama0e462b2017-09-05 20:46:39 -030018#include <g_dnl.h>
Tim Harvey354a7e32014-06-02 16:13:20 -070019
Jagan Teki7bb61bb2017-08-28 16:45:47 +053020DECLARE_GLOBAL_DATA_PTR;
21
Tim Harvey354a7e32014-06-02 16:13:20 -070022#if defined(CONFIG_MX6)
Nikita Kiryanov9fba8422014-10-29 19:28:33 +020023/* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 register */
Tim Harvey354a7e32014-06-02 16:13:20 -070024u32 spl_boot_device(void)
25{
Jagan Tekic981a942017-02-24 15:45:15 +053026 unsigned int bmode = readl(&src_base->sbmr2);
Jagan Tekie5f970b2017-02-24 15:45:12 +053027 u32 reg = imx6_src_get_boot_mode();
Tim Harvey354a7e32014-06-02 16:13:20 -070028
Stefano Babic587e72e2015-12-11 17:30:42 +010029 /*
30 * Check for BMODE if serial downloader is enabled
31 * BOOT_MODE - see IMX6DQRM Table 8-1
32 */
Stefan Agner15390962016-12-27 17:01:42 +010033 if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
Stefan Agnera0a50ce2017-08-15 17:49:43 -070034 return BOOT_DEVICE_BOARD;
Jagan Teki32a71142017-02-24 15:45:14 +053035
Stefan Agner47f547e2017-09-13 14:29:45 -070036 /*
37 * The above method does not detect that the boot ROM used
38 * serial downloader in case the boot ROM decided to use the
39 * serial downloader as a fall back (primary boot source failed).
40 *
41 * Infer that the boot ROM used the USB serial downloader by
42 * checking whether the USB PHY is currently active... This
43 * assumes that SPL did not (yet) initialize the USB PHY...
44 */
45 if (is_usbotg_phy_active())
46 return BOOT_DEVICE_BOARD;
47
Tim Harvey354a7e32014-06-02 16:13:20 -070048 /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
Jagan Teki32a71142017-02-24 15:45:14 +053049 switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
Tim Harvey354a7e32014-06-02 16:13:20 -070050 /* EIM: See 8.5.1, Table 8-9 */
Jagan Teki32a71142017-02-24 15:45:14 +053051 case IMX6_BMODE_EMI:
Tim Harvey354a7e32014-06-02 16:13:20 -070052 /* BOOT_CFG1[3]: NOR/OneNAND Selection */
Jagan Teki32a71142017-02-24 15:45:14 +053053 switch ((reg & IMX6_BMODE_EMI_MASK) >> IMX6_BMODE_EMI_SHIFT) {
54 case IMX6_BMODE_ONENAND:
Tim Harvey354a7e32014-06-02 16:13:20 -070055 return BOOT_DEVICE_ONENAND;
Jagan Teki32a71142017-02-24 15:45:14 +053056 case IMX6_BMODE_NOR:
Tim Harvey354a7e32014-06-02 16:13:20 -070057 return BOOT_DEVICE_NOR;
58 break;
Jagan Teki32a71142017-02-24 15:45:14 +053059 }
Stefan Agner15390962016-12-27 17:01:42 +010060 /* Reserved: Used to force Serial Downloader */
Stefan Agner53456f52017-08-15 17:49:42 -070061 case IMX6_BMODE_RESERVED:
Stefan Agnera0a50ce2017-08-15 17:49:43 -070062 return BOOT_DEVICE_BOARD;
Tim Harvey354a7e32014-06-02 16:13:20 -070063 /* SATA: See 8.5.4, Table 8-20 */
Stefan Agner34da4732017-08-29 09:10:11 -070064#if !defined(CONFIG_MX6UL) && !defined(CONFIG_MX6ULL)
Jagan Teki32a71142017-02-24 15:45:14 +053065 case IMX6_BMODE_SATA:
Tim Harvey354a7e32014-06-02 16:13:20 -070066 return BOOT_DEVICE_SATA;
Stefan Agner34da4732017-08-29 09:10:11 -070067#endif
Tim Harvey354a7e32014-06-02 16:13:20 -070068 /* Serial ROM: See 8.5.5.1, Table 8-22 */
Jagan Teki32a71142017-02-24 15:45:14 +053069 case IMX6_BMODE_SERIAL_ROM:
Tim Harvey354a7e32014-06-02 16:13:20 -070070 /* BOOT_CFG4[2:0] */
Jagan Teki32a71142017-02-24 15:45:14 +053071 switch ((reg & IMX6_BMODE_SERIAL_ROM_MASK) >>
72 IMX6_BMODE_SERIAL_ROM_SHIFT) {
73 case IMX6_BMODE_ECSPI1:
74 case IMX6_BMODE_ECSPI2:
75 case IMX6_BMODE_ECSPI3:
76 case IMX6_BMODE_ECSPI4:
77 case IMX6_BMODE_ECSPI5:
Tim Harvey354a7e32014-06-02 16:13:20 -070078 return BOOT_DEVICE_SPI;
Jagan Teki32a71142017-02-24 15:45:14 +053079 case IMX6_BMODE_I2C1:
80 case IMX6_BMODE_I2C2:
81 case IMX6_BMODE_I2C3:
Tim Harvey354a7e32014-06-02 16:13:20 -070082 return BOOT_DEVICE_I2C;
83 }
84 break;
85 /* SD/eSD: 8.5.3, Table 8-15 */
Jagan Teki32a71142017-02-24 15:45:14 +053086 case IMX6_BMODE_SD:
87 case IMX6_BMODE_ESD:
Breno Lima4d9bf022016-11-30 10:08:58 -020088 return BOOT_DEVICE_MMC1;
Tim Harvey354a7e32014-06-02 16:13:20 -070089 /* MMC/eMMC: 8.5.3 */
Jagan Teki32a71142017-02-24 15:45:14 +053090 case IMX6_BMODE_MMC:
91 case IMX6_BMODE_EMMC:
Tim Harvey354a7e32014-06-02 16:13:20 -070092 return BOOT_DEVICE_MMC1;
Jagan Teki4191b222017-02-24 15:45:13 +053093 /* NAND Flash: 8.5.2, Table 8-10 */
Eran Matityahu5fa7ca62017-12-14 20:20:02 +020094 case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX:
Tim Harvey354a7e32014-06-02 16:13:20 -070095 return BOOT_DEVICE_NAND;
96 }
97 return BOOT_DEVICE_NONE;
98}
Fabio Estevama0e462b2017-09-05 20:46:39 -030099
Peng Fan58f19b42018-01-10 13:20:26 +0800100#elif defined(CONFIG_MX7) || defined(CONFIG_MX8M)
101/* Translate iMX7/MX8M boot device to the SPL boot device enumeration */
Uri Mashiach5dd46892017-09-24 09:00:24 +0300102u32 spl_boot_device(void)
103{
104 enum boot_device boot_device_spl = get_boot_device();
105
106 switch (boot_device_spl) {
107 case SD1_BOOT:
108 case MMC1_BOOT:
Uri Mashiach5dd46892017-09-24 09:00:24 +0300109 case SD2_BOOT:
110 case MMC2_BOOT:
Eran Matityahu3d7aa682018-01-03 12:56:24 +0200111 case SD3_BOOT:
112 case MMC3_BOOT:
Eran Matityahu73596552018-01-03 12:53:08 +0200113 return BOOT_DEVICE_MMC1;
Eran Matityahu3d7aa682018-01-03 12:56:24 +0200114 case NAND_BOOT:
115 return BOOT_DEVICE_NAND;
Uri Mashiach5dd46892017-09-24 09:00:24 +0300116 case SPI_NOR_BOOT:
117 return BOOT_DEVICE_SPI;
Peng Fan58f19b42018-01-10 13:20:26 +0800118 case USB_BOOT:
119 return BOOT_DEVICE_USB;
Uri Mashiach5dd46892017-09-24 09:00:24 +0300120 default:
121 return BOOT_DEVICE_NONE;
122 }
123}
Peng Fan58f19b42018-01-10 13:20:26 +0800124#endif /* CONFIG_MX6 || CONFIG_MX7 || CONFIG_MX8M */
Uri Mashiach5dd46892017-09-24 09:00:24 +0300125
Fabio Estevama0e462b2017-09-05 20:46:39 -0300126#ifdef CONFIG_SPL_USB_GADGET_SUPPORT
127int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
128{
Maxime Ripard7f78b9d2017-09-07 08:58:08 +0200129 put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM + 0xfff, &dev->idProduct);
Fabio Estevama0e462b2017-09-05 20:46:39 -0300130
131 return 0;
132}
133#endif
Tim Harvey354a7e32014-06-02 16:13:20 -0700134
Sven Ebenfeldeba5e332016-11-06 16:37:55 +0100135#if defined(CONFIG_SECURE_BOOT)
136
Bryan O'Donoghue88919962018-01-12 12:40:01 +0000137/*
138 * +------------+ 0x0 (DDR_UIMAGE_START) -
139 * | Header | |
140 * +------------+ 0x40 |
141 * | | |
142 * | | |
143 * | | |
144 * | | |
145 * | Image Data | |
146 * . | |
147 * . | > Stuff to be authenticated ----+
148 * . | | |
149 * | | | |
150 * | | | |
151 * +------------+ | |
152 * | | | |
153 * | Fill Data | | |
154 * | | | |
155 * +------------+ Align to ALIGN_SIZE | |
156 * | IVT | | |
157 * +------------+ + IVT_SIZE - |
158 * | | |
159 * | CSF DATA | <---------------------------------------------------------+
160 * | |
161 * +------------+
162 * | |
163 * | Fill Data |
164 * | |
165 * +------------+ + CSF_PAD_SIZE
166 */
167
Sven Ebenfeldeba5e332016-11-06 16:37:55 +0100168__weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
169{
170 typedef void __noreturn (*image_entry_noargs_t)(void);
Bryan O'Donoghue88919962018-01-12 12:40:01 +0000171 uint32_t offset;
Sven Ebenfeldeba5e332016-11-06 16:37:55 +0100172
173 image_entry_noargs_t image_entry =
174 (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
175
Tom Rinif1c2fc02017-01-11 10:45:48 -0500176 debug("image entry point: 0x%lX\n", spl_image->entry_point);
Sven Ebenfeldeba5e332016-11-06 16:37:55 +0100177
178 /* HAB looks for the CSF at the end of the authenticated data therefore,
179 * we need to subtract the size of the CSF from the actual filesize */
Bryan O'Donoghue88919962018-01-12 12:40:01 +0000180 offset = spl_image->size - CONFIG_CSF_SIZE;
Bryan O'Donoghue1efba6a2018-01-12 12:40:13 +0000181 if (!imx_hab_authenticate_image(spl_image->load_addr,
182 offset + IVT_SIZE + CSF_PAD_SIZE,
183 offset)) {
Sven Ebenfeldeba5e332016-11-06 16:37:55 +0100184 image_entry();
185 } else {
186 puts("spl: ERROR: image authentication unsuccessful\n");
187 hang();
188 }
189}
190
Jagan Teki7bb61bb2017-08-28 16:45:47 +0530191#endif
192
193#if defined(CONFIG_MX6) && defined(CONFIG_SPL_OS_BOOT)
194int dram_init_banksize(void)
195{
196 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
197 gd->bd->bi_dram[0].size = imx_ddr_size();
198
199 return 0;
200}
Sven Ebenfeldeba5e332016-11-06 16:37:55 +0100201#endif