Device tree flattening code not copying properties from blob

Grant Likely grant.likely at secretlab.ca
Thu Jun 13 02:02:40 EST 2013


On Wed, Jun 12, 2013 at 3:32 PM, Collins, Rod
<Rod.Collins at saabsensis.com> wrote:
>
> I have been chasing a problem where a module device driver that uses the device tree I install, cannot find a compatible match when I know the device tree has the match for my driver.
>
> So I wrote a small module device driver that dumps the device tree information. I add it to the device driver list using insmod dtdump.ko. If I add the insmod to the start of the rc (using uCLinux distribution) file then I get the proper contents. If I add insmod at the end of the rc file then the device tree is bad.
>
> The problem is in the file fdt.c and the function unflatten_dt_node.
>
> When the unflattened tree is created the memory is allocated for the nodes and the property structures, however the pointers are just inserted into the property structure. The pointers are pointing in the memory area freed after initialization. This will work if the embedded __init memory is not freed but freeing this memory ends up with tree nodes that have invalid properties and thus the device tree is no good.

If your fdt blob is getting freed, then you've got a bug. How are you
loading the device tree? Normally the device tree is passed in from
the bootloader and the kernel marks the whole region as reserved.

> I am working on a fix to the unflatten_dt_node function. Allocate space for the property name and value and copy them in also as the node name is done.

unflatten_dt_node is actually doing the right thing. If the dt blob is
in an __init section, then it needs to be copied into non-init memory
before unflattening.

g.


More information about the devicetree-discuss mailing list