[RFC][PATCH 2/3] fdtdec: Introduce fdtdec_setup_mem_ram_top() to determine end of topmost DRAM bank
Marek Vasut
marek.vasut+renesas at mailbox.org
Wed Mar 25 04:17:05 CET 2026
Introduce function fdtdec_setup_mem_ram_top(), which determines the topmost
address in the last DRAM bank, to be assigned into gd->ram_top in order to
relocate U-Boot to the actual end of all DRAM. This makes use of iterator
function fdtdec_setup_mem_for_each_bank() introduced in previous commit.
Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
---
Cc: Casey Connolly <casey.connolly at linaro.org>
Cc: Ilias Apalodimas <ilias.apalodimas at linaro.org>
Cc: Nobuhiro Iwamatsu <iwamatsu at nigauri.org>
Cc: Raymond Mao <raymondmaoca at gmail.com>
Cc: Simon Glass <sjg at chromium.org>
Cc: Tom Rini <trini at konsulko.com>
Cc: u-boot at lists.denx.de
---
include/fdtdec.h | 16 ++++++++++++++++
lib/fdtdec.c | 18 ++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/include/fdtdec.h b/include/fdtdec.h
index d9fcd037ed2..26e40c3cdb4 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -933,6 +933,22 @@ int fdtdec_setup_mem_size_base(void);
*/
int fdtdec_setup_mem_size_base_lowest(void);
+/**
+ * fdtdec_setup_mem_ram_top() - decode and setup gd->ram_top to highest address
+ * available in any memory bank
+ *
+ * Decode the /memory 'reg' property to determine the highest end of the memory
+ * bank and populate the global data ram_top with it.
+ *
+ * This function should be called from a boards board_get_usable_ram_top().
+ * This helper function allows for boards to query the device tree for topmost
+ * DRAM address.
+ *
+ * Return: 0 if OK, -EINVAL if the /memory node or reg property is missing or
+ * invalid
+ */
+int fdtdec_setup_mem_ram_top(void);
+
/**
* fdtdec_setup_memory_banksize() - decode and populate gd->bd->bi_dram
*
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index d820f75b031..bdb26d8fb75 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1162,6 +1162,24 @@ int fdtdec_setup_mem_size_base_lowest(void)
return fdtdec_setup_mem_for_each_bank(fdtdec_setup_mem_size_base_lowest_bankfn);
}
+static void fdtdec_setup_mem_ram_top_bankfn(struct resource *res, int bank)
+{
+ if ((res->end + 1) > gd->ram_top)
+ gd->ram_top = res->end + 1;
+}
+
+int fdtdec_setup_mem_ram_top(void)
+{
+ phys_addr_t old_top = gd->ram_top;
+ int ret;
+
+ ret = fdtdec_setup_mem_for_each_bank(fdtdec_setup_mem_ram_top_bankfn);
+ if (ret)
+ gd->ram_top = old_top;
+
+ return ret;
+}
+
static int uncompress_blob(const void *src, ulong sz_src, void **dstp)
{
#if CONFIG_IS_ENABLED(MULTI_DTB_FIT_GZIP) ||\
--
2.53.0
More information about the U-Boot
mailing list