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>
18 #ifdef CONFIG_SPL_OS_BOOT
20 * Load the kernel, check for a valid header we can parse, and if found load
21 * the kernel and then device tree.
23 static int spi_load_image_os(struct spi_flash *flash,
24 struct image_header *header)
28 /* Read for a header, parse or error out. */
29 spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS, 0x40,
32 if (image_get_magic(header) != IH_MAGIC)
35 err = spl_parse_image_header(&spl_image, header);
39 spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS,
40 spl_image.size, (void *)spl_image.load_addr);
42 /* Read device tree. */
43 spi_flash_read(flash, CONFIG_SYS_SPI_ARGS_OFFS,
44 CONFIG_SYS_SPI_ARGS_SIZE,
45 (void *)CONFIG_SYS_SPL_ARGS_ADDR);
51 static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector,
52 ulong count, void *buf)
54 struct spi_flash *flash = load->dev;
57 ret = spi_flash_read(flash, sector, count, buf);
64 * The main entry for SPI booting. It's necessary that SDRAM is already
65 * configured and available since this code loads the main U-Boot image
66 * from SPI into SDRAM and starts it from there.
68 static int spl_spi_load_image(struct spl_boot_device *bootdev)
71 struct spi_flash *flash;
72 struct image_header *header;
75 * Load U-Boot image from SPI flash into RAM
78 flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
80 CONFIG_SF_DEFAULT_SPEED,
81 CONFIG_SF_DEFAULT_MODE);
83 puts("SPI probe failed.\n");
87 /* use CONFIG_SYS_TEXT_BASE as temporary storage area */
88 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
90 #ifdef CONFIG_SPL_OS_BOOT
91 if (spl_start_uboot() || spi_load_image_os(flash, header))
94 /* Load u-boot, mkimage header is 64 bytes. */
95 err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40,
100 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) {
101 struct spl_load_info load;
103 debug("Found FIT\n");
106 load.filename = NULL;
108 load.read = spl_spi_fit_read;
109 err = spl_load_simple_fit(&load,
110 CONFIG_SYS_SPI_U_BOOT_OFFS,
113 err = spl_parse_image_header(&spl_image, header);
116 err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS,
118 (void *)spl_image.load_addr);
124 /* Use priorty 1 so that boards can override this */
125 SPL_LOAD_IMAGE_METHOD(1, BOOT_DEVICE_SPI, spl_spi_load_image);