Skip to contentSkip to conversation

Environment "image" tool

U-Boot Alessio Sangalli 3 participants 9 messages Jul 16, 2011 – Jul 18, 2011

lore
Share & tools
lore
#0 lore raw

Hi, is there a tool to create an "environemnt image" that I can flash to my NAND?

I think I've seen a tool that takes a text file with an environment setting per line, calculates the CRC and generates a binary that can be transferred to the board (via tftp or other means) to be written with "nand write".

Alternatively, is there a description of how the environment is read, my U-Boot, so that I can write my own program to create such image?

Thanks!
bye
as

#1 lore raw

Dear Alessio Sangalli,

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

Hi, is there a tool to create an "environemnt image" that I can flash to my NAND?

I think I've seen a tool that takes a text file with an environment setting per line, calculates the CRC and generates a binary that can be transferred to the board (via tftp or other means) to be written with "nand write".

Alternatively, is there a description of how the environment is read, my U-Boot, so that I can write my own program to create such image?

Just load the text file into U-Boot (for example using TFTP or reading from some file system) and use "env import -t" on it.

Best regards,

Wolfgang Denk

Signature · 4 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're not part of the solution, you're part of the problem.
#2 lore raw
Quoted 4 lines · Wolfgang Denk

Dear Alessio Sangalli,

Just load the text file into U-Boot (for example using TFTP or reading from some file system) and use "env import -t" on it.

Hi Wolfgang!

Thanks this is a very interesting way but in this application it'd be easier to just flash what is needed on the NAND, so that I won't need an interactive session with U-Boot on the board.

I am writing a "flashing tool" for my NAND chip.

Is the format that U-Boot uses to write the environment "stable" or it could change?

Thanks!
bye
as

#3 lore raw
Quoted 4 lines · Alessio Sangalli

I am writing a "flashing tool" for my NAND chip.

Is the format that U-Boot uses to write the environment "stable" or it could change?

So I have written in my application some code that:

1) takes an area equivalent in size to ENV_SIZE and places a series of '\0' terminated strings
2) calculates the CRC32 and places it in the first 4 bytes

This is written to the NAND and used by U-Boot, no problems at all.

My application is GLP-3 and available at:

https://gitorious.org/microflasher

bye
as

#4 lore raw
In reply to Alessio Sangalli
Quoted 2 lines · Alessio Sangalli

Hi, is there a tool to create an "environemnt image" that I can flash to my NAND?

tools/envcrc will output the binary env blob if you give it the --binary option. but it does not take arbitrary env inputs. ./tools/envcrc --binary > env.bin

Quoted 4 lines

I think I've seen a tool that takes a text file with an environment setting per line, calculates the CRC and generates a binary that can be transferred to the board (via tftp or other means) to be written with "nand write".

sounds like it might be a useful addition to tools/envcrc

Quoted 2 lines

Alternatively, is there a description of how the environment is read, my U-Boot, so that I can write my own program to create such image?

<4 byte crc><var=value>\0[<var=value>\0]...\0
-mike

#5 lore raw
Quoted 7 lines · Mike Frysinger
Quoted 2 lines · Alessio Sangalli

Hi, is there a tool to create an "environemnt image" that I can flash to my NAND?

tools/envcrc will output the binary env blob if you give it the --binary option. but it does not take arbitrary env inputs. ./tools/envcrc --binary > env.bin

In the meanwhile I've written my own utility, but I do not understand the "it does not take arbitrary env inputs".

Quoted 1 line

sounds like it might be a useful addition to tools/envcrc

I could not find it so I rewrote such functionality. If you want, I could extract the relevant part of the code and send it to you. It's quite trivial once I figured out how the U-Boot environment works.

Quoted 4 lines
Quoted 2 lines

Alternatively, is there a description of how the environment is read, my U-Boot, so that I can write my own program to create such image?

<4 byte crc><var=value>\0[<var=value>\0]...\0

Yes, and the environment has a size specified by ENV_SIZE

bye
as

#6 lore raw
Quoted 11 lines · Alessio Sangalli
Quoted 7 lines · Mike Frysinger
Quoted 2 lines · Alessio Sangalli

Hi, is there a tool to create an "environemnt image" that I can flash to my NAND?

tools/envcrc will output the binary env blob if you give it the --binary option. ?but it does not take arbitrary env inputs. ./tools/envcrc --binary > env.bin

In the meanwhile I've written my own utility, but I do not understand the "it does not take arbitrary env inputs".

tools/envcrc atm only outputs the default env that the board is configured for. you cant give it a text representation of the env and have it calc things.

although thinking about it a bit more, you probably could do it in shell. (cat <env file> | tr '\n' '\0' ; dd if=/dev/zero count=1 ibs=1) > env.bin env_size=8192
pad_size=$(( env_size - $(set -- $(du -b env.bin); echo $1) - 4)) dd if=/dev/zero ibs=$pad_size count=1 | tr '\0' '\377' >> env.bin

and then you get the crc and prepend the 4 bytes
crc env.bin

Quoted 5 lines
Quoted 1 line

sounds like it might be a useful addition to tools/envcrc

I could not find it so I rewrote such functionality. If you want, I could extract the relevant part of the code and send it to you. It's quite trivial once I figured out how the U-Boot environment works.

extending tools/envcrc to take a --file option and use that rather than the linked in default would be cool imo.
-mike

#7 lore raw
Quoted 8 lines · Mike Frysinger

although thinking about it a bit more, you probably could do it in shell. (cat <env file> | tr '\n' '\0' ; dd if=/dev/zero count=1 ibs=1) > env.bin env_size=8192
pad_size=$(( env_size - $(set -- $(du -b env.bin); echo $1) - 4)) dd if=/dev/zero ibs=$pad_size count=1 | tr '\0' '\377' >> env.bin

and then you get the crc and prepend the 4 bytes
crc env.bin

Hi! I am not sure here how you would calculate the crc in the shell script. Are you suggesting there is a command "crc(1)"?

Quoted 2 lines

extending tools/envcrc to take a --file option and use that rather than the linked in default would be cool imo.

I will have a look at that prgram.

bye!!!
as

#8 lore raw
Quoted 7 lines · Alessio Sangalli
Quoted 6 lines · Mike Frysinger

although thinking about it a bit more, you probably could do it in shell. (cat <env file> | tr '\n' '\0' ; dd if=/dev/zero count=1 ibs=1) > env.bin env_size=8192
pad_size=$(( env_size - $(set -- $(du -b env.bin); echo $1) - 4)) dd if=/dev/zero ibs=$pad_size count=1 | tr '\0' '\377' >> env.bin

Quoted 5 lines
Quoted 2 lines

and then you get the crc and prepend the 4 bytes
crc env.bin

Hi! I am not sure here how you would calculate the crc in the shell script. Are you suggesting there is a command "crc(1)"?

there is indeed such a command. the "xc" program suite provides one. i'm sure there are others as well like crc32.

$ crc env.bin
5473921d    8188  env.bin
-mike