I can confirm that the device tree overlay mechanism essentially works as implemented in the SDK sources, I had previously made a typo.
To make it functional (as in: it selects different overlays depending on runtime detection of hardware), the following changes are needed:
-
Add all the different overlay files in
common/arch/arm64/boot/dts/amlogic/ -
Edit
device/khadas/common/kernelbuild/build.shunder"===build dtbo==="section to include all overlay files in the dtbo.img. Currently only the file defined bydevice/khadas/kvim4/build.config.meson.arm64.trunk:DTBO_DEVICETREEis included in the build. -
Create and execute a u-boot command/script during the CONFIG_PREBOOT stage that detects the hardware and selects the correct device tree overlay index by calling
setenv androidboot.dtbo_idx <selected index>; -
Even if
device/khadas/kvim4/BoardConfig.mk:BOARD_KERNEL_CMDLINE += androidboot.dtbo_idx=0is defined at build time the runtime variable will take precedence based on the code inbootloader/uboot/common/image-android.c:save_dtbo_idx()