[WIP] Porting Mikrotik RB2011 to ath79 - testers needed

I decided to try to port RB2011 to ath79. Getting it to boot was actually surprisingly easy, especially since another Mikrotik NAND device is already present in master (SXT). NAND, sysupgrade, wireless and USB works, but I'm struggling with getting switch(es) to work.

The current result is in my GitHub repo: https://github.com/danijelt/openwrt

After deciphering old mach-rb2011 file and some trial and error, both internal switch and AR8237 are initialized, they detect link status, swconfig also correctly shows when something is plugged in, but the packets don't go in or out - I can't even ping my PC.

If I configure wireless, I can connect to the network and it works just fine - that's how I tested sysupgrade.

Here's the full bootlog (NAND boot):

RouterBOOT booter 3.19

RouterBoard 2011UiAS-2HnD

CPU frequency: 600 MHz
 Memory speed: 200 MHz
  Memory size: 128 MiB
    NAND size: 128 MiB

Press any key within 1 seconds to enter setup.

loading kernel from nand... OK
setting up elf image... OK
jumping to kernel code
[    0.000000] Linux version 5.4.85 (danijel@danijel-pc) (gcc version 8.4.0 (OpenWrt GCC 8.4.0 r15350-b9389186b0)) #0 Fri Dec 25 09:38:13 2020
[    0.000000] printk: bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 0001974c (MIPS 74Kc)
[    0.000000] MIPS: machine is MikroTik RouterBOARD 2011
[    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] 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: 121740K/131072K available (5259K kernel code, 177K rwdata, 1180K rodata, 1184K init, 201K bss, 9332K 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] random: get_random_bytes called from start_kernel+0x32c/0x520 with crng_init=0
[    0.000000] CPU clock: 600.000 MHz
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 6370868154 ns
[    0.000009] sched_clock: 32 bits at 300MHz, resolution 3ns, wraps every 7158278654ns
[    0.008861] Calibrating delay loop... 299.26 BogoMIPS (lpj=598528)
[    0.051856] pid_max: default: 32768 minimum: 301
[    0.057263] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.065574] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.079269] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.090381] futex hash table entries: 256 (order: -1, 3072 bytes, linear)
[    0.098233] pinctrl core: initialized pinctrl subsystem
[    0.105231] NET: Registered protocol family 16
[    0.144085] workqueue: max_active 576 requested for napi_workq is out of range, clamping between 1 and 512
[    0.158268] clocksource: Switched to clocksource MIPS
[    0.165279] NET: Registered protocol family 2
[    0.171062] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes, linear)
[    0.180631] TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.189361] TCP bind hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.197382] TCP: Hash tables configured (established 1024 bind 1024)
[    0.204736] UDP hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.212209] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.220454] NET: Registered protocol family 1
[    0.225474] PCI: CLS 0 bytes, default 32
[    0.234010] workingset: timestamp_bits=14 max_order=15 bucket_order=1
[    0.248504] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.255173] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.284565] pinctrl-single 1804002c.pinmux: 544 pins, size 68
[    0.291715] gpio-export gpio-export: 1 gpio(s) exported
[    0.298611] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.306683] printk: console [ttyS0] disabled
[    0.311630] 18020000.uart: ttyS0 at MMIO 0x18020000 (irq = 9, base_baud = 1562500) is a 16550A
[    0.321440] printk: console [ttyS0] enabled
[    0.321440] printk: console [ttyS0] enabled
[    0.330503] printk: bootconsole [early0] disabled
[    0.330503] printk: bootconsole [early0] disabled
[    0.350431] nand: device found, Manufacturer ID: 0xec, Chip ID: 0xf1
[    0.357019] nand: Samsung NAND 128MiB 3,3V 8-bit
[    0.361805] nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
[    0.369674] Scanning device for bad blocks
[    0.380173] random: fast init done
[    0.475392] Bad eraseblock 821 at 0x0000066a0000
[    0.504048] 3 fixed-partitions partitions found on MTD device ar934x-nand
[    0.511084] Creating 3 MTD partitions on "ar934x-nand":
[    0.516495] 0x000000000000-0x000000040000 : "booter"
[    0.522722] 0x000000040000-0x000000400000 : "kernel"
[    0.528868] 0x000000400000-0x000008000000 : "ubi"
[    0.538983] spi-nor spi0.0: mx25l512e (64 Kbytes)
[    0.543936] 1 fixed-partitions partitions found on MTD device spi0.0
[    0.550514] Creating 1 MTD partitions on "spi0.0":
[    0.555492] 0x000000000000-0x000000010000 : "RouterBoot"
[    0.563353] 4 routerbootpart partitions found on MTD device RouterBoot
[    0.570148] Creating 4 MTD partitions on "RouterBoot":
[    0.575484] 0x000000000000-0x00000000c000 : "bootloader1"
[    0.582081] 0x00000000c000-0x00000000d000 : "hard_config"
[    0.588714] 0x00000000d000-0x00000000e000 : "bios"
[    0.594757] 0x00000000e000-0x00000000f000 : "soft_config"
[    0.602318] libphy: Fixed MDIO Bus: probed
[    0.612720] ag71xx 19000000.eth: invalid MAC address, using random address
[    0.936181] libphy: ag71xx_mdio: probed
[    0.943889] switch0: Atheros AR8327 rev. 4 switch registered on mdio.0
[    1.534750] ag71xx 19000000.eth: connected to PHY at mdio.0:00 [uid=004dd034, driver=Atheros AR8216/AR8236/AR8316]
[    1.546113] eth0: Atheros AG71xx at 0xb9000000, irq 4, mode: rgmii
[    1.552880] ag71xx 1a000000.eth: invalid MAC address, using random address
[    2.190657] libphy: ag71xx_mdio: probed
[    2.196236] libphy: ar8xxx-mdio: probed
[    2.209836] switch1: Atheros AR8229 rev. 1 switch registered on mdio.1
[    2.258332] ag71xx 1a000000.eth: connected to PHY at fixed-0:00 [uid=00000000, driver=Generic PHY]
[    2.268268] eth1: Atheros AG71xx at 0xba000000, irq 5, mode: gmii
[    2.275018] ath79-wdt 18060008.wdt: timeout value must be 0 < timeout < 10, using 10
[    2.289585] MikroTik RouterBOARD hardware configuration sysfs driver v0.06
[    2.297980] MikroTik RouterBOARD software configuration sysfs driver v0.03
[    2.306315] NET: Registered protocol family 10
[    2.313507] Segment Routing with IPv6
[    2.317485] NET: Registered protocol family 17
[    2.322183] 8021q: 802.1Q VLAN Support v1.8
[    2.330410] UBI: auto-attach mtd2
[    2.333864] ubi0: attaching mtd2
[    3.594288] ubi0: scanning is finished
[    3.615865] ubi0: attached mtd2 (name "ubi", size 124 MiB)
[    3.621590] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 129024 bytes
[    3.628711] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 512
[    3.635643] ubi0: VID header offset: 512 (aligned 512), data offset: 2048
[    3.642666] ubi0: good PEBs: 991, bad PEBs: 1, corrupted PEBs: 0
[    3.648876] ubi0: user volume: 3, internal volumes: 1, max. volumes count: 128
[    3.656342] ubi0: max/mean erase counter: 5/2, WL threshold: 4096, image sequence number: 2052226221
[    3.665784] ubi0: available PEBs: 0, total reserved PEBs: 991, PEBs reserved for bad PEB handling: 19
[    3.675400] ubi0: background thread "ubi_bgt0d" started, PID 385
[    3.683404] block ubiblock0_1: created from ubi0:1(rootfs)
[    3.689138] ubiblock: device ubiblock0_1 (rootfs) set to be root filesystem
[    3.705124] VFS: Mounted root (squashfs filesystem) readonly on device 254:0.
[    3.718106] Freeing unused kernel memory: 1184K
[    3.722812] This architecture does not have kernel memory protection.
[    3.729467] Run /sbin/init as init process
[    4.038340] random: crng init done
[    4.363938] init: Console is alive
[    4.367811] init: - watchdog -
[    5.442519] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    5.564910] usbcore: registered new interface driver usbfs
[    5.570738] usbcore: registered new interface driver hub
[    5.576350] usbcore: registered new device driver usb
[    5.588991] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    5.604848] SCSI subsystem initialized
[    5.614788] ehci-fsl: Freescale EHCI Host controller driver
[    5.622739] ehci-platform: EHCI generic platform driver
[    5.628456] ehci-platform 1b000000.usb: EHCI Host Controller
[    5.634377] ehci-platform 1b000000.usb: new USB bus registered, assigned bus number 1
[    5.642601] ehci-platform 1b000000.usb: irq 3, io mem 0x1b000000
[    5.662282] ehci-platform 1b000000.usb: USB 2.0 started, EHCI 1.00
[    5.669621] hub 1-0:1.0: USB hub found
[    5.673965] hub 1-0:1.0: 1 port detected
[    5.685837] usbcore: registered new interface driver usb-storage
[    5.692753] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    5.702675] init: - preinit -
[    8.775529] eth0: link up (1000Mbps/Full duplex)
[    8.786410] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    8.798417] IPv6: ADDRCONF(NETDEV_CHANGE): eth0.1: link becomes ready
Press the [f] key and hit [enter] to enter failsafe mode
Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level
[   13.036929] UBIFS (ubi0:2): Mounting in unauthenticated mode
[   13.043061] UBIFS (ubi0:2): background thread "ubifs_bgt0_2" started, PID 516
[   13.128547] UBIFS (ubi0:2): recovery needed
[   13.307531] UBIFS (ubi0:2): recovery completed
[   13.312256] UBIFS (ubi0:2): UBIFS: mounted UBI device 0, volume 2, name "rootfs_data"
[   13.320370] UBIFS (ubi0:2): LEB size: 129024 bytes (126 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[   13.330620] UBIFS (ubi0:2): FS size: 117669888 bytes (112 MiB, 912 LEBs), journal size 5935104 bytes (5 MiB, 46 LEBs)
[   13.341580] UBIFS (ubi0:2): reserved for root: 4952683 bytes (4836 KiB)
[   13.348422] UBIFS (ubi0:2): media format: w5/r0 (latest is w5/r0), UUID E2901872-5BE8-47EA-ADF0-9A0C1826C58B, small LPT model
[   13.366680] mount_root: switching to ubifs overlay
[   13.388253] urandom-seed: Seeding with /etc/urandom.seed
[   13.509478] eth0: link down
[   13.534310] procd: - early -
[   13.537415] procd: - watchdog -
[   14.178388] procd: - watchdog -
[   14.182239] procd: - ubus -
[   14.261467] procd: - init -
Please press Enter to activate this console.
[   15.334826] kmodloader: loading kernel modules from /etc/modules.d/*
[   15.390311] Loading modules backported from Linux version v5.8.18-0-gab435ce49bd1
[   15.398066] Backport generated by backports.git v5.8.18-1-0-ga630fd46
[   15.464052] xt_time: kernel timezone is -0000
[   15.638425] PPP generic driver version 2.4.2
[   15.651902] NET: Registered protocol family 24
[   15.729486] urngd: v1.0.2 started.
[   15.759763] ath9k 18100000.wmac: Direct firmware load for ath9k-eeprom-ahb-18100000.wmac.bin failed with error -2
[   15.770431] ath9k 18100000.wmac: Falling back to sysfs fallback for: ath9k-eeprom-ahb-18100000.wmac.bin
[   16.375493] ieee80211 phy0: Atheros AR9340 Rev:2 mem=0xb8100000, irq=12
[   16.490720] kmodloader: done loading kernel modules from /etc/modules.d/*
[   33.194735] eth0: link up (1000Mbps/Full duplex)
[   33.206574] device eth0 entered promiscuous mode
[   33.211805] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   33.226641] br-lan: port 1(eth0.1) entered blocking state
[   33.232399] br-lan: port 1(eth0.1) entered disabled state
[   33.238382] device eth0.1 entered promiscuous mode
[   33.262405] br-lan: port 1(eth0.1) entered blocking state
[   33.268024] br-lan: port 1(eth0.1) entered forwarding state
[   33.319273] eth1: link up (1000Mbps/Full duplex)
[   33.344602] IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
[   33.356587] device eth1 entered promiscuous mode
[   33.378866] br-lan: port 2(eth1.1) entered blocking state
[   33.384518] br-lan: port 2(eth1.1) entered disabled state
[   33.390598] device eth1.1 entered promiscuous mode
[   33.395750] br-lan: port 2(eth1.1) entered blocking state
[   33.401374] br-lan: port 2(eth1.1) entered forwarding state
[   34.194345] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready
[   44.466623] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 1 is up
[   48.014276] usb 1-1: new high-speed USB device number 2 using ehci-platform
[   48.178148] usb-storage 1-1:1.0: USB Mass Storage device detected
[   48.185940] scsi host0: usb-storage 1-1:1.0
[   49.203488] scsi 0:0:0:0: Direct-Access              USB Flash Memory PMAP PQ: 0 ANSI: 6
[   49.216428] sd 0:0:0:0: [sda] 60506112 512-byte logical blocks: (31.0 GB/28.9 GiB)
[   49.224761] sd 0:0:0:0: [sda] Write Protect is off
[   49.230526] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[   49.313379]  sda: sda1
[   49.320270] sd 0:0:0:0: [sda] Attached SCSI removable disk

Interestingly, over time the device builds the ARP database with all devices in my LAN (if I plug it into main router, I just can't ping anything from/to device.
Port 6 (SFP) is always in up state, but nothing is plugged in.

Another problem I have is that during netboot, NAND probe fails occasionally:

[    5.850307] ar934x-nand 1b000200.nand: read operation failed on page -1
[    6.442295] ar934x-nand 1b000200.nand: read operation failed on page -1
[    7.034294] ar934x-nand 1b000200.nand: read operation failed on page -1
[    7.041148] nand: device found, Manufacturer ID: 0xec, Chip ID: 0xf1
[    7.047714] nand: Samsung NAND 128MiB 3,3V 8-bit
[    7.052493] nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
[    7.060359] Scanning device for bad blocks
[    7.650297] ar934x-nand 1b000200.nand: read operation failed on page 0
[    8.242296] ar934x-nand 1b000200.nand: read operation failed on page 1
[    8.834296] ar934x-nand 1b000200.nand: read operation failed on page 64
[    9.426297] ar934x-nand 1b000200.nand: read operation failed on page 65
[   10.018296] ar934x-nand 1b000200.nand: read operation failed on page 128
[   10.610296] ar934x-nand 1b000200.nand: read operation failed on page 129
[   11.202296] ar934x-nand 1b000200.nand: read operation failed on page 192
[   11.794296] ar934x-nand 1b000200.nand: read operation failed on page 193
[   12.862296] ar934x-nand 1b000200.nand: read operation failed on page 257
[   13.454296] ar934x-nand 1b000200.nand: read operation failed on page 320
[   14.046296] ar934x-nand 1b000200.nand: read operation failed on page 321
...

A few hard reboots fix it. It doesn't happen on NAND boot so I'll dismiss it for now.

Pinging @robimarko hoping that you might know what's going on with the network, but others are welcome too.

4 Likes

Hi,
I am really bad with ath79 specifics as I mostly deal with Qualcomm ARM and AARCH64 in my work.

But I can immediately tell that the AR8327 switch config is wrong.
SFP does not work as port6 is not being configured as SGMII at all.

You have everything in OpenWrt 19.07 branch RB2011 code, all of the settings for the switch are there.

Also, please use gpio-hog to force the NAND nCE pin high like its being done in 19.07

I migrated all configuration from mach file, and after 3 days of trial and error I still have the same problem. I have no idea what I'm doing wrong so I guess I'll just put it off for a while to reset myself...

Yeah, I am looking now at the latest version and register values look OK.
As I said, I am really bad with ath79

I got the gigabit switch working now. The trick was to translate the former board configuration from here into proper qca,ar8327-initvals. I had to consult the good oldé AR8327N Data Sheet to make sense of them bits. Here it goes:

0x04 0x07c00000 /* PORT0 PAD MODE CTRL: Mac0_rgmii_en | Mac0_rgmii_txclk_delay_en | Mac0_rgmii_rxclk_delay_en | Mac0_rgmii_txclk_delay_sel3 | Mac0_rgmii_rxclk_delay_sel0 */

I am looking at the SFP port and the built-in FastEthernet switch now as well. Let's see...

2 Likes

I already did that part, I also read the AR8327 and AR9344 datasheets and configured mdio0/1 and eth0/1, however I can't get ping to work on gigabit switch no matter what I do. If I don't configure AR8327 and just use FE ports over swphy0/4, ping works, but nothing makes it work on AR8327. Can you share your DTS if ping works on GE ports for you?

Sure, but I cleaned it up some more. A quick changelog/comments:

  • sorted stuff alphabetically as it should be
  • beeper GPIO (rather will need toggling instead)
  • moved NAND power GPIO to an export (not fully sure which one is really better)
  • USB power GPIO (but USB still does not work for me)
  • working reset key
  • working external switch (was also missing definition for 5th port)
  • correctly working ar8327-initvals
  • added some pinmux (but internal switch LEDs not yet working)
  • your userspace swconfig stuff fails for me (both SFP as well as internal switch wrongly configured)
  • haven't tried SFP I2C and display yet
  • yet to figure out how the user/system LED works
  • BTW: I tested this on an RB2011UiAS-RM
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT

#include "ar9344.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

/ {
	compatible = "mikrotik,routerboard-2011", "qca,ar9344";
	model = "MikroTik RouterBOARD 2011";

	aliases {
		serial0 = &uart;
	};

	beeper {
		compatible = "gpio-beeper";
		gpios = <&gpio 22 GPIO_ACTIVE_HIGH>;
	};

	gpio-export {
		compatible = "gpio-export";

		gpio_nand_power {
			gpio-export,name = "rb2011:power:nand";
			gpio-export,output = <0>;
			gpios = <&gpio 14 GPIO_ACTIVE_LOW>;
		};

		gpio_usb_power {
			gpio-export,name = "rb2011:power:usb";
			gpio-export,output = <0>;
			gpios = <&gpio 20 GPIO_ACTIVE_LOW>;
		};
	};

	keys {
		compatible = "gpio-keys";

		reset {
			debounce-interval = <60>;
			gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
			label = "reset";
			linux,code = <KEY_RESTART>;
		};
	};

};

&builtin_switch {
	pinctrl-names = "default";
	pinctrl-0 = <&pmx_led_switch>;
};

&eth0 {
	#address-cells = <1>;
	#size-cells = <0>;
	phy-mode = "rgmii-rxid";
	pll-data = <0x6f000000 0x00000101 0x00001616>; /* default for ar934x, except for 1000M */
	status = "okay";

	fixed-link {
		speed = <1000>;
		full-duplex;
	};

	gmac-config {
		device = <&gmac>;
		rgmii-gmac0 = <1>;
		rxd-delay = <1>;
		rxdv-delay = <1>;
	};

	port@0 {
		compatible = "swconfig,port";
		reg = <0>;
		swconfig,segment = "lan";
		swconfig,portmap = <1 1>;
	};

	port@1 {
		compatible = "swconfig,port";
		reg = <1>;
		swconfig,segment = "lan";
		swconfig,portmap = <2 2>;
	};

	port@2 {
		compatible = "swconfig,port";
		reg = <2>;
		swconfig,segment = "lan";
		swconfig,portmap = <3 3>;
	};

	port@3 {
		compatible = "swconfig,port";
		reg = <3>;
		swconfig,segment = "lan";
		swconfig,portmap = <4 4>;
	};

	port@4 {
		compatible = "swconfig,port";
		reg = <4>;
		swconfig,segment = "lan";
		swconfig,portmap = <5 5>;
	};

	port@5 {
		compatible = "swconfig,port";
		reg = <5>;
		swconfig,segment = "lan";
		swconfig,portmap = <6 6>;
	};

	port@6 {
		compatible = "swconfig,port";
		reg = <6>;
		swconfig,segment = "sfp";
		swconfig,portmap = <7 7>;
	};
};

&eth1 {
	status = "okay";

	gmac-config {
		device = <&gmac>;
		switch-phy-swap = <0>;
		switch-only-mode = <1>;
	};
};

&mdio0 {
	phy-mask = <0>;
	status = "okay";

	phy0: ethernet-phy@0 {
		reg = <0>;

		qca,ar8327-initvals = <
			0x04 0x07c00000 /* PORT0 PAD MODE CTRL: Mac0_rgmii_en | Mac0_rgmii_txclk_delay_en | Mac0_rgmii_rxclk_delay_en | Mac0_rgmii_txclk_delay_sel3 | Mac0_rgmii_rxclk_delay_sel0 */
			0x10 0x81000080 /* PWS_REG: POWER_ON_STRAP | LED_OPEN_EN_CSR | SERDES_AEN*/
			0x50 0xc731c731 /* LED_CTRL0 */
			0x54 0x00000000 /* LED_CTRL1 */
			0x58 0x00000000 /* LED_CTRL2 */
			0x5c 0x0030c300 /* LED_CTRL3 */
			0x7c 0x0000007e /* PORT0_STATUS: DUPLEX_MODE_0 | RX_FLOW_EN_0 | TX_FLOW_EN_0 | RXMAC_EN_0 | TXMAC_EN_0 | SPEED_0 1000M */
			0x0c 0x00000080 /* PORT6 PAD MODE CTRL: Mac6_sgmii_en */
			0xe0 0xc70167d0 /* SGMII_CTRL */
			0x94 0x0000007e /* PORT6_STATUS: DUPLEX_MODE_0 | RX_FLOW_EN_0 | TX_FLOW_EN_0 | RXMAC_EN_0 | TXMAC_EN_0 | SPEED_0 1000M */
		>;
	};
};

&nand {
	nand-ecc-mode = "soft";
	qca,nand-scan-fixup;
	qca,nand-swap-dma;
	status = "okay";

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

		partition@0 {
			label = "booter";
			reg = <0x0000000 0x0040000>;
			read-only;
		};

		partition@40000 {
			label = "kernel";
			reg = <0x0040000 0x03c0000>;
		};

		partition@400000 {
			label = "ubi";
			reg = <0x0400000 0x7c00000>;
		};
	};
};

