All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] tools/envcrc: add --binary option to export embedded env
@ 2009-04-06 11:01 Mike Frysinger
  2009-04-27 22:15 ` Wolfgang Denk
  0 siblings, 1 reply; 9+ messages in thread
From: Mike Frysinger @ 2009-04-06 11:01 UTC (permalink / raw)
  To: u-boot

The --binary option to envcrc can be used to export the embedded env as a
binary blob so that it can be manipulated/examined/whatever externally.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 tools/envcrc.c |   45 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/tools/envcrc.c b/tools/envcrc.c
index 4334cdf..ac24967 100644
--- a/tools/envcrc.c
+++ b/tools/envcrc.c
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #ifndef __ASSEMBLY__
@@ -77,19 +78,55 @@ extern unsigned char environment;
 int main (int argc, char **argv)
 {
 #ifdef	ENV_IS_EMBEDDED
+	unsigned char pad = 0x00;
 	uint32_t crc;
 	unsigned char *envptr = &environment,
 		*dataptr = envptr + ENV_HEADER_SIZE;
 	unsigned int datasize = ENV_SIZE;
+	unsigned int eoe;
+
+	if (argv[1] && !strncmp(argv[1], "--binary=", 9)) {
+		int ipad;
+		sscanf(argv[1] + 9, "%i", &ipad);
+		pad = ipad;
+	}
+
+	if (pad) {
+		/* find the end of env */
+		for (eoe = 0; eoe < datasize - 1; ++eoe)
+			if (!dataptr[eoe] && !dataptr[eoe+1]) {
+				eoe += 2;
+				break;
+			}
+		if (eoe < datasize - 1)
+			memset(dataptr + eoe, pad, datasize - eoe);
+	}
 
 	crc = crc32 (0, dataptr, datasize);
 
 	/* Check if verbose mode is activated passing a parameter to the program */
 	if (argc > 1) {
-		printf ("CRC32 from offset %08X to %08X of environment = %08X\n",
-			(unsigned int) (dataptr - envptr),
-			(unsigned int) (dataptr - envptr) + datasize,
-			crc);
+		if (!strncmp(argv[1], "--binary", 8)) {
+			int le = (argc > 2 ? !strcmp(argv[2], "le") : 1);
+			size_t i, start, end, step;
+			if (le) {
+				start = 0;
+				end = ENV_HEADER_SIZE;
+				step = 1;
+			} else {
+				start = ENV_HEADER_SIZE - 1;
+				end = -1;
+				step = -1;
+			}
+			for (i = start; i != end; i += step)
+				printf("%c", (crc & (0xFF << (i * 8))) >> (i * 8));
+			fwrite(dataptr, 1, datasize, stdout);
+		} else {
+			printf("CRC32 from offset %08X to %08X of environment = %08X\n",
+				(unsigned int) (dataptr - envptr),
+				(unsigned int) (dataptr - envptr) + datasize,
+				crc);
+		}
 	} else {
 		printf ("0x%08X\n", crc);
 	}
-- 
1.6.2.2

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH] tools/envcrc: add --binary option to export embedded env
  2009-04-06 11:01 [U-Boot] [PATCH] tools/envcrc: add --binary option to export embedded env Mike Frysinger
@ 2009-04-27 22:15 ` Wolfgang Denk
  2009-04-27 23:55   ` Mike Frysinger
  0 siblings, 1 reply; 9+ messages in thread
From: Wolfgang Denk @ 2009-04-27 22:15 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <1239015670-28314-1-git-send-email-vapier@gentoo.org> you wrote:
> The --binary option to envcrc can be used to export the embedded env as a
> binary blob so that it can be manipulated/examined/whatever externally.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
>  tools/envcrc.c |   45 +++++++++++++++++++++++++++++++++++++++++----
>  1 files changed, 41 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/envcrc.c b/tools/envcrc.c
> index 4334cdf..ac24967 100644
> --- a/tools/envcrc.c
> +++ b/tools/envcrc.c
> @@ -24,6 +24,7 @@
>  #include <stdio.h>
>  #include <stdint.h>
>  #include <stdlib.h>
> +#include <string.h>
>  #include <unistd.h>
>  
>  #ifndef __ASSEMBLY__
> @@ -77,19 +78,55 @@ extern unsigned char environment;
>  int main (int argc, char **argv)
>  {
>  #ifdef	ENV_IS_EMBEDDED
> +	unsigned char pad = 0x00;

Should we not rather use 0xFF for padding - given that the envrionment
is frequently stored in NOR flash?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Of all possible committee reactions to any  given  agenda  item,  the
reaction  that will occur is the one which will liberate the greatest
amount of hot air.                                -- Thomas L. Martin

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH] tools/envcrc: add --binary option to export embedded env
  2009-04-27 22:15 ` Wolfgang Denk
