Saturday, 9 July 2016

Linux dts compilation using dtc compiler.

I was reading up on the dts (Device Tree Specification) specification and wanted to try out custom dts and compile it to dtb (Device Tree Blob).

The dts I wanted to compile was for the Wandboard which is the imx6dl-wandboard.dts

To compile I use the following command:

dtc -I dts -O dtb -o imx6dl-wandboard_test.dts

When trying this I get the error "FATAL ERROR: Unable to parse input tree near the includes..."

Turns out we have to use CPP (C Preprocessor)  to parse the includes and substitutions. Hence the next command is as follows:

cpp -nostdinc -I include -undef, -x assembler-with-cpp imx6dl-wandboard.dts > imx6dl-wandboard_bare.dts

 Here we use

-nostdinc:  We do not search system directories for header files. Only the directories I have specified wtih the -I are searched for header files.

-undef: We do not perform any system-specific or GCC-specific macros. All standard predefined macros remain definied.

-x: We provide the option assembler-with-cpp as the dtc compiler cannot auto ditacte whether the file is a "open", "clode", "read and write"

Pass the dts file and redirect the output to an output dts file.
Next we run the dtc compiler as above replacing imx6dl-wandboard_test.dts with the output generated from CPP. This will create the dtb file . You reverse the dtb to a dts by replacing the -I parameter with dtb and -O parameter with dts.

Also make sure you run this command in the arch/arm/boot/dts directory because of the includes present in it. Replace the "arm" with your CPU architecture of choice.

Additionally you can also create the dtb file running the rule dtbs in the makefile.

To make it work edit the Makefile in the arch/arm/boot/dts and add your dts file in the proper architecture. For my wandboard it will be dtb-$(CONFIG_ARCH_MXC).

Next create the dtb file with the following command:

1
ARCH=arm CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/arm-linux-androideabi- make -C kernel_imx/ dtbs



References: https://linux-sunxi.org/Device_Tree#Compiling_the_Device_Tree

"There must be no barriers to freedom of inquiry … There is no place for dogma in science. The scientist is free, and must be free to ask any question, to doubt any assertion, to seek for any evidence, to correct any errors."
--J Robert Oppenheimer



No comments:

Post a comment