&pinmux {
	pmx_led_switch: pinmux_led_switch {
		pinctrl-single,bits = <0x0 0x2b2a2d00 0xffffff00>;
	};

	pmx_spi_cs1: pinmux_spi_cs1 {
		pinctrl-single,bits = <0xc 0x07 0xff>;
	};
};

&spi {
	status = "okay";

	flash@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <40000000>;

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

			partition@0 {
				label = "RouterBoot";
				reg = <0x0 0x10000>;
				read-only;
				compatible = "mikrotik,routerboot-partitions";
				#address-cells = <1>;
				#size-cells = <1>;

				partition@0 {
					label = "bootloader1";
					reg = <0x0 0x0>;
					read-only;
				};

				hard_config: hard_config {
					read-only;
				};

				bios {
					size = <0x1000>;
					read-only;
				};

				soft_config {
				};
			};
		};
	};
};

&uart {
	status = "okay";
};

&usb {
	status = "okay";
};

&usb_phy {
	status = "okay";
};

&wmac {
	qca,no-eeprom;
	status = "okay";
};
2 Likes

Thanks a lot!
I don't know if you saw it, I already made a pull request here: https://github.com/openwrt/openwrt/pull/3729
The current tree that I pushed is not my current revision, and I really tried a lot of stuff. Unfortunately, the ar71xx -> ath79 migration is not well documented, and other ar934x devices which are already ported mostly use only the internal switch, only AR8327, or they have just one/two ports, so there's no good reference for a more complex device such as RB2011.

