Installing OpenWrt on RB2011UiAS-2HnD-IN fails

I found a missing item in the initial patch.

The commit in my staging has been updated.
Could you please rebuild & retry?

Thanks,

Koen

Installed :slight_smile:

root@OpenWrt:/# sysupgrade -n /tmp/openwrt-ar71xx-mikrotik-nand-large-squashfs-sysupgrade.bin 
Image metadata not found
Commencing upgrade. Closing all shell sessions.
Watchdog handover: fd=3
- watchdog -
killall: telnetd: no process killed
Sending TERM to remaining processes ... udhcpc odhcp6c ntpd dnsmasq ubusd logd netifd odhcpd 
Sending KILL to remaining processes ... 
Performing system upgrade...
Unlocking kernel ...
Erasing kernel ...
Writing data to block 0 at offset 0x0
Writing data to block 1 at offset 0x20000
Writing data to block 2 at offset 0x40000
Writing data to block 3 at offset 0x60000
Writing data to block 4 at offset 0x80000
Writing data to block 5 at offset 0xa0000
Writing data to block 6 at offset 0xc0000
Writing data to block 7 at offset 0xe0000
Writing data to block 8 at offset 0x100000
Writing data to block 9 at offset 0x120000
Writing data to block 10 at offset 0x140000
Writing data to block 11 at offset 0x160000
Writing data to block 12 at offset 0x180000
Writing data to block 13 at offset 0x1a0000
[  173.254617] ubi0: attaching mtd6
[  173.975251] ubi0: scanning is finished
[  173.979448] ubi0 error: ubi_read_volume_table: the layout volume was not found
[  173.987205] ubi0 error: ubi_attach_mtd_dev: failed to attach mtd6, error -22
ubiattach: error!: cannot attach mtd6
           error 22 (Invalid argument)
