[PATCH v2 3/4] fdtdec: Introduce fdtdec_setup_ram_size() to determine the memory size

Marek Vasut marek.vasut at mailbox.org
Wed Apr 1 17:40:47 CEST 2026


On 4/1/26 5:29 PM, Ilias Apalodimas wrote:
> Hi Marek,
> 
> On Wed, 1 Apr 2026 at 18:24, Marek Vasut <marek.vasut at mailbox.org> wrote:
>>
>> On 4/1/26 8:43 AM, Ilias Apalodimas wrote:
>>
>>>>> +++ b/include/fdtdec.h
>>>>> @@ -965,6 +965,21 @@ int fdtdec_setup_mem_ram_top(void);
>>>>>      * invalid
>>>>>      */
>>>>>     int fdtdec_setup_memory_banksize(void);
>>>>> +/**
>>>>> + * fdtdec_setup_ram_size() - decode and setup setup gd->ram_size to the sum of
>>>>> + *                        all banks
>>>>> + *
>>>>> + * Decode the /memory 'reg' property to determine the memory available in all
>>>>> + * banks and populate the global data ram_size with it.
>>>>> + *
>>>>> + * This function should be called from a boards board_get_usable_ram_top().
>>>>
>>>> Is the board_get_usable_ram_top() really the right place to call this ?
>>>> It feels like it is being conflated with ram_top here too.
>>>
>>> I don't think so. You are effectively calculating the top address you
>>> should relocate to. You should also calculate the difference in
>>> ramsize. Those two should not be separated actions
>> The address where you relocate to is gd->relocaddr, which is ram_top
>> minus all the reserved areas, see common/board_f.c setup_dest_addr().
>>
>> This setup_dest_addr() function does manipulate with gd->ram_size , but
>> only to handle CONFIG_SYS_MEM_TOP_HIDE , which may not be the right
>> place for it, I think it would be better to have a separate initcall for
>> the ram_size calculation, which precedes setup_dest_addr().
> 
> Yes, but when you calculate the reloc address and use a bigger
> ram_top, the right thing to do is adjust the size as well

That is the root of my concern, ram_top and ram_size are always the 
same, relocaddr is not.

>> With that, the function description can claim that each function must be
>> called before that specific initcall, fdtdec_setup_mem_ram_top() before
>> setup_dest_addr() and fdtdec_setup_ram_size() before
>> setup_whatever_is_the_new_initcall_name().
> 
> I really don't mind. I just don't see the point of making things so
> granular. Unless I am wrong and someone thinks it makes sense to
> change ram_top without taking into account the size.
Maybe it would make sense to decouple relocaddr from ram_top/ram_size 
calculation ?


More information about the U-Boot mailing list