diff mbox

[U-Boot,01/15] fdt: Use sed instead of cpp to pre-process the dtc

Message ID 1356560913-2205-2-git-send-email-sjg@chromium.org
State Superseded, archived
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Dec. 26, 2012, 10:28 p.m. UTC
Include file support in dtc is still not available in common distributions
so we need to keep our preprocessing arrangement around for a little
longer.

But # is commonly used in FDT files, so use sed instead of cpp for this
preprocessing.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 dts/Makefile |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)

Comments

Stephen Warren Dec. 28, 2012, 12:03 a.m. UTC | #1
On 12/26/2012 03:28 PM, Simon Glass wrote:
> Include file support in dtc is still not available in common distributions
> so we need to keep our preprocessing arrangement around for a little
> longer.
> 
> But # is commonly used in FDT files, so use sed instead of cpp for this
> preprocessing.

This sounds like the wrong approach to me. I'd suggest using what I
proposed for the kernel:

> 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)

The "-x assembler-with-cpp" is what solves the # problem IIRC.
Simon Glass Dec. 28, 2012, 2:55 p.m. UTC | #2
Hi Stephen,

On Thu, Dec 27, 2012 at 4:03 PM, Stephen Warren <swarren@wwwdotorg.org> wrote:
> On 12/26/2012 03:28 PM, Simon Glass wrote:
>> Include file support in dtc is still not available in common distributions
>> so we need to keep our preprocessing arrangement around for a little
>> longer.
>>
>> But # is commonly used in FDT files, so use sed instead of cpp for this
>> preprocessing.
>
> This sounds like the wrong approach to me. I'd suggest using what I
> proposed for the kernel:
>
>> 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)
>
> The "-x assembler-with-cpp" is what solves the # problem IIRC.

I originally used CPP as an expedient means of converting the
ARCH_CPU_DTS symbol until we all have a dtc with include path support.

Are you saying that we want to actually use the CPP on tthe device
tree and (presumably) use U-Boot include files within the FDT?

Regards,
Simon
Mike Frysinger Dec. 28, 2012, 4:42 p.m. UTC | #3
On Friday 28 December 2012 09:55:52 Simon Glass wrote:
> On Thu, Dec 27, 2012 at 4:03 PM, Stephen Warren wrote:
> > On 12/26/2012 03:28 PM, Simon Glass wrote:
> >> Include file support in dtc is still not available in common
> >> distributions so we need to keep our preprocessing arrangement around
> >> for a little longer.
> >> 
> >> But # is commonly used in FDT files, so use sed instead of cpp for this
> >> preprocessing.
> > 
> > This sounds like the wrong approach to me. I'd suggest using what I
> > 
> > proposed for the kernel:
> >> 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)
> > 
> > The "-x assembler-with-cpp" is what solves the # problem IIRC.
> 
> I originally used CPP as an expedient means of converting the
> ARCH_CPU_DTS symbol until we all have a dtc with include path support.
> 
> Are you saying that we want to actually use the CPP on tthe device
> tree and (presumably) use U-Boot include files within the FDT?

sounds reasonable to me.  we already do it with linker scripts, and if the 
kernel is doing it, it means we can (possibly) share more.
-mike
Simon Glass Dec. 28, 2012, 6:07 p.m. UTC | #4
Hi,

On Fri, Dec 28, 2012 at 8:42 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Friday 28 December 2012 09:55:52 Simon Glass wrote:
>> On Thu, Dec 27, 2012 at 4:03 PM, Stephen Warren wrote:
>> > On 12/26/2012 03:28 PM, Simon Glass wrote:
>> >> Include file support in dtc is still not available in common
>> >> distributions so we need to keep our preprocessing arrangement around
>> >> for a little longer.
>> >>
>> >> But # is commonly used in FDT files, so use sed instead of cpp for this
>> >> preprocessing.
>> >
>> > This sounds like the wrong approach to me. I'd suggest using what I
>> >
>> > proposed for the kernel:
>> >> 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)
>> >
>> > The "-x assembler-with-cpp" is what solves the # problem IIRC.
>>
>> I originally used CPP as an expedient means of converting the
>> ARCH_CPU_DTS symbol until we all have a dtc with include path support.
>>
>> Are you saying that we want to actually use the CPP on tthe device
>> tree and (presumably) use U-Boot include files within the FDT?
>
> sounds reasonable to me.  we already do it with linker scripts, and if the
> kernel is doing it, it means we can (possibly) share more.

OK. Stephen, what is the kernel actually doing with the preprocessor?
Have you given up on the dtc symbol stuff for now and plan to use CPP
instead?

Regards,
Simon

> -mike
Stephen Warren Dec. 28, 2012, 11:47 p.m. UTC | #5
On 12/28/2012 11:07 AM, Simon Glass wrote:
> Hi,
> 
> On Fri, Dec 28, 2012 at 8:42 AM, Mike Frysinger <vapier@gentoo.org> wrote:
>> On Friday 28 December 2012 09:55:52 Simon Glass wrote:
>>> On Thu, Dec 27, 2012 at 4:03 PM, Stephen Warren wrote:
>>>> On 12/26/2012 03:28 PM, Simon Glass wrote:
>>>>> Include file support in dtc is still not available in common
>>>>> distributions so we need to keep our preprocessing arrangement around
>>>>> for a little longer.
>>>>>
>>>>> But # is commonly used in FDT files, so use sed instead of cpp for this
>>>>> preprocessing.
>>>>
>>>> This sounds like the wrong approach to me. I'd suggest using what I
>>>>
>>>> proposed for the kernel:
>>>>> 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)
>>>>
>>>> The "-x assembler-with-cpp" is what solves the # problem IIRC.
>>>
>>> I originally used CPP as an expedient means of converting the
>>> ARCH_CPU_DTS symbol until we all have a dtc with include path support.
>>>
>>> Are you saying that we want to actually use the CPP on tthe device
>>> tree and (presumably) use U-Boot include files within the FDT?