@ 2009-04-27 23:55   ` Mike Frysinger
  2009-04-28  7:13     ` Wolfgang Denk
  0 siblings, 1 reply; 9+ messages in thread
From: Mike Frysinger @ 2009-04-27 23:55 UTC (permalink / raw)
  To: u-boot

On Monday 27 April 2009 18:15:58 Wolfgang Denk wrote:
> In message Mike Frysinger wrote:
> > The --binary option to envcrc can be used to export the embedded env as a
> > binary blob so that it can be manipulated/examined/whatever externally.
> >
> > @@ -77,19 +78,55 @@ extern unsigned char environment;
> >  int main (int argc, char **argv)
> >  {
> >  #ifdef	ENV_IS_EMBEDDED
> > +	unsigned char pad = 0x00;
>
> Should we not rather use 0xFF for padding - given that the envrionment
> is frequently stored in NOR flash?

i would love to (and with the Blackfin stuff, i do just that), but the problem 
is that there is no way of forcing the embedded environment to 0xff pad that i 
know of ...

so, to keep the most common behavior from changing (the char[] env is embedded 
in the .data section padded with 0x00), the padding defaults to 0x00.  this 
way `envcrc` outputs the right value (see common/Makefile).

for people (like me) who are using --binary to extract the env blob, we can do 
--binary=0xff and get what you're talking about.

i could extend the behavior so that using plain "--binary" is the same thing 
as "--binary=0xff" ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090427/e6a7a6cb/attachment-0001.pgp 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH] tools/envcrc: add --binary option to export embedded env
  2009-04-27 23:55   ` Mike Frysinger
@ 2009-04-28  7:13     ` Wolfgang Denk
  2009-04-28 12:54       ` Mike Frysinger
  0 siblings, 1 reply; 9+ messages in thread
From: Wolfgang Denk @ 2009-04-28  7:13 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <200904271955.08919.vapier@gentoo.org> you wrote:
>
> > Should we not rather use 0xFF for padding - given that the envrionment
> > is frequently stored in NOR flash?
>
> i would love to (and with the Blackfin stuff, i do just that), but the problem 
> is that there is no way of forcing the embedded environment to 0xff pad that i 
> know of ...

You mean in the code? Well, if you're using a separate section for it
(like the ppcenv section) this should be  straightforward  using  the
`=FILLEXP' output section attribute for the linker.

> so, to keep the most common behavior from changing (the char[] env is embedded 
> in the .data section padded with 0x00), the padding defaults to 0x00.  this 
> way `envcrc` outputs the right value (see common/Makefile).
>
> for people (like me) who are using --binary to extract the env blob, we can do 
> --binary=0xff and get what you're talking about.
>
> i could extend the behavior so that using plain "--binary" is the same thing 
> as "--binary=0xff" ...

OK.

I guess you want to suggest that I accept this patch as is, and we
address the gap filling with 0xFF in a separate patch? ;-)

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"Morality is one thing.  Ratings are everything."
- A Network 23 executive on "Max Headroom"

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH] tools/envcrc: add --binary option to export embedded env
  2009-04-28  7:13     ` Wolfgang Denk
@ 2009-04-28 12:54       ` Mike Frysinger
  2009-04-28 13:45         ` Wolfgang Denk
  0 siblings, 1 reply; 9+ messages in thread
From: Mike Frysinger @ 2009-04-28 12:54 UTC (permalink / raw)
  To: u-boot

On Tuesday 28 April 2009 03:13:05 Wolfgang Denk wrote:
> In message Mike Frysinger wrote:
> > > Should we not rather use 0xFF for padding - given that the envrionment
> > > is frequently stored in NOR flash?
> >
> > i would love to (and with the Blackfin stuff, i do just that), but the
> > problem is that there is no way of forcing the embedded environment to
> > 0xff pad that i know of ...
>
> You mean in the code? Well, if you're using a separate section for it
> (like the ppcenv section) this should be  straightforward  using  the
> `=FILLEXP' output section attribute for the linker.

hmm, a quick grep shows that almost no one has a dedicated section.  the 
majority of people (Blackfin boards included) insert it into the middle of 
their .text section.  this is the use case i was thinking of when i said "no 
way" because i hadnt seen anyone using a dedicated section before.

