blob: 1ef8ac8b89b6332d2cd4c57390c3d58c175cb061 [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
Simon Glass2a2ee2a2016-09-24 18:20:13 -060010static int spl_nor_load_image(struct spl_image_info *spl_image,
11 struct spl_boot_device *bootdev)
Stefan Roese33d34642012-08-27 12:50:59 +020012{
Marek Vasut7e0f2262016-04-29 00:44:54 +020013 int ret;
Stefan Roese33d34642012-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 Glass2a2ee2a2016-09-24 18:20:13 -060018 spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
Stefan Roese33d34642012-08-27 12:50:59 +020019
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090020#ifdef CONFIG_SPL_OS_BOOT
21 if (!spl_start_uboot()) {
Heiko Schocherb9ea0c32015-02-06 09:31:36 +010022 const struct image_header *header;
Stefan Roese33d34642012-08-27 12:50:59 +020023
Stefan Roese33d34642012-08-27 12:50:59 +020024 /*
25 * Load Linux from its location in NOR flash to its defined
26 * location in SDRAM
27 */
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090028 header = (const struct image_header *)CONFIG_SYS_OS_BASE;
Stefan Roese33d34642012-08-27 12:50:59 +020029
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090030 if (image_get_os(header) == IH_OS_LINUX) {
31 /* happy - was a Linux */
Stefan Roese33d34642012-08-27 12:50:59 +020032
Simon Glass2a2ee2a2016-09-24 18:20:13 -060033 ret = spl_parse_image_header(spl_image, header);
Marek Vasut7e0f2262016-04-29 00:44:54 +020034 if (ret)
35 return ret;
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090036
Simon Glass2a2ee2a2016-09-24 18:20:13 -060037 memcpy((void *)spl_image->load_addr,
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090038 (void *)(CONFIG_SYS_OS_BASE +
39 sizeof(struct image_header)),
Simon Glass2a2ee2a2016-09-24 18:20:13 -060040 spl_image->size);
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090041
Vikas Manocha5bf52502017-04-07 15:38:13 -070042 spl_image->arg = (void *)CONFIG_SYS_FDT_BASE;
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090043
Nikita Kiryanov36afd452015-11-08 17:11:49 +020044 return 0;
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090045 } else {
46 puts("The Expected Linux image was not found.\n"
47 "Please check your NOR configuration.\n"
48 "Trying to start u-boot now...\n");
49 }
Stefan Roese33d34642012-08-27 12:50:59 +020050 }
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090051#endif
52
53 /*
54 * Load real U-Boot from its location in NOR flash to its
55 * defined location in SDRAM
56 */
Simon Glass2a2ee2a2016-09-24 18:20:13 -060057 ret = spl_parse_image_header(spl_image,
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090058 (const struct image_header *)CONFIG_SYS_UBOOT_BASE);
Marek Vasut7e0f2262016-04-29 00:44:54 +020059 if (ret)
60 return ret;
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090061
Simon Glass2a2ee2a2016-09-24 18:20:13 -060062 memcpy((void *)(unsigned long)spl_image->load_addr,
Masahiro Yamada9f9d8702015-01-08 19:23:35 +090063 (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
Simon Glass2a2ee2a2016-09-24 18:20:13 -060064 spl_image->size);
Nikita Kiryanov36afd452015-11-08 17:11:49 +020065
66 return 0;
Stefan Roese33d34642012-08-27 12:50:59 +020067}
Simon Glassebc4ef62016-11-30 15:30:50 -070068SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);