Adding OpenWrt support for Mikrotik SXTG-2HnD v2

Hi,

I'm new to OpenWRT and I'm searching help to install OpenWRT on this product:

https://mikrotik.com/product/RBSXTG-2HnDr2-168

Here some additional information get from supout.rif:
platform : MikroTik
board-name : SXT 2
board : sxtg5p
system type : Mikrotik SXT G-5HPnD
cpu model : MIPS 74Kc V4.12
ASEs implemented : mips16
architecture-name: mipsbe

Modules:
usb-common.ko
nls_base.ko
usbcore.ko
ehci-hcd.ko
sram.ko
aths16.ko
ath8327.ko
phy_amcc_qt2025.ko
music_switch.ko
ag7240.ko
ath.ko
a9300.ko
a9300_ahb.ko

All netboot tested from SXT prebuild have failed. I suppose because there is an additional AR8033 Integrated 10/100/1000 Mbps Ethernet Transceiver.

There is no pre-cabled serial line console, but seems to be pins available for 3.3v serial line on print board circuit. I have no hardware to be able to get information from this.

Any help or advice would be welcome.

Hi huggo,

That device (the product link is different to the boardID from your supout) is not currently supported by OpenWrt.
If you are happy compiling and modifying OpenWrt yourself, you may be able to get it working. Note: OpenWrt does not have support for the old NAND filesystem RouterBoot requires, which may have caused NAND errors for some devices, and is why the there are no prebuilt snapshot images for Mikrotik NAND devices.

If you do want to try this, let us know, and we can give you some more hints.

For the serial lines, I use a CP210x based USB TTL / serial adapter, but any USB serial adapter that supports the correct voltage will be fine. Connect up the ground, TX, and RX pins only, but RouterBoot and RouterOS will (generally) not use the serial pins on hardware that does not have an advertised serial connection.

There is a supported device that is fairly similar. You may be able to compile that device, with a uci-defaults file to enable the wireless device to allow you to connect to Wi-Fi, then ssh into OpenWrt. Then work out the ethernet hardware from there. Or that device's netboot image might damage your hardware.

Hi johnth,

I would like to try to make that device working under OpenWRT.

What I have done since the last post:

  • Watch again the supout.rif
File 03_.startup:
  @discover@
    platform: MikroTik

  @syslog@
    market name = SXT 2
    board name  = SXT G-2HnD r2

  @led@
    btn 'sxtg5p'

So you're right, I have done a mistake on 'system type'.

  • Install the 'build system' v22.03.5 on GNU/Linux PC and build image
    openwrt-ath79-mikrotik-mikrotik_routerboard-sxt-5nd-r2-initramfs-kernel.bin
    including a file to modify defaut network configuration.
    When I netboot that image the system end-up by rebooting, returning to RouterOS.
    As I have no serial interface, I can't see what is wrong, but I guess that when Linux kernel does not find expected hardware, he 'panic' and reboot.

  • So I've started to make a new 'target' into the build system and change
    'target/linux/ath79/image/mikrotik.mk'

define Device/mikrotik_routerboard-sxtg-2hdn
  $(Device/mikrotik_nor)
  SOC := ar9344
  DEVICE_MODEL := RouterBOARD SXT G-2HnD r2 (SXT 2)
  DEVICE_PACKAGES += rssileds kmod-gpio-beeper
  SUPPORTED_DEVICES += rb-sxtg5p
endef
TARGET_DEVICES += mikrotik_routerboard-sxtg-2hdn

By the way, let me know if there is a mistake in that because I have not found documentation into openwrt.org web site for this .mk file.

  • I'm currently trying to make the Devicetree configuration for adding the PHY AR8033 which driver is luckly already enabled into the Linux kernel. But the interconnection with the Soc AR9344 is where I get suck.
    I guess it is linked to GMAC0 MAC device and throw MII bus. So GMAC1 and Ethernet switch can be disabled.

Any help would be appreciate to write the
target/linux/ath79/dts/ar9344_mikrotik_routerboard-sxtg-2hdn.dtsi
file.

That is a NAND device image, so less likely that it works.

LHG 5 looks to be the most similar, so base your work on it: https://github.com/openwrt/openwrt/commit/e0683839b8036388213d7662f3e0066a29b7d480
May have to adjust for later changes in OpenWrt.

Have a look at existing ar9344 mikrotik nor examples: https://github.com/openwrt/openwrt/blob/main/target/linux/ath79/dts/ar9344_mikrotik_routerboard-lhg-5nd.dts

Thanks johnth,

I've build
openwrt-ath79-mikrotik-mikrotik_routerboard-sxtg-2hdn-initramfs-kernel.bin
and it's look like OpenWRT starting:
-> user-led ligth, blink for several seconds and eventually stop blinking.
-> no Ethernet link

I bought an USB/LVTTL (3.3v) cable adapter to connect on GND/RX/TX pads on PCB (Indeed, one of the pad is labeled 3.3V.)

