blob: d07ca84382468278e066f69598b6c490f3b68661 [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
Simon Glassee306792016-09-24 18:20:13 -060010static int spl_nor_load_image(struct spl_image_info *spl_image,
11 struct spl_boot_device *bootdev)
Stefan Roese900c1772012-08-27 12:50:59 +020012{
Marek Vasut02266e22016-04-29 00:44:54 +020013 int ret;
Stefan Roese900c1772012-08-27 12:50:59 +020014 /*
15 * Loading of the payload to SDRAM is done with skipping of
16 * the mkimage header in this SPL NOR driver
17 */
Simon Glassee306792016-09-24 18:20:13 -060018 spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
Stefan Roese900c1772012-08-27 12:50:59 +020019
Masahiro Yamada225581b2015-01-08 19:23:35 +090020#ifdef CONFIG_SPL_OS_BOOT
21 if (!spl_start_uboot()) {
Heiko Schocher329b72a2015-02-06 09:31:36 +010022 const struct image_header *header;
Stefan Roese900c1772012-08-27 12:50:59 +020023
Stefan Roese900c1772012-08-27 12:50:59 +020024 /*
25 * Load Linux from its location in NOR flash to its defined
26 * location in SDRAM
27 */
Masahiro Yamada225581b2015-01-08 19:23:35 +090028 header = (const struct image_header *)CONFIG_SYS_OS_BASE;
Stefan Roese900c1772012-08-27 12:50:59 +020029
Masahiro Yamada225581b2015-01-08 19:23:35 +090030 if (image_get_os(header) == IH_OS_LINUX) {
31 /* happy - was a Linux */
Stefan Roese900c1772012-08-27 12:50:59 +020032
Simon Glassee306792016-09-24 18:20:13 -060033 ret = spl_parse_image_header(spl_image, header);
Marek Vasut02266e22016-04-29 00:44:54 +020034 if (ret)
35 return ret;
Masahiro Yamada225581b2015-01-08 19:23:35 +090036
Simon Glassee306792016-09-24 18:20:13 -060037 memcpy((void *)spl_image->load_addr,
Masahiro Yamada225581b2015-01-08 19:23:35 +090038 (void *)(CONFIG_SYS_OS_BASE +
39 sizeof(struct image_header)),
Simon Glassee306792016-09-24 18:20:13 -060040 spl_image->size);
Masahiro Yamada225581b2015-01-08 19:23:35 +090041
42 /*
43 * Copy DT blob (fdt) to SDRAM. Passing pointer to
Mike Looijmansde627902016-07-26 07:34:07 +020044 * flash doesn't work
Masahiro Yamada225581b2015-01-08 19:23:35 +090045 */
46 memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR,
47 (void *)(CONFIG_SYS_FDT_BASE),
Mike Looijmansde627902016-07-26 07:34:07 +020048 CONFIG_SYS_FDT_SIZE);
Masahiro Yamada225581b2015-01-08 19:23:35 +090049
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020050 return 0;
Masahiro Yamada225581b2015-01-08 19:23:35 +090051 } else {
52 puts("The Expected Linux image was not found.\n"
53 "Please check your NOR configuration.\n"
54 "Trying to start u-boot now...\n");
55 }
Stefan Roese900c1772012-08-27 12:50:59 +020056 }
Masahiro Yamada225581b2015-01-08 19:23:35 +090057#endif
58
59 /*
60 * Load real U-Boot from its location in NOR flash to its
61 * defined location in SDRAM
62 */
Simon Glassee306792016-09-24 18:20:13 -060063 ret = spl_parse_image_header(spl_image,
Masahiro Yamada225581b2015-01-08 19:23:35 +090064 (const struct image_header *)CONFIG_SYS_UBOOT_BASE);
Marek Vasut02266e22016-04-29 00:44:54 +020065 if (ret)
66 return ret;
Masahiro Yamada225581b2015-01-08 19:23:35 +090067
Simon Glassee306792016-09-24 18:20:13 -060068 memcpy((void *)(unsigned long)spl_image->load_addr,
Masahiro Yamada225581b2015-01-08 19:23:35 +090069 (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
Simon Glassee306792016-09-24 18:20:13 -060070 spl_image->size);
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020071
72 return 0;
Stefan Roese900c1772012-08-27 12:50:59 +020073}
Simon Glass4fc1f252016-11-30 15:30:50 -070074SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);