Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Stefan Roese <sr@denx.de> |
| 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <spl.h> |
| 9 | |
Simon Glass | ee30679 | 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 | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 12 | { |
Marek Vasut | 02266e2 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 13 | int ret; |
Stefan Roese | 900c177 | 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 | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 18 | spl_image->flags |= SPL_COPY_PAYLOAD_ONLY; |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 19 | |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 20 | #ifdef CONFIG_SPL_OS_BOOT |
| 21 | if (!spl_start_uboot()) { |
Heiko Schocher | 329b72a | 2015-02-06 09:31:36 +0100 | [diff] [blame] | 22 | const struct image_header *header; |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 23 | |
Stefan Roese | 900c177 | 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 | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 28 | header = (const struct image_header *)CONFIG_SYS_OS_BASE; |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 29 | |
Masahiro Yamada | 225581b | 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 | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 32 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 33 | ret = spl_parse_image_header(spl_image, header); |
Marek Vasut | 02266e2 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 34 | if (ret) |
| 35 | return ret; |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 36 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 37 | memcpy((void *)spl_image->load_addr, |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 38 | (void *)(CONFIG_SYS_OS_BASE + |
| 39 | sizeof(struct image_header)), |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 40 | spl_image->size); |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * Copy DT blob (fdt) to SDRAM. Passing pointer to |
Mike Looijmans | de62790 | 2016-07-26 07:34:07 +0200 | [diff] [blame] | 44 | * flash doesn't work |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 45 | */ |
| 46 | memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR, |
| 47 | (void *)(CONFIG_SYS_FDT_BASE), |
Mike Looijmans | de62790 | 2016-07-26 07:34:07 +0200 | [diff] [blame] | 48 | CONFIG_SYS_FDT_SIZE); |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 49 | |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 50 | return 0; |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 51 | } else { |
| 52 | puts("The Expected Linux image was not found.\n" |
| 53 | "Please check your NOR configuration.\n" |
| 54 | "Trying to start u-boot now...\n"); |
| 55 | } |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 56 | } |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 57 | #endif |
| 58 | |
| 59 | /* |
| 60 | * Load real U-Boot from its location in NOR flash to its |
| 61 | * defined location in SDRAM |
| 62 | */ |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 63 | ret = spl_parse_image_header(spl_image, |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 64 | (const struct image_header *)CONFIG_SYS_UBOOT_BASE); |
Marek Vasut | 02266e2 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 65 | if (ret) |
| 66 | return ret; |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 67 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 68 | memcpy((void *)(unsigned long)spl_image->load_addr, |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 69 | (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)), |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 70 | spl_image->size); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 71 | |
| 72 | return 0; |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 73 | } |
Simon Glass | 8f42e64 | 2016-09-24 18:20:04 -0600 | [diff] [blame] | 74 | SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_NOR, spl_nor_load_image); |