Skip to contentSkip to conversation

tools/envcrc: add --binary option to export embedded env

PATCH New Mike Frysinger 2 participants 9 messages Apr 6, 2009 – May 10, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/envcrc: add --binary option to export embedded env

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.

---
 tools/envcrc.c |   45 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 41 insertions(+), 4 deletions(-)
tools/envcrc.c +41 -4
index 4334cdf..ac24967 100644
@@ -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);
 	}
Signature · 1 line
1.6.2.2
#1 lore raw

PATCH 1/1 tools/envcrc: add --binary option to export embedded env

Dear Mike Frysinger,

Quoted 21 lines · In message <[email protected]> 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.

---
 tools/envcrc.c |   45 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 41 insertions(+), 4 deletions(-)
tools/envcrc.c +1 -0
index 4334cdf..ac24967 100644
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #ifndef __ASSEMBLY__

tools/envcrc.c extern unsigned char environment; · line 81

Quoted 4 lines
tools/envcrc.c +1 -0
@@ -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

Signature · 6 lines
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
#2 lore raw

PATCH 1/1 tools/envcrc: add --binary option to export embedded env

Quoted 4 lines · On Monday 27 April 2009 18:15:58 Wolfgang Denk wrote:
Quoted 3 lines · In message Mike Frysinger

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.

Quoted 8 lines

tools/envcrc.c extern unsigned char environment; · line 81

Quoted 5 lines
tools/envcrc.c +1 -0
@@ -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

#3 lore raw

PATCH 1/1 tools/envcrc: add --binary option to export embedded env

Dear Mike Frysinger,

Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 3 lines

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.

Quoted 9 lines

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

Signature · 5 lines
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"
#4 lore raw

PATCH 1/1 tools/envcrc: add --binary option to export embedded env

Quoted 11 lines · On Tuesday 28 April 2009 03:13:05 Wolfgang Denk wrote:
Quoted 6 lines · In message Mike Frysinger
Quoted 2 lines

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.

Quoted 7 lines
Quoted 7 lines

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.

Quoted 7 lines
Quoted 2 lines

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

#5 lore raw

PATCH 1/1 tools/envcrc: add --binary option to export embedded env

Dear Mike Frysinger,

Quoted 6 lines · In message <[email protected]> you wrote:
Quoted 4 lines

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

Quoted 3 lines

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.

Quoted 2 lines

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

Signature · 5 lines
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.
#6 lore raw

PATCH 1/1 tools/envcrc: add --binary option to export embedded env

Quoted 7 lines · On Tuesday 28 April 2009 09:45:38 Wolfgang Denk wrote:

Dear Mike Frysinger,

Quoted 4 lines · In message <[email protected]> you wrote:
Quoted 3 lines

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.

Quoted 6 lines
Quoted 1 line

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

Quoted 6 lines
Quoted 4 lines

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

#7 lore raw

PATCH v2 1/1 tools/envcrc: add --binary option to export embedded env

In reply to Wolfgang Denk

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.

---
v2
- accept just --binary and have it default to 0xff padding

 tools/envcrc.c |   46 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 42 insertions(+), 4 deletions(-)
tools/envcrc.c +42 -4
index 4334cdf..5b0f7cd 100644
@@ -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);
 	}
Signature · 1 line
1.6.2.5
#8 lore raw

PATCH v2 1/1 tools/envcrc: add --binary option to export embedded env

Dear Mike Frysinger,

Quoted 10 lines · In message <[email protected]> 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.

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

Signature · 6 lines
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.