armbian-build/patch/u-boot/u-boot-genio/0027-arch-mediatek-adjust-memory-size-at-runtime.patch
2026-01-08 12:30:24 +01:00

117 lines
3.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Bartosz Bilas <b.bilas@grinn-global.com>
Date: Thu, 2 Oct 2025 12:29:34 +0200
Subject: arch: mediatek: adjust memory size at runtime
Use TFA + libdram to obtain and set the actual memory size.
---
arch/arm/mach-mediatek/mt8188/init.c | 19 ++++++----
arch/arm/mach-mediatek/mt8370/init.c | 19 ++++++----
include/configs/mt8188.h | 3 ++
include/configs/mt8370.h | 3 ++
4 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/arch/arm/mach-mediatek/mt8188/init.c b/arch/arm/mach-mediatek/mt8188/init.c
index 111111111111..222222222222 100644
--- a/arch/arm/mach-mediatek/mt8188/init.c
+++ b/arch/arm/mach-mediatek/mt8188/init.c
@@ -21,11 +21,19 @@ int dram_init(void)
{
int ret;
- ret = fdtdec_setup_memory_banksize();
- if (ret)
- return ret;
+ if (BOOT_ARGUMENT->magic_number == BOOT_ARGUMENT_MAGIC) {
+ gd->ram_base = CONFIG_SYS_SDRAM_BASE;
+ gd->ram_size = BOOT_ARGUMENT->dram_size;
+ debug("Boot argument DRAM size: %lluGB\n", gd->ram_size >> 30);
+ } else {
+ ret = fdtdec_setup_mem_size_base();
+ if (ret)
+ return ret;
+ }
- fdtdec_setup_mem_size_base();
+ mem_map[0].size = gd->ram_size;
+ mem_map[0].phys = gd->ram_base;
+ mem_map[0].virt = gd->ram_base;
/*
* Limit gd->ram_top not exceeding SZ_4G.
@@ -80,9 +88,6 @@ int print_cpuinfo(void)
static struct mm_region mt8188_mem_map[] = {
{
/* DDR */
- .virt = 0x40000000UL,
- .phys = 0x40000000UL,
- .size = 0x200000000UL,
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE,
}, {
.virt = 0x00000000UL,
diff --git a/arch/arm/mach-mediatek/mt8370/init.c b/arch/arm/mach-mediatek/mt8370/init.c
index 111111111111..222222222222 100644
--- a/arch/arm/mach-mediatek/mt8370/init.c
+++ b/arch/arm/mach-mediatek/mt8370/init.c
@@ -21,11 +21,19 @@ int dram_init(void)
{
int ret;
- ret = fdtdec_setup_memory_banksize();
- if (ret)
- return ret;
+ if (BOOT_ARGUMENT->magic_number == BOOT_ARGUMENT_MAGIC) {
+ gd->ram_base = CONFIG_SYS_SDRAM_BASE;
+ gd->ram_size = BOOT_ARGUMENT->dram_size;
+ debug("Boot argument DRAM size: %lluGB\n", gd->ram_size >> 30);
+ } else {
+ ret = fdtdec_setup_mem_size_base();
+ if (ret)
+ return ret;
+ }
- fdtdec_setup_mem_size_base();
+ mem_map[0].size = gd->ram_size;
+ mem_map[0].phys = gd->ram_base;
+ mem_map[0].virt = gd->ram_base;
/*
* Limit gd->ram_top not exceeding SZ_4G.
@@ -75,9 +83,6 @@ int print_cpuinfo(void)
static struct mm_region mt8370_mem_map[] = {
{
/* DDR */
- .virt = 0x40000000UL,
- .phys = 0x40000000UL,
- .size = 0x200000000UL,
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE,
}, {
.virt = 0x00000000UL,
diff --git a/include/configs/mt8188.h b/include/configs/mt8188.h
index 111111111111..222222222222 100644
--- a/include/configs/mt8188.h
+++ b/include/configs/mt8188.h
@@ -122,4 +122,7 @@
#define MTK_SIP_PLAT_BINFO 0xC2000529
#endif
+/* DRAM */
+#define CONFIG_SYS_SDRAM_BASE 0x40000000
+
#endif
diff --git a/include/configs/mt8370.h b/include/configs/mt8370.h
index 111111111111..222222222222 100644
--- a/include/configs/mt8370.h
+++ b/include/configs/mt8370.h
@@ -113,4 +113,7 @@
#define MTK_SIP_PLAT_BINFO 0xC2000529
#endif
+/* DRAM */
+#define CONFIG_SYS_SDRAM_BASE 0x40000000
+
#endif
--
Armbian