* Re: [RFC] gen-dtb-s: make metadata binary fields always little-endian
2014-08-03 17:53 ` Antony Pavlov
@ 2014-08-04 6:31 ` Uwe Kleine-König
2014-08-04 17:34 ` Sascha Hauer
2014-08-06 4:00 ` Jean-Christophe PLAGNIOL-VILLARD
2 siblings, 0 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2014-08-04 6:31 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox
On Sun, Aug 03, 2014 at 09:53:38PM +0400, Antony Pavlov wrote:
> On Sun, 03 Aug 2014 18:17:45 +0200
> Jan Lübbe <jlu@pengutronix.de> wrote:
>
> > Hi,
> >
> > On Sat, 2014-08-02 at 09:45 +0400, Antony Pavlov wrote:
> > >
> > > compatlen=$($FDTGET -t s "$dtb" / compatible | wc -c)
> > > - echo ".int 0x640c8005"
> > > - echo ".int " $compatlen
> > > + echo ".byte 0x05, 0x80, 0x0c, 0x64"
> > > + python -c "print(\".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\\n\" % ($compatlen & 0xff, ($compatlen >> 8) & 0xff, ($compatlen >> 16) & 0xff, ($compatlen >> 24) & 0xff))"
> >
> > Rather than adding a build-time dependency on python, maybe we should
> > just handle this in C?
>
> We use sphinx for documentation generation so we already have dependency on python.
>
> Here is an another solution:
>
> - echo ".int " $compatlen
> + echo ".byte " $(printf "%08x" $compatlen | sed "s/\(..\)/0x\1\n/g" | tac | xargs | sed "s/ /, /g")
yet another alternative:
awk -v var=$compatlen 'BEGIN { for (i = 0; i < 4; ++i) ba[i] = and(rshift(var, 8 * i), 0xff); printf ".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", ba[0], ba[1], ba[2], ba[3]; }'
It's not shorter, but maybe a bit more obvious what it does.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] gen-dtb-s: make metadata binary fields always little-endian
2014-08-03 17:53 ` Antony Pavlov
2014-08-04 6:31 ` Uwe Kleine-König
@ 2014-08-04 17:34 ` Sascha Hauer
2014-08-04 19:19 ` Antony Pavlov
2014-08-06 4:00 ` Jean-Christophe PLAGNIOL-VILLARD
2 siblings, 1 reply; 7+ messages in thread
From: Sascha Hauer @ 2014-08-04 17:34 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox
On Sun, Aug 03, 2014 at 09:53:38PM +0400, Antony Pavlov wrote:
> On Sun, 03 Aug 2014 18:17:45 +0200
> Jan Lübbe <jlu@pengutronix.de> wrote:
>
> > Hi,
> >
> > On Sat, 2014-08-02 at 09:45 +0400, Antony Pavlov wrote:
> > >
> > > compatlen=$($FDTGET -t s "$dtb" / compatible | wc -c)
> > > - echo ".int 0x640c8005"
> > > - echo ".int " $compatlen
> > > + echo ".byte 0x05, 0x80, 0x0c, 0x64"
> > > + python -c "print(\".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\\n\" % ($compatlen & 0xff, ($compatlen >> 8) & 0xff, ($compatlen >> 16) & 0xff, ($compatlen >> 24) & 0xff))"
> >
> > Rather than adding a build-time dependency on python, maybe we should
> > just handle this in C?
>
> We use sphinx for documentation generation so we already have dependency on python.
Yeah, but 'make docs' is a separate target. We shouldn't add it for the
binary build without need.
How about this? It uses shell, is readable and uses a function to avoid
duplicating the endianess conversion code.
Sascha
From 9c3aded9eac3ec563827b6ee562335ff4bce607a Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer@pengutronix.de>
Date: Mon, 4 Aug 2014 19:31:54 +0200
Subject: [PATCH] gen-dtb-s: make metadata binary fields always little-endian
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
scripts/gen-dtb-s | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
index 3e4158f..434612f 100755
--- a/scripts/gen-dtb-s
+++ b/scripts/gen-dtb-s
@@ -6,6 +6,14 @@ imd=$3
echo "#include <asm-generic/barebox.lds.h>"
+le32() {
+ printf ".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" \
+ $(($1 & 0xff)) \
+ $((($1 >> 8) & 0xff)) \
+ $((($1 >> 16) & 0xff)) \
+ $((($1 >> 24) & 0xff))
+}
+
FDTGET=scripts/dtc/fdtget
if [ "$imd" = "y" ]; then
@@ -17,8 +25,8 @@ if [ "$imd" = "y" ]; then
if [ "$compat" != "notfound" ]; then
compatlen=$($FDTGET -t s "$dtb" / compatible | wc -c)
- echo ".int 0x640c8005"
- echo ".int " $compatlen
+ le32 0x640c8005
+ le32 $compatlen
echo ".byte " $compat
echo ".balign 4"
fi
@@ -27,8 +35,8 @@ if [ "$imd" = "y" ]; then
if [ "$model" != "notfound" ]; then
modellen=$($FDTGET -t s "$dtb" / model | wc -c)
- echo ".int 0x640c8004"
- echo ".int " $modellen
+ le32 0x640c8004
+ le32 $compatlen
echo ".byte " $model
echo ".balign 4"
fi
--
2.0.1
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 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] 7+ messages in thread
* Re: [RFC] gen-dtb-s: make metadata binary fields always little-endian
2014-08-04 17:34 ` Sascha Hauer
@ 2014-08-04 19:19 ` Antony Pavlov
0 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2014-08-04 19:19 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On Mon, 4 Aug 2014 19:34:59 +0200
Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Sun, Aug 03, 2014 at 09:53:38PM +0400, Antony Pavlov wrote:
> > On Sun, 03 Aug 2014 18:17:45 +0200
> > Jan Lübbe <jlu@pengutronix.de> wrote:
> >
> > > Hi,
> > >
> > > On Sat, 2014-08-02 at 09:45 +0400, Antony Pavlov wrote:
> > > >
> > > > compatlen=$($FDTGET -t s "$dtb" / compatible | wc -c)
> > > > - echo ".int 0x640c8005"
> > > > - echo ".int " $compatlen
> > > > + echo ".byte 0x05, 0x80, 0x0c, 0x64"
> > > > + python -c "print(\".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\\n\" % ($compatlen & 0xff, ($compatlen >> 8) & 0xff, ($compatlen >> 16) & 0xff, ($compatlen >> 24) & 0xff))"
> > >
> > > Rather than adding a build-time dependency on python, maybe we should
> > > just handle this in C?
> >
> > We use sphinx for documentation generation so we already have dependency on python.
>
> Yeah, but 'make docs' is a separate target. We shouldn't add it for the
> binary build without need.
>
> How about this? It uses shell, is readable and uses a function to avoid
> duplicating the endianess conversion code.
>
> Sascha
>
>
> From 9c3aded9eac3ec563827b6ee562335ff4bce607a Mon Sep 17 00:00:00 2001
> From: Sascha Hauer <s.hauer@pengutronix.de>
> Date: Mon, 4 Aug 2014 19:31:54 +0200
> Subject: [PATCH] gen-dtb-s: make metadata binary fields always little-endian
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> scripts/gen-dtb-s | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
> index 3e4158f..434612f 100755
> --- a/scripts/gen-dtb-s
> +++ b/scripts/gen-dtb-s
> @@ -6,6 +6,14 @@ imd=$3
>
> echo "#include <asm-generic/barebox.lds.h>"
>
> +le32() {
> + printf ".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" \
> + $(($1 & 0xff)) \
> + $((($1 >> 8) & 0xff)) \
> + $((($1 >> 16) & 0xff)) \
> + $((($1 >> 24) & 0xff))
> +}
> +
> FDTGET=scripts/dtc/fdtget
>
> if [ "$imd" = "y" ]; then
> @@ -17,8 +25,8 @@ if [ "$imd" = "y" ]; then
> if [ "$compat" != "notfound" ]; then
>
> compatlen=$($FDTGET -t s "$dtb" / compatible | wc -c)
> - echo ".int 0x640c8005"
> - echo ".int " $compatlen
> + le32 0x640c8005
> + le32 $compatlen
> echo ".byte " $compat
> echo ".balign 4"
> fi
> @@ -27,8 +35,8 @@ if [ "$imd" = "y" ]; then
>
> if [ "$model" != "notfound" ]; then
> modellen=$($FDTGET -t s "$dtb" / model | wc -c)
> - echo ".int 0x640c8004"
> - echo ".int " $modellen
> + le32 0x640c8004
> + le32 $compatlen
> echo ".byte " $model
> echo ".balign 4"
> fi
> --
> 2.0.1
I have just checked this patch with pbl-less big-endian qemu mips malta image.
Acked-by: Antony Pavlov <antonynpavlov@gmail.com>
--
Best regards,
Antony Pavlov
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] gen-dtb-s: make metadata binary fields always little-endian
2014-08-03 17:53 ` Antony Pavlov
2014-08-04 6:31 ` Uwe Kleine-König
2014-08-04 17:34 ` Sascha Hauer
@ 2014-08-06 4:00 ` Jean-Christophe PLAGNIOL-VILLARD
2 siblings, 0 replies; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2014-08-06 4:00 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox
On 21:53 Sun 03 Aug , Antony Pavlov wrote:
>
> On Sun, 03 Aug 2014 18:17:45 +0200
> Jan Lübbe <jlu@pengutronix.de> wrote:
>
> > Hi,
> >
> > On Sat, 2014-08-02 at 09:45 +0400, Antony Pavlov wrote:
> > >
> > > compatlen=$($FDTGET -t s "$dtb" / compatible | wc -c)
> > > - echo ".int 0x640c8005"
> > > - echo ".int " $compatlen
> > > + echo ".byte 0x05, 0x80, 0x0c, 0x64"
> > > + python -c "print(\".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\\n\" % ($compatlen & 0xff, ($compatlen >> 8) & 0xff, ($compatlen >> 16) & 0xff, ($compatlen >> 24) & 0xff))"
> >
> > Rather than adding a build-time dependency on python, maybe we should
> > just handle this in C?
>
> We use sphinx for documentation generation so we already have dependency on python.
not a fan of python and this will make it mandatory for build as it's only for
doc today
for me no
Best Regards,
J.
>
> Here is an another solution:
>
> - echo ".int " $compatlen
> + echo ".byte " $(printf "%08x" $compatlen | sed "s/\(..\)/0x\1\n/g" | tac | xargs | sed "s/ /, /g")
>
> --
> Best regards,
> Antony Pavlov
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread