Friday, April 10, 2015

OpenWRT on Pogoplug v3/Oxnas (Pro/Classic)

This tutorial assumes you have completed my previous tutorial - Hacking the Pogoplug v3/Oxnas (Pro/Classic) with Debian
- and already running Debian from a USB drive on the Pogoplug V3.

OpenWRT will be installed on the internal flash (NAND) of the Pogoplug. You will still be able to boot Debian from USB when attached.

Known Issues:

 - RT3090 (PCIE) Wi-Fi in the Pro is not working. 
All commands below needs to be executed from Debian.

#Verify MTD partition
cat /proc/mtd
#root@debian:~# cat /proc/mtd
#dev: size erasesize name
#mtd0: 00e00000 00020000 "boot"
#mtd1: 07200000 00020000 "data"

#download firmware/nand utilities
cd /tmp
wget http://download.qnology.com/pogoplug/v4/fw_printenv
wget http://download.qnology.com/pogoplug/v4/fw_setenv
wget http://download.qnology.com/pogoplug/v4/ubiattach
wget http://download.qnology.com/pogoplug/v4/ubimkvol
wget http://download.qnology.com/pogoplug/v4/ubiformat

#make executable
chmod +x fw_printenv fw_setenv ubiattach ubimkvol ubiformat

#format mtd1 (data)
/tmp/ubiformat /dev/mtd1

#attach
/tmp/ubiattach /dev/ubi_ctrl -m 1
/tmp/ubimkvol /dev/ubi0 -m -N rootfs

#mount ubi rootfs to /tmp/ubi
mkdir /tmp/ubi
mount -t ubifs ubi0:rootfs /tmp/ubi

#We're using the snapshot trunk release.

#There is no rootfs tarball, so we'll extract 
#it from the squashfs sysupgrade tar
cd /tmp
wget http://downloads.openwrt.org/snapshots/trunk/oxnas/generic/openwrt-oxnas-pogoplug-pro-squashfs-sysupgrade.tar

#extract
tar -xvf openwrt-oxnas-pogoplug-pro-squashfs-sysupgrade.tar

#unsquashfs
apt-get install squashfs-tools
unsquashfs sysupgrade-pogoplug-pro/root