> > so, to keep the most common behavior from changing (the char[] env is
> > embedded in the .data section padded with 0x00), the padding defaults to
> > 0x00.  this way `envcrc` outputs the right value (see common/Makefile).
> >
> > for people (like me) who are using --binary to extract the env blob, we
> > can do --binary=0xff and get what you're talking about.
> >
> > i could extend the behavior so that using plain "--binary" is the same
> > thing as "--binary=0xff" ...
>
> OK.
>
> I guess you want to suggest that I accept this patch as is, and we
> address the gap filling with 0xFF in a separate patch? ;-)

if you want the "--binary" thing, i can post a new patch.  otherwise yes, i 
dont see any changes to be made for now.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090428/ae1bc0ef/attachment.pgp 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH] tools/envcrc: add --binary option to export embedded env
  2009-04-28 12:54       ` Mike Frysinger
@ 2009-04-28 13:45         ` Wolfgang Denk
  2009-04-28 15:39           ` Mike Frysinger
  2009-05-06 12:41           ` [U-Boot] [PATCH v2] " Mike Frysinger
  0 siblings, 2 replies; 9+ messages in thread
From: Wolfgang Denk @ 2009-04-28 13:45 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <200904280854.53669.vapier@gentoo.org> you wrote:
>
> > You mean in the code? Well, if you're using a separate section for it
> > (like the ppcenv section) this should be  straightforward  using  the
> > `=FILLEXP' output section attribute for the linker.
>
> hmm, a quick grep shows that almost no one has a dedicated section.  the 

Everybody who uses CONFIG_SYS_USE_PPCENV or CONFIG_NAND_U_BOOT has:

-> find * -name 'u-boot*.lds' | xargs fgrep -l .ppcenv | wc -l
50


> majority of people (Blackfin boards included) insert it into the middle of
> their .text section.  this is the use case i was thinking of when i said "no 
> way" because i hadnt seen anyone using a dedicated section before.

But that would be easy to change - see how it's done on ppc.

> if you want the "--binary" thing, i can post a new patch.  otherwise yes, i  
> dont see any changes to be made for now.

OK.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
While money can't buy happiness, it certainly lets  you  choose  your
own form of misery.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH] tools/envcrc: add --binary option to export embedded env
  2009-04-28 13:45         ` Wolfgang Denk
@ 2009-04-28 15:39           ` Mike Frysinger
  2009-05-06 12:41           ` [U-Boot] [PATCH v2] " Mike Frysinger
  1 sibling, 0 replies; 9+ messages in thread
From: Mike Frysinger @ 2009-04-28 15:39 UTC (permalink / raw)
  To: u-boot

