Step by step, how to compile DTS with include files

Hi, I’m working on trying to get CoreElec to boot on a FireTV 2nd gen Cube (S922X). I don’t know that Amazon based the Cube board on any of the S922X development boards like the w400. But I would still like to try booting the Cube on the available S922X DTBs for CoreElec to see if any work. The amlogic-dt-id for the Cube is g12brevb_raven_2g (raven is the code name for the Cube). The Cube won’t accept the DTB unless it uses the raven amlogic-dt-id.

So I need to decompile the existing S922X DTB to DTS, change the amlogic-dt-id and recompile to DTB. This is easy enough with the linux dtc tool, but since most of the CoreElec DTBs have include files, I need to compile the DTS files through CoreElec.

So I cloned the repo

  1. GitHub - CoreELEC/coreelec-builder
  2. sudo apt-get update
  3. git clone git://github.com/CoreELEC/CoreELEC.git ~/CoreELEC
  4. cd ~/CoreELEC

And because I only want to compile the DTS files, I built with
5) Project=Amlogic-cd DEVICE=Amlogic-ng ./scripts/build linux:host

Then I got lost. I was told I needed to edit a package.mk file.
Which package.mk file?
What do I edit in it?
And how to I execute/start compiling after i have edited this file?

Just decompile dtb, change/add/remove values, and compile it back. All with dtc tool.

# device tree decompile
dtc -I dtb -O dts source.dtb -o source.dts
fdtdump source.dtb > source.dts

# device tree compile
dtc -I dts -O dtb source.dts -o source.dtb_new
1 Like

I guess he wants to build from a modified dts in the kernel source tree (thus he can include other .dtsi file) without modifying the linux package’s pacakge.mk and constantly rebuild it?
@YadaYada
Then you can create a package at projects/Amlogic-ce/devices/Amlogic-ng/packages/device-tree-firecube, with its package.mk containing the following lines:

PKG_NAME="device-tree-firecube"
PKG_VERSION="1"
PKG_SITE=""
PKG_URL=""
PKG_DEPENDS_TARGET="toolchain"
PKG_DEPENDS_UNPACK="linux"
PKG_LONGDESC="Device trees for Amazon cube"
PKG_IS_KERNEL_PKG="yes"
PKG_TOOLCHAIN="manual"
DTS_PATH="/absolute/path/to/your/dts"
PKG_NEED_UNPACK="${DTS_PATH}"

make_target() {
  pushd "$(get_build_dir linux)" > /dev/null
  cp -f "${DTS_PATH}" "arch/${TARGET_KERNEL_ARCH}/boot/dts/amlogic/"
  DTB_NAME="$(basename "${DTS_PATH}" .dts).dtb"
  kernel_make "${DTB_NAME}"
  cp "arch/${TARGET_KERNEL_ARCH}/boot/dts/amlogic/${DTB_NAME}" "${PKG_BUILD}/"
  popd > /dev/null
}

makeinstall_target() {
  : # Since you are not building a whole pacakge, then there's no much use to install it to image
}

Replace the /absolute/path/to/your/dts to the one you’re tinkering with in the kernel source, for example /home/myuser/development/coreelec-linux-amlogic/arch/arm64/boot/dts/amlogic/firecube.dts

Do this to (re)build the dtb:

PROJECT=Amlogic-ce DEVICE=Amlogic-ng ./scripts/build device-tree-firecube

(You could omit the two vars PROJECT and DEVICE since these are actually their default values, but I don’t know if you are using a version of build system with this feature)

The result dtb will be at build.DISTRO.DEVICE.ARCH.MAJOR/build/device-tree-firecube-1/whatever.dtb
After you update and save that dts file, you can use the same command to rebuild the dtb (Thanks to PKG_NEED_UNPACK)

When the dtb is ready for tests I think it would be a better idea to add the finished dts to linux-amlogic and open a PR to merge into CE’s linux-amlogic repo, instead of keeping it as a single device-tree package

1 Like

Great, thank you both! This gets me far enough to find the next thing that’s not working :smile:

If you make a “protected” device boot CoreELEC please let us know.