2 * Copyright (C) 2011 OMICRON electronics GmbH
4 * based on drivers/mtd/nand/nand_spl_load.c
7 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
9 * SPDX-License-Identifier: GPL-2.0+
14 #include <spi_flash.h>
17 #ifdef CONFIG_SPL_OS_BOOT
19 * Load the kernel, check for a valid header we can parse, and if found load
20 * the kernel and then device tree.
22 static int spi_load_image_os(struct spi_flash *flash,
23 struct image_header *header)
25 /* Read for a header, parse or error out. */
26 spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS, 0x40,
29 if (image_get_magic(header) != IH_MAGIC)
32 spl_parse_image_header(header);
34 spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS,
35 spl_image.size, (void *)spl_image.load_addr);
37 /* Read device tree. */
38 spi_flash_read(flash, CONFIG_SYS_SPI_ARGS_OFFS,
39 CONFIG_SYS_SPI_ARGS_SIZE,
40 (void *)CONFIG_SYS_SPL_ARGS_ADDR);
47 * The main entry for SPI booting. It's necessary that SDRAM is already
48 * configured and available since this code loads the main U-Boot image
49 * from SPI into SDRAM and starts it from there.
51 void spl_spi_load_image(void)
53 struct spi_flash *flash;
54 struct image_header *header;
57 * Load U-Boot image from SPI flash into RAM
60 flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
62 CONFIG_SF_DEFAULT_SPEED,
63 CONFIG_SF_DEFAULT_MODE);
65 puts("SPI probe failed.\n");
69 /* use CONFIG_SYS_TEXT_BASE as temporary storage area */
70 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
72 #ifdef CONFIG_SPL_OS_BOOT
73 if (spl_start_uboot() || spi_load_image_os(flash, header))
76 /* Load u-boot, mkimage header is 64 bytes. */
77 spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40,
79 spl_parse_image_header(header);
80 spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS,
81 spl_image.size, (void *)spl_image.load_addr);