Christian Riesch | 23f16a8 | 2011-12-09 09:47:35 +0000 | [diff] [blame] | 1 | /* |
| 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 Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
Christian Riesch | 23f16a8 | 2011-12-09 09:47:35 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
| 13 | #include <spi_flash.h> |
Tom Rini | 1e2abf9 | 2012-08-14 14:34:10 -0700 | [diff] [blame] | 14 | #include <spl.h> |
Christian Riesch | 23f16a8 | 2011-12-09 09:47:35 +0000 | [diff] [blame] | 15 | |
Tom Rini | d4cdb7a | 2014-04-03 07:52:55 -0400 | [diff] [blame^] | 16 | #ifdef CONFIG_SPL_OS_BOOT |
| 17 | /* |
| 18 | * Load the kernel, check for a valid header we can parse, and if found load |
| 19 | * the kernel and then device tree. |
| 20 | */ |
| 21 | static int spi_load_image_os(struct spi_flash *flash, |
| 22 | struct image_header *header) |
| 23 | { |
| 24 | /* Read for a header, parse or error out. */ |
| 25 | spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS, 0x40, |
| 26 | (void *)header); |
| 27 | |
| 28 | if (image_get_magic(header) != IH_MAGIC) |
| 29 | return -1; |
| 30 | |
| 31 | spl_parse_image_header(header); |
| 32 | |
| 33 | spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS, |
| 34 | spl_image.size, (void *)spl_image.load_addr); |
| 35 | |
| 36 | /* Read device tree. */ |
| 37 | spi_flash_read(flash, CONFIG_SYS_SPI_ARGS_OFFS, |
| 38 | CONFIG_SYS_SPI_ARGS_SIZE, |
| 39 | (void *)CONFIG_SYS_SPL_ARGS_ADDR); |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | #endif |
| 44 | |
Christian Riesch | 23f16a8 | 2011-12-09 09:47:35 +0000 | [diff] [blame] | 45 | /* |
| 46 | * The main entry for SPI booting. It's necessary that SDRAM is already |
| 47 | * configured and available since this code loads the main U-Boot image |
| 48 | * from SPI into SDRAM and starts it from there. |
| 49 | */ |
Tom Rini | 1e2abf9 | 2012-08-14 14:34:10 -0700 | [diff] [blame] | 50 | void spl_spi_load_image(void) |
Christian Riesch | 23f16a8 | 2011-12-09 09:47:35 +0000 | [diff] [blame] | 51 | { |
| 52 | struct spi_flash *flash; |
Tom Rini | 1e2abf9 | 2012-08-14 14:34:10 -0700 | [diff] [blame] | 53 | struct image_header *header; |
Christian Riesch | 23f16a8 | 2011-12-09 09:47:35 +0000 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Load U-Boot image from SPI flash into RAM |
| 57 | */ |
| 58 | |
| 59 | flash = spi_flash_probe(CONFIG_SPL_SPI_BUS, CONFIG_SPL_SPI_CS, |
| 60 | CONFIG_SF_DEFAULT_SPEED, SPI_MODE_3); |
| 61 | if (!flash) { |
Tom Rini | 1e2abf9 | 2012-08-14 14:34:10 -0700 | [diff] [blame] | 62 | puts("SPI probe failed.\n"); |
Christian Riesch | 23f16a8 | 2011-12-09 09:47:35 +0000 | [diff] [blame] | 63 | hang(); |
| 64 | } |
| 65 | |
Tom Rini | 1e2abf9 | 2012-08-14 14:34:10 -0700 | [diff] [blame] | 66 | /* use CONFIG_SYS_TEXT_BASE as temporary storage area */ |
| 67 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE); |
Christian Riesch | 23f16a8 | 2011-12-09 09:47:35 +0000 | [diff] [blame] | 68 | |
Tom Rini | d4cdb7a | 2014-04-03 07:52:55 -0400 | [diff] [blame^] | 69 | #ifdef CONFIG_SPL_OS_BOOT |
| 70 | if (spl_start_uboot() || spi_load_image_os(flash, header)) |
| 71 | #endif |
| 72 | { |
| 73 | /* Load u-boot, mkimage header is 64 bytes. */ |
| 74 | spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40, |
| 75 | (void *)header); |
| 76 | spl_parse_image_header(header); |
| 77 | spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, |
| 78 | spl_image.size, (void *)spl_image.load_addr); |
| 79 | } |
Christian Riesch | 23f16a8 | 2011-12-09 09:47:35 +0000 | [diff] [blame] | 80 | } |