Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ath79: POC for DT-based expansion-friendly fw #12174

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

InsaneKnight
Copy link
Contributor

@InsaneKnight InsaneKnight commented Mar 13, 2023

On former ar71xx, official firmwares could be directly flashed into a
device with expanded flash, provided that partitions like "art" have been
relocated to the end of the expanded flash, but it does not work well on
the current ath79, because the offset of all partitions is set in the
device tree. If partitions like "art" are kept in their original offset,
flashing an official firmware to an expanded device can work, but extra
space beyond the original end will not be usable.

However, there are special "offset" and "size" values documented in
include/linux/mtd/partitions.h of Linux:

// consume as much as possible, leaving size after the end of partition.
#define MTDPART_OFS_RETAIN (uint64_t)(-3)

// the partition will start at the next erase block.
#define MTDPART_OFS_NXTBLK (uint64_t)(-2)

// the partition will start where the previous one ended.
#define MTDPART_OFS_APPEND (uint64_t)(-1)

// the partition will extend to the end of the master MTD device.
#define MTDPART_SIZ_FULL (0)

When these special values are used, the actual offset and size of a
partition will be determined at runtime.

As a result, MTDPART_OFS_RETAIN could be used to define the "offset" of the
original writable partition. Its "size" is used to retain spaces for
read-only partitions after it. (e.g. art) All partitions after it could use
MTDPART_OFS_APPEND for its "offset". However, since these special values
have uint64_t type, the #address-cells should be 2 and format
should be used, e.g. <(-1) (-3)> for MTDPART_OFS_RETAIN.

If official firmwares are built in this way, they will be flashed to a
well-expanded device again, and can claim all extra space. Partitions like
art could still be relocated to the end of the expanded flash, as many
bootloaders expect.

Tested on my tplink tl-wdr4310 (unexpanded), and tl-wdr4900v2 (expanded to
16MiB).

Signed-off-by: Edward Chow equu@openmail.cc

@github-actions github-actions bot added the target/ath79 pull request/issue for ath79 target label Mar 13, 2023
@Leo-PL
Copy link
Contributor

Leo-PL commented Mar 14, 2023

I see a potential issue with this approach, that U-boot sometimes expects ART to be at the end of the flash, for example at Ubiquiti XM boards, and fail to initialize Ethernet. But otherwise, I like the idea.

Do you have boot logs, especially from unexpanded device?

@InsaneKnight
Copy link
Contributor Author

InsaneKnight commented Mar 15, 2023

I see a potential issue with this approach, that U-boot sometimes expects ART to be at the end of the flash, for example at Ubiquiti XM boards

We could initially mark boards like this as having an "expansion-unfriendly bootloader", but expansion-friendly firmware should remain working well on these boards, unexpanded.

At least, we could make official firmware work well on some expanded devices again.

Expanding a device with an "expansion-unfriendly bootloader" still needs to modify its device tree. We could improve image builder to pack vmlinux and dtb file on the fly , instead of providing pre-packed device-specific kernel image files. (In the past, to generate firmware image for my expanded tl-wdr4900v2, I should manually repack the kernel image for it with a modified dtb file)

Bootlog of expanded tl-wdr4900v2:

