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.

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
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)



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

#We're using the snapshot trunk release.
#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-kirkwood-generic-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

Wednesday, November 26, 2014

Debian on Pogoplug Tutorial - Webmin Installation

This is a continuation of my Hacking the Pogoplug v4 (Series 4 and Mobile) with Linux (Debian or Arch) Tutorial.




Webmin Installation


#Install required packages
apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python

#downloand and install webmin
cd /tmp
wget http://prdownloads.sourceforge.net/webadmin/webmin_1.720_all.deb
dpkg --install webmin_1.720_all.deb


#Webmin will automatically start on boot up.
#To stop Webmin from starting at bootup
update-rc.d -f webmin remove

#Auto Start Webmin on Boot
update-rc.d webmin defaults



Access Webmin @ https://IPAddress:10000

Reference: http://www.webmin.com/deb.html

Debian on Pogoplug Tutorial - MJPG-Streamer (WebCam) Installation

This is a continuation of my Hacking the Pogoplug v4 (Series 4 and Mobile) with Linux (Debian or Arch) Tutorial.



Tested WebCams:
MJPG-Streamer Installation

#Install required packages
apt-get install unzip subversion libv4l-dev libjpeg8-dev imagemagick build-essential psmisc

#build mjpg-streamer
mkdir /tmpbuild
cd /tmpbuild
wget http://sourceforge.net/code-snapshots/svn/m/mj/mjpg-streamer/code/mjpg-streamer-code-182.zip
unzip mjpg-streamer-code-182.zip
cd mjpg-streamer-code-182/mjpg-streamer
make
make install
cd /
rm -rf /tmpbuild

#Test - start mjpg_streamer on port 8088
#http://ipaddress:8088
mjpg_streamer -i "/usr/local/lib/input_uvc.so -f 15 -r 640x480 -d /dev/video0" -o "/usr/local/lib/output_http.so -w /usr/local/www -p 8088"

#Download service file for auto start on bootup
cd /etc/init.d
wget --no-check-certificate https://dl.dropboxusercontent.com/u/42238/pogoplug/debian/mjpg_streamerd
chmod +x mjpg_streamerd
update-rc.d mjpg_streamerd defaults


Motion (webcam security software) installation and configuration to come in another tutorial

Debian on Pogoplug Tutorial - Wireless Configuration

This is a continuation of my Hacking the Pogoplug v4 (Series 4 and Mobile) with Linux (Debian or Arch) Tutorial.



Tested Wi-Fi Adapters:

Wi-Fi Configuration for Debian on Pogoplug


#Add "non-free" repo
echo "deb http://http.debian.net/debian/ wheezy main contrib non-free">>/etc/apt/sources.list


#Update repo
apt-get update

#Install required Wi-Fi packages and common non-free Wi-Fi adapter firmware
apt-get install wireless-tools wpasupplicant usbutils firmware-ralink firmware-realtek firmware-atheros

#Bring up Wi-Fi adapter. If you get an error, try rebooting.
ifconfig wlan0 up

#Scan available Wi-Fi networks
iwlist wlan0 scanning

#Update interfaces file with Wi-Fi configuration
nano /etc/network/interfaces

#Add the following to the end of the /etc/network/interfaces file
#Update "YourWiFiNetworkName" and "YourWiFiPassword" with appropriate values.


#/etc/network/interfaces
#auto wlan0
#iface wlan0 inet dhcp
#   wpa-ssid "YourWiFiNetworkName"
#   wpa-psk "YourWiFiPassword"



#Restart Networking Service
/etc/init.d/networking restart

#Check if Wi-Fi configuration successful
#Note the IP Address assigned to wlan0
ifconfig

At this point, you should be able to reboot and unplug the Ethernet network cable from the Pogoplug.

Notes: I don't use wireless with my Pogoplugs so have not tested Wi-Fi extensively. If you don't have a stable Wi-Fi connection, you may want to look into a Wi-Fi auto reconnect script. If I find a good script or method for Wi-Fi auto reconnect, I'll post it. If you have a good solution, please share via the comments.

If you lose Wi-Fi connection, plugging in the Ethernet network cable should work, but note that it may take 2-3 minutes for the Pogoplug to pick up a IP Address.

Reference: https://wiki.debian.org/rtl819x#Debian_7_.22Wheezy.22

Sunday, July 27, 2014

