I reverted both partitions to factory image from Linksys and tried booting from both.
Regardless of which partition I booted up from, it appears the Linksys UI always writes to the 2nd partition.
So I decided to build with EA8100.dts
pointing kernel
and ubs
to the 2nd partition addresses. The -squashfs-sysupgrade.bin
was flashed via Linksys UI, and dmesg say the new addresses as expected:
[ 2.338784] 0x000000000000-0x000000080000 : "uboot"
[ 2.344774] 0x000000080000-0x0000000c0000 : "uboot_env"
[ 2.350950] 0x0000000c0000-0x000000100000 : "factory"
[ 2.357014] 0x000000100000-0x000000140000 : "s_env"
[ 2.362924] 0x000000140000-0x000000180000 : "devinfo"
[ 2.368923] 0x000002980000-0x000005180000 : "kernel"
[ 2.375207] 0x000002d80000-0x000005180000 : "ubi"
However:
[ 3.924342] UBI error: no valid UBI magic found inside mtd6
I tftp boot into -initramfs-kernel.bin
and found that the UBI header is not aligned:
root@OpenWrt:/# head /dev/mtd6 | hexdump -C | head
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00020000 55 42 49 23 01 00 00 00 00 00 00 00 00 00 00 00 |UBI#............|
00020010 00 00 08 00 00 00 10 00 7e 62 6e 91 00 00 00 00 |........~bn.....|
00020020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00020030 00 00 00 00 00 00 00 00 00 00 00 00 ff d4 03 e1 |................|
00020040 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
00020800 55 42 49 21 01 01 00 05 7f ff ef ff 00 00 00 00 |UBI!............|
00020810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
I reflashed with mtd
command:
root@OpenWrt:/tmp# mtd erase kernel
Unlocking kernel ...
Erasing kernel ...
Skipping bad block at 0x220000
Skipping bad block at 0x540000
Skipping bad block at 0x820000
Skipping bad block at 0xf80000
Skipping bad block at 0x1540000
Skipping bad block at 0x1a00000
root@OpenWrt:/tmp# mtd write openwrt-ramips-mt7621-ea8100-squashfs-sysupgrade.bi
n kernel
Unlocking kernel ...
Writing from openwrt-ramips-mt7621-ea8100-squashfs-sysupgrade.bin to kernel ... [e]
Skipping bad block at 0x00220000[e]
Skipping bad block at 0x0054000
However the result is the same.
I know the image is good in terms of alignment:
/home/tftpd# binwalk openwrt-ramips-mt7621-ea8100-squashfs-sysupgrade.bin
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 uImage header, header size: 64 bytes, header CRC: 0x9D840594, created: 2019-01-12 03:52:11, image size: 1896421 bytes, Data Address: 0x80001000, Entry Point: 0x80001000, data CRC: 0x9069E256, OS: Linux, CPU: MIPS, image type: OS Kernel Image, compression type: lzma, image name: "MIPS OpenWrt Linux-4.14.91"
64 0x40 LZMA compressed data, properties: 0x6D, dictionary size: 2097152 bytes, uncompressed size: 6051408 bytes
4194304 0x400000 UBI erase count header, version: 1, EC: 0x0, VID header offset: 0x800, data offset: 0x1000
/home/tftpd# hexdump -C openwrt-ramips-mt7621-ea8100-squashfs-sysupgrade.bin | egrep ^00400000 -A 30 | head
00400000 55 42 49 23 01 00 00 00 00 00 00 00 00 00 00 00 |UBI#............|
00400010 00 00 08 00 00 00 10 00 7e 62 6e 91 00 00 00 00 |........~bn.....|
00400020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00400030 00 00 00 00 00 00 00 00 00 00 00 00 ff d4 03 e1 |................|
00400040 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
00400800 55 42 49 21 01 01 00 05 7f ff ef ff 00 00 00 00 |UBI!............|
00400810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00400830 00 00 00 00 00 00 00 00 00 00 00 00 b8 25 64 a8 |.............%d.|
Is it due to bad erase blocks that the data got shifted? How do we work around this?