Project open source address: github.com/Mculover666…

0. Tutorial complete directory

1. Locate environment variables

The uboot supports SDRAM, Nor Flash, Nand Flash, and DM9000.



The reason for this warning is that the environment variable parameters have not been set, so the uboot fails to read the verification parameters. The default parameters are used.

Find the location by searching this line of log content:



common/env_common.cFind the function where this line of code resides in the file:



The main use of this functiondefault_environmentArray, and then look at the contents of that array, again defined in this file, and the function of that array isSet the default environment variable parameters according to the macro definition we defined.

2. Set default parameters

In single board configuration files include/configs/smdk2440 h configured in the relevant macro definition:

2.1. Kernel boot related

The CONFIG_BOOTARGS macro definition is the parameter passed in when the kernel is booted. Add the following configuration:

/* Kernel startup ENV */
#define CONFIG_BOOTARGS		"The console = ttySAC0, 115200 root = / dev/mtdblock3." "
#define	CONFIG_BOOTCOMMAND	"nand read 30000000 kernel 0x200000; bootm 30000000"
Copy the code

2.2. Network related

/* Network related ENV */
#define CONFIG_NETMASK		255.255.255.0
#define CONFIG_IPADDR		192.168.1.6
#define CONFIG_SERVERIP		192.168.1.3
#define CONFIG_ETHADDR		52:54:00:7c:df:b7
#define CONFIG_GATEWAYIP	192.168.1.1
Copy the code



Compile, download to development board, view serial port output:



Due to the CONFIG_BOOTCOMMAND macro definition configured, the countdown time starts when uboot is started. You must press any key within the configured time (5s by default) to enter the command line. Otherwise, you can directly pass the configured kernel parameters and use the configured command to boot the kernel.

Press the button to enter the CLI mode and check whether the network configuration information is configured by yourself:



The default configuration was successfully modified, but the following message is displayed at startup:

3. Run the saveenv command

This is because only the macro definitions in the code have been changed and these environment variable parameters have not been saved to Flash, so when the Uboot starts up, the error occurs to read the parameters in Flash, and the default environment variables are used, which are the macro definitions configured in Section 2.

You can see the saveenv command in the uboot command list to store the value of the environment variable to the current memory:



A global search for an implementation of saveenv found two definitions:

  • incommon/env_nand.cIn files: Saveenv stores environment variables in Nand flash;
  • incommon/env_flash.cIn files: Saveenv stores environment variables in NOR Flash;

If the two files have conflicting definitions, they will not be added to the project at the same time, so look at the makefile in the same directory as the two files:

As can be seen, the result is:

  • Config macro definition CONFIG_ENV_IS_IN_FLASH: joincommon/env_flash.cFile;
  • Configuration macro definition CONFIG_ENV_IS_IN_NAND: joincommon/env_nand.cFile;

Next, test storing environment variables in Nand Flash.

First, configure the macro definition in the board configuration file. Note that it conflicts with another macro definition:



Enter thecommon/env_nand.cFind the saveenv definition in the file:



It can be seen that there are three macro definitions in the definition, indicating the memory address, size, erasing range, add configuration in the board file (note to remove the conflict of the original macro definition) :



Then compile, write to development board, test in serial terminal:



Saveenv succeeds, restart the development board, and you can see that uboot has read environment variables from nand flash by default.Warnings disappear:

4. Dynamically modify environment variables and save the Settings

You can useprintView the values of all environment variables:

These environment variables can be modified using the uboot command set, for example:

setIpaddr 192.168.1.8Copy the code

Then save the environment variable to Flash:

saveenv
Copy the code

During the power-on, the Uboot automatically reads the environment variables in the Flash and displays the newly configured values.

Welcome to subscribe to my wechat official account: “McUlover666”.