1 // SPDX-License-Identifier: GPL-2.0+
4 * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
11 #include <linux/libfdt_env.h>
14 #if defined(CONFIG_SPL_NAND_RAW_ONLY)
15 static int spl_nand_load_image(struct spl_image_info *spl_image,
16 struct spl_boot_device *bootdev)
20 printf("Loading U-Boot from 0x%08x (size 0x%08x) to 0x%08x\n",
21 CONFIG_SYS_NAND_U_BOOT_OFFS, CONFIG_SYS_NAND_U_BOOT_SIZE,
22 CONFIG_SYS_NAND_U_BOOT_DST);
24 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
25 CONFIG_SYS_NAND_U_BOOT_SIZE,
26 (void *)CONFIG_SYS_NAND_U_BOOT_DST);
27 spl_set_header_raw_uboot(spl_image);
34 static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
35 ulong size, void *dst)
39 ret = nand_spl_load_image(offs, size, dst);
46 static int spl_nand_load_element(struct spl_image_info *spl_image,
47 int offset, struct image_header *header)
51 err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
55 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
56 image_get_magic(header) == FDT_MAGIC) {
57 struct spl_load_info load;
64 load.read = spl_nand_fit_read;
65 return spl_load_simple_fit(spl_image, &load, offset, header);
67 err = spl_parse_image_header(spl_image, header);
70 return nand_spl_load_image(offset, spl_image->size,
71 (void *)(ulong)spl_image->load_addr);
75 static int spl_nand_load_image(struct spl_image_info *spl_image,
76 struct spl_boot_device *bootdev)
79 struct image_header *header;
80 int *src __attribute__((unused));
81 int *dst __attribute__((unused));
83 #ifdef CONFIG_SPL_NAND_SOFTECC
84 debug("spl: nand - using sw ecc\n");
86 debug("spl: nand - using hw ecc\n");
90 header = spl_get_load_buffer(0, sizeof(*header));
92 #ifdef CONFIG_SPL_OS_BOOT
93 if (!spl_start_uboot()) {
95 * load parameter image
96 * load to temp position since nand_spl_load_image reads
97 * a whole block which is typically larger than
98 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
99 * following sections like BSS
101 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
102 CONFIG_CMD_SPL_WRITE_SIZE,
103 (void *)CONFIG_SYS_TEXT_BASE);
104 /* copy to destintion */
105 for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
106 src = (int *)CONFIG_SYS_TEXT_BASE;
107 src < (int *)(CONFIG_SYS_TEXT_BASE +
108 CONFIG_CMD_SPL_WRITE_SIZE);
110 writel(readl(src), dst);
114 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
115 sizeof(*header), (void *)header);
116 err = spl_parse_image_header(spl_image, header);
119 if (header->ih_os == IH_OS_LINUX) {
120 /* happy - was a linux */
121 err = nand_spl_load_image(
122 CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
124 (void *)spl_image->load_addr);
128 puts("The Expected Linux image was not "
129 "found. Please check your NAND "
131 puts("Trying to start u-boot now...\n");
135 #ifdef CONFIG_NAND_ENV_DST
136 spl_nand_load_element(spl_image, CONFIG_ENV_OFFSET, header);
137 #ifdef CONFIG_ENV_OFFSET_REDUND
138 spl_nand_load_element(spl_image, CONFIG_ENV_OFFSET_REDUND, header);
142 err = spl_nand_load_element(spl_image, CONFIG_SYS_NAND_U_BOOT_OFFS,
144 #ifdef CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
145 #if CONFIG_SYS_NAND_U_BOOT_OFFS != CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
147 err = spl_nand_load_element(spl_image,
148 CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND,
156 /* Use priorty 1 so that Ubi can override this */
157 SPL_LOAD_IMAGE_METHOD("NAND", 1, BOOT_DEVICE_NAND, spl_nand_load_image);