diff mbox

[OpenWrt-Devel,v2] Add support for C-style in dtsi files

Message ID 1449186024-4768-1-git-send-email-mar.kolya@gmail.com
State Superseded
Headers show

Commit Message

Nikolay Martynov Dec. 3, 2015, 11:40 p.m. UTC
Current way of compuling dts files involves calling C preprocessor on
main dts file only. This means that dtsi includes cannot have C-style includes.

This patch addresses this problem. It uses approach similar to one
use in linux kernel: it preprocesses all dtsi's in current dir into
tmp dir and then uses that tmp dir as include dir for main dts compilation.

Note: this patch preprocesses onlt *.dtsi, not *.dts, so only *.dtsi
can be includes, but it looks like all current architectures follow this convention.

This approach should be compatible with all current architectures.

This patch also updates ramips arch to use new dtsi comilation code.

v2: Use LINUX_KARCH to get to linux dh bindings.

Signed-off-by: Nikolay Martynov <mar.kolya@gmail.com>
---
 include/image.mk                   | 24 ++++++++++++++++++------
 target/linux/ramips/image/Makefile |  2 +-
 2 files changed, 19 insertions(+), 7 deletions(-)

Comments

Jonas Gorski Dec. 4, 2015, 8:57 p.m. UTC | #1
Hi,

On Fri, Dec 4, 2015 at 12:40 AM, Nikolay Martynov <mar.kolya@gmail.com> wrote:
> Current way of compuling dts files involves calling C preprocessor on
> main dts file only. This means that dtsi includes cannot have C-style includes.

Why not? Shouldn't they get processed as well as long as they are
included with #include, not /include/? Can you give an example that
doesn't work?

> This patch addresses this problem. It uses approach similar to one
> use in linux kernel: it preprocesses all dtsi's in current dir into
> tmp dir and then uses that tmp dir as include dir for main dts compilation.

I can't find this code in the kernel at all. Can you please point that out?

> Note: this patch preprocesses onlt *.dtsi, not *.dts, so only *.dtsi
> can be includes, but it looks like all current architectures follow this convention.
>
> This approach should be compatible with all current architectures.
>
> This patch also updates ramips arch to use new dtsi comilation code.
>
> v2: Use LINUX_KARCH to get to linux dh bindings.

This issue was copied from the DTS_DIR decleration, so maybe you can
fix that one up and then use -I$(DTS_DIR) -I$(DTS_DIR)/include ?

>
> Signed-off-by: Nikolay Martynov <mar.kolya@gmail.com>
> ---
>  include/image.mk                   | 24 ++++++++++++++++++------
>  target/linux/ramips/image/Makefile |  2 +-
>  2 files changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/include/image.mk b/include/image.mk
> index fd5e3f4..fa0314f 100644
> --- a/include/image.mk
> +++ b/include/image.mk
> @@ -138,19 +138,31 @@ define Image/BuildKernel/MkFIT
>  endef
>
>  # $(1) source dts file
> +# $(2) target dts file
> +# $(3) extra CPP flags
> +define Image/PreprocessDTS
> +       $(CPP) -nostdinc -x assembler-with-cpp \
> +               -I$(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts \
> +               -I$(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts/include \
> +               -undef -D__DTS__ $(3) \
> +               -o $(2) $(1);
> +endef
> +
> +
> +# $(1) source dts file
>  # $(2) target dtb file
>  # $(3) extra CPP flags
>  # $(4) extra DTC flags
>  define Image/BuildDTB
> -       $(CPP) -nostdinc -x assembler-with-cpp \
> -               -I$(LINUX_DIR)/arch/$(ARCH)/boot/dts \
> -               -I$(LINUX_DIR)/arch/$(ARCH)/boot/dts/include \
> -               -undef -D__DTS__ $(3) \
> -               -o $(2).tmp $(1)
> +       mkdir -p $(2).inc.tmp
> +       $(foreach inc,$(wildcard $(dir $(1))*.dtsi), \
> +               $(call Image/PreprocessDTS,$(inc),$(2).inc.tmp/$(notdir $(inc)),$(3)))

If I read this right you preprocess all dtsi files found there every
time you want to compile a dts file. This sounds like a lot of
unnecessary processing on e.g. arm, where arch/arm/boot/dts contains
435 .dtsi files as of 4.1. And since you remove the preprocessed
files, you need to do it again for the next dts file.


Jonas
diff mbox

Patch

diff --git a/include/image.mk b/include/image.mk
index fd5e3f4..fa0314f 100644
--- a/include/image.mk
+++ b/include/image.mk
@@ -138,19 +138,31 @@  define Image/BuildKernel/MkFIT
 endef
 
 # $(1) source dts file
+# $(2) target dts file
+# $(3) extra CPP flags
+define Image/PreprocessDTS
+	$(CPP) -nostdinc -x assembler-with-cpp \
+		-I$(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts \
+		-I$(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts/include \
+		-undef -D__DTS__ $(3) \
+		-o $(2) $(1);
+endef
+
+
+# $(1) source dts file
 # $(2) target dtb file
 # $(3) extra CPP flags
 # $(4) extra DTC flags
 define Image/BuildDTB
-	$(CPP) -nostdinc -x assembler-with-cpp \
-		-I$(LINUX_DIR)/arch/$(ARCH)/boot/dts \
-		-I$(LINUX_DIR)/arch/$(ARCH)/boot/dts/include \
-		-undef -D__DTS__ $(3) \
-		-o $(2).tmp $(1)
+	mkdir -p $(2).inc.tmp
+	$(foreach inc,$(wildcard $(dir $(1))*.dtsi), \
+		$(call Image/PreprocessDTS,$(inc),$(2).inc.tmp/$(notdir $(inc)),$(3)))
+	$(call Image/PreprocessDTS,$(1),$(2).tmp,$(3))
 	$(LINUX_DIR)/scripts/dtc/dtc -O dtb \
-		-i$(dir $(1)) $(4) \
+		-i$(2).inc.tmp $(4) \
 		-o $(2) $(2).tmp
 	$(RM) $(2).tmp
+	$(RM) -rf $(2).inc.tmp
 endef
 
 define Image/mkfs/jffs2/sub
diff --git a/target/linux/ramips/image/Makefile b/target/linux/ramips/image/Makefile
index e58d012..01e3fcb 100644
--- a/target/linux/ramips/image/Makefile
+++ b/target/linux/ramips/image/Makefile
@@ -39,7 +39,7 @@  define Device/Default
 endef
 
 define Build/patch-dtb
-	$(LINUX_DIR)/scripts/dtc/dtc -O dtb -o $@.dtb ../dts/$(DTS).dts
+	$(call Image/BuildDTB,../dts/$(DTS).dts,$@.dtb)
 	$(STAGING_DIR_HOST)/bin/patch-dtb $@ $@.dtb
 endef