ZyXEL NSA320

enable telnet
login as admin
http://192.168.2.127/r38571,/adv,/cgi-bin/remote_help-cgi?type=backdoor
telnet 192.168.2.127
root
YOUR_PASS

USB TTL to NSA-320
http://dl.panticz.de/hardware/zyxel_nsa320/nsa320_usb_ttl.jpg

install ssh
wget ftp://ftp.zyxel-tech.de/2.new_mirror/NSA310/4.40/zypkg/web_prefix -O /i-data/d154583a/admin/zy-pkgs/web_prefix
# firmware / package / reload
# install ffp
/i-data/d154583a/admin/zy-pkgs/ffp/ffp.log

#
# NEW
#
# http://forum.doozan.com/file.php?3,file=160,filename=kwboot-tool.tar.gz,download=1
# unbrick
sudo /tmp/kwboot -p -t -B 115200 /dev/ttyUSB0 -b /tmp/uboot.2016.05-tld-1.nsa320.mtd0.kwb

# flash uboot
# http://forum.doozan.com/read.php?3,12381
dhcp
tftpboot 0x800000 nsa320/uboot.2016.05-tld-1.nsa320.mtd0.kwb
nand erase 0x0 0x80000
nand write.e 0x800000 0x0 0x80000
reset

# flash image to nand (optional)
dhcp
tftp 0x00800000 /nsa320/uImage
nand erase 0x00c80000 0x00a00000
nand write 0x00800000 0x00c80000 0x00a00000

tftp 0x01c00000 /nsa320/kirkwood-nsa320.dtb
nand erase 0x01700000 0x00a00000
nand write 0x01c00000 0x01700000 0x00a00000

tftp 0x1100000 /nsa320/uInitrd
nand erase 0x04640000 0x00a00000
nand write 0x1100000 0x04640000 0x00a00000

setenv bootargs 'console=ttyS0,115200 root=LABEL=rootfs rootdelay=3 loglevel=7'
setenv bootcmd 'nand read.e 0x0800000 0x00c80000 0xa00000; nand read.e 0x01c00000 0x01700000 0xa00000; nand read.e 0x1100000 0x04640000 0xa00000; bootm 0x800000 0x1100000 0x1c00000'
saveenv
reset

# boot from USB
setenv load_dtb 'ext4load usb 0:1 0x1c00000 /boot/dts/kirkwood-nsa320.dtb'
setenv load_initrd 'ext4load usb 0:1 0x1100000 /boot/uInitrd'
setenv load_uimage 'ext4load usb 0:1 0x800000 /boot/uImage'

setenv bootargs 'console=ttyS0,115200 root=LABEL=rootfs rootdelay=3 loglevel=7'
setenv bootcmd 'usb start; run load_dtb; run load_uimage; if run load_initrd; then bootm 0x800000 0x1100000 0x1c00000; else bootm 0x800000 - 0x1c00000; fi'

saveenv
reset

# create USB (Debian Jessie)
DEVICE=/dev/sdc
umount ${DEVICE}*
parted ${DEVICE} -s rm 1
parted ${DEVICE} -s mklabel msdos
parted ${DEVICE} -s mkpart primary ext4 0% 99%
parted ${DEVICE} -s mkpart primary linux-swap 99% 100%
mkfs.ext4 ${DEVICE}1 -F -L rootfs
mkswap ${DEVICE}2

wget https://www.dropbox.com/s/qt2v378sm3j0loe/Debian-4.4.0-kirkwood-tld-1-rootfs-bodhi.tar.bz2 -P /tmp

mount /dev/sdc1 /mnt
tar xjf /tmp/Debian-4.4.0-kirkwood-tld-1-rootfs-bodhi.tar.bz2 -C /mnt/
sync
umount /dev/sdc1

root@debian:~# uname -a
Linux debian 4.6.0-kirkwood-tld-1 #1 PREEMPT Wed May 18 03:54:14 PDT 2016 armv5tel GNU/Linux

#
# OLD
#

