Cannot compile Device Tree Overlays from Source Code

I followed this link Build Device Tree Overlays from Source Code | Toradex Developer Center to compile the DTO.

I get an error:
In file included from fdtdump.c:14:
fdtdump.c: In function ‘main’:
libfdt/libfdt.h:251:28: error: array subscript ‘struct fdt_header[0]’ is partly outside array bounds of ‘unsigned char[4]’ [-Werror=array-bounds]
251 | fdth->name = cpu_to_fdt32(val);
| ~^~~~~~~~~
libfdt/libfdt.h:253:1: note: in expansion of macro ‘fdt_set_hdr_’
253 | fdt_set_hdr_(magic);
| ^~~~~~~~~~~~
fdtdump.c:216:31: note: while referencing ‘smagic’
216 | unsigned char smagic[FDT_MAGIC_SIZE];

How can I solve it ?

Hello @Massimo,

Could you please send us some more information regarding the BSP or TorizonCore that you are using on the module? Could you please send us the output of tdx-info command (Getting Device Information with Tdx-Info | Toradex Developer Center) from which we will get all the hardware and software information?

Also, could you please share with us the overlay file you have written so that we could try to reproduce the issue?

This is the tdx-info output:

root@colibri-imx6ull-14926715:~# tdx-info

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           6.1.22-6.2.0+git.3b29299e5f60 #1 SMP Thu Mar 30 10:49:31 UTC 2023
Kernel command line:      user_debug=30 ubi.mtd=ubi root=ubi0:rootfs rw rootfstype=ubifs ubi.fm_autoconvert=1 console=tty1 console=ttymxc0,115200n8 consoleblank=0 video=mxsfb:640x480M-16@60
Distro name:              NAME="TDX Wayland with XWayland Upstream"
Distro version:           VERSION_ID=6.2.0-build.6
Hostname:                 colibri-imx6ull-14926715
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Colibri iMX6ULL 256/512MB on Colibri Evaluation Board V3
Toradex version:          0044 V1.1A
Serial number:            14926715
Processor arch:           armv7l
------------------------------------------------------------
root@colibri-imx6ull-14926715:~# tdx-info -dt

Device tree
------------------------------------------------------------
Device tree enabled:      -
Compatible string:        toradex,colibri-imx6ull-evalfsl,imx6ull
Device trees available:   -
------------------------------------------------------------

Device tree overlays
------------------------------------------------------------
Overlays enabled:         -
Overlays available:       -
------------------------------------------------------------

Hello @Massimo,

Thanks for sending the tdx-info.

Please send us the overlay file so that we can try to reproduce the issue.

Hello Rudhi,
I can’t send you the overlay file. I had the compile error I reported when I tryed to build " Device Tree Compiler (DTC) Tool" with your procedure, following Build Device Tree Overlays from Source Code | Toradex Developer Center.
When I run: make inside the dtc directory, I get the error.
Consider that I run it on Ubuntu 22.04.2 LTC and that I installed the 32 bit host machine cross compilation.

Thanks

Hello @Massimo,

Could you please send me the output of echo $PATH command?
Also, please send the absolute path where gcc-linaro and dtc are installed.
Have you built the linux kernel as a mandatory requirement?

Hello Rudhi,

$ echo $PATH
/home/showroom/Toradex/DeviceTree/gcc-linaro/bin/:/home/showroom/Dev/Raspberry/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin

linaro path:
/home/showroom/Dev/Toradex/DeviceTree/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/

dtc path:
/home/showroom/Dev/Toradex/DeviceTree/dtc/

I haven’t built the linux kernel because to build only the device tree file, I would want to avoid this, but if it is necessary…

Hello @Massimo,

I was able to reproduce this error on an Ubuntu 22.04 machine. On further investigation, I found that the cause behind this error has been fixed on version 1.6.1 of dtc. I could solve the issue by simply cloning to this branch on the dtc repository. So you will need to do the following:

$ git clone git://git.kernel.org/pub/scm/utils/dtc/dtc.git -b v1.6.1 ~/dtc
$ cd ~/dtc
$ make
$ export PATH=$HOME/dtc/:$PATH

Thanks for reporting this error. Please let me know if this solves your issue.

Thank Rudhi,
dtc was compiled without error.

Now I ask you if it is necessary to download the kernel source code to compile the dts files ?
From here Build Device Tree Overlays from Source Code | Toradex Developer Center it seem yes because it is necessary to set the STAGING_KERNEL_DIR variable.

Dear @Massimo,

Glad to hear that it worked.

Now I ask you if it is necessary to download the kernel source code to compile the dts files ?
From here Build Device Tree Overlays from Source Code | Toradex Developer Center it seem yes because it is necessary to set the STAGING_KERNEL_DIR variable.

That’s right, you need to build the kernel and export the STAGING_KERNEL_DIR variable before you compile the dts files.

Dear Rudhi,
I’m trying to compile kernel following your Build Linux Kernel from Source Code | Toradex Developer Center .
I downloaded:
git clone -b v6.1 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git

When I run:
make imx_v6_v7_defconfig
I get:
scripts/Kconfig.include:39: C compiler ‘arm-none-linux-gnueabihf-gcc’ not found
make[1]: *** [scripts/kconfig/Makefile:94: imx_v6_v7_defconfig] Errore 1
make: *** [Makefile:697: imx_v6_v7_defconfig] Errore 2

How can I set the compiler ? I haven’t found in your site.
Thanks

Hello @Massimo,

This is because the environment variables are not set properly. Can you check the output of echo $CROSS_COMPILE ?

As it is mentioned on the linked article:
The U-Boot and Linux makefiles use the environment variables ARCH/CROSS_COMPILE to configure and call the compiler correctly. Therefore, these environment variables must be exported in any shell instance that will run configure/compile commands to build U-Boot or Linux for the target module.

$ export ARCH=arm
$ export DTC_FLAGS="-@"
$ export PATH=~/gcc-linaro/bin/:$PATH
$ export CROSS_COMPILE=arm-none-linux-gnueabihf-

Hello Rudhi,

echo $CROSS_COMPILE
arm-none-linux-gnueabihf-

Hi @Massimo,

I tried to reproduce the error on the exact same setup as yours but unfortunately, I couldn’t.

I followed all the steps listed on our web page and it just worked fine. It looks like you are probably missing one or several of the steps. Could you please retry?