1. Obtain u-boot's mkimage

	wget ftp://ftp.denx.de/pub/u-boot/u-boot-2009.11.tar.bz2
	tar xfj u-boot-2009.11.tar.bz2
	cd u-boot-2009.11
	touch include/config.{h,mk}
	make SUBDIRS=tools BIN_FILES-y=mkimage tools
	cp tools/mkimage /usr/local/bin
	cd ..

2. Build the kernel

	git clone git://projects.qi-hardware.com/qi-kernel.git
	cd qi-kernel
	git checkout ben-wpan
	cp ../ben-wpan-config-2.6.38 .config
  	patch -p1 -s <../openwrt-preinit-hack.patch
  OWRT	make ARCH=mips CROSS_COMPILE=mipsel-openwrt-linux- vmlinux.bin
  Jlime	make ARCH=mips CROSS_COMPILE=mipsel-linux- vmlinux.bin
	gzip -9 -f arch/mips/boot/vmlinux.bin
  OWRT	mkimage -A mips -O linux -T kernel -a 0x80010000 \
	    -C gzip -e 0x`mipsel-openwrt-linux-nm vmlinux | \
	    grep " kernel_entry" | cut -f1 -d ' '` \
	    -n 'Ben NanoNote Linux Kernel' \
	    -d arch/mips/boot/vmlinux.bin.gz uImage
  Jlime	mkimage -A mips -O linux -T kernel -a 0x80010000 \
	    -C gzip -e 0x`mipsel-linux-nm vmlinux | \
	    grep " kernel_entry" | cut -f1 -d ' '` \
	    -n 'Ben NanoNote Linux Kernel' \
	    -d arch/mips/boot/vmlinux.bin.gz uImage
	cd ..

3. Install the kernel

    Using usbboot:

	- remove battery and USB
	- wait 15 seconds
	- press the "U" key on the Ben
	- insert USB while keeping "U" pressed
	- release the "U" key
	- on the host, run
	  usbboot -c "boot;nprog 1024 qi-kernel/uImage 0 0 -n"
	- disconnect USB
	- wait 15 seconds
	- connect USB again

   Using nandwrite:

	- set up TCP/IP networking with the Ben
	- get the Ben's IPv4 address:
	  NN=`ifconfig usb0 |
	  sed '/.*inet addr:\([^ ]*\).*/{s//\1/;s/100$/101/;s/200$/202/;p;};d'`
	  # should be  NN=192.168.254.101  for OpenWRT,
	  # NN=192.168.1.202  for Jlime
	- copy the kernel:
	  scp qi-kernel/uImage $NN:
	- flash the kernel, clean up, and reboot:
	  ssh $NN 'PATH=$PATH:/usr/sbin;
	    flash_eraseall /dev/mtd1 && nandwrite -p /dev/mtd1 uImage &&
	    rm -f uImage && sync && sleep 1 && sync && sleep 1 &&
	    /sbin/reboot -f'
	- press ^C to return to the shell

4. Set up the user space on the Ben

	- connect to the Ben
	  ssh $NN
	- run the following commands:
  OWRT	  opkg install ip
  OWRT	  opkg install ldconfig
	  mkdir -p /usr/local/var/run
	  exit

5. Build libnl-1 for cross-development and install the run-time library

	wget http://www.infradead.org/~tgr/libnl/files/libnl-1.1.tar.gz
	tar xfz libnl-1.1.tar.gz
	cd libnl-1.1
  OWRT	gcc=`readlink -f \`which mipsel-openwrt-linux-gcc\``
  OWRT	./configure --prefix=${gcc%/bin/*} --host=mipsel-openwrt-linux
  Jlime patch -p1 -s <../libnl-1.1-limits.patch
  Jlime	inc=`mipsel-linux-cpp -v </dev/null 2>&1 | grep usr/include | tr -d \ `
  Jlime	./configure --prefix=${inc%/include} --host=mipsel-linux
	make
	make install

	scp lib/libnl.so.1.1 $NN:/usr/lib
	ssh $NN /sbin/ldconfig
	cd ..

6. Build the user space tools of the linux-zigbee project

	git clone git://linux-zigbee.git.sourceforge.net/gitroot/linux-zigbee/linux-zigbee
	cd linux-zigbee
  OWRT	./autogen.sh --host=mipsel-openwrt-linux
  JLime	./autogen.sh --host=mipsel-linux
	make

	scp src/iz src/izcoordinator src/izchat $NN:/usr/sbin/
	cd ..

7. Build dirtpan, a crude IPv4-over-IEEE 802.15.4 tunnel

	git clone git://projects.qi-hardware.com/ben-wpan.git

	# If compiling dirtpan.c fails due a missing ieee802145.h header,
	# copy it over from lowpan-tools:

	cp lowpan-tools-0.2.2/include/ieee802154.h tools/dirtpan/

	cd ben-wpan/tools
  OWRT	make TARGET=ben_openwrt
  OWRT	make -C dirtpan TARGET=ben_openwrt
  JLime	make TARGET=ben_jlime
  JLime	make -C dirtpan TARGET=ben_jlime
	scp dirtpan/dirtpan $NN:/usr/sbin