mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/1] kbuild: dtc: Allow adding device tree fragments via config
@ 2021-09-22 18:13 Trent Piepho
  2021-10-01 12:52 ` Sascha Hauer
  2022-01-26 12:29 ` Antony Pavlov
  0 siblings, 2 replies; 4+ messages in thread
From: Trent Piepho @ 2021-09-22 18:13 UTC (permalink / raw)
  To: barebox; +Cc: Trent Piepho

This introduces a config variable that allows adding additional fragments
to the Barebox device tree(s).

Example uses are adjusting the flash partition layout, adding barebox
state variables, or adding an I2C device.  These can be now be done with
build configuration only, without needing to patch the existing dts
files in the Barebox source.

The advantage is greater when an external build system, such as Yocto or
Buildroot, is being used to build Barebox.  The build system can drop in
a dts fragment to partition flash and build from unaltered Barebox
source.  This avoids the need for cumbersome maintenance of patch files
to modify Barebox's source for each flash partition layout.

Preprocessing the dts file gains another layer, where a generated dts
source consisting of an include directive for the original dts source is
followed by more includes for each fragment.  This is piped to the
existing preprocessor call on stdin to avoid another temporary file.
cpp/dtc will correctly identify errors in the source files they occur
in.  The -MT option is used so the cpp auto-dependencies reference the
original dts source and not the generated code passed on stdin.

A preprocessor macro named after the base dts file, e.g. foo-bar.dts
will define foo_bar_dts, will be defined so that the fragments can
possibly operate differently based on which image's dts is being built.

Signed-off-by: Trent Piepho <trent.piepho@igorinstitute.com>
---
Changes from v1:
  - Remove 2nd config variable for in-tree fragments.
  - Add macro to preproccessed dts

 common/Kconfig       | 18 ++++++++++++++++++
 scripts/Makefile.lib |  8 +++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/common/Kconfig b/common/Kconfig
index a9feae2ae..6fdc14148 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1091,6 +1091,24 @@ config SYSTEMD_OF_WATCHDOG
 	  in the kernel device tree. If the kernel is booted without a device
 	  tree or with one that lacks aliases, nothing is added.
 
+config EXTERNAL_DTS_FRAGMENTS
+	string "external dts file fragments"
+	depends on OFTREE
+	help
+	  List of dts fragment files that will be appended to Barebox's device
+	  tree(s) source when building the dtb file(s).  If multiple files are
+	  listed, they will be appended in order.  Relative filenames will use
+	  the dtc include search path.
+
+	  A preprocessor macro based on the name of the main dts will be
+	  defined, which allows the dts fragments to based on which image of a
+	  multi image build they are being used in.
+
+	  It not intended that this be put into into Barebox defconfig files.
+	  Instead, it's an external build system, like Yocto or buildroot, to
+	  add dts fragments from outside the Barebox source tree into the
+	  Barebox build.
+
 menu "OP-TEE loading"
 
 config OPTEE_SIZE
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 80d76b177..4496f1a70 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -201,6 +201,7 @@ cpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(__cpp_flags)
 ld_flags       = $(KBUILD_LDFLAGS) $(ldflags-y)
 
 dtc_cpp_flags  = -Wp,-MD,$(depfile).pre -nostdinc                        \
+		 -Wp,-MT,$(basename $(notdir $@)).o                      \
 		 -I$(srctree)/arch/$(SRCARCH)/dts/include		 \
 		 -I$(srctree)/dts/include                                \
 		 -I$(srctree)/include                                    \
@@ -335,8 +336,13 @@ cmd_dt_S_dtb = $(srctree)/scripts/gen-dtb-s $(subst -,_,$(*F)) $< $(CONFIG_IMD)
 $(obj)/%.dtb.S: $(obj)/%.dtb $(srctree)/scripts/gen-dtb-s FORCE
 	$(call if_changed,dt_S_dtb)
 
+dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
 quiet_cmd_dtc = DTC     $@
