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> |
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"); |
Sean Anderson | 35f15fe | 2023-11-08 11:48:43 -0500 | [diff] [blame] | 52 | spl_set_bl_len(&load, 1); |
York Sun | 7975725 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 53 | load.read = spl_nor_load_read; |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 54 | |
York Sun | 7975725 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 55 | ret = spl_load_simple_fit(spl_image, &load, |
| 56 | CONFIG_SYS_OS_BASE, |
| 57 | (void *)header); |
| 58 | |
Simon Glass | 259cdb4 | 2023-09-26 08:14:17 -0600 | [diff] [blame] | 59 | #if defined CONFIG_SPL_PAYLOAD_ARGS_ADDR && defined CONFIG_CMD_SPL_NOR_OFS |
| 60 | memcpy((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, |
Lukasz Majewski | 55ce92e | 2019-10-15 10:28:45 +0200 | [diff] [blame] | 61 | (void *)CONFIG_CMD_SPL_NOR_OFS, |
| 62 | CONFIG_CMD_SPL_WRITE_SIZE); |
| 63 | #endif |
York Sun | 7975725 | 2018-06-26 10:10:03 -0700 | [diff] [blame] | 64 | return ret; |
| 65 | } |
| 66 | #endif |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 67 | if (image_get_os(header) == IH_OS_LINUX) { |
| 68 | /* happy - was a Linux */ |
Stefan Roese | 4ee4cf9 | 2020-04-21 09:28:44 +0200 | [diff] [blame] | 69 | int ret; |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 70 | |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 71 | ret = spl_parse_image_header(spl_image, bootdev, header); |
Marek Vasut | 02266e2 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 72 | if (ret) |
| 73 | return ret; |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 74 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 75 | memcpy((void *)spl_image->load_addr, |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 76 | (void *)(CONFIG_SYS_OS_BASE + |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 77 | sizeof(struct legacy_img_hdr)), |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 78 | spl_image->size); |
Simon Glass | 259cdb4 | 2023-09-26 08:14:17 -0600 | [diff] [blame] | 79 | #ifdef CONFIG_SPL_PAYLOAD_ARGS_ADDR |
| 80 | spl_image->arg = (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR; |
York Sun | f0370c0 | 2018-06-26 10:10:04 -0700 | [diff] [blame] | 81 | #endif |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 82 | |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 83 | return 0; |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 84 | } else { |
| 85 | puts("The Expected Linux image was not found.\n" |
| 86 | "Please check your NOR configuration.\n" |
| 87 | "Trying to start u-boot now...\n"); |
| 88 | } |
Stefan Roese | 900c177 | 2012-08-27 12:50:59 +0200 | [diff] [blame] | 89 | } |
Masahiro Yamada | 225581b | 2015-01-08 19:23:35 +0900 | [diff] [blame] | 90 | #endif |
| 91 | |
| 92 | /* |
| 93 | * Load real U-Boot from its location in NOR flash to its |
| 94 | * defined location in SDRAM |
| 95 | */ |
Sean Anderson | 2a5d23f | 2023-11-08 11:48:53 -0500 | [diff] [blame] | 96 | spl_set_bl_len(&load, 1); |
| 97 | load.read = spl_nor_load_read; |
| 98 | 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] | 99 | } |
Simon Glass | 4fc1f25 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 100 | SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image); |