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