Supporting ZSUN Wifi Card Reader (16MB Flash, 64MB RAM, AR9331)

we need to get it upstream. It's not included even in the snapshot released.

The biggest problem is still that it's a wifi only device and lede ships with wifi-off as default. So it would be nicely softbricked after successfull flashing :confused:

The image available is 17.01.1 and already outdated. Some needs to get the available patches (device is full compatible with lede & has a reset routine when using micro-sd trigger when booting) and it needs to be solved that somehow wifi is accessible in these builds by default.

EDIT: I just gave a look in the custom imagebuilder from openwrt. It uses the ar71xx-generic profile and included the available patches for zsun. Maybe someone is skilled to do this for LEDE (17.01.4/snapshot) and provide a the custom/unofficial imagebuilder :hugs:

Thanks for the reply-good point, i never thought of the unit would be inaccessible if the wifi was switched off on first reboot after the flash!
I'd still like to know how the posters on here built there custom builds-and with wifi enabled :slight_smile: -as there are some packages on the current build I dont need-and some I would like to add. And I'd like to be able to have a go at actually making a build :slight_smile:

I live in hope, even if it is 17.01.1-but looks like the community is against builds with wifi on, out of the box.....

Cheers
cabs

@rabarbara9 provided the latest (17.01.1) LEDE builds as binaries. There is no image builder included in the provided download package but a zsun-patch (0001-Zsun.patch, 12kb).

I guess someone how is skilled can port this to the most recent version (17.01.4 & maybe snapshot) and provide a custom image builder for our so beloved ZSUN!

This tiny hardware is quite powerful and with 16mb flash there could be a lot's of things included (travelmate, adblock with ssl support and far more!)

Here is the 0001-Zsun.patch

From 27f1a2ccecf15aba391057ff5511edb261966a19 Mon Sep 17 00:00:00 2001
    From: devtop <devtop@one>
    Date: Sat, 29 Apr 2017 03:25:21 +0200
    Subject: [PATCH 1/1] Zsun

    ---
 .../linux/ar71xx/base-files/etc/board.d/02_network |   3 +-
 target/linux/ar71xx/base-files/etc/diag.sh         |   3 +-
 target/linux/ar71xx/base-files/etc/rc.button/BTN_1 |   5 +
 .../etc/uci-defaults/99_zsun-enable-wifi           |   7 ++
 target/linux/ar71xx/base-files/lib/ar71xx.sh       |   3 +
 .../ar71xx/base-files/lib/preinit/50_failsafe_wipe |  11 +++
 .../ar71xx/base-files/lib/upgrade/platform.sh      |   3 +-
 target/linux/ar71xx/config-4.4                     |   1 +
 .../ar71xx/files/arch/mips/ath79/Kconfig.openwrt   |  10 ++
 target/linux/ar71xx/files/arch/mips/ath79/Makefile |   1 +
 .../files/arch/mips/ath79/mach-zsun-sdreader.c     | 101 +++++++++++++++++++++
 .../linux/ar71xx/files/arch/mips/ath79/machtypes.h |   1 +
 target/linux/ar71xx/image/generic.mk               |  13 +++
 target/linux/ar71xx/mikrotik/config-default        |   1 +
 target/linux/ar71xx/nand/config-default            |   1 +
 15 files changed, 161 insertions(+), 3 deletions(-)
 create mode 100644 target/linux/ar71xx/base-files/etc/rc.button/BTN_1
 create mode 100644 target/linux/ar71xx/base-files/etc/uci-defaults/99_zsun-enable-wifi
 create mode 100644 target/linux/ar71xx/base-files/lib/preinit/50_failsafe_wipe
 create mode 100644 target/linux/ar71xx/files/arch/mips/ath79/mach-zsun-sdreader.c

diff --git a/target/linux/ar71xx/base-files/etc/board.d/02_network b/target/linux/ar71xx/base-files/etc/board.d/02_network
index 10f84bf..579883b 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/02_network
+++ b/target/linux/ar71xx/base-files/etc/board.d/02_network
@@ -115,7 +115,8 @@ ar71xx_setup_interfaces()
 	tube2h|\
 	unifiac-lite|\
 	wndap360|\
-	wp543)
+	wp543|\
+    zsun-sdreader)
 		ucidef_set_interface_lan "eth0"
 		;;
 	a40|\
