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 spl_image_info *spl_image,
24 struct spi_flash *flash,
25 struct image_header *header)
29 /* Read for a header, parse or error out. */
30 spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS, 0x40,
33 if (image_get_magic(header) != IH_MAGIC)
36 err = spl_parse_image_header(spl_image, header);
40 spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS,
41 spl_image->size, (void *)spl_image->load_addr);
43 /* Read device tree. */
44 spi_flash_read(flash, CONFIG_SYS_SPI_ARGS_OFFS,
45 CONFIG_SYS_SPI_ARGS_SIZE,
46 (void *)CONFIG_SYS_SPL_ARGS_ADDR);
52 static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector,
53 ulong count, void *buf)
55 struct spi_flash *flash = load->dev;
58 ret = spi_flash_read(flash, sector, count, buf);
65 * The main entry for SPI booting. It's necessary that SDRAM is already
66 * configured and available since this code loads the main U-Boot image
67 * from SPI into SDRAM and starts it from there.
69 static int spl_spi_load_image(struct spl_image_info *spl_image,
70 struct spl_boot_device *bootdev)
73 struct spi_flash *flash;
74 struct image_header *header;
77 * Load U-Boot image from SPI flash into RAM
80 flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
82 CONFIG_SF_DEFAULT_SPEED,
83 CONFIG_SF_DEFAULT_MODE);
85 puts("SPI probe failed.\n");
89 /* use CONFIG_SYS_TEXT_BASE as temporary storage area */
90 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
92 #ifdef CONFIG_SPL_OS_BOOT
93 if (spl_start_uboot() || spi_load_image_os(spl_image, flash, header))
96 /* Load u-boot, mkimage header is 64 bytes. */
97 err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40,
102 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) {
103 struct spl_load_info load;
105 debug("Found FIT\n");
108 load.filename = NULL;
110 load.read = spl_spi_fit_read;
111 err = spl_load_simple_fit(&load,
112 CONFIG_SYS_SPI_U_BOOT_OFFS,
115 err = spl_parse_image_header(spl_image, header);
118 err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS,
120 (void *)spl_image->load_addr);
126 /* Use priorty 1 so that boards can override this */
127 SPL_LOAD_IMAGE_METHOD(1, BOOT_DEVICE_SPI, spl_spi_load_image);