ubiformat: mtd6 (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: 859 eraseblocks are supposedly empty
ubiformat: warning!: 133 of 992 eraseblocks contain non-UBI data
ubiformat: warning!: only 0 of 992 eraseblocks have valid erase counter
ubiformat: erase counter 0 will be used for all eraseblocks
ubiformat: note, arbitrary erase counter value may be specified using -e option
ubiformat: use erase counter 0 for all eraseblocks
ubiformat: formatting eraseblock 991 -- 100 % complete  
[  184.821109] ubi0: scanning is finished
[  184.841782] ubi0: attached mtd6 (name "ubi", size 124 MiB)
[  184.847514] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[  184.854615] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[  184.861635] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[  184.868836] ubi0: good PEBs: 992, bad PEBs: 0, corrupted PEBs: 0
[  184.875043] ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
[  184.882513] ubi0: max/mean erase counter: 0/0, WL threshold: 4096, image sequence number: 103011554
[  184.891865] ubi0: available PEBs: 968, total reserved PEBs: 24, PEBs reserved for bad PEB handling: 20
[  184.906021] ubi0: background thread "ubi_bgt0d" started, PID 1643
UBI device number 0, total 992 LEBs (125960192 bytes, 120.1 MiB), available 968 LEBs (122912768 bytes, 117.2 MiB), LEB size 126976 bytes (124.0 KiB)
Volume ID 0, size 14 LEBs (1777664 bytes, 1.6 MiB), LEB size 126976 bytes (124.0 KiB), dynamic, name "none", alignment 1
Volume ID 1, size 18 LEBs (2285568 bytes, 2.1 MiB), LEB size 126976 bytes (124.0 KiB), dynamic, name "rootfs", alignment 1
Set volume size to 118849536
Volume ID 2, size 936 LEBs (118849536 bytes, 113.3 MiB), LEB size 126976 bytes (124.0 KiB), dynamic, name "rootfs_data", alignment 1
sysupgrade successful
umount: can't unmount /dev: Resource busy
umount: can't unmount /tmp: Resource busy
umount: can't unmount /: Invalid argument
[  186.777318] reboot: Restarting system


RouterBOOT booter 3.41

RouterBoard 2011UiAS-2HnD r2

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

Press any key within 2 seconds to enter setup..

loading kernel... OK
setting up elf image... OK
jumping to kernel code


OpenWrt kernel loader for AR7XXX/AR9XXX
Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
Decompressing kernel... done!
Starting kernel at 80060000...

[    0.000000] Linux version 4.14.111 (bota@NorbiPC) (gcc version 7.4.0 (OpenWrt GCC 7.4.0 r9860-5b39e72f6c)) #0 Fri Apr 12 11:56:31 2019
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 0001974c (MIPS 74Kc)
[    0.000000] SoC: Atheros AR9344 rev 3
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 08000000 @ 00000000 (usable)
[    0.000000] User-defined physical RAM map:
[    0.000000]  memory: 08000000 @ 00000000 (usable)
[    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] random: get_random_bytes called from start_kernel+0x8c/0x474 with crng_init=0
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 32512
[    0.000000] Kernel command line: lcd_ctrl=84 parts=1 boot_part_size=4194304 gpio=249403 HZ=300000000 mem=128M kmac=B8:69:F4:A4:E4:D0 board=2011r5 board=2011r5 ver=3.41 hw_opt=00718004 boot=1 mlc=11 console=ttyS0,115200 rootfstype=squashfs noinitrd
[    0.000000] PID hash table entries: 512 (order: -1, 2048 bytes)
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] Memory: 124044K/131072K available (3941K kernel code, 166K rwdata, 892K rodata, 240K init, 205K bss, 7028K 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] Clocks: CPU:600.000MHz, DDR:400.000MHz, AHB:400.000MHz, Ref:25.000MHz
[    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.008853] Calibrating delay loop... 299.82 BogoMIPS (lpj=1499136)
[    0.085998] pid_max: default: 32768 minimum: 301
[    0.091454] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.098963] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.109377] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.120584] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.127984] NET: Registered protocol family 16
[    0.137677] MIPS: machine is Mikrotik RouterBOARD 2011UiAS-2HnD r2
[    0.645891] clocksource: Switched to clocksource MIPS
[    0.652631] NET: Registered protocol family 2
[    0.658385] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    0.666350] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    0.673567] TCP: Hash tables configured (established 1024 bind 1024)
[    0.680921] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.687598] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.694962] NET: Registered protocol family 1
[    0.704745] Crashlog allocated RAM at address 0x3f00000
[    0.712068] workingset: timestamp_bits=30 max_order=15 bucket_order=0
[    0.724151] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.730812] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.751834] io scheduler noop registered
[    0.756334] io scheduler deadline registered (default)
[    0.762436] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.770075] console [ttyS0] disabled
[    0.794289] serial8250.0: ttyS0 at MMIO 0x18020000 (irq = 11, base_baud = 1562500) is a 16550A
[    0.804094] console [ttyS0] enabled
[    0.804094] console [ttyS0] enabled
[    0.811650] bootconsole [early0] disabled
[    0.811650] bootconsole [early0] disabled
[    0.824041] m25p80 spi0.0: found w25x05, expected m25p80
[    0.840630] m25p80 spi0.0: w25x05 (64 Kbytes)
[    0.845631] Creating 4 MTD partitions on "spi0.0":
[    0.850647] 0x000000000000-0x00000000c000 : "routerboot"
[    0.857844] 0x00000000c000-0x00000000d000 : "hard_config"
[    0.864784] 0x00000000d000-0x00000000e000 : "bios"
[    0.871819] 0x00000000e000-0x00000000f000 : "soft_config"
[    0.880402] nand: device found, Manufacturer ID: 0xef, Chip ID: 0xf1
[    0.887019] nand: Winbond NAND 128MiB 3,3V 8-bit
[    0.891788] nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
[    0.899653] Scanning device for bad blocks
[    0.908123] random: fast init done
[    0.959374] Creating 3 MTD partitions on "ar934x-nfc":
[    0.964697] 0x000000000000-0x000000040000 : "booter"
[    0.971550] 0x000000040000-0x000000400000 : "kernel"
[    0.978132] 0x000000400000-0x000008000000 : "ubi"
[    0.988493] libphy: Fixed MDIO Bus: probed
[    1.007955] libphy: ag71xx_mdio: probed
[    1.020867] switch0: Atheros AR8327 rev. 4 switch registered on ag71xx-mdio.0
[    1.746670] libphy: ag71xx_mdio: probed
[    2.377356] ag71xx ag71xx.0: connected to PHY at ag71xx-mdio.0:00 [uid=004dd034, driver=Atheros AR8216/AR8236/AR8316]
[    2.388941] eth0: Atheros AG71xx at 0xb9000000, irq 4, mode:RGMII
[    3.017672] ag71xx-mdio.1: Found an AR934X built-in switch
[    3.069928] eth1: Atheros AG71xx at 0xba000000, irq 5, mode:GMII
[    3.077632] NET: Registered protocol family 10
[    3.085961] Segment Routing with IPv6
[    3.089865] NET: Registered protocol family 17
[    3.094513] 8021q: 802.1Q VLAN Support v1.8
[    3.102481] UBI: auto-attach mtd6
[    3.105982] ubi0: attaching mtd6
[    4.416058] ubi0: scanning is finished
[    4.437313] ubi0: attached mtd6 (name "ubi", size 124 MiB)
[    4.442986] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[    4.450127] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[    4.457145] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[    4.464335] ubi0: good PEBs: 992, bad PEBs: 0, corrupted PEBs: 0
[    4.470548] ubi0: user volume: 3, internal volumes: 1, max. volumes count: 128
[    4.478022] ubi0: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 103011554
[    4.487375] ubi0: available PEBs: 0, total reserved PEBs: 992, PEBs reserved for bad PEB handling: 20
[    4.496987] ubi0: background thread "ubi_bgt0d" started, PID 355
[    4.504843] block ubiblock0_1: created from ubi0:1(rootfs)
[    4.510572] ubiblock: device ubiblock0_1 (rootfs) set to be root filesystem
[    4.527391] VFS: Mounted root (squashfs filesystem) readonly on device 254:0.
[    4.535936] Freeing unused kernel memory: 240K
[    4.540529] This architecture does not have kernel memory protection.
[    5.157961] init: Console is alive
[    5.161725] init: - watchdog -
[    6.308752] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    6.374009] usbcore: registered new interface driver usbfs
[    6.379805] usbcore: registered new interface driver hub
[    6.385398] usbcore: registered new device driver usb
[    6.395842] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    6.404235] ehci-platform: EHCI generic platform driver
[    6.409791] ehci-platform ehci-platform: EHCI Host Controller
[    6.415765] ehci-platform ehci-platform: new USB bus registered, assigned bus number 1
[    6.426071] ehci-platform ehci-platform: TX-TX IDP fix enabled
[    6.432112] ehci-platform ehci-platform: irq 3, io mem 0x1b000000
[    6.465914] ehci-platform ehci-platform: USB 2.0 started, EHCI 1.00
[    6.473228] hub 1-0:1.0: USB hub found
[    6.477512] hub 1-0:1.0: 1 port detected
[    6.484693] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    6.492670] ohci-platform: OHCI generic platform driver
[    6.498908] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    6.508838] init: - preinit -
[    7.165726] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not 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
[    8.177524] eth0: link up (1000Mbps/Full duplex)
[    8.340960] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   10.403647] random: procd: uninitialized urandom read (4 bytes read)
[   10.437312] UBIFS (ubi0:2): default file-system created
[   10.456559] UBIFS (ubi0:2): background thread "ubifs_bgt0_2" started, PID 425
[   10.670450] UBIFS (ubi0:2): UBIFS: mounted UBI device 0, volume 2, name "rootfs_data"
[   10.678588] UBIFS (ubi0:2): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[   10.688840] UBIFS (ubi0:2): FS size: 117452800 bytes (112 MiB, 925 LEBs), journal size 5840896 bytes (5 MiB, 46 LEBs)
[   10.699799] UBIFS (ubi0:2): reserved for root: 4952683 bytes (4836 KiB)
[   10.706640] UBIFS (ubi0:2): media format: w4/r0 (latest is w5/r0), UUID FE524338-BDE1-4EE3-97DB-4BAFA252E819, small LPT model
[   10.721035] mount_root: overlay filesystem has not been fully initialized yet
[   10.728512] random: crng init done
[   10.732506] mount_root: switching to ubifs overlay
[   10.766348] urandom-seed: Seed file not found (/etc/urandom.seed)
[   10.868662] eth0: link down
[   10.883243] procd: - early -
[   10.887068] procd: - watchdog -
[   11.590226] procd: - watchdog -
[   11.593777] procd: - ubus -
[   11.825870] procd: - init -
Please press Enter to activate this console.
[   12.153677] kmodloader: loading kernel modules from /etc/modules.d/*
[   12.167335] ip6_tables: (C) 2000-2006 Netfilter Core Team
[   12.183758] Loading modules backported from Linux version v4.19.32-0-g3a2156c839c7
[   12.191632] Backport generated by backports.git v4.19.32-1-0-g1c4f7569
[   12.201494] ip_tables: (C) 2000-2006 Netfilter Core Team
[   12.216092] nf_conntrack version 0.5.0 (2048 buckets, 8192 max)
[   12.283967] xt_time: kernel timezone is -0000
[   12.351231] PPP generic driver version 2.4.2
[   12.358404] NET: Registered protocol family 24
[   12.423926] ieee80211 phy0: Atheros AR9340 Rev:3 mem=0xb8100000, irq=47
[   12.462404] kmodloader: done loading kernel modules from /etc/modules.d/*



BusyBox v1.30.1 () built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt SNAPSHOT, r9860-5b39e72f6c
 -----------------------------------------------------
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
root@OpenWrt:/# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 2.3M      2.3M         0 100% /rom
tmpfs                    60.7M     32.0K     60.7M   0% /tmp
/dev/ubi0_2             102.9M     44.0K     98.2M   0% /overlay
overlayfs:/overlay      102.9M     44.0K     98.2M   0% /
tmpfs                   512.0K         0    512.0K   0% /dev
root@OpenWrt:/# 

Nice :slight_smile:

Enjoy it.

Regards,

Koen

Thanks for helping.

Regards,
Norbert

Hello Koen

The staging tree version work fine for me. I hope to see the patch in the official branch.

Thanks,

Erwann

fyi, I've pushed the r2 version patch to master.

Regards,

Koen

2 Likes

Hi Koen!

The switch1 leds(6-10) not working on my r2 when the trigger is "Switchport activity (switch1)".

Regards,
Norbert

EDIT: Master image has installed succesfully on my r2

1 Like

Hello RebroN, we have the same problem. Could you give us a link to download the correct sysupgrade file?

thank you very much in advance

If you refer to the led problem, than that problem has not been fixed yet.

Regards,

Norbert

tb2019 via OpenWrt Forum mail@forum.openwrt.org ezt írta (időpont: 2019. ápr. 25., Csü 13:48):

Hi Norbert, my problem is when i load the sysupgrade.bin file the router reboot continously.
I think you solved this problem building a new one. I'd be very grateful if you could tell me how to solve this problem.

Regards,
Tb.

Hi!

I had a different problem.
Build an image from Koen's staging tree!

Regards,
Norbert

Hi Koen,

Thank you for this.

Your fix also works for the Mikrotik RouterBOARD 2011iLS (5 x fast ethernet, 5 x GBit ethernet, 1x SFP, no Wireless, no USB, No serial terminal from rooterboot) ,
Board identifier seems to be 2011r5

Kernel command line: parts=1 boot_part_size=4194304 gpio=249387 HZ=300000000 mem=64M kmac=B8:69:F4:ba:db:ad board=2011r5 board=2011r5 ver=3.41 hw_opt=00110001 boot=1 mlc=11 console=ttyS0,115200 rootfstype=squashfs noinitrd

byt cpuinfo reports as expected

 cat /proc/cpuinfo
system type             : Atheros AR9344 rev 3
machine                 : Mikrotik RouterBOARD 2011iLS
processor               : 0
cpu model               : MIPS 74Kc V4.12
BogoMIPS                : 299.82
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb]
isa                     : mips1 mips2 mips32r1 mips32r2
ASEs implemented        : mips16 dsp dsp2
shadow register sets    : 1
kscratch registers      : 0
package                 : 0
core                    : 0
VCED exceptions         : not available
VCEI exceptions         : not available

1 Like

@DDK

Thanks for testing :slight_smile:

I'll let it sit in staging for another week until I'm confident enough that it doesn't break anything else.

If it's stable after more testing, I'll check if it can be added to the 19.07 branch so it will be present in the next official release.

Regards,

Koen

Hello,

Any news or guidance on this one? The only one I could get working as the 19 version of : ECC errors in UBI RB2011UiAS-2HnD-IN (and solution)

However, I'm having lots of troubles with kernel modules as the packages on the openwrt repository requires different kernel version than the one running on this image.

Thanks,
Marcelo

Does anyone have working SFP on these ?
I found this post ( Mikrotik Rb2011ILS-IN SFP port not working ) that mentions that SFP power is connected to a switch LED pin, But I have not managed to get them working using the regular build ( master ) or that proposed fix.

@DDK

If I have some time tomorrow i'll give it a try. :slight_smile:

I'm also poking around on mine ( trying to find the buzzer gpio ), but SFP is more important ( Lightning doesn't go thru glass )

I got SFP working with the proposed fix - The device needs a power cycle for the switch to apply new settings to the LED control register - a simple system reboot didn't do it - ( page 58 : http://microchip.ho.ua/data/AR8327.pdf ) - seems port3 LED2 is connected to a transistor that controls power to the SFP cage.

swconfig still reports that the link is down, but there is traffic on the port ( using it as a VLAN trunk between 2 sites )

Edit: Iperf results between devices on either side of the SFP connection ( VLAN tagging and untagging is also involved ) :

Connecting to host 10.0.0.117, port 5201
[  4] local 10.0.0.180 port 11188 connected to 10.0.0.117 port 5201
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-1.00   sec   104 MBytes   876 Mbits/sec
[  4]   1.00-2.00   sec   111 MBytes   929 Mbits/sec
[  4]   2.00-3.00   sec   110 MBytes   924 Mbits/sec
[  4]   3.00-4.00   sec   112 MBytes   940 Mbits/sec
[  4]   4.00-5.00   sec   110 MBytes   925 Mbits/sec
[  4]   5.00-6.00   sec   110 MBytes   918 Mbits/sec
[  4]   6.00-7.00   sec   108 MBytes   904 Mbits/sec
[  4]   7.00-8.00   sec   107 MBytes   897 Mbits/sec
[  4]   8.00-9.00   sec   105 MBytes   880 Mbits/sec
[  4]   9.00-10.00  sec   112 MBytes   935 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-10.00  sec  1.06 GBytes   913 Mbits/sec                  sender
[  4]   0.00-10.00  sec  1.06 GBytes   913 Mbits/sec                  receiver

Hello. It has already been a long time, but I still got the SFP to work in RB2011. swconfig showed the link on SFP port.
This is my version of mach-rb2011.c(for LEDE):

/*
 *  MikroTik RouterBOARD 2011 support
 *
 *  Copyright (C) 2012 Stijn Tintel <stijn@linux-ipv6.be>
 *  Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
 *
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License version 2 as published
 *  by the Free Software Foundation.
 */