-cmd_dtc = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
+# For compatibility between make 4.2 and 4.3
+H := \#
+cmd_dtc = /bin/echo -e '$(H)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(dts-frags),'$(H)include "$(f)"\n') | \
+	$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
 	$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
 		-i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \
 		-i $(srctree)/dts/src/$(SRCARCH) \
-- 
2.31.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] kbuild: dtc: Allow adding device tree fragments via config
  2021-09-22 18:13 [PATCH v2 1/1] kbuild: dtc: Allow adding device tree fragments via config Trent Piepho
@ 2021-10-01 12:52 ` Sascha Hauer
  2022-01-26 12:29 ` Antony Pavlov
  1 sibling, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2021-10-01 12:52 UTC (permalink / raw)
  To: Trent Piepho; +Cc: barebox

Hi Trent,

On Wed, Sep 22, 2021 at 11:13:36AM -0700, Trent Piepho wrote:
> This introduces a config variable that allows adding additional fragments
> to the Barebox device tree(s).
> 
> Example uses are adjusting the flash partition layout, adding barebox
> state variables, or adding an I2C device.  These can be now be done with
> build configuration only, without needing to patch the existing dts
> files in the Barebox source.
> 
> The advantage is greater when an external build system, such as Yocto or
> Buildroot, is being used to build Barebox.  The build system can drop in
> a dts fragment to partition flash and build from unaltered Barebox
> source.  This avoids the need for cumbersome maintenance of patch files
> to modify Barebox's source for each flash partition layout.
> 
> Preprocessing the dts file gains another layer, where a generated dts
> source consisting of an include directive for the original dts source is
> followed by more includes for each fragment.  This is piped to the
> existing preprocessor call on stdin to avoid another temporary file.
> cpp/dtc will correctly identify errors in the source files they occur
> in.  The -MT option is used so the cpp auto-dependencies reference the
> original dts source and not the generated code passed on stdin.
> 
> A preprocessor macro named after the base dts file, e.g. foo-bar.dts
> will define foo_bar_dts, will be defined so that the fragments can
> possibly operate differently based on which image's dts is being built.
> 
> Signed-off-by: Trent Piepho <trent.piepho@igorinstitute.com>
> ---
> Changes from v1:
>   - Remove 2nd config variable for in-tree fragments.
>   - Add macro to preproccessed dts

I tested this myself and it works as expected. Applied with a little
change

> +config EXTERNAL_DTS_FRAGMENTS
> +	string "external dts file fragments"
> +	depends on OFTREE
> +	help
> +	  List of dts fragment files that will be appended to Barebox's device
> +	  tree(s) source when building the dtb file(s).  If multiple files are
> +	  listed, they will be appended in order.  Relative filenames will use
> +	  the dtc include search path.
> +
> +	  A preprocessor macro based on the name of the main dts will be
> +	  defined, which allows the dts fragments to based on which image of a
> +	  multi image build they are being used in.

Changed this to:

	  A preprocessor macro based on the name of the main dts will be
	  defined, which allows the dts fragments to based on which image of a
	  multi image build they are being used in. Given the dts filename
	  used for a board is "foo-board.dts" the external dts usage can be
	  limited to that board with

	  #ifdef foo_board_dts
	  ...
	  #endif

