Multiboot using u-boot

=Multiboot Overview=

This Howto will provide a way to boot different OS (Distributions) without changing main boot device (SD Card). Second stage bootloader (u-boot) does not provide multi choise menu system like grub to boot different options. But u-boot provides scripting features which is used in this howto.

=Prerequisites=

- Linux System to prepare the scripts and images - serial console access - USB-Disk or USB-Stick partitioned with at least 2 bootable rootfs. - Two or more bootable SD Card configured to boot above OS - initial boot scripts

=Preparation=

This can be done on the PandaBoard itself or a local Linux system.

Copy files
First create working directory on your local machine.


 * 1) mkdir multiboot

For all OS you want to multiboot, copy uImage and uInitrd from corresponding SD Card to working directory.

Mount SD Card: Copy files: Copy initial boot script to the working directory (sample Ubuntu Server 12.04)
 * 1) mount /dev/mmcblk0p1 /media/boot
 * 1) cp uImage ~/multiboot/os1.uImage
 * 2) cp uInitrd ~/multiboot/os1.uInitrd
 * 1) cp /boot/boot.script ~/multiboot/os1.script

Copy one set as default OS:
 * 1) cd ~/multiboot
 * 2) cp os1.uImage uImage
 * 3) cp os1.uInitrd uInitrd
 * 4) cp os1.script boot.script

Edit boot scripts
Add additional echo commands to print when OS is booting.

Sample boot script (Ubuntu Server 12.04):
 * 1) root@ARMedPanda:/media/data# cat precise.script
 * 2) fatload mmc 0:1 0x80000000 precise.uImage
 * 3) fatload mmc 0:1 0x81600000 precise.uInitrd
 * 4) setenv bootargs ro elevator=noop vram=32M mem=456M@0x80000000 mem=512M@0xA0000000 root=/dev/sda2 fixrtc quiet splash console=ttyO2,115200n8
 * 5) echo -
 * 6) echo          booting Precise
 * 7) echo -
 * 8) bootm 0x80000000 0x81600000

Make sure "root=" points to the correct rootfs.

Create binary scripts
All scripts needs to compile into images.
 * 1) mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "PandaBoard boot script" -d os1.script os1.scr

Create Environment
create a new text file which will hold bootable OS as environment variables
 * 1) touch preEnv.txt
 * 2) nano preEnv.txt

Sample content:
 * 1) myos1=fatload mmc 0:1 0x80000000 os1.scr; source
 * 2) myos2=fatload mmc 0:1 0x80000000 os2.scr; source

First is the name of the variable. This variable holds commands to load a script in memory and executes it from the given memory address.

compile SD Card
Best way is to use a pre created bootable SD Card with MLO and u-boot.bin.

Copy files:
 * 1) cp ~/multiboot/*.uInitrd /media/boot
 * 2) cp ~/multiboot/*.uImage /media/boot
 * 3) cp ~/multiboot/*.scr /media/boot
 * 4) cp ~/multiboot/preEnv.txt /media/boot
 * 5) cp ~/multiboot/uInitrd /media/boot
 * 6) cp ~/multiboot/uImage /media/boot

Booting
Attach the created SD Card and your USB-Disk/USB-Stick to the Pandaboard. Make sure you have serial console up and running. Power on the PandaBoard. During second stage boot (u-boot) you will see: Hit a key to get to u-boot cli prompt and run your OS using the run command:
 * 1) Hit any key to stop autoboot:  3
 * 1) Environment size: 1828/131068 bytes
 * 2) Panda # run myos1

If no key is hit the default OS will be booted.

=risk and todo=

- Every time the booted OS is updating the system, mostly also uImage, boot.scr and/or uInitrd are updated. So you need to take care to restore your multi boot. - rework article - need scripts to manage the multi boot partition on SD Card