1 // SPDX-License-Identifier: GPL-2.0+
4 * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
11 #include <linux/libfdt_env.h>
14 uint32_t __weak spl_nand_get_uboot_raw_page(void)
16 return CONFIG_SYS_NAND_U_BOOT_OFFS;
19 #if defined(CONFIG_SPL_NAND_RAW_ONLY)
20 static int spl_nand_load_image(struct spl_image_info *spl_image,
21 struct spl_boot_device *bootdev)
25 printf("Loading U-Boot from 0x%08x (size 0x%08x) to 0x%08x\n",
26 CONFIG_SYS_NAND_U_BOOT_OFFS, CONFIG_SYS_NAND_U_BOOT_SIZE,
27 CONFIG_SYS_NAND_U_BOOT_DST);
29 nand_spl_load_image(spl_nand_get_uboot_raw_page(),
30 CONFIG_SYS_NAND_U_BOOT_SIZE,
31 (void *)CONFIG_SYS_NAND_U_BOOT_DST);
32 spl_set_header_raw_uboot(spl_image);
39 static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
40 ulong size, void *dst)
44 ret = nand_spl_load_image(offs, size, dst);
51 static int spl_nand_load_element(struct spl_image_info *spl_image,
52 int offset, struct image_header *header)
56 err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
60 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
61 image_get_magic(header) == FDT_MAGIC) {
62 struct spl_load_info load;
69 load.read = spl_nand_fit_read;
70 return spl_load_simple_fit(spl_image, &load, offset, header);
71 } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
72 struct spl_load_info load;
78 load.read = spl_nand_fit_read;
79 return spl_load_imx_container(spl_image, &load, offset);
81 err = spl_parse_image_header(spl_image, header);
84 return nand_spl_load_image(offset, spl_image->size,
85 (void *)(ulong)spl_image->load_addr);
89 static int spl_nand_load_image(struct spl_image_info *spl_image,
90 struct spl_boot_device *bootdev)
93 struct image_header *header;
94 int *src __attribute__((unused));
95 int *dst __attribute__((unused));
97 #ifdef CONFIG_SPL_NAND_SOFTECC
98 debug("spl: nand - using sw ecc\n");
100 debug("spl: nand - using hw ecc\n");
104 header = spl_get_load_buffer(0, sizeof(*header));
106 #ifdef CONFIG_SPL_OS_BOOT
107 if (!spl_start_uboot()) {
109 * load parameter image
110 * load to temp position since nand_spl_load_image reads
111 * a whole block which is typically larger than
112 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
113 * following sections like BSS
115 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
116 CONFIG_CMD_SPL_WRITE_SIZE,
117 (void *)CONFIG_SYS_TEXT_BASE);
118 /* copy to destintion */
119 for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
120 src = (int *)CONFIG_SYS_TEXT_BASE;
121 src < (int *)(CONFIG_SYS_TEXT_BASE +
122 CONFIG_CMD_SPL_WRITE_SIZE);
124 writel(readl(src), dst);
128 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
129 sizeof(*header), (void *)header);
130 err = spl_parse_image_header(spl_image, header);
133 if (header->ih_os == IH_OS_LINUX) {
134 /* happy - was a linux */
135 err = nand_spl_load_image(
136 CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
138 (void *)spl_image->load_addr);
142 puts("The Expected Linux image was not "
143 "found. Please check your NAND "
145 puts("Trying to start u-boot now...\n");
149 #ifdef CONFIG_NAND_ENV_DST
150 spl_nand_load_element(spl_image, CONFIG_ENV_OFFSET, header);
151 #ifdef CONFIG_ENV_OFFSET_REDUND
152 spl_nand_load_element(spl_image, CONFIG_ENV_OFFSET_REDUND, header);
156 err = spl_nand_load_element(spl_image, spl_nand_get_uboot_raw_page(),
158 #ifdef CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
159 #if CONFIG_SYS_NAND_U_BOOT_OFFS != CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
161 err = spl_nand_load_element(spl_image,
162 CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND,
170 /* Use priorty 1 so that Ubi can override this */
171 SPL_LOAD_IMAGE_METHOD("NAND", 1, BOOT_DEVICE_NAND, spl_nand_load_image);