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 | |
York Sun | 6ecd820 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 9 | #ifdef CONFIG_SPL_LOAD_FIT |
| 10 | static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector, |
| 11 | ulong count, void *buf) |
| 12 | { |
| 13 | debug("%s: sector %lx, count %lx, buf %p\n", |
| 14 | __func__, sector, count, buf); |
| 15 | memcpy(buf, (void *)sector, count); |
| 16 | |
| 17 | return count; |
| 18 | } |
| 19 | #endif |
| 20 | |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 21 | static int spl_nor_load_image(struct spl_image_info *spl_image, |
| 22 | struct spl_boot_device *bootdev) |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 23 | { |
Marek Vasut | 7e0f226 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 24 | int ret; |
York Sun | 6ecd820 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 25 | __maybe_unused const struct image_header *header; |
| 26 | __maybe_unused struct spl_load_info load; |
| 27 | |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 28 | /* |
| 29 | * Loading of the payload to SDRAM is done with skipping of |
| 30 | * the mkimage header in this SPL NOR driver |
| 31 | */ |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 32 | spl_image->flags |= SPL_COPY_PAYLOAD_ONLY; |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 33 | |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 34 | #ifdef CONFIG_SPL_OS_BOOT |
| 35 | if (!spl_start_uboot()) { |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 36 | /* |
| 37 | * Load Linux from its location in NOR flash to its defined |
| 38 | * location in SDRAM |
| 39 | */ |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 40 | header = (const struct image_header *)CONFIG_SYS_OS_BASE; |
York Sun | 6ecd820 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 41 | #ifdef CONFIG_SPL_LOAD_FIT |
| 42 | if (image_get_magic(header) == FDT_MAGIC) { |
| 43 | debug("Found FIT\n"); |
| 44 | load.bl_len = 1; |
| 45 | load.read = spl_nor_load_read; |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 46 | |
York Sun | 6ecd820 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 47 | ret = spl_load_simple_fit(spl_image, &load, |
| 48 | CONFIG_SYS_OS_BASE, |
| 49 | (void *)header); |
| 50 | |
| 51 | return ret; |
| 52 | } |
| 53 | #endif |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 54 | if (image_get_os(header) == IH_OS_LINUX) { |
| 55 | /* happy - was a Linux */ |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 56 | |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 57 | ret = spl_parse_image_header(spl_image, header); |
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 *)spl_image->load_addr, |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 62 | (void *)(CONFIG_SYS_OS_BASE + |
| 63 | sizeof(struct image_header)), |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 64 | spl_image->size); |
York Sun | 14acea0 | 2018-06-26 10:10:04 -0700 | [diff] [blame] | 65 | #ifdef CONFIG_SYS_FDT_BASE |
Vikas Manocha | 5bf5250 | 2017-04-07 15:38:13 -0700 | [diff] [blame] | 66 | spl_image->arg = (void *)CONFIG_SYS_FDT_BASE; |
York Sun | 14acea0 | 2018-06-26 10:10:04 -0700 | [diff] [blame] | 67 | #endif |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 68 | |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 69 | return 0; |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 70 | } else { |
| 71 | puts("The Expected Linux image was not found.\n" |
| 72 | "Please check your NOR configuration.\n" |
| 73 | "Trying to start u-boot now...\n"); |
| 74 | } |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 75 | } |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 76 | #endif |
| 77 | |
| 78 | /* |
| 79 | * Load real U-Boot from its location in NOR flash to its |
| 80 | * defined location in SDRAM |
| 81 | */ |
York Sun | 6ecd820 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 82 | #ifdef CONFIG_SPL_LOAD_FIT |
| 83 | header = (const struct image_header *)CONFIG_SYS_UBOOT_BASE; |
| 84 | if (image_get_magic(header) == FDT_MAGIC) { |
| 85 | debug("Found FIT format U-Boot\n"); |
| 86 | load.bl_len = 1; |
| 87 | load.read = spl_nor_load_read; |
| 88 | ret = spl_load_simple_fit(spl_image, &load, |
| 89 | CONFIG_SYS_UBOOT_BASE, |
| 90 | (void *)header); |
| 91 | |
| 92 | return ret; |
| 93 | } |
| 94 | #endif |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 95 | ret = spl_parse_image_header(spl_image, |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 96 | (const struct image_header *)CONFIG_SYS_UBOOT_BASE); |
Marek Vasut | 7e0f226 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 97 | if (ret) |
| 98 | return ret; |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 99 | |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 100 | memcpy((void *)(unsigned long)spl_image->load_addr, |
Masahiro Yamada | 9f9d870 | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 101 | (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)), |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 102 | spl_image->size); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 103 | |
| 104 | return 0; |
Stefan Roese | 33d3464 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 105 | } |
Simon Glass | ebc4ef6 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 106 | SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image); |