#define pr_fmt(fmt) "rb2011: " fmt

#include <linux/phy.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/ath9k_platform.h>
#include <linux/ar8216_platform.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/partitions.h>
#include <linux/spi/spi.h>
#include <linux/spi/flash.h>
#include <linux/routerboot.h>
#include <linux/gpio.h>

#include <asm/prom.h>
#include <asm/mach-ath79/ath79.h>
#include <asm/mach-ath79/ar71xx_regs.h>

#include "common.h"
#include "dev-eth.h"
#include "dev-m25p80.h"
#include "dev-gpio-buttons.h"
#include "dev-nfc.h"
#include "dev-usb.h"
#include "dev-wmac.h"
#include "machtypes.h"
#include "routerboot.h"

#define RB2011_GPIO_PORT10_POE 2
#define RB2011_GPIO_NAND_NCE	14
#define RB2011_GPIO_BTN_RESET	15
#define RB2011_GPIO_USB_POE	20
#define RB2011_GPIO_SFP_LOS	21
#define RB2011_GPIO_SPEAKER	22

#define RBHAPX_KEYS_POLL_INTERVAL 20 /* msecs */
#define RBHAPX_KEYS_DEBOUNCE_INTERVAL (3 * RBHAPX_KEYS_POLL_INTERVAL)

