1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
9 #ifdef CONFIG_SPL_LOAD_FIT
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);
21 unsigned long __weak spl_nor_get_uboot_base(void)
23 return CONFIG_SYS_UBOOT_BASE;
26 static int spl_nor_load_image(struct spl_image_info *spl_image,
27 struct spl_boot_device *bootdev)
30 __maybe_unused const struct image_header *header;
31 __maybe_unused struct spl_load_info load;
34 * Loading of the payload to SDRAM is done with skipping of
35 * the mkimage header in this SPL NOR driver
37 spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
39 #ifdef CONFIG_SPL_OS_BOOT
40 if (!spl_start_uboot()) {
42 * Load Linux from its location in NOR flash to its defined
45 header = (const struct image_header *)CONFIG_SYS_OS_BASE;
46 #ifdef CONFIG_SPL_LOAD_FIT
47 if (image_get_magic(header) == FDT_MAGIC) {
50 load.read = spl_nor_load_read;
52 ret = spl_load_simple_fit(spl_image, &load,
59 if (image_get_os(header) == IH_OS_LINUX) {
60 /* happy - was a Linux */
62 ret = spl_parse_image_header(spl_image, header);
66 memcpy((void *)spl_image->load_addr,
67 (void *)(CONFIG_SYS_OS_BASE +
68 sizeof(struct image_header)),
70 #ifdef CONFIG_SYS_FDT_BASE
71 spl_image->arg = (void *)CONFIG_SYS_FDT_BASE;
76 puts("The Expected Linux image was not found.\n"
77 "Please check your NOR configuration.\n"
78 "Trying to start u-boot now...\n");
84 * Load real U-Boot from its location in NOR flash to its
85 * defined location in SDRAM
87 #ifdef CONFIG_SPL_LOAD_FIT
88 header = (const struct image_header *)spl_nor_get_uboot_base();
89 if (image_get_magic(header) == FDT_MAGIC) {
90 debug("Found FIT format U-Boot\n");
92 load.read = spl_nor_load_read;
93 ret = spl_load_simple_fit(spl_image, &load,
94 spl_nor_get_uboot_base(),
100 ret = spl_parse_image_header(spl_image,
101 (const struct image_header *)spl_nor_get_uboot_base());
105 memcpy((void *)(unsigned long)spl_image->load_addr,
106 (void *)(spl_nor_get_uboot_base() + sizeof(struct image_header)),
111 SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);