2012-10-26 19:30:10

by Stephen Warren

[permalink] [raw]
Subject: [PATCH V4 REPOST 1/2] kbuild: centralize .dts->.dtb rule

From: Stephen Warren <[email protected]>

All architectures that use cmd_dtc do so in the same way. Move the build
rule to a central location to avoid duplication.

Signed-off-by: Stephen Warren <[email protected]>
---
v4: No change.
v3: No change.
v2: New patch.
---
arch/arm/boot/Makefile | 4 ----
arch/c6x/boot/Makefile | 3 ---
arch/openrisc/boot/Makefile | 3 ---
arch/powerpc/boot/Makefile | 4 ----
scripts/Makefile.lib | 3 +++
5 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/arch/arm/boot/Makefile b/arch/arm/boot/Makefile
index f2aa09e..208bb4c 100644
--- a/arch/arm/boot/Makefile
+++ b/arch/arm/boot/Makefile
@@ -61,10 +61,6 @@ endif

targets += $(dtb-y)

-# Rule to build device tree blobs
-$(obj)/%.dtb: $(src)/dts/%.dts FORCE
- $(call if_changed_dep,dtc)
-
$(obj)/dtbs: $(addprefix $(obj)/, $(dtb-y))

clean-files := *.dtb
diff --git a/arch/c6x/boot/Makefile b/arch/c6x/boot/Makefile
index 6891257..ad605fb 100644
--- a/arch/c6x/boot/Makefile
+++ b/arch/c6x/boot/Makefile
@@ -12,9 +12,6 @@ ifneq ($(DTB),)
obj-y += linked_dtb.o
endif

-$(obj)/%.dtb: $(src)/dts/%.dts FORCE
- $(call if_changed_dep,dtc)
-
quiet_cmd_cp = CP $< $@$2
cmd_cp = cat $< >$@$2 || (rm -f $@ && echo false)

diff --git a/arch/openrisc/boot/Makefile b/arch/openrisc/boot/Makefile
index 0995835..fd329bd 100644
--- a/arch/openrisc/boot/Makefile
+++ b/arch/openrisc/boot/Makefile
@@ -10,6 +10,3 @@ obj-y += $(BUILTIN_DTB)
clean-files := *.dtb.S

#DTC_FLAGS ?= -p 1024
-
-$(obj)/%.dtb: $(src)/dts/%.dts FORCE
- $(call if_changed_dep,dtc)
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 6a15c96..90206f2 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -356,10 +356,6 @@ $(obj)/treeImage.initrd.%: vmlinux $(obj)/%.dtb $(wrapperbits)
$(obj)/treeImage.%: vmlinux $(obj)/%.dtb $(wrapperbits)
$(call if_changed,wrap,treeboot-$*,,$(obj)/$*.dtb)

-# Rule to build device tree blobs
-$(obj)/%.dtb: $(src)/dts/%.dts FORCE
- $(call if_changed_dep,dtc)
-
# If there isn't a platform selected then just strip the vmlinux.
ifeq (,$(image-y))
image-y := vmlinux.strip
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 0be6f11..425578e 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -266,6 +266,9 @@ $(obj)/%.dtb.S: $(obj)/%.dtb
quiet_cmd_dtc = DTC $@
cmd_dtc = $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 $(DTC_FLAGS) -d $(depfile) $<

+$(obj)/%.dtb: $(src)/dts/%.dts FORCE
+ $(call if_changed_dep,dtc)
+
# Bzip2
# ---------------------------------------------------------------------------

--
1.7.0.4


2012-10-26 19:30:27

by Stephen Warren

[permalink] [raw]
Subject: [PATCH V4 REPOST 2/2] kbuild: run the pre-processor on *.dts files

From: Stephen Warren <[email protected]>

Modify cmd_dtc to run the C pre-processor on the input .dts file before
passing it to dtc for final compilation. This allows the use of #define
and #include within the .dts file.

Signed-off-by: Stephen Warren <[email protected]>
---
v4:
* Use -x assembler-with-cpp so pre-defined macros are set up so that
#included header files know to only use cpp syntax, not C syntax.
* Define __DTS__ for similar reasons.
* use $(CPP) not $(CC) -E, and use $(cpp_flags).
* Save the pre-processed results so they can be easily inspected when
debugging build issues.
* The use of -x assembler-with-cpp causes cpp to recognize directives in
column 1 only. Hence, there's no need to escape property names that
begin with #. Hence, there's no need for separate skeleton.dtsi and
skeleton.dtsip. Maintain a separate file extension and build rule so that
CPP-usage is opt-in. In particular, when using CPP, #include must be used
rather than /include/ so that dependencies work.
v3: Pass "-x c" not "-xc" to cpp.
v2: Place make %.dtb: %.dtsp rule into Makefile.lib.
---
scripts/Makefile.lib | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 425578e..33432f4 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -269,6 +269,15 @@ cmd_dtc = $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 $(DTC_FLAGS) -d $(depfile
$(obj)/%.dtb: $(src)/dts/%.dts FORCE
$(call if_changed_dep,dtc)

+dtc-tmp = $(subst $(comma),_,$(dot-target).dts)
+
+quiet_cmd_dtc_cpp = DTC+CPP $@
+cmd_dtc_cpp = $(CPP) $(cpp_flags) -D__DTS__ -x assembler-with-cpp -o $(dtc-tmp) $< ; \
+ $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 $(DTC_FLAGS) $(dtc-tmp)
+
+$(obj)/%.dtb: $(src)/dts/%.dtsp FORCE
+ $(call if_changed_dep,dtc_cpp)
+
# Bzip2
# ---------------------------------------------------------------------------

--
1.7.0.4

2012-10-26 19:57:56

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH V4 REPOST 2/2] kbuild: run the pre-processor on *.dts files

