User Tools

Site Tools


projects:zsun-wifi-card-reader

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
projects:zsun-wifi-card-reader [2016/01/01 17:16] – [Hardware hacking] emerythprojects:zsun-wifi-card-reader [2020/02/12 16:14] (current) emeryth
Line 1: Line 1:
 +{{template>:template:project
 + | name=zsun-wifi-card-reader
 + | status=abandoned
 + | founder=[[user>emeryth]]
 + | repo=[[github>emeryth/source]] [[github>emeryth/openwrt-zsun]]
 +}}
 +
 ====== Hacking the Zsun WiFi SD Card Reader ====== ====== Hacking the Zsun WiFi SD Card Reader ======
 +{{:projects:banner.jpg?nolink&700|}}
  
 The goal of this project is to learn as much as possible about the Zsun WiFi card reader and run OpenWrt on it to turn it into an awesome wifi device. The goal of this project is to learn as much as possible about the Zsun WiFi card reader and run OpenWrt on it to turn it into an awesome wifi device.
  
 +**UPDATE 2017-09-12** Info about LEDE and USB gadget working \\
 +**UPDATE 2016-11-28** Adding some more info about the new PCB revision, thanks to Erik Dorner, who sent me his analysis a long time ago \\
 +**UPDATE 2016-04-23** The new PCB is missing a jumper on the RX serial line, see serial port section \\
 +**UPDATE 2016-03-16** The second PCB revision has identical software and hardware (apart from optimized minor component layout), flashing works the same \\
 +**UPDATE 2016-03-12** We now know that there are at least two different PCB versions of the reader!  \\
 +**UPDATE 2016-02-21** github mirror at https://github.com/Emeryth/openwrt-zsun \\
 +**UPDATE 2016-01-27** informatic seems to have figured out how to use the original firmware's update function: [[projects:zsun-wifi-card-reader:factory-update|Zsun Card Reader Firmware Update Format]]
  
 === People Involved === === People Involved ===
Line 10: Line 25:
  
  
-==== State ====+==== Current status ====
  
 All the important aspects of hardware are understood. \\ All the important aspects of hardware are understood. \\
