Tuesday, March 23, 2010

Trashed NAND storage rebuilding

The great thing about OMAP processors is that they offer a huge number of functions on a single chip. The most advanced models include an ARM, a DSP, video and 3D accelerators, and a long list of connectivity options. The problem is that all of these features make OMAP a complicated chip. Building a system around such a complex chip is a major challenge. Hence, OMAP has historically been use for high-volume apps where the design effort could be justified.

Gumstix is changing the rules. Its modules include basic features like power supplies, memory (Ram and NAND Flash Rom), and WiFi/Bluetooth interfaces. These COM modules plug into expansion boards with I/O such as DVI and USB. (Gumstix offers four different COM [Computer on Module] base modules and five expansion boards, all of which are pin-compatible with each other.) If you are interested you can check out the complete Gumstix line here: Gumstix Website These modules take away a huge part of the basic engineering, letting you focus on the value-added work. One commonality among all the Gumstix COM modules is the amount and type of Ram and NAND Flash Rom on board. Since this is a common ‘trait’ of the COM board’s restoration of the NAND Flash Rom content is the same across the Overo line of COM computer modules.

Part of the process of performing value-added work involves developing software to take advantage of the different capabilities of the Omap processor. Once you have that bright, shiny new Overo COM board and expansion module you decide you want to do some "programming" and/or "installations" and proceed to go about re-programming the on-board 256-meg storage on the COM (computer on module). Why not? Installing software in the NAND Flash Rom makes sense as all of the system is contained within a very small footprint and it does not add anything to the power budget (requirements). Things are proceeding right along and the updates are occurring and you get to a critical update point when suddenly the power flickers! (No lie - had that exact thing happen to me!). Now the system is no longer responsive! What do you do???

When you try cycling the power no changes are noted and the computer does not do anything as the Overo computer just sits there with its unflinching power indicator lit and nothing else happening - other than your imagination taking hold and you are thinking you have a very small computer BRICK (in other words – non-responsive). In a panic now you decide to see if the computer will boot-up from that microSD card you set up with a bootable Overo image. Will it boot up as it did once before - yes it does! Well, at least you feel the hardware is working since it booted off the microSD card but it will not boot up from the internal NAND memory. Now what - you want to run the system from NAND and use the microSD card for removable storage - not for the operating system itself - or not use the microSD card slot at all to keep power requirements to the absolute minimum. Now the question you ask yourself is "How to 'restore' the NAND to a bootable state as it was from the factory - or at least some facsimile"?

Well - that is not such a hard problem to solve at all. The folks at Gumstix thought it best to make the system test and boot off the microSD card first in the boot up sequence to cover such contingencies. We can setup a microSD card to boot up the computer and use it to restore the contents in the on-board NAND memory for those cases where things go terribly wrong. If you read my previous posting (Overo Information Blog) on how to setup a bootable microSD card then you are already ahead of the game. If you did not I would suggest you do so as you will need to install a bootable system in a microSD card in order to restore the contents into the on-board NAND rom.

It is recommended that you use the linux mtd utilities to write images to NAND Rom. Microsoft Windows tools just seem to have issues with doing this sort of work and most of the tools will not allow performing some of the steps required to setup a microSD card for boot up in the Overo COM computers. If you don’t have a linux machine setup you can always download and install VMware’s Free Server software and build a linux system in VMware on your Windows machine.

The following steps are performed with the microSD card mounted to your Linux Overo development system machine. You can mount the microSD card either through a SD Card adaptor installed directly on your computer or use a USB to microSD adaptor.

Setup a bootable microSD card with an operating system image that boots up on the Overo COM board then follow the steps below to setup the system to restore the contents in the NAND rom on-board the COM.

Next, copy the image files you are going to restore to the NAND rom to the microSD card (say to /home/root/images). Create the following script in the same directory as you copied the image files. You may need to modify the script to reflect the names of your image files if they are not the default file names.

Make sure the script is marked as executable.

Unmount the microSD card from your development machine, insert it in the Overo microSD slot and apply power to boot up the machine.

Once your COM computer has booted up to the login prompt login and run the script you created earlier. You should see messages from the script as the NAND rom reloading process proceeds. If there is an error during the update process the script will print an error message to let you know what the error was. If there are no errors during the restoration process the script will inform you the restoration is complete.

Once you have successfully restored the NAND rom contents you should be able to shutdown the COM, remove the microSD card then apply power to reboot the COM back up again. Don't just remove power when the NAND rom updates are complete as that could corrupt the contents of your microSD card! You are running a Linux system so you don't want to just power down improperly...

----------------------------------- script ----------------------------------

# script to reload the NAND Flash rom with a bootable OS


# reload the boot loader

if [ -e $uboot ]; then
          echo "Erasing u-boot partition ..."
          flash_eraseall /dev/mtd1
          echo "Erasing u-boot environment partition ..."
          flash_eraseall /dev/mtd2
          echo "Writing u-boot to NAND ..."
          nandwrite -p /dev/mtd1 $uboot
          echo "u-boot image has been written to NAND ..."
          echo "ERROR: couldn't find u-boot binary"

# reload the kernel image

if [ -e $uimage ]; then
          echo "Erasing kernel partition ..."
          flash_eraseall /dev/mtd3
          echo "Writing kernel to NAND ..."
          nandwrite -p /dev/mtd3 $uimage
          echo " Kernel image has been written to NAND ..."
          echo "ERROR: couldn't find kernel binary"

# reload the root filesystem

if [ -e $rootfs ]; then
          umount /dev/mtdblock4
          echo "Erasing and formatting rootfs partition ..."
          flash_eraseall -j /dev/mtd4
          echo "Mounting rootfs partition ..."
          mkdir -p /media/mtdblock4
          mount -t jffs2 /dev/mtdblock4 /media/mtdblock4
          cd /media/mtdblock4
          tar xjf $dir/$rootfs
          echo "The rootfs has been written to the NAND ..."
          echo "The NAND restoration is complete ..."
          echo "ERROR: couldn't find rootfs tarball"

# end of script

---------------------------- End of Script --------------------------------

Keeping a bootable microSD card around with a restorable NAND image is not a bad idea. It is always good to have a method of restoring the NAND Rom content - especially if you do a bit of experimentation with the NAND rom content. It is always nice to be able to restore to a known configuration for experimentation. This concept also works if you decide to make changes and modifications to the original Overo BitBake / OpenEmbedded recipes for the omap-desktop-image as you can setup the image to a specific configuration then restore it if something gets trashed. Nice insurance to say the least.

This technique can also be used for major upgrades in the field - just pop in a microSD card with the new images and kernel and let it perform the update itself. You can even automate the update process by having the script start execution as final part of the boot up process to make it totally automatic for the installation process.

If you have ideas or want to leave me a message here.

A second item - I have listed several hardware sites where you can get really good pricing and I make a very small commission from the sale - I realize this seems tacky but I have to do something given the current financial hole I find myself in at the moment.

Third Item:  Here is a link to microSD and microSDHC cards that can be used with the Overo COM computers.  Click Here to Access MicroSD hardware

Thanks for understanding and a Special Thanks to those who help out!

If you would rather have a PDF e-Book on this subject you can find it here:

Overo COM NAND Flash Memory ROM Restoration