blob: da2422f30515ac07d1af7161ac7ae906783de3f7 [file] [log] [blame]
Stefan Roese33d34642012-08-27 12:50:59 +02001/*
2 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese33d34642012-08-27 12:50:59 +02005 */
6
7#include <common.h>
8#include <spl.h>
9
Nikita Kiryanov36afd452015-11-08 17:11:49 +020010int spl_nor_load_image(void)
Stefan Roese33d34642012-08-27 12:50:59 +020011{
Marek Vasut7e0f2262016-04-29 00:44:54 +020012 int ret;
Stefan Roese33d34642012-08-27 12:50:59 +020013 /*
14 * Loading of the payload to SDRAM is done with skipping of
15 * the mkimage header in this SPL NOR driver
16 */
17 spl_image.flags |= SPL_COPY_PAYLOAD_ONLY;
18
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090019#ifdef CONFIG_SPL_OS_BOOT
20 if (!spl_start_uboot()) {
Heiko Schocherb9ea0c32015-02-06 09:31:36 +010021 const struct image_header *header;
Stefan Roese33d34642012-08-27 12:50:59 +020022
Stefan Roese33d34642012-08-27 12:50:59 +020023 /*
24 * Load Linux from its location in NOR flash to its defined
25 * location in SDRAM
26 */
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090027 header = (const struct image_header *)CONFIG_SYS_OS_BASE;
Stefan Roese33d34642012-08-27 12:50:59 +020028
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090029 if (image_get_os(header) == IH_OS_LINUX) {
30 /* happy - was a Linux */
Stefan Roese33d34642012-08-27 12:50:59 +020031
Marek Vasut7e0f2262016-04-29 00:44:54 +020032 ret = spl_parse_image_header(header);
33 if (ret)
34 return ret;
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090035
36 memcpy((void *)spl_image.load_addr,
37 (void *)(CONFIG_SYS_OS_BASE +
38 sizeof(struct image_header)),
39 spl_image.size);
40
41 /*
42 * Copy DT blob (fdt) to SDRAM. Passing pointer to
43 * flash doesn't work (16 KiB should be enough for DT)
44 */
45 memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR,
46 (void *)(CONFIG_SYS_FDT_BASE),
47 (16 << 10));
48
Nikita Kiryanov36afd452015-11-08 17:11:49 +020049 return 0;
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090050 } else {
51 puts("The Expected Linux image was not found.\n"
52 "Please check your NOR configuration.\n"
53 "Trying to start u-boot now...\n");
54 }
Stefan Roese33d34642012-08-27 12:50:59 +020055 }
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090056#endif
57
58 /*
59 * Load real U-Boot from its location in NOR flash to its
60 * defined location in SDRAM
61 */
Marek Vasut7e0f2262016-04-29 00:44:54 +020062 ret = spl_parse_image_header(
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090063 (const struct image_header *)CONFIG_SYS_UBOOT_BASE);
Marek Vasut7e0f2262016-04-29 00:44:54 +020064 if (ret)
65 return ret;
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090066
Masahiro Yamada70e64282016-02-29 20:50:34 +090067 memcpy((void *)(unsigned long)spl_image.load_addr,
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090068 (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
69 spl_image.size);
Nikita Kiryanov36afd452015-11-08 17:11:49 +020070
71 return 0;
Stefan Roese33d34642012-08-27 12:50:59 +020072}