Hi Randolph, On Wed, 22 Apr 2026 at 20:10, <[email protected]> wrote: > > From: Randolph Sapp <[email protected]> > > 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. > > Since PRAM comes out of this initial area up to initial_relocaddr, we no > longer need to account for it separately.
Several CI tests are complaining with this series. https://source.denx.de/u-boot/custodians/u-boot-tpm/-/pipelines/29989 Can you have a look? Thanks /Ilias > > Signed-off-by: Randolph Sapp <[email protected]> > --- > common/board_f.c | 9 ++++++- > include/asm-generic/global_data.h | 7 ++++++ > lib/efi_loader/efi_memory.c | 2 +- > lib/lmb.c | 39 +++++-------------------------- > 4 files changed, 22 insertions(+), 35 deletions(-) > > diff --git a/common/board_f.c b/common/board_f.c > index ce87c619e68..31c6eb725fb 100644 > --- a/common/board_f.c > +++ b/common/board_f.c > @@ -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 != 0) > + return ret; > + > + gd->initial_relocaddr = gd->relocaddr; > + return ret; > } > > #ifdef CFG_PRAM > diff --git a/include/asm-generic/global_data.h > b/include/asm-generic/global_data.h > index 745d2c3a966..6c60a79c2ab 100644 > --- a/include/asm-generic/global_data.h > +++ b/include/asm-generic/global_data.h > @@ -107,6 +107,13 @@ struct global_data { > * GDB using the 'add-symbol-file u-boot <relocaddr>' command. > */ > unsigned long relocaddr; > + /** > + * @initial_relocaddr: end of memory currently in use by uboot > + * > + * This should be the original value of relocaddr before any other > + * allocations or reservations shift it. > + */ > + unsigned long initial_relocaddr; > /** > * @irq_sp: IRQ stack pointer > */ > diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c > index 046a2bb4641..ece05c142f0 100644 > --- a/lib/efi_loader/efi_memory.c > +++ b/lib/efi_loader/efi_memory.c > @@ -869,7 +869,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, 0) - > uboot_start + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT; > efi_update_memory_map(uboot_start, uboot_pages, > EFI_BOOT_SERVICES_CODE, > false, false); > diff --git a/lib/lmb.c b/lib/lmb.c > index 9a8c70b778a..e5d4d726ab1 100644 > --- a/lib/lmb.c > +++ b/lib/lmb.c > @@ -534,46 +534,19 @@ static long lmb_reserve(phys_addr_t base, phys_size_t > size, u32 flags) > > static void lmb_reserve_uboot_region(void) > { > - int bank; > - ulong end, bank_end; > + ulong size; > phys_addr_t rsv_start; > - ulong pram = 0; > > rsv_start = gd->start_addr_sp - CONFIG_STACK_SIZE; > - end = gd->ram_top; > + size = gd->initial_relocaddr - rsv_start; > > - /* > - * Reserve memory from aligned address below the bottom of U-Boot > stack > - * until end of RAM area 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); > - pram = pram << 10; /* size is in kB */ > -#endif > - > - for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { > - if (!gd->bd->bi_dram[bank].size || > - rsv_start < gd->bd->bi_dram[bank].start) > - continue; > - /* Watch out for RAM at end of address space! */ > - bank_end = gd->bd->bi_dram[bank].start + > - gd->bd->bi_dram[bank].size - 1; > - if (rsv_start > bank_end) > - continue; > - if (bank_end > end) > - bank_end = end - 1; > + lmb_reserve(rsv_start, size, LMB_NOOVERWRITE); > > - lmb_reserve(rsv_start, bank_end - rsv_start - pram + 1, > + if (gd->flags & GD_FLG_SKIP_RELOC) > + lmb_reserve((phys_addr_t)(uintptr_t)_start, gd->mon_len, > LMB_NOOVERWRITE); > - > - if (gd->flags & GD_FLG_SKIP_RELOC) > - lmb_reserve((phys_addr_t)(uintptr_t)_start, > - gd->mon_len, LMB_NOOVERWRITE); > - > - break; > - } > } > > static void lmb_reserve_common(void *fdt_blob) > -- > 2.53.0 >

