]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/spl/spl.c
spl: Correct address in spl_relocate_stack_gd()
[karo-tx-uboot.git] / common / spl / spl.c
index 1826c47a99c464bd0023f3c173cab788de49acb0..8f11328ad36f1885b99293b1bf86198b211a92d2 100644 (file)
@@ -101,10 +101,22 @@ void spl_parse_image_header(const struct image_header *header)
                        (int)sizeof(spl_image.name), spl_image.name,
                        spl_image.load_addr, spl_image.size);
        } else {
+#ifdef CONFIG_SPL_PANIC_ON_RAW_IMAGE
+               /*
+                * CONFIG_SPL_PANIC_ON_RAW_IMAGE is defined when the
+                * code which loads images in SPL cannot guarantee that
+                * absolutely all read errors will be reported.
+                * An example is the LPC32XX MLC NAND driver, which
+                * will consider that a completely unreadable NAND block
+                * is bad, and thus should be skipped silently.
+                */
+               panic("** no mkimage signature but raw image not supported");
+#else
                /* Signature not found - assume u-boot.bin */
                debug("mkimage signature not found - ih_magic = %x\n",
                        header->ih_magic);
                spl_set_header_raw_uboot();
+#endif
        }
 }
 
@@ -113,7 +125,7 @@ __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
        typedef void __noreturn (*image_entry_noargs_t)(void);
 
        image_entry_noargs_t image_entry =
-                       (image_entry_noargs_t) spl_image->entry_point;
+               (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
 
        debug("image entry point: 0x%X\n", spl_image->entry_point);
        image_entry();
@@ -139,6 +151,8 @@ static void spl_ram_load_image(void)
 void board_init_r(gd_t *dummy1, ulong dummy2)
 {
        u32 boot_device;
+       int ret;
+
        debug(">>spl:board_init_r()\n");
 
 #if defined(CONFIG_SYS_SPL_MALLOC_START)
@@ -146,12 +160,24 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
                        CONFIG_SYS_SPL_MALLOC_SIZE);
        gd->flags |= GD_FLG_FULL_MALLOC_INIT;
 #elif defined(CONFIG_SYS_MALLOC_F_LEN)
-       gd->malloc_limit = gd->malloc_base + CONFIG_SYS_MALLOC_F_LEN;
+       gd->malloc_limit = CONFIG_SYS_MALLOC_F_LEN;
        gd->malloc_ptr = 0;
 #endif
-#ifdef CONFIG_SPL_DM
-       dm_init_and_scan(true);
-#endif
+       if (IS_ENABLED(CONFIG_OF_CONTROL) &&
+                       !IS_ENABLED(CONFIG_SPL_DISABLE_OF_CONTROL)) {
+               ret = fdtdec_setup();
+               if (ret) {
+                       debug("fdtdec_setup() returned error %d\n", ret);
+                       hang();
+               }
+       }
+       if (IS_ENABLED(CONFIG_SPL_DM)) {
+               ret = dm_init_and_scan(true);
+               if (ret) {
+                       debug("dm_init_and_scan() returned error %d\n", ret);
+                       hang();
+               }
+       }
 
 #ifndef CONFIG_PPC
        /*
@@ -182,8 +208,9 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 #endif
 #ifdef CONFIG_SPL_NAND_SUPPORT
        case BOOT_DEVICE_NAND:
-               spl_nand_load_image();
-               break;
+               if (spl_nand_load_image() == 0)
+                       break;
+               /* fallthru in case of failure to activate ymodem download */
 #endif
 #ifdef CONFIG_SPL_ONENAND_SUPPORT
        case BOOT_DEVICE_ONENAND:
@@ -228,10 +255,15 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
        case BOOT_DEVICE_SATA:
                spl_sata_load_image();
                break;
+#endif
+#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE
+       case BOOT_DEVICE_BOARD:
+               spl_board_load_image();
+               break;
 #endif
        default:
 #if defined(CONFIG_SPL_SERIAL_SUPPORT) && defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
-               printf("SPL: Unsupported Boot Device %d\n", boot_device);
+               puts("SPL: Unsupported Boot Device!\n");
 #endif
                hang();
        }
@@ -276,3 +308,38 @@ void preloader_console_init(void)
        spl_display_print();
 #endif
 }
+
+/**
+ * spl_relocate_stack_gd() - Relocate stack ready for board_init_r() execution
+ *
+ * Sometimes board_init_f() runs with a stack in SRAM but we want to use SDRAM
+ * for the main board_init_r() execution. This is typically because we need
+ * more stack space for things like the MMC sub-system.
+ *
+ * This function calculates the stack position, copies the global_data into
+ * place and returns the new stack position. The caller is responsible for
+ * setting up the sp register.
+ *
+ * @return new stack location, or 0 to use the same stack
+ */
+ulong spl_relocate_stack_gd(void)
+{
+#ifdef CONFIG_SPL_STACK_R
+       gd_t *new_gd;
+       ulong ptr;
+
+       /* Get stack position: use 8-byte alignment for ABI compliance */
+       ptr = CONFIG_SPL_STACK_R_ADDR - sizeof(gd_t);
+       ptr &= ~7;
+       new_gd = (gd_t *)ptr;
+       memcpy(new_gd, (void *)gd, sizeof(gd_t));
+       gd = new_gd;
+
+       /* Clear the BSS. */
+       memset(__bss_start, 0, __bss_end - __bss_start);
+
+       return ptr;
+#else
+       return 0;
+#endif
+}