]>
Commit | Line | Data |
---|---|---|
32b11273 CR |
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 | * | |
1a459660 | 9 | * SPDX-License-Identifier: GPL-2.0+ |
32b11273 CR |
10 | */ |
11 | ||
12 | #include <common.h> | |
ff0960f9 | 13 | #include <spi.h> |
32b11273 | 14 | #include <spi_flash.h> |
36afd451 | 15 | #include <errno.h> |
a4cc1c48 | 16 | #include <spl.h> |
32b11273 | 17 | |
fa1a73fa TR |
18 | #ifdef CONFIG_SPL_OS_BOOT |
19 | /* | |
20 | * Load the kernel, check for a valid header we can parse, and if found load | |
21 | * the kernel and then device tree. | |
22 | */ | |
23 | static int spi_load_image_os(struct spi_flash *flash, | |
24 | struct image_header *header) | |
25 | { | |
7e0f2267 MV |
26 | int err; |
27 | ||
fa1a73fa TR |
28 | /* Read for a header, parse or error out. */ |
29 | spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS, 0x40, | |
30 | (void *)header); | |
31 | ||
32 | if (image_get_magic(header) != IH_MAGIC) | |
33 | return -1; | |
34 | ||
7e0f2267 MV |
35 | err = spl_parse_image_header(header); |
36 | if (err) | |
37 | return err; | |
fa1a73fa TR |
38 | |
39 | spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS, | |
40 | spl_image.size, (void *)spl_image.load_addr); | |
41 | ||
42 | /* Read device tree. */ | |
43 | spi_flash_read(flash, CONFIG_SYS_SPI_ARGS_OFFS, | |
44 | CONFIG_SYS_SPI_ARGS_SIZE, | |
45 | (void *)CONFIG_SYS_SPL_ARGS_ADDR); | |
46 | ||
47 | return 0; | |
48 | } | |
49 | #endif | |
50 | ||
32b11273 CR |
51 | /* |
52 | * The main entry for SPI booting. It's necessary that SDRAM is already | |
53 | * configured and available since this code loads the main U-Boot image | |
54 | * from SPI into SDRAM and starts it from there. | |
55 | */ | |
36afd451 | 56 | int spl_spi_load_image(void) |
32b11273 | 57 | { |
36afd451 | 58 | int err = 0; |
32b11273 | 59 | struct spi_flash *flash; |
a4cc1c48 | 60 | struct image_header *header; |
32b11273 CR |
61 | |
62 | /* | |
63 | * Load U-Boot image from SPI flash into RAM | |
64 | */ | |
65 | ||
88e34e5f NK |
66 | flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, |
67 | CONFIG_SF_DEFAULT_CS, | |
68 | CONFIG_SF_DEFAULT_SPEED, | |
69 | CONFIG_SF_DEFAULT_MODE); | |
32b11273 | 70 | if (!flash) { |
a4cc1c48 | 71 | puts("SPI probe failed.\n"); |
36afd451 | 72 | return -ENODEV; |
32b11273 CR |
73 | } |
74 | ||
a4cc1c48 TR |
75 | /* use CONFIG_SYS_TEXT_BASE as temporary storage area */ |
76 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE); | |
32b11273 | 77 | |
fa1a73fa TR |
78 | #ifdef CONFIG_SPL_OS_BOOT |
79 | if (spl_start_uboot() || spi_load_image_os(flash, header)) | |
80 | #endif | |
81 | { | |
82 | /* Load u-boot, mkimage header is 64 bytes. */ | |
36afd451 NK |
83 | err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40, |
84 | (void *)header); | |
85 | if (err) | |
86 | return err; | |
87 | ||
7e0f2267 MV |
88 | err = spl_parse_image_header(header); |
89 | if (err) | |
90 | return err; | |
36afd451 | 91 | err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, |
fa1a73fa TR |
92 | spl_image.size, (void *)spl_image.load_addr); |
93 | } | |
36afd451 NK |
94 | |
95 | return err; | |
32b11273 | 96 | } |