3

Let me preface this by saying I don't know much about device trees. I do know a bit about ATAGs, since I'm working with this operating system that currently only uses ATAGs.

I'm modifying the operating system to work on the Raspberry Pi 3s, and the stack address that the kernel gets from the ATAGs seems to be off, since I can't, for example, print out what's in saddr[0]. I've found that ATAGs are becoming obsolete, so instead of figuring out what's wrong with the ATAGs, I'm thinking about switching the OS over to using device trees.

Problem is, I don't even know where to start. My team tried adding a .dtb file taken from here: Raspberry Pi 3 UART Overlay Workaround to our SD card but said it "didn't work." To be fair, we had no idea what we were doing when we added that file. We hadn't modified the operating system to work with device trees, and we were focusing on a different problem when we added that file (so the thing that "didn't work" was that we couldn't get any input from PL011 UART driver, and there are so many things that could have caused that to not work).

So if I want the operating system to use device trees, where do I start? Do I have to make my own or is there one already available that I can use? Are dtb files specific to specific platforms, operating systems, or processors? I can't find much documentation for this online, so if you could give me something to read that'd be great.

1
  • 1
    "My team tried adding a .dtb file to our SD card but said it didn't work." - That's a very poor problem statement. Commented Jun 29, 2017 at 14:03

2 Answers 2

4

You only need to think about adding Device Tree support under following conditions:

  • you know how to write operating systems
  • you are currently in the process of writing an operating system
  • your operating system has to run on multiple different ARM devices, not only the Raspberry Pi
  • your devices do not offer ACPI and have peripherals which cannot be enumerated over an bus (unlike PCI and USB devices)
  • you want to leverage code and work which is mainly Linux-focused

Device Tree was invented so that Linux users don't need to compile a different kernel for each different ARM board out there. The idea is that the same kernel reads different DTB files and loads the appropriate drivers instead. On the x86 platform Linux could rely on the high degree of standardization which simply doesn't exist in the ARM world.

So far i know the only operating systems using device tree are Linux and FreeBSD.

If your OS doesn't support flattened device trees, you must add the support yourself. DTB files are specific to a board and describe the CPU, memory map, on-board peripherals and in the case of the Pi things connected via GPIO too.

DTB files are compiled from DTS files via dtc, the device tree compiler. The dtc project also maintains libfdt , which can parse DTB files.

The most experience on ATAG parsing on the Pi is probably concentrated in the bare metal forum on raspberrypi.org , along with people versed in OS development for the Raspberry Pi.

Most documentation on device tree will be for Linux.

1

I've run across your (now old-ish) question during my research on a related subject. Creating your own device tree may be an ambitious undertaking, and beyond the scope of Q&A here. But your question indicated that "something to read" might be of help. So here are a few things:

  1. This document provides an overview of how to write a device tree for a new machine. The key word being overview. I think it's a reasonable place to get a "birds-eye view" of the device tree.

  2. I will hazard a guess - without knowing what it is you're trying to do - that you may find it simpler to modify/adapt existing device tree files than creating your own. If that's the case, you may find those in the Raspberry Pi GitHub repos at this location. It's an extensive list; for example this is the "core" device tree source file for the RPi 4B, but it's certainly not the only one.

  3. And speaking of modifications: Since the RPi already has a reasonably extensive (that's a guess since RPi hardware is proprietary to Broadcom & The Foundation) device tree, maybe all you need is to create an overlay to the existing device tree - a much simpler (but non-trivial) task than a complete tree. I 'bookmarked' this blog post; it was informative, current and included other references that are also useful.

  4. You'll want to read the "Official Documentation". There are two pages in particular: Device Trees, overlays, and parameters, and Changing the default pin configuration.

  5. You will find your "compiled" device tree (.dtb) on your RPi in /boot - there may be several: ls -l /boot | grep .dtb. There are a couple of tools that will allow you to see the source version of these .dtb files:

    • dtc is the device tree compiler; man dtc explains how
    • fdtdump will output a readable version of a .dtb file

That will get you started. There are a lot more resources available for the cost of an Internet search.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.