Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Stefan Roese <sr@denx.de> |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <spl.h> |
| 8 | |
Simon Glass | ee30679 | 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 | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 11 | { |
Marek Vasut | 02266e2 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 12 | int ret; |
Stefan Roese | 900c177 | 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 | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 17 | spl_image->flags |= SPL_COPY_PAYLOAD_ONLY; |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 18 | |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 19 | #ifdef CONFIG_SPL_OS_BOOT |
| 20 | if (!spl_start_uboot()) { |
Heiko Schocher | 329b72a | 2015-02-06 09:31:36 +0100 | [diff] [blame] | 21 | const struct image_header *header; |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 22 | |
Stefan Roese | 900c177 | 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 | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 27 | header = (const struct image_header *)CONFIG_SYS_OS_BASE; |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 28 | |
Masahiro Yamada | 225581b | 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 | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 31 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 32 | ret = spl_parse_image_header(spl_image, header); |
Marek Vasut | 02266e2 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 33 | if (ret) |
| 34 | return ret; |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 35 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 36 | memcpy((void *)spl_image->load_addr, |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 37 | (void *)(CONFIG_SYS_OS_BASE + |
| 38 | sizeof(struct image_header)), |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 39 | spl_image->size); |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 40 | |
Vikas Manocha | 62b021c | 2017-04-07 15:38:13 -0700 | [diff] [blame] | 41 | spl_image->arg = (void *)CONFIG_SYS_FDT_BASE; |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 42 | |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 43 | return 0; |
Masahiro Yamada | 225581b | 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 | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 49 | } |
Masahiro Yamada | 225581b | 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 | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 56 | ret = spl_parse_image_header(spl_image, |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 57 | (const struct image_header *)CONFIG_SYS_UBOOT_BASE); |
Marek Vasut | 02266e2 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 58 | if (ret) |
| 59 | return ret; |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 60 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 61 | memcpy((void *)(unsigned long)spl_image->load_addr, |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 62 | (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)), |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 63 | spl_image->size); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 64 | |
| 65 | return 0; |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 66 | } |
Simon Glass | 4fc1f25 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 67 | SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image); |