Add MTK_DRAM_DESC_HANDOFF to stop in SPL if the boot stage that
initializes the DRAM did not pass a transfer list with a devicetree
overlay, and enable it on MT8189.

The overlay describes the DRAM size and the memory reserved for the DRAM
controller, which depend on the DRAM fitted to the board. The devicetree
built into U-Boot cannot describe them, so booting without the overlay
would give the OS a wrong memory size and let it use reserved memory.

The option is not specific to MT8189. The DRAM initialization on MT8366
has the same code to reserve memory for the DRAM controller, so the
Genio 360 can use it as well once support for that is added later.

Signed-off-by: David Lechner <[email protected]>
---
 arch/arm/mach-mediatek/Kconfig | 13 +++++++++++++
 arch/arm/mach-mediatek/spl.c   | 31 +++++++++++++++++++++++++++++++
 configs/mt8189.config          |  1 +
 3 files changed, 45 insertions(+)

diff --git a/arch/arm/mach-mediatek/Kconfig b/arch/arm/mach-mediatek/Kconfig
index 1fde892baa2..42868c9113d 100644
--- a/arch/arm/mach-mediatek/Kconfig
+++ b/arch/arm/mach-mediatek/Kconfig
@@ -278,6 +278,19 @@ config MTK_GENIO_BL31_LOAD_ADDR
 
 endif
 
+config MTK_DRAM_DESC_HANDOFF
+       bool "Require the DRAM description in a transfer list"
+       depends on BLOBLIST
+       depends on SPL_BLOBLIST || !SPL
+       help
+         The DRAM size and the memory reserved for the DRAM controller depend
+         on the DRAM fitted to the board, so the devicetree built into U-Boot
+         cannot describe them. The boot stage that initializes the DRAM
+         describes them instead, with a devicetree overlay in a Firmware
+         Handoff transfer list.
+
+         Make SPL stop if it does not receive such an overlay.
+
 config MTK_TZ_MOVABLE
        select ARCH_MISC_INIT
        select OF_SYSTEM_SETUP
diff --git a/arch/arm/mach-mediatek/spl.c b/arch/arm/mach-mediatek/spl.c
index 125ebcd784f..9150f677b04 100644
--- a/arch/arm/mach-mediatek/spl.c
+++ b/arch/arm/mach-mediatek/spl.c
@@ -4,16 +4,43 @@
  * Author: Ryder Lee <[email protected]>
  */
 
+#include <bloblist.h>
 #include <clk.h>
+#include <errno.h>
 #include <hang.h>
 #include <init.h>
 #include <spl.h>
+#include <stdio.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 __weak int mtk_soc_early_init(void)
 {
        return 0;
 }
 
+/*
+ * The boot stage that initializes the DRAM describes the DRAM size and the
+ * memory reserved for the DRAM controller with a devicetree overlay in a
+ * transfer list. The devicetree cannot describe them, so do not boot without
+ * the overlay.
+ */
+static int mtk_dram_desc_check(void)
+{
+       if (!IS_ENABLED(CONFIG_MTK_DRAM_DESC_HANDOFF) ||
+           !CONFIG_IS_ENABLED(BLOBLIST))
+               return 0;
+
+       if (!(gd->flags & GD_FLG_BLOBLIST_HANDOFF) ||
+           !bloblist_find(BLOBLISTT_FDT_OVERLAY, 0)) {
+               printf("No DRAM description from the previous boot stage\n");
+               return -ENOENT;
+       }
+
+       return 0;
+}
+
 void board_init_f(ulong dummy)
 {
        int ret;
@@ -29,6 +56,10 @@ void board_init_f(ulong dummy)
        ret = mtk_soc_early_init();
        if (ret)
                hang();
+
+       ret = mtk_dram_desc_check();
+       if (ret)
+               hang();
 }
 
 u32 spl_boot_device(void)
diff --git a/configs/mt8189.config b/configs/mt8189.config
index efa95a2fe03..356673af059 100644
--- a/configs/mt8189.config
+++ b/configs/mt8189.config
@@ -8,6 +8,7 @@ CONFIG_DM_GPIO=y
 CONFIG_OF_LIBFDT_OVERLAY=y
 CONFIG_TARGET_MT8189=y
 CONFIG_MTK_MEM_MAP_DDR_SIZE=0x200000000
+CONFIG_MTK_DRAM_DESC_HANDOFF=y
 CONFIG_SYS_LOAD_ADDR=0x4c000000
 CONFIG_FIT=y
 CONFIG_BOOTSTD_FULL=y

-- 
2.53.0

Reply via email to