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
15 void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst)
17 struct spi_flash *flash;
19 flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
20 CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
22 puts("\nspi_flash_probe failed");
26 spi_flash_read(flash, offs, size, vdst);
30 * The main entry for SPI booting. It's necessary that SDRAM is already
31 * configured and available since this code loads the main U-Boot image
32 * from SPI into SDRAM and starts it from there.
36 void (*uboot)(void) __noreturn;
37 u32 offset, code_len, copy_len = 0;
38 #ifndef CONFIG_FSL_CORENET
39 unsigned char *buf = NULL;
41 struct spi_flash *flash;
43 flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
44 CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
46 puts("\nspi_flash_probe failed");
50 #ifdef CONFIG_FSL_CORENET
51 offset = CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
52 code_len = CONFIG_SYS_SPI_FLASH_U_BOOT_SIZE;
55 * Load U-Boot image from SPI flash into RAM
57 buf = malloc(flash->page_size);
59 puts("\nmalloc failed");
62 memset(buf, 0, flash->page_size);
64 spi_flash_read(flash, CONFIG_CFG_DATA_SECTOR,
65 flash->page_size, (void *)buf);
66 offset = *(u32 *)(buf + ESPI_BOOT_IMAGE_ADDR);
68 offset += CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
69 /* Get the code size from offset 0x48 */
70 code_len = *(u32 *)(buf + ESPI_BOOT_IMAGE_SIZE);
72 code_len = code_len - CONFIG_SPL_MAX_SIZE;
74 /* copy code to DDR */
75 printf("Loading second stage boot loader ");
76 while (copy_len <= code_len) {
77 spi_flash_read(flash, offset + copy_len, 0x2000,
78 (void *)(CONFIG_SYS_SPI_FLASH_U_BOOT_DST
80 copy_len = copy_len + 0x2000;
85 * Jump to U-Boot image
87 flush_cache(CONFIG_SYS_SPI_FLASH_U_BOOT_DST, code_len);
88 uboot = (void *)CONFIG_SYS_SPI_FLASH_U_BOOT_START;