Building own image, device tree

How can I change device tree in own image? e.g. I want to use raspberry pi cm4 image like a base and add few devices to a device tree, how cna i do this?

Hello @M4xell

did you read how to set the device tree overlay docs? Advanced boot settings - Balena Documentation

Let us know how we can help you more with your next steps!

This is overlay for device tree, if want to change just device tree, is it possibility?

In other hand if I need to add some custom overlay (my own), where should i put this overlay?

If I build own system, how can i change config.txt? I want to build-in to the image, not add after flash the device as you described in documentation.

Hi, it sounds like you want to do some custom BSP work. My recommendation would be to build your own image following the instructions in balena-raspberrypi/README.md at master · balena-os/balena-raspberrypi · GitHub, modify the source as required, and then submit your custom overlay as a pull request so we can add it to the next OS release.

1 Like

modify the source as required, and then submit your custom overlay as a pull request so we can add it to the next OS release.

Ok, can you tell my where is good location to put this overlay? In other hand. how can i test this? I can’t put any file to the disk because is read-only …

How about device-tree? How it looks, how can i modify and release my own image? I can’t find device tree in basic repository, i see that after build device tree is appears in tmp directory but when i try to modifie I just receive a error durring next compilation.

I also waiting for the answer for config.txt.

Ok, can you tell my where is good location to put this overlay? In other hand. how can i test this? I can’t put any file to the disk because is read-only … How about device-tree? How it looks, how can i modify and release my own image? I can’t find device tree in basic repository, i see that after build device tree is appears in tmp directory but when i try to modifie I just receive a error durring next compilation.

It looks that I can manipulate device tree only by overlay and overlay can by added only by add by patch. I put my patch in this location meta-balena-raspberrypi/recipes-kernel/linux/linux-raspberrypi/. Please confirm for me and other users :wink: Can you add my patch if I send here?

I also waiting for the answer for config.txt.

It looks that I can add some variable to config.txt by add this to the file meta-balena-raspberrypi/recipes-bsp/bootfiles/rpi-config_git.bbappend, please also confirm. After compilation I see that config.txt have my change.

Hi, you have examples of device tree overlay additions in the balena-raspberrypi repository history. For example, the patch [1] which is added to the kernel recipe in [2], adds a new device tree overlay.

Once the image is built, the device trees and overlays are placed on the boot partition, /mnt/boot at runtime, which is a writable partition. You can replace/add overlays there while testing.

As for config.txt, the recommended way to modify it is documented in Advanced boot settings - Balena Documentation. There is no need to change the source for this.

[1] balena-raspberrypi/0006-overlays-Add-Hyperpixel4-overlays.patch at master · balena-os/balena-raspberrypi · GitHub
[2] balena-raspberrypi/linux-raspberrypi_5.10.bbappend at aca48aeb972de46e9bb4315f47d1b8a57e42f2ed · balena-os/balena-raspberrypi · GitHub

Hi,

Just wanted to add a little something I’m using in my build to modify my device tree.

In your <layer>/conf/layer.conf file, you can add entries like KERNEL_DEVICETREE_remove_<device> = "overlays/uart0.dtbo" and KERNEL_DEVICE_TREE_append_<device> = " overlays/notice_the_space_in_front.dtbo"

You may also want to take a look at this article if you haven’t already.

Thanks a lot, i will check.

I can’t see “/etc/modules” in hostOS, this is a problem because some driver not load automatically. The easiest solution which I know is add this drivers to this file e.g. mcp3422. Do you know any other solution?

Hi, the solution is to use an application container to load modules - you can access /etc/modules in the container.