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