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