This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM3354: uEnv.txt stored in mmcblk0p2 (ext4 file system) gives an error invalid CRC

Part Number: AM3354

I have u-boot env stored in MMC and default values in code get stored in MMC and works fine. 

I want to add few objects/modify from linux. I tried to use fw_printenv/fw_saveenv , which didnt work. 

I think the best option would be to use uEnv.txt.

So I copied my default env to uEnv.txt and stored in /dev/mmcblk0p2, which is n ext4 file system and gave the name as entry in u-boot configuration

The uboot code tries to read the file from ext4 file system , it reads the file but says CRC32 error and then load defaults from the MMC. I have been trying to solve this for few days

Any help appeciated

  • Hi Anees,
    An alternative option is to build the u-boot environment variable into u-boot itself.
    I'm using the latest AM335x SDK 6.3 as an example, u-boot environment variables are configured in files...
    "am335x_evm.h, ti_am335x_common.h, ti_armv7_omap.h under /include/configs/"
    "mmc.h, board.h under /include/environment/ti"
    Best,
    -Hong

  • Well, that will not work, since i have few variables I need to update in linux , so its ideal to be placed in uEnv.txt and then any change in uboot later on will not impact the product.

    I went down the path to tracking down where the crc was called .tried to look into file u-boot/cmd/nvedit.c in the function

    static int do_env_import(cmd_tbl_t *cmdtp, int flag,
    int argc, char * const argv[])

     as below. But doesnt seem to solve it. if any one has an idea pls share!!!!

    #if 0
    if (chk) {
    uint32_t crc;
    env_t *ep = (env_t *)ptr;
    size -= offsetof(env_t, data);
    memcpy(&crc, &ep->crc, sizeof(crc));
    if (crc32(0, ep->data, size) != crc) {
    puts("## Error: bad CRC, import failed\n");
    return 1;
    }
    ptr = (char *)ep->data;
    }

    #endif

  • Hi Anees,
    What type of CRC error was observed on your setup?
    If it is "puts("## Error: bad CRC, import failed\n");" from the function do_env_import() in "/cmd/nvedit.c",
    One option would be checking ep->crc against crc32(0, ep->data, size) via adding printf or using JTAG.
    Did you have CRC32 option when you export u-boot environment file?

    		memcpy(&crc, &ep->crc, sizeof(crc));
    		if (crc32(0, ep->data, size) != crc) {
    			puts("## Error: bad CRC, import failed\n");
    			return 1;
    		}

    Best,

    -Hong

  • Just to clarify the first letter in env is replaced in every line with \

  • Hi Anees,
    What type of CRC error was observed on your setup?
    I'm tring to simulate your user case if the error is triggered from "puts("## Error: bad CRC, import failed\n");"
    in function do_env_import() in "/cmd/nvedit.c".
    I'm attaching my test run as listed below.

    Note that there's CRC32 endianness swap necessary depending on how you generate and pre-append CRC32 to your environment file.
    Specifically in my test, crc32 for 81000004 ... 8100001e ==> 57906077 as listed below:
    81000000: 57 90 60 77 75 45 6e 76 5f 54 45 53 54 3d 74 65 W.`wuEnv_TEST=te
    81000010: 73 74 69 6e 67 20 75 45 6e 76 2e 74 78 74 3b 00
    But I have to manually swap CRC32 as shown below in order to pass CRC check in do_env_import()
    81000000: 77 60 90 57 75 45 6e 76 5f 54 45 53 54 3d 74 65 w`.WuEnv_TEST=te
    81000010: 73 74 69 6e 67 20 75 45 6e 76 2e 74 78 74 3b 00 sting uEnv.txt;

    => setenv bootenvfile uEnv_test.txt
    => setenv uEnv_addr 0x81000004
    => setenv uEnv_crc_addr 0x81000000
    => fatload mmc ${mmcdev} ${uEnv_addr} ${bootenvfile}
    27 bytes read in 14 ms (1000 Bytes/s)
    => md.b ${uEnv_crc_addr}
    81000000: 00 00 00 00 75 45 6e 76 5f 54 45 53 54 3d 74 65    ....uEnv_TEST=te
    81000010: 73 74 69 6e 67 20 75 45 6e 76 2e 74 78 74 3b 00    sting uEnv.txt;.
    81000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    81000030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    => printenv filesize
    filesize=1b
    => env import -c ${uEnv_addr} 1B
    ## Error: bad CRC, import failed
    => crc32 ${uEnv_addr} ${filesize} ${uEnv_crc_addr}
    crc32 for 81000004 ... 8100001e ==> 57906077
    => md.b ${uEnv_crc_addr}
    81000000: 57 90 60 77 75 45 6e 76 5f 54 45 53 54 3d 74 65    W.`wuEnv_TEST=te
    81000010: 73 74 69 6e 67 20 75 45 6e 76 2e 74 78 74 3b 00    sting uEnv.txt;.
    81000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    81000030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    => env import -c ${uEnv_crc_addr} 1F
    ## Error: bad CRC, import failed
    => mm.l ${uEnv_crc_addr}
    81000000: 77609057 ? 0x57906077
    81000004: 766e4575 ?                                                              
    => md.b ${uEnv_crc_addr}
    81000000: 77 60 90 57 75 45 6e 76 5f 54 45 53 54 3d 74 65    w`.WuEnv_TEST=te
    81000010: 73 74 69 6e 67 20 75 45 6e 76 2e 74 78 74 3b 00    sting uEnv.txt;.
    81000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    81000030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    => env import -c ${uEnv_crc_addr} 1F
    => printenv uEnv_TEST
    uEnv_TEST=testing uEnv.txt;
    => 

    Best,

    -Hong

    .

  • The issue was with env address. i changed it in uboot to E000000 and then everything is working fine. I can use fw_printenv and fw_setenv to read env from linux