Merge branch '2019-08-11-ti-imports'
[oweals/u-boot.git] / common / spl / spl.c
index 88d4b8a9bf15b70e990758cd33ea5b984ef93f11..2c696f2a79c9304c6eaa8f1a2279836148efa3b1 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/compiler.h>
 #include <fdt_support.h>
 #include <bootcount.h>
+#include <wdt.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -194,10 +195,12 @@ static int spl_load_fit_image(struct spl_image_info *spl_image,
 #ifdef CONFIG_SPL_FIT_SIGNATURE
        images.verify = 1;
 #endif
-       fit_image_load(&images, (ulong)header,
+       ret = fit_image_load(&images, (ulong)header,
                       &fit_uname_fdt, &fit_uname_config,
                       IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1,
                       FIT_LOAD_OPTIONAL, &dt_data, &dt_len);
+       if (ret >= 0)
+               spl_image->fdt_addr = (void *)dt_data;
 
        conf_noffset = fit_conf_get_node((const void *)header,
                                         fit_uname_config);
@@ -532,7 +535,7 @@ static int spl_load_image(struct spl_image_info *spl_image,
 }
 
 /**
- * boot_from_devices() - Try loading an booting U-Boot from a list of devices
+ * boot_from_devices() - Try loading a booting U-Boot from a list of devices
  *
  * @spl_image: Place to put the image details if successful
  * @spl_boot_list: List of boot devices to try
@@ -600,6 +603,10 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
        spl_board_init();
 #endif
 
+#if defined(CONFIG_SPL_WATCHDOG_SUPPORT) && CONFIG_IS_ENABLED(WDT)
+       initr_watchdog();
+#endif
+
        if (IS_ENABLED(CONFIG_SPL_OS_BOOT) || CONFIG_IS_ENABLED(HANDOFF))
                dram_init_banksize();
 
@@ -702,6 +709,28 @@ void preloader_console_init(void)
 }
 #endif
 
+/**
+ * This function is called before the stack is changed from initial stack to
+ * relocated stack. It tries to dump the stack size used
+ */
+__weak void spl_relocate_stack_check(void)
+{
+#if CONFIG_IS_ENABLED(SYS_REPORT_STACK_F_USAGE)
+       ulong init_sp = gd->start_addr_sp;
+       ulong stack_bottom = init_sp - CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK);
+       u8 *ptr = (u8 *)stack_bottom;
+       ulong i;
+
+       for (i = 0; i < CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK); i++) {
+               if (*ptr != CONFIG_VAL(SYS_STACK_F_CHECK_BYTE))
+                       break;
+               ptr++;
+       }
+       printf("SPL initial stack usage: %lu bytes\n",
+              CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK) - i);
+#endif
+}
+
 /**
  * spl_relocate_stack_gd() - Relocate stack ready for board_init_r() execution
  *
@@ -726,6 +755,9 @@ ulong spl_relocate_stack_gd(void)
        gd_t *new_gd;
        ulong ptr = CONFIG_SPL_STACK_R_ADDR;
 
+       if (CONFIG_IS_ENABLED(SYS_REPORT_STACK_F_USAGE))
+               spl_relocate_stack_check();
+
 #if defined(CONFIG_SPL_SYS_MALLOC_SIMPLE) && CONFIG_VAL(SYS_MALLOC_F_LEN)
        if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN) {
                debug("SPL malloc() before relocation used 0x%lx bytes (%ld KB)\n",