ipq806x/storm: Return NULL for cbmem_top if DRAM is not initialized

DRAM initialization on storm requires ipq blobs to be
loaded from cbfs. vboot_locator first checks cbmem_find to see if cbmem is
initialized and contains selected region info, else it falls back to
vboot work buffer.

Since cbmem_find calls into cbmem_top to identify the location of
cbmem area, board/chipset is expected to return NULL until the backing
store is ready, which in this case until DRAM is initialized in
romstage, return NULL for cbmem_top.

Change-Id: I1880ce61dcfdabaa527d7a6dcc3482dfe5d5fd17
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/14182
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Tested-by: build bot (Jenkins)
diff --git a/src/soc/qualcomm/ipq806x/cbmem.c b/src/soc/qualcomm/ipq806x/cbmem.c
index 7aff231..9674db6 100644
--- a/src/soc/qualcomm/ipq806x/cbmem.c
+++ b/src/soc/qualcomm/ipq806x/cbmem.c
@@ -16,7 +16,24 @@
 #include <cbmem.h>
 #include <soc/soc_services.h>
 
+static int cbmem_backing_store_ready;
+
+void ipq_cbmem_backing_store_ready(void)
+{
+	cbmem_backing_store_ready = 1;
+}
+
 void *cbmem_top(void)
 {
+	/*
+	 * In romstage, make sure that cbmem backing store is ready before
+	 * returning the pointer to cbmem top. Otherwise, it could lead to
+	 * issues with components that utilize cbmem in romstage
+	 * (e.g. vboot_locator for loading ipq blobs before DRAM is
+	 * initialized).
+	 */
+	if (ENV_ROMSTAGE && (cbmem_backing_store_ready == 0))
+		return NULL;
+
 	return _memlayout_cbmem_top;
 }