spl: Drop bd_info in the data section

This uses up space in the SPL binary but it always starts as zero. Also
some boards cannot support data in TPL (e.g. Intel Apollo Lake).

Use malloc() to allocate this structure instead, by moving the init a
little later, after malloc() is inited. Make this function optional since
it pulls in malloc().

This reduces the TPL binary size on coral by about 64 bytes

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 63c48fb..835c53d 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -53,9 +53,6 @@
 binman_sym_declare(ulong, spl, size);
 #endif
 
-/* Define board data structure */
-static struct bd_info bdata __attribute__ ((section(".data")));
-
 /*
  * Board-specific Platform code can reimplement show_boot_progress () if needed
  */
@@ -443,14 +440,19 @@
 	return 0;
 }
 
-void spl_set_bd(void)
+int spl_alloc_bd(void)
 {
 	/*
 	 * NOTE: On some platforms (e.g. x86) bdata may be in flash and not
 	 * writeable.
 	 */
-	if (!gd->bd)
-		gd->bd = &bdata;
+	if (!gd->bd) {
+		gd->bd = malloc(sizeof(*gd->bd));
+		if (!gd->bd)
+			return -ENOMEM;
+	}
+
+	return 0;
 }
 
 int spl_early_init(void)
@@ -600,8 +602,6 @@
 
 	debug(">>" SPL_TPL_PROMPT "board_init_r()\n");
 
-	spl_set_bd();
-
 #if defined(CONFIG_SYS_SPL_MALLOC_START)
 	mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
 			CONFIG_SYS_SPL_MALLOC_SIZE);
@@ -611,6 +611,10 @@
 		if (spl_init())
 			hang();
 	}
+	if (IS_ENABLED(CONFIG_SPL_ALLOC_BD) && spl_alloc_bd()) {
+		puts("Cannot alloc bd\n");
+		hang();
+	}
 #if !defined(CONFIG_PPC) && !defined(CONFIG_ARCH_MX6)
 	/*
 	 * timer_init() does not exist on PPC systems. The timer is initialized