[RFC][PATCH 2/3] fdtdec: Introduce fdtdec_setup_mem_ram_top() to determine end of topmost DRAM bank

Ilias Apalodimas ilias.apalodimas at linaro.org
Thu Mar 26 10:37:01 CET 2026


Hi Marek

[...]

> + * 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;

We can also update gd->ram_size.

I'll send a v2 with some changes in board_f.c using this code, so I'll
update it there

Reviewed-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>


> +}
> +
> +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