Custom device tree

I’m using IMX7D emmc and i have built my custom Device tree and i have tested it .i want to replace it by main Toradex device tree .
i wonder how i could set my custom device tree in yocot image (tdx-reference-minimal-image) .
and how to patch uboot to run my custom device tree instead of the default toradex on .
thanks in advance.

Device tree blob located at the boot partition and U_boot environment variables β€œfdt_file” defines which file will be loaded. So you can manually replace dtb file there. Please check this post if you want to include new DT to your Yocto build.

Thanks For your Response.
i have followed This Instruction link
but there is some parts that i don’t understand.
for example the part that say :


KERNEL_DEVICETREE_append = " my-custom-devicetree-file.dtb"

i dont have any directory name machine .
and i as i checked the deploy directory the device tree has been compiled but hasn’t been added in boot patrion.

and for the second question i have :

do_configure_append() {
    sed -i 's/#define FDT_FILE.*/#define FDT_FILE "my-custom-devicetree-file.dtb"/' ${S}/include/configs/colibri_imx6.h

in this part we are telling the u-boot to boot our device tree.
but i think for IMX7 it’s different .
it would be nice if you guide me more .
cheers joe :slight_smile:

Hi @joe.hiko,

This is just a folder used as an example, you will need to create it.

For Colibri iMX7, you will use colibri_imx7.h file. This file comes from u-boot, you can clone the u-boot repo on your computer and search for these files inside include/configs/. This is the folder where Yocto will get these files. You can see how you can clone the u-boot here. This is only for you to search the files, but you don’t need to do this to build your custom layer because Yocto will download u-boot and Linux kernel automatically.

Sure! I made an example here, where I’m going to build a custom layer to add my own device tree file. The structure of your meta-customer should be something as follows:

yocto@984338ceadd3:~/oe-core/layers/meta-customer$ tree
β”œβ”€β”€ conf
β”‚   β”œβ”€β”€ layer.conf
β”‚   └── machine
β”‚       └── colibri-imx7d-emmc-extra.conf
β”œβ”€β”€ COPYING.MIT
β”œβ”€β”€ README
β”œβ”€β”€ recipes-bsp
β”‚   └── u-boot
β”‚       └── u-boot-toradex_%.bbappend
└── recipes-kernel
    └── linux
        β”œβ”€β”€ linux-toradex
        β”‚   └── my-custom-devicetree-file.dts
        └── linux-toradex%.bbappend

Where the files are defined as:

yocto@984338ceadd3:~/oe-core/layers/meta-customer/recipes-bsp/u-boot$ cat u-boot-toradex_%.bbappend 
do_configure_append() {
    sed -i 's/#define FDT_FILE.*/#define FDT_FILE "my-custom-devicetree-file.dtb"/' ${S}/include/configs/colibri_imx7.h
yocto@984338ceadd3:~/oe-core/layers/meta-customer/recipes-kernel/linux$ cat linux-toradex%.bbappend 
FILESEXTRAPATHS_prepend := "${THISDIR}/linux-toradex:"

# Prevent the use of in-tree defconfig

CUSTOM_DEVICETREE = "my-custom-devicetree-file.dts"

SRC_URI += "\ 
    file://${CUSTOM_DEVICETREE} \

do_configure_append() {
    cp ${WORKDIR}/${CUSTOM_DEVICETREE} ${S}/arch/arm/boot/dts
yocto@984338ceadd3:~/oe-core/layers/meta-customer/conf$ cat layer.conf 
# We have a conf and classes directory, add to BBPATH

# We have recipes-* directories, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \

BBFILE_COLLECTIONS += "meta-customer"
BBFILE_PATTERN_meta-customer = "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-customer = "6"

LAYERDEPENDS_meta-customer = "core"
LAYERSERIES_COMPAT_meta-customer = "dunfell"

include conf/machine/colibri-imx7d-emmc-extra.conf
yocto@984338ceadd3:~/oe-core/layers/meta-customer/conf/machine$ cat colibri-imx7d-emmc-extra.conf 
KERNEL_DEVICETREE_append = " my-custom-devicetree-file.dtb"

Please, don’t forget to add this layer to your bblayers.conf file.

Reference: Custom meta layers, recipes and images in Yocto Project (hello-world examples) | Toradex Developer Center

I hope this will help you. Please, feel free to ask any questions you might have.

Best regards,

1 Like

Thank you Hiago!!
This is Exactly what i needed. ill give it a try and i lll let you know about the result. thanks :slight_smile:
kind regards.

1 Like

Hi Hiago
I have Tried What you said and i was able to successfully Set My custom Device Tree To The bootfs .
but as i searched in toradex-uboot specially this file:


I couldnt Find The macro that Sets :

#define FDT_FILE

and i maked menuconfig for the imx7_emmc i found that toradex use diffrent method for setting the fdtfile .

and as you can see there is a preboot value that sets the fdtfile .
and i wanna know to set my own device tree with this structure.
Best Regards.

Hi @joe.hiko,

yes, you are right, Toradex u-boot sets the device tree file based on these two variables: $soc and $fdt_board.

For example, if you are using a custom device tree named β€œimx7-colibri-emmc-custom.dtb”, you can enter in the u-boot terminal and run:

setenv fdt_board custom

The $soc value is set automatically by u-boot, it will be β€œimx7” in your case.
With this command, u-boot will set automatically the device tree file called β€œimx7-colibri-emmc-custom.dtb”, which has to be inside the /boot/ folder for u-boot to find it.

Therefore, if you don’t want to set your device tree in Yocto, you can remove the part where we set the custom device tree in your meta layer and set it inside u-boot as I mentioned above.
For production though, we recommend setting the device tree file with Yocto, because it will be easier to manage your custom image and set the device tree for all your modules.

Best regards,