[    0.000000] Linux version 5.15.98 (<user>@<hostname>) (mips-openwrt-linux-musl-gcc (OpenWrt GCC 12.2.0 r21847+1-4a444e576f) 12.2.0, GNU ld (GNU Binutils) 2.40.0) #0 Mon Mar 13 12:04:26 2023
[    0.000000] printk: bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 00019750 (MIPS 74Kc)
[    0.000000] MIPS: machine is TP-Link TL-WDR4900 v2
[    0.000000] SoC: Qualcomm Atheros QCA9558 ver 1 rev 0
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0 
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 32480
[    0.000000] Kernel command line: console=ttyS0,115200n8 rootfstype=squashfs,jffs2
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes, linear)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 120696K/131072K available (5751K kernel code, 587K rwdata, 1252K rodata, 1232K init, 207K bss, 10376K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 51
[    0.000000] CPU clock: 720.000 MHz
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 5309056796 ns
[    0.000001] sched_clock: 32 bits at 360MHz, resolution 2ns, wraps every 5965232126ns
[    0.008347] Calibrating delay loop... 358.80 BogoMIPS (lpj=1794048)
[    0.075032] pid_max: default: 32768 minimum: 301
[    0.080149] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.087940] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.098268] dyndbg: Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build
[    0.109061] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.119578] futex hash table entries: 256 (order: -1, 3072 bytes, linear)
[    0.126915] pinctrl core: initialized pinctrl subsystem
[    0.133711] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.156884] clocksource: Switched to clocksource MIPS
[    0.163101] NET: Registered PF_INET protocol family
[    0.168546] IP idents hash table entries: 2048 (order: 2, 16384 bytes, linear)
[    0.176796] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes, linear)
[    0.185753] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.194018] TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.202195] TCP bind hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.209720] TCP: Hash tables configured (established 1024 bind 1024)
[    0.216577] UDP hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.223586] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.231292] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.237392] PCI: CLS 0 bytes, default 32
[    0.244348] workingset: timestamp_bits=14 max_order=15 bucket_order=1
[    0.255065] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.261329] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.274979] pinctrl-single 1804002c.pinmux: 544 pins, size 68
[    0.281713] gpio-export gpio-export: 2 gpio(s) exported
[    0.288240] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.295599] printk: console [ttyS0] disabled
[    0.300251] 18020000.uart: ttyS0 at MMIO 0x18020000 (irq = 9, base_baud = 2500000) is a 16550A
[    0.309460] printk: console [ttyS0] enabled
[    0.318362] printk: bootconsole [early0] disabled
[    0.340525] spi-nor spi0.0: w25q128 (16384 Kbytes)
[    0.345444] 4 fixed-partitions partitions found on MTD device spi0.0
[    0.351964] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.358724] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.366061] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.372852] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.380015] Creating 4 MTD partitions on "spi0.0":
[    0.384892] 0x000000000000-0x000000020000 : "u-boot"
[    0.395580] 0x000000020000-0x0000007f0000 : "basefw"
[    0.401513] 0x0000007f0000-0x000000800000 : "art"
[    0.408634] 0x000000800000-0x000004000000 : "extfw"
[    0.413601] mtd: partition "extfw" extends beyond the end of device "spi0.0" -- size truncated to 0x800000
[    0.425821] Concatenating MTD devices:
[    0.429689] (0): "basefw"
[    0.432343] (1): "extfw"
[    0.434913] into device "virtual_flash"
[    0.438844] 1 fixed-partitions partitions found on MTD device virtual_flash
[    0.446137] Creating 1 MTD partitions on "virtual_flash":
[    0.451655] 0x000000000000-0x000000fd0000 : "firmware"
[    0.462505] 2 tplink-fw partitions found on MTD device firmware
[    0.468570] Creating 2 MTD partitions on "firmware":
[    0.473621] 0x000000000000-0x00000023d325 : "kernel"
[    0.478685] mtd: partition "kernel" doesn't end on an erase/write block -- force read-only
[    0.488606] 0x00000023d328-0x000000fd0000 : "rootfs"
[    0.493665] mtd: partition "rootfs" doesn't start on an erase/write block boundary -- force read-only
[    0.503803] mtd: setting mtd6 (rootfs) as root device
[    0.509788] 1 squashfs-split partitions found on MTD device rootfs
[    0.516092] 0x000000620000-0x000000fd0000 : "rootfs_data"
[    0.901956] switch0: Atheros AR8327 rev. 4 switch registered on mdio.0
[    1.556252] ag71xx 19000000.eth: connected to PHY at mdio.0:00 [uid=004dd034, driver=Atheros AR8216/AR8236/AR8316]
[    1.567324] eth0: Atheros AG71xx at 0xb9000000, irq 4, mode: rgmii
[    1.908868] ag71xx 1a000000.eth: connected to PHY at fixed-0:00 [uid=00000000, driver=Generic PHY]
[    1.918516] eth1: Atheros AG71xx at 0xba000000, irq 5, mode: sgmii
[    1.925189] i2c_dev: i2c /dev entries driver
[    1.931649] NET: Registered PF_INET6 protocol family
[    1.945198] Segment Routing with IPv6
[    1.949050] In-situ OAM (IOAM) with IPv6
[    1.953147] NET: Registered PF_PACKET protocol family
[    1.958385] 8021q: 802.1Q VLAN Support v1.8
[    1.963574] PCI host bridge to bus 0000:00
[    1.967788] pci_bus 0000:00: root bus resource [mem 0x12000000-0x13ffffff]
[    1.974775] pci_bus 0000:00: root bus resource [io  0x0001]
[    1.980449] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.988533] pci 0000:00:00.0: [168c:0033] type 00 class 0x028000
[    1.994667] pci 0000:00:00.0: reg 0x10: [mem 0x00000000-0x0001ffff 64bit]
[    2.001616] pci 0000:00:00.0: reg 0x30: [mem 0x00000000-0x0000ffff pref]
[    2.008510] pci 0000:00:00.0: supports D1
[    2.012580] pci 0000:00:00.0: PME# supported from D0 D1 D3hot
[    2.019843] pci_bus 0000:00: busn_res: [bus 00-ff] end is updated to 00
[    2.026585] pci 0000:00:00.0: BAR 0: assigned [mem 0x12000000-0x1201ffff 64bit]
[    2.034068] pci 0000:00:00.0: BAR 6: assigned [mem 0x12020000-0x1202ffff pref]
[    2.056761] VFS: Mounted root (squashfs filesystem) readonly on device 31:6.
[    2.068277] Freeing unused kernel image (initmem) memory: 1232K
[    2.074293] This architecture does not have kernel memory protection.
[    2.080856] Run /sbin/init as init process
[    2.085011]   with arguments:
[    2.085015]     /sbin/init
[    2.085020]   with environment:
[    2.085024]     HOME=/
[    2.085029]     TERM=linux
[    2.768910] init: Console is alive
[    2.772770] init: - watchdog -
[    4.022450] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    4.094446] usbcore: registered new interface driver usbfs
[    4.100124] usbcore: registered new interface driver hub
[    4.105591] usbcore: registered new device driver usb
[    4.122793] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    4.152241] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    4.162364] init: - preinit -
[    5.606265] random: jshn: uninitialized urandom read (4 bytes read)
[    5.987130] random: jshn: uninitialized urandom read (4 bytes read)
[    6.134439] random: jshn: uninitialized urandom read (4 bytes read)
[    7.465770] eth1: link up (1000Mbps/Full duplex)
[    7.476342] IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
[    7.489147] IPv6: ADDRCONF(NETDEV_CHANGE): eth1.1: link becomes ready
[    7.504720] random: procd: uninitialized urandom read (4 bytes read)
[    9.814190] jffs2: notice: (432) jffs2_build_xattr_subsystem: complete building xattr subsystem, 8 of xdatum (0 unchecked, 3 orphan) and 9 of xref (3 dead, 0 orphan) found.
[    9.831620] mount_root: switching to jffs2 overlay
[    9.840328] overlayfs: upper fs does not support tmpfile.
[    9.852223] urandom-seed: Seeding with /etc/urandom.seed
[    9.921336] eth1: link down
[    9.942613] procd: - early -
[    9.945827] procd: - watchdog -
[   10.584179] procd: - watchdog -
[   10.588804] procd: - ubus -
[   10.671449] random: ubusd: uninitialized urandom read (4 bytes read)
[   10.680362] random: ubusd: uninitialized urandom read (4 bytes read)
[   10.687316] random: ubusd: uninitialized urandom read (4 bytes read)
[   10.701439] procd: - init -
[   11.800175] random: jshn: uninitialized urandom read (4 bytes read)
[   11.850572] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.867110] random: ubus: uninitialized urandom read (4 bytes read)
[   11.909578] kmodloader: loading kernel modules from /etc/modules.d/*
[   12.346647] urngd: v1.0.2 started.
[   12.475039] Loading modules backported from Linux version v6.1-rc8-0-g76dcd734eca2
[   12.482782] Backport generated by backports.git v5.15.81-1-41-g02e352527db5
[   12.551817] random: crng init done
[   12.555286] random: 24 urandom warning(s) missed due to ratelimiting
[   12.966068] PPP generic driver version 2.4.2
[   12.974055] NET: Registered PF_PPPOX protocol family
[   13.025551] ath: EEPROM regdomain: 0x0
[   13.025572] ath: EEPROM indicates default country code should be used
[   13.025578] ath: doing EEPROM country->regdmn map search
[   13.025591] ath: country maps to regdmn code: 0x3a
[   13.025599] ath: Country alpha2 being used: US
[   13.025605] ath: Regpair used: 0x3a
[   13.042502] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
[   13.044240] ieee80211 phy0: Atheros AR9550 Rev:0 mem=0xb8100000, irq=12
[   13.051525] ath9k 0000:00:00.0: enabling device (0000 -> 0002)
[   13.070038] ath: EEPROM regdomain: 0x0
[   13.070060] ath: EEPROM indicates default country code should be used
[   13.070066] ath: doing EEPROM country->regdmn map search
[   13.070079] ath: country maps to regdmn code: 0x3a
[   13.070087] ath: Country alpha2 being used: US
[   13.070094] ath: Regpair used: 0x3a
[   13.080360] ieee80211 phy1: Selected rate control algorithm 'minstrel_ht'
[   13.082284] ieee80211 phy1: Atheros AR9300 Rev:4 mem=0xb2000000, irq=17
[   13.155364] kmodloader: done loading kernel modules from /etc/modules.d/*
[   32.757812] eth1: link up (1000Mbps/Full duplex)
[   32.779481] br-lan: port 1(eth1.1) entered blocking state
[   32.784983] br-lan: port 1(eth1.1) entered disabled state
[   32.790767] device eth1.1 entered promiscuous mode
[   32.795639] device eth1 entered promiscuous mode
[   32.803731] IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
[   32.830770] br-lan: port 1(eth1.1) entered blocking state
[   32.836270] br-lan: port 1(eth1.1) entered forwarding state
[   32.926511] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 5 is up
[   32.934068] eth0: link up (1000Mbps/Full duplex)
[   33.011998] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   33.777283] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready

Bootlog of unexpanded tl-wdr4310:

[    0.000000] Linux version 5.15.98 (<user>@<hostname>) (mips-openwrt-linux-musl-gcc (OpenWrt GCC 12.2.0 r21847+1-4a444e576f) 12.2.0, GNU ld (GNU Binutils) 2.40.0) #0 Mon Mar 13 12:04:26 2023
[    0.000000] printk: bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 0001974c (MIPS 74Kc)
[    0.000000] MIPS: machine is TP-Link TL-WDR4310 v1
[    0.000000] SoC: Atheros AR9344 rev 2
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0 
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 32480
[    0.000000] Kernel command line: console=ttyS0,115200 rootfstype=squashfs,jffs2
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes, linear)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 120696K/131072K available (5751K kernel code, 587K rwdata, 1252K rodata, 1232K init, 207K bss, 10376K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 51
[    0.000000] CPU clock: 560.000 MHz
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 6825930166 ns
[    0.000001] sched_clock: 32 bits at 280MHz, resolution 3ns, wraps every 7669584382ns
[    0.008381] Calibrating delay loop... 278.93 BogoMIPS (lpj=1394688)
[    0.084998] pid_max: default: 32768 minimum: 301
[    0.090167] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.097982] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.108853] dyndbg: Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build
[    0.120351] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.130884] futex hash table entries: 256 (order: -1, 3072 bytes, linear)
[    0.138252] pinctrl core: initialized pinctrl subsystem
[    0.145381] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.171669] clocksource: Switched to clocksource MIPS
[    0.178128] NET: Registered PF_INET protocol family
[    0.183646] IP idents hash table entries: 2048 (order: 2, 16384 bytes, linear)
[    0.192079] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes, linear)
[    0.201022] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.209322] TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.217502] TCP bind hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.225032] TCP: Hash tables configured (established 1024 bind 1024)
[    0.231930] UDP hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.238913] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.246700] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.252821] PCI: CLS 0 bytes, default 32
[    0.260449] workingset: timestamp_bits=14 max_order=15 bucket_order=1
[    0.272344] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.278565] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.293045] pinctrl-single 1804002c.pinmux: 544 pins, size 68
[    0.300043] gpio-export gpio-export: 4 gpio(s) exported
[    0.306629] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.314231] printk: console [ttyS0] disabled
[    0.318874] 18020000.uart: ttyS0 at MMIO 0x18020000 (irq = 9, base_baud = 2500000) is a 16550A
[    0.328132] printk: console [ttyS0] enabled
[    0.337048] printk: bootconsole [early0] disabled
[    0.362625] spi-nor spi0.0: s25fl064k (8192 Kbytes)
[    0.367656] 4 fixed-partitions partitions found on MTD device spi0.0
[    0.374200] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.380966] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.388392] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.395219] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.402489] Creating 4 MTD partitions on "spi0.0":
[    0.407375] 0x000000000000-0x000000020000 : "u-boot"
[    0.419139] 0x000000020000-0x0000007f0000 : "basefw"
[    0.425290] 0x0000007f0000-0x000000800000 : "art"
[    0.433029] 0x000000800000-0x000004000000 : "extfw"
[    0.438001] mtd: partition "extfw" is out of reach -- disabled
[    0.446894] Concatenating MTD devices:
[    0.450717] (0): "basefw"
[    0.453442] (1): "extfw"
[    0.456013] into device "virtual_flash"
[    0.459938] 1 fixed-partitions partitions found on MTD device virtual_flash
[    0.467334] Creating 1 MTD partitions on "virtual_flash":
[    0.472866] 0x000000000000-0x0000007d0000 : "firmware"
[    0.485415] 2 tplink-fw partitions found on MTD device firmware
[    0.491447] Creating 2 MTD partitions on "firmware":
[    0.496565] 0x000000000000-0x00000023d36a : "kernel"
[    0.501607] mtd: partition "kernel" doesn't end on an erase/write block -- force read-only
[    0.511977] 0x00000023d36c-0x0000007d0000 : "rootfs"
[    0.517044] mtd: partition "rootfs" doesn't start on an erase/write block boundary -- force read-only
[    0.527426] mtd: setting mtd6 (rootfs) as root device
[    0.533563] 1 squashfs-split partitions found on MTD device rootfs
[    0.539879] 0x000000620000-0x0000007d0000 : "rootfs_data"
[    0.937423] switch0: Atheros AR8327 rev. 4 switch registered on mdio.0
[    1.591838] ag71xx 19000000.eth: connected to PHY at mdio.0:00 [uid=004dd034, driver=Atheros AR8216/AR8236/AR8316]
[    1.603029] eth0: Atheros AG71xx at 0xb9000000, irq 4, mode: rgmii
[    1.609812] i2c_dev: i2c /dev entries driver
[    1.616801] NET: Registered PF_INET6 protocol family
[    1.632507] Segment Routing with IPv6
[    1.636332] In-situ OAM (IOAM) with IPv6
[    1.640459] NET: Registered PF_PACKET protocol family
[    1.645744] 8021q: 802.1Q VLAN Support v1.8
[    1.651348] PCI host bridge to bus 0000:00
[    1.655582] pci_bus 0000:00: root bus resource [mem 0x10000000-0x13ffffff]
[    1.662593] pci_bus 0000:00: root bus resource [io  0x0000]
[    1.668251] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.676362] pci 0000:00:00.0: [168c:0033] type 00 class 0x028000
[    1.682523] pci 0000:00:00.0: reg 0x10: [mem 0x00000000-0x0001ffff 64bit]
[    1.689468] pci 0000:00:00.0: reg 0x30: [mem 0x00000000-0x0000ffff pref]
[    1.696366] pci 0000:00:00.0: supports D1
[    1.700441] pci 0000:00:00.0: PME# supported from D0 D1 D3hot
[    1.708049] pci_bus 0000:00: busn_res: [bus 00-ff] end is updated to 00
[    1.714854] pci 0000:00:00.0: BAR 0: assigned [mem 0x10000000-0x1001ffff 64bit]
[    1.722327] pci 0000:00:00.0: BAR 6: assigned [mem 0x10020000-0x1002ffff pref]
[    1.745168] VFS: Mounted root (squashfs filesystem) readonly on device 31:6.
[    1.757631] Freeing unused kernel image (initmem) memory: 1232K
[    1.763689] This architecture does not have kernel memory protection.
[    1.770236] Run /sbin/init as init process
[    1.774409]   with arguments:
[    1.774416]     /sbin/init
[    1.774422]   with environment:
[    1.774428]     HOME=/
[    1.774434]     TERM=linux
[    2.513121] init: Console is alive
[    2.517069] init: - watchdog -
[    3.879114] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    3.958597] usbcore: registered new interface driver usbfs
[    3.964310] usbcore: registered new interface driver hub
[    3.969801] usbcore: registered new device driver usb
[    3.989264] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    4.026039] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    4.043931] init: - preinit -
[    5.665954] random: jshn: uninitialized urandom read (4 bytes read)
[    6.110394] random: jshn: uninitialized urandom read (4 bytes read)
[    6.312485] random: jshn: uninitialized urandom read (4 bytes read)
[    6.709324] random: jshn: uninitialized urandom read (4 bytes read)
[    7.802831] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 5 is up
[    7.810369] eth0: link up (1000Mbps/Full duplex)
[    7.829908] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    7.847887] IPv6: ADDRCONF(NETDEV_CHANGE): eth0.1: link becomes ready
[    7.862285] random: procd: uninitialized urandom read (4 bytes read)
[   10.170638] jffs2: notice: (422) jffs2_build_xattr_subsystem: complete building xattr subsystem, 6 of xdatum (0 unchecked, 1 orphan) and 7 of xref (1 dead, 0 orphan) found.
[   10.188299] mount_root: switching to jffs2 overlay
[   10.199142] overlayfs: upper fs does not support tmpfile.
[   10.212513] urandom-seed: Seeding with /etc/urandom.seed
[   10.291643] eth0: link down
[   10.318416] procd: - early -
[   10.321792] procd: - watchdog -
[   10.989449] procd: - watchdog -
[   10.994507] procd: - ubus -
[   11.083621] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.093247] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.100286] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.115505] procd: - init -
[   12.398352] random: jshn: uninitialized urandom read (4 bytes read)
[   12.462327] random: ubusd: uninitialized urandom read (4 bytes read)
[   12.557723] kmodloader: loading kernel modules from /etc/modules.d/*
[   13.096308] urngd: v1.0.2 started.
[   13.294508] Loading modules backported from Linux version v6.1-rc8-0-g76dcd734eca2
[   13.302268] Backport generated by backports.git v5.15.81-1-41-g02e352527db5
[   13.319475] random: crng init done
[   13.323018] random: 24 urandom warning(s) missed due to ratelimiting
[   13.817240] PPP generic driver version 2.4.2
[   13.826174] NET: Registered PF_PPPOX protocol family
[   13.887143] ath: EEPROM regdomain: 0x0
[   13.887168] ath: EEPROM indicates default country code should be used
[   13.887176] ath: doing EEPROM country->regdmn map search
[   13.887194] ath: country maps to regdmn code: 0x3a
[   13.887203] ath: Country alpha2 being used: US
[   13.887212] ath: Regpair used: 0x3a
[   13.900263] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
[   13.902475] ieee80211 phy0: Atheros AR9340 Rev:2 mem=0xb8100000, irq=12
[   13.909830] ath9k 0000:00:00.0: enabling device (0000 -> 0002)
[   13.930387] ath: EEPROM regdomain: 0x0
[   13.930414] ath: EEPROM indicates default country code should be used
[   13.930421] ath: doing EEPROM country->regdmn map search
[   13.930438] ath: country maps to regdmn code: 0x3a
[   13.930448] ath: Country alpha2 being used: US
[   13.930457] ath: Regpair used: 0x3a
[   13.941451] ieee80211 phy1: Selected rate control algorithm 'minstrel_ht'
[   13.943846] ieee80211 phy1: Atheros AR9300 Rev:4 mem=0xb0000000, irq=14
[   14.023827] kmodloader: done loading kernel modules from /etc/modules.d/*
[   38.421416] eth0: link up (1000Mbps/Full duplex)
[   38.445515] br-lan: port 1(eth0.1) entered blocking state
[   38.451020] br-lan: port 1(eth0.1) entered disabled state
[   38.456890] device eth0.1 entered promiscuous mode
[   38.461814] device eth0 entered promiscuous mode
[   38.470806] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   38.500718] br-lan: port 1(eth0.1) entered blocking state
[   38.506273] br-lan: port 1(eth0.1) entered forwarding state
[   39.461763] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready

@981213
Copy link
Member

981213 commented Mar 20, 2023

provided that partitions like "art" have been
relocated to the end of the expanded flash

For tp-link devices specifically:
I think moving ART is the most common approach among flash mods.
I personally prefer the ar71xx behaviour over your mtdconcat one, because there are already widely used open-source u-boot mods with web recovery expecting ART at the end of the flash. Your mtdconcat breaks their web recovery functionality and makes flashing via u-boot console significantly more annoying. (manual firmware split required.)

It's possible to port and improve the mtdsplit driver from ar71xx to reproduce the old behaviour. Maybe you can try this instead?

@InsaneKnight
Copy link
Contributor Author

provided that partitions like "art" have been
relocated to the end of the expanded flash

For tp-link devices specifically: I think moving ART is the most common approach among flash mods. I personally prefer the ar71xx behaviour over your mtdconcat one, because there are already widely used open-source u-boot mods with web recovery expecting ART at the end of the flash. Your mtdconcat breaks their web recovery functionality and makes flashing via u-boot console significantly more annoying. (manual firmware split required.)

It's possible to port and improve the mtdsplit driver from ar71xx to reproduce the old behaviour. Maybe you can try this instead?

This time special offset values defined in include/linux/mtd/partitions.h of Linux are used to restore the old behavior.

Bootlog of expanded tl-wdr4900v2:

[    0.000000] Linux version 5.15.98 (<user>@<hostname>) (mips-openwrt-linux-musl-gcc (OpenWrt GCC 12.2.0 r21847+1-4a444e576f) 12.2.0, GNU ld (GNU Binutils) 2.40.0) #0 Mon Mar 20 12:46:53 2023
[    0.000000] printk: bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 00019750 (MIPS 74Kc)
[    0.000000] MIPS: machine is TP-Link TL-WDR4900 v2
[    0.000000] SoC: Qualcomm Atheros QCA9558 ver 1 rev 0
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0 
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 32480
[    0.000000] Kernel command line: console=ttyS0,115200n8 rootfstype=squashfs,jffs2
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes, linear)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 120700K/131072K available (5751K kernel code, 587K rwdata, 1252K rodata, 1232K init, 207K bss, 10372K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 51
[    0.000000] CPU clock: 720.000 MHz
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 5309056796 ns
[    0.000001] sched_clock: 32 bits at 360MHz, resolution 2ns, wraps every 5965232126ns
[    0.008346] Calibrating delay loop... 358.80 BogoMIPS (lpj=1794048)
[    0.075032] pid_max: default: 32768 minimum: 301
[    0.080148] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.087940] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.098267] dyndbg: Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build
[    0.108991] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.119499] futex hash table entries: 256 (order: -1, 3072 bytes, linear)
[    0.126830] pinctrl core: initialized pinctrl subsystem
[    0.133635] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.156659] clocksource: Switched to clocksource MIPS
[    0.162874] NET: Registered PF_INET protocol family
[    0.168320] IP idents hash table entries: 2048 (order: 2, 16384 bytes, linear)
[    0.176567] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes, linear)
[    0.185525] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.193793] TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.201966] TCP bind hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.209490] TCP: Hash tables configured (established 1024 bind 1024)
[    0.216353] UDP hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.223359] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.231057] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.237158] PCI: CLS 0 bytes, default 32
[    0.244109] workingset: timestamp_bits=14 max_order=15 bucket_order=1
[    0.254818] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.261076] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.274740] pinctrl-single 1804002c.pinmux: 544 pins, size 68
[    0.281466] gpio-export gpio-export: 2 gpio(s) exported
[    0.287982] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.295346] printk: console [ttyS0] disabled
[    0.300001] 18020000.uart: ttyS0 at MMIO 0x18020000 (irq = 9, base_baud = 2500000) is a 16550A
[    0.309209] printk: console [ttyS0] enabled
[    0.318119] printk: bootconsole [early0] disabled
[    0.340245] spi-nor spi0.0: w25q128 (16384 Kbytes)
[    0.345163] 3 fixed-partitions partitions found on MTD device spi0.0
[    0.351683] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.358446] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.365778] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.372573] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.379549] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.386294] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.393446] Creating 3 MTD partitions on "spi0.0":
[    0.398368] 0x000000000000-0x000000020000 : "u-boot"
[    0.409370] 0x000000020000-0x000000ff0000 : "firmware"
[    0.415803] 2 tplink-fw partitions found on MTD device firmware
[    0.421874] Creating 2 MTD partitions on "firmware":
[    0.426927] 0x000000000000-0x00000023d301 : "kernel"
[    0.431969] mtd: partition "kernel" doesn't end on an erase/write block -- force read-only
[    0.442554] 0x00000023d304-0x000000fd0000 : "rootfs"
[    0.447649] mtd: partition "rootfs" doesn't start on an erase/write block boundary -- force read-only
[    0.457831] mtd: setting mtd3 (rootfs) as root device
[    0.463742] 1 squashfs-split partitions found on MTD device rootfs
[    0.470073] 0x000000620000-0x000000fd0000 : "rootfs_data"
[    0.476362] 0x000000ff0000-0x000001000000 : "art"
[    0.871718] switch0: Atheros AR8327 rev. 4 switch registered on mdio.0
[    1.526021] ag71xx 19000000.eth: connected to PHY at mdio.0:00 [uid=004dd034, driver=Atheros AR8216/AR8236/AR8316]
[    1.537106] eth0: Atheros AG71xx at 0xb9000000, irq 4, mode: rgmii
[    1.878634] ag71xx 1a000000.eth: connected to PHY at fixed-0:00 [uid=00000000, driver=Generic PHY]
[    1.888269] eth1: Atheros AG71xx at 0xba000000, irq 5, mode: sgmii
[    1.894935] i2c_dev: i2c /dev entries driver
[    1.901411] NET: Registered PF_INET6 protocol family
[    1.914922] Segment Routing with IPv6
[    1.918772] In-situ OAM (IOAM) with IPv6
[    1.922880] NET: Registered PF_PACKET protocol family
[    1.928116] 8021q: 802.1Q VLAN Support v1.8
[    1.933357] PCI host bridge to bus 0000:00
[    1.937573] pci_bus 0000:00: root bus resource [mem 0x12000000-0x13ffffff]
[    1.944559] pci_bus 0000:00: root bus resource [io  0x0001]
[    1.950231] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.958316] pci 0000:00:00.0: [168c:0033] type 00 class 0x028000
[    1.964450] pci 0000:00:00.0: reg 0x10: [mem 0x00000000-0x0001ffff 64bit]
[    1.971401] pci 0000:00:00.0: reg 0x30: [mem 0x00000000-0x0000ffff pref]
[    1.978285] pci 0000:00:00.0: supports D1
[    1.982353] pci 0000:00:00.0: PME# supported from D0 D1 D3hot
[    1.989539] pci_bus 0000:00: busn_res: [bus 00-ff] end is updated to 00
[    1.996281] pci 0000:00:00.0: BAR 0: assigned [mem 0x12000000-0x1201ffff 64bit]
[    2.003763] pci 0000:00:00.0: BAR 6: assigned [mem 0x12020000-0x1202ffff pref]
[    2.026451] VFS: Mounted root (squashfs filesystem) readonly on device 31:3.
[    2.037956] Freeing unused kernel image (initmem) memory: 1232K
[    2.043970] This architecture does not have kernel memory protection.
[    2.050534] Run /sbin/init as init process
[    2.054688]   with arguments:
[    2.054693]     /sbin/init
[    2.054698]   with environment:
[    2.054702]     HOME=/
[    2.054707]     TERM=linux
[    2.737870] init: Console is alive
[    2.741721] init: - watchdog -
[    3.990346] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    4.062023] usbcore: registered new interface driver usbfs
[    4.067694] usbcore: registered new interface driver hub
[    4.073160] usbcore: registered new device driver usb
[    4.091441] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    4.119749] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    4.137526] init: - preinit -
[    5.583270] random: jshn: uninitialized urandom read (4 bytes read)
[    5.963492] random: jshn: uninitialized urandom read (4 bytes read)
[    6.110673] random: jshn: uninitialized urandom read (4 bytes read)
[    7.435612] eth1: link up (1000Mbps/Full duplex)
[    7.446213] IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
[    7.458986] IPv6: ADDRCONF(NETDEV_CHANGE): eth1.1: link becomes ready
[    7.474644] random: procd: uninitialized urandom read (4 bytes read)
[    9.777473] jffs2: notice: (421) jffs2_build_xattr_subsystem: complete building xattr subsystem, 6 of xdatum (0 unchecked, 1 orphan) and 7 of xref (1 dead, 0 orphan) found.
[    9.794869] mount_root: switching to jffs2 overlay
[    9.805046] overlayfs: upper fs does not support tmpfile.
[    9.817334] urandom-seed: Seeding with /etc/urandom.seed
[    9.885493] eth1: link down
[    9.906225] procd: - early -
[    9.910572] procd: - watchdog -
[   10.532777] procd: - watchdog -
[   10.537467] procd: - ubus -
[   10.619604] random: ubusd: uninitialized urandom read (4 bytes read)
[   10.628529] random: ubusd: uninitialized urandom read (4 bytes read)
[   10.635448] random: ubusd: uninitialized urandom read (4 bytes read)
[   10.649950] procd: - init -
[   11.741987] random: jshn: uninitialized urandom read (4 bytes read)
[   11.775150] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.806206] random: ubus: uninitialized urandom read (4 bytes read)
[   11.868326] kmodloader: loading kernel modules from /etc/modules.d/*
[   12.288820] urngd: v1.0.2 started.
[   12.438525] Loading modules backported from Linux version v6.1-rc8-0-g76dcd734eca2
[   12.446221] Backport generated by backports.git v5.15.81-1-41-g02e352527db5
[   12.470004] random: crng init done
[   12.473476] random: 24 urandom warning(s) missed due to ratelimiting
[   12.906508] PPP generic driver version 2.4.2
[   12.914484] NET: Registered PF_PPPOX protocol family
[   12.966064] ath: EEPROM regdomain: 0x0
[   12.966084] ath: EEPROM indicates default country code should be used
[   12.966091] ath: doing EEPROM country->regdmn map search
[   12.966104] ath: country maps to regdmn code: 0x3a
[   12.966112] ath: Country alpha2 being used: US
[   12.966118] ath: Regpair used: 0x3a
[   12.982678] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
[   12.984414] ieee80211 phy0: Atheros AR9550 Rev:0 mem=0xb8100000, irq=12
[   12.991685] ath9k 0000:00:00.0: enabling device (0000 -> 0002)
[   13.010334] ath: EEPROM regdomain: 0x0
[   13.010356] ath: EEPROM indicates default country code should be used
[   13.010362] ath: doing EEPROM country->regdmn map search
[   13.010375] ath: country maps to regdmn code: 0x3a
[   13.010383] ath: Country alpha2 being used: US
[   13.010390] ath: Regpair used: 0x3a
[   13.020691] ieee80211 phy1: Selected rate control algorithm 'minstrel_ht'
[   13.022563] ieee80211 phy1: Atheros AR9300 Rev:4 mem=0xb2000000, irq=17
[   13.095669] kmodloader: done loading kernel modules from /etc/modules.d/*
[   32.708795] eth1: link up (1000Mbps/Full duplex)
[   32.713514] IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
[   32.737823] br-lan: port 1(eth1.1) entered blocking state
[   32.743328] br-lan: port 1(eth1.1) entered disabled state
[   32.749115] device eth1.1 entered promiscuous mode
[   32.753991] device eth1 entered promiscuous mode
[   32.780309] br-lan: port 1(eth1.1) entered blocking state
[   32.785805] br-lan: port 1(eth1.1) entered forwarding state
[   32.876438] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 5 is up
[   32.883991] eth0: link up (1000Mbps/Full duplex)
[   32.962049] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   33.802979] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready

Bootlog of unexpanded tl-wdr4310:

[    0.000000] Linux version 5.15.98 (<user>@<hostname>) (mips-openwrt-linux-musl-gcc (OpenWrt GCC 12.2.0 r21847+1-4a444e576f) 12.2.0, GNU ld (GNU Binutils) 2.40.0) #0 Sun Mar 12 13:00:26 2023
[    0.000000] printk: bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 0001974c (MIPS 74Kc)
[    0.000000] MIPS: machine is TP-Link TL-WDR4310 v1
[    0.000000] SoC: Atheros AR9344 rev 2
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0 
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 32480
[    0.000000] Kernel command line: console=ttyS0,115200 rootfstype=squashfs,jffs2
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes, linear)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 120700K/131072K available (5751K kernel code, 587K rwdata, 1252K rodata, 1232K init, 207K bss, 10372K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 51
[    0.000000] CPU clock: 560.000 MHz
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 6825930166 ns
[    0.000001] sched_clock: 32 bits at 280MHz, resolution 3ns, wraps every 7669584382ns
[    0.008380] Calibrating delay loop... 278.93 BogoMIPS (lpj=1394688)
[    0.084998] pid_max: default: 32768 minimum: 301
[    0.090165] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.097981] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.108849] dyndbg: Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build
[    0.120245] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.130769] futex hash table entries: 256 (order: -1, 3072 bytes, linear)
[    0.138132] pinctrl core: initialized pinctrl subsystem
[    0.145271] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.171385] clocksource: Switched to clocksource MIPS
[    0.177830] NET: Registered PF_INET protocol family
[    0.183347] IP idents hash table entries: 2048 (order: 2, 16384 bytes, linear)
[    0.191788] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes, linear)
[    0.200728] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.209026] TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.217208] TCP bind hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.224738] TCP: Hash tables configured (established 1024 bind 1024)
[    0.231633] UDP hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.238620] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.246417] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.252545] PCI: CLS 0 bytes, default 32
[    0.260194] workingset: timestamp_bits=14 max_order=15 bucket_order=1
[    0.272063] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.278279] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.292763] pinctrl-single 1804002c.pinmux: 544 pins, size 68
[    0.299747] gpio-export gpio-export: 4 gpio(s) exported
[    0.306356] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.313953] printk: console [ttyS0] disabled
[    0.318595] 18020000.uart: ttyS0 at MMIO 0x18020000 (irq = 9, base_baud = 2500000) is a 16550A
[    0.327846] printk: console [ttyS0] enabled
[    0.336762] printk: bootconsole [early0] disabled
[    0.362376] spi-nor spi0.0: s25fl064k (8192 Kbytes)
[    0.367402] 3 fixed-partitions partitions found on MTD device spi0.0
[    0.373946] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.380705] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.388131] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.394959] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.401988] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.408746] OF: Bad cell count for /ahb/spi@1f000000/flash@0/partitions
[    0.416029] Creating 3 MTD partitions on "spi0.0":
[    0.420914] 0x000000000000-0x000000020000 : "u-boot"
[    0.433137] 0x000000020000-0x0000007f0000 : "firmware"
[    0.439740] 2 tplink-fw partitions found on MTD device firmware
[    0.445831] Creating 2 MTD partitions on "firmware":
[    0.450878] 0x000000000000-0x00000023d38b : "kernel"
[    0.455939] mtd: partition "kernel" doesn't end on an erase/write block -- force read-only
[    0.467084] 0x00000023d38c-0x0000007d0000 : "rootfs"
[    0.472200] mtd: partition "rootfs" doesn't start on an erase/write block boundary -- force read-only
[    0.482601] mtd: setting mtd3 (rootfs) as root device
[    0.488697] 1 squashfs-split partitions found on MTD device rootfs
[    0.495051] 0x000000620000-0x0000007d0000 : "rootfs_data"
[    0.501620] 0x0000007f0000-0x000000800000 : "art"
[    0.907125] switch0: Atheros AR8327 rev. 4 switch registered on mdio.0
[    1.561556] ag71xx 19000000.eth: connected to PHY at mdio.0:00 [uid=004dd034, driver=Atheros AR8216/AR8236/AR8316]
[    1.572752] eth0: Atheros AG71xx at 0xb9000000, irq 4, mode: rgmii
[    1.579530] i2c_dev: i2c /dev entries driver
[    1.586483] NET: Registered PF_INET6 protocol family
[    1.602246] Segment Routing with IPv6
[    1.606073] In-situ OAM (IOAM) with IPv6
[    1.610199] NET: Registered PF_PACKET protocol family
[    1.615484] 8021q: 802.1Q VLAN Support v1.8
[    1.621074] PCI host bridge to bus 0000:00
[    1.625306] pci_bus 0000:00: root bus resource [mem 0x10000000-0x13ffffff]
[    1.632316] pci_bus 0000:00: root bus resource [io  0x0000]
[    1.637975] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.646078] pci 0000:00:00.0: [168c:0033] type 00 class 0x028000
[    1.652237] pci 0000:00:00.0: reg 0x10: [mem 0x00000000-0x0001ffff 64bit]
[    1.659183] pci 0000:00:00.0: reg 0x30: [mem 0x00000000-0x0000ffff pref]
[    1.666081] pci 0000:00:00.0: supports D1
[    1.670156] pci 0000:00:00.0: PME# supported from D0 D1 D3hot
[    1.677741] pci_bus 0000:00: busn_res: [bus 00-ff] end is updated to 00
[    1.684549] pci 0000:00:00.0: BAR 0: assigned [mem 0x10000000-0x1001ffff 64bit]
[    1.692024] pci 0000:00:00.0: BAR 6: assigned [mem 0x10020000-0x1002ffff pref]
[    1.714873] VFS: Mounted root (squashfs filesystem) readonly on device 31:3.
[    1.727411] Freeing unused kernel image (initmem) memory: 1232K
[    1.733466] This architecture does not have kernel memory protection.
[    1.740011] Run /sbin/init as init process
[    1.744177]   with arguments:
[    1.744183]     /sbin/init
[    1.744190]   with environment:
[    1.744195]     HOME=/
[    1.744201]     TERM=linux
[    2.481807] init: Console is alive
[    2.485763] init: - watchdog -
[    3.846808] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    3.926990] usbcore: registered new interface driver usbfs
[    3.932714] usbcore: registered new interface driver hub
[    3.938179] usbcore: registered new device driver usb
[    3.957633] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    3.993871] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    4.011763] init: - preinit -
[    5.634756] random: jshn: uninitialized urandom read (4 bytes read)
[    6.079363] random: jshn: uninitialized urandom read (4 bytes read)
[    6.281045] random: jshn: uninitialized urandom read (4 bytes read)
[    6.677031] random: jshn: uninitialized urandom read (4 bytes read)
[    7.772739] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 5 is up
[    7.780279] eth0: link up (1000Mbps/Full duplex)
[    7.800014] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    7.818044] IPv6: ADDRCONF(NETDEV_CHANGE): eth0.1: link becomes ready
[    7.832561] random: procd: uninitialized urandom read (4 bytes read)
[   10.143016] jffs2: notice: (411) jffs2_build_xattr_subsystem: complete building xattr subsystem, 6 of xdatum (0 unchecked, 1 orphan) and 7 of xref (1 dead, 0 orphan) found.
[   10.160649] mount_root: switching to jffs2 overlay
[   10.171203] overlayfs: upper fs does not support tmpfile.
[   10.184950] urandom-seed: Seeding with /etc/urandom.seed
[   10.264004] eth0: link down
[   10.290163] procd: - early -
[   10.294172] procd: - watchdog -
[   10.937870] procd: - watchdog -
[   10.942978] procd: - ubus -
[   11.031798] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.041341] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.048462] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.064245] procd: - init -
[   12.358175] random: jshn: uninitialized urandom read (4 bytes read)
[   12.399725] random: ubusd: uninitialized urandom read (4 bytes read)
[   12.493511] kmodloader: loading kernel modules from /etc/modules.d/*
[   13.022117] urngd: v1.0.2 started.
[   13.196007] Loading modules backported from Linux version v6.1-rc8-0-g76dcd734eca2
[   13.203771] Backport generated by backports.git v5.15.81-1-41-g02e352527db5
[   13.274877] random: crng init done
[   13.278350] random: 24 urandom warning(s) missed due to ratelimiting
[   13.742344] PPP generic driver version 2.4.2
[   13.750199] NET: Registered PF_PPPOX protocol family
[   13.811279] ath: EEPROM regdomain: 0x0
[   13.811305] ath: EEPROM indicates default country code should be used
[   13.811312] ath: doing EEPROM country->regdmn map search
[   13.811330] ath: country maps to regdmn code: 0x3a
[   13.811339] ath: Country alpha2 being used: US
[   13.811348] ath: Regpair used: 0x3a
[   13.824479] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
[   13.826622] ieee80211 phy0: Atheros AR9340 Rev:2 mem=0xb8100000, irq=12
[   13.834041] ath9k 0000:00:00.0: enabling device (0000 -> 0002)
[   13.854388] ath: EEPROM regdomain: 0x0
[   13.854415] ath: EEPROM indicates default country code should be used
[   13.854423] ath: doing EEPROM country->regdmn map search
[   13.854440] ath: country maps to regdmn code: 0x3a
[   13.854449] ath: Country alpha2 being used: US
[   13.854459] ath: Regpair used: 0x3a
[   13.865304] ieee80211 phy1: Selected rate control algorithm 'minstrel_ht'
[   13.867668] ieee80211 phy1: Atheros AR9300 Rev:4 mem=0xb0000000, irq=14
[   13.947534] kmodloader: done loading kernel modules from /etc/modules.d/*
[   38.371588] eth0: link up (1000Mbps/Full duplex)
[   38.395120] br-lan: port 1(eth0.1) entered blocking state
[   38.400627] br-lan: port 1(eth0.1) entered disabled state
[   38.406487] device eth0.1 entered promiscuous mode
[   38.411370] device eth0 entered promiscuous mode
[   38.420398] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   38.450718] br-lan: port 1(eth0.1) entered blocking state
[   38.456274] br-lan: port 1(eth0.1) entered forwarding state
[   39.381517] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready

@Leo-PL
Copy link
Contributor

Leo-PL commented Mar 21, 2023

@InsaneKnight wow, thanks for finding this. This is clever, very clever!
I'm eager to test it out myself :-D

@Leo-PL
Copy link
Contributor

Leo-PL commented Mar 24, 2023

I think that for "classic TP-link" devices we might even go as far, as creating a .dtsi file containing the layout, like this:

&flash {
	partitions {
		compatible = "fixed-partitions";
		#address-cells = <2>;
		#size-cells = <1>;

		uboot: partition@0 {
			label = "u-boot";
			reg = <0 0x000000 0x020000>;
			read-only;
		};

		partition@20000 {
			compatible = "tplink,firmware";
			label = "firmware";
			// retain 0x10000
			// offset = MTDPART_OFS_RETAIN
			reg = <(-1) (-3) 0x010000>;
		};

		art: partition@7f0000 {
			label = "art";
			// offset = MTDPART_OFS_APPEND
			reg = <(-1) (-1) 0x010000>;
			read-only;
		};
	};
};

and include that in all relevant devices.
Adding relevant defines to Linux upstream somewhere in include/dt-bindings could make this cleaner.
Alternatively, we could add additional "flags" property" to the partition parser, to put those offset flags there.

@github-actions github-actions bot added the kernel pull request/issue with Linux kernel related changes label Mar 31, 2023
@InsaneKnight
Copy link
Contributor Author

InsaneKnight commented Mar 31, 2023 via email

@InsaneKnight InsaneKnight force-pushed the wdr4900v2-extensible-flash branch 2 times, most recently from 74e0781 to c0588bf Compare April 5, 2023 02:30
@InsaneKnight
Copy link
Contributor Author

InsaneKnight commented Apr 9, 2023 via email

@InsaneKnight
Copy link
Contributor Author

InsaneKnight commented Apr 9, 2023 via email

@InsaneKnight
Copy link
Contributor Author

InsaneKnight commented May 5, 2023 via email

@InsaneKnight
Copy link
Contributor Author

InsaneKnight commented May 5, 2023 via email

@InsaneKnight
Copy link
Contributor Author

InsaneKnight commented May 18, 2023 via email

@InsaneKnight
Copy link
Contributor Author

InsaneKnight commented Oct 7, 2023 via email

@InsaneKnight
Copy link
Contributor Author

InsaneKnight commented Oct 23, 2023 via email

On former ar71xx, official firmwares could be directly flashed into a
device with expanded flash, provided that partitions like "art" have been
relocated to the end of the expanded flash, but it does not work well on
the current ath79, because the offset of all partitions is set in the
device tree. If partitions like "art" are kept in their original offset,
flashing an official firmware to an expanded device can work, but extra
space beyond the original end will not be usable.

However, there are special "offset" and "size" values documented in
include/linux/mtd/partitions.h of Linux:

 // consume as much as possible, leaving size after the end of partition.
 #define MTDPART_OFS_RETAIN	(uint64_t)(-3)

 // the partition will start at the next erase block.
 #define MTDPART_OFS_NXTBLK	(uint64_t)(-2)

 // the partition will start where the previous one ended.
 #define MTDPART_OFS_APPEND	(uint64_t)(-1)

 // the partition will extend to the end of the master MTD device.
 #define MTDPART_SIZ_FULL	(0)

When these special values are used, the actual offset and size of a
partition will be determined at runtime.

As a result, MTDPART_OFS_RETAIN could be used to define the "offset" of the
original writable partition. Its "size" is used to retain spaces for
read-only partitions after it. (e.g. art) All partitions after it could use
MTDPART_OFS_APPEND for its "offset". However, since these special values
have uint64_t type, the #address-cells should be 2 and format
<high32 low32> should be used, e.g. <(-1) (-3)> for MTDPART_OFS_RETAIN.

If official firmwares are built in this way, they will be flashed to a
well-expanded device again, and can claim all extra space. Partitions like
art could still be relocated to the end of the expanded flash, as many
bootloaders expect.

The common expansion-friendly layout for "classic" tplink devices is now
in tplink_classic_flash_layout.dtsi, which could later be included to the
dts file of all such device.

Tested on my tplink tl-wdr4310 (unexpanded), and tl-wdr4900v2 (expanded to
16MiB).

Signed-off-by: Edward Chow <equu@openmail.cc>
Official firmware image can now be flashed to a device with flash
expanded without changing its device tree.

Signed-off-by: Edward Chow <equu@openmail.cc>
Official firmware image can now be flashed to a device with flash
expanded without changing its device tree.

Signed-off-by: Edward Chow <equu@openmail.cc>
Official firmware image can now be flashed to a device with flash
expanded without changing its device tree.

Signed-off-by: Edward Chow <equu@openmail.cc>
Official firmware image can now be flashed to a device with flash
expanded without changing its device tree.

Signed-off-by: Edward Chow <equu@openmail.cc>
@981213
Copy link
Member

981213 commented Oct 25, 2023

Hi! Would you mind sending the partitions.h patch upstream and see what they think? I don't feel like either approach is good but I don't have any better ideas right now :(

@InsaneKnight
Copy link
Contributor Author

InsaneKnight commented Oct 25, 2023 via email

@981213
Copy link
Member

981213 commented Oct 25, 2023

I managed to send the patch here: @.***/

I mean sending the kernel patch to devicetree@vger.kernel.org and linux-mtd@lists.infradead.org as an RFC patch for comments. You could check out the detailed process in the kernel documentation: https://docs.kernel.org/process/5.Posting.html#development-posting

@Leo-PL
Copy link
Contributor

Leo-PL commented Oct 25, 2023

@InsaneKnight please CC me in while sending this patch to LKML.

@InsaneKnight
Copy link
Contributor Author

InsaneKnight commented Oct 25, 2023

@InsaneKnight please CC me in while sending this patch to LKML.

@Leo-PL
The patch can be found at https://lore.kernel.org/all/20231025052937.830813-1-equu@openmail.cc/ now. I have post it in #12174 (comment) via email, but the link is obscured by github.

@InsaneKnight
Copy link
Contributor Author

@Leo-PL
Currently the big guys replying me oppose this idea. Maybe you can help me to convince them about its usefulness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel pull request/issue with Linux kernel related changes target/ath79 pull request/issue for ath79 target
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants