[PATCH v3 7/7] of_overlay: Add option to apply overlay to live tree

Michael Riesch michael.riesch at wolfvision.net
Tue Mar 14 09:03:25 PDT 2023


Hello Sascha,

On 3/14/23 16:49, Sascha Hauer wrote:
> On Tue, Mar 14, 2023 at 03:59:29PM +0100, Michael Riesch wrote:
>> Hi Sascha,
>>
>> On 3/10/23 10:42, Sascha Hauer wrote:
>>> The of_overlay command currently only supports applying overlays to the
>>> Linux device tree. Add an option to apply an overlay to the live tree.
>>> Using this option will apply the overlay and also triggers rescanning
>>> the device tree in case new devices have been added.
>>>
>>> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
>>> ---
>>>  commands/of_overlay.c | 38 ++++++++++++++++++++++++++++++++++----
>>>  1 file changed, 34 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/commands/of_overlay.c b/commands/of_overlay.c
>>> index b3660b4bf1..1d68e31ef2 100644
>>> --- a/commands/of_overlay.c
>>> +++ b/commands/of_overlay.c
>>> @@ -17,10 +17,20 @@ static int do_of_overlay(int argc, char *argv[])
>>>  	struct fdt_header *fdt;
>>>  	struct device_node *overlay;
>>>  	size_t size;
>>> +	bool live_tree = false;
>>> +	int opt;
>>>  
>>> -	if (argc != 2)
>>> +	if (argc < 2)
>>>  		return COMMAND_ERROR_USAGE;
>>>  
>>> +	while ((opt = getopt(argc, argv, "l")) > 0) {
>>> +		switch (opt) {
>>> +		case 'l':
>>> +			live_tree = true;
>>> +			break;
>>> +		}
>>> +	}
>>> +
>>>  	fdt = read_file(argv[optind], &size);
>>
>> of course this is not the intended usage, but "of_overlay -l" (i.e.,
>> skipping the overlay argument) throws an exception.
> 
> Okay, will fix.
> 
>>
>>>  	if (!fdt) {
>>>  		printf("cannot read %s\n", argv[optind]);
>>> @@ -32,7 +42,14 @@ static int do_of_overlay(int argc, char *argv[])
>>>  	if (IS_ERR(overlay))
>>>  		return PTR_ERR(overlay);
>>>  
>>> -	ret = of_register_overlay(overlay);
>>> +	if (live_tree) {
>>> +		ret = of_overlay_apply_tree(of_get_root_node(), overlay);
>>
>> If I pass a meaningful argument ("of_overlay -l path_to_my_overlay"), I get
>>
>> ERROR: of_resolver: __symbols__ missing from base devicetree
>> cannot apply oftree overlay: Invalid argument
>> of_overlay: Invalid argument
>>
>> in return. The base device tree does not contain any __symbols__
>> sections indeed. How can I activate the generation of this section?
> 
> Please enable CONFIG_OF_OVERLAY_LIVE. Maybe we can improve this a bit to
> make this clearer somehow / somewhere,

This seems to do the trick, thanks! A bit of documentation would be
great, though.

Thanks and best regards,
Michael



More information about the barebox mailing list