#
# flash new uboot
#
# http://forum.doozan.com/read.php?2,7806
# on tftp server
wget http://dl.dropbox.com/u/1015928/Kirkwood/rootfs_images/NSA320quickstart.tar.gz -O /tmp/NSA320quickstart.tar.gz
tar -C /tmp -xzf /tmp/NSA320quickstart.tar.gz NSA320quickstart/uboot.NAND-NSA320-IDEfixedv4-scripted.kwb.tar.gz
tar -C /tmp -xzf /tmp/NSA320quickstart/uboot.NAND-NSA320-IDEfixedv4-scripted.kwb.tar.gz
cp /tmp/uboot.NAND-NSA320-IDEfixedv4-scripted.kwb /var/lib/tftpboot/

# flash
dhcp
tftpboot 0x800000 uboot.NAND-NSA320-IDEfixedv4-scripted.kwb
nand erase 0x0 0x80000
nand write.e 0x800000 0x0 0x80000
reset

# set netconsole
setenv serverip 192.168.2.155 # set to your desktop ip
setenv ipaddr 192.168.2.1
saveenv

# start netconsole on your desktop
nc -l -u -p 6666

sudo /tmp/kwboot -p -t -B 115200 /dev/ttyUSB0 -b /tmp/uboot.NAND-NSA320-IDEfixedv4-scripted.kwb
sudo /home/pako/develop/nsa320/kwboot -p -t -B 115200 /dev/ttyUSB0 -b /tmp/NSA320quickstart/uboot.NAND-NSA320-IDEfixedv4-scripted.kwb

#
# install debian
#
on TFTP Server
# get uImage from Arch Linux (no nfs server support?)
mkdir /var/lib/tftpboot/nsa320
#wget -q http://us.mirror.archlinuxarm.org/os/ArchLinuxARM-armv5te-latest.tar.gz -O - | tar -C /tmp/ -xz ./boot/uImage
#mv /tmp/boot/uImage /var/lib/tftpboot/nsa320/
#rm -r /tmp/boot/

# get initrd.gz
# dep # wget http://www.scintilla.utwente.nl/~petero/nsa310/initrd.gz -O /var/lib/tftpboot/nsa320/initrd.gz
wget -q ftp://ftp.debian.org/debian/dists/stable/main/installer-armel/current/images/kirkwood/netboot/marvell/sheevaplug/uInitrd -O /var/lib/tftpboot/nsa320/initrd.gz

on ZyXEL NSA320 (serial)
setenv mainlineLinux yes
setenv arcNumber 3956
saveenv
reset

dhcp
tftpboot 0x800000 /nsa320/uImage
tftpboot 0xb00000 /nsa320/initrd.gz
setenv bootargs 'console=ttyS0,115200n8'
bootm 0x00800000 0xb00000

flash uImage to nand
dhcp
tftp 0x800000 /nsa320/uImage
nand erase 0x4640000 0x300000
nand write.e 0x800000 0x4640000 0x300000
# boot from second device (USB pen)
setenv bootargs 'console=ttyS0,115200 root=/dev/sdb1 rootdelay=10 loglevel=7'
setenv bootcmd 'nand read.e 0x2000000 0x04640000 0x400000; bootm 0x2000000'
saveenv
reset

v2, get kernel and initrd from doozan.com
http://forum.doozan.com/read.php?2,12096,12180

umount /dev/sdb1
dd if=/dev/zero of=/dev/sdb bs=1M count=1
fdisk /dev/sdb
mkfs.ext3 -L rootfs /dev/sdb1
mount /dev/sdb1 /mnt
wget "http://dl.dropboxusercontent.com/s/818tlrq9seb2rgy/Debian-3.12.0-kirkwood-tld-3-rootfs-bodhi.tar.bz2?dl=1&token_hash=AAENHmNkqRuE1nujL4M3mgjP6E-HD3qykyDp9rLCNaSa6A" -O - | tar -C /tmp/ -xj ./boot/uInitrd ./boot/uImage
cp /tmp/boot/uImage /tmp/boot/uInitrd /var/lib/tftpboot/nsa320/

#tar -C /mnt/ -xjf /tmp/Debian-3.12.0-kirkwood-tld-3-rootfs-bodhi.tar.bz2
#sync
#umount /mnt

tftp 0x800000 /nsa320/uImage
nand erase 0x00C80000 0xa00000
nand write 0x800000 0x00C80000 0xa00000

