Getting RUT240 to work

Hi,

I'm trying to port openwrt to RUT240.

For now - as quick hack - I've added to target/linux/ar71xx/image the following:

define Device/rut200
  DEVICE_TITLE := Teltonika RUT200
  DEVICE_PACKAGES := kmod-usb-core kmod-usb2 -uboot-envtools
  BOARDNAME := GL-AR150
  SUPPORTED_DEVICES := rut200
  IMAGE_SIZE := 15552k
  MTDPARTS := spi0.0:128k(u-boot)ro,64k(config)ro,64k(art)ro,15552k(firmware),576k(event-log)ro
  TPLINK_HWID := 0x32200002
  TPLINK_HWREV := 0x1
  TPLINK_HEADER_VERSION := 1
  CONSOLE := ttyATH0,115200
  REVISION := RUT2xx
  KERNEL := kernel-bin | patch-cmdline | lzma | tplink-v1-header
  KERNEL_INITRAMFS := kernel-bin | patch-cmdline | lzma | uImage lzma
  IMAGES := sysupgrade.bin factory.bin
  IMAGE/factory.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs |\
    pad-rootfs | teltonika-fw-fake-checksum | append-string RUT200019999 | append-string master |\
    append-md5sum-bin | check-size $$$$(IMAGE_SIZE)
  IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) |\
    append-rootfs | pad-rootfs | append-metadata |\
    check-size $$$$(IMAGE_SIZE)
endef
TARGET_DEVICES += rut200

I then get a working image for rut240, that boots.

But i'm very surprised to see that wifi does not work. No wlan interface is created, which I find very surprising for a AR9331 processor. I worked with several devices with this processor, and wifi always worked out of the box. Do you have any idea why wifi could not work with this board?

Ok I get:

[   12.229044] ath9k ar933x_wmac: failed to initialize device
[   12.234481] ath9k: probe of ar933x_wmac failed with error -5

I guess it's related to me having the wrong dts, but I got no idea what I should put in the DTS, so I copied GL-AR150 dts for now.

Please mind that ar71xx is deprecated; ath79 is the way to go.

https://openwrt.org/docs/techref/targets/ar71xx
https://openwrt.org/docs/techref/targets/ath79

Ok then I tried to add the following to target/linux/ath79/image/generic.mk

define Device/rut200
  DEVICE_TITLE := Teltonika RUT200
  ATH_SOC := ar9330
  DEVICE_PACKAGES := kmod-usb-core kmod-usb2 -uboot-envtools
  SUPPORTED_DEVICES := rut200
  IMAGE_SIZE := 15552k
  MTDPARTS := spi0.0:128k(u-boot)ro,64k(config)ro,64k(art)ro,15552k(firmware),576k(event-log)ro
  TPLINK_HWID := 0x32200002
  TPLINK_HWREV := 0x1
  TPLINK_HEADER_VERSION := 1
  CONSOLE := ttyATH0,115200
  REVISION := RUT2xx
  KERNEL := kernel-bin | patch-cmdline | lzma | tplink-v1-header
  KERNEL_INITRAMFS := kernel-bin | patch-cmdline | lzma | uImage lzma
  IMAGES := sysupgrade.bin factory.bin
  IMAGE/factory.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs |\
    pad-rootfs | teltonika-fw-fake-checksum | append-string RUT200019999 | append-string master |\
    append-md5sum-bin | check-size $$$$(IMAGE_SIZE)
  IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) |\
    append-rootfs | pad-rootfs | append-metadata |\
    check-size $$$$(IMAGE_SIZE)
endef
TARGET_DEVICES += rut200

I get

[    0.000000] Linux version 4.19.79 (pparent@pierre-laptop) (gcc version 8.3.0 (OpenWrt GCC 8.3.0 r11274-ee41b602a2)) #0 Mon Oct 21 07:06:52 2019
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 00019374 (MIPS 24Kc)
[    0.000000] SoC: Atheros AR9330 rev 1
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 04000000 @ 00000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] OF: fdt: No valid device tree found, continuing without
[    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-0x0000000003ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000003ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000003ffffff]
[    0.000000] random: get_random_bytes called from start_kernel+0x98/0x4a8 with crng_init=0
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 16240
[    0.000000] Kernel command line:   rootfstype=squashfs,jffs2
[    0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] Memory: 57604K/65536K available (4273K kernel code, 178K rwdata, 1008K rodata, 1188K init, 206K bss, 7932K 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] Failed to get CPU node
[    0.000000] sched_clock: 32 bits at 100 Hz, resolution 10000000ns, wraps every 21474836475000000ns

