]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
memory: reserve from start_addr_sp to initial_relocaddr
authorRandolph Sapp <rs@ti.com>
Thu, 4 Jun 2026 15:50:38 +0000 (10:50 -0500)
committerTom Rini <trini@konsulko.com>
Mon, 15 Jun 2026 17:04:39 +0000 (11:04 -0600)
Add a new global data struct member called initial_relocaddr. This
stores the original value of relocaddr, directly from setup_dest_addr.
This is specifically to avoid any adjustments made by other init
functions.

Reserve the memory from gd->start_addr_sp - CONFIG_STACK_SIZE to
gd->initial_relocaddr instead of gd->ram_top. This allows platform
specific relocation addresses to work without unnecessarily painting
over a large range.

Signed-off-by: Randolph Sapp <rs@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
common/board_f.c
include/asm-generic/global_data.h
lib/efi_loader/efi_memory.c
lib/lmb.c

index ce87c619e680f848943e405be421f84c3185aa8c..aeb53b4c274e77efff65d2b180f31ff72a7164ae 100644 (file)
@@ -330,6 +330,8 @@ __weak int arch_setup_dest_addr(void)
 
 static int setup_dest_addr(void)
 {
+       int ret;
+
        debug("Monitor len: %08x\n", gd->mon_len);
        /*
         * Ram is setup, size stored in gd !!
@@ -356,7 +358,12 @@ static int setup_dest_addr(void)
        gd->relocaddr = gd->ram_top;
        debug("Ram top: %08llX\n", (unsigned long long)gd->ram_top);
 
-       return arch_setup_dest_addr();
+       ret = arch_setup_dest_addr();
+       if (ret)
+               return ret;
+
+       gd->initial_relocaddr = gd->relocaddr;
+       return 0;
 }
 
 #ifdef CFG_PRAM
index 745d2c3a96634feff2f079701de5c100b9282e71..8d1d49b1133d0de1d9fde3255a1d51b2c04fda27 100644 (file)
@@ -107,6 +107,15 @@ struct global_data {
         * GDB using the 'add-symbol-file u-boot <relocaddr>' command.
         */
        unsigned long relocaddr;
+       /**
+        * @initial_relocaddr: top address of U-Boot in RAM
+        *
+        * This should be the value of relocaddr after setup_dest_addr() and
+        * before reserve_pram() or any other allocations or reservations shift
+        * it. This address will, depending on the platform, be equivalent to
+        * ram_top and should also be considered an exclusive address.
+        */
+       unsigned long initial_relocaddr;
        /**
         * @irq_sp: IRQ stack pointer
         */
index 2feb29f0a2c335dbf2da12c2e4d920ceff42720a..c3da7c20cb2048e3ddfe06e244e10edd34e2d81d 100644 (file)
@@ -871,7 +871,7 @@ static void add_u_boot_and_runtime(void)
        /* Add U-Boot */
        uboot_start = ((uintptr_t)map_sysmem(gd->start_addr_sp, 0) -
                       uboot_stack_size) & ~EFI_PAGE_MASK;
-       uboot_pages = ((uintptr_t)map_sysmem(gd->ram_top - 1, 0) -
+       uboot_pages = ((uintptr_t)map_sysmem(gd->initial_relocaddr - 1, 0) -
                       uboot_start + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
        efi_update_memory_map(uboot_start, uboot_pages, EFI_BOOT_SERVICES_CODE,
                              false, false);
index 8f12c6ad8e595c39ab061fb27a4c4f2f55f23198..27c8565e590fb882f18c64a053fe8e360541833e 100644 (file)
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -540,13 +540,14 @@ static void lmb_reserve_uboot_region(void)
        ulong pram = 0;
 
        rsv_start = gd->start_addr_sp - CONFIG_STACK_SIZE;
-       end = gd->ram_top;
+       end = gd->initial_relocaddr;
 
        /*
         * Reserve memory from aligned address below the bottom of U-Boot stack
-        * until end of RAM area to prevent LMB from overwriting that memory.
+        * until the original relocation address to prevent LMB from
+        * overwriting that memory.
         */
-       debug("## Current stack ends at 0x%08lx ", (ulong)rsv_start);
+       debug("## Current stack ends at 0x%08lx\n", (ulong)rsv_start);
 
 #ifdef CFG_PRAM
        pram = env_get_ulong("pram", 10, CFG_PRAM);