#move extracted rootfs to ubi
mv squashfs-root/* /tmp/ubi

#download kernel zImage
mkdir -p /tmp/ubi/boot
cd /tmp/ubi/boot
wget http://downloads.openwrt.org/snapshots/trunk/oxnas/generic/openwrt-oxnas-zImage

#rename zImage file
mv openwrt-oxnas-zImage zImage


#download fdt
wget http://downloads.openwrt.org/snapshots/trunk/oxnas/generic/openwrt-oxnas-pogoplug-pro.dtb
wget http://download.qnology.com/pogoplug/oxnas/ox820-pogoplug-classic.dtb


sync
cd /
umount /tmp/ubi

#Setup uBoot Environment
#Cut and Paste this whole section
/tmp/fw_setenv zimage '/boot/zImage'
/tmp/fw_setenv loadaddr '0x60500000'
/tmp/fw_setenv fdt_addr '0x62c00000'
/tmp/fw_setenv loadubi 'echo Trying to boot from NAND ...;if run mountubi; then run loadubizimage;run loadubifdt;ubifsumount;run bootzubi;fi'
/tmp/fw_setenv mountubi 'ubi part data; ubifsmount ubi0:rootfs'
/tmp/fw_setenv loadubizimage 'ubifsload ${loadaddr} ${zimage}'
/tmp/fw_setenv loadubifdt 'ubifsload ${fdt_addr} ${fdt_file_ubi}'
/tmp/fw_setenv bootzubi 'echo Booting from nand ...; run setargsubi; bootz ${loadaddr} - ${fdt_addr};'
/tmp/fw_setenv setargsubi 'setenv bootargs console=ttyS0,115200n8 ubi.mtd=1 root=ubi0:rootfs rw rootfstype=ubifs rootwait ${mtdparts}'

#Select the appropriate fdt - Pro (Wi-Fi) versus regular.

#Pogoplug Pro
/tmp/fw_setenv fdt_file_ubi '/boot/openwrt-oxnas-pogoplug-pro.dtb'

#Non-Pro (use this if unsure)
/tmp/fw_setenv fdt_file_ubi '/boot/ox820-pogoplug-classic.dtb'

#S
etup boot order.
#USB first, then UBI/NAND
/tmp/fw_setenv dt_bootcmd_usb 'usb start; run dt_usb_bootcmd; usb stop'

/tmp/fw_setenv bootcmd 'run dt_bootcmd_usb; run loadubi; reset'

#poweroff Pogoplug and then remove USB flash drive.
poweroff

OpenWRT Initial Boot via Telnet

At this point, we're ready to boot into OpenWRT. During the bootup process the LED on the Pogoplug will blink. However once it successfully boots into OpenWRT the LED will be completely off.

Note that by default, OpenWRT will default to 192.168.1.1 and will (or should) act as a DHCP Server.  Plug a network cable from your computer directly into the Pogoplug and power it on (do not plug the Pogoplug into your router). You should now be able to Telnet into the Pogoplug at 192.168.1.1 (username and password not required). If you're not able to telnet into the Pogoplug try setting a static IP address of 192.168.1.2 on your computer.

Note that SSH is disabled and will automatically start after a root password is set.

#set passwd and enable ssh
passwd

#Reconfigure Network to DHCP Client
#disable dhcp server on lan
#Ignore if any error.
uci set dhcp.lan.ignore=1
uci commit dhcp
/etc/init.d/dnsmasq restart

#set wired ethernet interface to dhcp client
uci set network.lan.proto=dhcp
uci commit network

#reboot
reboot

OpenWRT SSH and Initial Package Installation

Plug the Pogoplug and your computer back into your network/router. Check your router for the IP Address assigned to your Pogoplug. You should now be able to SSH into the Pogoplug.

Note that since we're using the daily snapshot trunk build of OpenWRT, you'll need to install your kernel packages right away (kmod-xxx), otherwise it will get out of sync.

opkg update

#Pogoplug has 128MB flash
#No need to be stingy on the packages
opkg install nano wget luci uboot-envtools pciutils usbutils htop wireless-tools kmod-rt2x00-pci kmod-usb-storage block-mount kmod-fs-ext4 kmod-fs-vfat kmod-fs-ntfs kmod-nls-cp437 kmod-nls-iso8859-1 e2fsprogs fdisk kmod-usb2 samba36-server samba36-client luci-app-samba kmod-rtl8187 wireless-tools kmod-usb-net-asix-ax88179 kmod-rt2800-lib kmod-rt2800-usb kmod-rt2x00-lib kmod-rt2x00-usb kmod-usb-serial-pl2303  kmod-usb-serial-cp210x  kmod-usb-serial-ftdi picocom screen

#Assume you're using the USB RT5370 Wi-Fi below 
#Regenerate Wi-Fi configuration
#Verify if Wi-Fi is working properly
rm -f /etc/config/wireless 
wifi detect > /etc/config/wireless

#If wireless is working properly, you should see something
cat /etc/config/wireless

#Enable Wi-Fi
sed -i 's^option disabled 1^option disabled 0^' /etc/config/wireless
/etc/init.d/network restart

Note that the built in Wi-Fi (PCIE) on the Pogoplug Pro is not working.

If you need wireless, I would highly recommend a USB Wi-Fi card based on the RT5730 chipset for less than $8.

Mini Wireless 150Mbs USB Ralink RT5370 (or from Ebay)

Tuesday, April 7, 2015

Hacking the Pogoplug v3/Oxnas (Pro/Classic) with Debian

This is quick publish tutorial on installing Debian on the Pogoplug V3(Oxnas)

All credit to @bodhi on Jeff Doozan's Forum for the uBoot, Debian rootfs, instructions and support. Note that I re-hosted some of @bodhi's files for an easier install.


References:


WARNING: You can potentially brick your Pogoplug following this tutorial. Your warranty will be voided. These instructions are for the Pogoplug V3/Oxnas. Flashing the uBoot below on any other model of the Pogoplug will result in a brick. There is no going back to the Pogoplug OS. You will not be able to use the my.pogoplug.com service. Proceed at your own risk.



Requirements:


1) Pogoplug V3 - Dual 700Mhz ARM, 128MB RAM, SATA (internal), Gigabit Ethernet, 4 USB 2.0 Ports, Wireless*

*Only Pogoplug Pro comes with built in Wi-Fi (AzureWave AW-NE762H 802.11 b/g/n PCI Express RT3090)

Model numbers located on bottom of foot. Please ignore the label on the box. You can potential receive a Pogoplug V2 (POGO-E02 Kirkwood) when buying a P21/P22.




Check the bottom of the Pogoplug's foot for correct model


2) USB Flash Drive (2GB+) or USB Hard Drive


Recommendations/Tested:



Outline of Steps:

  • uBoot Installation via SSH Console
  • Setup Netconsole
  • Debian Installation on USB Hard/Flash Drive
  • Initial Debian Setup
  • Upgrade Debian to 3.18.5 kernel
  • Pogoplug Pro Wireless Configuration



Enable SSH Access to Pogoplug


There are two methods to enable SSH on your Pogoplug.

1) Official Method - Activate on my.pogoplug.com and then enable SSH

2) Backdoor Method (credit to GTVHacker.com)

Make sure your Pogoplug is connected to your network and has internet access.

Check your router or use a network scanning tool (iNet Network Scanner on iPhone) to determine the IP Address of the Pogoplug.

From a Linux computer (e.g. another Pogoplug running Debian/Alarm) run the below curl command.

curl -k "https://root:ceadmin@[PogoplugIPAddress]/sqdiag/HBPlug?action=command&command=dropbear%20start";

Note that the backdoor method is not persistent (SSH access will not be available after a reboot).

uBoot Installation via SSH Console


Use Putty or your favorite SSH client to connect to your Pogoplug.

If you used the "Official Method" for activating and enabling SSH on your Pogoplug, then the username will be "root" and the password will be whatever you set (note that it's not the same password used to log into my.pogoplug.com).
For the "Backdoor Method", the username and password is root/ceadmin.

From here, everything is done via the SSH console.


#Verify Pogoplug is expected version (Oxnas)
cat /proc/cpuinfo | grep Hardware

#Stop here if not expected output.
#Expected output
#Hardware : Oxsemi NAS

#stop my.pogoplug.com service
killall hbwd


#download firmware utilities
cd /tmp
wget http://download.qnology.com/pogoplug/v4/nanddump
wget http://download.qnology.com/pogoplug/v4/nandwrite
wget http://download.qnology.com/pogoplug/v4/flash_erase
wget http://download.qnology.com/pogoplug/v4/fw_printenv
wget http://download.qnology.com/pogoplug/v4/fw_setenv


#make executable
chmod +x flash_erase fw_printenv fw_setenv nanddump nandwrite


#remount '/' as read/write
#by default the Pogoplug OS (internal flash) is read only
mount -o remount,rw /


#setup fw_env.config for oxnas
echo "/dev/mtd0 0x00100000 0x20000 0x20000">/etc/fw_env.config


#save original envs
/usr/local/cloudengines/bin/blparam > /blparam.txt


#Download and flash new uBoot
wget http://download.qnology.com/pogoplug/oxnas/uboot.2013.10-tld-4.ox820.bodhi.tar
wget http://download.qnology.com/pogoplug/oxnas/uboot.2013.10-tld-4.ox820.bodhi.tar.md5


#check md5sum
md5sum -c uboot.2013.10-tld-4.ox820.bodhi.tar.md5


#extract uBoot files
tar -xf uboot.2013.10-tld-4.ox820.bodhi.tar

#BE EXTRA CAREFUL WITH THE THESE COMMANDS.
#NO TYPOS! CUT AND PASTE.
#Erase and flash uboot on mtd0
#Flash encoded spl stage1 to 0x0
/tmp/flash_erase /dev/mtd0 0x0 6
/tmp/nandwrite /dev/mtd0 uboot.spl.2013.10.ox820.850mhz.mtd0.img


#Flash uboot to 0x40000
/tmp/nandwrite -s 262144 /dev/mtd0 uboot.2013.10-tld-4.ox820.mtd0.img

#Flash uboot environment
#Erase 1 block starting 0x00100000
/tmp/flash_erase /dev/mtd0 0x00100000 1
/tmp/nandwrite -s 1048576 /dev/mtd0 pogopro_uboot_env.img


#Set MAC Address
/tmp/fw_setenv ethaddr "$(cat /sys/class/net/eth0/address)"


#default to pogoplug classic dtb
/tmp/fw_setenv fdt_file '/boot/dts/ox820-pogoplug-classic.dtb'
/tmp/fw_setenv dt_load_dtb 'ext2load usb 0:1 $dtb_addr $fdt_file'

#double check the MAC Address matches with
#what is on the bottom of your Pogoplug
/tmp/fw_printenv ethaddr

#print out all uboot environment parameters
#make sure there are no errors
/tmp/fw_printenv > /fw_printenv.txt
/tmp/fw_printenv



Setup Netconsole

More info here - http://forum.doozan.com/read.php?3,14,14


#Update IP Addresses as appropriate
#ipaddr = Pogoplug IP
/tmp/fw_setenv preboot 'run preboot_nc'
/tmp/fw_setenv ipaddr '192.168.1.10'
/tmp/fw_setenv serverip '192.168.1.100'



Debian Installation on USB Hard/Flash Drive


Plug in your USB flash drive

#Partition your USB flash/hard drive
/sbin/fdisk /dev/sda

# Type in the following commands to erase
# and re-partition USB flash/hard drive
#(WARNING - FLASH/HARD DRIVE WILL BE COMPLETELY WIPED):
#
# p # list current partitions
# o # to delete all partitions
# n # new partition
# p # primary partition
# 1 (one) # first partition
# <enter> # default start block
# <enter> # default end block (to use the whole drive)
# If you're using a hard drive, create a small
# 4GB partition instead of using the whole drive,
# leaving the rest for a data partition
# +4G # to create a 4GB partition
# w # write new partition to disk


#Format USB Flash Drive
cd /tmp
wget http://archlinuxarm.org/os/pogoplug/mke2fs
chmod 755 mke2fs

#format as ext3 and label partition as 'rootfs'
./mke2fs -L rootfs -j /dev/sda1

#mount
mkdir /tmp/usb
mount /dev/sda1 /tmp/usb
cd /tmp/usb

#Download Debian rootfs
wget http://download.qnology.com/pogoplug/oxnas/Debian-3.17.0-oxnas-tld-1-rootfs-bodhi.tar.bz2
wget http://download.qnology.com/pogoplug/oxnas/Debian-3.17.0-oxnas-tld-1-rootfs-bodhi.tar.bz2.md5

#check md5sum
md5sum -c Debian-3.17.0-oxnas-tld-1-rootfs-bodhi.tar.bz2.md5

#extract
tar -xvjf Debian-3.17.0-oxnas-tld-1-rootfs-bodhi.tar.bz2

#cleanup
rm Debian-3.17.0-oxnas-tld-1-rootfs-bodhi.tar.bz2*

#Sync and reboot, cross your fingers
sync
cd ..
umount /tmp/usb
reboot


At this point, your Pogoplug should boot back up into Debian. Note that the IP Address of your Pogoplug may have changed. Double check your router for the IP Address assigned to your Pogoplug or use a network scanning tool (iNet Network Scanner on iPhone) to determine the IP Address of the Pogoplug.

For Debian, the default username and password is root/root.

Initial Debian Setup


#Change password
passwd

#Generate New OpenSSH Keys
rm /etc/ssh/ssh_host*
ssh-keygen -A

#Initial update
apt-get update
apt-get upgrade

#Set hostname to DebianPlug or whatever you like
echo DebianPlug>/etc/hostname

#Set Time Zone
tzselect

reboot


Upgrade Debian to 3.18.5 kernel


Latest kernel and instructions here - http://forum.doozan.com/read.php?2,16044


#backup original kernel files
cd /boot
mkdir backup
mv *3.17* backup
mv uImage backup/uImage3.17
mv uInitrd backup/uInitrd3.17

#download from bodhi's dropbox
wget --no-check-certificate https://www.dropbox.com/s/o9fp0xg8b6aajg6/linux-3.18.5-oxnas-tld-1.bodhi.tar.bz2

#check md5
echo "df386f09cf7323472d40432d3da382d5 linux-3.18.5-oxnas-tld-1.bodhi.tar.bz2" |md5sum -c

#extract
tar -xvjf linux-3.18.5-oxnas-tld-1.bodhi.tar.bz2

#install kernel and headers
dpkg -i linux-image-3.18.5-oxnas-tld-1_1_armel.deb
dpkg -i linux-headers-3.18.5-oxnas-tld-1_1_armel.deb

#Create uImage and uInitrd manually
mkimage -A arm -O linux -T kernel -C none -a 0x60008000 -e 0x60008000 -n Linux-3.18.5-oxnas-tld-1 -d /boot/vmlinuz-3.18.5-oxnas-tld-1 /boot/uImage

mkimage -A arm -O linux -T ramdisk -C gzip -a 0x60000000 -e 0x60000000 -n initramfs-3.18.5-oxnas-tld-1 -d /boot/initrd.img-3.18.5-oxnas-tld-1 /boot/uInitrd


#clean up
rm linux-3.18.5-oxnas-tld-1.bodhi.tar.bz2
rm *.dtb

#reboot and verify
reboot

uname -a


Pogoplug Pro Wireless Configuration


#update fdt file to pogoplug pro and reboot
#Warning: if you don't truly have a pro, your pogoplug
#will not boot properly.

fw_setenv fdt_file '/boot/dts/ox820-pogoplug-pro.dtb'
reboot


Follow Debian on Pogoplug Tutorial - Wireless Configuration


Pogoplug Pro - AzureWave AW-NE762H 802.11 b/g/n PCI Express RT3090

Pogoplug V3 - Dual 700Mhz ARM, 128MB RAM, SATA (internal),
Gigabit Ethernet, 4 USB 2.0 Ports, Wireless (Pro only)