raspberry-piyoctobootyocto-layerraspberry-pi5

How to set up a Yocto layer in order to modify the boot/config.txt file of a Raspberrypi 5


I am trying to automatically change this variable in the config.txt file :

From :

dtoverlay=vc4-kms-v3d

to :

dtoverlay=vc4-fkms-v3d

And also add some other lines that will allow me to use a specific device. Therefore I want to have the following at the end of my file :

dtoverlay=vc4-fkms-v3d

#Added lines for the mini-PCIe HAT
dtparam=pciex1
dtparam=pciex1_gen=3

I can do it manually after generating my image, but the idea is to use Yocto in order to do so.

I've tried to apply a patch with a Yocto layer which I've created, but to no avail.

Here's the layer structure :

meta-patch-config/
├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
├── recipes-bsp
│   └── rpi-firmware
│       ├── files
│       │   └── configtxt.patch
│       └── rpi-bootfiles.bbappend
└── recipes-example
    └── example
        └── example_0.1.bb

With the rpi-bootfiles.bbappend being written like this :

FILESEXTRAPATHS:prepend := "${THISDIR}/files:"

SRC_URI:append = " file://configtxt.patch"

and the patch file :

--- a/config.txt.orig
+++ b/config.txt
@@ -242,5 +242,8 @@
 
 #dtoverlay=act-led,activelow=off
 # Enable VC4 Graphics
-dtoverlay=vc4-kms-v3d
+dtoverlay=vc4-fkms-v3d
 
+#Added lines for the mini-PCIe HAT
+dtparam=pciex1
+dtparam=pciex1_gen=3

Unfortunately, my patch isn't being applied.


Solution

  • Searching for a recipe named rpi-bootfiles.bb, I find github.com/agherzan/meta-raspberrypi which could match.

    Your approach is right by creating a new layer, ensure however the priority of your layer is higher than the meta-raspberrypi (9 in this case) to make the bbappend work on top of it.

    However, patching the configuration file is not the best because do_patch occurs really soon in the build steps, between do_unpack and do_deploy so your patch applies probably on line which doesn't exist yet, created during the do_deploy in this particular case (and not coming from the sources as usual).

    It's better to append your logic to the do_deploy to keep the same overall logic.

    Based on meta-raspberrypi, you layer would look like that :

    meta-patch-config/
    ├── conf
    │   └── layer.conf
    ├── COPYING.MIT
    ├── README
    └── recipes-bsp
        └── bootfiles
            └── rpi-config_git.bbappend
    

    From there, the rpi-config cares already about the dtoverlay that you can simply override in your bbappend:

    VC4DTBO = "vc4-fkms-v3d"
    

    This is used in the do_deploy and requires VC4GRAPHICS to be set (vc4graphics must be set in MACHINE_FEATURES):

        # VC4 Graphics support
        if [ "${VC4GRAPHICS}" = "1" ]; then
            echo "# Enable VC4 Graphics" >> $CONFIG
            echo "dtoverlay=${VC4DTBO}" >> $CONFIG
        fi
    

    Given your other dtparams are not handled, you can simply append the do_deploy to add your extra params at the end of the file :

    do_deploy:append() {
        echo "#Added lines for the mini-PCIe HAT" >> $CONFIG
        echo "dtparam=pciex1" >> $CONFIG
        echo "dtparam=pciex1_gen=3" >> $CONFIG
    }
    

    Final rpi-config_git.bbappend is simply that :

    VC4DTBO = "vc4-fkms-v3d"
    
    do_deploy:append() {
        echo "#Added lines for the mini-PCIe HAT" >> $CONFIG
        echo "dtparam=pciex1" >> $CONFIG
        echo "dtparam=pciex1_gen=3" >> $CONFIG
    }
    

    As an extra and because I'm not sure you are using this meta, you can also use sed in the do_deploy:append if you want to modify data coming from sources or already defined by the parent's do_deploy.