LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Custom module to add device tree overlay - kernel 4.14-rc4 (https://www.linuxquestions.org/questions/linux-kernel-70/custom-module-to-add-device-tree-overlay-kernel-4-14-rc4-4175627119/)

Carli-K 04-06-2018 04:36 AM

Custom module to add device tree overlay - kernel 4.14-rc4
 
Hi,

I made a custom module using the kernel API (of_fdt_unflatten_tree + of_resolve_phandles + of_overlay_create ) to dynamically (after my kernel has booted) insert an overlay.

It seems to work just fine, I can see the result in /proc/device-tree, but theses changes are not propagated to /dev or to /sys/devices/plateform. So I can't use what I have added using my overlay.

I first though that the device/plateform driver was not re-probed, but even if I include a line like this one :
Code:

platform_device_register_simple("at91_rtc", -1, NULL, 0);
it does not work :/.

So I was wondering if someone knows a way to dynamically add an overlay and can see the changes. (not only in /proc/device-tree).

PS: I don't use U-Boot, nor configfs, and I don't want to use my overlay through the bootloader.

Best regards,
Carli-K

richo25 05-28-2018 02:17 AM

Hi Carli-K
I'm looking to do the same thing. Don't suppose you got something working?
Have a stub driver that loads a specific dst overlay depending on what it finds.
In this case it is similar to the cape manager I think. Ie go and scan for the presence of some hardware and if found load in an overlay.
I can't find any real examples of how to do this.
There are hints about using request_firmware(), of_fdt_unflatten_tree(), of_resolve_phandles(), of_overlay_create() to load a dtbo but no real full flow descriptions.

Reading the kernel code only gets you sofar..
Not sure of what the effects are.. ie does doing this automatically then go and trigger another probe looking for any matching of compatible entries?

I for example just simply want to define some GPIO's differently depending on the board detected..
Spent a few days trying to come to grips with this, very frustrating.

Richard

Carli-K 05-28-2018 02:54 AM

Hi Richard,

I am sorry, I did not find any solution for this issue. I have asked the devicetree/kernel mailing list but I did not get any answers :/.

But yea the idea is to create a "driver" using the kernel API, request_firmware(), of_fdt_unflatten_tree(), of_resolve_phandles(), of_overlay_create().
You have an example in "drivers/of/unittest.c".
And then with some magic re-probe the driver to take what we've just added into account. Otherwise the changes will just be visible in /proc/device-tree.

I saw a lot of people doing this through the bootloader, so I guess that currently it is the only reliable way of adding overlays.

I wish you good luck with this, and if I found a solution I will let you know ;).

Carli-K

richo25 05-29-2018 08:40 PM

Hi Carli
Thanks for getting back to me.
Yep it's rather frustrating as the docs say to do just that, but then seem to miss out I don't know how many other steps to actually make it work. Think some of the driver maintainers need to be forced into updating the docs when they add/change features because they are in a woeful state. Don't know if any of them have actually tried to use what they design :/

I'll post back if I figure something out.

Cheers
Richard


All times are GMT -5. The time now is 08:48 PM.