diff --git a/target/linux/ar71xx/base-files/etc/diag.sh b/target/linux/ar71xx/base-files/etc/diag.sh
index 7b8aac8..f0d2568 100644
--- a/target/linux/ar71xx/base-files/etc/diag.sh
+++ b/target/linux/ar71xx/base-files/etc/diag.sh
@@ -34,7 +34,8 @@ get_status_led() {
 	dr344|\
 	tew-632brp|\
 	wpj344|\
-	zbt-we1526)
+	zbt-we1526|\
+    zsun-sdreader)
 		status_led="$board:green:status"
 		;;
 	ap136-010|\
diff --git a/target/linux/ar71xx/base-files/etc/rc.button/BTN_1 b/target/linux/ar71xx/base-files/etc/rc.button/BTN_1
new file mode 100644
index 0000000..3902df9
--- /dev/null
+++ b/target/linux/ar71xx/base-files/etc/rc.button/BTN_1
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+logger Resetting the SD card reader
+echo "0" > /sys/class/gpio/gpio18/value
+echo "1" > /sys/class/gpio/gpio18/value
diff --git a/target/linux/ar71xx/base-files/etc/uci-defaults/99_zsun-enable-wifi b/target/linux/ar71xx/base-files/etc/uci-defaults/99_zsun-enable-wifi
new file mode 100644
index 0000000..fb4fc56
--- /dev/null
+++ b/target/linux/ar71xx/base-files/etc/uci-defaults/99_zsun-enable-wifi
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+uci set wireless.@wifi-device[0].disabled=0
+uci commit wireless
+wifi
+
+exit 0
\ No newline at end of file
diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh
index b035535..9dfac52 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -1217,6 +1217,9 @@ ar71xx_board_detect() {
 	*ZCN-1523H-5)
 		name="zcn-1523h-5"
 		;;
+	*"ZSUN WiFi SD Card Reader")
+		name="zsun-sdreader"
+        ;;
 	*EmbWir-Dorin)
 		name="ew-dorin"
 		;;
