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 | |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 10 | int spl_nor_load_image(void) |
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 | */ |
| 17 | spl_image.flags |= SPL_COPY_PAYLOAD_ONLY; |
| 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 | |
Marek Vasut | 7e0f226 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 32 | ret = spl_parse_image_header(header); |
| 33 | if (ret) |
| 34 | return ret; |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 35 | |
| 36 | memcpy((void *)spl_image.load_addr, |
| 37 | (void *)(CONFIG_SYS_OS_BASE + |
| 38 | sizeof(struct image_header)), |
| 39 | spl_image.size); |
| 40 | |
| 41 | /* |
| 42 | * Copy DT blob (fdt) to SDRAM. Passing pointer to |
Mike Looijmans | 5aa79f2 | 2016-07-26 07:34:07 +0200 | [diff] [blame] | 43 | * flash doesn't work |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 44 | */ |
| 45 | memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR, |
| 46 | (void *)(CONFIG_SYS_FDT_BASE), |
Mike Looijmans | 5aa79f2 | 2016-07-26 07:34:07 +0200 | [diff] [blame] | 47 | CONFIG_SYS_FDT_SIZE); |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 48 | |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 49 | return 0; |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 50 | } else { |
| 51 | puts("The Expected Linux image was not found.\n" |
| 52 | "Please check your NOR configuration.\n" |
| 53 | "Trying to start u-boot now...\n"); |
| 54 | } |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 55 | } |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 56 | #endif |
| 57 | |
| 58 | /* |
| 59 | * Load real U-Boot from its location in NOR flash to its |
| 60 | * defined location in SDRAM |
| 61 | */ |
Marek Vasut | 7e0f226 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 62 | ret = spl_parse_image_header( |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 63 | (const struct image_header *)CONFIG_SYS_UBOOT_BASE); |
Marek Vasut | 7e0f226 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 64 | if (ret) |
| 65 | return ret; |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 66 | |
Masahiro Yamada | 70e6428 | 2016-02-29 20:50:34 +0900 | [diff] [blame] | 67 | memcpy((void *)(unsigned long)spl_image.load_addr, |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 68 | (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)), |
| 69 | spl_image.size); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 70 | |
| 71 | return 0; |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 72 | } |