Wednesday, February 11, 2015

OpenWRT on Pogoplug Mobile

Booting OpenWRT from internal flash on Pogoplug Mobile

In this tutorial we're replacing the original Pogoplug OS on the internal flash with OpenWRT. OpenWRT is a lightweight but feature rich Linux distribution for embedded devices. 


The Pogoplug is arguably one of the best OpenWRT platform for the price and performance. You can use OpenWRT on the Pogoplug as your main Linux distro skipping the need for a USB flash drive or SD Card, or just use it as a Rescue System (for fixing corrupt disk or reinstallation) if something goes wrong with your ALARM or Debian installation.


This tutorial assumes you have completed my previous tutorial - Hacking the Pogoplug v4 (Series 4 and Mobile) with Linux (Debian or Arch) - and already running Debian or ArchLinuxARM (from a USB drive or SD Card) on the Pogoplug Mobile.


Note that for the Series 4, the USB3 ports does not work properly yet with OpenWRT. Hopefully this will get resolved in the near future. [Edit] - Looks like the USB3 ports work with USB3 devices and if you plug in a USB3 device, the other USB3 port will work with a USB2 device.


WARNING: There is no going back to the Pogoplug OS. You will not be able to use the my.pogoplug.com service. Please proceed at your own risk.


LETS GET STARTED:

Boot up Debian or ArchLinuxARM on your Pogoplug. All commands below assumes you're running Debian or ALARM.

#Update mtdparts so we have one continuous partition to work with.
cd /tmp
wget http://download.qnology.com/pogoplug/v4/fw_setenv
chmod +x fw_setenv

#setup fw_env.config
echo "/dev/mtd0 0xc0000 0x20000 0x20000">/etc/fw_env.config

#1MB for the uBoot, the rest for rootfs (~122MB)
/tmp/fw_setenv mtdparts 'mtdparts=orion_nand:1M(u-boot),-(rootfs)'



#This reboot is important
reboot

After rebooting double check the mtdpart is correct.

cat /proc/mtd

#root@debian:~# cat /proc/mtd
#dev: size erasesize name
#mtd0: 00100000 00020000 "u-boot"
#mtd1: 07f00000 00020000 "rootfs"
#mtd2: 00010000 00008000 "spi0.0"


#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 (rootfs)
#Will be prompted for confirmation three times.
/tmp/ubiformat /dev/mtd1

/tmp/ubiattach -p /dev/mtd1
/tmp/ubimkvol /dev/ubi0 -m -N rootfs

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

#Chaos Calmer 15.05
cd /tmp
wget http://downloads.openwrt.org/chaos_calmer/15.05/kirkwood/generic/openwrt-15.05-kirkwood-generic-rootfs.tar.gz
wget http://downloads.openwrt.org/chaos_calmer/15.05/kirkwood/generic/openwrt-15.05-kirkwood-zImage   
wget http://downloads.openwrt.org/chaos_calmer/15.05/kirkwood/generic/md5sums

#Trunk release.
#Note that Barrier Breaker 14.07 doesn't work.
#cd /tmp
#wget http://downloads.openwrt.org/snapshots/trunk/kirkwood/generic/openwrt-kirkwood-generic-rootfs.tar.gz
#wget http://downloads.openwrt.org/snapshots/trunk/kirkwood/generic/openwrt-kirkwood-zImage
#wget http://downloads.openwrt.org/snapshots/trunk/kirkwood/generic/md5sums


#check that zImage and rootfs.tar.gz are OK
md5sum -c md5sums

#extract rootfs.tar.gz to ubi rootfs at 
/tmp/ubi
cd /tmp/ubi
tar xvzf /tmp/openwrt*rootfs.tar.gz

mkdir boot
mv /tmp/openwrt*kirkwood-zImage ./boot/zImage

#FDT from http://forum.doozan.com/read.php?2,12096
cd boot

wget http://download.qnology.com/pogoplug/v4/kirkwood-pogoplug_v4.dtb

sync
cd /

umount /tmp/ubi


#Setup uBoot Environment

#Cut and Paste this whole section
/tmp/fw_setenv fdt_file '/boot/kirkwood-pogoplug_v4.dtb'
/tmp/fw_setenv loadaddr '0x800000'
/tmp/fw_setenv zimage '/boot/zImage'
/tmp/fw_setenv fdt_addr '0x1c00000'
/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 rootfs; ubifsmount ubi0:rootfs'
/tmp/fw_setenv loadubizimage 'ubifsload ${loadaddr} ${zimage}'
/tmp/fw_setenv loadubifdt 'ubifsload ${fdt_addr} ${fdt_file}'
/tmp/fw_setenv bootzubi 'echo Booting from nand ...; run setargsubi; bootz ${loadaddr} - ${fdt_addr};'
/tmp/fw_setenv setargsubi 'setenv bootargs console=${console},${baudrate} ${optargs} ubi.mtd=1 root=ubi0:rootfs rw rootfstype=ubifs rootwait ${mtdparts}'

#Setup boot order.
#USB->SD->SATA->UBI/NAND
/tmp/fw_setenv bootcmd 'run bootcmd_usb; run bootcmd_mmc; run bootcmd_sata; run loadubi; reset'

#poweroff Pogoplug and remove SD Card and USB flash drive.
poweroff

At this point, we're ready to boot into OpenWRT. Note that by default, OpenWRT will default to 192.168.1.1 and will act as a DHCP Server. Plug a network cable from your computer directly into the Pogoplug and power it on. You should now be able to Telnet into the Pogoplug at 192.168.1.1 (username and password not required). Note that SSH is disabled and will automatically start after a root password is set.

#####Initial Boot via Telnet######
#set passwd and enable ssh
passwd

#Reconfigure Network to DHCP Client

#disable dhcp server on lan
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


Plug the Pogoplug and your computer back into your network. 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.



#####Initial OpenWRT configuration#####
opkg update

#Install some essential packages
opkg install nano wget luci uboot-envtools pciutils usbutils 
kmod-usb2 kmod-usb3 kmod-mmc kmod-usb-storage block-mount kmod-fs-ext4 kmod-fs-vfat kmod-fs-ntfs kmod-nls-cp437 kmod-nls-iso8859-1 e2fsprogs fdisk 

#SAMBA - configure via luci web gui
opkg install samba36-server samba36-client luci-app-samba



Major credit goes to @moonman on the ArchLinuxArm Forum - http://archlinuxarm.org/forum/viewtopic.php?f=30&t=8383