I'll try it out later.

I figured out that USB works if some USB device is plugged in during boot, but as you can see from my dmesg in the first post, it will randomly initialize and work fine either way. Looking back at some old OpenWrt bug reports from cca. 2017, someone had the same experience back then too. My guess is that it's initialization/power/reset issue like with NAND, maybe some missing GPIO?

LEDs are interesting.
I disassembled the case and traced the pins, all 10 ethernet LEDs are wired to the AR8327 switch. 6-10 don't light up in the bootloader either, and there's something about configuring them in the old mach file, but I didn't get to that part yet. I can work on that if your dts fixes my network problem.

Yes, I skimmed through it. But besides the device tree which you have now, I do not have any further comments so far.

BTW: While migrating from ar71xx to ath79 I thought directly moving to DSA would be kinda cool as well. However, while there are mainline drivers now for both the ar9331 which seems close to the ar9344 we have and the qca8334 resp. qca8337 which seems close to the ar8327 we have this probably is not quite that straight forward. Let's see, maybe I will play with it a little if I find some time...

1 Like

Does FE switch work for you? I can't get it to work now when AR8327 works, even after messing with mdio1 and eth1. Also, swconfig detects only 4 ports, not 5.
The behavior on FE ports is now the same as with GE before your dts: link is detected but TX doesn't work, counters are at 0.

