Martin Michlmayr
A NSLU2 from the front

How to modify a NSLU2 flash image

The Linksys NSLU2 has a nice feature that allows users to write a firmware image to flash to the NSLU2 via the network. The tool upslug2 can be used under Linux to write an image to a NSLU2. The firmware image consists of the Linux kernel, a ramdisk and some other components. This page describes how to take an existing firmware image, unpack it, make changes and then pack it again. This is useful for a number of reasons, for example to add the NPE microcode to an installer image or to change oldsys-preseed (the tool creating the network configuration for the Debian installer based on the settings from the NSLU2 firmware) so it will use different network settings.

In order to modify a NSLU2 image, you have to install some tools:

apt-get install slugimage devio

Now download a NSLU2 image and save it as nslu2.bin. You can now unpack this image:

sudo rm -rf initrd
rm -rf new-nslu2.img new-initrd*
slugimage -u -i nslu2.bin
devio '<< ramdisk.gz; xp $ 4' > ramdisk-swap.gz
mkdir initrd; cd initrd
zcat ../ramdisk-swap.gz | sudo cpio -i

The image is now unpacked and you can make changes. For example, to add the NPE microcode you'd have to do this:

sudo mkdir lib/firmware
sudo cp ~/NPE-B.01020201 lib/firmware
sudo ln -s NPE-B.01020201 lib/firmware/NPE-B

Now that you have made some changes, you can generate a new image:

find . | sudo cpio --quiet -o -H newc > ../new-initrd
cd ..
gzip -9 new-initrd
dd if=new-initrd.gz of=new-initrd.gz.padded ibs=6291440 conv=sync
devio "<<"new-initrd.gz.padded > new-initrd.gz.swapped "xp $,4"
slugimage -p -o new-nslu2.img -k vmlinuz -L apex.bin -r new-initrd.gz.swapped

You now have a new image called new-nslu2.img and you can use upslug2 to write it to your NSLU2.