#define RB_ROUTERBOOT_OFFSET	0x0000
#define RB_ROUTERBOOT_MIN_SIZE	0xb000
#define RB_HARD_CFG_SIZE	0x1000
#define RB_BIOS_OFFSET		0xd000
#define RB_BIOS_SIZE		0x1000
#define RB_SOFT_CFG_OFFSET	0xf000
#define RB_SOFT_CFG_SIZE	0x1000

#define RB_ART_SIZE		0x10000

#define RB2011_FLAG_OLD_SFP		BIT(0)
#define RB2011_FLAG_NEW_SFP		BIT(1)
#define RB2011_FLAG_USB				BIT(2)
#define RB2011_FLAG_WLAN			BIT(3)

static struct mtd_partition rb2011_spi_partitions[] = {
	{
		.name		= "routerboot",
		.offset		= RB_ROUTERBOOT_OFFSET,
		.mask_flags	= MTD_WRITEABLE,
	}, {
		.name		= "hard_config",
		.size		= RB_HARD_CFG_SIZE,
		.mask_flags	= MTD_WRITEABLE,
	}, {
		.name		= "bios",
		.offset		= RB_BIOS_OFFSET,
		.size		= RB_BIOS_SIZE,
		.mask_flags	= MTD_WRITEABLE,
	}, {
		.name		= "soft_config",
		.size		= RB_SOFT_CFG_SIZE,
	}
};

