blob: aada83f1902a683743ad18dd4954090d3e1ab194 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roeseb0f80b92015-01-19 11:33:42 +01002/*
Stefan Roesea5f88872016-01-07 14:09:09 +01003 * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de>
Stefan Roeseb0f80b92015-01-19 11:33:42 +01004 */
5
6#include <common.h>
Stefan Roese64512232015-11-25 07:37:00 +01007#include <dm.h>
Stefan Roese64512232015-11-25 07:37:00 +01008#include <fdtdec.h>
Simon Glassdb41d652019-12-28 10:45:07 -07009#include <hang.h>
Pali Rohár2226ca12021-07-23 11:14:29 +020010#include <image.h>
Simon Glass691d7192020-05-10 11:40:02 -060011#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Stefan Roeseb0f80b92015-01-19 11:33:42 +010013#include <spl.h>
Simon Glass401d1c42020-10-30 21:38:53 -060014#include <asm/global_data.h>
Stefan Roeseb0f80b92015-01-19 11:33:42 +010015#include <asm/io.h>
16#include <asm/arch/cpu.h>
17#include <asm/arch/soc.h>
18
Simon Glass103c5f12021-08-08 12:20:09 -060019#if defined(CONFIG_SPL_SPI_FLASH_SUPPORT) || defined(CONFIG_SPL_MMC) || \
Simon Glassf7560372021-08-08 12:20:17 -060020 defined(CONFIG_SPL_SATA)
Pali Rohár2226ca12021-07-23 11:14:29 +020021
22/*
23 * When loading U-Boot via SPL from SPI NOR, CONFIG_SYS_SPI_U_BOOT_OFFS must
24 * point to the offset of kwbimage main header which is always at offset zero
25 * (defined by BootROM). Therefore other values of CONFIG_SYS_SPI_U_BOOT_OFFS
26 * makes U-Boot non-bootable.
27 */
28#ifdef CONFIG_SPL_SPI_FLASH_SUPPORT
29#if defined(CONFIG_SYS_SPI_U_BOOT_OFFS) && CONFIG_SYS_SPI_U_BOOT_OFFS != 0
30#error CONFIG_SYS_SPI_U_BOOT_OFFS must be set to 0
31#endif
32#endif
33
34/*
35 * When loading U-Boot via SPL from eMMC (in Marvell terminology SDIO), the
36 * kwbimage main header is stored at sector 0. U-Boot SPL needs to parse this
37 * header and figure out at which sector the U-Boot proper binary is stored.
38 * Partition booting is therefore not supported and CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
39 * and CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET need to point to the
40 * kwbimage main header.
41 */
Simon Glass103c5f12021-08-08 12:20:09 -060042#ifdef CONFIG_SPL_MMC
Pali Rohár2226ca12021-07-23 11:14:29 +020043#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
44#error CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION is unsupported
45#endif
46#if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR) && CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR != 0
47#error CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR must be set to 0
48#endif
49#if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET) && CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET != 0
50#error CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET must be set to 0
51#endif
52#endif
53
54/*
55 * When loading U-Boot via SPL from SATA disk, the kwbimage main header is
56 * stored at sector 1. Therefore CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR must be
57 * set to 1. Otherwise U-Boot SPL would not be able to load U-Boot proper.
58 */
Simon Glassf7560372021-08-08 12:20:17 -060059#ifdef CONFIG_SPL_SATA
Pali Rohár2226ca12021-07-23 11:14:29 +020060#if !defined(CONFIG_SPL_SATA_RAW_U_BOOT_USE_SECTOR) || !defined(CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR) || CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR != 1
61#error CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR must be set to 1
62#endif
63#endif
64
65/* Boot Type - block ID */
66#define IBR_HDR_I2C_ID 0x4D
67#define IBR_HDR_SPI_ID 0x5A
68#define IBR_HDR_NAND_ID 0x8B
69#define IBR_HDR_SATA_ID 0x78
70#define IBR_HDR_PEX_ID 0x9C
71#define IBR_HDR_UART_ID 0x69
72#define IBR_HDR_SDIO_ID 0xAE
73
Pali Rohár7af368f2021-10-22 12:41:10 +020074/* Structure of the main header, version 1 (Armada 370/XP/375/38x/39x) */
Pali Rohár2226ca12021-07-23 11:14:29 +020075struct kwbimage_main_hdr_v1 {
76 uint8_t blockid; /* 0x0 */
77 uint8_t flags; /* 0x1 */
Pali Rohár33cdd9e2021-10-22 12:37:48 +020078 uint16_t nandpagesize; /* 0x2-0x3 */
Pali Rohár2226ca12021-07-23 11:14:29 +020079 uint32_t blocksize; /* 0x4-0x7 */
80 uint8_t version; /* 0x8 */
81 uint8_t headersz_msb; /* 0x9 */
82 uint16_t headersz_lsb; /* 0xA-0xB */
83 uint32_t srcaddr; /* 0xC-0xF */
84 uint32_t destaddr; /* 0x10-0x13 */
85 uint32_t execaddr; /* 0x14-0x17 */
86 uint8_t options; /* 0x18 */
87 uint8_t nandblocksize; /* 0x19 */
88 uint8_t nandbadblklocation; /* 0x1A */
89 uint8_t reserved4; /* 0x1B */
90 uint16_t reserved5; /* 0x1C-0x1D */
91 uint8_t ext; /* 0x1E */
92 uint8_t checksum; /* 0x1F */
93} __packed;
94
Simon Glass103c5f12021-08-08 12:20:09 -060095#ifdef CONFIG_SPL_MMC
Pali Rohár2226ca12021-07-23 11:14:29 +020096u32 spl_mmc_boot_mode(const u32 boot_device)
97{
98 return MMCSD_MODE_RAW;
99}
100#endif
101
102int spl_parse_board_header(struct spl_image_info *spl_image,
103 const void *image_header, size_t size)
104{
105 const struct kwbimage_main_hdr_v1 *mhdr = image_header;
106
107 if (size < sizeof(*mhdr)) {
108 /* This should be compile time assert */
109 printf("FATAL ERROR: Image header size is too small\n");
110 hang();
111 }
112
113 /*
114 * Very basic check for image validity. We cannot check mhdr->checksum
115 * as it is calculated also from variable length extended headers
116 * (including SPL content) which is not included in U-Boot image_header.
117 */
118 if (mhdr->version != 1 ||
119 ((mhdr->headersz_msb << 16) | mhdr->headersz_lsb) < sizeof(*mhdr) ||
120 (
121#ifdef CONFIG_SPL_SPI_FLASH_SUPPORT
122 mhdr->blockid != IBR_HDR_SPI_ID &&
123#endif
Simon Glassf7560372021-08-08 12:20:17 -0600124#ifdef CONFIG_SPL_SATA
Pali Rohár2226ca12021-07-23 11:14:29 +0200125 mhdr->blockid != IBR_HDR_SATA_ID &&
126#endif
Simon Glass103c5f12021-08-08 12:20:09 -0600127#ifdef CONFIG_SPL_MMC
Pali Rohár2226ca12021-07-23 11:14:29 +0200128 mhdr->blockid != IBR_HDR_SDIO_ID &&
129#endif
130 1
131 )) {
132 printf("ERROR: Not valid SPI/NAND/SATA/SDIO kwbimage v1\n");
133 return -EINVAL;
134 }
135
136 spl_image->offset = mhdr->srcaddr;
137
Simon Glassf7560372021-08-08 12:20:17 -0600138#ifdef CONFIG_SPL_SATA
Pali Rohár2226ca12021-07-23 11:14:29 +0200139 /*
140 * For SATA srcaddr is specified in number of sectors.
141 * The main header is must be stored at sector number 1.
142 * This expects that sector size is 512 bytes and recalculates
143 * data offset to bytes relative to the main header.
144 */
145 if (mhdr->blockid == IBR_HDR_SATA_ID) {
146 if (spl_image->offset < 1) {
147 printf("ERROR: Wrong SATA srcaddr in kwbimage\n");
148 return -EINVAL;
149 }
150 spl_image->offset -= 1;
151 spl_image->offset *= 512;
152 }
153#endif
154
Simon Glass103c5f12021-08-08 12:20:09 -0600155#ifdef CONFIG_SPL_MMC
Pali Rohár2226ca12021-07-23 11:14:29 +0200156 /*
157 * For SDIO (eMMC) srcaddr is specified in number of sectors.
158 * This expects that sector size is 512 bytes and recalculates
159 * data offset to bytes.
160 */
161 if (mhdr->blockid == IBR_HDR_SDIO_ID)
162 spl_image->offset *= 512;
163#endif
164
165 spl_image->size = mhdr->blocksize;
166 spl_image->entry_point = mhdr->execaddr;
167 spl_image->load_addr = mhdr->destaddr;
168 spl_image->os = IH_OS_U_BOOT;
169 spl_image->name = "U-Boot";
170
171 return 0;
172}
173
Stefan Roeseb0f80b92015-01-19 11:33:42 +0100174u32 spl_boot_device(void)
175{
Pali Rohárabbf2172021-07-23 11:14:26 +0200176 u32 boot_device = get_boot_device();
177
Pali Rohár2226ca12021-07-23 11:14:29 +0200178 switch (boot_device) {
Pali Rohárabbf2172021-07-23 11:14:26 +0200179 /*
180 * Return to the BootROM to continue the Marvell xmodem
181 * UART boot protocol. As initiated by the kwboot tool.
182 *
183 * This can only be done by the BootROM since the beginning
184 * of the image is already read and interpreted by the BootROM.
185 * SPL has no chance to receive this information. So we
186 * need to return to the BootROM to enable this xmodem
187 * UART download. Use SPL infrastructure to return to BootROM.
Pali Rohárabbf2172021-07-23 11:14:26 +0200188 */
Pali Rohárabbf2172021-07-23 11:14:26 +0200189 case BOOT_DEVICE_UART:
Pali Rohárabbf2172021-07-23 11:14:26 +0200190 return BOOT_DEVICE_BOOTROM;
Pali Rohár2226ca12021-07-23 11:14:29 +0200191
192 /*
193 * If SPL is compiled with chosen boot_device support
194 * then use SPL driver for loading U-Boot proper.
195 */
Simon Glass103c5f12021-08-08 12:20:09 -0600196#ifdef CONFIG_SPL_MMC
Pali Rohár2226ca12021-07-23 11:14:29 +0200197 case BOOT_DEVICE_MMC1:
198 return BOOT_DEVICE_MMC1;
199#endif
Simon Glassf7560372021-08-08 12:20:17 -0600200#ifdef CONFIG_SPL_SATA
Pali Rohárd73db302021-10-29 14:09:48 +0200201 case BOOT_DEVICE_SATA:
202 return BOOT_DEVICE_SATA;
Pali Rohár2226ca12021-07-23 11:14:29 +0200203#endif
204#ifdef CONFIG_SPL_SPI_FLASH_SUPPORT
205 case BOOT_DEVICE_SPI:
206 return BOOT_DEVICE_SPI;
207#endif
208
209 /*
210 * If SPL is not compiled with chosen boot_device support
211 * then return to the BootROM. BootROM supports loading
212 * U-Boot proper from any valid boot_device present in SAR
213 * register.
214 */
Pali Rohárabbf2172021-07-23 11:14:26 +0200215 default:
Pali Rohár2226ca12021-07-23 11:14:29 +0200216 return BOOT_DEVICE_BOOTROM;
Pali Rohárabbf2172021-07-23 11:14:26 +0200217 }
Stefan Roeseb0f80b92015-01-19 11:33:42 +0100218}
219
Marek Behúndc595e32021-08-16 15:19:37 +0200220#else
221
222u32 spl_boot_device(void)
223{
224 return BOOT_DEVICE_BOOTROM;
225}
226
227#endif
228
Pali Rohár9d0225b2021-07-23 11:14:25 +0200229int board_return_to_bootrom(struct spl_image_info *spl_image,
230 struct spl_boot_device *bootdev)
231{
232 u32 *regs = *(u32 **)CONFIG_SPL_BOOTROM_SAVE;
233
234 printf("Returning to BootROM (return address 0x%08x)...\n", regs[13]);
235 return_to_bootrom();
236
237 /* NOTREACHED - return_to_bootrom() does not return */
238 hang();
239}
240
Stefan Roeseb0f80b92015-01-19 11:33:42 +0100241void board_init_f(ulong dummy)
242{
Stefan Roese64512232015-11-25 07:37:00 +0100243 int ret;
244
Stefan Roesee3cccf92015-04-17 18:13:06 +0200245 /*
246 * Pin muxing needs to be done before UART output, since
247 * on A38x the UART pins need some re-muxing for output
248 * to work.
249 */
250 board_early_init_f();
251
Stefan Roesef2100f62019-04-12 16:42:28 +0200252 /*
253 * Use special translation offset for SPL. This needs to be
254 * configured *before* spl_init() is called as this function
255 * calls dm_init() which calls the bind functions of the
256 * device drivers. Here the base address needs to be configured
257 * (translated) correctly.
258 */
259 gd->translation_offset = 0xd0000000 - 0xf1000000;
260
Stefan Roese64512232015-11-25 07:37:00 +0100261 ret = spl_init();
262 if (ret) {
Pali Rohár2e5d0aa2021-12-17 18:31:14 +0100263 printf("spl_init() failed: %d\n", ret);
Stefan Roese64512232015-11-25 07:37:00 +0100264 hang();
265 }
266
Stefan Roeseb0f80b92015-01-19 11:33:42 +0100267 preloader_console_init();
268
Stefan Roeseade741b2015-07-15 15:36:52 +0200269 timer_init();
270
Stefan Roese09e89ab2016-02-10 07:23:00 +0100271 /* Armada 375 does not support SerDes and DDR3 init yet */
272#if !defined(CONFIG_ARMADA_375)
Stefan Roeseb0f80b92015-01-19 11:33:42 +0100273 /* First init the serdes PHY's */
274 serdes_phy_config();
275
276 /* Setup DDR */
Pali Rohár7e1c0d02021-08-09 17:44:35 +0200277 ret = ddr3_init();
278 if (ret) {
Pali Rohár2e5d0aa2021-12-17 18:31:14 +0100279 printf("ddr3_init() failed: %d\n", ret);
Pali Rohár7e1c0d02021-08-09 17:44:35 +0200280 hang();
281 }
Stefan Roese09e89ab2016-02-10 07:23:00 +0100282#endif
Stefan Roeseb0f80b92015-01-19 11:33:42 +0100283
Baruch Siachcc66ebd2019-07-10 18:23:04 +0300284 /* Initialize Auto Voltage Scaling */
285 mv_avs_init();
286
Chris Packhamad91fdf2020-02-26 19:53:50 +1300287 /* Update read timing control for PCIe */
288 mv_rtc_config();
Stefan Roeseb0f80b92015-01-19 11:33:42 +0100289}