Add #define sentence into a device tree overlay

Hi,

I am creating a basic device tree overlay, and I want to include a #define, but when the sentence is added to the device tree overlay (see below), the dtc reports the error:

FATAL ERROR: Unable to parse input tree

Is possible to add a #define sentence in a device tree overlay?

Device tree overlay:

/dts-v1/;
/plugin/;

#define VERSION "0.0"

/ {
    overlay-name = "Overlay Example";
    jetson-header-name = "Jetson 40pin Header";
    compatible = "nvidia,p3509-0000+p3668-0001";

    fragment@0 {
        target-path = "/";
        __overlay__ {
			description = "Description";
	    };
    };
};

Thanks.

hello ManuelLeiva,

as I knew, it’s able to add #define into the device tree sources,
I assume you should not add the marco outside the overlay example. please have a try, thanks

Hi Jerry,

I have tried to set the define in the overlay node but I have the same error (See DT overlay below). I tried to use compiler macros as __FILE__ (dtfilename = __FILE__;) and I have the same error.
I wondering if there is some flag or special node to use a #define or a macro.

/dts-v1/;
/plugin/;
 
/ {
    overlay-name = "Overlay Example";
    jetson-header-name = "Jetson 40pin Header";
    compatible = "nvidia,p3509-0000+p3668-0001";

    fragment@0 {
        target-path = "/";
        __overlay__ {
            #define VERSION "0.0"
            // filename = __FILE__;
            description = "Description";
	    };
    };
};

Thanks.

hello ManuelLeiva,

I cannot reproduce the same by adding the same into device tree overlay,
can other marco works here, for example, are you able to include the header file?

Hello JerryChang

I am getting this problem during the compilation time, If you try to compile the device tree overlay, Are you not able to reproduce my problem?
I am using this compilation line: dtc -O dtb -o tx2_overlay.dtbo -@ tx2_overlay.dts

hello ManuelLeiva,

ahh… I’ve follow Kernel Customization to build device tree blob from sources.

Hello JerryChang,
I am not trying to build a device tree blob from sources. In my case, I am building a device tree Overlay, Nvidia provides instructions to build a basic device tree overlay (Device tree Overlay)
But I was wondering if can use a #define because when I have tried to add one, I get a compilation error, but since when we build a device tree blob we can use definitions, I supposed I can use it in a device tree Overlay as well.

hello ManuelLeiva,

this marco, # define it should only works in the cpp files.
please refer to below as see-also for using dtc compiler
thanks

Excellent, thanks.

Wiki with more information:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.