When CONFIG_MULTI_DTB_FIT is enabled, fit-dtb.blob is produced by
mkimage with one "-b " argument for every entry in CONFIG_OF_LIST.
The make rule, however, only listed dts/dt.dtb (i.e. the
CONFIG_DEFAULT_DEVICE_TREE blob) as a prerequisite:

  fit-dtb.blob: dts/dt.dtb FORCE
      $(call if_changed,mkimage)

Because FORCE is PHONY, if_changed ignores it and rebuilds only when
any-prereq or arg-check is non-empty.  Editing a non-default dts in
OF_LIST rebuilds its .dtb (tracked correctly via fixdep), but that
.dtb was not a prerequisite of fit-dtb.blob, so $? stayed empty; the
mkimage command line was unchanged too, so arg-check was empty as
well.  if_changed therefore skipped mkimage and fit-dtb.blob kept the
stale dtbs.  u-boot.bin, which appends fit-dtb.blob, then shipped the
old device tree and the dts change did not take effect.

A previous attempt to fix this added every OF_LIST .dtb *output* as a
prerequisite.  That is wrong on two counts:

  - Clean build regression: the OF_LIST .dtb files are produced only
    by the recursive dts/dt.dtb -> arch-dtbs sub-make descent and have
    no rule at the top make level, so listing them as prerequisites
    makes them rule-less/intermediate.  After a from-scratch rebuild
    (e.g. wiping an out-of-tree build directory) it fails:

      make[1]: *** No rule to make target 'arch/arm/dts/.dtb',
               needed by 'fit-dtb.blob'.  Stop.

  - Incremental two-build race still present: the .dtb outputs are
    written by a child sub-make descent while the parent make level
    checks prerequisites, so under `make -j` an edit can still need
    two make invocations to take effect.

List the .dts *sources* instead, which the top make level can see via
VPATH in both objtree and srctree.  Use $(dt_dir), as
MKIMAGEFLAGS_fit-dtb.blob already does just below, so that
CONFIG_OF_UPSTREAM boards (whose sources live under dts/upstream/src/)
are handled too; a helper variable keeps the rule under 80 columns.

Limitation: this only catches edits to the top-level .dts files in
OF_LIST.  An edit to an included .dtsi (including the *-u-boot.dtsi
files) rebuilds the .dtb but leaves fit-dtb.blob stale, so the
two-build problem remains in that case.  Fixing that fully would need
the .dtb outputs (rather than the .dts sources) as prerequisites,
which reintroduces the clean-build problem above; covering top-level
.dts edits is already a worthwhile improvement.

Signed-off-by: Lianghong Liu <[email protected]>
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 7f5d83658d7..fec20669607 100644
--- a/Makefile
+++ b/Makefile
@@ -1475,7 +1475,8 @@ fit-dtb.blob.gz: fit-dtb.blob
 fit-dtb.blob.lzo: fit-dtb.blob
        @lzop -f9 $< > $@
 
-fit-dtb.blob: dts/dt.dtb FORCE
+of_list_srcs := $(patsubst %,$(dt_dir)/%.dts,$(subst ",,$(CONFIG_OF_LIST)))
+fit-dtb.blob: dts/dt.dtb $(of_list_srcs) FORCE
        $(call if_changed,mkimage)
 ifneq ($(SOURCE_DATE_EPOCH),)
        touch -d @$(SOURCE_DATE_EPOCH) fit-dtb.blob
-- 
2.34.1

Reply via email to