Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Stefan Roese <sr@denx.de> |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <spl.h> |
| 9 | |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 10 | static int spl_nor_load_image(struct spl_image_info *spl_image, |
| 11 | struct spl_boot_device *bootdev) |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 12 | { |
Marek Vasut | 7e0f226 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 13 | int ret; |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 14 | /* |
| 15 | * Loading of the payload to SDRAM is done with skipping of |
| 16 | * the mkimage header in this SPL NOR driver |
| 17 | */ |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 18 | spl_image->flags |= SPL_COPY_PAYLOAD_ONLY; |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 19 | |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 20 | #ifdef CONFIG_SPL_OS_BOOT |
| 21 | if (!spl_start_uboot()) { |
Heiko Schocher | b9ea0c3 | 2015-02-06 09:31:36 +0100 | [diff] [blame] | 22 | const struct image_header *header; |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 23 | |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 24 | /* |
| 25 | * Load Linux from its location in NOR flash to its defined |
| 26 | * location in SDRAM |
| 27 | */ |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 28 | header = (const struct image_header *)CONFIG_SYS_OS_BASE; |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 29 | |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 30 | if (image_get_os(header) == IH_OS_LINUX) { |
| 31 | /* happy - was a Linux */ |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 32 | |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 33 | ret = spl_parse_image_header(spl_image, header); |
Marek Vasut | 7e0f226 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 34 | if (ret) |
| 35 | return ret; |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 36 | |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 37 | memcpy((void *)spl_image->load_addr, |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 38 | (void *)(CONFIG_SYS_OS_BASE + |
| 39 | sizeof(struct image_header)), |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 40 | spl_image->size); |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 41 | |
Vikas Manocha | 5bf5250 | 2017-04-07 15:38:13 -0700 | [diff] [blame^] | 42 | spl_image->arg = (void *)CONFIG_SYS_FDT_BASE; |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 43 | |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 44 | return 0; |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 45 | } 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 Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 50 | } |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 51 | #endif |
| 52 | |
| 53 | /* |
| 54 | * Load real U-Boot from its location in NOR flash to its |
| 55 | * defined location in SDRAM |
| 56 | */ |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 57 | ret = spl_parse_image_header(spl_image, |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 58 | (const struct image_header *)CONFIG_SYS_UBOOT_BASE); |
Marek Vasut | 7e0f226 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 59 | if (ret) |
| 60 | return ret; |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 61 | |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 62 | memcpy((void *)(unsigned long)spl_image->load_addr, |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 63 | (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)), |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 64 | spl_image->size); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 65 | |
| 66 | return 0; |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 67 | } |
Simon Glass | ebc4ef6 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 68 | SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image); |