Yeah, sorry. That's what I meant by:

your userspace swconfig stuff fails for me (both SFP as well as internal switch wrongly configured)

Anyway, I have not (yet) figured out how to make them all 5 FE ports show up but with the following patch at least 4 work fine:

diff --git a/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network b/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network
index b2eac54752..43a758443a 100755
--- a/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network
+++ b/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network
@@ -27,7 +27,7 @@ ath79_setup_interfaces()
                ucidef_add_switch "switch0" \
                        "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:lan 6:sfp"
                ucidef_add_switch "switch1" \
-                       "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:lan"
+                       "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
                ;;
        *)
                ucidef_set_interfaces_lan_wan "eth0" "eth1"

Another problem is that the external switch also only shows 5 ports rather than 6 (the last one would be the SFP) resp. it shows SFP but that one at least right now is just port 5 (;-p).

The wrong definition for switch0 is my accidental mistake, it should be "5:lan" "6:sfp", quotes got lost somewhere :slight_smile:

I got all 5 FE ports working. I'm still battling with NAND, though, I'll keep working and update you when I get something.

Also, I just noticed that PoE is always on (24 V) and none of 32 GPIOs disable it...

And, USB is a bit weird too, I have yet to trace that one.

1 Like

Good catch, how could I not have spotted that one? Maybe one should not be hacking well after midnight (;-p).

