23

Bootloaders like U-Boot that do not implement the Open Firmware API, are expected to pass to the kernel a binary form of the flattened device tree - LinuxFDTBlob

Why are the DTS files present in the kernel as well? Isn't that redundant?

As an example, U-boot source code has following file:
arch/arm/dts/tegra124-jetson-tk1.dts

This file can also be found under Linux source code:
arch/arm/boot/dts/tegra124-jetson-tk1.dts

Although the kernel version is 4 times the U-boot version, I would like to know the reason behind this redundancy. I believe it is harder to maintain and use both for the maintainers and the developers

Hamzahfrq
  • 696
  • 1
  • 6
  • 25
  • 2
    It's an issue that [people have been trying to work out how to resolve for quite some time](http://thread.gmane.org/gmane.comp.devicetree.compiler/14). – Notlikethat Jun 08 '15 at 20:23
  • it looks like the didn't complete the migration when they almost found a solution :| – Hamzahfrq Jun 09 '15 at 07:39
  • 4
    They are for different purposes. The *u-boot* version allows different version of *u-boot* to run on several boards. It is part of a [tag:kbuild] or *config* infrastructure that is a WIP. The Linux versions are for booting Linux. Obviously, the *u-boot* is a stripped down version as there are not as many peripherals needed to boot. You can make the same argument for all the *u-boot* drivers; most are copies of the Linux drivers with interrupts replaced by polling routines. Why does BSD and Linux exist? Don't they duplicate each other? Why does every project have it's own linked list? – artless noise Jun 09 '15 at 14:09
  • 2
    @artlessnoise What I've understood from your comment is that u-boot uses its dtb for initial hardware init and Linux uses its dtb when kernel boots. Please elaborate one more point i.e. which dtb is passed by u-boot to Linux kernel at boot time. – Hamzahfrq Jun 09 '15 at 15:03
  • 1
    The *u-boot* source uses the u-boot DTB. You always use the kernel version for Linux; Ie, *u-boot* passes this one to Linux (as well as load bzImage or *vmlinux*). Many of the *u-boot* drivers are almost identical to Linux. Using the same open-firmware interface enables them to match closer. – artless noise Jun 09 '15 at 16:27
  • @artlessnoise that answers my question. I could select it as an answer if you could post it – Hamzahfrq Jun 10 '15 at 08:51

3 Answers3

13

Below is the answer from the comments of Artlessnoise:

The u-boot source uses the u-boot DTB while Linux uses Linux DTB when kernel boots. The u-boot version is a stripped down version as there are not as many peripherals needed to boot. You always use the kernel version for Linux i.e. u-boot passes this one to Linux (as well as load bzImage or vmlinux).

Many of the u-boot drivers are almost identical to Linux. Obviously, you can make the same argument for all the u-boot drivers; most are copies of the Linux drivers with interrupts replaced by polling routines. Using the same open-firmware interface enables them to match closer.

Hamzahfrq
  • 696
  • 1
  • 6
  • 25
  • 2
    So then does Linux completely ignore the device tree passed from u-boot? Or is the linux device tree layered on top of the u-boot device tree, and then linux uses that merged tree? It feels like this question never got answered. – Chris Warth Jan 18 '17 at 17:55
  • 1
    Yes linux ignores the device tree which is in u-boot. linux device tree comes after kernel part. it is like u-boot->Kernel->dtb->rootfs – seereddi sekhar Mar 21 '17 at 09:05
  • 5
    @ChrisWarth Linux kernel _uses_ the DTB passed by u-boot. But the DTB passed by u-boot is not the uboot's DTB. It is the Kernel's DTB (present in kernel sources). The uboot DTB is used by uboot during boot-up, to configure the devices, before the kernel is even loaded in memory – Hamzahfrq Mar 08 '18 at 15:03
  • 1
    @Hamzahfrq This clears things out signifficantly! – 71GA Jan 21 '22 at 10:54
6
  1. UBoot and Linux Kernel are two different projects. So they would require different copies for managing their separate projects.
  2. Linux kernels can be booted with other bootloaders as well. There are other ways to pass DTB to the linux kernel, eg. the kernel image can be appended with DTB it needs to use.

Because of the above mentioned reasons it makes sense to replicate copies of the DTS.

  • 2
    yea but it makes more sense to me if the bootloader and kernel are independent of the hardware details i.e. same device tree which is properly maintained should work for both of them – Hamzahfrq Jun 09 '15 at 07:40
  • 1
    In an ideal world yes, they should have been shared. Device tree was linux's answer to un-maintainable ARM SoC ports by different companies. Technically linux folks maintain their DTS files. Uboot will only be concerned about few aspects of the DTS such as arch type, memory, storage mechanism etc; While the Linux DTS needs to be exhaustive. So now it becomes a question of politics and logstics; who will maintain what and where; rather than technical feasibility. Personal opinion, this duplication will continue to be, until the arm device discovery is standardized (like PCI) – Arun Valiaparambil Jun 09 '15 at 14:08
3

Uboot has separate DTS file, which can be set as CONFIG_DEFAULT_DEVICE_TREE in uboot defconfig. This DTS file is built with uboot image, meaning it is a part of uboot image. Syntax of uboot DTS file is same as Linux kernel DTS file. Linux DTS file is compiled into DTB file and used as separately for parsing hardware configuration by Linux kernel. Linux DTB image is flashed separately from Linux kernel image.