To make that point a little more clear.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] kbuild: dtc: Allow adding device tree fragments via config
  2021-09-22 18:13 [PATCH v2 1/1] kbuild: dtc: Allow adding device tree fragments via config Trent Piepho
  2021-10-01 12:52 ` Sascha Hauer
@ 2022-01-26 12:29 ` Antony Pavlov
  2022-01-26 22:10   ` Trent Piepho
  1 sibling, 1 reply; 4+ messages in thread
From: Antony Pavlov @ 2022-01-26 12:29 UTC (permalink / raw)
  To: Trent Piepho; +Cc: barebox, Sascha Hauer, Ahmad Fatoum

On Wed, 22 Sep 2021 11:13:36 -0700
Trent Piepho <trent.piepho@igorinstitute.com> wrote:

Hi!

This patch was applied to barebox source tree as 
  
  2ae7ac7ab2 kbuild: dtc: Allow adding device tree fragments via config

With this patch I see build error if device tree file name starts with digit (0-9),
e.g.:

  barebox$ git checkout v2022.01.0

  barebox$ make mrproper

  barebox$ export ARCH=arm
  barebox$ export CROSS_COMPILE=arm-none-eabi-
  barebox$ sed -i "s/virt2real.dtb/2virt2real.dtb/" arch/arm/dts/Makefile
  barebox$ mv arch/arm/dts/virt2real.dts arch/arm/dts/2virt2real.dts

  barebox$ make virt2real_defconfig
  ...
  barebox$ make -s
  <stdin>:1:9: error: macro names must be identifiers                                              make[1]:  [scripts/Makefile.lib:352: arch/arm/dts/2virt2real.dtb] Error 1
  make:  [Makefile:952: arch/arm/dts] Error 2




> This introduces a config variable that allows adding additional fragments
> to the Barebox device tree(s).
> 
> Example uses are adjusting the flash partition layout, adding barebox
> state variables, or adding an I2C device.  These can be now be done with
> build configuration only, without needing to patch the existing dts
> files in the Barebox source.
> 
> The advantage is greater when an external build system, such as Yocto or
> Buildroot, is being used to build Barebox.  The build system can drop in
> a dts fragment to partition flash and build from unaltered Barebox
> source.  This avoids the need for cumbersome maintenance of patch files
> to modify Barebox's source for each flash partition layout.
> 
> Preprocessing the dts file gains another layer, where a generated dts
> source consisting of an include directive for the original dts source is
> followed by more includes for each fragment.  This is piped to the
> existing preprocessor call on stdin to avoid another temporary file.
> cpp/dtc will correctly identify errors in the source files they occur
> in.  The -MT option is used so the cpp auto-dependencies reference the
> original dts source and not the generated code passed on stdin.
> 
> A preprocessor macro named after the base dts file, e.g. foo-bar.dts
> will define foo_bar_dts, will be defined so that the fragments can
> possibly operate differently based on which image's dts is being built.
> 
> Signed-off-by: Trent Piepho <trent.piepho@igorinstitute.com>
> ---
> Changes from v1:
>   - Remove 2nd config variable for in-tree fragments.
>   - Add macro to preproccessed dts
> 
>  common/Kconfig       | 18 ++++++++++++++++++
>  scripts/Makefile.lib |  8 +++++++-
>  2 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/common/Kconfig b/common/Kconfig
> index a9feae2ae..6fdc14148 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -1091,6 +1091,24 @@ config SYSTEMD_OF_WATCHDOG
>  	  in the kernel device tree. If the kernel is booted without a device
>  	  tree or with one that lacks aliases, nothing is added.
>  
> +config EXTERNAL_DTS_FRAGMENTS
> +	string "external dts file fragments"
> +	depends on OFTREE
> +	help
> +	  List of dts fragment files that will be appended to Barebox's device
> +	  tree(s) source when building the dtb file(s).  If multiple files are
> +	  listed, they will be appended in order.  Relative filenames will use
> +	  the dtc include search path.
> +
> +	  A preprocessor macro based on the name of the main dts will be
> +	  defined, which allows the dts fragments to based on which image of a
> +	  multi image build they are being used in.
> +
> +	  It not intended that this be put into into Barebox defconfig files.
> +	  Instead, it's an external build system, like Yocto or buildroot, to
> +	  add dts fragments from outside the Barebox source tree into the
> +	  Barebox build.
> +
>  menu "OP-TEE loading"
>  
>  config OPTEE_SIZE
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 80d76b177..4496f1a70 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -201,6 +201,7 @@ cpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(__cpp_flags)
>  ld_flags       = $(KBUILD_LDFLAGS) $(ldflags-y)
>  
>  dtc_cpp_flags  = -Wp,-MD,$(depfile).pre -nostdinc                        \
> +		 -Wp,-MT,$(basename $(notdir $@)).o                      \
>  		 -I$(srctree)/arch/$(SRCARCH)/dts/include		 \
>  		 -I$(srctree)/dts/include                                \
>  		 -I$(srctree)/include                                    \
> @@ -335,8 +336,13 @@ cmd_dt_S_dtb = $(srctree)/scripts/gen-dtb-s $(subst -,_,$(*F)) $< $(CONFIG_IMD)
>  $(obj)/%.dtb.S: $(obj)/%.dtb $(srctree)/scripts/gen-dtb-s FORCE
>  	$(call if_changed,dt_S_dtb)
>  
> +dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
>  quiet_cmd_dtc = DTC     $@
> -cmd_dtc = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
> +# For compatibility between make 4.2 and 4.3
> +H := \#
> +cmd_dtc = /bin/echo -e '$(H)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(dts-frags),'$(H)include "$(f)"\n') | \
> +	$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
>  	$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
>  		-i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \
>  		-i $(srctree)/dts/src/$(SRCARCH) \
> -- 
> 2.31.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


-- 
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] kbuild: dtc: Allow adding device tree fragments via config
  2022-01-26 12:29 ` Antony Pavlov