How exactly did you get that last one to work?

I thought NAND worked fine for me. Let me check again.

I believe I understand now how GPIOs work on those suckers. However, I doubt the ar71xx port had much of it properly covered. Let me skim through the vendor sources again...

2 Likes

TBH, I was looking at it for a while as well until I realized what happened. But midnight hackings are the most fun ones. :slight_smile:

I traced qca,phy4-mii-enable property of builtin_switch in ar934x.dtsi, which led me to this piece of code in ar8216.c:

if (of_property_read_bool(priv->pdev->of_node, "qca,phy4-mii-enable")) {
	priv->port4_phy = true;
	swdev->ports--;
}

So I removed that property like this:

&builtin_switch {
	pinctrl-names = "default";
	pinctrl-0 = <&pmx_led_switch>;
	/delete-property/ qca,phy4-mii-enable; /* need to delete this to make all 5 FE ports work */
};

And now the fifth port is shown in swconfig. Then I also reordered the ports in 02_network:
"0@eth1" "1:lan:5" "2:lan:4" "3:lan:3" "4:lan:2" "5:lan:1"

I guess you were just lucky initially, just like I was. When booting from network, NAND will sometimes randomly fail to initialize properly and the boot gets stuck while the driver throws a bunch of failures like this:
[ 7.051366] ar934x-nand 1b000200.nand: read operation failed on page 65
I don't know what causes it, but a reboot or two fixes it. It doesn't happen when I flash the image and boot from NAND.