tftp 0xb00000 /nsa320/uInitrd
nand erase 0x04640000 0xa00000
nand write 0xb00000 0x04640000 0xa00000

#setenv bootargs 'console=ttyS0,115200n8 root=/dev/sda1 rootdelay=10 loglevel=7'
#setenv bootargs 'console=ttyS0,115200n8 root=UUID=9080a964-97f8-497a-82ab-d1aae62310fe rootdelay=10 loglevel=7'
setenv bootargs 'console=ttyS0,115200 root=LABEL=rootfs rootdelay=10 loglevel=7'
setenv bootcmd 'nand read.e 0x800000 0x00C80000 0xa00000; nand read.e 0xb00000 0x04640000 0xa00000; bootm 0x800000 0xb00000'
saveenv
reset

HDD LEDs
# add to /etc/rc.local
http://dl.panticz.de/hardware/zyxel_nsa320/leds

Wake On Lan
# set original mac address in u-boot
setenv ethaddr XX:XX:XX:XX:XX:XX
saveenv

# enable wol under linux?
ethtool -s eth0 wol g

# wol from other machine
wakeonlan -i 192.168.2.255 ec:43:f6:be:6e:3b

Install kernel modules (in running nsa320 linux system)
wget http://dl.dropboxusercontent.com/s/818tlrq9seb2rgy/Debian-3.12.0-kirkwood-tld-3-rootfs-bodhi.tar.bz2 -O /tmp/Debian-3.12.0-kirkwood-tld-3-rootfs-bodhi.tar.bz2
tar -C /tmp -xjf /tmp/Debian-3.12.0-kirkwood-tld-3-rootfs-bodhi.tar.bz2
cp -a /tmp/lib/modules/ /lib/

Auto power on after power failure
# power on on power fail
http://forum.doozan.com/read.php?2,12096,13404#msg-13404
/bin/echo 47 > /sys/class/gpio/export
/bin/echo 49 > /sys/class/gpio/export
# 49 out, value 1
/bin/echo "out" > /sys/class/gpio/gpio49/direction
/bin/echo 1 > /sys/class/gpio/gpio49/value
# 47 out, value 1
/bin/echo "out" > /sys/class/gpio/gpio47/direction
# next line 0 to disable, 1 to enable resume from power loss (powers the PHY also!!)
/bin/echo 1 > /sys/class/gpio/gpio47/value
# set 49 value 0
/bin/echo 0 > /sys/class/gpio/gpio49/value

Install sensors
apt-get install lm-sensors

Install S.M.A.R.T.
wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/installit/master/install.smartmontools.sh -O - | bash -

Links
http://forum.nas-central.org/viewtopic.php?f=249&t=3939
http://archlinuxarm.org/platforms/armv5/zyxel-nsa320
http://linuxwiki.de/ZYXEL%20NSA-310/
https://github.com/peeter123/NSA310-320-debian
http://forum.doozan.com/read.php?2,12096
http://blog.julianxhokaxhiu.com/entry/install-debian-wheezy-zyxel-nsa320

# recovery
wget ftp://ftp.zyxel.it/guide/nas/nsa320_recovery_usb.zip -O /tmp/nsa320_recovery_usb.zip
cd /tmp
unzip nsa320_recovery_usb.zip

bin2ram little /tmp/nsa310_fw/ras.bin /tmp/tlv.bin;

 && echo OK
 
mkdir /tmp/nsa320fw 
fw_unpack -C /tmp/nsa320fw -i /tmp/tlv.bin; [ $? == 0 ] && echo OK
 
tar cjf nsa320_fw.tar.bz2 /tmp/nsa320fw/
 
# create raid
for DEV in /dev/sd{a..b}; do
    parted ${DEV} -s mklabel msdos
    parted ${DEV} -s mkpart primary 2048s 100%
    parted ${DEV} -s set 1 raid on
#    mdadm --zero-superblock ${DEV}1
done
 
 
ftp://ftp.zyxel.it/guide/nas/
http://downloads.zyxel.nas-central.org/Users/Mijzelf/
http://www.zyxelforum.de/nsa-320-325-boot-probleme-oder-im-netzwerk-nicht-gefunden%C7%83-t4310.html