Sorry, you need to enable JavaScript to visit this website.

fw_setenv corrupts env

2 posts / 0 new
joshua5526's picture
fw_setenv corrupts env

Hello!  Has anyone been able to get fw_setenv working on the MicroZed?  I was using v2016.03 and now I am using v2017.07 from git://  fw_printenv is working fine.  My /etc/fw_env.config file looks like:
/dev/mtd1               0x0000          0x20000
I have also tried it with a sector erase size of 0x1000 and 0x2000.  But whenever I try to use fw_setenv, then fw_printenv and the boot log show the CRC error.  Catting /dev/mtd1 I can see that after I try to save something the first couple characters or so get messed up.
Anyone else using fw_setenv on MicroZed?  What does your fw_env.config file look like?

joshua5526's picture
fw_setenv corrupts env

I figured it out.  The m25p80 driver incorrectly assumes that the entire flash device can be erased by the 4k erase command.  This could be corrected by removing the SECT_4K flag from the capabilities listed for s25fl128s in the spi-nor.c file

{ "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SECT_4K | SPI_NOR_QUAD_READ) },
But instead of modifying the driver code, there is a kernel flag MTD_SPI_NOR_USE_4K_SECTORS which can be set to disabled using petalinux-config -c kernel.

│ Symbol: MTD_SPI_NOR_USE_4K_SECTORS [=y] │
│ Type : boolean │
│ Prompt: Use small 4096 B erase sectors │
│ Location: │
│ -> Device Drivers │
│ -> Memory Technology Device (MTD) support (MTD [=y]) │
│ (1) -> SPI-NOR device support (MTD_SPI_NOR [=y]) │
│ Defined at drivers/mtd/spi-nor/Kconfig:18 │
│ Depends on: MTD [=y] && MTD_SPI_NOR [=y]
The text in the config window for this entry is "Use small 4096 B erase sectors".
Disable MTD_SPI_NOR_USE_4K_SECTORS and recompile

petalinux-build -c kernel
and now all the different flash commands work correctly.  This includes jff2, fw_setenv, and probably flashcp though I haven't tested that yet.
I would consider this a bug which the PetaLinux folks (or upstream MTD folks) should correct somehow.  Ideally the driver should know when it can use 4K erasures and when it can't.  But at least changing the default to disabling 4K erasures makes the MicroZed flash writable in the case where the activity is past address 00020000h.