blob: 8ea874c888e8d6d4c8c2594458e1f2641f33fc47 [file] [log] [blame]
Stefan Roese900c1772012-08-27 12:50:59 +02001/*
2 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese900c1772012-08-27 12:50:59 +02005 */
6
7#include <common.h>
8#include <spl.h>
9
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020010int spl_nor_load_image(void)
Stefan Roese900c1772012-08-27 12:50:59 +020011{
Marek Vasut02266e22016-04-29 00:44:54 +020012 int ret;
Stefan Roese900c1772012-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 Yamada225581b2015-01-08 19:23:35 +090019#ifdef CONFIG_SPL_OS_BOOT
20 if (!spl_start_uboot()) {
Heiko Schocher329b72a2015-02-06 09:31:36 +010021 const struct image_header *header;
Stefan Roese900c1772012-08-27 12:50:59 +020022
Stefan Roese900c1772012-08-27 12:50:59 +020023 /*
24 * Load Linux from its location in NOR flash to its defined
25 * location in SDRAM
26 */
Masahiro Yamada225581b2015-01-08 19:23:35 +090027 header = (const struct image_header *)CONFIG_SYS_OS_BASE;
Stefan Roese900c1772012-08-27 12:50:59 +020028
Masahiro Yamada225581b2015-01-08 19:23:35 +090029 if (image_get_os(header) == IH_OS_LINUX) {
30 /* happy - was a Linux */
Stefan Roese900c1772012-08-27 12:50:59 +020031
Marek Vasut02266e22016-04-29 00:44:54 +020032 ret = spl_parse_image_header(header);
33 if (ret)
34 return ret;
Masahiro Yamada225581b2015-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
Mike Looijmansde627902016-07-26 07:34:07 +020043 * flash doesn't work
Masahiro Yamada225581b2015-01-08 19:23:35 +090044 */
45 memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR,
46 (void *)(CONFIG_SYS_FDT_BASE),
Mike Looijmansde627902016-07-26 07:34:07 +020047 CONFIG_SYS_FDT_SIZE);
Masahiro Yamada225581b2015-01-08 19:23:35 +090048
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020049 return 0;
Masahiro Yamada225581b2015-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 Roese900c1772012-08-27 12:50:59 +020055 }
Masahiro Yamada225581b2015-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 Vasut02266e22016-04-29 00:44:54 +020062 ret = spl_parse_image_header(
Masahiro Yamada225581b2015-01-08 19:23:35 +090063 (const struct image_header *)CONFIG_SYS_UBOOT_BASE);
Marek Vasut02266e22016-04-29 00:44:54 +020064 if (ret)
65 return ret;
Masahiro Yamada225581b2015-01-08 19:23:35 +090066
Masahiro Yamadabc69da22016-02-29 20:50:34 +090067 memcpy((void *)(unsigned long)spl_image.load_addr,
Masahiro Yamada225581b2015-01-08 19:23:35 +090068 (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
69 spl_image.size);
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020070
71 return 0;
Stefan Roese900c1772012-08-27 12:50:59 +020072}