On 10/26/2012 02:29 PM, Stephen Warren wrote:
> From: Stephen Warren <[email protected]>
>
> Modify cmd_dtc to run the C pre-processor on the input .dts file before
> passing it to dtc for final compilation. This allows the use of #define
> and #include within the .dts file.

While this change is small the implications are not. I don't think no
comments reflects agreement on this.

Like I said previously, I think we first need guidelines on what is and
isn't acceptable use of C preprocessor in dts files.

Rob

>
> Signed-off-by: Stephen Warren <[email protected]>
> ---
> v4:
> * Use -x assembler-with-cpp so pre-defined macros are set up so that
> #included header files know to only use cpp syntax, not C syntax.
> * Define __DTS__ for similar reasons.
> * use $(CPP) not $(CC) -E, and use $(cpp_flags).
> * Save the pre-processed results so they can be easily inspected when
> debugging build issues.
> * The use of -x assembler-with-cpp causes cpp to recognize directives in
> column 1 only. Hence, there's no need to escape property names that
> begin with #. Hence, there's no need for separate skeleton.dtsi and
> skeleton.dtsip. Maintain a separate file extension and build rule so that
> CPP-usage is opt-in. In particular, when using CPP, #include must be used
> rather than /include/ so that dependencies work.
> v3: Pass "-x c" not "-xc" to cpp.
> v2: Place make %.dtb: %.dtsp rule into Makefile.lib.
> ---
> scripts/Makefile.lib | 9 +++++++++
> 1 files changed, 9 insertions(+), 0 deletions(-)
>
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 425578e..33432f4 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -269,6 +269,15 @@ cmd_dtc = $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 $(DTC_FLAGS) -d $(depfile
> $(obj)/%.dtb: $(src)/dts/%.dts FORCE
> $(call if_changed_dep,dtc)
>
> +dtc-tmp = $(subst $(comma),_,$(dot-target).dts)
> +
> +quiet_cmd_dtc_cpp = DTC+CPP $@
> +cmd_dtc_cpp = $(CPP) $(cpp_flags) -D__DTS__ -x assembler-with-cpp -o $(dtc-tmp) $< ; \
> + $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 $(DTC_FLAGS) $(dtc-tmp)
> +
> +$(obj)/%.dtb: $(src)/dts/%.dtsp FORCE
> + $(call if_changed_dep,dtc_cpp)
> +
> # Bzip2
> # ---------------------------------------------------------------------------
>
>

2012-10-27 22:06:48

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH V4 REPOST 2/2] kbuild: run the pre-processor on *.dts files

On Fri, Oct 26, 2012 at 02:57:50PM -0500, Rob Herring wrote:

> Like I said previously, I think we first need guidelines on what is and
> isn't acceptable use of C preprocessor in dts files.

Didn't we already say that it was just the same rules as for things tht
get included in .S files? Besides for plain .dts files (as opposed to
.dtsi files) it seems like if people break things they get to keep all
the pieces without disrupting other people too much.


Attachments:
(No filename) (459.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments

2012-10-28 02:10:17

by Stephen Warren

[permalink] [raw]
Subject: Re: [PATCH V4 REPOST 2/2] kbuild: run the pre-processor on *.dts files

On 10/27/2012 07:06 PM, Rob Herring wrote:
> Mark Brown <[email protected]> wrote:
>
> On Fri, Oct 26, 2012 at 02:57:50PM -0500, Rob Herring wrote:
>
> Like I said previously, I think we first need guidelines on what
> is and
> isn't acceptable use of C preprocessor in dts files.
>
>
> Didn't we already say that it was just the same rules as for things tht
> get included in .S files? Besides for plain .dts files (as opposed to
> .dtsi files) it seems like if people break things they get to keep all
> the pieces without disrupting other people too much.
>
>
> Yes, but can we document that. Also, I'd like others with more DT
> historical knowledge to weigh in.

OK. What's the appropriate file to document that in? I assume you're not
just looking for an explanation in the commit description?

2012-10-28 07:24:42

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH V4 REPOST 1/2] kbuild: centralize .dts->.dtb rule

On Fri, Oct 26, 2012 at 01:29:56PM -0600, Stephen Warren wrote:
> From: Stephen Warren <[email protected]>
>
> All architectures that use cmd_dtc do so in the same way. Move the build
> rule to a central location to avoid duplication.
>
> Signed-off-by: Stephen Warren <[email protected]>

This is missing documentation of the new rule in Documentation/kbuild/makefiles.txt

Sam