* ** Warning-bad CRC or nand, using default environment

Source: Internet
Author: User
Tags crc32

When uboot start, dispaly following info:

U-boot 1.1.6 (Mar 19 2008-14:02:12)

So Google and find,

Means nothing wrong, but need some environment variables for uboot when booting.

, And "The message will go away as soon as you save the envrionment variables usingCommand"

Digest from:

Http://www.denx.de/wiki/DULG/WarningBadCRCUsingDefaultEnvironment

Http://www.koansoftware.com/it/art.php? Art = 80

[Postscript]

Explain the cause and solution of *** warning-bad CRC or NAND and using default environment:

[Reason]

The logic in uboot is that after the Assembly is executed, it is switched to the C code entry (here it is the ARM platform), and here it is lib_arm \ board. start_armboot in C, which will be called after a series of initialization

/* Initialize environment */
Env_relocate ();

To load environment variables, env_relocate () in common \ env_common.c ():

If (Gd-> env_valid = 0 ){
# If defined (config_where) | defined (config_env_is_nowhere)/* environment not changable */
Puts ("using default environment \ n ");
# Else
Puts ("*** warning-bad CRC, using default environment \ n ");
Show_boot_progress (-60 );
# Endif
Set_default_env ();
}
Else {
Env_relocate_spec ();
}

It is determined based on whether or not the GD-> env_valid is initialized and whether it is set to 1,

Is to directly call the default environment variable, (I defined in uboot here is # define config_env_is_in_nand
In env_nand.c, it has initialized Gd-> env_valid = 1 ;)

Or call env_relocate_spec () to load the environment variables you previously stored from the specified device.

Here, as described above, we will execute env_relocate_spec (),

In common \ env_nand.c

Void env_relocate_spec (void)
{
# If! Defined (env_is_embedded)
Int ret;

Ret = readenv (config_env_offset, (u_char *) env_ptr );
If (RET)
Return use_default ();

If (CRC32 (0, env_ptr-> data, env_size )! = Env_ptr-> CRC)
Return use_default ();
# Endif /*! Env_is_embedded */
}

Static void use_default ()
{
Puts ("*** warning-bad CRC or nand, using default environment \ n ");
Set_default_env ();
}

It is clear that if readenv fails to read the environment variable, use_default is called to use the default environment variable.

If the CRC32 check fails even if the data is read correctly, use_default is called to use the default environment variable.

In both cases, when use_default is called, *** warning-bad CRC or NAND and using default environment will be printed. Then, when you compile uboot, define the default values in your own header files. For example, for commonly used startup parameters and startup commands, what is in my code is:

/* Read kernel from mtdblock2 no matter for 24/4 K pagesize NAND */
# Define config_bootcommand "NAND read 0x40007fc0 0x100000 0x200000; bootm 0x40007fc0"
/* Mmcblk0p2-> rootfs partition */
# Define config_bootargs "root =/dev/mtdblock2 RW init =/linuxrc console = ttyama1, 115200 mem = 64 m rootfstype = yaffs2"
If the environment variables you read from the specified NAND device are normal, then those values will be used instead of the values written in your code.

[Solution]

After knowing the specific cause, it is easy to solve the problem:

1. The normal way is, if you are sure you have implemented saveenv, that is,

The corresponding value has been defined in the header file:

Here I use the NAND storage env as an example, which is similar to this:

/* Use NAND to store env */
# Define config_env_is_in_nand
/*
Current layout:
0-0x100000, uboot;
0x100000-0x800000, kernel;
0x800000-0x900000, ENV;
0x900000 -~ , Rootfs;
*/
# Define config_env_offset 0x800000
# Define config_env_addr config_env_offset/* duplicate define */
# Define config_env_size 0X4000/* 16kb is large enough */
/* Set the block size to the max one: 128kb of 2 K, 512kb of 4 K pagesze NAND */
# Define config_env_sect_size 0x80000
# Define config_sys_env_overwrite 1
# Define config_assist_saveenv 1

Make sure that your Data Reading code is OK:

That is to say, you have implemented functions related to the NAND drive, and can read/write data and erase the block.

Then, the saveenv should work properly.

In this case, you can enter uboot after the first startup (this warning will be triggered for the first time) (generally press the s key, provided that you set the uboot wait time in your code, run the command to enter uboot) and run saveenv to store the default env values obtained from the code for the first time to the NAND. After that, no such prompt will appear, because you can normally read and write the corresponding env from the specified NAND device.

2. if you want something special and do not want others to change the Env values such as your startup parameters, you can choose not to define config_sys_env_overwrite in the header file, and then do not define config_env_is_in_nand similar to this.

When other people cannot modify these environment variables, they will prompt you every time

* ** Warning-bad CRC or nand, using default environment. In this case, you can directly comment out the line ..., although the practice is not elegant, it can still achieve the purpose...

[Summary]

In a word, as long as the source code is available, the problem cannot be solved. For all problems, refer to the source code to find the root cause.

For ARM + nand, the specific files and functions are summarized as follows:

1. lib_arm \ board. c

Void start_armboot (void)
{

...

For (init_fnc_ptr = init_sequence; * init_fnc_ptr; ++ init_fnc_ptr ){
If (* init_fnc_ptr )()! = 0) {// env_init () will be called here ()
Hang ();
}
}

...

/* Initialize environment */
Env_relocate ();

...

}

2. For env_init (), because config_env_is_in_nand is specified here, it corresponds:

Common \ env_nand.c:

Int env_init (void)
{

...

GD-> env_valid = 1;

...

}

3. Common \ env_common.c:

Void env_relocate (void)
{

...

If (Gd-> env_valid = 0 ){
# If defined (config_where) | defined (config_env_is_nowhere)/* environment not changable */
Puts ("using default environment \ n ");
# Else
Puts ("*** warning-bad CRC, using default environment \ n ");
Show_boot_progress (-60 );
# Endif
Set_default_env ();
}
Else {
Env_relocate_spec ();
}
...

}

4. env_relocate_spec here, which corresponds to common \ env_nand.c:

Void env_relocate_spec (void)
{
# If! Defined (env_is_embedded)
Int ret;

Ret = readenv (config_env_offset, (u_char *) env_ptr );
If (RET)
Return use_default ();

If (CRC32 (0, env_ptr-> data, env_size )! = Env_ptr-> CRC)
Return use_default ();
# Endif /*! Env_is_embedded */
}

5. Common \ env_nand.c:

Static void use_default ()
{
Puts ("*** warning-bad CRC or nand, using default environment \ n ");
Set_default_env ();
}

Therefore, an error is prompted. OK. The summary is complete. If there is a problem, it is best to track the code on your own. It can be done in the end.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.