[PATCH v2 6/6] common: Add an option to relocate on ram top

Ilias Apalodimas ilias.apalodimas at linaro.org
Thu Apr 23 17:28:56 CEST 2026


Hi Michal


> >   {
> >       debug("Monitor len: %08x\n", gd->mon_len);
> > -#if CONFIG_VAL(SYS_MEM_TOP_HIDE)
> > +
> > +     if (CONFIG_IS_ENABLED(RELOC_ADDR_TOP)) {
> > +             int bank;
> > +             phys_size_t total_size = 0;
> > +
> > +             for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
> > +                     if (gd->ram_top <= gd->bi_dram[bank].start)
> > +                             gd->ram_top = gd->bi_dram[bank].start +
> > +                                             gd->bi_dram[bank].size;
> > +                     total_size += gd->bi_dram[bank].size;
>
> Here you have one problem. If the latest bank is defined with size = 0
> then your code won't ignore it and just use it. I think you should check at
> least that size is not zero.

I don't think this checks belongs here. IIRC the only reason to do
that is have some previous stage bootloader, or earlier u-boot code
update the zero length with a valid region. We already do similar
checks in fdt_fixup_memory_banks(). We should add similar ones to the
dram_init_banksize() variants. Most of the board specific functions
call fdtdec_setup_memory_banksize() anyway, which I plan to fix as
well and get rid of board code that's not needed anymore.

>
> Obviously size needs to be big enough to fit u-boot itself.

Yea that makes sense, I can add a check for this.

>
> And as I said this is one configuration. Versal Gen 2 code has by default
> configuration that it stays in a bank where it runs.
> board/amd/versal2/board.c: dram_init()
>
> Added by commit 3aebac5a759b ("arm64: versal2: Populate DRAM banks before page
> table size calculation")
> Focus on text variable.
>
> That's why I can imagine that above code can be extended by one more
> configuration to stay inside bank where actually u-boot is now.

With having the dram bank in an array we can go an extra step in the
future and have a Kconfig option with an int, representing the array
position of the bank we want to relocate. That should cover what you
ask here?

Thanks
/Ilias
>
> Thanks,
> Michal
>
>
>
>
>
>
> Thanks,
> Michal


More information about the U-Boot mailing list