Sheevaplug Debian Squeeze NAND installation 2.0

Dec. 13, 2010, 5:49 p.m.

I decided to do a kernel upgrade and clean install on my Sheevaplug. I thought my guide could use a touch-up at the same time.

If you followed the first guide to the letter, have a working squeeze install, and just need to touch up your kernel: skip to the 'Obtaining a new Kernel' step after you backup. You can also disregard the MiniSD card requirement.

What you need

  • 1GB or 2GB MiniSD card or MicroSD with MiniSD adapter. I am not sure what the size limit is, 2GB was tested.

  • JTAG USB/Serial device.

  • Putty.exe Download Putty

  • FAT16 aka FAT (not FAT32) formatted USB pendrive.*

  • Some type of USB storage to backup your existing files if needed.

* - FAT16 means a size of <=4GB. I was able to use a 4GB Kingston DataTraveler.


You may want to collect anything you will need in the future before you get too involved with this process. e.g. /etc/samba, /etc/cups, /etc/denyhosts.conf... your home folder, etc. These need to be on storage that will be disconnected during the entire install.

Back up your installed/deinstalled package information:

dpkg --get-selections > dpkg-selections.txt

Move dpkg-selections.txt to the same safe storage as your /etc/ and home backups.
You can later re-install these one by one using the list to review and install only what you were actually using before, or just attempt to re-install en-masse (may cause problems):
dpkg --set-selections < selections.txt
apt-get update
apt-get upgrade

Getting started

Insert your SD card into the JTAG adapter with write-lock disabled if available. You will lose the contents of this card.

SSH to your existing install and issue this command:

sudo shutdown -h now

That should drop your Sheevaplug to maintenance mode. Disconnect any external USB storage on the Sheevaplug. Now you can attach the JTAG adapter, this will cause Windows to attempt to detect the device.

In my case, with Windows 7 64 bit as the installing OS, I had to plug in the JTAG adapter and ignore the plug-n-play failure messages. Then I ran Windows Update "Check for Updates" and install twice, once to get the JTAG driver, and a second time to get the serial port child device. Annoying but easy.

Connect to this new serial port at 115200 baud, 8 data bits, 1 stop bit, no parity, and no flow control.

Press the reset button on the JTAG adapter. You should see a bunch of text from the U-Boot process.

Eventually you will be dropped off at the previous OS console, login here with whatever you used before.

Preparing SD card

To format the SD card in the JTAG adapter perform the steps below. You need to be very sure that mmcblk0 is your SD card. It should be, but your case may vary.
sudo fdisk /dev/mmcblk0

  1. Press 'p' to print current partitions. If you see something amiss here, double check everything. If the card hasn't been used for this purpose before, you will probably see a single FAT16 partition approximately the size of the SD card.

  2. If you only saw a partition that you are sure you can do without (like a FAT16 partition described above) press 'd' to delete it.

  3. Now press 'n' to create a new partition, 'p' for primary, partition number 1, then accept the defaults for first and last cylinders. It should be 1 and N where N is the total number of cylinders.

  4. Press 'w' to write to disk and exit.

Now make a ext2 filesystem on this new partition. The following command assumes that you are targeting the first partion of the device you fdisk'ed above. If you have altered the steps above or have multiple partitions on the device, think carefully about the command you actually need to use instead.

sudo mke2fs /dev/mmcblk0p1

Bootstrap preparation rootfs.tar.gz

Now we can really get started.
sudo su -
mkdir sdcard
mount /dev/mmcblk0p1 sdcard
cd sdcard
chmod +x

This will take some time, you can continue with the next step and stop.

Preparing USB Pendrive

If your pendrive has data on it, back that up then format the drive as FAT (FAT16).

Download and extract this to the root of your FAT16 formatted USB pendrive.

"Safely remove" the pendrive.

Collect rootfs.tar.gz

Return to the Serial Sheevaplug terminal (Putty). You should get output containing "INFO:Debian Squeeze Build complete!"

Insert the USB pendrive into the Sheevaplug. This should cause output to be dumped to the console e.g.

sd 0:0:0:0: [sda] Assuming drive cache: write through
sda: sda1
sd 0:0:0:0: [sda] Attached SCSI removable disk

Replace sda1 below with what you see in the output above. It should be sda1, but double check anyway.

Now mount this and copy your rootfs.tar.gz tarball over.

cd ~
mkdir pendrive
mount /dev/sda1 pendrive
cp sdcard/rootfs.tar.gz pendrive
ls -R pendrive

The "ls" output should look very similar to this:

initrd modules.tar.gz rootfs.tar.gz uboot uImage


U-Boot Upgrade

You can skip this session if you know you already have 3.4.27+pingtoo or better version of U-Boot.

  1. Open the Serial connection in Putty and press the reset button on your JTAG.

  2. During the countdown to startup, press any key to stop autoboot. This should drop you to a Marvell>> prompt.

  3. Type "version" and check the output. We want 3.4.27+pingtoo or better. If you are good, skip to the next part.

  4. If you are not at the correct version, issue these commands one at a time:

    usb start
    fatload usb 0:1 0x0800000 /uboot/uboot.bin

  5. If either of those commands gave you an error STOP! Continuing will most likely brick your device if
    you have not loaded the new U-Boot into memory properly.

  6. If you did not get an error above, issue these commands one at a time

    nand erase 0x0 0xa0000
    nand write 0x0800000 0x0 0xa0000

Credit to for the info.

OS Upgrade