I believe that the initial support was made by someone who was struggling too, because the support was being added in stages and it was refined through the years.

Anyway, with the switch resolved, major issues left are PoE, with USB and NAND being nuisance more than deal breaker.

Speaking of USB, I have RB2011Ui which has the microUSB port, and the USB controller initializes when the USB OTG cable is plugged in on boot. The cable grounds pin 4 on the connector which goes... somewhere, and if it's not grounded, the controller fails. Can you try the same on your RB2011UiAS-RM, it has the standard USB A socket.
Since I don't see anything special related to the USB in vendor's mach files, I guess RouterOS continuously checks the USB and restarts the bus to see if something is plugged in?

1 Like

See, one of them many reasons I would love getting mainline DSA stuff to work on it.

Hm, I don't recall ever having seen that. For me, NAND seems to work. But then how we hard-code this nCS is probably wrong as well but rather we should configure GPIO14 to be NAND_CS instead. I am still glancing through the manual to get the exact hex values to configure that.

That might have to do with this USB_MODE bootstrap option which is described in the manual. Maybe we need to do something about that.

Well, it does apply power but no further reaction so far. There is also a USB_SUSPEND pinmux option. Maybe that has to do with it?

Yeah, maybe it requires some custom polling or something.

BTW: Did you ever really test the SFP? For me, while it shows the link (of course because we hard-coded it) I can't yet get it to convince the peer to link up or transfer anything.

