]> Git Repo - J-u-boot.git/blame - arch/arm/mach-mvebu/spl.c
ppc: Rename MPC8XXX_INIT_DDR_SUPPORT to MPC8XXX_INIT_DDR
[J-u-boot.git] / arch / arm / mach-mvebu / spl.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
b0f80b91 2/*
a5f88877 3 * Copyright (C) 2014-2016 Stefan Roese <[email protected]>
b0f80b91
SR
4 */
5
6#include <common.h>
6451223a
SR
7#include <dm.h>
8#include <debug_uart.h>
9#include <fdtdec.h>
db41d65a 10#include <hang.h>
2226ca17 11#include <image.h>
691d719d 12#include <init.h>
f7ae49fc 13#include <log.h>
b0f80b91 14#include <spl.h>
401d1c4f 15#include <asm/global_data.h>
b0f80b91
SR
16#include <asm/io.h>
17#include <asm/arch/cpu.h>
18#include <asm/arch/soc.h>
19
103c5f18
SG
20#if defined(CONFIG_SPL_SPI_FLASH_SUPPORT) || defined(CONFIG_SPL_MMC) || \
21 defined(CONFIG_SPL_SATA_SUPPORT)
2226ca17
T
22
23/*
24 * When loading U-Boot via SPL from SPI NOR, CONFIG_SYS_SPI_U_BOOT_OFFS must
25 * point to the offset of kwbimage main header which is always at offset zero
26 * (defined by BootROM). Therefore other values of CONFIG_SYS_SPI_U_BOOT_OFFS
27 * makes U-Boot non-bootable.
28 */
29#ifdef CONFIG_SPL_SPI_FLASH_SUPPORT
30#if defined(CONFIG_SYS_SPI_U_BOOT_OFFS) && CONFIG_SYS_SPI_U_BOOT_OFFS != 0
31#error CONFIG_SYS_SPI_U_BOOT_OFFS must be set to 0
32#endif
33#endif
34
35/*
36 * When loading U-Boot via SPL from eMMC (in Marvell terminology SDIO), the
37 * kwbimage main header is stored at sector 0. U-Boot SPL needs to parse this
38 * header and figure out at which sector the U-Boot proper binary is stored.
39 * Partition booting is therefore not supported and CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
40 * and CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET need to point to the
41 * kwbimage main header.
42 */
103c5f18 43#ifdef CONFIG_SPL_MMC
2226ca17
T
44#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
45#error CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION is unsupported
46#endif
47#if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR) && CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR != 0
48#error CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR must be set to 0
49#endif
50#if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET) && CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET != 0
51#error CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET must be set to 0
52#endif
53#endif
54
55/*
56 * When loading U-Boot via SPL from SATA disk, the kwbimage main header is
57 * stored at sector 1. Therefore CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR must be
58 * set to 1. Otherwise U-Boot SPL would not be able to load U-Boot proper.
59 */
60#ifdef CONFIG_SPL_SATA_SUPPORT
61#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
62#error CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR must be set to 1
63#endif
64#endif
65
66/* Boot Type - block ID */
67#define IBR_HDR_I2C_ID 0x4D
68#define IBR_HDR_SPI_ID 0x5A
69#define IBR_HDR_NAND_ID 0x8B
70#define IBR_HDR_SATA_ID 0x78
71#define IBR_HDR_PEX_ID 0x9C
72#define IBR_HDR_UART_ID 0x69
73#define IBR_HDR_SDIO_ID 0xAE
74
75/* Structure of the main header, version 1 (Armada 370/38x/XP) */
76struct kwbimage_main_hdr_v1 {
77 uint8_t blockid; /* 0x0 */
78 uint8_t flags; /* 0x1 */
79 uint16_t reserved2; /* 0x2-0x3 */
80 uint32_t blocksize; /* 0x4-0x7 */
81 uint8_t version; /* 0x8 */
82 uint8_t headersz_msb; /* 0x9 */
83 uint16_t headersz_lsb; /* 0xA-0xB */
84 uint32_t srcaddr; /* 0xC-0xF */
85 uint32_t destaddr; /* 0x10-0x13 */
86 uint32_t execaddr; /* 0x14-0x17 */
87 uint8_t options; /* 0x18 */
88 uint8_t nandblocksize; /* 0x19 */
89 uint8_t nandbadblklocation; /* 0x1A */
90 uint8_t reserved4; /* 0x1B */
91 uint16_t reserved5; /* 0x1C-0x1D */
92 uint8_t ext; /* 0x1E */
93 uint8_t checksum; /* 0x1F */
94} __packed;
95
103c5f18 96#ifdef CONFIG_SPL_MMC
2226ca17
T
97u32 spl_mmc_boot_mode(const u32 boot_device)
98{
99 return MMCSD_MODE_RAW;
100}
101#endif
102
103int spl_parse_board_header(struct spl_image_info *spl_image,
104 const void *image_header, size_t size)
105{
106 const struct kwbimage_main_hdr_v1 *mhdr = image_header;
107
108 if (size < sizeof(*mhdr)) {
109 /* This should be compile time assert */
110 printf("FATAL ERROR: Image header size is too small\n");
111 hang();
112 }
113
114 /*
115 * Very basic check for image validity. We cannot check mhdr->checksum
116 * as it is calculated also from variable length extended headers
117 * (including SPL content) which is not included in U-Boot image_header.
118 */
119 if (mhdr->version != 1 ||
120 ((mhdr->headersz_msb << 16) | mhdr->headersz_lsb) < sizeof(*mhdr) ||
121 (
122#ifdef CONFIG_SPL_SPI_FLASH_SUPPORT
123 mhdr->blockid != IBR_HDR_SPI_ID &&
124#endif
125#ifdef CONFIG_SPL_SATA_SUPPORT
126 mhdr->blockid != IBR_HDR_SATA_ID &&
127#endif
103c5f18 128#ifdef CONFIG_SPL_MMC
2226ca17
T
129 mhdr->blockid != IBR_HDR_SDIO_ID &&
130#endif
131 1
132 )) {
133 printf("ERROR: Not valid SPI/NAND/SATA/SDIO kwbimage v1\n");
134 return -EINVAL;
135 }
136
137 spl_image->offset = mhdr->srcaddr;
138
139#ifdef CONFIG_SPL_SATA_SUPPORT
140 /*
141 * For SATA srcaddr is specified in number of sectors.
142 * The main header is must be stored at sector number 1.
143 * This expects that sector size is 512 bytes and recalculates
144 * data offset to bytes relative to the main header.
145 */
146 if (mhdr->blockid == IBR_HDR_SATA_ID) {
147 if (spl_image->offset < 1) {
148 printf("ERROR: Wrong SATA srcaddr in kwbimage\n");
149 return -EINVAL;
150 }
151 spl_image->offset -= 1;
152 spl_image->offset *= 512;
153 }
154#endif
155
103c5f18 156#ifdef CONFIG_SPL_MMC
2226ca17
T
157 /*
158 * For SDIO (eMMC) srcaddr is specified in number of sectors.
159 * This expects that sector size is 512 bytes and recalculates
160 * data offset to bytes.
161 */
162 if (mhdr->blockid == IBR_HDR_SDIO_ID)
163 spl_image->offset *= 512;
164#endif
165
166 spl_image->size = mhdr->blocksize;
167 spl_image->entry_point = mhdr->execaddr;
168 spl_image->load_addr = mhdr->destaddr;
169 spl_image->os = IH_OS_U_BOOT;
170 spl_image->name = "U-Boot";
171
172 return 0;
173}
174
a5f88877 175static u32 get_boot_device(void)
b0f80b91 176{
a5f88877
SR
177 u32 val;
178 u32 boot_device;
179
f4db6c97
SR
180 /*
181 * First check, if UART boot-mode is active. This can only
182 * be done, via the bootrom error register. Here the
183 * MSB marks if the UART mode is active.
184 */
185 val = readl(CONFIG_BOOTROM_ERR_REG);
186 boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS;
187 debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device);
188 if (boot_device == BOOTROM_ERR_MODE_UART)
189 return BOOT_DEVICE_UART;
190
2fd42840
CP
191#ifdef CONFIG_ARMADA_38X
192 /*
193 * If the bootrom error code contains any other than zeros it's an
194 * error condition and the bootROM has fallen back to UART boot
195 */
196 boot_device = (val & BOOTROM_ERR_CODE_MASK) >> BOOTROM_ERR_CODE_OFFS;
197 if (boot_device)
198 return BOOT_DEVICE_UART;
199#endif
200
f4db6c97
SR
201 /*
202 * Now check the SAR register for the strapped boot-device
203 */
a5f88877
SR
204 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
205 boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
f4db6c97 206 debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
a5f88877 207 switch (boot_device) {
2226ca17 208#ifdef BOOT_FROM_NAND
926c8b2e
SN
209 case BOOT_FROM_NAND:
210 return BOOT_DEVICE_NAND;
211#endif
2226ca17 212#ifdef BOOT_FROM_MMC
a5f88877
SR
213 case BOOT_FROM_MMC:
214 case BOOT_FROM_MMC_ALT:
215 return BOOT_DEVICE_MMC1;
8ed43b96 216#endif
a5f88877 217 case BOOT_FROM_UART:
f3a88e2c
BS
218#ifdef BOOT_FROM_UART_ALT
219 case BOOT_FROM_UART_ALT:
220#endif
a5f88877 221 return BOOT_DEVICE_UART;
22c65455
BS
222#ifdef BOOT_FROM_SATA
223 case BOOT_FROM_SATA:
224 case BOOT_FROM_SATA_ALT:
225 return BOOT_DEVICE_SATA;
226#endif
a5f88877 227 case BOOT_FROM_SPI:
a5f88877 228 return BOOT_DEVICE_SPI;
2226ca17
T
229 default:
230 return BOOT_DEVICE_BOOTROM;
a5f88877
SR
231 };
232}
233
2226ca17
T
234#else
235
236static u32 get_boot_device(void)
237{
238 return BOOT_DEVICE_BOOTROM;
239}
240
241#endif
242
a5f88877
SR
243u32 spl_boot_device(void)
244{
abbf2179
T
245 u32 boot_device = get_boot_device();
246
2226ca17 247 switch (boot_device) {
abbf2179
T
248 /*
249 * Return to the BootROM to continue the Marvell xmodem
250 * UART boot protocol. As initiated by the kwboot tool.
251 *
252 * This can only be done by the BootROM since the beginning
253 * of the image is already read and interpreted by the BootROM.
254 * SPL has no chance to receive this information. So we
255 * need to return to the BootROM to enable this xmodem
256 * UART download. Use SPL infrastructure to return to BootROM.
abbf2179 257 */
abbf2179 258 case BOOT_DEVICE_UART:
abbf2179 259 return BOOT_DEVICE_BOOTROM;
2226ca17
T
260
261 /*
262 * If SPL is compiled with chosen boot_device support
263 * then use SPL driver for loading U-Boot proper.
264 */
103c5f18 265#ifdef CONFIG_SPL_MMC
2226ca17
T
266 case BOOT_DEVICE_MMC1:
267 return BOOT_DEVICE_MMC1;
268#endif
269#ifdef CONFIG_SPL_SATA_SUPPORT
270 case BOOT_FROM_SATA:
271 return BOOT_FROM_SATA;
272#endif
273#ifdef CONFIG_SPL_SPI_FLASH_SUPPORT
274 case BOOT_DEVICE_SPI:
275 return BOOT_DEVICE_SPI;
276#endif
277
278 /*
279 * If SPL is not compiled with chosen boot_device support
280 * then return to the BootROM. BootROM supports loading
281 * U-Boot proper from any valid boot_device present in SAR
282 * register.
283 */
abbf2179 284 default:
2226ca17 285 return BOOT_DEVICE_BOOTROM;
abbf2179 286 }
b0f80b91
SR
287}
288
9d0225b7
T
289int board_return_to_bootrom(struct spl_image_info *spl_image,
290 struct spl_boot_device *bootdev)
291{
292 u32 *regs = *(u32 **)CONFIG_SPL_BOOTROM_SAVE;
293
294 printf("Returning to BootROM (return address 0x%08x)...\n", regs[13]);
295 return_to_bootrom();
296
297 /* NOTREACHED - return_to_bootrom() does not return */
298 hang();
299}
300
b0f80b91
SR
301void board_init_f(ulong dummy)
302{
6451223a
SR
303 int ret;
304
e3cccf9e
SR
305 /*
306 * Pin muxing needs to be done before UART output, since
307 * on A38x the UART pins need some re-muxing for output
308 * to work.
309 */
310 board_early_init_f();
311
6451223a
SR
312 /* Example code showing how to enable the debug UART on MVEBU */
313#ifdef EARLY_UART
314 /*
315 * Debug UART can be used from here if required:
316 *
317 * debug_uart_init();
318 * printch('a');
319 * printhex8(0x1234);
320 * printascii("string");
321 */
322#endif
323
f2100f6f
SR
324 /*
325 * Use special translation offset for SPL. This needs to be
326 * configured *before* spl_init() is called as this function
327 * calls dm_init() which calls the bind functions of the
328 * device drivers. Here the base address needs to be configured
329 * (translated) correctly.
330 */
331 gd->translation_offset = 0xd0000000 - 0xf1000000;
332
6451223a
SR
333 ret = spl_init();
334 if (ret) {
335 debug("spl_init() failed: %d\n", ret);
336 hang();
337 }
338
b0f80b91
SR
339 preloader_console_init();
340
ade741b3
SR
341 timer_init();
342
09e89ab4
SR
343 /* Armada 375 does not support SerDes and DDR3 init yet */
344#if !defined(CONFIG_ARMADA_375)
b0f80b91
SR
345 /* First init the serdes PHY's */
346 serdes_phy_config();
347
348 /* Setup DDR */
7e1c0d0d
T
349 ret = ddr3_init();
350 if (ret) {
351 debug("ddr3_init() failed: %d\n", ret);
352 hang();
353 }
09e89ab4 354#endif
b0f80b91 355
cc66ebde
BS
356 /* Initialize Auto Voltage Scaling */
357 mv_avs_init();
358
ad91fdff
CP
359 /* Update read timing control for PCIe */
360 mv_rtc_config();
b0f80b91 361}
This page took 0.386714 seconds and 4 git commands to generate.