static void __init rb2011_init_partitions(const struct rb_info *info)
{
	rb2011_spi_partitions[0].size = info->hard_cfg_offs;
	rb2011_spi_partitions[1].offset = info->hard_cfg_offs;
	rb2011_spi_partitions[3].offset = info->soft_cfg_offs;
}

static struct mtd_partition rb2011_nand_partitions[] = {
	{
		.name	= "booter",
		.offset	= 0,
		.size	= (256 * 1024),
		.mask_flags = MTD_WRITEABLE,
	},
	{
		.name	= "kernel",
		.offset	= (256 * 1024),
		.size	= (4 * 1024 * 1024) - (256 * 1024),
	},
	{
		.name	= "ubi",
		.offset	= MTDPART_OFS_NXTBLK,
		.size	= MTDPART_SIZ_FULL,
	},
};

static struct flash_platform_data rb2011_spi_flash_data = {
	.parts		= rb2011_spi_partitions,
	.nr_parts	= ARRAY_SIZE(rb2011_spi_partitions),
};

static struct ar8327_pad_cfg rb2011_ar8327_pad0_cfg = {
	.mode = AR8327_PAD_MAC_RGMII,
	.txclk_delay_en = true,
	.rxclk_delay_en = true,
	.txclk_delay_sel = AR8327_CLK_DELAY_SEL3,
	.rxclk_delay_sel = AR8327_CLK_DELAY_SEL0,
};

