Custom device tree apalis imx8

I have been following this to use our own custom device tree.

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

However, linux boots up with the normal device tree.
I cannot find any deviances from the article. What am I doing wrong?

the .dts file seems to be included in tmp/work-shared/apalis-imx8/kernel-source/arch/arm64/boot/dts/freescale.

content of custom layer
/meta-custom/recipes-kernel/linux/linux-toradex_5.4%.bbappend

FILESEXTRAPATHS:prepend := "${THISDIR}/linux-toradex:"

CUSTOM_DEVICETREE = "imx8qm-apalis-v1.1-cust.dts"
CUSTOM_DEVICETREE_INCLUDE = "imx8-apalis-cust.dtsi"

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

do_configure:append() {
    cp ${WORKDIR}/${CUSTOM_DEVICETREE} ${S}/arch/arm64/boot/dts/freescale
    cp ${WORKDIR}/${CUSTOM_DEVICETREE_INCLUDE} ${S}/arch/arm64/boot/dts/freescale
}

meta-custom/recipes-kernel/linux/linux-toradex holds the custom .dts and .dtsi files

meta-custom/conf/machine/apalis-imx8-extra.conf:

KERNEL_DEVICETREE:append = "freescale/imx8qm-apalis-v1.1-cust.dtb"

meta-custom/conf/layer.conf:

include conf/machine/apalis-imx8-extra.conf

# We have a conf and classes directory, add to BBPATH
BBPATH .= ":${LAYERDIR}"

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

BBFILE_COLLECTIONS += "meta-custom"
BBFILE_PATTERN_meta-custom = "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-custom = "91"

LAYERVERSION_meta-custom = "1"
LAYERDEPENDS_meta-custom = "core"
LAYERSERIES_COMPAT_meta-custom = "dunfell"

meta-custom/recipes-bsp/u-boot/u-boot-toradex_%.bbappend

do_configure:append() {
    # Remove existing fdtfile, it there is one
    sed -i '/"fdtfile=.*\\0" \\/d' ${S}/include/configs/apalis-imx8.h
    # Add new fdtfile
    sed -i 's/\("fdt_board=.*\\0" \\\)/\0\n "fdtfile=imx8qm-apalis-v1.1-cust.dtb\\0" \\/' ${S}/include/configs/apalis-imx8.h

}

Please note that device tree is not a kernel module or application. It’s a blob located in separate (boot) partition and that blob should be loaded to certain memory location by U-Boot before starting kernel.
Please double check if your imx8qm-apalis-v1.1-cust.dtb was included in deployable tarball. Than you need to check image json file. For example:

"blockdevs": [
    {
        "name": "mmcblk0",
        "partitions": [
            {
                "partition_size_nominal": 48,
                "want_maximised": false,
                "content": {
                    "label": "BOOT",
                    "filesystem_type": "FAT",
                    "mkfs_options": "",
                    "filename": "Reference-Minimal-Image-apalis-imx8.bootfs.tar.xz",
                    "uncompressed_size": 10.59765625
                }
            },

In that case your custom dtb file should be included in the Reference-Minimal-Image-apalis-imx8.bootfs.tar.xz

Then you need to verify if U_Boot environment set properly . Check fdtfile value in u-boot-initial-env-sd file.

Ifimx8qm-apalis-v1.1-cust.dtb got built but not included in the tarball or U_boot environment you can manually edit that files to test your new device tree.

Hi @alex.tx,

I did printenv fdtfile in uboot and that outputs fdtfile=imx8qm-apalis-v1.1-eval.dtb.

I was hoping that the sed operations in meta-custom/recipes-bsp/u-boot/u-boot-toradex_%.bbappend would take care of that.

This is the content of my image.json

"blockdevs": [
        {
            "name": "mmcblk0",
            "partitions": [
                {
                    "partition_size_nominal": 512,
                    "want_maximised": true,
                    "content": {
                        "label": "otaroot",
                        "filesystem_type": "ext4",
                        "mkfs_options": "-E nodiscard",
                        "filename": "torizon-core-custom-apalis-imx8.ota.tar.zst",
                        "uncompressed_size": 646.93359375
                    }
                }
            ]
        },
        {
            "name": "mmcblk0boot0",
            "erase": true,
            "content": {
                "filesystem_type": "raw",
                "rawfiles": [
                    {
                        "filename": "imx-boot",
                        "dd_options": "seek=0"
                    }
                ]
            }
        }
    ]

There is no imx8qm-apalis-v1.1-cust.dtb in torizon-core-custom-apalis-imx8.ota.tar.zst.

The file deploy/images/apalis-imx8/u-boot-initial-env-apalis-imx8-sd-2020.04-r0 in my build folder has these lines.

fdt_board=eval
fdtfile=imx8qm-apalis-v1.1-emli-4.dtb

However, I cannot find imx8qm-apalis-v1.1-emli-4.dtb anywhere in my build folder.
Other dtb files , e.g. imx8qm-apalis-eval-apalis-imx8.dtb , are in /tmp/work/apalis_imx8-tdx-linux/linux-toradex/5.4.193+gitAUTOINC+cf62fa8fd9_f782992971-r0/deploy-linux-toradex
Does that mean it wasn’t built properly?

Hi @alex.tx,

I was trying an intermediate solution to test my device-tree file, and have managed to compile the .dtb file. However, when i do

setenv fdtfile imx8qm-apalis-v1.1-emli-4.dtb
saveenv
reset

nothing changes i u-boot.

After reboot and going into uboot, the original imxqm-apalis-v1.1-eval.dtb is still listed when doing printenv.

I saw it mentioned as fixed here Problem changing FDTFILE on 3.0b4.254, but it does not work for me.

Hi @jugge ,

Have a look at printenv preboot. There the fdtfile string is created. You can try to set it from there to your device tree.

That should have the desired effect, at least temporarily.

Let me know if that worked.

Best Regards
Kevin

For some reason it was possible to set it after i changed with

setenv preboot imx8qm-apalis-v1.1.emli-4.dtb
savenv
reset

and then setting fdtfile

setenv fdtfile imx8qm-apalis-v1.1-emli4.dtb
savenv 
reset

However, just as above i did a typo in setenv fdtfile and forgot the dash between emli and 4. Now I cannot do a setenv fdtfile to change it again.

edit:
if I do the change to preboot and save it and reset, i can change the fdtfile again…

I managed to include my custom device tree .dtb manually by setting the preboot and fdtfile as described above.

I have also managed to include in using Yocto, but I had to change the line in conf/layer.conf from as described in the article

include conf/machine/verdin-imx8mp-extra.conf

to

include machine/verdin-imx8mp-extra.conf

to get the relative search path correct.

In my case it’s not verdin-imx8mp, so my include is

include machine/apalis-imx8-extra.conf

I alos needed to change the sed commands so that fdt_board is replaced as well.

    # Replace existing fdtfile with a new one
    sed -i 's/\("fdtfile=.*\\0" \\\)/"fdtfile=imx8qm-apalis-v1.1-custom.dtb\\0" \\/' ${S}/include/configs/apalis-imx8.h
    # Replace existing fdt_board with a new one. Not sure why needed, but probably since preboot in u-boot uses fdt_board to set fdtfile.
    sed -i 's/\("fdt_board=.*\\0" \\\)/"fdt_board=custom\\0" \\/' ${S}/include/configs/apalis-imx8.h

After this my custom device tree is included in the yocto build, and I can flash the image with my custom device tree included.