Write Images to Flash

Flashing with Linux

We recommend using the Linux mtd utilities to write images to flash. This will require a bootable microSD card, which you can create by following the instructions posted here.

Now, copy the image files, and the script below, to the microSD card (for example to /home/root/images). You may need to modify the script to reflect the names of your image files. Make sure the script is marked as executable.

Unmount the microSD card from your development machine, insert in the Overo microSD slot and boot.

Login and run the script. If you are using a zImage rather than a uImage, it gets flashed as part of the rootfs---just leave the uimage variable blank.  Some users have reported that 'flash_erase /dev/mtdX 0' erases the partition where the syntax 'flash_erase /dev/mtdX 0 0' fails---this seems to occur on version 1.4.1 of mtd_utils (check with 'smart info mtd-utils').

uboot=u-boot-overo.bin
uimage=uImage-overo.bin
rootfs=omap3-desktop-nand-image-overo.ubi

if [ -e $uboot ]; then
  echo "Erasing u-boot partition ..."
  flash_erase /dev/mtd1 0 0
  echo "Erasing u-boot environment partition ..."
  flash_erase /dev/mtd2 0 0
  echo "Writing u-boot to NAND ..."
  nandwrite -p /dev/mtd1 $uboot
else
  echo "ERROR:  couldn't find u-boot binary"
fi

if [ -e $uimage ]; then                 
  echo "Erasing kernel partition ..."            
  flash_erase /dev/mtd3 0 0                      
  echo "Writing kernel to NAND ..."         
  nandwrite -p /dev/mtd3 $uimage
else                                             
  echo "WARN:  Not flashing uImage kernel"
  flash_erase /dev/mtd3 0 0
fi
                                               
if [ -e $rootfs ]; then
  umount /dev/mtdblock4
  echo "Writing rootfs to NAND ..."
  ubiformat -y /dev/mtd4 -f $rootfs
else
  echo "ERROR:  couldn't find rootfs ubi"
fi

Replacing MLO

The Overo COM bootstrap loader MLO (x-load) requires 1-bit hardware error checking which is only available within the u-boot environment.  The following commands issued at the u-boot prompt write four copies of an MLO (filename="MLO") from the FAT partition of a microSD card to Flash memory on the COM.  Four copies are used for redundancy in case of corruption.

Overo # mmc rescan 0
Overo # load mmc 0 ${loadaddr} MLO
reading MLO

24220 bytes read
Overo # nandecc hw
HW ECC selected
Overo # nand erase.part xloader

NAND erase: device 0 offset 0x0, size 0x80000
Erasing at 0x60000 -- 100% complete.
OK
Overo # nand write ${loadaddr} 0x0 ${filesize}

NAND write: device 0 offset 0x0, size 0x20000
131072 bytes written: OK
Overo # nand write ${loadaddr} 0x20000 ${filesize}
...
Overo # nand write ${loadaddr} 0x40000 ${filesize}
...
Overo # nand write ${loadaddr} 0x60000 ${filesize}
...

Alternatively, you can write a u-boot script to flash MLO.

$ nano flash-MLO.cmd
load mmc 0 ${loadaddr} MLO
nandecc hw
nand erase.part xloader
nand write ${loadaddr} 0x0 ${filesize}
nand write ${loadaddr} 0x20000 ${filesize}
nand write ${loadaddr} 0x40000 ${filesize}
nand write ${loadaddr} 0x60000 ${filesize}

Make the script readable by u-boot.

$ mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "flash-MLO" -d flash-MLO.cmd flash-MLO.scr

Copy flash-MLO.scr to your boot partition, insert the microSD card in your COM and wait for u-boot to load from mmc. Interrupt the boot process when you see Hit any key to stop autoboot and enter these commands.

# mmc rescan 0; fatload mmc 0 ${loadaddr} flash-MLO.scr; source ${loadaddr}

Flashing with U-Boot

It is possible to completely reflash the COM (MLO, u-boot, kernel, root file system) from u-boot. First, you need to prepare a bootable microSD card. Then copy the files you wish to flash to the '/boot' directory on the rootfs partition. For example:

# assume the rootfs is mounted at /media/rootfs/
$ cd /media/rootfs/boot
$ wget https://s3-us-west-2.amazonaws.com/gumstix-yocto/2015-02-25/overo/master/MLO
$ wget https://s3-us-west-2.amazonaws.com/gumstix-yocto/2015-02-25/overo/master/u-boot.img
$ wget https://s3-us-west-2.amazonaws.com/gumstix-yocto/2015-02-25/overo/master/gumstix-console-image-overo.ubi -O rootfs.ubi

Now create a script to write the files to flash.

$ nano flash-all.cmd
nand erase.chip

# switch to 1-bit ECC and write MLO
load mmc 0:2 ${loadaddr} /boot/MLO
nandecc hw
nand write ${loadaddr} 0x0 ${filesize}
nand write ${loadaddr} 0x20000 ${filesize}
nand write ${loadaddr} 0x40000 ${filesize}
nand write ${loadaddr} 0x60000 ${filesize}

# switch back to BCH8 and write u-boot
nandecc sw bch8
load mmc 0:2 ${loadaddr} /boot/u-boot.img
nand write ${loadaddr} u-boot ${filesize}

# write the kernel (if uImage...otherwise skip)
load mmc 0:2 ${loadaddr} /boot/uImage
nand write ${loadaddr} linux ${filesize}

# write the filesystem
load mmc 0:2 ${loadaddr} /boot/rootfs.ubi
nand write ${loadaddr} rootfs ${filesize}

To make the script readable by u-boot, use the following command (assuming the boot partition is mounted at /media/boot

$ mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "flash-all" -d flash-all.cmd /media/boot/flash-all.scr

Unmount, insert the microSD card in your COM and wait for u-boot to load from mmc. Interrupt the boot process when you see Hit any key to stop autoboot and enter these commands.

# mmc rescan 0; load mmc 0 ${loadaddr} flash-all.scr; source ${loadaddr}

Remove the SD card and restart your system. If all went well, your system should start normally.