Add custom modification into prebuilt DTB

Dear Community,

I would like to know if there’s a good way to append modification of dts into a dtb file of a commercial Jetson Xaver NX carrier board, please ? For example, I’m bringing up custom camera drivers and I would like to add the modification for these drivers while keeping the rest provided by the board’s maker.

Thanks in advance and best regards,
Khang.

You’d need to experiment, and this isn’t a full answer, but here is some trivia which will probably help:

  • Device trees are used in the “.dtb” binary format. The source code is human readable “.dts” format.
  • The “dtc” application (which you can add via “sudo apt-get install device-tree-compiler” if you don’t have it) can convert those formats. dtc can also extract the kernel’s current idea of what tree it runs via the right command.
  • To extract a running system’s tree:
    dtc -I fs -O dts -o extracted.dts /proc/device-tree
  • The actual tree used is probably best discovered by logging a flash and monitoring the log.
  • The tree might be located in a partition (in which case it is also signed, and signing would need to be removed before using dtc to modify it), or from somewhere in “/boot” if the “/boot/extlinux/extlinux.conf” “FDT” entry exists.
  • The tree can be used in earlier boot stages. The content would be inherited during load of the Linux kernel via the “extlinux.conf”'s “${cboot}” environment variable (and inheriting hardware state).
  • It is possible that the earlier boot stages will slightly edit the entry before passing on to Linux. Mostly though there won’t be much difference. That possibility of difference though implies it is usually best to start with the actual tree used rather than with an extracted tree.
  • What is your “extlinux.conf” content? If this does not mention FDT, then this is the best/easiest place to develop a tree. By default most systems will start with the tree in the partition. If you know the correct tree, and do not have the FDT entry, then you could add that entry and you would be essentially loading the same tree. Then you could edit that as a test without touching the partition version (which would need flash software). If you find the edit, you could then use the edited tree to flash the partition. The partition version is mandatory if security fuses have been burned.
  • Device tree is not really part of the kernel, but is instead what you could think of as custom arguments to drivers as they load. This allows different tweaks of hardware layout without adding every single one into the actual kernel source. Thus the tree content is related to whatever drivers the kernel has set. For this reason, if you are set up to build an exact duplicate configuration of your running kernel, then building the “make dtbs” target would build any tree related to this. One of those would be for your particular combination of carrier board and module, and would also be the same as what the system ships with.
  • In kernel source a build pieces together bits of tree (usually via something which is a fragment of a tree) into a single monolithic file. If you edit those pieces you get your modification, but this would in theory be the same as reverse compiling the large monolithic binary tree and editing that, then recompiling it back to binary format. An example work flow with dtc:
    1. Find your tree name, e.g., “some-tree.dtb”.
    2. Turn this into source, e.g., “dtc -I dtb -O dts -o some-tree.dts some-tree.dtb”.
    3. Edit the source, “some-tree.dts”, then recompile via:
      dtc -I dts -O dtb -o some-tree-modified.dtb some-tree.dts”.
    4. Install that in any available format, e.g., put in in:
      /boot/some-tree-modified.dtb
      …then add this in your extlinux.conf boot:
      FDT /boot/some-tree-modified.dtb
    5. Preferable the above adds a new entry and leaves the old one in place, which gives you the ability to use serial console to pick which one is used at boot (if it fails to boot you could use the original entry). It is very highly recommended to have serial console available before working on such things.
  • Note that an overlay is only intended to edit existing nodes in the tree. If you edit the source file (the .dts), then you can also add new nodes.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.