Patchwork [U-Boot,V2,1/9] Validate dtc is new enough

login
register
mail settings
Submitter Stephen Warren
Date June 24, 2013, 3:43 p.m.
Message ID <1372088629-14134-2-git-send-email-swarren@wwwdotorg.org>
Download mbox | patch
Permalink /patch/253899/
State Superseded
Delegated to: Tom Rini
Headers show

Comments

Stephen Warren - June 24, 2013, 3:43 p.m.
From: Stephen Warren <swarren@nvidia.com>

Subsequent patches assume that dtc supports various recent features.
These are available in dtc 1.4.0. Validate that dtc is at least that
version.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
v2: New patch.
---
 Makefile             |  8 +++++++-
 config.mk            |  1 +
 tools/dtc-version.sh | 20 ++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100755 tools/dtc-version.sh
Simon Glass - June 25, 2013, 12:45 a.m.
Hi Stephen,

On Mon, Jun 24, 2013 at 8:43 AM, Stephen Warren <swarren@wwwdotorg.org>wrote:

> From: Stephen Warren <swarren@nvidia.com>
>
> Subsequent patches assume that dtc supports various recent features.
> These are available in dtc 1.4.0. Validate that dtc is at least that
> version.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
> v2: New patch.
>

Acked-by: Simon Glass <sjg@chromium.org>

See note below.


> ---
>  Makefile             |  8 +++++++-
>  config.mk            |  1 +
>  tools/dtc-version.sh | 20 ++++++++++++++++++++
>  3 files changed, 28 insertions(+), 1 deletion(-)
>  create mode 100755 tools/dtc-version.sh
>
> diff --git a/Makefile b/Makefile
> index 50880c9..f167458 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -428,7 +428,7 @@ endif
>
>  all:           $(ALL-y) $(SUBDIR_EXAMPLES)
>
> -$(obj)u-boot.dtb:      $(obj)u-boot
> +$(obj)u-boot.dtb:      checkdtc $(obj)u-boot
>

Any reason this is not in dts/Makefile? Still this is fine.


>                 $(MAKE) -C dts binary
>                 mv $(obj)dts/dt.dtb $@
>
> @@ -686,6 +686,12 @@ checkgcc4:
>                 false; \
>         fi
>
> +checkdtc:
> +       @if test $(call dtc-version) -lt 0104; then \
> +               echo '*** Your dtc is too old, please upgrade to dtc 1.4
> or newer'; \
> +               false; \
> +       fi
> +
>  #
>  # Auto-generate the autoconf.mk file (which is included by all makefiles)
>  #
> diff --git a/config.mk b/config.mk
> index 6e17ed8..32643ec 100644
> --- a/config.mk
> +++ b/config.mk
> @@ -136,6 +136,7 @@ endif
>  # Usage gcc-ver := $(call cc-version)
>  cc-version = $(shell $(SHELL) $(SRCTREE)/tools/gcc-version.sh $(CC))
>  binutils-version = $(shell $(SHELL) $(SRCTREE)/tools/binutils-version.sh
> $(AS))
> +dtc-version = $(shell $(SHELL) $(SRCTREE)/tools/dtc-version.sh $(DTC))
>
>  #
>  # Include the make variables (CC, etc...)
> diff --git a/tools/dtc-version.sh b/tools/dtc-version.sh
> new file mode 100755
> index 0000000..e8c94d3
> --- /dev/null
> +++ b/tools/dtc-version.sh
> @@ -0,0 +1,20 @@
> +#!/bin/sh
> +#
> +# dtc-version dtc-command
> +#
> +# Prints the dtc version of `dtc-command' in a canonical 4-digit form
> +# such as `0222' for binutils 2.22
> +#
> +
> +dtc="$*"
> +
> +if [ ${#dtc} -eq 0 ]; then
> +       echo "Error: No dtc command specified."
> +       printf "Usage:\n\t$0 <dtc-command>\n"
> +       exit 1
> +fi
> +
> +MAJOR=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 1)
> +MINOR=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 2)
> +
> +printf "%02d%02d\\n" $MAJOR $MINOR
> --
> 1.8.1.5
>
>
Stephen Warren - June 25, 2013, 2:47 p.m.
On 06/24/2013 06:45 PM, Simon Glass wrote:
> Hi Stephen,
> 
> On Mon, Jun 24, 2013 at 8:43 AM, Stephen Warren <swarren@wwwdotorg.org
> <mailto:swarren@wwwdotorg.org>> wrote:
> 
>     From: Stephen Warren <swarren@nvidia.com <mailto:swarren@nvidia.com>>
> 
>     Subsequent patches assume that dtc supports various recent features.
>     These are available in dtc 1.4.0. Validate that dtc is at least that
>     version.
> 