-OpenWrt confirmed working, but no easy way of flashing yet.+OpenWrt Chaos Calmer ported (but not yet thoroughly tested), can be flashed over telnet if you dare. 
 + 
 +==== What can I do with it? ==== 
 +  * Use it for its intended purpose of serving files, duh 
 +  * Use as a tiny and pretty good WiFi AP/client/repeater (the hardware supports multiple simultaneous wireless interfaces!) 
 +  * Play around with OpenWrt 
 +  * Use it as the brains of your IoT project 
 +  * Buy a dozen and play around with mesh networking 
 +  * Use it for distributed WiFi activism like PirateBox or OccupyWiFi, or run a [[https://gist.github.com/Informatic/65261ffd1aee8ddae861|minimal Tor hidden service]] (with addition of being easily hidden in public places) 
 +  * Host Node.js on it and take your apps to your favorite coffee shop :^) 
 +\\ 
 +{{:projects:zsun_powerbank.jpg?direct&400|Size comparison with a single cell powerbank}} 
 + 
 +Size comparison with a single 18650 cell powerbank. 
  
 ==== Hardware ==== ==== Hardware ====
Line 23: Line 52:
 \\ \\
 The device consists of two PCBs sandwiched together and connected via 8 pins.\\ The device consists of two PCBs sandwiched together and connected via 8 pins.\\
 +**WARNING** There are at least 2 PCB revisions, our original research was on the "old" revision, the "new" revision appeared in early 2016.
 +The new revision has optimized layout with some minor changes, software is identical. 
 +
 The bottom PCB contains only the SD card reader chip and SD slot, it can be safely removed without affecting operation. The bottom PCB contains only the SD card reader chip and SD slot, it can be safely removed without affecting operation.
 +**This is only true for the old PCB revision!** The new revision moved the 3.3V regulator to the PCB with the card reader.
 +
  
 === Serial Port === === Serial Port ===
Line 30: Line 64:
 Bitrate is 115200. Bitrate is 115200.
  
-Original firmware root password is "zsun1188"+Original firmware root password is "zsun1188" \\ 
 + 
 +The new PCB has a missing jumper that connects the serial RX testpad to the SoC. Short it or solder directly to the lower pad of the jumper to use serial. 
 +(The second missing resistor is a pull up/down, I guess) 
 + 
 +{{:projects:rx_jumper.jpg?direct&600|}} 
 + 
 +Thanks to Andreas H. for the clear picture of the new PCB.
  
 === Ethernet Port === === Ethernet Port ===
Line 37: Line 78:
 Use a Magjack or similar connector with magnetics.\\ Use a Magjack or similar connector with magnetics.\\
 This port is required for uploading images to u-boot.\\ This port is required for uploading images to u-boot.\\
 +
 +Here's how to properly connect the ethernet port, thanks to **Erik Dorner**: \\
 +
 +The AR9331 uses a current-mode line driver, which, in practical terms, means that the center taps of the primary coils of the Ethernet transformer must be connected to the PHY power supply voltage (2.0V for the AR9331).\\
 +The SoC is capable of producing this voltage, but it needs some external components (a general purpose PNP transistor and some filter/buffer capacitors) to do so.\\
 +Fortunately, the relevant pins of the AR9331 are also broken out as test points.\\
 +
 +{{:projects:zsun_how_to_connect_eth_tranformer.jpg?direct&800|}}
 +
 +If you don't care that much, you can connect 3.3V to the center taps, it should work.
  
 === USB switch === === USB switch ===
Line 71: Line 122:
  
  
 +=== USB device mode ===
  
 +AR9331 is capable of working as a usb device (gadget).
 +<del>Unfortunately the code for that exists only as a patch for an old version of OpenWrt:
 +http://neykov.name/posts/ar933x-usb-device-driver/ </del>
  
 +**The USB device/gadget patch has been added to mainline LEDE!**
  
 +(It's not in the 17.01 stable release, though)
 +
 +So if you want to use the zsun as a USB gadget you will need to:
 +  - <del>Port the code</del> Compile LEDE from source, look for more info in the LEDE section of this page
 +  - Remove the G13 bootstrap resistor setting USB to host mode
 +  - <del>Remove the card reader PCB and</del> (the card reader PCB now contains the 3.3V regulator, so you can't just remove it) rewire the the USB signal pins (the ones on the bottom right in the pictures) to a USB plug
 +
 +
 +Here's what it looks like on the old PCB with the pins connected to the original USB plug:
 +
 +{{:projects:usb_gadget.jpg?direct&600|}}
 ==== Original firmware ==== ==== Original firmware ====
  
Line 79: Line 146:
 Source: [[http://www.zoobab.com/zsun-sd11x-wifi-card-reader]] Source: [[http://www.zoobab.com/zsun-sd11x-wifi-card-reader]]
  
-Regular telnet won'work but you can connect using socat:+Regular telnet might not work (''netkit-telnet'' in Ubuntu 15.10 works fine) but you can connect using socat:
  
 <code> <code>
Line 103: Line 170:
 ~ # ~ #
 </code> </code>
 +
 +If you want to use proper telnet just run it on different port with:
 +<code>telnetd -p 2137</code>
  
  
Line 111: Line 181:
 My OpenWrt port, based on the 15.05 "Chaos Calmer" release: \\ My OpenWrt port, based on the 15.05 "Chaos Calmer" release: \\
 https://code.hackerspace.pl/emeryth/openwrt_zsun/ https://code.hackerspace.pl/emeryth/openwrt_zsun/
 +
 +**You have to clone the "zsun" branch** \\
 +  git clone -b zsun https://code.hackerspace.pl/emeryth/openwrt_zsun/
 +
 +Github mirror:
 +https://github.com/Emeryth/openwrt-zsun 
 +
 +Compiled images and image builder: \\
 +<del>https://owncloud.hackerspace.pl/index.php/s/7s5c5RDS7Njgwpv</del>
 +https://owncloud.hackerspace.pl/s/e4zWPZ8FqFMnrgk
 +
 +**You cannot use kernel modules from the official repository, use the image builder or compile them yourself if they're not included.**
  
 This port sticks to the original flash layout. \\ This port sticks to the original flash layout. \\
 I've added a few things to this port to make it more usable on the zsun without having to solder. I've added a few things to this port to make it more usable on the zsun without having to solder.
   * Wifi is enabled by default, AP mode, no encryption   * Wifi is enabled by default, AP mode, no encryption
-  * Entering failsafe will run a script that automatically does a factory rest+  * Entering failsafe will run a script that automatically does a factory reset
   * The SD card detect pin is registered as a button and will trigger failsafe when inserted/removed during boot   * The SD card detect pin is registered as a button and will trigger failsafe when inserted/removed during boot
 +  * The SD card reader is reset every time a card is inserted or removed
 +
 +
 +==== LEDE ====
 +
 +https://forum.lede-project.org/t/supporting-zsun-wifi-card-reader-16mb-flash-64mb-ram-ar9331/2142
 +
 +I've made a quick port of LEDE:
 +https://github.com/Emeryth/source/tree/zsun
 +
 +**good news:**
 +It has USB gadget
 +
 +**bad news:**
 +The standard LEDE kernel is too big to fit in the original kernel partition.
 +You need to either change the bootloader and flash layout, or decrease the kernel image size by disabling things like debug symbols.
 +
 +
 +==== Backing up the original firmware ====
 +
 +\\
 +**YOU SHOULD DO THIS BEFORE ATTEMPTING TO FLASH** \\
 +At the end of the flash chip there is an "ART" partition that contains calibration data for wifi, you want to have a backup of this. \\
 +You can backup the entire flash over telnet by using dd.
 +
 +<code>dd if=/dev/mtd0 of=/tmp/mtd0.bin</code>
 +
 +**Do this with all the mtd partitions (mtd0 to mtd5)**
 +
 +Then make a symlink to /tmp in /etc/disk so you can download the files via the web interface.
  
  
 +<code> ln -s /tmp /etc/disk </code>
 ==== Flashing ==== ==== Flashing ====
  
Line 126: Line 239:
   - Reflash the firmware from the original firmware using mtd_write (easy but you have to do it right on the first try)   - Reflash the firmware from the original firmware using mtd_write (easy but you have to do it right on the first try)
   - Attach a programmer to the flash chip (impossible to mess up)   - Attach a programmer to the flash chip (impossible to mess up)
 +  - Use the original firmware's update function 
  
  
Line 140: Line 254:
 </code> </code>
  
-Where openwrt.bin is your rootfs+kernel image (in that order!).+Where openwrt.bin is your rootfs+kernel image (in that order! and the kernel must be at the correct offset!), that is **openwrt-ar71xx-generic-zsun-sdreader-squashfs-sysupgrade.bin** if you're using our image. 
 + 
 + 
 +=== Flashing from original firmware (mtd_write) === 
 + 
 +**WARNING** **This method is risky, you have only one chance to get it right.** However if you fail to do so, you still can use above method (unless you completely screw it up by overwriting u-boot, but that's pretty unlikely) 
 + 
 +The method could use some improvement, like a script that does pivotroot... 
 + 
 +There are multiple ways to get files onto zsun rootfs, one of which is TFTP (pretty easy to setup, no need for SD card) 
 +To start TFTP server on your Linux computer you can use dnsmasq, like this: 
 +<code>sudo dnsmasq -p0 --enable-tftp --tftp-root=`pwd` -d --user=`whoami` 
 +# serves files off your current directory, remember to chmod o+r files you'd like to use</code> 
 + 
 +Then download your files onto zsun's /tmp (ramfs is mounted there), just to be safe, and write them with mtd_write. 
 +Keep in mind **you have to flash kernel first**, since rootfs is used by running system. 
 + 
 +**To be extra safe, you can kill all processes that are not telentd and your shell.** 
 +It has been shown that flashing can succeed without this, but you never know. 
 + 
 +<code> 
 +$ socat - TCP4:10.168.168.1:11880 
 +(none) login: root 
 +Password: zsun1188 
 + 
 +[...] 
 + 
 +# cd /tmp 
 +# tftp -g 10.168.168.100 -r openwrt-ar71xx-generic-zsun-sdreader-kernel.bin 
 +# tftp -g 10.168.168.100 -r openwrt-ar71xx-generic-zsun-sdreader-rootfs-squashfs.bin 
 +# cat /proc/mtd 
 +dev:    size   erasesize  name 
 +mtd0: 00010000 00010000 "u-boot" 
 +mtd1: 00010000 00010000 "u-boot-env" 
 +mtd2: 00e90000 00010000 "rootfs" 
 +mtd3: 00130000 00010000 "uImage" 
 +mtd4: 00010000 00010000 "NVRAM" 
 +mtd5: 00010000 00010000 "ART" 
 +# mtd_write write openwrt-ar71xx-generic-zsun-sdreader-kernel.bin /dev/mtd3 
 +Unlocking /dev/mtd3 ... 
 +Writing from openwrt-ar71xx-generic-zsun-sdreader-kernel.bin to /dev/mtd3 ... [w] 
 +# mtd_write write openwrt-ar71xx-generic-zsun-sdreader-rootfs-squashfs.bin /dev/mtd2 
 +Unlocking /dev/mtd2 ... 
 +Writing from openwrt-ar71xx-generic-zsun-sdreader-rootfs-squashfs.bin to /dev/mtd2 ...  [w] 
 +Bus error 
 +</code> 
 + 
 +"//Bus error//" indicates system finished flashing, you can now just power cycle the device and wait for open "//OpenWRT//" network. First boot takes quite some time. 
 + 
 +=== Using the original firmware's update function  === 
 + 
 +Device can be flashed without any special tools even in Windows by copying special update package with SMB/Network Shares and opening two URLs. More information here: 
 +[[projects:zsun-wifi-card-reader:factory-update|Zsun Card Reader Firmware Update Format]] 
 ==== Pictures ==== ==== Pictures ====
  
-{{:projects:zsun_top_annot.jpg?200|}} +{{:projects:zsun_top_annot.jpg?direct&400|}} 
-{{:projects:zsun_top.jpg?200|}} +{{:projects:zsun_top.jpg?direct&400|}} 
-{{:projects:zsun_inside.jpg?200|}} +{{:projects:zsun_inside.jpg?direct&400|}} 
-{{:projects:zsun_bottom.jpg?200|}}+{{:projects:zsun_bottom.jpg?direct&400|}} 
 +{{:projects:2zsuns.jpg?direct&400|}}
projects/zsun-wifi-card-reader.1451668601.txt.gz · Last modified: 2016/01/01 17:16 by emeryth

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki