# Building own image, device tree

**URL:** <https://forums.balena.io/t/building-own-image-device-tree/357876>\
**Category:** General\
**Created:** [May 16, 2022, 9:07am UTC](https://forums.balena.io/t/building-own-image-device-tree/357876 "2022-05-16T09:07:54Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![M4xell](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M4xell](https://forums.balena.io/u/M4xell)\
**Post date:** [May 16, 2022, 9:07am UTC](https://forums.balena.io/t/building-own-image-device-tree/357876/1 "2022-05-16T09:07:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mpous](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mpous/32/4742_2.png) [@mpous](https://forums.balena.io/u/mpous)\
**Post date:** [May 16, 2022, 12:24pm UTC](https://forums.balena.io/t/building-own-image-device-tree/357876/2 "2022-05-16T12:24:38Z")

</div>

Hello @M4xell

did you read how to set the device tree overlay docs? [Advanced boot settings - Balena Documentation](https://www.balena.io/docs/reference/OS/advanced/#setting-device-tree-overlays-dtoverlay-and-parameters-dtparam)

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

---

<div class="post-metadata">

**Author:** ![M4xell](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M4xell](https://forums.balena.io/u/M4xell)\
**Post date:** [May 16, 2022, 1:34pm UTC](https://forums.balena.io/t/building-own-image-device-tree/357876/4 "2022-05-16T13:34:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alexgg](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@alexgg](https://forums.balena.io/u/alexgg)\
**Post date:** [May 16, 2022, 4:14pm UTC](https://forums.balena.io/t/building-own-image-device-tree/357876/5 "2022-05-16T16:14:57Z")

</div>

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](https://github.com/balena-os/balena-raspberrypi/blob/master/README.md), 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.

---

<div class="post-metadata">

**Author:** ![M4xell](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M4xell](https://forums.balena.io/u/M4xell)\
**Post date:** [May 17, 2022, 6:07am UTC](https://forums.balena.io/t/building-own-image-device-tree/357876/8 "2022-05-17T06:07:19Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![M4xell](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M4xell](https://forums.balena.io/u/M4xell)\
**Post date:** [May 17, 2022, 10:22am UTC](https://forums.balena.io/t/building-own-image-device-tree/357876/9 "2022-05-17T10:22:59Z")

</div>

> 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 😉 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.

---

<div class="post-metadata">

**Author:** ![alexgg](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@alexgg](https://forums.balena.io/u/alexgg)\
**Post date:** [May 19, 2022, 10:35am UTC](https://forums.balena.io/t/building-own-image-device-tree/357876/10 "2022-05-19T10:35:29Z")

</div>

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](https://www.balena.io/docs/reference/OS/advanced/#raspberry-pi). 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](https://github.com/balena-os/balena-raspberrypi/blob/master/layers/meta-balena-raspberrypi/recipes-kernel/linux/linux-raspberrypi/0006-overlays-Add-Hyperpixel4-overlays.patch)  
[2] [balena-raspberrypi/linux-raspberrypi\_5.10.bbappend at aca48aeb972de46e9bb4315f47d1b8a57e42f2ed · balena-os/balena-raspberrypi · GitHub](https://github.com/balena-os/balena-raspberrypi/blob/aca48aeb972de46e9bb4315f47d1b8a57e42f2ed/layers/meta-balena-raspberrypi/recipes-kernel/linux/linux-raspberrypi_5.10.bbappend#L18)

---

<div class="post-metadata">

**Author:** ![TJvV](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TJvV](https://forums.balena.io/u/TJvV)\
**Post date:** [May 20, 2022, 7:25am UTC](https://forums.balena.io/t/building-own-image-device-tree/357876/13 "2022-05-20T07:25:52Z")

</div>

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](https://newbedev.com/how-to-use-an-own-device-tree-and-modified-kernel-config-in-yocto) if you haven’t already.

---

<div class="post-metadata">

**Author:** ![M4xell](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M4xell](https://forums.balena.io/u/M4xell)\
**Post date:** [May 20, 2022, 11:00am UTC](https://forums.balena.io/t/building-own-image-device-tree/357876/14 "2022-05-20T11:00:37Z")

</div>

Thanks a lot, i will check.

---

<div class="post-metadata">

**Author:** ![M4xell](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M4xell](https://forums.balena.io/u/M4xell)\
**Post date:** [May 31, 2022, 9:08am UTC](https://forums.balena.io/t/building-own-image-device-tree/357876/16 "2022-05-31T09:08:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![alexgg](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@alexgg](https://forums.balena.io/u/alexgg)\
**Post date:** [May 31, 2022, 12:35pm UTC](https://forums.balena.io/t/building-own-image-device-tree/357876/17 "2022-05-31T12:35:54Z")

</div>

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