What am I doing wrong? WHy is it not booting with this arch?

So in the mean time i've succeded to get wifi working with ar71xx: (thank's to someone who gave me the info)

Here is the mach info needed to correctly initialize the wlan mac address:

#define RUT2XX_GPIO_LED_LAN1		14
#define RUT2XX_GPIO_LED_WAN		17
#define RUT2XX_GPIO_LED_2G		8
#define RUT2XX_GPIO_LED_3G		24
#define RUT2XX_GPIO_LED_4G		21

#define RUT2XX_GPIO_BTN_RESET		22

#define RUT2XX_WMAC_CALDATA_OFFSET	0x1000

#define RUT2XX_KEYS_POLL_INTERVAL	20
#define RUT2XX_KEYS_DEBOUNCE_INTERVAL	(3 * RUT2XX_KEYS_POLL_INTERVAL)


static struct gpio_led rut200_leds_gpio[] __initdata = {
	{
		.name		= "rut200:green:lan1",
		.gpio		= RUT2XX_GPIO_LED_LAN1,
		.active_low	= 0,
	}, {
		.name		= "rut200:green:status",
		.gpio		= RUT2XX_GPIO_LED_4G,
		.active_low	= 0,
	}, {
		.name		= "rut200:green:wan",
		.gpio		= RUT2XX_GPIO_LED_WAN,
		.active_low	= 0,
	}, 
};

static struct gpio_keys_button rut200_gpio_keys[] __initdata = {
	{
		.desc			= "reset",
		.type			= EV_KEY,
		.code			= KEY_RESTART,
		.debounce_interval	= RUT2XX_KEYS_DEBOUNCE_INTERVAL,
		.gpio			= RUT2XX_GPIO_BTN_RESET,
		.active_low		= 0,
	},
};


static void __init gl_inet_setup(void)
{
	u8 *art = (u8 *) KSEG1ADDR(0x1f030000);
	u8 *mac = (u8 *) KSEG1ADDR(0x1f020000);
	u8  wlan_mac[ETH_ALEN];

	ath79_register_m25p80(NULL);

	ath79_register_mdio(0, 0x0);

	/* LAN */
	ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
	ath79_register_eth(1);

	/* WAN */
	ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
	ath79_register_eth(0);


	ath79_register_leds_gpio(-1, ARRAY_SIZE(rut200_leds_gpio),
				 rut200_leds_gpio);

	ath79_register_gpio_keys_polled(1, RUT2XX_KEYS_POLL_INTERVAL,
					ARRAY_SIZE(rut200_gpio_keys),
					rut200_gpio_keys);

	ath79_init_mac(wlan_mac, mac, 2);
        ath79_register_wmac(art + RUT2XX_WMAC_CALDATA_OFFSET, wlan_mac);
    

	ath79_register_usb();
}

I've found how to power on the lte/4G modem:

 echo "19" > /sys/class/gpio/export
 echo "out" > /sys/class/gpio/gpio19/direction  
 echo "1" > /sys/class/gpio/gpio19/value
find target/linux/ath79/ | grep '.dts' | grep ar933
1 Like
find target/linux/ath79/ | grep '.dts' | grep ar933
target/linux/ath79/dts/ar9331_etactica_eg200.dts
target/linux/ath79/dts/ar9331_tplink_tl-mr3020-v1.dts
target/linux/ath79/dts/ar9331_8dev_carambola2.dts
target/linux/ath79/dts/ar9331_pisen_ts-d084.dts
target/linux/ath79/dts/ar9330_pqi_air-pen.dts
target/linux/ath79/dts/ar9331_tplink_tl-wr703n.dts
target/linux/ath79/dts/ar9330_glinet_gl-ar150.dts
target/linux/ath79/dts/ar9331_tplink_tl-wr710n-v1.dts
target/linux/ath79/dts/ar9331_embeddedwireless_dorin.dts
target/linux/ath79/dts/ar9331_pisen_wmm003n.dts
target/linux/ath79/dts/ar9331_tplink_tl-mr3040-v2.dts
target/linux/ath79/dts/ar9331_alfa-network_ap121f.dts
target/linux/ath79/dts/ar9331_tplink_tl-wr741nd-v4.dts
target/linux/ath79/dts/ar9331_tplink_tl-mr10u.dts
target/linux/ath79/dts/ar9331_tplink_tl-wr741nd-v4.dtsi
target/linux/ath79/dts/ar9331.dtsi
target/linux/ath79/dts/ar9330_rut200.dts
target/linux/ath79/dts/ar9331_tplink_tl-wr703n_tl-mr10u.dtsi
target/linux/ath79/dts/ar9331_rut200.dts
target/linux/ath79/dts/ar9331_tplink_tl-wr740n-v4.dts
target/linux/ath79/dts/ar9330.dtsi

