2 * Copyright 2013 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
11 #define ESPI_BOOT_IMAGE_SIZE 0x48
12 #define ESPI_BOOT_IMAGE_ADDR 0x50
13 #define CONFIG_CFG_DATA_SECTOR 0
16 * The main entry for SPI booting. It's necessary that SDRAM is already
17 * configured and available since this code loads the main U-Boot image
18 * from SPI into SDRAM and starts it from there.
22 void (*uboot)(void) __noreturn;
23 u32 offset, code_len, copy_len = 0;
24 #ifndef CONFIG_FSL_CORENET
25 unsigned char *buf = NULL;
27 struct spi_flash *flash;
29 flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
30 CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
32 puts("\nspi_flash_probe failed");
36 #ifdef CONFIG_FSL_CORENET
37 offset = CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
38 code_len = CONFIG_SYS_SPI_FLASH_U_BOOT_SIZE;
41 * Load U-Boot image from SPI flash into RAM
43 buf = malloc(flash->page_size);
45 puts("\nmalloc failed");
48 memset(buf, 0, flash->page_size);
50 spi_flash_read(flash, CONFIG_CFG_DATA_SECTOR,
51 flash->page_size, (void *)buf);
52 offset = *(u32 *)(buf + ESPI_BOOT_IMAGE_ADDR);
54 offset += CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
55 /* Get the code size from offset 0x48 */
56 code_len = *(u32 *)(buf + ESPI_BOOT_IMAGE_SIZE);
58 code_len = code_len - CONFIG_SPL_MAX_SIZE;
60 /* copy code to DDR */
61 printf("Loading second stage boot loader ");
62 while (copy_len <= code_len) {
63 spi_flash_read(flash, offset + copy_len, 0x2000,
64 (void *)(CONFIG_SYS_SPI_FLASH_U_BOOT_DST
66 copy_len = copy_len + 0x2000;
71 * Jump to U-Boot image
73 flush_cache(CONFIG_SYS_SPI_FLASH_U_BOOT_DST, code_len);
74 uboot = (void *)CONFIG_SYS_SPI_FLASH_U_BOOT_START;