1 Like

I have no idea how much more or less complicated it would be compared to this. I didn't work with DSA before.

I tried to make GPIO 14 the reset pin for NAND but it didn't help. (Really I don't know what should I do so I started trying everything.) I don't quite understand how it's handled in the old 19.07 mach file but there is some logic which sets the pin low or high.

Regarding USB, you mean AR9344 datasheet? I'll have to check the USB section too. On the first glance, GPIO20 is the only thing that controls the host/device mode.

No, I don't have any SFP at hand. I'll get one next week. The link state is on GPIO 21 and there's some mention of get_port_link in ar8327.c but I get lost there trying to figure out what does it do.

HI, I would like to join the testing/porting effort for this endeavor. I have a (currently non-booting) RB2011, I can reach and control the bootloader via serial.

I cloned your repo, and compiled with fairly default settings, selected ath79, mikrotik, RB2011. Then I got the LZMA initramfs, and the sysupgrade bins, and tried pushing both with the dnsmasq-tftpboot procedure, for both I see the transfer, but the bootloader replies: "invalid upgrade file id"

For the record, I used openwrt-ath79-mikrotik-mikrotik_routerboard-2011-initramfs-kernel.bin.

The example uses an ELF file, but in the target image option I did not see an ELF option.
Could you give me a hint, on how to proceed, please?
Thanks already for all your work so far :slight_smile:

