[RFC PATCH v2 2/3] of: Add support for -@ when compiling overlays

From: Detlev Casanova
Date: Wed Apr 27 2022 - 15:03:33 EST

This commit adds an option to compile all device trees with -@ to add the
symbol table to the Device Tree Blobs.

It prepares the introduction of device tree overlays that are
not applied on device trees at compile time (dtbo files.)

These device tree overlays will be used by either a bootloader or a
linux userspace tool to extend the base device tree.

This is used e.g. for drivers that need device tree nodes for optional
non plug and play devices, like an external DSI touchscreen panel that
embeds different i2c devices to control it.

Signed-off-by: Detlev Casanova <detlev.casanova@xxxxxxxxxxxxx>
drivers/of/Kconfig | 8 ++++++++
scripts/Makefile.lib | 9 +++++++--
2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 80b5fd44ab1c..28cf8d18ac45 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -76,11 +76,19 @@ config OF_RESERVED_MEM

+config OF_SYMBOLS
+ bool "Include device tree symbols"
+ help
+ Loading a device tree overlay dynamically can require the base
+ device tree symbols to be present.
+ If this is enabled, the device tree blobs will be bigger.
bool "Device Tree overlays"
+ select OF_SYMBOLS
Overlays are a method to dynamically modify part of the kernel's
device tree with dynamically loaded data.
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 79be57fdd32a..4c330e565297 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -319,8 +319,13 @@ endif

DTC_FLAGS += $(DTC_FLAGS_$(basetarget))

-# Set -@ if the target is a base DTB that overlay is applied onto
-DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
+ifeq ($(CONFIG_OF_SYMBOLS),y)
+ # Add symbols in all devicetrees
+ DTC_FLAGS += -@
+ # Set -@ if the target is a base DTB that overlay is applied onto
+ DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)

# Generate an assembly file to wrap the output of the device tree compiler
quiet_cmd_dt_S_dtb= DTB $@