@ 2022-01-26 22:10   ` Trent Piepho
  0 siblings, 0 replies; 4+ messages in thread
From: Trent Piepho @ 2022-01-26 22:10 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox, Sascha Hauer, Ahmad Fatoum

There are no defconfigs that begin with a digit, but I guess there are
dts names that do.

Should probably just change the macro name from FOO_BOARD_DTS to DTS_FOO_BOARD.


On Wed, Jan 26, 2022 at 4:29 AM Antony Pavlov <antonynpavlov@gmail.com> wrote:
>
> On Wed, 22 Sep 2021 11:13:36 -0700
> Trent Piepho <trent.piepho@igorinstitute.com> wrote:
>
> Hi!
>
> This patch was applied to barebox source tree as
>
>   2ae7ac7ab2 kbuild: dtc: Allow adding device tree fragments via config
>
> With this patch I see build error if device tree file name starts with digit (0-9),
> e.g.:
>
>   barebox$ git checkout v2022.01.0
>
>   barebox$ make mrproper
>
>   barebox$ export ARCH=arm
>   barebox$ export CROSS_COMPILE=arm-none-eabi-
>   barebox$ sed -i "s/virt2real.dtb/2virt2real.dtb/" arch/arm/dts/Makefile
>   barebox$ mv arch/arm/dts/virt2real.dts arch/arm/dts/2virt2real.dts
>
>   barebox$ make virt2real_defconfig
>   ...
>   barebox$ make -s
>   <stdin>:1:9: error: macro names must be identifiers                                              make[1]:  [scripts/Makefile.lib:352: arch/arm/dts/2virt2real.dtb] Error 1
>   make:  [Makefile:952: arch/arm/dts] Error 2
>
>
>
>
> > This introduces a config variable that allows adding additional fragments
> > to the Barebox device tree(s).
> >
> > Example uses are adjusting the flash partition layout, adding barebox
> > state variables, or adding an I2C device.  These can be now be done with
> > build configuration only, without needing to patch the existing dts
> > files in the Barebox source.
> >
> > The advantage is greater when an external build system, such as Yocto or
> > Buildroot, is being used to build Barebox.  The build system can drop in
> > a dts fragment to partition flash and build from unaltered Barebox
> > source.  This avoids the need for cumbersome maintenance of patch files
> > to modify Barebox's source for each flash partition layout.
> >
> > Preprocessing the dts file gains another layer, where a generated dts
> > source consisting of an include directive for the original dts source is
> > followed by more includes for each fragment.  This is piped to the
> > existing preprocessor call on stdin to avoid another temporary file.
> > cpp/dtc will correctly identify errors in the source files they occur
> > in.  The -MT option is used so the cpp auto-dependencies reference the
> > original dts source and not the generated code passed on stdin.
> >
> > A preprocessor macro named after the base dts file, e.g. foo-bar.dts
> > will define foo_bar_dts, will be defined so that the fragments can
> > possibly operate differently based on which image's dts is being built.
> >
> > Signed-off-by: Trent Piepho <trent.piepho@igorinstitute.com>
> > ---
> > Changes from v1:
> >   - Remove 2nd config variable for in-tree fragments.
> >   - Add macro to preproccessed dts
> >
> >  common/Kconfig       | 18 ++++++++++++++++++
> >  scripts/Makefile.lib |  8 +++++++-
> >  2 files changed, 25 insertions(+), 1 deletion(-)
> >
> > diff --git a/common/Kconfig b/common/Kconfig
> > index a9feae2ae..6fdc14148 100644
> > --- a/common/Kconfig
> > +++ b/common/Kconfig
> > @@ -1091,6 +1091,24 @@ config SYSTEMD_OF_WATCHDOG
> >         in the kernel device tree. If the kernel is booted without a device
> >         tree or with one that lacks aliases, nothing is added.
> >
> > +config EXTERNAL_DTS_FRAGMENTS
> > +     string "external dts file fragments"
> > +     depends on OFTREE
> > +     help
> > +       List of dts fragment files that will be appended to Barebox's device
> > +       tree(s) source when building the dtb file(s).  If multiple files are
> > +       listed, they will be appended in order.  Relative filenames will use
> > +       the dtc include search path.
> > +
> > +       A preprocessor macro based on the name of the main dts will be
> > +       defined, which allows the dts fragments to based on which image of a
> > +       multi image build they are being used in.
> > +
> > +       It not intended that this be put into into Barebox defconfig files.
> > +       Instead, it's an external build system, like Yocto or buildroot, to
> > +       add dts fragments from outside the Barebox source tree into the
> > +       Barebox build.
> > +
> >  menu "OP-TEE loading"
> >
> >  config OPTEE_SIZE
> > diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> > index 80d76b177..4496f1a70 100644
> > --- a/scripts/Makefile.lib
> > +++ b/scripts/Makefile.lib
> > @@ -201,6 +201,7 @@ cpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(__cpp_flags)
> >  ld_flags       = $(KBUILD_LDFLAGS) $(ldflags-y)
> >
> >  dtc_cpp_flags  = -Wp,-MD,$(depfile).pre -nostdinc                        \
> > +              -Wp,-MT,$(basename $(notdir $@)).o                      \
> >                -I$(srctree)/arch/$(SRCARCH)/dts/include                \
> >                -I$(srctree)/dts/include                                \
> >                -I$(srctree)/include                                    \
> > @@ -335,8 +336,13 @@ cmd_dt_S_dtb = $(srctree)/scripts/gen-dtb-s $(subst -,_,$(*F)) $< $(CONFIG_IMD)
> >  $(obj)/%.dtb.S: $(obj)/%.dtb $(srctree)/scripts/gen-dtb-s FORCE
> >       $(call if_changed,dt_S_dtb)
> >
> > +dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
> >  quiet_cmd_dtc = DTC     $@
> > -cmd_dtc = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
> > +# For compatibility between make 4.2 and 4.3
> > +H := \#
> > +cmd_dtc = /bin/echo -e '$(H)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(dts-frags),'$(H)include "$(f)"\n') | \
> > +     $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
> >       $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
> >               -i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \
> >               -i $(srctree)/dts/src/$(SRCARCH) \
> > --
> > 2.31.1
> >
> >
> > _______________________________________________
> > barebox mailing list
> > barebox@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
>
>
> --
> Best regards,
>   Antony Pavlov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-26 22:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22 18:13 [PATCH v2 1/1] kbuild: dtc: Allow adding device tree fragments via config Trent Piepho
2021-10-01 12:52 ` Sascha Hauer
2022-01-26 12:29 ` Antony Pavlov
2022-01-26 22:10   ` Trent Piepho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox