How to cross compile static dtc for ARM ?

As we seen in our previous post, “How to Compile and Install device-tree-compiler (DTC) On Ubuntu”, we could compile DTC ( Device Tree Compiler ) for Host machine i.e. Ubuntu

In this post, we will describe what changes are required to get the DTC compiled to execute on embedded targets such as ARM. Since executing dtc on embedded targets is required very few times, we will get it statically compiled so we dont need to resolve the runtime library linking issues.

$ git clone git://git.kernel.org/pub/scm/utils/dtc/dtc.git

Assuming you have the toolchain and your GCC is something like “arm-linux-gnueabi-gcc” OR you can install the toolchain as,

$ sudo apt-get install gcc-arm-linux-gnueabi

once you installed toolchain, modify Makefile as,

$ cd dtc
$ vim Makefile
CC=arm-linux-gnueabi-gcc
CFLAGS = -g -Os $(SHAREDLIB_CFLAGS) -Werror $(WARNINGS) -static
$ file dtc
dtc: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=024c7cafca22f3477e9266a293f98fcd82deb5c9, with debug_info, not stripped

Note: while compilation, you may get an error as below, but you can ignore this, as our main aim was to get DTC statically compiled which has been done with above changes and steps.

/usr/lib/gcc-cross/arm-linux-gnueabi/7/../../../../arm-linux-gnueabi/bin/ld: attempted static link of dynamic object `libfdt/libfdt-1.6.0.so'
collect2: error: ld returned 1 exit status
Makefile:343: recipe for target 'fdtget' failed
make: *** [fdtget] Error 1

Ignore above error.

1 thought on “How to cross compile static dtc for ARM ?”

Leave a Comment