diff mbox series

[RFC,1/2] linux: install in-tree device-tree blob overlays

Message ID 20240412140945.1626579-2-gael.portay@rtone.fr
State New
Headers show
Series linux: install in-tree device-tree blob overlays | expand

Commit Message

Gaël PORTAY April 12, 2024, 2:09 p.m. UTC
The device-tree blob overlays are automatically built from the custom
raspberrypi linux tree (for both architectures arm and arm64).

The device-tree overlays is mostly a downstream feature even though the
upstream kernel generates the symbols node into the device-tree blobs it
compiles (thanks to the option -@ in the DTC_FLAGS); and it does not
have intree device-tree overlays.

Note: The device-tree overlays require the node __symbols__ to be part
of the device-tree blob to get successfully loaded at runtime if the
overlaied nodes make reference to symbols from the original devicetree
blob.

The kernel image and the device-tree blobs for the raspberrypi boards
are built from the downstream linux package, and the device-tree blob
overlays are taken from the package rpi-firmware. Both packages linux
and rpi-firmware have to be closely synced.

The buildroot tree maintains the packages and the board configurations,
and it keeps things synced.

The downstream configurations in br2-external trees require to pay
attention to that synchronization as well. If the files are out-of-sync,
(i.e. the dtbos in the rpi-firmware package from the buildroot tree do
not match the linux commit in the br2-external tree), then the boot may
fail.

Since the Raspberry Pi's with Bluetooth have no dedicated debugging UART,
they require to merge the bt-miniuart.dtbo to restore the UART0 to the
accessible GPIOs of 40-pin GPIO header.

The investigation of the boot failure is comlicated if the root cause is
due to the out-of-sync merge of the debugging uart's dtbo to the dtb and
if firmware bootloader does not output the debug traces.

	MESS:00:00:05.389885:0: brfs: File read: /mfs/sd/overlays/miniuart-bt.dtbo
	MESS:00:00:05.408881:0: dterror: can't find symbol 'uart1_bt_pins'
	MESS:00:00:05.411942:0: Failed to resolve overlay 'miniuart-bt'

All this long story to introduce the three new dtbos configs to build
in-tree or out-of-tree dtbos, and to keep the directory name (assuming
the downstream trees uses the directory name overlays).

The three configs are the equivalent to existing dts configs:
 - BR2_LINUX_KERNEL_INTREE_DTS_OVERLAY_NAMES is equivalent to
   BR2_LINUX_KERNEL_INTREE_DTS_NAME
 - BR2_LINUX_KERNEL_CUSTOM_DTS_OVERLAY_PATH is equivalent to
   BR2_LINUX_KERNEL_CUSTOM_DTS_PATH
 - BR2_LINUX_KERNEL_DTBO_KEEP_DIRNAME is equivalent to
   BR2_LINUX_KERNEL_DTB_KEEP_DIRNAME

Signed-off-by: Gaël PORTAY <gael.portay@rtone.fr>
---
 linux/Config.in | 23 +++++++++++++++++++++++
 linux/linux.mk  | 24 ++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

--
2.44.0
diff mbox series

Patch

diff --git a/linux/Config.in b/linux/Config.in
index 2767b709d4..fdd57e6ff9 100644
--- a/linux/Config.in
+++ b/linux/Config.in
@@ -434,6 +434,29 @@  config BR2_LINUX_KERNEL_DTB_OVERLAY_SUPPORT
 	  Choose this option to support Device Tree overlays
 	  on the target system.

+config BR2_LINUX_KERNEL_INTREE_DTS_OVERLAY_NAMES
+	string "In-tree Device Tree Source Overlay file names"
+	depends on BR2_LINUX_KERNEL_DTB_OVERLAY_SUPPORT
+	help
+	  Name of in-tree device tree source file, without
+	  the trailing -overlay.dts. You can provide a list of
+	  dts files to build, separated by spaces.
+
+config BR2_LINUX_KERNEL_CUSTOM_DTS_OVERLAY_PATH
+	string "Out-of-tree Device Tree Source Overlay file paths"
+	help
+	  Paths to out-of-tree Device Tree Source Overlay (-overlay.dts)
+	  and Device Tree Source Include (.dtsi) files, separated by
+	  spaces. These files will be copied to the kernel sources and
+	  the .dts files will be compiled from there.
+
+config BR2_LINUX_KERNEL_DTBO_KEEP_DIRNAME
+	bool "Keep the directory name of the Device Tree Overlay"
+	help
+	  If enabled, the device tree blob overlays keep their
+	  directory prefixes when they get copied to the
+	  output image directory or the target directory.
+
 endif

 config BR2_LINUX_KERNEL_INSTALL_TARGET
