1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
9 static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
10 ulong count, void *buf)
12 debug("%s: sector %lx, count %lx, buf %p\n",
13 __func__, sector, count, buf);
14 memcpy(buf, (void *)sector, count);
19 unsigned long __weak spl_nor_get_uboot_base(void)
21 return CONFIG_SYS_UBOOT_BASE;
24 static int spl_nor_load_image(struct spl_image_info *spl_image,
25 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) {
48 load.read = spl_nor_load_read;
50 ret = spl_load_simple_fit(spl_image, &load,
57 if (image_get_os(header) == IH_OS_LINUX) {
58 /* happy - was a Linux */
60 ret = spl_parse_image_header(spl_image, header);
64 memcpy((void *)spl_image->load_addr,
65 (void *)(CONFIG_SYS_OS_BASE +
66 sizeof(struct image_header)),
68 #ifdef CONFIG_SYS_FDT_BASE
69 spl_image->arg = (void *)CONFIG_SYS_FDT_BASE;
74 puts("The Expected Linux image was not found.\n"
75 "Please check your NOR configuration.\n"
76 "Trying to start u-boot now...\n");
82 * Load real U-Boot from its location in NOR flash to its
83 * defined location in SDRAM
85 #ifdef CONFIG_SPL_LOAD_FIT
86 header = (const struct image_header *)spl_nor_get_uboot_base();
87 if (image_get_magic(header) == FDT_MAGIC) {
88 debug("Found FIT format U-Boot\n");
90 load.read = spl_nor_load_read;
91 ret = spl_load_simple_fit(spl_image, &load,
92 spl_nor_get_uboot_base(),
98 if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
100 load.read = spl_nor_load_read;
101 return spl_load_imx_container(spl_image, &load,
102 spl_nor_get_uboot_base());
105 ret = spl_parse_image_header(spl_image,
106 (const struct image_header *)spl_nor_get_uboot_base());
110 memcpy((void *)(unsigned long)spl_image->load_addr,
111 (void *)(spl_nor_get_uboot_base() + sizeof(struct image_header)),
116 SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);