3 * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
5 * SPDX-License-Identifier: GPL-2.0+
12 #include <libfdt_env.h>
15 #if defined(CONFIG_SPL_NAND_RAW_ONLY)
16 int spl_nand_load_image(struct spl_image_info
*spl_image
,
17 struct spl_boot_device
*bootdev
)
21 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS
,
22 CONFIG_SYS_NAND_U_BOOT_SIZE
,
23 (void *)CONFIG_SYS_NAND_U_BOOT_DST
);
24 spl_set_header_raw_uboot(spl_image
);
31 static ulong
spl_nand_fit_read(struct spl_load_info
*load
, ulong offs
,
32 ulong size
, void *dst
)
36 ret
= nand_spl_load_image(offs
, size
, dst
);
43 static int spl_nand_load_element(struct spl_image_info
*spl_image
,
44 int offset
, struct image_header
*header
)
48 err
= nand_spl_load_image(offset
, sizeof(*header
), (void *)header
);
52 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT
) &&
53 image_get_magic(header
) == FDT_MAGIC
) {
54 struct spl_load_info load
;
61 load
.read
= spl_nand_fit_read
;
62 return spl_load_simple_fit(spl_image
, &load
, offset
, header
);
64 err
= spl_parse_image_header(spl_image
, header
);
67 return nand_spl_load_image(offset
, spl_image
->size
,
68 (void *)(ulong
)spl_image
->load_addr
);
72 static int spl_nand_load_image(struct spl_image_info
*spl_image
,
73 struct spl_boot_device
*bootdev
)
76 struct image_header
*header
;
77 int *src
__attribute__((unused
));
78 int *dst
__attribute__((unused
));
80 #ifdef CONFIG_SPL_NAND_SOFTECC
81 debug("spl: nand - using sw ecc\n");
83 debug("spl: nand - using hw ecc\n");
87 /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
88 header
= (struct image_header
*)(CONFIG_SYS_TEXT_BASE
);
89 #ifdef CONFIG_SPL_OS_BOOT
90 if (!spl_start_uboot()) {
92 * load parameter image
93 * load to temp position since nand_spl_load_image reads
94 * a whole block which is typically larger than
95 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
96 * following sections like BSS
98 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS
,
99 CONFIG_CMD_SPL_WRITE_SIZE
,
100 (void *)CONFIG_SYS_TEXT_BASE
);
101 /* copy to destintion */
102 for (dst
= (int *)CONFIG_SYS_SPL_ARGS_ADDR
,
103 src
= (int *)CONFIG_SYS_TEXT_BASE
;
104 src
< (int *)(CONFIG_SYS_TEXT_BASE
+
105 CONFIG_CMD_SPL_WRITE_SIZE
);
107 writel(readl(src
), dst
);
111 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS
,
112 sizeof(*header
), (void *)header
);
113 err
= spl_parse_image_header(spl_image
, header
);
116 if (header
->ih_os
== IH_OS_LINUX
) {
117 /* happy - was a linux */
118 err
= nand_spl_load_image(
119 CONFIG_SYS_NAND_SPL_KERNEL_OFFS
,
121 (void *)spl_image
->load_addr
);
125 puts("The Expected Linux image was not "
126 "found. Please check your NAND "
128 puts("Trying to start u-boot now...\n");
132 #ifdef CONFIG_NAND_ENV_DST
133 spl_nand_load_element(spl_image
, CONFIG_ENV_OFFSET
, header
);
134 #ifdef CONFIG_ENV_OFFSET_REDUND
135 spl_nand_load_element(spl_image
, CONFIG_ENV_OFFSET_REDUND
, header
);
139 err
= spl_nand_load_element(spl_image
, CONFIG_SYS_NAND_U_BOOT_OFFS
,
141 #ifdef CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
142 #if CONFIG_SYS_NAND_U_BOOT_OFFS != CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
144 err
= spl_nand_load_element(spl_image
,
145 CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
,
153 /* Use priorty 1 so that Ubi can override this */
154 SPL_LOAD_IMAGE_METHOD("NAND", 1, BOOT_DEVICE_NAND
, spl_nand_load_image
);