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.

fw_setenv cannot pass mtd device erase

Other Parts Discussed in Thread: AM1705, OMAPL138

Hi all,

My board is custom build, based on davinici da830evm. Processor is am1705, SDK is PSP-SDK-03.22.00.06.

I have been round and round with trying to get fw_setenv working but it never gets past the ioctl call with MEMERASE. However, fw_printenv is working fine. So I've come to the experts for help.

root@module:/sbin#
root@module:/sbin# fw_printenv csi_fs_dev
csi_fs_dev=5
root@module:/sbin# fw_setenv csi_fs_dev 6
MTD erase error on /dev/mtd3: Invalid argument
Error: can't write fw_env to flash
root@module:/sbin#

I have CONFIG_ENV_SIZE defined as 0x2800 in da830evm.h

I am trying to write to the uboot environment stored at /dev/mtd3 on a NAND flash device.

root@module:/sbin# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00020000 00020000 "bootloader"
mtd1: 00020000 00020000 "AISUBL"
mtd2: 00120000 00020000 "U-Boot"
mtd3: 00040000 00020000 "U-BootEnv"
mtd4: 00600000 00020000 "kernel"
mtd5: 0fc20000 00020000 "rootfs1"
mtd6: 0fc20000 00020000 "rootfs2"
mtd7: 00002000 00001000 "BOARD-INFO"
mtd8: 001fe000 00001000 "CSI-Storage"

Here is the fw_env.config

/dev/mtd3               0x0000          0x2800          0x20000                 1

Here is strace of the same command from above.

