1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
10 static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
11 ulong count, void *buf)
13 debug("%s: sector %lx, count %lx, buf %p\n",
14 __func__, sector, count, buf);
15 memcpy(buf, (void *)sector, count);
20 unsigned long __weak spl_nor_get_uboot_base(void)
22 return CONFIG_SYS_UBOOT_BASE;
25 static int spl_nor_load_image(struct spl_image_info *spl_image,
26 struct spl_boot_device *bootdev)
28 __maybe_unused const struct image_header *header;
29 __maybe_unused struct spl_load_info load;
32 * Loading of the payload to SDRAM is done with skipping of
33 * the mkimage header in this SPL NOR driver
35 spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
37 #ifdef CONFIG_SPL_OS_BOOT
38 if (!spl_start_uboot()) {
40 * Load Linux from its location in NOR flash to its defined
43 header = (const struct image_header *)CONFIG_SYS_OS_BASE;
44 #ifdef CONFIG_SPL_LOAD_FIT
45 if (image_get_magic(header) == FDT_MAGIC) {
50 load.read = spl_nor_load_read;
52 ret = spl_load_simple_fit(spl_image, &load,
56 #if defined CONFIG_SYS_SPL_ARGS_ADDR && defined CONFIG_CMD_SPL_NOR_OFS
57 memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR,
58 (void *)CONFIG_CMD_SPL_NOR_OFS,
59 CONFIG_CMD_SPL_WRITE_SIZE);
64 if (image_get_os(header) == IH_OS_LINUX) {
65 /* happy - was a Linux */
68 ret = spl_parse_image_header(spl_image, header);
72 memcpy((void *)spl_image->load_addr,
73 (void *)(CONFIG_SYS_OS_BASE +
74 sizeof(struct image_header)),
76 #ifdef CONFIG_SYS_FDT_BASE
77 spl_image->arg = (void *)CONFIG_SYS_FDT_BASE;
82 puts("The Expected Linux image was not found.\n"
83 "Please check your NOR configuration.\n"
84 "Trying to start u-boot now...\n");
90 * Load real U-Boot from its location in NOR flash to its
91 * defined location in SDRAM
93 #ifdef CONFIG_SPL_LOAD_FIT
94 header = (const struct image_header *)spl_nor_get_uboot_base();
95 if (image_get_magic(header) == FDT_MAGIC) {
96 debug("Found FIT format U-Boot\n");
98 load.read = spl_nor_load_read;
99 return spl_load_simple_fit(spl_image, &load,
100 spl_nor_get_uboot_base(),
104 if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
106 load.read = spl_nor_load_read;
107 return spl_load_imx_container(spl_image, &load,
108 spl_nor_get_uboot_base());
111 /* Legacy image handling */
112 if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_SUPPORT)) {
114 load.read = spl_nor_load_read;
115 return spl_load_legacy_img(spl_image, &load,
116 spl_nor_get_uboot_base());
121 SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);