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
)
26 /* Read for a header, parse or error out. */
27 spi_flash_read(flash
, CONFIG_SYS_SPI_KERNEL_OFFS
, 0x40,
30 if (image_get_magic(header
) != IH_MAGIC
)
33 spl_parse_image_header(header
);
35 spi_flash_read(flash
, CONFIG_SYS_SPI_KERNEL_OFFS
,
36 spl_image
.size
, (void *)spl_image
.load_addr
);
38 /* Read device tree. */
39 spi_flash_read(flash
, CONFIG_SYS_SPI_ARGS_OFFS
,
40 CONFIG_SYS_SPI_ARGS_SIZE
,
41 (void *)CONFIG_SYS_SPL_ARGS_ADDR
);
48 * The main entry for SPI booting. It's necessary that SDRAM is already
49 * configured and available since this code loads the main U-Boot image
50 * from SPI into SDRAM and starts it from there.
52 int spl_spi_load_image(void)
55 struct spi_flash
*flash
;
56 struct image_header
*header
;
59 * Load U-Boot image from SPI flash into RAM
62 flash
= spi_flash_probe(CONFIG_SF_DEFAULT_BUS
,
64 CONFIG_SF_DEFAULT_SPEED
,
65 CONFIG_SF_DEFAULT_MODE
);
67 puts("SPI probe failed.\n");
71 /* use CONFIG_SYS_TEXT_BASE as temporary storage area */
72 header
= (struct image_header
*)(CONFIG_SYS_TEXT_BASE
);
74 #ifdef CONFIG_SPL_OS_BOOT
75 if (spl_start_uboot() || spi_load_image_os(flash
, header
))
78 /* Load u-boot, mkimage header is 64 bytes. */
79 err
= spi_flash_read(flash
, CONFIG_SYS_SPI_U_BOOT_OFFS
, 0x40,
84 spl_parse_image_header(header
);
85 err
= spi_flash_read(flash
, CONFIG_SYS_SPI_U_BOOT_OFFS
,
86 spl_image
.size
, (void *)spl_image
.load_addr
);