Yocto Kirkstone Beaglebone Black add custom devicetree
Asked Answered
L

2

6

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?

Lolland answered 23/5, 2023 at 8:38 Comment(1)
"I have tried compiling mycustom.dtsi into mycustom.dtb ... which builds correctly" -- That doesn't make sense or seem plausible. A .dtsi is merely an include file. The .dtb file is compiled from a .dts file.Ale
L
3

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.

Lolland answered 29/5, 2023 at 12:48 Comment(0)
F
0

Shouldnt you be able to simply add your dtsi to the boot/dts/ dir, and append the am335x-boneblack.dts with an include statement pointing at your .dtsi file?

i.e. Put your dtsi file in meta-mylayer/recipes-kernel/linux/files/, as you described above, then in your meta-mylayer/recipes-kernel/linux/linux-yocto_%.bbappend

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
 
SRC_URI_append = " \
        file://am335x-boneblack-your-custom.dtsi \
"
 
do_configure_append() {
        cp ${WORKDIR}/am335x-boneblack-your-custom.dtsi ${B}/source/arch/${ARCH}/boot/dts
        echo '/include/ "am335x-boneblack-your-custom.dtsi"' >> ${B}/source/arch/${ARCH}/boot/dts/am335x-boneblack.dts
}
Febrifuge answered 28/9, 2023 at 7:19 Comment(3)
I haven't tried it, but that may work, thanks. I don't like that the image would still use am335x-boneblack.dtb but it would be different to the official .dtb making the changes somehow hidden.Lolland
Maybe im misunderstanding, and your original dilemma was only related to compiling overlay files that would be deployed during runtime, as apposed to actual device-tree modifications via .dtsi include files?Febrifuge
What I was describing has little to do with dtb files, and nothing to do with them being deployed to a filesystem. What I described is all being implemented at the source file level, before any compilation has been done. The entire idea behind the device tree is to facilitate this modularity. Unless you are implementing a bespoke version of the beaglebone reference design in a novel way, you should always start with Ti's configuration, then inherit/include the beaglebone(black) include file(s); then use your include file to disable, enable, and configure nodes that are specific to your buildFebrifuge

© 2022 - 2024 — McMap. All rights reserved.