Hacking the Pogoplug v4 (Series 4 and Mobile) with Linux (Debian or Arch)

This is a quick publish tutorial on hacking the Pogoplug V4 - Series 4 or Mobile - with Debian or Arch Linux ARM. Last updated 02/11/2015.

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

This tutorial assumes you're starting with a brand new, never modified Pogoplug Mobile or Series 4. However, if you have a previously modified Pogoplug V4, the uBoot instructions will work under Debian/ALARM if you want to upgrade your uBoot for SD Card booting and want to boot the default Pogoplug OS.

At the end of this tutorial your Pogoplug will be booting Debian (or ALARM) from a SD Card. Instructions for booting off a USB Hard/Flash Drive is also included.

My recommendation is to boot via SD Card to keep the USB port free for a USB Hard Drive, USB DAC (for MPD, Airplay and/or SqueezeLite), WebCam, Wi-Fi Adapter or printer.

WARNING: You can potentially brick your Pogoplug following this tutorial. Your warranty will be voided. Proceed at your own risk. I didn't think I needed to say this but I do - these instructions are for the Pogoplug V4. Flashing the uBoot below on any other model of the Pogoplug will result in a brick. 

If you made a mistake, bricked your Pogoplug or simply didn't understand what you got yourself into or want to start fresh, you're in luck! Here is a ~$13 solution.

Requirements:
Outline of Steps:
  1. Enable SSH access to Pogoplug
  2. uBoot Installation via SSH Console 
    • Kill Pogoplug Service and Download uBoot Flashing Utilities
    • Download and Flash New uBoot
    • Download and Flash Default uBoot Environment Parameters
    • Update uBoot Environment Parameters
  3. Setup Netconsole (optional but highly recommended)
  4. Boot default Pogoplug OS when USB/SD Card not attached
  5. Debian/ALARM Installation on SD Card (or USB Hard/Flash Drive)

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 not available after a reboot).


SSH/Putty into Pogoplug V4 and Perform Installation

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. Here is a complete console installation log. Open it up and compare with what you're seeing on your ssh console screen as you're going through the tutorial.

Kill Pogoplug Service and Download uBoot Flashing Utilities

#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 execuable
chmod +x flash_erase fw_printenv fw_setenv nanddump nandwrite

#remount '/' as read/write
#by default the Pogoplug OS (internal flash) is read only
#skip if running from Debian/ALARM
mount -o remount,rw /

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


Download and Flash new uBoot

#download uboot and md5
wget http://download.qnology.com/pogoplug/v4/uboot.2014.07-tld-1.pogo_v4.bodhi.tar
wget http://download.qnology.com/pogoplug/v4/uboot.2014.07-tld-1.pogo_v4.bodhi.tar.md5

#check md5sum
md5sum -c uboot.2014.07-tld-1.pogo_v4.bodhi.tar.md5

#extract uboot
tar -xf uboot.2014.07-tld-1.pogo_v4.bodhi.tar


#Erase and flash uboot on mtd0
#BE EXTRA CAREFUL WITH THE NEXT TWO COMMANDS. NO TYPOS! CUT AND PASTE.
/tmp/flash_erase /dev/mtd0 0 4
/tmp/nandwrite /dev/mtd0 /tmp/uboot.2014.07-tld-1.pogo_v4.mtd0.kwb



Download and Flash uBoot Environment Parameters

#download default uboot env settings and md5
wget http://download.qnology.com/pogoplug/v4/uboot.2014.07-tld-1.environment.img.bodhi.tar
wget http://download.qnology.com/pogoplug/v4/uboot.2014.07-tld-1.environment.img.bodhi.tar.md5

#check md5 sum
md5sum -c uboot.2014.07-tld-1.environment.img.bodhi.tar.md5

#extract uboot env settings
tar -xf uboot.2014.07-tld-1.environment.img.bodhi.tar

#Flash default uboot env setting
#BE EXTRA CAREFUL WITH THE NEXT TWO COMMANDS. NO TYPOS! CUT AND PASTE.
/tmp/flash_erase /dev/mtd0 0xc0000 1
/tmp/nandwrite -s 786432 /dev/mtd0 uboot.2014.07-tld-1.environment.img


Update uBoot Environment Parameters

#SET MACADDRESS
/tmp/fw_setenv ethaddr "$(cat /sys/class/net/eth0/address)"

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

