[U-Boot] [PATCH] fdt: Try to read #address-cells/size-cells from parent

Simon Glass sjg at chromium.org
Tue Feb 16 17:00:22 CET 2016


Hi Michal,

On 15 February 2016 at 02:58, Michal Simek <michal.simek at xilinx.com> wrote:
> Hi Simon,
>
> On 10.2.2016 13:04, Michal Simek wrote:
>> Read #address-cells and #size-cells from parent if they are not present in
>> current node.
>>
>> Signed-off-by: Michal Simek <michal.simek at xilinx.com>
>> ---
>>
>> I have code which read information about memory for zynqmp but memory
>> node most of the time doesn't contain #address/size-cells which are
>> present in parent node.
>> That's why let's try to read it from parent.
>>
>> Also I think that we shouldn't return 2 if property is not found because
>> it has side effect on 32bit systems with #address/size-cells = <1>;
>>
>> ---
>>  lib/libfdt/fdt_addresses.c | 18 ++++++++++++++----
>>  1 file changed, 14 insertions(+), 4 deletions(-)
>>
>> diff --git a/lib/libfdt/fdt_addresses.c b/lib/libfdt/fdt_addresses.c
>> index 76054d98e5fd..b164d0988079 100644
>> --- a/lib/libfdt/fdt_addresses.c
>> +++ b/lib/libfdt/fdt_addresses.c
>> @@ -19,10 +19,15 @@ int fdt_address_cells(const void *fdt, int nodeoffset)
>>       const fdt32_t *ac;
>>       int val;
>>       int len;
>> +     int parent;
>>
>>       ac = fdt_getprop(fdt, nodeoffset, "#address-cells", &len);
>> -     if (!ac)
>> -             return 2;
>> +     if (!ac) {
>> +             parent = fdt_parent_offset(fdt, nodeoffset);
>> +             ac = fdt_getprop(fdt, parent, "#address-cells", &len);
>> +             if (!ac)
>> +                     return 2;
>> +     }
>>
>>       if (len != sizeof(*ac))
>>               return -FDT_ERR_BADNCELLS;
>> @@ -39,10 +44,15 @@ int fdt_size_cells(const void *fdt, int nodeoffset)
>>       const fdt32_t *sc;
>>       int val;
>>       int len;
>> +     int parent;
>>
>>       sc = fdt_getprop(fdt, nodeoffset, "#size-cells", &len);
>> -     if (!sc)
>> -             return 2;
>> +     if (!sc) {
>> +             parent = fdt_parent_offset(fdt, nodeoffset);
>> +             sc = fdt_getprop(fdt, parent, "#size-cells", &len);
>> +             if (!sc)
>> +                     return 2;
>> +     }
>>
>>       if (len != sizeof(*sc))
>>               return -FDT_ERR_BADNCELLS;
>>
>
> Simon: Any comment?

It seems risky to change the behaviour here. Also fdt_parent_offset() is slow.

Can you point me to the binding / example DT that you are trying to parse?

Regards,
Simon


More information about the U-Boot mailing list