On Tuesday 28 April 2009 09:45:38 Wolfgang Denk wrote:
> Dear Mike Frysinger,
>
> In message <200904280854.53669.vapier@gentoo.org> you wrote:
> > > You mean in the code? Well, if you're using a separate section for it
> > > (like the ppcenv section) this should be  straightforward  using  the
> > > `=FILLEXP' output section attribute for the linker.
> >
> > hmm, a quick grep shows that almost no one has a dedicated section.  the
>
> Everybody who uses CONFIG_SYS_USE_PPCENV or CONFIG_NAND_U_BOOT has:
>
> -> find * -name 'u-boot*.lds' | xargs fgrep -l .ppcenv | wc -l
> 50

not really ... look at the linker scripts and you'll see most do:
.text {
	...
	common/env_embedded.o (.ppcenv)
	...

that's why i didnt use the CONFIG_SYS_USE_PPCENV to figure out how many people 
had a dedicated section

> > majority of people (Blackfin boards included) insert it into the middle
> > of their .text section.  this is the use case i was thinking of when i
> > said "no way" because i hadnt seen anyone using a dedicated section
> > before.
>
> But that would be easy to change - see how it's done on ppc.

can you name a board ?  the ones i saw placed the env sector after things, 
they didnt split the .text section.  otherwise we'd have to do like:
.text.pre.env { ... custom filler ... }
.ppcenv { common/env_embedded.o (.ppcenv) }
.text { ... glob remaining .text }
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090428/f671c307/attachment.pgp 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH v2] tools/envcrc: add --binary option to export embedded env
  2009-04-28 13:45         ` Wolfgang Denk
  2009-04-28 15:39           ` Mike Frysinger
@ 2009-05-06 12:41           ` Mike Frysinger
  2009-05-10 20:11             ` Wolfgang Denk
  1 sibling, 1 reply; 9+ messages in thread
From: Mike Frysinger @ 2009-05-06 12:41 UTC (permalink / raw)
  To: u-boot

The --binary option to envcrc can be used to export the embedded env as a
binary blob so that it can be manipulated/examined/whatever externally.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v2
	- accept just --binary and have it default to 0xff padding

 tools/envcrc.c |   46 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/tools/envcrc.c b/tools/envcrc.c
index 4334cdf..5b0f7cd 100644
--- a/tools/envcrc.c
+++ b/tools/envcrc.c
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #ifndef __ASSEMBLY__
@@ -77,19 +78,56 @@ extern unsigned char environment;
 int main (int argc, char **argv)
 {
 #ifdef	ENV_IS_EMBEDDED
+	unsigned char pad = 0x00;
 	uint32_t crc;
 	unsigned char *envptr = &environment,
 		*dataptr = envptr + ENV_HEADER_SIZE;
 	unsigned int datasize = ENV_SIZE;
+	unsigned int eoe;
+
+	if (argv[1] && !strncmp(argv[1], "--binary", 8)) {
+		int ipad = 0xff;
+		if (argv[1][8] == '=')
+			sscanf(argv[1] + 9, "%i", &ipad);
+		pad = ipad;
+	}
+
+	if (pad) {
+		/* find the end of env */
+		for (eoe = 0; eoe < datasize - 1; ++eoe)
+			if (!dataptr[eoe] && !dataptr[eoe+1]) {
+				eoe += 2;
+				break;
+			}
+		if (eoe < datasize - 1)
+			memset(dataptr + eoe, pad, datasize - eoe);
+	}
 
 	crc = crc32 (0, dataptr, datasize);
 
 	/* Check if verbose mode is activated passing a parameter to the program */
 	if (argc > 1) {
-		printf ("CRC32 from offset %08X to %08X of environment = %08X\n",
-			(unsigned int) (dataptr - envptr),
-			(unsigned int) (dataptr - envptr) + datasize,
-			crc);
+		if (!strncmp(argv[1], "--binary", 8)) {
+			int le = (argc > 2 ? !strcmp(argv[2], "le") : 1);
+			size_t i, start, end, step;
+			if (le) {
+				start = 0;
+				end = ENV_HEADER_SIZE;
+				step = 1;
+			} else {
+				start = ENV_HEADER_SIZE - 1;
+				end = -1;
+				step = -1;
+			}
+			for (i = start; i != end; i += step)
+				printf("%c", (crc & (0xFF << (i * 8))) >> (i * 8));
+			fwrite(dataptr, 1, datasize, stdout);
+		} else {
+			printf("CRC32 from offset %08X to %08X of environment = %08X\n",
+				(unsigned int) (dataptr - envptr),
+				(unsigned int) (dataptr - envptr) + datasize,
+				crc);
+		}
 	} else {
 		printf ("0x%08X\n", crc);
 	}
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH v2] tools/envcrc: add --binary option to export embedded env
  2009-05-06 12:41           ` [U-Boot] [PATCH v2] " Mike Frysinger
@ 2009-05-10 20:11             ` Wolfgang Denk
  0 siblings, 0 replies; 9+ messages in thread
From: Wolfgang Denk @ 2009-05-10 20:11 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <1241613705-8622-1-git-send-email-vapier@gentoo.org> you wrote:
> The --binary option to envcrc can be used to export the embedded env as a
> binary blob so that it can be manipulated/examined/whatever externally.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
> v2
> 	- accept just --binary and have it default to 0xff padding
> 
>  tools/envcrc.c |   46 ++++++++++++++++++++++++++++++++++++++++++----
>  1 files changed, 42 insertions(+), 4 deletions(-)

Applied to "next" branch. Thanks.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
If you believe that feeling bad or worrying long enough will change a
past or future event, then you are residing on another planet with  a
different reality system.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-05-10 20:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-06 11:01 [U-Boot] [PATCH] tools/envcrc: add --binary option to export embedded env Mike Frysinger
2009-04-27 22:15 ` Wolfgang Denk
2009-04-27 23:55   ` Mike Frysinger
2009-04-28  7:13     ` Wolfgang Denk
2009-04-28 12:54       ` Mike Frysinger
2009-04-28 13:45         ` Wolfgang Denk
2009-04-28 15:39           ` Mike Frysinger
2009-05-06 12:41           ` [U-Boot] [PATCH v2] " Mike Frysinger
2009-05-10 20:11             ` Wolfgang Denk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.