diff --git a/linux/linux.mk b/linux/linux.mk
index 4e12b36c1f..8b3563394d 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -199,6 +199,14 @@  LINUX_DTS_NAME += $(basename $(filter %.dts,$(notdir $(call qstrip,$(BR2_LINUX_K

 LINUX_DTBS = $(addsuffix .dtb,$(LINUX_DTS_NAME))

+ifeq ($(BR2_LINUX_KERNEL_DTB_OVERLAY_SUPPORT),y)
+LINUX_DTS_OVERLAY_NAMES += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_OVERLAY_NAMES))
+
+LINUX_DTS_OVERLAY_NAMES += $(basename $(filter %-overlay.dts,$(notdir $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_OVERLAY_PATH)))))
+
+LINUX_DTBOS = $(addsuffix .dtbo,$(LINUX_DTS_OVERLAY_NAMES))
+endif
+
 ifeq ($(BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM),y)
 LINUX_IMAGE_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_NAME))
 LINUX_TARGET_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_TARGET_NAME))
@@ -459,10 +467,23 @@  define LINUX_INSTALL_DTB
 			$(1)/$(if $(BR2_LINUX_KERNEL_DTB_KEEP_DIRNAME),$(dtb),$(notdir $(dtb)))
 	)
 endef
+define LINUX_INSTALL_DTBO
+	$(foreach dtbo,$(LINUX_DTBOS), \
+		install -D \
+			$(wildcard $(LINUX_ARCH_PATH)/boot/dts/$(dtbo)) \
+			$(1)/$(if $(BR2_LINUX_KERNEL_DTBO_KEEP_DIRNAME),$(dtbo),$(notdir $(dtbo)))
+	)
+endef
 endif # BR2_LINUX_KERNEL_APPENDED_DTB
 endif # BR2_LINUX_KERNEL_DTB_IS_SELF_BUILT
 endif # BR2_LINUX_KERNEL_DTS_SUPPORT

+ifeq ($(BR2_LINUX_KERNEL_DTS_OVERLAY_SUPPORT),y)
+define LINUX_BUILD_DTBO
+	$(LINUX_MAKE_ENV) $(BR2_MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_DTBOS)
+endef
+endif # BR2_LINUX_KERNEL_DTS_OVERLAY_SUPPORT
+
 ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),y)
 # dtbs moved from arch/$ARCH/boot to arch/$ARCH/boot/dts since 3.8-rc1
 define LINUX_APPEND_DTB
@@ -509,6 +530,7 @@  define LINUX_BUILD_CMDS
 	$(LINUX_MAKE_ENV) $(BR2_MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_TARGET_NAME)
 	$(LINUX_BUILD_DTB)
 	$(LINUX_APPEND_DTB)
+	$(LINUX_BUILD_DTBO)
 endef

 ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),y)
@@ -530,6 +552,7 @@  ifeq ($(BR2_LINUX_KERNEL_INSTALL_TARGET),y)
 define LINUX_INSTALL_KERNEL_IMAGE_TO_TARGET
 	$(call LINUX_INSTALL_IMAGE,$(TARGET_DIR)/boot)
 	$(call LINUX_INSTALL_DTB,$(TARGET_DIR)/boot)
+	$(call LINUX_INSTALL_DTBO,$(TARGET_DIR)/boot/overlays)
 endef
 endif

@@ -544,6 +567,7 @@  endef
 define LINUX_INSTALL_IMAGES_CMDS
 	$(call LINUX_INSTALL_IMAGE,$(BINARIES_DIR))
 	$(call LINUX_INSTALL_DTB,$(BINARIES_DIR))
+	$(call LINUX_INSTALL_DTBO,$(BINARIES_DIR))
 endef

 ifeq ($(BR2_STRIP_strip),y)