ARM: zynq: Do not select options if SPL is not enabled
[oweals/u-boot.git] / common / spl / spl.c
index 7913c527fdda098b5ad4fd63dab4efcdc0d4cf71..e5167bf73e4c3181ef7c74b7736431e0df121668 100644 (file)
@@ -195,6 +195,84 @@ __weak void board_boot_order(u32 *spl_boot_list)
        spl_boot_list[0] = spl_boot_device();
 }
 
+#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE
+__weak void spl_board_announce_boot_device(void) { }
+#endif
+
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
+struct boot_device_name {
+       u32 boot_dev;
+       const char *name;
+};
+
+struct boot_device_name boot_name_table[] = {
+#ifdef CONFIG_SPL_RAM_DEVICE
+       { BOOT_DEVICE_RAM, "RAM" },
+#endif
+#ifdef CONFIG_SPL_MMC_SUPPORT
+       { BOOT_DEVICE_MMC1, "MMC" },
+       { BOOT_DEVICE_MMC2, "MMC" },
+       { BOOT_DEVICE_MMC2_2, "MMC" },
+#endif
+#ifdef CONFIG_SPL_NAND_SUPPORT
+       { BOOT_DEVICE_NAND, "NAND" },
+#endif
+#ifdef CONFIG_SPL_ONENAND_SUPPORT
+       { BOOT_DEVICE_ONENAND, "OneNAND" },
+#endif
+#ifdef CONFIG_SPL_NOR_SUPPORT
+       { BOOT_DEVICE_NOR, "NOR" },
+#endif
+#ifdef CONFIG_SPL_YMODEM_SUPPORT
+       { BOOT_DEVICE_UART, "UART" },
+#endif
+#ifdef CONFIG_SPL_SPI_SUPPORT
+       { BOOT_DEVICE_SPI, "SPI" },
+#endif
+#ifdef CONFIG_SPL_ETH_SUPPORT
+#ifdef CONFIG_SPL_ETH_DEVICE
+       { BOOT_DEVICE_CPGMAC, "eth device" },
+#else
+       { BOOT_DEVICE_CPGMAC, "net" },
+#endif
+#endif
+#ifdef CONFIG_SPL_USBETH_SUPPORT
+       { BOOT_DEVICE_USBETH, "USB eth" },
+#endif
+#ifdef CONFIG_SPL_USB_SUPPORT
+       { BOOT_DEVICE_USB, "USB" },
+#endif
+#ifdef CONFIG_SPL_SATA_SUPPORT
+       { BOOT_DEVICE_SATA, "SATA" },
+#endif
+       /* Keep this entry last */
+       { BOOT_DEVICE_NONE, "unknown boot device" },
+};
+
+static void announce_boot_device(u32 boot_device)
+{
+       int i;
+
+       puts("Trying to boot from ");
+
+#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE
+       if (boot_device == BOOT_DEVICE_BOARD) {
+               spl_board_announce_boot_device();
+               puts("\n");
+               return;
+       }
+#endif
+       for (i = 0; i < ARRAY_SIZE(boot_name_table) - 1; i++) {
+               if (boot_name_table[i].boot_dev == boot_device)
+                       break;
+       }
+
+       printf("%s\n", boot_name_table[i].name);
+}
+#else
+static inline void announce_boot_device(u32 boot_device) { }
+#endif
+
 static int spl_load_image(u32 boot_device)
 {
        switch (boot_device) {
@@ -206,7 +284,7 @@ static int spl_load_image(u32 boot_device)
        case BOOT_DEVICE_MMC1:
        case BOOT_DEVICE_MMC2:
        case BOOT_DEVICE_MMC2_2:
-               return spl_mmc_load_image();
+               return spl_mmc_load_image(boot_device);
 #endif
 #ifdef CONFIG_SPL_NAND_SUPPORT
        case BOOT_DEVICE_NAND:
@@ -292,6 +370,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
        board_boot_order(spl_boot_list);
        for (i = 0; i < ARRAY_SIZE(spl_boot_list) &&
                        spl_boot_list[i] != BOOT_DEVICE_NONE; i++) {
+               announce_boot_device(spl_boot_list[i]);
                if (!spl_load_image(spl_boot_list[i]))
                        break;
        }
@@ -352,8 +431,13 @@ void preloader_console_init(void)
  * 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.
+ * place, sets the new gd (except for ARM, for which setting GD within a C
+ * function may not always work) and returns the new stack position. The
+ * caller is responsible for setting up the sp register and, in the case
+ * of ARM, setting up gd.
+ *
+ * All of this is done using the same layout and alignments as done in
+ * board_init_f_init_reserve() / board_init_f_alloc_reserve().
  *
  * @return new stack location, or 0 to use the same stack
  */
@@ -361,19 +445,12 @@ 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;
+       ulong ptr = CONFIG_SPL_STACK_R_ADDR;
 
 #ifdef CONFIG_SPL_SYS_MALLOC_SIMPLE
        if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN) {
                if (!(gd->flags & GD_FLG_SPL_INIT))
-                       panic("spl_init must be called before heap reloc");
+                       panic_str("spl_init must be called before heap reloc");
 
                ptr -= CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN;
                gd->malloc_base = ptr;
@@ -381,7 +458,13 @@ ulong spl_relocate_stack_gd(void)
                gd->malloc_ptr = 0;
        }
 #endif
-
+       /* Get stack position: use 8-byte alignment for ABI compliance */
+       ptr = CONFIG_SPL_STACK_R_ADDR - roundup(sizeof(gd_t),16);
+       new_gd = (gd_t *)ptr;
+       memcpy(new_gd, (void *)gd, sizeof(gd_t));
+#if !defined(CONFIG_ARM)
+       gd = new_gd;
+#endif
        return ptr;
 #else
        return 0;