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;
24 unsigned char *buf = NULL;
25 struct spi_flash *flash;
27 flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
28 CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
30 puts("\nspi_flash_probe failed");
34 #ifdef CONFIG_FSL_CORENET
35 offset = CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
36 code_len = CONFIG_SYS_SPI_FLASH_U_BOOT_SIZE;
39 * Load U-Boot image from SPI flash into RAM
41 buf = malloc(flash->page_size);
43 puts("\nmalloc failed");
46 memset(buf, 0, flash->page_size);
48 spi_flash_read(flash, CONFIG_CFG_DATA_SECTOR,
49 flash->page_size, (void *)buf);
50 offset = *(u32 *)(buf + ESPI_BOOT_IMAGE_ADDR);
52 offset += CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
53 /* Get the code size from offset 0x48 */
54 code_len = *(u32 *)(buf + ESPI_BOOT_IMAGE_SIZE);
56 code_len = code_len - CONFIG_SPL_MAX_SIZE;
58 /* copy code to DDR */
59 spi_flash_read(flash, offset, code_len,
60 (void *)CONFIG_SYS_SPI_FLASH_U_BOOT_DST);
62 * Jump to U-Boot image
64 flush_cache(CONFIG_SYS_SPI_FLASH_U_BOOT_DST, code_len);
65 uboot = (void *)CONFIG_SYS_SPI_FLASH_U_BOOT_START;