Yet i've created the dts

interesting name....

fgrep -r 'rut200' target/linux/ath79 | grep '.dts'

fgrep -r 'rut200' target/linux/ath79 | grep '.dts'
target/linux/ath79/dts/ar9330_rut200.dts:       model = "Teltonika rut200";
target/linux/ath79/dts/ar9330_rut200.dts:       compatible = "Teltonika,rut200", "qca,ar9330";

spot the difference ( and it's not 9330 / 9331 )

target/linux/ath79/image/generic.mk:define Device/etactica_eg200
target/linux/ath79/dts/ar9331_etactica_eg200.dts:	compatible = "etactica,eg200", "qca,ar9331";

target/linux/ath79/image/generic.mk:define Device/rut200
target/linux/ath79/dts/ar9330_rut200.dts:       compatible = "Teltonika,rut200", "qca,ar9330";

I've got it booting on the ath79 target. Can't remember if anything wasn't working or not, since it's quite a while ago I worked on this. But I'm pretty sure I hadn't gotten the modem to enable yet.

The modem power may be controlled via a GPIO pin. There is a thread somewhere on here with more info on the RUT950's, not the same, but could be a lead.

Please I gave the answer above the power of the modem is controled by gpio 19. Doing the following will enable the modem:

  echo "19" > /sys/class/gpio/export
  echo "out" > /sys/class/gpio/gpio19/direction  
  echo "1" > /sys/class/gpio/gpio19/value

@Lochnair Thank's a lot for your code.

1 Like

I tried that yesterday, but no luck. Could be that the USB definition in the DTS file might be wrong/missing something.

I did find some interesting stuff in package/base-files/files/lib/preinit/81_modem_restart and package/base-files/files/sbin/gpio.sh from the GPL archive.

According to those the modem is reset upon boot:

        #Reset
        /sbin/gpio.sh clear MON
        #Power off
        /sbin/gpio.sh set MRST

        #SIM
        if [ `uci -q get simcard.simcard.default` = "sim2" ]; then
                /sbin/gpio.sh clear SIM
        else
                /sbin/gpio.sh set SIM
        fi

        #Clear reset
        /sbin/gpio.sh set MON
        #Power on
        /sbin/gpio.sh clear MRST

MON is pin 19 and MRST is pin 18. I'm guessing the SIM part doesn't apply to this device.

Might be enough to set the GPIO pins to the right value in the DTS.
Guess I'll fiddle more with this when I get home.

Edit: Fiddled more with the GPIO pins last night - no joy. Looking at the behavior with stock firmware, I should see the USB controller/hub come up regardless of the pins. I'm not sure where to start looking to figure out the USB issue.

Turns out I was just missing the right USB driver :man_facepalming:
Some tweaks are still needed, but the important things are in place.

I've uploaded a build if anyone would like to try:
https://dl.lochnair.net/OpenWrt/openwrt-ath79-generic-teltonika_rut240-squashfs-factory.bin

1 Like

Hey, @Lochnair, could you please re-upload your build? The link is dead. Am I right in assuming that this build has the modem working?

Ah, yes I'm moving things to a new box, so until I've restored services it's down.
I put it here on GitHub meanwhile.

I can't say for sure. The modem does initialize, but when I was working on it, I didn't have a SIM card available to test with.

Thank you so much!
Could you also provide a config you used to make this build?
I am having a trouble trying to compile one myself.

Thanks again!

One more question. Sorry, I am new to this. I tried to upgrade with openwrt-ath79-generic-teltonika_rut240-squashfs-factory.bin in luci, it says: can't downgrade =(
Should I use recovery mode or, what is the process?