blob: bb6194fafdc6c678d7c3669b1fef400409261899 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese33d34642012-08-27 12:50:59 +02002/*
3 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
Stefan Roese33d34642012-08-27 12:50:59 +02004 */
5
6#include <common.h>
7#include <spl.h>
8
Simon Glass2a2ee2a2016-09-24 18:20:13 -06009static int spl_nor_load_image(struct spl_image_info *spl_image,
10 struct spl_boot_device *bootdev)
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 */
Simon Glass2a2ee2a2016-09-24 18:20:13 -060017 spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
Stefan Roese33d34642012-08-27 12:50:59 +020018
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
Simon Glass2a2ee2a2016-09-24 18:20:13 -060032 ret = spl_parse_image_header(spl_image, header);
Marek Vasut7e0f2262016-04-29 00:44:54 +020033 if (ret)
34 return ret;
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090035
Simon Glass2a2ee2a2016-09-24 18:20:13 -060036 memcpy((void *)spl_image->load_addr,
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090037 (void *)(CONFIG_SYS_OS_BASE +
38 sizeof(struct image_header)),
Simon Glass2a2ee2a2016-09-24 18:20:13 -060039 spl_image->size);
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090040
Vikas Manocha5bf52502017-04-07 15:38:13 -070041 spl_image->arg = (void *)CONFIG_SYS_FDT_BASE;
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090042
Nikita Kiryanov36afd452015-11-08 17:11:49 +020043 return 0;
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090044 } else {
45 puts("The Expected Linux image was not found.\n"
46 "Please check your NOR configuration.\n"
47 "Trying to start u-boot now...\n");
48 }
Stefan Roese33d34642012-08-27 12:50:59 +020049 }
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090050#endif
51
52 /*
53 * Load real U-Boot from its location in NOR flash to its
54 * defined location in SDRAM
55 */
Simon Glass2a2ee2a2016-09-24 18:20:13 -060056 ret = spl_parse_image_header(spl_image,
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090057 (const struct image_header *)CONFIG_SYS_UBOOT_BASE);
Marek Vasut7e0f2262016-04-29 00:44:54 +020058 if (ret)
59 return ret;
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090060
Simon Glass2a2ee2a2016-09-24 18:20:13 -060061 memcpy((void *)(unsigned long)spl_image->load_addr,
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090062 (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
Simon Glass2a2ee2a2016-09-24 18:20:13 -060063 spl_image->size);
Nikita Kiryanov36afd452015-11-08 17:11:49 +020064
65 return 0;
Stefan Roese33d34642012-08-27 12:50:59 +020066}
Simon Glassebc4ef62016-11-30 15:30:50 -070067SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);