All Forums
 Embedded Linux
 Linux FAQ
 Updating on-board flash while running Linux
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

jmalone

61 Posts

Posted - 26 Oct 2004 :  11:07:42  Show Profile  Email Poster
How can I update my kernel and root file system while linux is running on my board?

On-board flash memory is used to store programs and data. Typically the flash is aranged into several partitions where the first partition is the bootloader, the second is the kernel and the third is the root file system. The root file system can have different formats including a ramdisk, CRAMFS and JFFS2. The layout of the on-board flash partitions is usually defined by the 'mtdparts' kernel parameter which is described in more detail in this topic.


Updating the kernel (zImage) partition

    The program 'zImage_util' can read and write the zImage, cmdline.txt and register.txt files in the zImage partition.

    zImage_util -r will read the cmdline.txt, register.txt and zImage from the MTD partition and copy them into the current directory. After running zImage_util -r you should have 3 new files in your current directory:

    • cmdline.txt
    • register.txt
    • zImage

    zImage_util -w will write new files (from your current directory) into the zImage partition. If you are not storing a kernel command line or register settings, zImage_util will complain about missing register.txt or cmdline.txt files and create blank ones in their place.

    For example, to install a new zImage, cmdline.txt and register.txt while running the current Debian ramdisk, type:

      zImage_util -w

    You should see the following output:

      Erasing zImage partition /dev/mtdc2 ... done.
      Writing zImage partition /dev/mtdc2 ... done.

    See the output of zImage_util -h for more options.

    The zImage_util binary is on our root filesystems in /sbin. If you do not have zImage_util on your filesystem, it is available here.
    The source for zImage_util is available here.

Updating the ramdisk.gz partition

    Since a ramdisk is copied into memory before it is mounted, you can update a ramdisk partition while the ramdisk is in use, as the flash itself is not actually being used at that time.

    To update the ramdisk.gz partition, first erase it by running:

      eraseall /dev/mtd2

    and then write the new ramdisk.gz into that partition by running:

      dd if=ramdisk.gz of=/dev/mtdblock2


Updating a JFFS2 flash filesystem

    JFFS2 (journalling flash file system, version 2) is a compressed file system designed for use on flash memory. It is a load leveling file system that avoids burning out some sections of flash before others when writing to flash memory but does not compress as well as cramfs.

    To update a JFFS2 filesystem while Linux is running, you have two options:

    • Replace individual files while the JFFS2 is mounted

    • Since JFFS2 is a writable filesystem, you can make changes to it as you would any normal Linux filesystem.

      If the filesystem is mounted and in use, you may be unable to replace certain files. One way to work around this is to move ('mv') the file to another location or filename (for example, oldname.deleteme) and copy in the new file. After rebooting the system, you can then delete all of the *.deleteme files. Note, however, that JFFS2 is a journalling filesystem, and using this technique to replace a large number of files may adversely affect the performance of your filesystem (and significantly increase the time it takes to mount the filesystem).

      To safely update all files on a JFFS2 filesystem, you should employ one of the strategies detailed in the next section.


    • Unmount the JFFS2 filesystem and replace the entire filesystem with a new image

    • With the MTD partition unmounted, you can update a JFFS2 filesystem by running

        eraseall /dev/mtd2
        dd if=/path/to/new_image of=/dev/mtdblock2


    If the JFFS2 partition is your root filesystem, you will need to employ some sort of alternate root filesystem during the update. For this, there are several attractive alternatives availble:

    • Using a temporary ramdisk

    • A small ramdisk could be stored in a flash partition for use while updating a JFFS2 partition. The ramdisk would need to have only enough functionality to retrieve a flash image (i.e., from the network), erase the JFFS2 partition and program the new image (using 'dd').


    • Using dual JFFS2 partitions

    • An alternate flash updating scheme is to employ 2 JFFS2 partitions, allowing you to update one while running the other.

      For example, if you are running with mtdblock2 as your root filesystem, when you want to update your root, you can program the new image into mtdblock3 and then switch your root filesystem to mtdblock3 when you reboot (using zImage_util to program the new cmdline.txt specifying /dev/mtdblock3 as the root device). The next time you update, the process would be reversed (program and switch to /dev/mtdblock2).

      The primary drawback to this method is that you effectively cut your usable flash in half because you have to have enough room to hold your root filesystem twice. However, if your root filesystem is small enough, this method is simple to employ.


    When retrieving a filesystem image from the network, you may be able to use a RAMFS filesystem to temporarily hold the new image while progamming it, assuming you have sufficient free RAM. Also, your update script should check the image file's integrity using 'md5sum' or other such mechanism before erasing and programming flash.

    Note: when creating a JFFS2 filesystem the erase size is 0x40000 - this is the 256k block size for the flash chips.


Updating a CRAMFS filesystem
    The cramfs file system is a compressed, read only file system residing in on-board flash. The contents of a CRAMFS filesystem can only be altered by replacing the entire image.

    Since you cannot reprogram a CRAMFS partition while it is mounted and in use, you will need to employ one of the alternate root filesystem techniques discussed above in 'Updating a JFFS2 filesystem'. With the CRAMFS partition unmounted, you can reprogram the MTD partition by running

      eraseall /dev/mtd2
      dd if=/path/to/new_image of=/dev/mtdblock2

jmalone

61 Posts

Posted - 26 Oct 2004 :  14:31:04  Show Profile  Email Poster
As an example, here is a bash script designed to update a JFFS2 root filesystem by switching between 2 MTD partitions (updating one while running the other).

flash_reload.sh

This script is designed to pull files from an NFS server, check that they were copied correctly (using md5sum) and then program them to flash. A RAMFS is used to hold the files while they are being checksummed.

The command line for this setup splits the flash into 2 roughly equal partitions with this mtdparts section:
    mtdparts=pxa:256k(adslinux.rom)ro,1536k(zImage),14848k(flashfs1),-(flashfs2)
Go to Top of Page

rwhaley

628 Posts

Posted - 28 Aug 2007 :  17:18:37  Show Profile  Email Poster
Newer boards use the flash_eraseall command instead of the erase or eraseall command.

Newer boards do not use zImage_util, instead the zImage file can be copied directly to the appropriate mtd partiton.

For example on a BitysyXb, to replace the zImage:

flash_eraseall /dev/mtd2
cp zImage /dev/mtd2
Go to Top of Page

adrian

17 Posts

Posted - 14 Jan 2008 :  13:15:00  Show Profile  Email Poster
Newer releases of zImage_util can be installed using the following command:

apt-get install zimage-util

Note that the installation directory is no longer /sbin. The current path can be determined by running:

dpkg -L zimage-util
Go to Top of Page
  Topic  
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.03 seconds. Snitz Forums 2000