Bad CRC after saving uboot Environment

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bad CRC after saving uboot Environment

Jump to solution
5,064 Views
trongthinh
Contributor IV

I created a uboot environment file by this command:

$ mkenvimage -s 0x4200 -o uEnv.bin uboot-env.txt

Then I load this uboot env file in uboot command line:

=> fatload mmc 3:1 0x12100000 uEnv.bin
16896 bytes read in 15 ms (1.1 MiB/s)
=> env import -c 0x12100000 0x4200
=> env print bootcompleted
bootcompleted=true

It works, because the value of var bootcompleted is correct. Afterthat, I would like to change the value of bootcompleted and save to uEnv.bin

=> setenv bootcompleted false
=> env export -c 0x12100000 -s 0x4200
=> fatwrite mmc 3:1 0x12100000 uEnv.bin 0x4200
16896 bytes written

Then, I reboot the board and import uboot env from uEnv.bin again

=> fatload mmc 3:1 0x12100000 uEnv.bin
16896 bytes read in 18 ms (916 KiB/s)
=> env import -c 0x12100000 0x4200
## Error: bad CRC, import failed

It said that imported failed because bad CRC. how to fix this problem? Please advise! 

Labels (3)
1 Solution
4,834 Views
kunalkotecha1
Senior Contributor II

Hi trongthinh,

The "mkenvimage" source generates the redundant environment variable from text file based on key-value pairs. It is appending the CRC at the beginning of the generated binary file, to make sure at load time that the file is not corrupted.You can see the implementation of "mkenvimage" source code located at "tools/mkenvimage.c"

As you are over-writing  uEnv.bin file in u-boot using the "fatwrite" command. Next time you try to import the same binary file it will give a CRC error as you are getting.

According to me, you should import the new u-boot environment variable and then you can save those environment variables "saveenv". If you want, you can change and again save them. After importing once it will be always shown in "printenv" and there won't be the requirement of importing again. I don't see any requirement to write the updated u-boot variable to the binary(uEnv.bin) file again. Is there any specific use case for which you want to write back to binary file?

Feel free to let us know if you have any confusion.

Regards,

Kunal

View solution in original post

0 Kudos
2 Replies
4,835 Views
kunalkotecha1
Senior Contributor II

Hi trongthinh,

The "mkenvimage" source generates the redundant environment variable from text file based on key-value pairs. It is appending the CRC at the beginning of the generated binary file, to make sure at load time that the file is not corrupted.You can see the implementation of "mkenvimage" source code located at "tools/mkenvimage.c"

As you are over-writing  uEnv.bin file in u-boot using the "fatwrite" command. Next time you try to import the same binary file it will give a CRC error as you are getting.

According to me, you should import the new u-boot environment variable and then you can save those environment variables "saveenv". If you want, you can change and again save them. After importing once it will be always shown in "printenv" and there won't be the requirement of importing again. I don't see any requirement to write the updated u-boot variable to the binary(uEnv.bin) file again. Is there any specific use case for which you want to write back to binary file?

Feel free to let us know if you have any confusion.

Regards,

Kunal

0 Kudos
4,834 Views
trongthinh
Contributor IV

Dear Kunal,

I think it is an incorrect usage in my case. Thank for clarify me.

Regards,