static struct ar8327_pad_cfg rb2011_ar8327_pad6_cfg;
static struct ar8327_sgmii_cfg rb2011_ar8327_sgmii_cfg;

static struct ar8327_led_cfg rb2011_ar8327_led_cfg = {
	.led_ctrl0 = 0xc731c731,
	.led_ctrl1 = 0x00000000,
	.led_ctrl2 = 0x00008000, //shut down led on LCD screen(sw LED PORT 2)
	.led_ctrl3 = 0x0030c300,
	.open_drain = false,
};

static const struct ar8327_led_info rb2011_ar8327_leds[] __initconst = {
	AR8327_LED_INFO(PHY0_0, HW, "rb:green:eth1"),
	AR8327_LED_INFO(PHY1_0, HW, "rb:green:eth2"),
	AR8327_LED_INFO(PHY2_0, HW, "rb:green:eth3"),
	AR8327_LED_INFO(PHY3_0, HW, "rb:green:eth4"),
	AR8327_LED_INFO(PHY4_0, HW, "rb:green:eth5"),
	AR8327_LED_INFO(PHY0_1, SW, "rb:green:eth6"),
	AR8327_LED_INFO(PHY1_1, SW, "rb:green:eth7"),
	AR8327_LED_INFO(PHY2_1, SW, "rb:green:eth8"),
	AR8327_LED_INFO(PHY3_1, SW, "rb:green:eth9"),
	AR8327_LED_INFO(PHY4_1, SW, "rb:green:eth10"),
	AR8327_LED_INFO(PHY4_2, SW, "rb:green:usr"),
	{
		.name = "rb:lcd:led",
		.led_num = AR8327_LED_PHY0_2,
		.mode = AR8327_LED_MODE_SW,
		.active_low = 0,
		.default_trigger = "default-on",
	}
};

static struct ar8327_platform_data rb2011_ar8327_data = {
	.pad0_cfg = &rb2011_ar8327_pad0_cfg,
	.port0_cfg = {
		.force_link = 1,
		.speed = AR8327_PORT_SPEED_1000,
		.duplex = 1,
		.txpause = 1,
		.rxpause = 1,
	},
	.led_cfg = &rb2011_ar8327_led_cfg,
	.num_leds = ARRAY_SIZE(rb2011_ar8327_leds),
	.leds = rb2011_ar8327_leds,
};