#set archNumber and machid (for LED)
/tmp/fw_setenv arcNumber 3960
/tmp/fw_setenv machid F78

#set rootfs file system type
/tmp/fw_setenv usb_rootfstype ext3

#set to original mtd partition layout
/tmp/fw_setenv mtdparts 'mtdparts=orion_nand:2M(u-boot),3M(uImage),3M(uImage2),8M(failsafe),112M(root)'

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


Setup Netconsole (Optional but highly recommended)

More info here - http://forum.doozan.com/read.php?3,14,14
Just run the below commands if you're not sure.

#Update IP Addresses as needed
/tmp/fw_setenv serverip 192.168.1.100

/tmp/fw_setenv ipaddr 192.168.1.10
/tmp/fw_setenv if_netconsole 'ping $serverip'
/tmp/fw_setenv start_netconsole 'setenv ncip $serverip; setenv bootdelay 10; setenv stdin nc; setenv stdout nc; setenv stderr nc; version;'
/tmp/fw_setenv preboot 'run if_netconsole start_netconsole'


Boot default Pogoplug OS when USB/SD Card not attached

Note that this section only works on a new unmodified Pogoplug. It assumes the command are all executed from within the default Pogoplug OS and not from Arch Linux or Debian.

If you previously installed the uBoot from archlinuxarm.org and/or already running ALARM or Debian, use these instructions instead - Pogoplug v4 - Add option to boot default Pogoplug OS when USB/SD Card is Not Attached.

To boot the default Pogoplug OS, we will need to chain load the original (dockstar) uboot which we'll download and store on the internal flash. The boot order will be USB, MMC/SD, SATA (Series 4 only) and then last, the original uBoot which will then load the default Pogoplug OS.

Don't forget that you'll need to activate the Pogoplug on my.pogoplug.com if you plan on SSHing into the default Pogoplug OS.

#remount '/' as read/write
mount -o remount,rw /

#download original uboot
cd /
wget http://download.doozan.com/uboot/files/uboot/uboot.mtd0.dockstar.original.kwb

#update boot order to include pogoplug OS
/tmp/fw_setenv bootcmd 'run bootcmd_usb; run bootcmd_mmc; run bootcmd_sata; run bootcmd_pogo; reset'

#chain load original uboot
/tmp/fw_setenv bootcmd_pogo 'if ubi part root 2048 && ubifsmount ubi:rootfs && ubifsload 0x800000 uboot.mtd0.dockstar.original.kwb ; then go 0x800200; fi'


Debian/ALARM Installation on SD Card (or USB Hard/Flash Drive)

Insert SD Card or USB Hard/Flash Drive. The commands below are for Debian on a SD Card. However, I've noted the difference for USB Hard/Flash Drive and Arch Linux.

#stop my.pogoplug.com service (just in case)
killall hbwd

#make device node for mmc/sd card
#skip command for usb install
mknod /tmp/mmcblk0 b 179 0

#Partition your SD Card
/sbin/fdisk /tmp/mmcblk0

#OR Partition your USB Flash/Hard Drive
#/sbin/fdisk /dev/sda

# Type in the following commands to erase
# and re-partition SD Card/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 # create a 4GB partition
# w # write new partition to disk

#make device node for partition
#command not needed for USB install
mknod /tmp/mmcblk0p1 b 179 1

#download format utility
cd /tmp
wget http://archlinuxarm.org/os/pogoplug/mke2fs
chmod +x mke2fs

#format newly created partition
#ext3 with "rootfs" as label
/tmp/mke2fs -L rootfs -j /tmp/mmcblk0p1

#OR format USB Flash/Hard Drive
#/tmp/mke2fs -L rootfs -j /dev/sda1

#create mount point
mkdir /tmp/mnt


#mount SD Card
mount /tmp/mmcblk0p1 /tmp/mnt

#OR mount USB Flash/Hard Drive
#mount /dev/sda1 /tmp/mnt

#download Debian rootfs and md5
cd /tmp/mnt
wget http://download.qnology.com/pogoplug/v4/Debian-3.14.0-kirkwood-tld-1-rootfs-bodhi.tar.bz2.md5

#check md5
md5sum -c Debian-3.14.0-kirkwood-tld-1-rootfs-bodhi.tar.bz2.md5

#extract and delete