> Acked-by: Simon Glass <sjg@chromium.org <mailto:sjg@chromium.org>>
> 
> See note below.

>     diff --git a/Makefile b/Makefile

>     -$(obj)u-boot.dtb:      $(obj)u-boot
>     +$(obj)u-boot.dtb:      checkdtc $(obj)u-boot
> 
> 
> Any reason this is not in dts/Makefile? Still this is fine.

I guess that would have worked too. One advantage of the current
placement is that make just happens to evaluate the rule really early
(at least with more than -j1!), so you don't build a lot before it
errors out, thus giving you quicker feedback. It also keeps all the tool
version checks in one file; perhaps easier maintenance?
Simon Glass - June 25, 2013, 2:58 p.m.
Hi Stephen,

On Tue, Jun 25, 2013 at 7:47 AM, Stephen Warren <swarren@wwwdotorg.org>wrote:

> On 06/24/2013 06:45 PM, Simon Glass wrote:
> > Hi Stephen,
> >
> > On Mon, Jun 24, 2013 at 8:43 AM, Stephen Warren <swarren@wwwdotorg.org
> > <mailto:swarren@wwwdotorg.org>> wrote:
> >
> >     From: Stephen Warren <swarren@nvidia.com <mailto:swarren@nvidia.com
> >>
> >
> >     Subsequent patches assume that dtc supports various recent features.
> >     These are available in dtc 1.4.0. Validate that dtc is at least that
> >     version.
> >
>
> > Acked-by: Simon Glass <sjg@chromium.org <mailto:sjg@chromium.org>>
> >
> > See note below.
>
> >     diff --git a/Makefile b/Makefile
>
> >     -$(obj)u-boot.dtb:      $(obj)u-boot
> >     +$(obj)u-boot.dtb:      checkdtc $(obj)u-boot
> >
> >
> > Any reason this is not in dts/Makefile? Still this is fine.
>
> I guess that would have worked too. One advantage of the current
> placement is that make just happens to evaluate the rule really early
> (at least with more than -j1!), so you don't build a lot before it
> errors out, thus giving you quicker feedback. It also keeps all the tool
> version checks in one file; perhaps easier maintenance?
>

Sounds good to me.

Regards,
Simon
Gerhard Sittig - June 25, 2013, 5:22 p.m.
On Mon, Jun 24, 2013 at 09:43 -0600, Stephen Warren wrote:
> 
> +checkdtc:
> +	@if test $(call dtc-version) -lt 0104; then \
> +		echo '*** Your dtc is too old, please upgrade to dtc 1.4 or newer'; \
> +		false; \
> +	fi

... and ...

> --- /dev/null
> +++ b/tools/dtc-version.sh
> @@ -0,0 +1,20 @@
> +#!/bin/sh
> +#
> +# dtc-version dtc-command
> +#
> +# Prints the dtc version of `dtc-command' in a canonical 4-digit form
> +# such as `0222' for binutils 2.22
> +#

So the numbers get converted to something that's neatly aligned
and free of whitespace and can get sorted alphabetically.

But the numbers get passed to $SHELL and the builtin test(1)
command, and get compared numerically ('-lt' operator).

Does that mean that the test break with digits beyond seven, when
numbers no longer can get interpreted as valid octal numbers?


