Dual booting OpenWRT and Debian on an iConnect

I’ve now got both OpenWRT and Debian wheezy installed and working on my iConnect however they both expect to be the only OS installed on the iConnect so the u-boot config needs a bit of tweaking to have them both installed and bootable.

I have OpenWRT installed completely on the internal flash as OpenWRT is setup for that and it’s only 32MB taken up, Debian I have installed on a usb flash drive but the kernel and initrd are stored on the internal flash after OpenWRT’s rootfs.

I have divided the the 512M of NAND flash in my iConnect like this:

1M u-boot loader with config stored @0xc000
3M of OpenWRT kernel
32M of OpenWRT root filesystem
5M of Debian kernel
20M of Debian initfs
425M of Data (currently unused)

First of all we need to make sure that u-boot, OpenWRT and Debian have the same view of the flash in the iConnect:

setenv mtdparts 'mtdparts=orion_nand:1M(u-boot),3M@1M(kernel),32M@4M(rootfs),5M@36M(debian-uimage),20M@41M(debian-initrd),425M@86M(data)'

Tell u-boot to use the mtdparts we have just defined:

setenv mtdids 'nand0=orion_nand'

We want the same console settings for all of the OS’s so lets define it once:

setenv bootargs_console 'console=ttyS0,115200'

Set the boot command and rootfs UUID for Debian

setenv debian_root 'root=UUID=8f9f89f2-5bc2-4ba2-9a8f-6d92cf5c46af ro rootdelay=10'
setenv debian_bootcmd 'nand read 0x800000 debian-uimage; nand read 0x1100000 debian-initrd'

Because I’m using an OpenWRT u-boot the OpenWRT boot commands are already defined as x_ commands, but if you didn’t the commands to setup OpenWRT booting are

setenv openwrt_root 'root=/dev/mtdblock2 rw rootfstype=jffs2'
setenv openwrt_bootcmd 'nand read 0x6400000 0x100000 0x300000'

To switch to booting Debian you need to set the machine id to something that Debian works with, update the bootcmd and then save and reset.

setenv machid 692
setenv bootcmd 'setenv bootargs $(bootargs_console) $(mtdparts) $(debian_root); run debian_bootcmd; bootm 0x00800000 0x01100000; reset'

To switch to booting OpenWRT you need to clear machine id, update the bootcmd and then save and reset.

setenv machid
setenv bootcmd 'run openwrt_bootcmd; setenv bootargs $(mtdparts) $(bootargs_console) $(openwrt_root); bootm 0x6400000; reset'