This is the part that took me the most time to reverse engineer last time around. Thankfully this time was much easier.

  1. Open the Serial connection in Putty and press the reset button on your JTAG.

  2. During the countdown to startup, press any key to stop autoboot. This should drop you to a Marvell>> prompt.

  3. Type "version" and check the output. You want 3.4.27+pingtoo or better. If you are below this, return to U-Boot upgrade section above.

  4. Copy the text below to notepad or your preferred raw text editor.
    setenv bootargs_root 'ubi.mtd=1 root=ubi0:rootfs rootfstype=ubifs'
    setenv ethaddr 'ac:de:48:00:00:01'
    setenv mtdpartitions 'mtdparts=orion_nand:0x400000@0x100000(uImage),0x1fb00000@0x500000(rootfs)'
    setenv bootargs_console 'console=ttyS0,115200'
    setenv rootinfo 'root=/dev/ram0 rw ramdisk=0x01100000,8M install_type=nand'
    setenv real_bootcmd 'setenv bootargs $(bootargs_console) $(mtdpartitions) $(bootargs_root); nand read.e 0x00800000 0x00100000 0x00400000; bootm 0x00800000'
    setenv bootcmd 'run recover1'
    setenv recover1 'setenv mainlineLinux yes; setenv arcNumber 2097; setenv bootcmd run recover2; saveenv; reset'
    setenv recover2 'run recover3; setenv bootcmd $(real_bootcmd); saveenv; setenv bootargs $(bootargs_console) $(mtdpartitions) $(rootinfo); bootm 0x00800000 0x01100000'
    setenv recover3 'run recover4; nand erase clean 0x00100000 0x00400000; nand write.e 0x00800000 0x00100000 0x00400000'
    setenv recover4 'usb start; fatload usb 0 0x00800000 uImage; fatload usb 0 0x01100000 initrd'

  5. Modify the "ethaddr 'xxxx'" on line 2 to reflect your actual Sheevaplug MAC address. Failure to do so will probably not be good.

  6. Copy and paste ONE LINE AT A TIME from the text editor into the serial terminal pressing enter after each.

  7. It is imperative that you are careful when pasting above. Do not try to paste everything at once, it will fail unpredictably.

  8. Once the reset command has been issued do not press anything. If you are stuck for over 5 minutes, you can try the reset button as USB support can be flaky when it is booting. You may need to go back to step one of this section and try again.

  9. Once you see this prompt, you can remove your pendrive. Unless you want to upgrade the kernel.
    Debian GNU/Linux squeeze/sid debian ttyS0

    debian login:

  10. Login with username: root, password: nosoup4u

  11. Type the command 'passwd' to change your root password to something better. Failure to perform this step will implicitly enroll you in a botnet if you have ssh exposed to the Internet.

Obtaining a New Kernel

Unless you want the latest kernel, skip the next two parts. There are security considerations involved with keeping the old kernel, choose appropriately for your environment. You will likely regret this when a kernel upgrade rolls out as you have to repeat these two steps. Also, this kernel takes up about 50MB of NAND by the time all of the dependencies pile in. You also need to clean up after the old kernel once you upgrade.

cd ~
apt-get install linux-image-kirkwood
mkdir pendrive
mount /dev/sda1 pendrive
mkimage -A arm -O linux -T kernel -C none -a 0x00008000 -e 0x00008000 -d /vmlinuz pendrive/uImage-k
umount /dev/sda1
rmdir pendrive/

Replacing the Kernel

The uImage-k file should not exceed 4MB.

  1. Open the Serial connection in Putty and perform a 'reboot' command from inside your new Debian install.

  2. During the countdown to startup, press any key to stop autoboot. This should drop you to a Marvell>> prompt.

  3. Enter these commands in order one at a time waiting for each to complete successfully:

    usb start
    fatload usb 0 0x00800000 uImage-k
    nand erase clean 0x00100000 0x00400000
    nand write.e 0x00800000 0x00100000 0x00400000

This should look a little familiar. During the install process this installed the installation kernel, which is what Debian later can use to run. Here we replace that section of NAND with the new Kernel provided by Debian and reboot.

Once the system reboots you can remove /boot/uImage. This is the installation kernel image and was probably useless before, definately useless now.

Reclaiming the SD Card

After formatting to ext2 filesystem, your SD card is pretty much useless for normal purposes.
As root issue the command below:
sudo fdisk /dev/mmcblk0

  1. Press 'd' to delete the partition made earlier

  2. Now press 'n' to create a new partition, 'p' for primary, partition number 1, then accept the defaults for first and last cylinders. It should be 1 and N where N is the total number of cylinders.

  3. Press 't' to change the type. Enter type 6.

  4. Press 'w' to commit these changes once you are sure that you are in good shape.

  5. Now as root issue the command:

    mkdosfs /dev/mmcblk0p1

Connecting to the Sheevaplug

Your device should have pulled a DHCP address. From the serial console enter ifconfig and check your inet addr. Make a note of that and use Putty in SSH mode to connect to that IP.

Finishing touches

  • 'apt-get clean' will get back some free space.

  • 'apt-get install localepurge' will regain 40MB of space due to unnecessary translations hogging your NAND. It will keep your system clean in the long run as well. With a new kernel and localepurge installed I kept 324MB free as a starting point.

  • Install sudo then create a new user and add them to /etc/sudoers, or add them to the sudo group
    Open /etc/ssh/sshd_config and change 'PermitRootLogin' to 'no'. Restart the SSH daemon.

  • Change your timezone via 'sudo dpkg-reconfigure tzdata'

  • If you plan on exposing SSH to the public, try out denyhosts.

There is probably a good case for deleting the vzimage file from /boot/ among others. There may be a follow-up post coming on that.

tags( #linux #sheevaplug )


Various Coding and Scripting Endeavors


Whats going on generally.

Neat Stuff

Things I have found useful or interesting on the internet, for what it is worth.

Follow caller9com on Twitter