diff --git a/target/linux/ar71xx/base-files/lib/preinit/50_failsafe_wipe b/target/linux/ar71xx/base-files/lib/preinit/50_failsafe_wipe
new file mode 100644
index 0000000..b514462
--- /dev/null
+++ b/target/linux/ar71xx/base-files/lib/preinit/50_failsafe_wipe
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+failsafe_wipe() {
+      echo "Doing a factory reset."
+      mount_root
+      firstboot -y
+      sleep 10
+      reboot -f
+}
+  
+boot_hook_add failsafe failsafe_wipe
\ No newline at end of file
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
index 4f479ce..2d12b9e 100755
--- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
@@ -310,7 +310,8 @@ platform_check_image() {
 	wpj558|\
 	zbt-we1526|\
 	zcn-1523h-2|\
-	zcn-1523h-5)
+	zcn-1523h-5|\
+    zsun-sdreader)
 		[ "$magic_long" != "68737173" -a "$magic_long" != "19852003" ] && {
 			echo "Invalid image type."
 			return 1
diff --git a/target/linux/ar71xx/config-4.4 b/target/linux/ar71xx/config-4.4
index ff6bb13..660e4df 100644
--- a/target/linux/ar71xx/config-4.4
+++ b/target/linux/ar71xx/config-4.4
@@ -225,6 +225,7 @@ CONFIG_ATH79_MACH_XD3200=y
 CONFIG_ATH79_MACH_Z1=y
 CONFIG_ATH79_MACH_ZBT_WE1526=y
 CONFIG_ATH79_MACH_ZCN_1523H=y
+CONFIG_ATH79_MACH_ZSUN_SDREADER=y
 CONFIG_ATH79_NVRAM=y
 CONFIG_ATH79_PCI_ATH9K_FIXUP=y
 # CONFIG_ATH79_ROUTERBOOT is not set
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
index 894367f..4ccf42c 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
+++ b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
@@ -1856,3 +1856,13 @@ config ATH79_MACH_TL_WPA8630
 	select ATH79_DEV_LEDS_GPIO
 	select ATH79_DEV_M25P80
 	select ATH79_DEV_WMAC
+
+config ATH79_MACH_ZSUN_SDREADER
+	bool "ZSUN WiFi SD Card Reader"
+	select SOC_AR933X
+	select ATH79_DEV_ETH
+	select ATH79_DEV_GPIO_BUTTONS
+	select ATH79_DEV_LEDS_GPIO
+	select ATH79_DEV_M25P80
+	select ATH79_DEV_USB
+	select ATH79_DEV_WMAC
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Makefile b/target/linux/ar71xx/files/arch/mips/ath79/Makefile
index c91d03f..4cc4a04 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/Makefile
+++ b/target/linux/ar71xx/files/arch/mips/ath79/Makefile
@@ -229,3 +229,4 @@ obj-$(CONFIG_ATH79_MACH_XD3200)			+= mach-sr3200.o
 obj-$(CONFIG_ATH79_MACH_Z1)			+= mach-z1.o
 obj-$(CONFIG_ATH79_MACH_ZBT_WE1526)		+= mach-zbt-we1526.o
 obj-$(CONFIG_ATH79_MACH_ZCN_1523H)		+= mach-zcn-1523h.o
+obj-$(CONFIG_ATH79_MACH_ZSUN_SDREADER)	+= mach-zsun-sdreader.o
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-zsun-sdreader.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-zsun-sdreader.c
new file mode 100644
index 0000000..56d2a32
--- /dev/null
+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-zsun-sdreader.c
@@ -0,0 +1,101 @@
+/*
+ *  ZSUN WiFi SD Card Reader support
+ *
+ *  Copyright (C) 2015 by Andrzej Surowiec <emeryth@hackerspace.pl>
+ *  Based on mach-carambola2.c copyright (C) 2013 Darius Augulis <darius@8devices.com>
+ *
+ *  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.
+ */
+
+#include <linux/gpio.h>
+#include <asm/mach-ath79/ath79.h>
+#include <asm/mach-ath79/ar71xx_regs.h>
+#include "common.h"
+#include "dev-eth.h"
+#include "dev-gpio-buttons.h"
+#include "dev-leds-gpio.h"
+#include "dev-m25p80.h"
+#include "dev-spi.h"
+#include "dev-usb.h"
+#include "dev-wmac.h"
+#include "machtypes.h"
+
+#define ZSUN_SDREADER_GPIO_LED_SYSTEM		0
+
+#define ZSUN_SDREADER_GPIO_SW_SD		22
+#define ZSUN_SDREADER_GPIO_USB_SWITCH		21
+#define ZSUN_SDREADER_GPIO_SD_RESET		18
+
+#define ZSUN_SDREADER_MAC0_OFFSET		0x0000
+#define ZSUN_SDREADER_MAC1_OFFSET		0x0006
+#define ZSUN_SDREADER_CALDATA_OFFSET		0x1000
+#define ZSUN_SDREADER_WMAC_MAC_OFFSET		0x1002
+
+#define ZSUN_SDREADER_KEYS_POLL_INTERVAL	20	/* msecs */
+#define ZSUN_SDREADER_KEYS_DEBOUNCE_INTERVAL	(3 * ZSUN_SDREADER_KEYS_POLL_INTERVAL)
+
+static struct gpio_led zsun_sdreader_leds_gpio[] __initdata = {
+	{
+		.name		= "zsun-sdreader:green:system",
+		.gpio		= ZSUN_SDREADER_GPIO_LED_SYSTEM,
+		.active_low	= 0,
+	}
+};
+
+static struct gpio_keys_button zsun_sdreader_gpio_keys[] __initdata = {
+	{
+		.desc           = "SD Card insert switch",
+		.type           = EV_KEY,
+		.code           = BTN_1,
+		.debounce_interval = ZSUN_SDREADER_KEYS_DEBOUNCE_INTERVAL,
+		.gpio           = ZSUN_SDREADER_GPIO_SW_SD,
+		.active_low	= 1,
+	}
+};
+
+
+static void __init zsun_sdreader_common_setup(void)
+{
+	u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
+
+	ath79_register_m25p80(NULL);
+	ath79_register_wmac(art + ZSUN_SDREADER_CALDATA_OFFSET,
+			    art + ZSUN_SDREADER_WMAC_MAC_OFFSET);
+
+	ath79_setup_ar933x_phy4_switch(true, true);
+
+	//ath79_init_mac(ath79_eth0_data.mac_addr, art + ZSUN_SDREADER_MAC0_OFFSET, 0);
+	ath79_init_mac(ath79_eth1_data.mac_addr, art + ZSUN_SDREADER_MAC1_OFFSET, 0);
+
+
+	ath79_register_mdio(0, 0x0);
+
+	//ath79_register_eth(0);
+	ath79_register_eth(1);
+}
+
+static void __init zsun_sdreader_setup(void)
+{
+	zsun_sdreader_common_setup();
+
+	ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
+				AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
+				AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
+				AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
+				AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
+
+	ath79_register_leds_gpio(-1, ARRAY_SIZE(zsun_sdreader_leds_gpio),
+				 zsun_sdreader_leds_gpio);
+	ath79_register_gpio_keys_polled(-1, ZSUN_SDREADER_KEYS_POLL_INTERVAL,
+					ARRAY_SIZE(zsun_sdreader_gpio_keys),
+					zsun_sdreader_gpio_keys);
+	gpio_request_one(ZSUN_SDREADER_GPIO_USB_SWITCH, GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED, "USB switch");
+	gpio_request_one(ZSUN_SDREADER_GPIO_SD_RESET, GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_CHANGEABLE, "SD reader reset");
+
+	ath79_register_usb();
+}
+
+MIPS_MACHINE(ATH79_MACH_ZSUN_SDREADER, "ZSUN-SDREADER", "ZSUN WiFi SD Card Reader",
+		zsun_sdreader_setup);
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
index b9a8e3e..3f05878 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
+++ b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
@@ -294,6 +294,7 @@ enum ath79_mach_type {
 	ATH79_MACH_ZBT_WE1526,			/* Zbtlink ZBT-WE1526 */
 	ATH79_MACH_ZCN_1523H_2,			/* Zcomax ZCN-1523H-2-xx */
 	ATH79_MACH_ZCN_1523H_5,			/* Zcomax ZCN-1523H-5-xx */
+    ATH79_MACH_ZSUN_SDREADER,	/* Zsun WiFi SD Card Reader */
 };
 
 #endif /* _ATH79_MACHTYPE_H */
diff --git a/target/linux/ar71xx/image/generic.mk b/target/linux/ar71xx/image/generic.mk
index d978dec..54b2f0f 100644
--- a/target/linux/ar71xx/image/generic.mk
+++ b/target/linux/ar71xx/image/generic.mk
@@ -725,3 +725,16 @@ define Device/bhr-4grv2
   IMAGE/factory.bin = append-kernel | pad-to $$$$(KERNEL_SIZE) | append-rootfs | pad-rootfs | mkbuffaloimg
 endef
 TARGET_DEVICES += bhr-4grv2
+
+define Device/zsun-sdreader
+  DEVICE_TITLE := ZSUN WiFi SD Card Reader
+  BOARDNAME := ZSUN-SDREADER
+  ROOTFS_SIZE := 14912k
+  KERNEL_SIZE := 1216k
+  IMAGE_SIZE := 16128k
+  CONSOLE := ttyATH0,115200
+  MTDPARTS := spi0.0:64k(u-boot)ro,64k(u-boot-env)ro,14912k(rootfs),1216k(kernel),64k(nvram),64k(art),16128k@0x20000(firmware) 
+  IMAGES := sysupgrade.bin
+  IMAGE/sysupgrade.bin = append-rootfs | pad-rootfs | pad-to $$$$(ROOTFS_SIZE) | append-kernel | check-size $$$$(IMAGE_SIZE)
+endef
+TARGET_DEVICES += zsun-sdreader
diff --git a/target/linux/ar71xx/mikrotik/config-default b/target/linux/ar71xx/mikrotik/config-default
index 44ea327..1092c85 100644
--- a/target/linux/ar71xx/mikrotik/config-default
+++ b/target/linux/ar71xx/mikrotik/config-default
@@ -190,6 +190,7 @@ CONFIG_ATH79_MACH_RBSXTLITE=y
 # CONFIG_ATH79_MACH_Z1 is not set
 # CONFIG_ATH79_MACH_ZBT_WE1526 is not set
 # CONFIG_ATH79_MACH_ZCN_1523H is not set
+# CONFIG_ATH79_MACH_ZSUN_SDREADER is not set
 # CONFIG_ATH79_NVRAM is not set
 CONFIG_ATH79_ROUTERBOOT=y
 CONFIG_CMDLINE="rootfstype=squashfs noinitrd"
diff --git a/target/linux/ar71xx/nand/config-default b/target/linux/ar71xx/nand/config-default
index 515266b..d73568c 100644
--- a/target/linux/ar71xx/nand/config-default
+++ b/target/linux/ar71xx/nand/config-default
@@ -80,6 +80,7 @@
 # CONFIG_ATH79_MACH_WZR_HP_G300NH2 is not set
 # CONFIG_ATH79_MACH_WZR_HP_G450H is not set
 # CONFIG_ATH79_MACH_ZCN_1523H is not set
+# CONFIG_ATH79_MACH_ZSUN_SDREADER is not set
 # CONFIG_ATH79_NVRAM is not set
 CONFIG_CMDLINE="rootfstype=squashfs noinitrd"
 # CONFIG_IP17XX_PHY is not set
-- 
2.1.4

:slight_smile:
Most of this part is now beyond me, so it looks like I will continue to use the image that was kindly supplied higher up in this thread.But I will continue to be subsrcribed, in the hope the Zsun (it packs a very powerful punch for such a small device!) makes it into the mainline

thanks!

cabs

Maybe somebody is capable of porting this one to LEDE:
https://github.com/openwrt/openwrt/pull/312

I tried making my own firmware and apparently it didn't work...

Anyone know the easiest way to debrick one of these? Also on that front, has there been progress in updating the Uboot loader with some sort of failsafe (like USB firmware loading a la the custom A5V11 Uboot)?

I don't think there's an "easy" way. The device has UART and ethernet on tiny solder pads -- doable, but hard if you're not somewhat adept at soldering. After connecting a serial line and an ethernet port you can flash a new image from uboot.

Do I need both, or can I just use either serial or Ethernet?

You need both because the factory u-boot does not allow upload through serial, tftp via ethernet is the only way. There's the theoretical option of installing a more capable u-boot that will allow serial upload, but as far as I can tell noone has created one.

Edit: It seems to be possible to upload through uboot, albeit really slowly: https://github.com/maurerr/ubootwrite

i was just about to recommend the same thing as i'm the author of the fork :slight_smile:
make sure you use a minimal bin image ( you can use mine https://www.dropbox.com/s/rg7d2iz4i4do30u/openwrt-ar71xx-generic-zsun-sdreader-min270416.bin?dl=1 ) as it writes with about <1KB/s so it takes at least 30-40 min

in the meantime i'll try to port the patch to latest LEDE 17.01.4 and share the code + sdk

LE: I have compiled LEDE 17.01.4 !
I've tested it and it's working - at least with upgrade from 15.05
https://mega.nz/#!R9pBxJCI!m4qA84DytH_zwexZjTJCUuQMRDLMzeSI2SUJ-QXn5i4

the SDK is:
https://mega.nz/#!81wh3BzA!wRtQrE-_mjlaPKDa49MWL9dDSrWW2ETFzs14wcsUznw

and the imagebuilder:
https://mega.nz/#!kho31TAB!Myp2u5EETPdewbDW4SZwuokE6QxBTluganp6hPEXNbg

7 Likes

Wow! :star_struck:

@maurer: Can you tell if this build (and the imagebuilder) has the two most important features for our (then unbrickable!) ZSUN included:

  • It starts with WIFI on (and open?) automatically when flashed without keepings settings ("stock" settings)
  • The micro sd card slot can trigger a reset (which will end one line up = WIFI on)

yeah, it has both features as were implemented in the patch above.
it doesn't have thou dmesg kernel debug as it won't fit

I might have to get another one now then (I bricked my other one and suck at soldering on pads that freaking small.

You don't need soldering. Just buy this kind of probes https://m.ebay.com/itm/10Pcs-Test-Clip-Mini-Grabber-SMD-IC-Hook-Probe-Jumper-Practical/401074805909 and clip it on the 3 pins (rx TX gnd)

1 Like

For the dumb Windows user in the room, can someone spell this out for me please?

As I read @maurer's post above I think there are 2 options (files) in the post, and the files are massively different in size
1 - "minimal bin image"
2 - "Compiled LEDE 17.01.4"

Can the ubootwrite be used to load either? Are there detailed instructions for using this?

Is it easier\safer to use the original process to install 15.05 and then do a sysupgrade?

You misunderstood. One, the smaller file at around ~16 MB, is the LEDE image that goes on the device itself. You could utilize the original update process, inserting it into a factory update archive, but it's probably easier to use the one provided on that page (for OpenWrt CC) and in a second step sysupgrade to the new LEDE image.

The other one, weighing in at ~220 MB, is the matching Image Generator / Image Builder archive. This can be used to build your own custom LEDE image. It's really a courtesy of @maurer to provide this, too, since it makes it so much easier to create customized images. But if you just want to install LEDE and go from there, you'll have no use for it.

actually the minimal build image is the one in Dropbox and only 2.5mb

Not clear what you mean by "inserting it into a factory update archive". I am familiar with the page. Are you suggesting I sub the "Compiled LEDE 17.01.4" file for the SD100-openwrt.tar.gz.

What about the ubootwrite tools?

Oh, THAT one. That is a special image to use with the ubootwrite tools. Since ubootwrite writes so slow, a regular fully featured image would take multiple hours to transmit. You can use the minimal image to get the device running, and then sysupgrade to a regular image.

And how would one use this tool (ie commands at a syntax level)?

I don't know what you mean by "commands at a syntax level", but there's instructions on the Github page. I never actually tried running python on Windows, though.