tar -xjf Debian-3.14.0-kirkwood-tld-1-rootfs-bodhi.tar.bz2
rm Debian-3.14.0-kirkwood-tld-1-rootfs-bodhi.tar.bz2
rm Debian-3.14.0-kirkwood-tld-1-rootfs-bodhi.tar.bz2.md5

#OR For Arch Linux ARM
#cd /tmp/mnt
#wget http://archlinuxarm.org/os/ArchLinuxARM-kirkwood-latest.tar.gz 
#tar -xzvf ArchLinuxARM-kirkwood-latest.tar.gz
#rm ArchLinuxARM-kirkwood-latest.tar.gz

#Make SD Card first boot device (optional)
#Default boot order is USB->MMC/SD->SATA->POGO_OS
/tmp/fw_setenv bootcmd 'run bootcmd_mmc; run bootcmd_usb; run bootcmd_sata; run bootcmd_pogo; reset'

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


At this point, your Pogoplug should boot back up into Debian or Arch Linux ARM. 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 both Debian or Arch Linux, 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


Upgrade Debian to 3.18.5 kernel (optional)
Latest kernel and instructions here - http://forum.doozan.com/read.php?2,12096


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

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

#check md5
echo "68c96df62427c69bc7599ff31859b9b4  linux-3.18.5-kirkwood-tld-1-bodhi.tar.bz2" |md5sum -c

#extract
tar -xvjf linux-3.18.5-kirkwood-tld-1-bodhi.tar.bz2
tar -xvf  linux-dtb-3.18.5-kirkwood-tld-1.tar

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

#generate new uImage and uInitrd with fdt file. No need to modify uboot env
cp -a zImage-3.18.5-kirkwood-tld-1  zImage.fdt
cat dts/kirkwood-pogoplug_v4.dtb  >> zImage.fdt
mkimage -A arm -O linux -T kernel -C none -a 0x00008000 -e 0x00008000 -n Linux-3.18.5-kirkwood-tld-1 -d zImage.fdt uImage
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initramfs-3.18.5-kirkwood-tld-1 -d initrd.img-3.18.5-kirkwood-tld-1 uInitrd
rm zImage.fdt


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

#reboot and verify
uname -a



Install SAMBA for a simple NAS (Network Attached Storage) - Debian

Plug in your USB Hard Drive and partition and format the drive as ext3.

mkdir -p /media/usb/share
mount /dev/sda1 /media/usb/share

apt-get install samba
cd /etc/samba
mv smb.conf smb.conf.bak

#download example smb.conf for public share
#no authentication require, everyone has
#read/write access to / (root$) and usb (/media/usb/share)
wget --no-check-certificate https://dl.dropboxusercontent.com/u/42238/pogoplug/debian/smb.conf
/etc/init.d/samba restart



Debian Pogoplug Tutorials:

Troubleshooting

On the Series 4, only the top USB port is bootable. The blue USB 3.0 ports on the back of the Series 4 are not bootable.

Not all SD cards and USB flash drive are equal. If you're having issues booting into ALARM or Debian, try using a different SD card or USB flash drive.

Double check that you're SD Card is not in the "locked" (read only) position.

Cannot SSH back into the Pogoplug - double check the IP Address assigned to your Pogoplug. After booting Debian/ALARM, chances are your router will assign the Pogoplug a different IP Address. Check your router or use a network scanning tool to help figure out what IP Address was assigned to your Pogoplug.

Use Netconsole to see what's going on. Hopefully you followed my recommendation and setup netconsole.

Reinstallation - If you need to setup a new SD Card or USB Flash Drive, what you need to do is use a Linux computer or boot a Live Linux CD to partition, format (please make sure to use ext3 and not ext4), download and extract the rootfs to your SD Card or USB Flash Drive. Here is a basic outline of the steps from the ArchLinuxArm.org website. Note for Debian, you'll want to use the link to the tarball in this tutorial.

Note that it's fairly difficult or nearly impossible to truly brick the Pogoplug v4. The most risky part of this tutorial is the four uBoot erasing/flashing lines (highlighted red). Even if somehow that went wrong (bad blocks for instance), you can recover via a serial connection and UART booting. More info here - http://forum.doozan.com/read.php?3,7852,7852


Miscellaneous Links and Reference
Self Promotion

Three Pogoplugs gave their lives bringing you this tutorial and countless hours. If you would like to show your support for this blog, please check out my AirEnabler or buy me a cup of coffee (link above). Thank you for your support.