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