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 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 6 | #include <config.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 7 | #include <image.h> |
Sean Anderson | 952ed67 | 2023-10-14 16:47:44 -0400 | [diff] [blame] | 8 | #include <imx_container.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 10 | #include <spl.h> |
Sean Anderson | 2a5d23f | 2023-11-08 11:48:53 -0500 | [diff] [blame] | 11 | #include <spl_load.h> |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 12 | |
York Sun | 7975725 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 13 | static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector, |
| 14 | ulong count, void *buf) |
| 15 | { |
| 16 | debug("%s: sector %lx, count %lx, buf %p\n", |
| 17 | __func__, sector, count, buf); |
Sean Anderson | 5ff7772 | 2023-10-14 16:47:55 -0400 | [diff] [blame] | 18 | memcpy(buf, map_sysmem(sector, count), count); |
York Sun | 7975725 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 19 | |
| 20 | return count; |
| 21 | } |
York Sun | 7975725 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 22 | |
Peng Fan | 6e773f9 | 2019-09-23 10:18:42 +0800 | [diff] [blame] | 23 | unsigned long __weak spl_nor_get_uboot_base(void) |
| 24 | { |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 25 | return CFG_SYS_UBOOT_BASE; |
Peng Fan | 6e773f9 | 2019-09-23 10:18:42 +0800 | [diff] [blame] | 26 | } |
| 27 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 28 | static int spl_nor_load_image(struct spl_image_info *spl_image, |
| 29 | struct spl_boot_device *bootdev) |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 30 | { |
Sean Anderson | 2a5d23f | 2023-11-08 11:48:53 -0500 | [diff] [blame] | 31 | struct spl_load_info load; |
York Sun | 7975725 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 32 | |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 33 | /* |
| 34 | * Loading of the payload to SDRAM is done with skipping of |
| 35 | * the mkimage header in this SPL NOR driver |
| 36 | */ |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 37 | spl_image->flags |= SPL_COPY_PAYLOAD_ONLY; |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 38 | |
Tom Rini | c2e7888 | 2021-10-30 23:03:48 -0400 | [diff] [blame] | 39 | #if CONFIG_IS_ENABLED(OS_BOOT) |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 40 | if (!spl_start_uboot()) { |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 41 | /* |
| 42 | * Load Linux from its location in NOR flash to its defined |
| 43 | * location in SDRAM |
| 44 | */ |
Sean Anderson | 2a5d23f | 2023-11-08 11:48:53 -0500 | [diff] [blame] | 45 | const struct legacy_img_hdr *header = |
| 46 | (const struct legacy_img_hdr *)CONFIG_SYS_OS_BASE; |
York Sun | 7975725 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 47 | #ifdef CONFIG_SPL_LOAD_FIT |
| 48 | if (image_get_magic(header) == FDT_MAGIC) { |
Stefan Roese | 4ee4cf9 | 2020-04-21 09:28:44 +0200 | [diff] [blame] | 49 | int ret; |
| 50 | |
York Sun | 7975725 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 51 | debug("Found FIT\n"); |
Simon Glass | e806686 | 2024-08-22 07:55:02 -0600 | [diff] [blame] | 52 | spl_load_init(&load, spl_nor_load_read, NULL, 1); |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 53 | |
York Sun | 7975725 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 54 | ret = spl_load_simple_fit(spl_image, &load, |
| 55 | CONFIG_SYS_OS_BASE, |
| 56 | (void *)header); |
| 57 | |
Simon Glass | 259cdb4 | 2023-09-26 08:14:17 -0600 | [diff] [blame] | 58 | #if defined CONFIG_SPL_PAYLOAD_ARGS_ADDR && defined CONFIG_CMD_SPL_NOR_OFS |
| 59 | memcpy((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, |
Lukasz Majewski | 55ce92e | 2019-10-15 10:28:45 +0200 | [diff] [blame] | 60 | (void *)CONFIG_CMD_SPL_NOR_OFS, |
| 61 | CONFIG_CMD_SPL_WRITE_SIZE); |
| 62 | #endif |
York Sun | 7975725 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 63 | return ret; |
| 64 | } |
| 65 | #endif |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 66 | if (image_get_os(header) == IH_OS_LINUX) { |
| 67 | /* happy - was a Linux */ |
Stefan Roese | 4ee4cf9 | 2020-04-21 09:28:44 +0200 | [diff] [blame] | 68 | int ret; |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 69 | |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 70 | ret = spl_parse_image_header(spl_image, bootdev, header); |
Marek Vasut | 02266e2 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 71 | if (ret) |
| 72 | return ret; |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 73 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 74 | memcpy((void *)spl_image->load_addr, |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 75 | (void *)(CONFIG_SYS_OS_BASE + |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 76 | sizeof(struct legacy_img_hdr)), |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 77 | spl_image->size); |
Simon Glass | 259cdb4 | 2023-09-26 08:14:17 -0600 | [diff] [blame] | 78 | #ifdef CONFIG_SPL_PAYLOAD_ARGS_ADDR |
| 79 | spl_image->arg = (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR; |
York Sun | f0370c0 | 2018-06-26 10:10:04 -0700 | [diff] [blame] | 80 | #endif |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 81 | |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 82 | return 0; |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 83 | } else { |
| 84 | puts("The Expected Linux image was not found.\n" |
| 85 | "Please check your NOR configuration.\n" |
| 86 | "Trying to start u-boot now...\n"); |
| 87 | } |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 88 | } |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 89 | #endif |
| 90 | |
| 91 | /* |
| 92 | * Load real U-Boot from its location in NOR flash to its |
| 93 | * defined location in SDRAM |
| 94 | */ |
Simon Glass | e806686 | 2024-08-22 07:55:02 -0600 | [diff] [blame] | 95 | spl_load_init(&load, spl_nor_load_read, NULL, 1); |
Sean Anderson | 2a5d23f | 2023-11-08 11:48:53 -0500 | [diff] [blame] | 96 | return spl_load(spl_image, bootdev, &load, 0, spl_nor_get_uboot_base()); |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 97 | } |
Simon Glass | 4fc1f25 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 98 | SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image); |