]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
kbuild: Produce diff between base DT and U-Boot augmented DT if DEVICE_TREE_DEBUG=1
authorMarek Vasut <marek.vasut+renesas@mailbox.org>
Fri, 19 Dec 2025 02:40:44 +0000 (03:40 +0100)
committerTom Rini <trini@konsulko.com>
Mon, 5 Jan 2026 15:02:19 +0000 (09:02 -0600)
In case DEVICE_TREE_DEBUG is set, produce a diff between the base DT and
DT with U-Boot extras, to show how much does the U-Boot DT differ from
the base DT. This is particularly useful together with OF_UPSTREAM, to
minimize the diff between upstream DTs and U-Boot DTs.

This requires DTC 1.7.2 which does not resolve phandles when used in
the 'dtc -I dts -O dts ...' mode. With older DTC, the diff is full of
churn due to the resolved phandles.

Example usage:
$ make r8a779g3_sparrowhawk_defconfig && make DEVICE_TREE_DEBUG=1
$ cat ./dts/upstream/src/arm64/renesas/r8a779g3-sparrow-hawk.dtb.diff

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
scripts/Makefile.lib

index ebac649d39ae38eafc6a9e55932a6a539a91c66f..377a4700b9408fa280159f86543854a10ad648c9 100644 (file)
@@ -424,6 +424,26 @@ ifeq ($(CONFIG_OF_LIBFDT_OVERLAY),y)
 DTC_FLAGS += -@
 endif
 
+# In case DEVICE_TREE_DEBUG is set, produce a diff between the base DT and
+# DT with U-Boot extras, to show how much does the U-Boot DT differ from
+# the base DT. This is particularly useful together with OF_UPSTREAM, to
+# minimize the diff between upstream DTs and U-Boot DTs.
+ifdef DEVICE_TREE_DEBUG
+cmd_dtc_diff = \
+       $(HOSTCC) -E $(dtc_cpp_flags) -I$(obj) -x assembler-with-cpp -o $(dtn-tmp) $< ; \
+       $(DTC) -s -O dts -o $@.clean.dts -b 0 \
+               -i $(dir $<) $(DTC_FLAGS) $(dtn-tmp) || \
+               (echo "Check $(shell pwd)/$< for errors" && false); \
+       $(DTC) -s -O dts -o $@.full.dts -b 0 \
+               -i $(dir $<) -i $(u_boot_dtsi_loc) $(DTC_FLAGS) $(dtc-tmp) || \
+               (echo "Check $(shell pwd)/$(pre-tmp) for errors" && false); \
+       (diff -Naru $@.clean.dts $@.full.dts > $@.diff || true)
+
+dtn-tmp = $(subst $(comma),_,$(dot-target).dtn.tmp)
+else
+cmd_dtc_diff = true
+endif
+
 quiet_cmd_dtc = DTC     $@
 # Modified for U-Boot
 # Bring in any U-Boot-specific include at the end of the file
@@ -438,7 +458,8 @@ cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
                -d $(depfile).dtc.tmp $(dtc-tmp) || \
                (echo "Check $(shell pwd)/$(pre-tmp) for errors" && false) \
                ; \
-       sed "s:$(pre-tmp):$(<):" $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
+       sed "s:$(pre-tmp):$(<):" $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) ; \
+       $(cmd_dtc_diff)
 
 dtsi_include_list_deps := $(addprefix $(u_boot_dtsi_loc),$(subst $(quote),,$(dtsi_include_list)))