That's weird. I use the same file. I have configured DHCP boot mode and serve the update file from another OpenWrt router (Network -> DHCP and DNS -> TFTP settings). What is the exact model of RB2011 that you use (mainly, if it has SFP, USB and PoE).

1 Like

AH, mine is still in TFTP mode. I'll switch the mode, and report back later today. I have the model with SFP (but no module), micro-USB, PoE, and display. No wifi.

I tried again with "boot protocol" set to DHCP, that worked. I started the initramfs version, then sysupgraded to the squashfs version. During flash i got this error:

[  495.242454] ubi0: attaching mtd2                                                                                                                    
[  495.246712] ubi0 error: validate_ec_hdr: bad VID header offset 2048, expected 512                                                                   
[  495.254481] ubi0 error: validate_ec_hdr: bad EC header                                                                                              
[  495.259798] Erase counter header dump:                                                                                                              
[  495.263686]  magic          0x55424923                                                                                                              
[  495.267566]  version        1                                                                                                                       
[  495.270638]  ec             1                                                                                                                       
[  495.273710]  vid_hdr_offset 2048                                                                                                                    
[  495.277042]  data_offset    4096                                                                                                                    
[  495.280378]  image_seq      1138492434                                                                                                              
[  495.284257]  hdr_crc        0xf5844283                                                                                                              
[  495.288136] erase counter header hexdump:                                                                                                           
[  495.292318] CPU: 0 PID: 2798 Comm: ubiattach Not tainted 5.4.85 #0                                                                                  
[  495.298712] Stack : 806d0000 806d4358 00000000 00000000 806d34d8 87425ccc 87dd4300 8070e0a7                                                         
[  495.307356]         806648ec 00000aee 80b532d8 00000000 55424923 00000001 87425c80 b1df358d                                                         
[  495.316003]         00000000 00000000 80b80000 000000ee 00000030 00000000 74656420 352e342e                                                         
[  495.324648]         000000ee a76258cb 00000000 000475de 80000000 87e8a000 00000000 87e8a000                                                         
[  495.333296]         55424923 00000000 55424923 87ee050c 00000001 8038d4dc 00000000 80b50000                                                         
[  495.341941]         ...                                                                                                                             
[  495.344466] Call Trace:                                                                                                                             
[  495.347030] [<8006a224>] show_stack+0x30/0x100                                                                                                      
[  495.351644] [<803f7d40>] validate_ec_hdr+0xc0/0x118                                                                                                 
[  495.356700] [<803f8b0c>] ubi_io_read_ec_hdr+0x234/0x294                                                                                             
[  495.362119] [<803fe218>] ubi_attach+0x364/0x1514                                                                                                    
[  495.366907] [<803f21c8>] ubi_attach_mtd_dev+0x5e4/0xb74                                                                                             
[  495.372317] [<803f3618>] ctrl_cdev_ioctl+0x16c/0x1c4                                                                                                
[  495.377468] [<801d8d1c>] do_vfs_ioctl+0xb8/0x784                                                                                                    
[  495.382254] [<801d9438>] ksys_ioctl+0x50/0xb4                                                                                                       
[  495.386772] [<8006ee6c>] syscall_common+0x34/0x58                                                                                                   
[  495.391656] ubi0 error: ubi_io_read_ec_hdr: validation failed for PEB 0                                                                             
[  495.398505] ubi0 error: ubi_attach_mtd_dev: failed to attach mtd2, error -22                                                                        
ubiattach: error!: cannot attach mtd2                                                                                                                  
           error 22 (Invalid argument)

It did continue with the following though:

ubiformat: mtd2 (nand), size 130023424 bytes (124.0 MiB), 992 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes                        
libscan: scanning eraseblock 991 -- 100 % complete                                                                                                     
ubiformat: 992 eraseblocks have valid erase counter, mean value is 0                                                                                   
ubiformat: warning!: VID header and data offsets on flash are 2048 and 4096, which is different to requested offsets 512 and 2048                      
ubiformat: use new offsets 512 and 2048? yes
ubiformat: use offsets 512 and 2048
ubiformat: formatting eraseblock 952 -- 96 [  504.858786] ubi0: attaching mtd2
ubiformat: formatting eraseblock 991 -- 100 % complete  

It the rebooted normally, and loaded into openwrt. Cool, thanks!

Is it known, whether the rb2011 can act as a USB device? I have not encountered this Freescale controller before.