Yes, I'd explicitly like to be able to use C-style header files to
define named constants etc.

>> sounds reasonable to me.  we already do it with linker scripts, and if the
>> kernel is doing it, it means we can (possibly) share more.
> 
> OK. Stephen, what is the kernel actually doing with the preprocessor?
> Have you given up on the dtc symbol stuff for now and plan to use CPP
> instead?

Yes, I've given up on getting any kind of pre-processor or macro
language into dtc itself. I haven't managed to get the kernel to accept
the logic I quoted above either yet; this has all been a very long and
tortuous process. I hope to repost the patch that implements this in the
kernel within the next week or so.
Simon Glass Dec. 29, 2012, 12:34 a.m. UTC | #6
Hi Stephen,

On Fri, Dec 28, 2012 at 3:47 PM, Stephen Warren <swarren@wwwdotorg.org> wrote:
> On 12/28/2012 11:07 AM, Simon Glass wrote:
>> Hi,
>>
>> On Fri, Dec 28, 2012 at 8:42 AM, Mike Frysinger <vapier@gentoo.org> wrote:
>>> On Friday 28 December 2012 09:55:52 Simon Glass wrote:
>>>> On Thu, Dec 27, 2012 at 4:03 PM, Stephen Warren wrote:
>>>>> On 12/26/2012 03:28 PM, Simon Glass wrote:
>>>>>> Include file support in dtc is still not available in common
>>>>>> distributions so we need to keep our preprocessing arrangement around
>>>>>> for a little longer.
>>>>>>
>>>>>> But # is commonly used in FDT files, so use sed instead of cpp for this
>>>>>> preprocessing.
>>>>>
>>>>> This sounds like the wrong approach to me. I'd suggest using what I
>>>>>
>>>>> proposed for the kernel:
>>>>>> 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)
>>>>>
>>>>> The "-x assembler-with-cpp" is what solves the # problem IIRC.
>>>>
>>>> I originally used CPP as an expedient means of converting the
>>>> ARCH_CPU_DTS symbol until we all have a dtc with include path support.
>>>>
>>>> Are you saying that we want to actually use the CPP on tthe device
>>>> tree and (presumably) use U-Boot include files within the FDT?
>
> Yes, I'd explicitly like to be able to use C-style header files to
> define named constants etc.
>
>>> sounds reasonable to me.  we already do it with linker scripts, and if the
>>> kernel is doing it, it means we can (possibly) share more.
>>
>> OK. Stephen, what is the kernel actually doing with the preprocessor?
>> Have you given up on the dtc symbol stuff for now and plan to use CPP
>> instead?
>
> Yes, I've given up on getting any kind of pre-processor or macro
> language into dtc itself. I haven't managed to get the kernel to accept
> the logic I quoted above either yet; this has all been a very long and
> tortuous process. I hope to repost the patch that implements this in the
> kernel within the next week or so.

OK good luck with the cat-herding. I will update this patch along the
lines you describe above and resend. I hope we are not opening a can
of worms using the full power of the pre-processor, but clearly we are
not getting anywhere with dtc, so this is the only reasonable option.

Regards,
Simon
diff mbox

Patch

diff --git a/dts/Makefile b/dts/Makefile
index 785104e..76f1461 100644
--- a/dts/Makefile
+++ b/dts/Makefile
@@ -35,11 +35,6 @@  $(if $(CONFIG_ARCH_DEVICE_TREE),,\
 $(error Your architecture does not have device tree support enabled. \
 Please define CONFIG_ARCH_DEVICE_TREE))
 
-# We preprocess the device tree file provide a useful define
-DTS_CPPFLAGS := -ansi \
-		-DARCH_CPU_DTS=\"$(SRCTREE)/arch/$(ARCH)/dts/$(CONFIG_ARCH_DEVICE_TREE).dtsi\" \
-		-DBOARD_DTS=\"$(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts/$(DEVICE_TREE).dts\"
-
 all:	$(obj).depend $(LIB)
 
 # Use a constant name for this so we can access it from C code.
@@ -49,7 +44,10 @@  DT_BIN	:= $(obj)dt.dtb
 
 $(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
 	rc=$$( \
-		cat $< | $(CPP) -P $(DTS_CPPFLAGS) - | \
+		cat $< \
+		| sed '{s#ARCH_CPU_DTS#"$(SRCTREE)/arch/$(ARCH)/dts/$(CONFIG_ARCH_DEVICE_TREE).dtsi"#; \
+			s#BOARD_DTS#$(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts/$(DEVICE_TREE).dts#}' | \
+		tee dts.tmp | \
 		{ { $(DTC) -R 4 -p 0x1000 -O dtb -o ${DT_BIN} - 2>&1 ; \
 		    echo $$? >&3 ; } | \
 		  grep -v '^DTC: dts->dtb  on file' ; \