static struct mdio_board_info rb2011_mdio0_info[] = {
	{
		.bus_id = "ag71xx-mdio.0",
		.phy_addr = 0,
		.platform_data = &rb2011_ar8327_data,
	},
};

static struct gpio_keys_button rb2011_gpio_keys[] __initdata = {
	{
		.desc = "Reset button",
		.type = EV_KEY,
		.code = KEY_RESTART,
		.debounce_interval = RBHAPX_KEYS_DEBOUNCE_INTERVAL,
		.gpio = RB2011_GPIO_BTN_RESET,
		.active_low = 1,
	},
};

static void __init rb2011_wlan_init(void)
{
	char *art_buf;
	u8 wlan_mac[ETH_ALEN];

	art_buf = rb_get_wlan_data();
	if (art_buf == NULL)
		return;

	ath79_init_mac(wlan_mac, ath79_mac_base, 11);
	ath79_register_wmac(art_buf + 0x1000, wlan_mac);

	kfree(art_buf);
}

static void rb2011_nand_select_chip(int chip_no)
{
	switch (chip_no) {
	case 0:
		gpio_set_value(RB2011_GPIO_NAND_NCE, 0);
		break;
	default:
		gpio_set_value(RB2011_GPIO_NAND_NCE, 1);
		break;
	}
	ndelay(500);
}

static struct nand_ecclayout rb2011_nand_ecclayout = {
	.eccbytes	= 6,
	.eccpos		= { 8, 9, 10, 13, 14, 15 },
	.oobavail	= 9,
	.oobfree	= { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
};

static int rb2011_nand_scan_fixup(struct mtd_info *mtd)
{
	struct nand_chip *chip = mtd->priv;

	if (mtd->writesize == 512) {
		/*
		 * Use the OLD Yaffs-1 OOB layout, otherwise RouterBoot
		 * will not be able to find the kernel that we load.
		 */
		chip->ecc.layout = &rb2011_nand_ecclayout;
	}

	return 0;
}

static void __init rb2011_nand_init(void)
{
	gpio_request_one(RB2011_GPIO_NAND_NCE, GPIOF_OUT_INIT_HIGH, "NAND nCE");

	ath79_nfc_set_scan_fixup(rb2011_nand_scan_fixup);
	ath79_nfc_set_parts(rb2011_nand_partitions,
			    ARRAY_SIZE(rb2011_nand_partitions));
	ath79_nfc_set_select_chip(rb2011_nand_select_chip);
	ath79_nfc_set_swap_dma(true);
	ath79_register_nfc();
}

static int rb2011_old_get_port_link(unsigned port)
{
	if (port != 6)
		return -EINVAL;

	/* The Loss of signal line is active low */
	return !gpio_get_value(RB2011_GPIO_SFP_LOS);
}


static void __init rb2011_old_sfp_init(void)
{
	gpio_request_one(RB2011_GPIO_SFP_LOS, GPIOF_IN, "SFP LOS");

	rb2011_ar8327_pad6_cfg.mode = AR8327_PAD_MAC_SGMII;

	rb2011_ar8327_data.pad6_cfg = &rb2011_ar8327_pad6_cfg;

	rb2011_ar8327_sgmii_cfg.sgmii_ctrl = 0xc70167d0;
	rb2011_ar8327_sgmii_cfg.serdes_aen = true;

	rb2011_ar8327_data.sgmii_cfg = &rb2011_ar8327_sgmii_cfg;

	rb2011_ar8327_data.port6_cfg.force_link = 1;
	rb2011_ar8327_data.port6_cfg.speed = AR8327_PORT_SPEED_1000;
	rb2011_ar8327_data.port6_cfg.duplex = 1;

	rb2011_ar8327_data.get_port_link = rb2011_old_get_port_link;
}


static void __init rb2011_new_sfp_init(void)
{
	rb2011_ar8327_pad6_cfg.mode = AR8327_PAD_MAC_SGMII;
	rb2011_ar8327_pad6_cfg.rxclk_delay_en = true;
	rb2011_ar8327_pad6_cfg.rxclk_delay_sel = AR8327_CLK_DELAY_SEL0;

	rb2011_ar8327_data.pad6_cfg = &rb2011_ar8327_pad6_cfg;

	rb2011_ar8327_sgmii_cfg.sgmii_ctrl = 0xc701e7d0;
	rb2011_ar8327_sgmii_cfg.serdes_aen = true; //autonegotination

	rb2011_ar8327_data.sgmii_cfg = &rb2011_ar8327_sgmii_cfg;

	rb2011_ar8327_data.port6_cfg.force_link = 0;
	rb2011_ar8327_data.port6_cfg.speed = AR8327_PORT_SPEED_1000;
	rb2011_ar8327_data.port6_cfg.duplex = 1;
	rb2011_ar8327_data.port6_cfg.txpause = 1;
	rb2011_ar8327_data.port6_cfg.rxpause = 1;
	rb2011_ar8327_data.port6_custom_set_power_state = 20115;
}

static int __init rb2011_setup(u32 flags)
{
	const struct rb_info *info;
	char buf[64];

	info = rb_init_info((void *) KSEG1ADDR(0x1f000000), 0x10000);
	if (!info)
		return -ENODEV;

	scnprintf(buf, sizeof(buf), "Mikrotik RouterBOARD %s",
		  (info->board_name) ? info->board_name : "");
	mips_set_machine_name(buf);

	rb2011_init_partitions(info);

	ath79_register_m25p80(&rb2011_spi_flash_data);
	rb2011_nand_init();

	ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
					 AR934X_ETH_CFG_RXD_DELAY |
				   AR934X_ETH_CFG_SW_ONLY_MODE);

