> From: Casey Connolly <casey.conno...@linaro.org> > Date: Tue, 10 Jun 2025 18:23:33 +0200
Hi Casey, > Since we're using the upstream file structure, we know at build time > the path to each DTB that we build. These same paths are used relative > to some (maybe version specific) dtb directory on the boot partition > or ESP. > > By recording this path at build time and embedding it into the > devicetree, we can set the fdtfile environment variable with 100% > certainty that it is correct. > > Devicetree file names are already treated as stable kernel API upstream, > since they are used by OS loaders extensively. But when something similar was suggested some time ago, the Linux kernel folks explicitly stated that the file names are ~*not* considered to be ABI. So I think this proposal should be discussed in a broader context, probably on the devicetree-s...@vger.kernel.org mailing list. > Embedding the path into the devicetree itself just simplifies the > process and allows U-Boot or the OS loader to select a devicetree of a > different version for the specific board that U-Boot is running on. > > Signed-off-by: Casey Connolly <casey.conno...@linaro.org> > --- > scripts/Makefile.lib | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib > index > e89a4a51b74ddccfd9f0a6463cdeded12eaa5235..1f95bda0597c14d2ee785eb8058d607a6c819a56 > 100644 > --- a/scripts/Makefile.lib > +++ b/scripts/Makefile.lib > @@ -360,16 +360,31 @@ $(obj)/%.dtbo.S: $(obj)/%.dtbo > ifeq ($(CONFIG_OF_LIBFDT_OVERLAY),y) > DTC_FLAGS += -@ > endif > > +ifeq ($(CONFIG_ARM64),y) > +dt_dir := dts/upstream/src/arm64 > +else > +dt_dir := dts/upstream/src/$(ARCH) > +endif > + > +ifeq ($(CONFIG_OF_UPSTREAM),y) > +# Embed the upstream path to the DTB into it as /chosen/fdtfile. This > property is used > +# at runtime to set the fdtfile variable > +dt_extra_snippet = / { chosen { fdtfile = "$(subst $(dt_dir)/,,$@)"; }; }; > +else > +dt_extra_snippet = > +endif > + > quiet_cmd_dtc = DTC $@ > # Modified for U-Boot > # Bring in any U-Boot-specific include at the end of the file > # And finally any custom .dtsi fragments specified with > CONFIG_DEVICE_TREE_INCLUDES > cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \ > (cat $< > $(pre-tmp)); \ > $(foreach f,$(subst $(quote),,$(dtsi_include_list) > $(CONFIG_DEVICE_TREE_INCLUDES)), \ > echo '$(pound)include "$(f)"' >> $(pre-tmp);) \ > + [[ -z "$(dt_extra_snippet)" ]] || echo '$(dt_extra_snippet)' >> > $(pre-tmp); \ > $(HOSTCC) -E $(dtc_cpp_flags) -I$(obj) -x assembler-with-cpp -o > $(dtc-tmp) $(pre-tmp) ; \ > $(DTC) -O dtb -o $@ -b 0 \ > -i $(dir $<) -i $(u_boot_dtsi_loc) $(DTC_FLAGS) \ > -d $(depfile).dtc.tmp $(dtc-tmp) || \ > > -- > 2.49.0 > >