Unfortunately, there were no data on serial terminal (picocom).
After testing successfully the adapter with a loopback test, I understand that the problem was comming from the board.

I've searched for hours reading AR9344 data-sheet, then I realized that I/O voltage is 2.62 V ! (see page 453 at the end of the data-sheet)

Using a voltmeter to test PCB pads, I notice a 2.65 V on RX but 0 V on TX !!
So TX line is probably broken.

I conclude that I can't go on with a blind system, and hope someone would find the correct device-tree configuration to support OpenWRT for this board.

I often mix TX and RX. Check that.
RouterBOOT usually does not output console on device without an advertised serial connector (this can usually be changed by flipping the NO_UART bit on NOR). If your device usually beeps when starting kernel, but is not beeping when you try to boot your image, it is likely that kernel is not booting.
After kernel boots, you should see the LED start the fast flashes (failsafe opportunity) for a few seconds before changing to slow flashes.

A good trick to try here is to use uci-defaults (under files in the build directory) to start the wi-fi, so you may get access that way.

If you share your git tree, I can have a look and see if I can spot anything.

Hi johnth,

Several questions comes in my mind:

  • Is the serial interface of AR9344 has already been used by someone on Mikrotik product?
    I asking that because when I read the data-sheet I see UART lines could be multiplexed to available GPIO pins. So Mikrotik could have connectedt RX/TX not to default pins !

  • Into the Linux kernel code supplied by Mikrotik, I haven't found references to "sxtg5p_devices" structure shown into "platform.c". I assume it is in some code which is not "open source"?
    So I can't deduce the configuration of the SoC from that code?

  • I saw in the forum some have succeed to get a root shell on RouterOS. If I can get this access, would it be possible to read the SoC registers in order to show the configuration?

No guarantee the pads are even connected to the SoC.

The tricky part is working out what they refer to it (in source) as. You should be able to find this from the SPI NOR hard_config data type 0x17 (board_type in prom.c): https://github.com/john-tho/linux/blob/708fc99a000d4a7fef9fa0e19caf857f2634caf0/arch/mips/rb/prom.c We know is has G (gigabit ethernet), SPI touch screen controller (voltage), buzzer, NOR. https://github.com/john-tho/linux/blob/708fc99a000d4a7fef9fa0e19caf857f2634caf0/arch/mips/rb/platform.c The way they bundle devices together with hardware options to enable/disable parts also complicates thing.

I used this on a hapac to dump SoC registers (busybox devmem).

Hi johnth,

I have done one step forward: I have now a root shell access on RouterOS on my device using your provided informations of the last post.

  • Using "devmem" I was able to configure GPIO to change voltage state on UART TX output. That mean:
    a) I have happily not damage that hardware output
    b) The pad is really connected to the SoC GPIO

  • Using "devmem" I was able to read the configuration of GPIOs:
    a) UART TX and RX are routed/muxed in there default position
    b) TX should be an output, but it is configured as an input and same reverse thing for RX.

  • Test on serial TX/RX
    a) With RouterOS: TX stay to 0V and RX to 2,6V
    b) With OpenWRT: TX stay to 0V and RX to 2,6V
    I suppose Mikotik bootloader modify the GPIOs configuration and OpenWRT does not reconfigure GPIOs, that's why serial lines can't work.

So here are questions:

  • Should the GPIOs input/ouput configuration be done in device-tree, and if so how?
  • If that sould't be done in device-tree, should it be done into a driver ?
  • I saw that one of the kernel args is "no_uart", is there a mean to modify the kernel args?
  • Are kernel args into mikrotik image or in the boot-loader?
  • From OpenWRT shell, can I re-enable de serial device driver with root privilege, and how?

Also worth dumping the OEM ethernet regs (gmac*), to work out why that is not working, and get the initvals

Can you read any output using ground and (logical) TX when booting OpenWrt?

Yes, this can happen.You should be able to check via the uart regs.

Yes, but via the driver. For this SoC function routing (UART TX via GPIOn), the driver does not have comprehensive support, so we use pinctrl. Also may need to use this to change SPI CS GPIOs for ath79. You can find examples in the ath79 dts, and documentation in the Linux bindings (see that dir): https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt

These kernel args are what RouterBOOT passes on to RouterOS, after reading the Hard type-length-value settings from NOR.
Most of these kernel args are specific to RouterOS drivers, and the OpenWrt kernel on these devices completly ignores these. The board param will tell you the source name to look up in prom.c. no-uart comes from the hw_opt (type 0x15) bit 0 (more details here: https://github.com/openwrt/openwrt/blob/a61fd0f0bb0f70dc414b282ae20bdcd6a6e25926/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c#L64). On most of these Mikrotik devices flipping this bit on NOR will enable the console in RouterBOOT and RouterOS, but make sure you have a full dump of the NOR, and means to restore it, in case things go wrong.