[U-Boot] [PATCH] fdt: Fix alignment issue when reading 64-bits properties

Jean-Jacques Hiblot jjhiblot at ti.com
Tue Oct 22 07:56:54 UTC 2019


Hi Simon,

On 22/10/2019 01:46, Simon Glass wrote:
> Hi Jean-Jacques,
>
> On Mon, 21 Oct 2019 at 06:50, Jean-Jacques Hiblot <jjhiblot at ti.com> wrote:
>> The FDT specification [0] gives a requirement of aligning properties on
>> 32-bits. Make sure that the compiler is aware of this constraint when
>> accessing 64-bits properties.
>>
>> [0]: https://github.com/devicetree-org/devicetree-specification/blob/master/source/flattened-format.rst
>>
>> Signed-off-by: Jean-Jacques Hiblot <jjhiblot at ti.com>
>> ---
>>   common/fdt_support.c  | 2 +-
>>   drivers/core/ofnode.c | 2 +-
>>   lib/fdtdec.c          | 2 +-
>>   3 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/common/fdt_support.c b/common/fdt_support.c
>> index baf7924ff6..d14cf7f61a 100644
>> --- a/common/fdt_support.c
>> +++ b/common/fdt_support.c
>> @@ -1566,7 +1566,7 @@ static int fdt_read_prop(const fdt32_t *prop, int prop_len, int cell_off,
>>                           uint64_t *val, int cells)
>>   {
>>          const fdt32_t *prop32 = &prop[cell_off];
>> -       const fdt64_t *prop64 = (const fdt64_t *)&prop[cell_off];
>> +       const fdt64_t *prop64 __aligned(4) = (const fdt64_t *)&prop[cell_off];
> Excuse my ignorance, but what does this actually mean? That the
> pointer points to something that is aligned?

Well it should have made the compiler assume that the address is aligned 
on 32-bits not 64-bits. But I see now that it doesn't. As I didn't see 
the issue anymore iI thought it worked, but it just was my DTB not 
exposing the issue anymore.

Anyway I'll send a v2 with the effective changes.

Thanks.

JJ

> Regards,
> Simon
>


More information about the U-Boot mailing list