root@module:/sbin# strace fw_setenv csi_fs_dev 6
execve("/sbin/fw_setenv", ["fw_setenv", "csi_fs_dev", "6"], [/* 12 vars */]) = 0
brk(0)                                  = 0x13000
uname({sys="Linux", node="module", ...}) = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f4b000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=13799, ...}) = 0
mmap2(NULL, 13799, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6f47000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabi/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\230\204\1\0004\0\0\0"..., 512) = 512
lseek(3, 1264508, SEEK_SET)             = 1264508
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 2840) = 2840
lseek(3, 1261076, SEEK_SET)             = 1261076
read(3, "A)\0\0\0aeabi\0\1\37\0\0\0\0054T\0\6\2\10\1\t\1\22\4\23\1\24\1"..., 42) = 42
fstat64(3, {st_mode=S_IFREG|0755, st_size=1267348, ...}) = 0
mmap2(NULL, 1303968, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6de6000
mprotect(0xb6f17000, 32768, PROT_NONE)  = 0
mmap2(0xb6f1f000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x131000) = 0xb6f1f000
mmap2(0xb6f22000, 9632, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6f22000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f46000
set_tls(0xb6f466d0, 0xb6f46db8, 0xb6f4d050, 0xb6f466d0, 0xb6f4d050) = 0
mprotect(0xb6f1f000, 8192, PROT_READ)   = 0
mprotect(0xb6f4c000, 4096, PROT_READ)   = 0
munmap(0xb6f47000, 13799)               = 0
stat64("/dev/mtd3", {st_mode=S_IFCHR|0600, st_rdev=makedev(90, 6), ...}) = 0
brk(0)                                  = 0x13000
brk(0x36000)                            = 0x36000
open("/dev/mtd3", O_RDONLY)             = 3
ioctl(3, MCE_GET_RECORD_LEN or MEMGETINFO or MTRRIOC_SET_ENTRY, {type=MTD_NANDFLASH, flags=MTD_WRITEABLE, size=0x40000, erasesize=0x20000, writesize=0x800, oobsize=0x40, padding=0}) = 0
ioctl(3, MEMGETBADBLOCK, [0])           = 0
lseek(3, 0, SEEK_SET)                   = 0
read(3, "\242[A\10baudrate=115200\0bootargs=mem"..., 10240) = 10240
close(3)                                = 0
open("/dev/mtd3", O_RDWR)               = 3
ioctl(3, MEMGETBADBLOCK, [0])           = 0
ioctl(3, MEMUNLOCK or MTRRIOC_SET_PAGE_ENTRY, {start=0, length=0x2800}) = -1 EOPNOTSUPP (Operation not supported)
ioctl(3, MCE_GET_LOG_LEN or MEMERASE or MTRRIOC_DEL_ENTRY, {start=0, length=0x2800}) = -1 EINVAL (Invalid argument)
write(2, "MTD erase error on /dev/mtd3: In"..., 47MTD erase error on /dev/mtd3: Invalid argument
) = 47
close(3)                                = 0
write(2, "Error: can't write fw_env to fla"..., 35Error: can't write fw_env to flash
) = 35
exit_group(1)                           = ?
+++ exited with 1 +++
root@module:/sbin#

thanks for reviewing this.

Dan

  • Hello Titus,

    I had read that thread before. It sounded promising but doesn't look like the problem was resolved. My situation is similar, everything else seems to work fine: nandwrite, flash_erase, flashcp, etc. I don't see any complaints about ecc but I don't think the fw_setenv is getting that far.

  • Hi Dan,

    Could you please try with the attached "fw_setenv"

    7608.fw_printenv.txt

    Rename "fw_printenv.txt" to "fw_printenv" and also to ""fw_setenv"

    I'm able to work with this attached binary on OMAPL138 LCDK board.

    struct mtd_partition omapl138_lcdk_nandflash_partition[] = {
    	{
    		.name           = "u-boot env",
    		.offset         = 0,
    		.size           = SZ_128K,
    		.mask_flags     = 0,	//Titus : Enable the permission
    	},
    	{
    		.name           = "u-boot",
    		.offset         = MTDPART_OFS_APPEND,
    		.size           = SZ_512K,
    		.mask_flags     = MTD_WRITEABLE,
    	},
    	{
    		.name           = "kernel",
    		.offset         = MTDPART_OFS_APPEND,
    		.size           = SZ_2M,
    		.mask_flags     = 0,
    	},
    	{
    		.name           = "filesystem",
    		.offset         = MTDPART_OFS_APPEND,
    		.size           = MTDPART_SIZ_FULL,
    		.mask_flags     = 0,
    	},
    };
    

    Log:

    root@omapl138-lcdk:~# cd /
    root@omapl138-lcdk:/# ./fw_printenv
    Warning: Bad CRC, using default environment
    bootcmd=bootp; setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostm
    bootdelay=5
    baudrate=115200
    root@omapl138-lcdk:/# ./fw_setenv bootdelay 3
    Warning: Bad CRC, using default environment
    root@omapl138-lcdk:/# ./fw_printenv
    bootcmd=bootp; setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostm
    baudrate=115200
    bootdelay=3
    root@omapl138-lcdk:/# cat /etc/fw_env.config
    # Configuration file for fw_(printenv/saveenv) utility.
    # Up to two entries are valid, in this case the redundant
    # environment sector is assumed present.
    # Notice, that the "Number of sectors" is ignored on NOR and SPI-dataflash.
    # Futhermore, if the Flash sector size is ommitted, this value is assumed to
    # be the same as the Environment size, which is valid for NOR and SPI-dataflash

    # NOR example
    # MTD device name       Device offset   Env. size       Flash sector size       Number of sectors
    #/dev/mtd1              0x0000          0x4000          0x4000
    /dev/mtd0               0x0000          0x4000          0x20000

    # MTD SPI-dataflash example
    # MTD device name       Device offset   Env. size       Flash sector size       Number of sectors
    #/dev/mtd5              0x4200          0x4200
    #/dev/mtd6              0x4200          0x4200

    # NAND example
    #/dev/mtd0              0x4000          0x4000          0x20000                 2
    root@omapl138-lcdk:/#
    root@omapl138-lcdk:/#
    root@omapl138-lcdk:/#
    root@omapl138-lcdk:/#
    root@omapl138-lcdk:/# cat /proc/partitions
    major minor  #blocks  name

      31        0        128 mtdblock0
      31        1        512 mtdblock1
      31        2       2048 mtdblock2
      31        3     521600 mtdblock3
    root@omapl138-lcdk:/#
    root@omapl138-lcdk:/# cat /proc/mtd
    dev:    size   erasesize  name
    mtd0: 00020000 00020000 "u-boot env"
    mtd1: 00080000 00020000 "u-boot"
    mtd2: 00200000 00020000 "kernel"
    mtd3: 1fd60000 00020000 "filesystem"
    root@omapl138-lcdk:/#

  • Titus,

    Thank you! That build works exactly as I want.

    root@spm7:~# fw_setenv csi_fs_dev mtdblock6
    root@spm7:~#
    root@spm7:~#
    root@spm7:~# fw_printenv
    baudrate=115200
    bootargs=mem=32M console=ttyS1,115200n8 root=/dev/mtdblock6 rw rootfstype=jffs2
    bootcmd=nboot.e 0xc0700000 0 0x1a0000;bootm
    bootdelay=3
    bootfile=uImage
    csi_module=CSI_MODULE_SPM
    ethact=DaVinci-EMAC
    ethaddr=70:b3:d5:3c:21:2c
    stderr=serial
    stdin=serial
    stdout=serial
    ver=U-Boot 2012.04.01 (Aug 15 2014 - 10:33:48)
    csi_fs_dev=mtdblock6
    root@spm7:~#

    If this is a simple fix I'd like to get it into our code base, but in the least I can archive your fw_printenv image.

    thanks,

    Dan

  • Hi Dan,

    Thanks for your update.

    Apologize, actually I have downloaded this binary from internet which had the fix for "Error: can't write fw_env to flash" and actually that link referring the old bootloader source.

    Try this and let me know.

    3617.fw_env.c