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

mediatek: filogic: convert ASUS device to use NVMEM-on-UBI #14676

Merged
merged 3 commits into from Feb 23, 2024

Conversation

dangowrt
Copy link
Member

@dangowrt dangowrt commented Feb 19, 2024

Some recent ASUS devices started storing their factory data inside a UBI volume. Instead of extracting WiFi EEPROM data and MAC addresses in userspace, use the now available new way to reference the NVMEM bits in device tree.

Lacking the hardware no runtime testing has been done on my end, hence I rely on users to give feedback if the works as intended.

User tested and confirmed MAC addresses and WiFi EEPROM:

  • ASUS RT-AX59U
  • ASUS TUF-AX4200
  • ASUS TUF-AX6000

@github-actions github-actions bot added the target/mediatek pull request/issue for mediatek target label Feb 19, 2024
};
};
};
};

&ubi_factory {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we used to do that a lot in OpenWrt but I have no idea why and I think recently we do less of such referencing.

If ubi_factory is in the same file (just few lines above) why not put nvmem-layout directly there? I think that would help reading DTS fle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only makes sense to do with dts files that reference dtsi definitions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used to agree but was criticized for that and told that references are ok also if they reduce the level of indentation (which is why I applied this here). I don't mind either way, my screen is big enough and my text editor smart enough for me not to care.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 2 cents when the nvmem conversion was done all the reference were done as it was easier to handle them with a script. But the normal way would be that if the node is in the same dts then the node should be changed directly.

@patrykk
Copy link
Contributor

patrykk commented Feb 19, 2024

Could we iterate MAC addresses for rest of the eth ports?

@dangowrt
Copy link
Member Author

@patrykk The idea is to always assign MAC addresses exactly like the stock firmware does. You can of course divert from that in your configuration and assign custom MAC addresses to each port.

@remittor
Copy link
Contributor

Some recent ASUS devices started storing their factory data inside a UBI volume.

also ASUS RT-AC58U (ipq4018)

@Gingernut1978
Copy link
Contributor

Gingernut1978 commented Feb 19, 2024

ASUS TUF-AX4200

Made a quick build with this PR included and after the flash it went into a boot loop.

Was running 6.1 without issues.

I'll see what the serial output says when I get time.

@Gingernut1978
Copy link
Contributor

Gingernut1978 commented Feb 21, 2024

@dangowrt

TUF-AX4200 bootloader version: 1.0.0.3
MAC Address: C8:7F:54:20:A0:80
HwID A
Read 40 bytes from volume linux to 0000000046000000
   FIT/FDT format image found at 0x46000000,size 0x3e5350
Read 4084600 bytes from volume linux to 0000000046000000
## Loading kernel from FIT Image at 46000000 ...
   Using 'config-1' configuration
   Trying 'kernel-1' kernel subimage
     Description:  ARM64 OpenWrt Linux-6.1.78
     Type:         Kernel Image
     Compression:  lzma compressed
     Data Start:   0x460000e8
     Data Size:    4060846 Bytes = 3.9 MiB
     Architecture: AArch64
     OS:           Linux
     Load Address: 0x48000000
     Entry Point:  0x48000000
     Hash algo:    crc32
     Hash value:   a9a4d90f
     Hash algo:    sha1
     Hash value:   4058a48cf992564ee9bbf51f4b9792527d6795a7
   Verifying Hash Integrity ... crc32+ sha1+ OK
## Loading fdt from FIT Image at 46000000 ...
   Using 'config-1' configuration
   Trying 'fdt-1' fdt subimage
     Description:  ARM64 OpenWrt asus_tuf-ax4200 device tree blob
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0x463df8d8
     Data Size:    21834 Bytes = 21.3 KiB
     Architecture: AArch64
     Load Address: 0x47000000
     Hash algo:    crc32
     Hash value:   df3d292f
     Hash algo:    sha1
     Hash value:   91cd448e597eb40987788220dea1a56bbd788de0
   Verifying Hash Integrity ... crc32+ sha1+ OK
   Loading fdt from 0x463df8d8 to 0x47000000
   Booting using the fdt blob at 0x47000000
Read 40 bytes from volume linux2 to 000000005f7ffb90
   Uncompressing Kernel Image
   Loading Device Tree to 000000005f7f3000, end 000000005f7fb549 ... OK
volume linux seq: 4

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[    0.000000] Linux version 6.1.78 (asim@ASIM-MS-7D20) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 12.3.0 r25153+109-869df9ecdf) 12.3.0, GNU                                               ld (GNU Binutils) 2.40.0) #0 SMP Mon Feb 19 19:43:04 2024
[    0.000000] Machine model: ASUS TUF-AX4200
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000040000000-0x000000005fffffff]
[    0.000000]   DMA32    empty
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000040000000-0x0000000042ffffff]
[    0.000000]   node   0: [mem 0x0000000043000000-0x000000004302ffff]
[    0.000000]   node   0: [mem 0x0000000043030000-0x000000004fbfffff]
[    0.000000]   node   0: [mem 0x000000004fc00000-0x000000004ffbffff]
[    0.000000]   node   0: [mem 0x000000004ffc0000-0x000000005fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000040000000-0x000000005fffffff]
[    0.000000] psci: probing for conduit method from DT.
[    0.000000] psci: PSCIv1.1 detected in firmware.
[    0.000000] psci: Using standard PSCI v0.2 function IDs
[    0.000000] psci: MIGRATE_INFO_TYPE not supported.
[    0.000000] psci: SMC Calling Convention v1.2
[    0.000000] percpu: Embedded 17 pages/cpu s30312 r8192 d31128 u69632
[    0.000000] pcpu-alloc: s30312 r8192 d31128 u69632 alloc=17*4096
[    0.000000] pcpu-alloc: [0] 0 [0] 1 [0] 2 [0] 3
[    0.000000] Detected VIPT I-cache on CPU0
[    0.000000] CPU features: detected: GIC system register CPU interface
[    0.000000] CPU features: kernel page table isolation disabled by kernel configuration
[    0.000000] alternatives: applying boot alternatives
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 129024
[    0.000000] Kernel command line: rootfstype=squashfs ubi.mtd=UBI_DEV root=/dev/mtdblock6
[    0.000000] Dentry cache hash table entries: 65536 (order: 7, 524288 bytes, linear)
[    0.000000] Inode-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 497184K/524288K available (8384K kernel code, 886K rwdata, 2432K rodata, 448K init, 289K bss, 27104K reserved, 0K cma-re                                              served)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] rcu: Hierarchical RCU implementation.
[    0.000000]  Tracing variant of Tasks RCU enabled.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000] GICv3: GIC: Using split EOI/Deactivate mode
[    0.000000] GICv3: 640 SPIs implemented
[    0.000000] GICv3: 0 Extended SPIs implemented
[    0.000000] Root IRQ handler: gic_handle_irq
[    0.000000] GICv3: GICv3 features: 16 PPIs
[    0.000000] GICv3: CPU0: found redistributor 0 region 0:0x000000000c080000
[    0.000000] rcu: srcu_init: Setting srcu_struct sizes based on contention.
[    0.000000] arch_timer: cp15 timer(s) running at 13.00MHz (phys).
[    0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x2ff89eacb, max_idle_ns: 440795202429 ns
[    0.000000] sched_clock: 56 bits at 13MHz, resolution 76ns, wraps every 4398046511101ns
[    0.000117] Calibrating delay loop (skipped), value calculated using timer frequency.. 26.00 BogoMIPS (lpj=130000)
[    0.000124] pid_max: default: 32768 minimum: 301
[    0.000325] Mount-cache hash table entries: 1024 (order: 1, 8192 bytes, linear)
[    0.000332] Mountpoint-cache hash table entries: 1024 (order: 1, 8192 bytes, linear)
[    0.000975] cacheinfo: Unable to detect cache hierarchy for CPU 0
[    0.001287] cblist_init_generic: Setting adjustable number of callback queues.
[    0.001289] cblist_init_generic: Setting shift to 2 and lim to 1.
[    0.001380] rcu: Hierarchical SRCU implementation.
[    0.001382] rcu:     Max phase no-delay instances is 1000.
[    0.001670] smp: Bringing up secondary CPUs ...
[    0.001928] Detected VIPT I-cache on CPU1
[    0.001970] cacheinfo: Unable to detect cache hierarchy for CPU 1
[    0.001977] GICv3: CPU1: found redistributor 1 region 0:0x000000000c0a0000
[    0.002003] CPU1: Booted secondary processor 0x0000000001 [0x410fd034]
[    0.002269] Detected VIPT I-cache on CPU2
[    0.002299] cacheinfo: Unable to detect cache hierarchy for CPU 2
[    0.002302] GICv3: CPU2: found redistributor 2 region 0:0x000000000c0c0000
[    0.002314] CPU2: Booted secondary processor 0x0000000002 [0x410fd034]
[    0.002567] Detected VIPT I-cache on CPU3
[    0.002594] cacheinfo: Unable to detect cache hierarchy for CPU 3
[    0.002598] GICv3: CPU3: found redistributor 3 region 0:0x000000000c0e0000
[    0.002607] CPU3: Booted secondary processor 0x0000000003 [0x410fd034]
[    0.002632] smp: Brought up 1 node, 4 CPUs
[    0.002635] SMP: Total of 4 processors activated.
[    0.002637] CPU features: detected: 32-bit EL0 Support
[    0.002639] CPU features: detected: CRC32 instructions
[    0.002662] CPU features: emulated: Privileged Access Never (PAN) using TTBR0_EL1 switching
[    0.002665] CPU: All CPU(s) started at EL2
[    0.002666] alternatives: applying system-wide alternatives
[    0.005124] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.005139] futex hash table entries: 1024 (order: 4, 65536 bytes, linear)
[    0.005282] pinctrl core: initialized pinctrl subsystem
[    0.005769] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.006014] DMA: preallocated 128 KiB GFP_KERNEL pool for atomic allocations
[    0.006034] DMA: preallocated 128 KiB GFP_KERNEL|GFP_DMA pool for atomic allocations
[    0.006050] DMA: preallocated 128 KiB GFP_KERNEL|GFP_DMA32 pool for atomic allocations
[    0.006377] thermal_sys: Registered thermal governor 'fair_share'
[    0.006379] thermal_sys: Registered thermal governor 'bang_bang'
[    0.006381] thermal_sys: Registered thermal governor 'step_wise'
[    0.006383] thermal_sys: Registered thermal governor 'user_space'
[    0.006426] ASID allocator initialised with 65536 entries
[    0.006784] pstore: Registered ramoops as persistent store backend
[    0.006786] ramoops: using 0x10000@0x42ff0000, ecc: 0
[    0.007576] OF: /soc/ethernet@15100000/mac@0: could not find phandle 33
[    0.007698] OF: /soc/wifi@18000000: could not find phandle 38
[    0.014032] cryptd: max_cpu_qlen set to 1000
[    0.014908] SCSI subsystem initialized
[    0.014981] libata version 3.00 loaded.
[    0.015848] clocksource: Switched to clocksource arch_sys_counter
[    0.016388] NET: Registered PF_INET protocol family
[    0.016473] IP idents hash table entries: 8192 (order: 4, 65536 bytes, linear)
[    0.016853] tcp_listen_portaddr_hash hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.016863] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.016869] TCP established hash table entries: 4096 (order: 3, 32768 bytes, linear)
[    0.016889] TCP bind hash table entries: 4096 (order: 5, 131072 bytes, linear)
[    0.016981] TCP: Hash tables configured (established 4096 bind 4096)
[    0.017048] UDP hash table entries: 256 (order: 1, 8192 bytes, linear)
[    0.017064] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes, linear)
[    0.017153] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.017177] PCI: CLS 0 bytes, default 64
[    0.018093] workingset: timestamp_bits=46 max_order=17 bucket_order=0
[    0.020808] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.020815] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.045957] Serial: 8250/16550 driver, 3 ports, IRQ sharing disabled
[    0.046631] printk: console [ttyS0] disabled
[    0.066776] 11002000.serial: ttyS0 at MMIO 0x11002000 (irq = 116, base_baud = 2500000) is a ST16650V2
[    0.764400] printk: console [ttyS0] enabled
[    0.769187] mtk_rng 1020f000.rng: registered RNG driver
[    0.769440] random: crng init done
[    0.774620] cacheinfo: Unable to detect cache hierarchy for CPU 0
[    0.786034] loop: module loaded
[    0.790230] spi spi0.0: setup: ignoring unsupported mode bits a00
[    0.796557] spi-nand spi0.0: Winbond SPI NAND was found.
[    0.801852] spi-nand spi0.0: 256 MiB, block size: 128 KiB, page size: 2048, OOB size: 128
[    0.810170] 2 fixed-partitions partitions found on MTD device spi0.0
[    0.816568] Creating 2 MTD partitions on "spi0.0":
[    0.821342] 0x000000000000-0x000000400000 : "Bootloader"
[    0.830608] 0x000000400000-0x000010000000 : "UBI_DEV"
[    1.187070] OF: /soc/ethernet@15100000/mac@0: could not find phandle 33
[    1.193696] OF: /soc/ethernet@15100000/mac@0: could not find phandle 33
[    1.200305] mtk_soc_eth 15100000.ethernet: generated random MAC address 65:74:68:25:64:00
[    1.208469] mtk_soc_eth 15100000.ethernet: generated random MAC address 65:74:68:25:64:00
[    1.278051] Maxlinear Ethernet GPY211C mdio-bus:06: Firmware Version: 8.111 (0x886F)
[    1.287981] mtk_soc_eth 15100000.ethernet eth0: mediatek frame engine at 0xffffffc009380000, irq 120
[    1.297782] mtk_soc_eth 15100000.ethernet eth1: mediatek frame engine at 0xffffffc009380000, irq 120
[    1.307311] i2c_dev: i2c /dev entries driver
[    1.312744] mtk-wdt 1001c000.watchdog: Watchdog enabled (timeout=31 sec, nowayout=0)
[    1.321129] NET: Registered PF_INET6 protocol family
[    1.326693] Segment Routing with IPv6
[    1.330354] In-situ OAM (IOAM) with IPv6
[    1.334290] NET: Registered PF_PACKET protocol family
[    1.339415] 8021q: 802.1Q VLAN Support v1.8
[    1.344808] pstore: Using crash dump compression: deflate
[    1.390335] mt7530-mdio mdio-bus:1f: no interrupt support
[    1.401806] mt7530-mdio mdio-bus:1f: configuring for fixed/2500base-x link mode
[    1.410770] mt7530-mdio mdio-bus:1f: Link is Up - 2.5Gbps/Full - flow control rx/tx
[    1.419956] MediaTek MT7531 PHY mt7530-0:01: Configure LED registers (num=14)
[    1.434488] mt7530-mdio mdio-bus:1f lan1 (uninitialized): PHY [mt7530-0:01] driver [MediaTek MT7531 PHY] (irq=POLL)
[    1.454532] MediaTek MT7531 PHY mt7530-0:02: Configure LED registers (num=14)
[    1.469069] mt7530-mdio mdio-bus:1f lan2 (uninitialized): PHY [mt7530-0:02] driver [MediaTek MT7531 PHY] (irq=POLL)
[    1.488829] MediaTek MT7531 PHY mt7530-0:03: Configure LED registers (num=14)
[    1.503362] mt7530-mdio mdio-bus:1f lan3 (uninitialized): PHY [mt7530-0:03] driver [MediaTek MT7531 PHY] (irq=POLL)
[    1.523114] MediaTek MT7531 PHY mt7530-0:04: Configure LED registers (num=14)
[    1.537649] mt7530-mdio mdio-bus:1f lan4 (uninitialized): PHY [mt7530-0:04] driver [MediaTek MT7531 PHY] (irq=POLL)
[    1.548817] device eth0 entered promiscuous mode
[    1.553443] DSA: tree 0 setup
[    1.556596] ubi0: default fastmap pool size: 100
[    1.561198] ubi0: default fastmap WL pool size: 50
[    1.565998] ubi0: attaching mtd1
[    5.699751] ubi0: scanning is finished
[    5.727477] ubi0: attached mtd1 (name "UBI_DEV", size 252 MiB)
[    5.733306] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[    5.740176] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[    5.746947] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[    5.753886] ubi0: good PEBs: 2016, bad PEBs: 0, corrupted PEBs: 0
[    5.759960] ubi0: user volume: 8, internal volumes: 1, max. volumes count: 128
[    5.767162] ubi0: max/mean erase counter: 23/16, WL threshold: 4096, image sequence number: 2037501690
[    5.776443] ubi0: available PEBs: 0, total reserved PEBs: 2016, PEBs reserved for bad PEB handling: 40
[    5.785729] ubi0: background thread "ubi_bgt0d" started, PID 408
[    5.789454] block ubiblock0_6: created from ubi0:6(rootfs)
[    5.797191] ubiblock: device ubiblock0_6 (rootfs) set to be root filesystem
[    5.807040] /dev/root: Can't open blockdev
[    5.811131] VFS: Cannot open root device "mtdblock6" or unknown-block(0,0): error -6
[    5.818856] Please append a correct "root=" boot option; here are the available partitions:
[    5.827194] 1f00            4096 mtdblock0
[    5.827198]  (driver?)
[    5.833707] 1f01          258048 mtdblock1
[    5.833710]  (driver?)
[    5.840222] fe00           17360 ubiblock0_6
[    5.840225]  (driver?)
[    5.846911] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[    5.855150] SMP: stopping secondary CPUs
[    5.859058] Kernel Offset: disabled
[    5.862529] CPU features: 0x00000,00000004,0000400b
[    5.867389] Memory Limit: none
[    5.872151] Rebooting in 1 seconds..
`

@remittor
Copy link
Contributor

@Gingernut1978
Main reason:

[    0.000000] Kernel command line: rootfstype=squashfs ubi.mtd=UBI_DEV root=/dev/mtdblock6

Fix: #14546 (comment)

@Gingernut1978
Copy link
Contributor

Gingernut1978 commented Feb 21, 2024

@Gingernut1978 Main reason:

[    0.000000] Kernel command line: rootfstype=squashfs ubi.mtd=UBI_DEV root=/dev/mtdblock6

Fix: #14546 (comment)

Doesn't the mediatek/filogic platform have the patch already?

@remittor
Copy link
Contributor

@dangowrt , Why did you break everything?
bba47ba#diff-32db122094202595201623322fd2167e48adc79e7f3d0a784d7e2164b2301a2fL24

@dangowrt
Copy link
Member Author

@dangowrt , Why did you break everything?

Because I don't actually have the board and any knowledge about the stock bootloader and the cmdline options it passes to the kernel 🤷 This is exactly why I wanted people who actually own the hardware to test this. And turns out bootloader passes root=/dev/mtdblock6 which should be dropped. To resolve this, I have re-added the bootargs-override property, but instead of passing the UBI volume (which is not needed due to linux,ubi compatible) it's just an empty string now.

Please try again with that and let me know if that works now.

@dangowrt
Copy link
Member Author

dangowrt commented Feb 22, 2024

[ 0.821342] 0x000000000000-0x000000400000 : "Bootloader"

I wonder where that Bootloader label (with capital B) comes from. Does the loader modify the board dts (beyond filling MAC addresses) before launching the kernel?! Is that why there are many unused labels in the Device Tree (partitions, spi_nand_flash)? If so, will it just not do that if we remove the labels? Or do we need hacks like

diff --git a/target/linux/mediatek/dts/mt7986a-asus-tuf-ax4200.dts b/target/linux/mediatek/dts/mt7986a-asus-tuf-ax4200.dts
index adaaae11ed..ad1406c93d 100644
--- a/target/linux/mediatek/dts/mt7986a-asus-tuf-ax4200.dts
+++ b/target/linux/mediatek/dts/mt7986a-asus-tuf-ax4200.dts
@@ -218,7 +218,7 @@
                spi-tx-bus-width = <4>;
                spi-rx-bus-width = <4>;
 
-               partitions: partitions {
+               partitions {
                        compatible = "fixed-partitions";
                        #address-cells = <1>;
                        #size-cells = <1>;
@@ -241,6 +241,9 @@
                                };
                        };
                };
+
+               partitions: dummy {
+               };
        };
 };

Edit: I found this comment in qcom-ipq4018-rt-ac58u.dts which gives me hope that removing the labels will do the trick, and all we'll see is a warning, hopefully:

                /*
                 * U-boot looks for "spinand,mt29f" node,
                 * if we don't have it, it will spit out the following warning:
                 * "ipq: fdt fixup unable to find compatible node".
                 */

@remittor
Copy link
Contributor

remittor commented Feb 22, 2024

Does the loader modify the board dts (beyond filling MAC addresses) before launching the kernel?!

Asus programmers love to do this. Here's a recent example: https://forum.openwrt.org/t/add-support-for-asus-rt-ax89x-ax6000/137003/328

del /soc/dp6 okay
del /soc/mdio@90000/ethernet-phy@5 okay
del /soc/ess-instance/ess-switch@3a000000/qcom,port_phyinfo/port@5 okay
enable /soc/dp6_aqr113c/status okay
enable /soc/mdio1/ethernet-phy@5/status okay
enable /soc/ess-instance/ess-switch@3a000000/qcom,port_phyinfo/port@5_113c/status okay
Using machid 0x8010000 from environment

From u-boot sources: https://github.com/u-boot/u-boot/blob/83cdab8b2c6ea0fc0860f8444d083353b47f1d5c/common/fdt_support.c#L995-L1009

From IDA disasm uboot AX4200:

__int64 __fastcall sub_41E046C4(__int64 a1)
{
  setenv("mtdparts", "mtdparts=spi-nand0:4096k(Bootloader),-(UBI_DEV)");
  return fdt_fixup_mtdparts(a1, &off_41E72D18, 1u);
}

All 3 devices (AX59U/AX4200/AX6000) automatically support NAND flash drives in 2 sizes: 128MiB and 256MiB
A 128 MiB flash drive will only have 1 partition linux

@Gingernut1978
Copy link
Contributor

Gingernut1978 commented Feb 22, 2024

@dangowrt

https://pastebin.com/DSKjnqU5

Not booting on latest changes.

[    1.558300] /dev/root: Can't open blockdev
[    1.562388] VFS: Cannot open root device "(null)" or unknown-block(0,0): error -6
[    1.569858] Please append a correct "root=" boot option; here are the available partitions:
[    1.578198] 1f00            4096 mtdblock0
[    1.578202]  (driver?)
[    1.584712] 1f01          258048 mtdblock1
[    1.584714]  (driver?)
[    1.591225] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

@remittor
Copy link
Contributor

remittor commented Feb 22, 2024

@dangowrt
Maybe it makes sense to make a common .dtsi file for all 4 devices?

All 4 devices (AX52/AX59U/AX4200/AX6000) automatically support NAND flash drives in 2 sizes: 128MiB and 256MiB
A 128 MiB flash drive will only have 1 volume linux

@dangowrt
Copy link
Member Author

Not booting on latest changes.

Strange. Despite kernel cmdline being flushed and labels removed from device tree the bootloader still manages to completely replace the content of the partitions node and drops the necessary compatible string as well as volumes subnode. We will have to trick it even more to behave.

And all that for something as useless as adjusting the size -- just always having 256 MiB in DTS will be ok, Linux will warn and truncate the final partition (UBI) to the flash size on 128 MiB, but that's absolutely ok and actually what we want in this case.

PS: I thought ASUS was better than others because they were smart enough to use UBI. Turns out they are over-smarting things so much that in the end it makes it worse.

@remittor
Copy link
Contributor

remittor commented Feb 22, 2024

@dangowrt

PS: I thought ASUS was better than others because they were smart enough to use UBI. Turns out they are over-smarting things so much that in the end it makes it worse.

This is where they outdid themselves:

  1. add support ARMv7 and ARM64: https://forum.openwrt.org/t/add-support-for-asus-rt-ax89x-ax6000/137003/219
  2. add support legacy uImage without FIT-images: https://forum.openwrt.org/t/add-support-for-asus-rt-ax89x-ax6000/137003/259

@xabolcs
Copy link
Contributor

xabolcs commented Feb 22, 2024

Not booting on latest changes.

Strange. Despite kernel cmdline being flushed and labels removed from device tree the bootloader still manages to completely replace the content of the partitions node and drops the necessary compatible string as well as volumes subnode. We will have to trick it even more to behave.

Another workaround in AX3600.dtsi to workaround Xiaomi U-Boot smartness! 🙄

&qpic_nand {
	status = "okay";

	/*
	 * Bootloader will find the NAND DT node by the compatible and
	 * then "fixup" it by adding the partitions from the SMEM table
	 * using the legacy bindings thus making it impossible for us
	 * to change the partition table or utilize NVMEM for calibration.
	 * So add a dummy partitions node that bootloader will populate
	 * and set it as disabled so the kernel ignores it instead of
	 * printing warnings due to the broken way bootloader adds the
	 * partitions.
	 */
	partitions {
		status = "disabled";
	};

@dangowrt
Copy link
Member Author

dangowrt commented Feb 22, 2024

I've added some (guessed) work-around for those borked bootloaders.

@remittor

__int64 __fastcall sub_41E046C4(__int64 a1)

How do they pick pointer to OF node a1? By label or by path or by node name?
As you seem to have access to the hardware or at least a flash dump, do you find sharing that and/or checking the way I'm trying to get that intrusive ASUS bootloader to stay away from us can work.

@Gingernut1978 Can you give it another try please?

@remittor
Copy link
Contributor

remittor commented Feb 22, 2024

@dangowrt

fdt_fixup_mtdparts(a1, &off_41E72D18, 1u);

How do they pick pointer to OF node a1?

a1: pointer to DTB (blob)

By label or by path or by node name?

&off_41E72D18: pointer to struct node_info = { "spi-nand", FDT_IS_COMPAT }
1: is node_info_size = 1

algorithm: https://github.com/u-boot/u-boot/blob/83cdab8b2c6ea0fc0860f8444d083353b47f1d5c/common/fdt_support.c#L1009

@dangowrt
Copy link
Member Author

dangowrt commented Feb 22, 2024

Not sure if this is going to work, but my hope is that U-Boot will now replace a dummy bait node instead of the actual flash partition definitions...

@dangowrt
Copy link
Member Author

@Gingernut1978 can you give it another shot please?

@Gingernut1978
Copy link
Contributor

@dangowrt definitely, just need to find the time.

@Gingernut1978
Copy link
Contributor

Gingernut1978 commented Feb 23, 2024

@Gingernut1978 can you give it another shot please?

bootlog: https://pastebin.com/4at7ayAX

Looking good. With latest changes you nailed it. All MACs are correct and wireless radios working.

Anything you would like me to try or check?

Nice job.

@remittor
Copy link
Contributor

[    0.802179] 0x000000000000-0x000000400000 : "bootloader"
[    0.811666] 0x000000400000-0x000010000000 : "UBI_DEV"
...
[    5.281613] ubiblock: device ubiblock0_6 (rootfs) set to be root filesystem

The bootloader was successfully deceived

@tkso1997
Copy link

tkso1997 commented Feb 23, 2024

Works on AX59U!

[ 0.795263] 2 fixed-partitions partitions found on MTD device spi0.0
[ 0.801786] Creating 2 MTD partitions on "spi0.0":
[ 0.806565] 0x000000000000-0x000000400000 : "u-boot"
[ 0.815005] 0x000000400000-0x000010000000 : "UBI_DEV"
[ 0.820052] mtd: partition "UBI_DEV" extends beyond the end of device "spi0.0" -- size truncated to 0x7c00000
...

...
9.719317] mt798x-wmac 18000000.wifi: HW/SW Version: 0x8a108a10, Build Time: 20221012174648a
[ 9.719317]
[ 10.045542] mt798x-wmac 18000000.wifi: WM Firmware Version: ____000000, Build Time: 20221012174725
[ 10.195157] mt798x-wmac 18000000.wifi: WA Firmware Version: DEV_000000, Build Time: 20221012174937
[ 10.302782] mt798x-wmac 18000000.wifi: registering led 'mt76-phy0'
[ 10.310337] mt798x-wmac 18000000.wifi: registering led 'mt76-phy1'

@remittor
Copy link
Contributor

@dangowrt

And all that for something as useless as adjusting the size -- just always having 256 MiB in DTS will be ok, Linux will warn and truncate the final partition (UBI) to the flash size on 128 MiB, but that's absolutely ok and actually what we want in this case.

[ 0.820052] mtd: partition "UBI_DEV" extends beyond the end of device "spi0.0" -- size truncated to 0x7c00000

You turned out to be absolutely right!

@dangowrt
Copy link
Member Author

Anything you would like me to try or check?

Serial console bootlog including bootloader would be interesting, but just out of curiosity, not worth stealing your time just for that.

@remittor You reckon it's safe to assume that if it works on AX4200 it will work on AX6000 in the same way?

@remittor
Copy link
Contributor

@dangowrt

You reckon it's safe to assume that if it works on AX4200 it will work on AX6000 in the same way?

Yes. I looked at the bootloaders from both devices in disasm and did not see any differences at all (except for the names of TRX images).

@csharper2005
Copy link
Contributor

@dangowrt sorry for offtopic. Can we use such method (NVMEM) if WiFi EEPROM data and MAC address are the files in Ubifs volume?

@dangowrt
Copy link
Member Author

@csharper2005 while this is of course theoretically possible, it would kinda open a can of worms to have the kernel read NVMEM content from (any) filesystem... I'd prefer to keep that in userspace.

Use newly added support for NVMEM-on-UBI instead of extracting MAC
address and WiFi EEPROM data in userspace.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Use newly added support for NVMEM-on-UBI instead of extracting MAC
address and WiFi EEPROM data in userspace.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Use newly added support for NVMEM-on-UBI instead of extracting MAC
address and WiFi EEPROM data in userspace.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
@openwrt-bot openwrt-bot merged commit 1794309 into openwrt:main Feb 23, 2024
3 checks passed
@dangowrt dangowrt deleted the filogic-asus-nvmem-on-ubi branch February 23, 2024 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
target/mediatek pull request/issue for mediatek target
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet