Skip to content

Commit

Permalink
mk/compile.mk: separate rule to produce preprocessed dts files
Browse files Browse the repository at this point in the history
When compiling a .dts into a .dtb, there is a pre-preprocessing phase
where the C preprocessor is run on the .dts to produce a .pre.dts, then
the device tree compiler is called to generate the .dtb. The two phases
are currently bundled into a single makefile recipe, which is not ideal.

Extract the preprocessing commands into a separate recipe to address
this concern. This allows to do for example:

 make PLATFORM=stm32mp1-157A_DK1 \
      out/arm-plat-stm32mp1/core/arch/arm/dts/stm32mp157a-dk1.pre.dts

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
  • Loading branch information
jforissier committed Aug 14, 2024
1 parent ca0b57f commit 9c97e7d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions mk/compile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ define gen-dtb-file
dtb-basename-$2 := $$(basename $$(notdir $2))
dtb-predts-$2 := $$(dir $2)$$(dtb-basename-$2).pre.dts
dtb-predep-$2 := $$(dir $2).$$(dtb-basename-$2).pre.dts.d
dtb-precmd-file-$2 := $$(dir $2).$$(dtb-basename-$2).pre.dts.cmd
dtb-dep-$2 := $$(dir $2).$$(notdir $2).d
dtb-cmd-file-$2 := $$(dir $2).$$(notdir $2).cmd

Expand All @@ -279,27 +280,32 @@ dtb-dtcflags-$2 := $$(DTC_FLAGS) -I dts -O dtb -Wno-unit_address_vs_reg \
-include $$(dtb-dep-$2)
-include $$(dtb-predep-$2)
-include $$(dtb-cmd-file-$2)
-include $$(dtb-precmd-file-$2)

dtb-precmd-$2 = $$(CPP$(sm)) $$(dtb-cppflags-$2) -o $$(dtb-predts-$2) $$<
dtb-cmd-$2 = $$(DTC) $$(dtb-dtcflags-$2) -o $$@ $$(dtb-predts-$2)

$2: $1 FORCE
# Check if any prerequisites are newer than the target and
# check if command line has changed
$$(dtb-predts-$2): $1 FORCE
$$(if $$(strip $$(filter-out FORCE, $$?) \
$$(filter-out $$(dtb-precmd-$2), $$(dtb-old-precmd-$2)) \
$$(filter-out $$(dtb-old-precmd-$2), $$(dtb-precmd-$2)) \
$$(filter-out $$(dtb-cmd-$2), $$(dtb-old-cmd-$2)) \
$$(filter-out $$(dtb-old-cmd-$2), $$(dtb-cmd-$2))), \
$$(filter-out $$(dtb-old-precmd-$2), $$(dtb-precmd-$2))), \
$(q)set -e; \
mkdir -p $$(dir $2); \
$(cmd-echo-silent) ' CPP $$(dtb-predts-$2)'; \
$$(dtb-precmd-$2); \
echo "dtb-old-precmd-$2 := $$(subst \",\\\",$$(dtb-precmd-$2))" > \
$$(dtb-precmd-file-$2) ;\
)

$2: $$(dtb-predts-$2) FORCE
$$(if $$(strip $$(filter-out FORCE, $$?) \
$$(filter-out $$(dtb-cmd-$2), $$(dtb-old-cmd-$2)) \
$$(filter-out $$(dtb-old-cmd-$2), $$(dtb-cmd-$2))), \
$(q)set -e; \
mkdir -p $$(dir $2); \
$(cmd-echo-silent) ' DTC $$@'; \
$$(dtb-cmd-$2); \
echo "dtb-old-precmd-$2 := $$(subst \",\\\",$$(dtb-precmd-$2))" > \
$$(dtb-cmd-file-$2) ;\
echo "dtb-old-cmd-$2 := $$(subst \",\\\",$$(dtb-cmd-$2))" >> \
echo "dtb-old-cmd-$2 := $$(subst \",\\\",$$(dtb-cmd-$2))" > \
$$(dtb-cmd-file-$2) ;\
)

Expand Down

0 comments on commit 9c97e7d

Please sign in to comment.