linux-kernelyoctodevice-treeyocto-recipeyocto-layer

Yocto Kirkstone Beaglebone Black add custom devicetree


When I build a core-image using Yocto Kirkstone for machine beaglebone-yocto, I get a file /boot/extlinux/extlinux.conf. This file looks like:

default Yocto
label Yocto
   kernel /zImage
   fdtdir /
append root=PARTUUID=f8fbccd5-02 rootwait console=ttyS0,115200

I can append, inside the label a DEVICETREE /mycustom.dtb and it will load mycustom.dtb as the device tree in the next boot. I do not know how to include this in the Yocto build so mycustm.dtsi gets compiled and added to the /boot folder.

I have tried compiling mycustom.dts into mycustom.dtb with a recipe like:

inherit devicetree
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI = " \
    file://mycustom.dts;subdir=git/overlays \
"
S = "${WORKDIR}/git/overlays"
COMPATIBLE_MACHINE = ".*(beaglebone).*"

which builds correctly, but when I use it in an image, I get an error: No match for argument: mycustom because the do_rootfs: Could not invoke dnf. It looks like do_root is adding mycustom as an argument to the command and it makes it fail.

I have read multiple questions about adding a dts to the kernel and adding a custom kernel_devicetree but I have not manage to implement them successfully and I keep thinking that there must be an easier way than having to patch u-boot and kernel, since manually modifying the extlinux.conf file works. Am I wrong?


Solution

  • I've got an answer for most of the question, although not as complete as I would like:

    To build a .dts with .dtsi includes:

    In you own layer, create a folder meta-mylayer/recipes-kernel/linux/files In files copy the mycustom.dts and all the myinclude.dtsi. Create the recipe meta-mylayer/recipes-kernel/linux/linux-yocto_%.bbappend that will append to any linux-yocto kernel that you use with the following:

    FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
    SRC_URI:append = " \
        file://mycustom.dts \
        file://myinclude.dtsi \
    "
    
    do_configure:append(){
     cp ${WORKDIR}/*.dt* ${S}/arch/arm/boot/dts
     echo 'dtb-$(CONFIG_SOC_AM33XX) += mycustom.dtb' >> ${S}/arch/arm/boot/dts/Makefile
    }
    

    The recipe will patch the Makefile to include your mycustom.dtb. This is not as neat as creating a patch for it and it will append it twice if you run configure twice, but I don't think it will do any harm and it is clear what it is trying to do.

    Now add your mycustom.dtb to the KERNEL_DEVICETREE variable in the conf/local.conf file:

    KERNEL_DEVICETREE:append = " mycustom.dtb"
    

    I tried adding this to the bbappend or the image recipes but it did not work. Probably because the kernel does not check those recipes.

    When you compile the image, it will now add mycustom.dtb to the /boot folder. If you want to check if you are in the right track, clean and configure the kernel with:

    bitbake -c cleanall virtual/kernel
    bitbake -c configure virtual/kernel
    

    You should find the file tmp/work-shared/beaglebone-yocto/kernel-source/arch/arm/boot/dts/Makefile has dtb-$(CONFIG_SOC_AM33XX) += mycustom.dtb in the last line and the folder tmp/work-shared/beaglebone-yocto/kernel-source/arch/arm/boot/dts/ has mycustom.dts and myincludes.dtsi. When you compile the kernel

    bitbake virtual/kernel
    

    mycustom.dtb exists in tmp/work/beaglebone_yocto-poky-linux-gnueabi/linux-yocto/5.15.54+gitAUTOINC+e4b95ec172_9aabbaa89f-r0/linux-beaglebone_yocto-standard-build/arch/arm/boot/dts/ your kernel version may be different.

    When you boot your image, it should now show mycustom.dtb in the /boot folder. To tell u-boot to use mycustom.dtb, I wanted to change the file /boot/extlinux/extlinux.conf. To do this, you can create a custom extlinux.conf file with:

    default Yocto
    label Yocto
       kernel /zImage
       fdtdir /
       DEVICETREE /mycustom.dtb
    append root=/dev/mmcblk0p2 rootwait console=ttyS0,115200
    

    and copy it to poky/meta-yocto-bsp/wic/myextlinux.conf. Finally modify the file poky/meta-yocto-bsp/wic/beaglebone-yocto.wks and in the bootloader last line, add --configfile myextlinux.conf so it reads:

    bootloader --append="console=ttyS0,115200" --configfile myextlinux.conf
    

    Bitbake your image and it will now use you mycustom.dtb by default.

    I tried creating my own wks file so I could keep it in my layer, but I got an error that it couldn't find my kernel. I also tried creating my own machine, but I got other errors. I wish I didn't have to use /dev/mmcblk0p2, but I don't know if I can or how to use PARTUUID. Using /dev/mmcblk0p2 may give issues if the image is flashed to EMMC. That's the best answer I've got, at least for the moment.