1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2013 Freescale Semiconductor, Inc.
12 #define ESPI_BOOT_IMAGE_SIZE 0x48
13 #define ESPI_BOOT_IMAGE_ADDR 0x50
14 #define CONFIG_CFG_DATA_SECTOR 0
16 void fsl_spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst)
18 struct spi_flash *flash;
20 flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
21 CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
23 puts("\nspi_flash_probe failed");
27 spi_flash_read(flash, offs, size, vdst);
31 * The main entry for SPI booting. It's necessary that SDRAM is already
32 * configured and available since this code loads the main U-Boot image
33 * from SPI into SDRAM and starts it from there.
35 void fsl_spi_boot(void)
37 void (*uboot)(void) __noreturn;
38 u32 offset, code_len, copy_len = 0;
39 #ifndef CONFIG_FSL_CORENET
40 unsigned char *buf = NULL;
42 struct spi_flash *flash;
44 flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
45 CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
47 puts("\nspi_flash_probe failed");
51 #ifdef CONFIG_FSL_CORENET
52 offset = CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
53 code_len = CONFIG_SYS_SPI_FLASH_U_BOOT_SIZE;
56 * Load U-Boot image from SPI flash into RAM
58 buf = malloc(flash->page_size);
60 puts("\nmalloc failed");
63 memset(buf, 0, flash->page_size);
65 spi_flash_read(flash, CONFIG_CFG_DATA_SECTOR,
66 flash->page_size, (void *)buf);
67 offset = *(u32 *)(buf + ESPI_BOOT_IMAGE_ADDR);
69 offset += CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
70 /* Get the code size from offset 0x48 */
71 code_len = *(u32 *)(buf + ESPI_BOOT_IMAGE_SIZE);
73 code_len = code_len - CONFIG_SPL_MAX_SIZE;
75 /* copy code to DDR */
76 printf("Loading second stage boot loader ");
77 while (copy_len <= code_len) {
78 spi_flash_read(flash, offset + copy_len, 0x2000,
79 (void *)(CONFIG_SYS_SPI_FLASH_U_BOOT_DST
81 copy_len = copy_len + 0x2000;
86 * Jump to U-Boot image
88 flush_cache(CONFIG_SYS_SPI_FLASH_U_BOOT_DST, code_len);
89 uboot = (void *)CONFIG_SYS_SPI_FLASH_U_BOOT_START;