	ath79_register_mdio(1, 0x0);
	ath79_register_mdio(0, 0x0);

	mdiobus_register_board_info(rb2011_mdio0_info,
				    ARRAY_SIZE(rb2011_mdio0_info));

	/* GMAC0 is connected to an ar8327 switch */
	ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
	ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
	ath79_eth0_data.phy_mask = BIT(0);
	ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
	ath79_eth0_pll_data.pll_1000 = 0x6f000000; //here tx/rx delay is more.
	//ath79_eth0_pll_data.pll_1000 = 0x2000000; //also work!

	ath79_register_eth(0);

	/* GMAC1 is connected to the internal switch */
	ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 5);
	ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
	ath79_eth1_data.speed = SPEED_1000;
	ath79_eth1_data.duplex = DUPLEX_FULL;

	ath79_register_eth(1);

	if (flags & RB2011_FLAG_OLD_SFP)
		rb2011_old_sfp_init();

	if (flags & RB2011_FLAG_NEW_SFP)
		rb2011_new_sfp_init();

	if (flags & RB2011_FLAG_WLAN)
		rb2011_wlan_init();

	if (flags & RB2011_FLAG_USB){
		ath79_register_usb();
		gpio_request_one(RB2011_GPIO_USB_POE, GPIOF_ACTIVE_LOW |
			GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED, "USB power off");
	}
	gpio_request_one(RB2011_GPIO_PORT10_POE, GPIOF_OUT_INIT_LOW |
		GPIOF_EXPORT_DIR_FIXED, "Port10 PoE");

	ath79_register_gpio_keys_polled(-1, RBHAPX_KEYS_POLL_INTERVAL,
		ARRAY_SIZE(rb2011_gpio_keys), rb2011_gpio_keys);

	return 0;
}

static void __init rb2011l_setup(void)
{
	rb2011_setup(0);
}

MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011L, "2011L", rb2011l_setup);

static void __init rb2011us_setup(void)
{
	rb2011_setup(RB2011_FLAG_OLD_SFP | RB2011_FLAG_USB);
}

MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011US, "2011US", rb2011us_setup);

static void __init rb2011r5_setup(void)
{
	//RB2011_FLAG_WLAN
	rb2011_setup(RB2011_FLAG_NEW_SFP | RB2011_FLAG_USB);
}

MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011R5, "2011r5", rb2011r5_setup);

static void __init rb2011g_setup(void)
{
	rb2011_setup(RB2011_FLAG_OLD_SFP |
		     RB2011_FLAG_USB |
		     RB2011_FLAG_WLAN);
}

MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011G, "2011G", rb2011g_setup);

All my changes you can see here: https://github.com/adron-s/ag71xx_my
Hope this helps You.

P.S.: As far as I remember the most important thing is collected in the rb2011_new_sfp_init() function.

1 Like

A post was split to a new topic: Get 24V passive PoE working from Port 10 with RB2011

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.