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