Set Default ENV in Uboot


1. Overview

21x/22x从V11版本相关配置已默认切换到env双备份机制,在这个机制下还可以增加一种设置default env的方法再给ENV增加一份保护。


2. How to Set

When the env partition is suddenly powered off during reading and writing, there is a small probability that the data will be damaged, and the env will be lost, causing the system to fail to start. To avoid this, when the CRC fails, it will automatically start with the default value. The settings of each user partition may be different, but the following setting steps are the same.

The following log shows that ENV CRC failed:

Take NAND flash as an example (for NOR flash, please check the relevant code)

Modify the corresponding macro definition in boot/include/configs/pioneer3.h (MTDPARTS_DEFAULT is more than one, please make sure that the change is correct):

  1. Make sure the contents of CONFIG_BOOTARGS and bootargs in uboot are the same

  2. Make sure the contents of CONFIG_BOOTCOMMAND and bootcmd in uboot are the same

  3. Make sure the contents of MTDPARTS_DEFAULT and mtdparts in uboot are the same

  4. Fill in CONFIG_EXTRA_ENV_SETTINGS, and the environment variables needed in uboot, Please pay attention to ernel_file_size and recovery_file_size. If the fastboot version includes rootfs_file_size, the burn value is the file size. If the file size cannot be judged, it will default to the partition size!

    #define CONFIG_BOOTARGS "ubi.mtd=UBI,2048 root=/dev/mtdblock7 rootfstype=squashfs ro init=/linuxrc LX_MEM=0x3FE0000 mma_heap=mma_heap_name0,miu=0,sz=0x1E00000 cma=2M highres=off mmap_reserved=fb,miu=0,sz=0x300000,max_start_off=0x3300000,max_end_off=0x3600000 mtdparts=nand0:1664k@1280k(BOOT0),1664k(BOOT1),256k(ENV),256k(ENV1),128k(KEY_CUST),5m(KERNEL),5m(RECOVERY),6m(rootfs),640k(MISC),108800k(UBI)"
    #define CONFIG_BOOTCOMMAND \
    "nand read.e 0x22000000 KERNEL ${kernel_file_size};" \
    "dcache on ;" \
    "bootlogo 0 0 0 0;" \
    "bootm 0x22000000;" \
    "nand read.e 0x22000000 RECOVERY ${recovery_file_size};" \
    "dcache on ;" \
    "bootm 0x22000000" \
    ""
    #define MTDIDS_DEFAULT "nand0=nand0" /* "nor0=physmap-flash.0,nand0=nand" */
    /* must be different from real partition to test NAND partition function */
    #define MTDPARTS_DEFAULT "mtdparts=nand0:1664k@1280k(BOOT0),1664k(BOOT1),256k(ENV),256k(ENV1),128k(KEY_CUST),5m(KERNEL),5m(RECOVERY),6m(rootfs),640k(MISC),108800k(UBI)"
    #define CONFIG_EXTRA_ENV_SETTINGS \
    "mtdids=" MTDIDS_DEFAULT "\0" \
    "mtdparts=" MTDPARTS_DEFAULT "\0" \
    "partition=nand0,0\0" \
    "autoestart=0\0" \
    "baudrate=115200\0" \
    "bootdelay=0\0" \
    "ethact=sstar_emac\0" \
    "ethaddr=00:30:1b:ba:02:db\0" \
    "kernel_file_size=0x500000\0" \
    "mtddevname=BOOT0\0" \
    "mtddevnum=0\0" \
    "recovery_file_size=0x500000\0" \
    "sstar_bbm=off\0" \
    "stderr=serial\0" \
    "stdin=serial\0" \
    "stdout=serial\0" \
    "usb_folder=images\0" \
    ""
    

After setting the default env necessary for system startup in boot/include/configs/pioneer3.h, recompile uboot and update it to the board to ensure that the system can still be started normally when the env data is lost.