blob: 29355307f3689c0b61f2c6432a0033c4504a8c0f [file] [log] [blame]
Christian Riesch32b11272011-12-09 09:47:35 +00001/*
2 * Copyright (C) 2011 OMICRON electronics GmbH
3 *
4 * based on drivers/mtd/nand/nand_spl_load.c
5 *
6 * Copyright (C) 2011
7 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
8 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Christian Riesch32b11272011-12-09 09:47:35 +000010 */
11
12#include <common.h>
13#include <spi_flash.h>
Tom Rinia4cc1c42012-08-14 14:34:10 -070014#include <spl.h>
Christian Riesch32b11272011-12-09 09:47:35 +000015
16/*
17 * The main entry for SPI booting. It's necessary that SDRAM is already
18 * configured and available since this code loads the main U-Boot image
19 * from SPI into SDRAM and starts it from there.
20 */
Tom Rinia4cc1c42012-08-14 14:34:10 -070021void spl_spi_load_image(void)
Christian Riesch32b11272011-12-09 09:47:35 +000022{
23 struct spi_flash *flash;
Tom Rinia4cc1c42012-08-14 14:34:10 -070024 struct image_header *header;
Christian Riesch32b11272011-12-09 09:47:35 +000025
26 /*
27 * Load U-Boot image from SPI flash into RAM
28 */
29
30 flash = spi_flash_probe(CONFIG_SPL_SPI_BUS, CONFIG_SPL_SPI_CS,
31 CONFIG_SF_DEFAULT_SPEED, SPI_MODE_3);
32 if (!flash) {
Tom Rinia4cc1c42012-08-14 14:34:10 -070033 puts("SPI probe failed.\n");
Christian Riesch32b11272011-12-09 09:47:35 +000034 hang();
35 }
36
Tom Rinia4cc1c42012-08-14 14:34:10 -070037 /* use CONFIG_SYS_TEXT_BASE as temporary storage area */
38 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
Christian Riesch32b11272011-12-09 09:47:35 +000039
Tom Rinia4cc1c42012-08-14 14:34:10 -070040 /* Load u-boot, mkimage header is 64 bytes. */
41 spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40,
Jagannadha Sutradharudu Teki5928b9a2013-07-29 22:43:57 +053042 (void *)header);
Tom Rinia4cc1c42012-08-14 14:34:10 -070043 spl_parse_image_header(header);
44 spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS,
45 spl_image.size, (void *)spl_image.load_addr);
Christian Riesch32b11272011-12-09 09:47:35 +000046}