virtually yours
Gerhard Sittig
Stephen Warren - June 25, 2013, 6:07 p.m.
On 06/25/2013 11:22 AM, Gerhard Sittig wrote:
> On Mon, Jun 24, 2013 at 09:43 -0600, Stephen Warren wrote:
>>
>> +checkdtc:
>> +	@if test $(call dtc-version) -lt 0104; then \
>> +		echo '*** Your dtc is too old, please upgrade to dtc 1.4 or newer'; \
>> +		false; \
>> +	fi
> 
> ... and ...
> 
>> --- /dev/null
>> +++ b/tools/dtc-version.sh
>> @@ -0,0 +1,20 @@
>> +#!/bin/sh
>> +#
>> +# dtc-version dtc-command
>> +#
>> +# Prints the dtc version of `dtc-command' in a canonical 4-digit form
>> +# such as `0222' for binutils 2.22
>> +#
> 
> So the numbers get converted to something that's neatly aligned
> and free of whitespace and can get sorted alphabetically.
> 
> But the numbers get passed to $SHELL and the builtin test(1)
> command, and get compared numerically ('-lt' operator).
> 
> Does that mean that the test break with digits beyond seven, when
> numbers no longer can get interpreted as valid octal numbers?

I'm pretty sure sh treats the numbers as decimal. Testing appears to
support this:

[swarren@swarren-lx1 kernel.git]$ if [ 0104 -lt 0104 ]; then echo yes;
else echo no; fi
no

[swarren@swarren-lx1 kernel.git]$ if [ 0103 -lt 0104 ]; then echo yes;
else echo no; fi
yes

[swarren@swarren-lx1 kernel.git]$ if [ 0803 -lt 0104 ]; then echo yes;
else echo no; fi
no

[swarren@swarren-lx1 kernel.git]$ if [ 0802 -lt 0804 ]; then echo yes;
else echo no; fi
yes

[swarren@swarren-lx1 kernel.git]$ if [ 0804 -lt 0804 ]; then echo yes;
else echo no; fi
no

[swarren@swarren-lx1 kernel.git]$ if [ 0806 -lt 0804 ]; then echo yes;
else echo no; fi
no

Patch

diff --git a/Makefile b/Makefile
index 50880c9..f167458 100644
--- a/Makefile
+++ b/Makefile
@@ -428,7 +428,7 @@  endif
 
 all:		$(ALL-y) $(SUBDIR_EXAMPLES)
 
-$(obj)u-boot.dtb:	$(obj)u-boot
+$(obj)u-boot.dtb:	checkdtc $(obj)u-boot
 		$(MAKE) -C dts binary
 		mv $(obj)dts/dt.dtb $@
 
@@ -686,6 +686,12 @@  checkgcc4:
 		false; \
 	fi
 
+checkdtc:
+	@if test $(call dtc-version) -lt 0104; then \
+		echo '*** Your dtc is too old, please upgrade to dtc 1.4 or newer'; \
+		false; \
+	fi
+
 #
 # Auto-generate the autoconf.mk file (which is included by all makefiles)
 #
diff --git a/config.mk b/config.mk
index 6e17ed8..32643ec 100644
--- a/config.mk
+++ b/config.mk
@@ -136,6 +136,7 @@  endif
 # Usage gcc-ver := $(call cc-version)
 cc-version = $(shell $(SHELL) $(SRCTREE)/tools/gcc-version.sh $(CC))
 binutils-version = $(shell $(SHELL) $(SRCTREE)/tools/binutils-version.sh $(AS))
+dtc-version = $(shell $(SHELL) $(SRCTREE)/tools/dtc-version.sh $(DTC))
 
 #
 # Include the make variables (CC, etc...)
diff --git a/tools/dtc-version.sh b/tools/dtc-version.sh
new file mode 100755
index 0000000..e8c94d3
--- /dev/null
+++ b/tools/dtc-version.sh
@@ -0,0 +1,20 @@ 
+#!/bin/sh
+#
+# dtc-version dtc-command
+#
+# Prints the dtc version of `dtc-command' in a canonical 4-digit form
+# such as `0222' for binutils 2.22
+#
+
+dtc="$*"
+
+if [ ${#dtc} -eq 0 ]; then
+	echo "Error: No dtc command specified."
+	printf "Usage:\n\t$0 <dtc-command>\n"
+	exit 1
+fi
+
+MAJOR=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 1)
+MINOR=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 2)
+
+printf "%02d%02d\\n" $MAJOR $MINOR