MT7621 32MB SPI NOR Flash jffs2: Erase at 0x012d0000 failed immediately: errno -22

When do sysupgrade with 32MB SPI NOR Flash on MT7621 platform router.
A new error -22 find when build jffs2 filesystem.
And this will occur after that every reboot.
After do sysupgrade several times, jffs2 crash.

[    7.716082] random: procd: uninitialized urandom read (4 bytes read)
[   12.138717] jffs2_scan_eraseblock(): End of filesystem marker found at 0xc0000
[   12.153172] jffs2_build_filesystem(): unlocking the mtd device...
[   12.153179] done.
[   12.169288] jffs2_build_filesystem(): erasing all blocks after the end marker...
[   12.169320] jffs2: Erase at 0x012d0000 failed immediately: errno -22
[   12.290157] random: crng init done
[  212.345024] done.
[  212.348903] jffs2: notice: (470) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.
[  212.381164] mount_root: overlay filesystem has not been fully initialized yet
[  212.705146] mount_root: switching to jffs2 overlay

If it’s happening at the same address ,the flash chip is probably on its last legs .

If your device can be flashed via tftp method or similar, give that a try..

Also, usual recommendation is to use squashfs rather than jffs. If you try tftp flashing this would be good time to switch images

This is another incarnation of a serious bug, obviously not only on MT7620A. You will find quite a few other posts reagrding this problem here on the forum, search for "sysupgrade" or "jffs2". I filed an offcial bug report myself already.
You might consider to revert to an older version of openwrt, for the time being. 18.06.08 should be OK.

OpenWrt SNAPSHOT, r11829-e3e939d
Linux 4.14.160
not include this bug, I have already downgrade my router.

Error address is not fixed, firmware different size got different error address.
And SPI NOR Flash no pin lost problem, lost data pin in SPI trans mode will lost all data.
Because it is serial trans mode.

Could be related, see:
https://bugs.openwrt.org/index.php?do=details&task_id=2837
https://bugs.openwrt.org/index.php?do=details&task_id=2864

For a temporary fix, revert 15a0701cdde8eeae2a54880b813cdb8cdc09a384

And @rmilecki is already looking into it: https://www.mail-archive.com/openwrt-devel@lists.openwrt.org/msg51389.html

15a0701cdde8eeae2a54880b813cdb8cdc09a384 use Linux 4.14.169, I searched kernel.org 4.14.169 to 4.14.172, no new fs/jffs2 code. This bug should be introduce by OpenWrt side.

Just revert it, rebuild the image and see if the problem still exists.

I have every full flash backup before upgrade to new build, just restore a backup file by script.

cat restore_full_bin.sh
#!/bin/sh
if [ ! -f /tmp/full_flash.bin ]; then
    echo "Backup file not found!"
    echo "Please upload backup file you need to restore as /tmp/full_flash.bin and try again."
    exit 1
fi

if [ $(mount | grep "/overlay type" | grep -v "mtd" | wc -l) -gt "0" ]; then
    rm -f /overlay/etc/.extroot-uuid
    echo "extroot: reset uuid"
fi

#dd if=/tmp/full_flash.bin of=/tmp/factory.bin bs=1K skip=256 count=64
dd if=/tmp/full_flash.bin of=/tmp/firmware.bin bs=1K skip=320
rm -f /tmp/full_flash.bin
#mtd write /tmp/factory.bin factory
mtd -r write /tmp/firmware.bin firmware

OpenWrt SNAPSHOT, r12202-cc89c5f
Linux 4.14.169
No error -22 find.

When I do sysupgrade from v4.14.169-r12202-cc89c5f to v4.14.169-r12229-73f3ad1
I got
[ 15.700264] jffs2: Erase at 0x00b70000 failed immediately: errno -22
and the full git commit ID is

scripts/getver.sh r12229
73f3ad1df2e1d33d3d5aae4fd2093aa80406cc4a

which introduce this bug, between
r12202 - r12229
cc89c5fe2764cc4d67103491f9209aa96d4cc380 - 73f3ad1df2e1d33d3d5aae4fd2093aa80406cc4a

I am trying revert a suspicious patch and rebuild trunk.
git checkout cc89c5fe2764cc4d67103491f9209aa96d4cc380 -- target/linux/generic/pending-4.14/401-mtd-add-support-for-different-partition-parser-types.patch
wating for build and sysupgrade result.

After rebuild and sysupgrade.
OpenWrt SNAPSHOT, r12470-dfb7a4c Linux 4.14.171
error -22 disappear.
Confirm that target/linux/generic/pending-4.14/401-mtd-add-support-for-different-partition-parser-types.patch last change introduce this bug.

[   15.468337] random: crng init done
[   15.699973] jffs2_scan_eraseblock(): End of filesystem marker found at 0x40000
[   15.714479] jffs2_build_filesystem(): unlocking the mtd device...
[   15.714486] done.
[   15.730616] jffs2_build_filesystem(): erasing all blocks after the end marker...
[   31.507395] done.
[   31.526142] jffs2: notice: (525) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.
1 Like