UBIFS initial experiments

From OLPC
Revision as of 00:45, 10 October 2008 by Dsaxena (talk | contribs) (New page: == Introduction == In this page I document my steps in creating a release 8.2 image running on top of UBIFS for the purpose of initial experimentation with that file system and point out...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

In this page I document my steps in creating a release 8.2 image running on top of UBIFS for the purpose of initial experimentation with that file system and point out some of my initial findings and questions that have popped up. If you are just interested in downloading and running the final, image jump down to Resulting Image.

Flash Layout

Open Firmware does not support reading from UBIFS so to deal with this, the flash is partitioned into a 32MiB JFFS2 partition with the remainder of the space left over for use by UBI. OFW loads the kernel and initrd from the JFFS2 partition and the initrd handles mounting the UBIFS. Note that one flash erase block dedicated to the RedBoot partition table ("FIS directory" in RedBoot speak).

MTD Partition Location
FIS directory. 0x00000000-0x00020000 (128KiB)
boot 0x00020000-0x02020000 (32Mib)
system 0x02020000-0x3ffc0000 (991.785 MiB)

JFFS2 Partition

The JFFS partition simply contains a boot/ directory with three files: olpc.fth OFW boot script, vmlinuz compressed kernel binary, and olpcrd.img ramdisk image.

olpc.fth

The olpc.fth script simply had the following modification applied to pass the proper boot parameters to the kernel and initrd:

@@ -77,7 +77,7 @@
    then

    " nand"  dn-buf count  sindex  0>=   if
-      " root=mtd0 rootfstype=jffs2"
+      " ubi.mtd=system root=ubi0:rootfs rootfstype=ubifs"
    else
       " root=LABEL=OLPCRoot rootfstype=ext3"
    then

The parameter "ubi.mtd=system" tells the UBI layer to attach to the named MTD device. This creates a new UBI device, ubi0 which contains the root filesystem volume, called "rootfs" The "root=ubi:rootfs" option tells the kernel to mount this volume. (This parameter is actually unused as the initrd handles the mounting of the root filesystem).

olpcrd

The olpcrd is identical to that in the 8.2 release except for the following change to initutil.py:

@@ -134,11 +134,12 @@
                     # when partitioned, expect bootpath like:
                     # /pci/nandflash@c:root,\boot\vmlinuz//jffs2-file-system:\boot\vmlinuz
                     if p is None: p = 0 # unpartitioned by default
-                    if type(p) is int:
-                        dev = 'mtd%d' % p
-                    else:
-                        dev = 'mtd:%s' % p
-                    extra = ['-t','jffs2']
+                    # if type(p) is int:
+                    #    dev = 'mtd%d' % p
+                    # else:
+                    #    dev = 'mtd:%s' % p
+                   dev = 'ubi0:rootfs'
+                   extra = ['-t','ubifs']
             else: # we're running under emulation
                 # these modules only needed if we're running in qemu
                 from stat import S_IFBLK

Note that this is not a permanent solution as we probably want to handle booting the same release on both a JFFS2 and UBIFS layout.

Kernel

The kernel used is available at here. It is composed of the OLPC kernel used for the 8.2 release merged with the linux-2.6.25 UBI backport tree. The kernel is built with UBI and UBIFS built in statically as we are going to be moving away from modules for required features to speed up boot time (see LWN article).

UBI Partition

The UBI system partition contains a single UBI volume named rootfs that covers the full partition minus overhead due to UBI overhead.

The UBIFS image is created via the following command:

/usr/local/bin/mkfs.ubifs -m 2KiB -e 124KiB -x lzo -c 7849 -d system/ -o system_ubifs.img

Where we have the following parameters:

-m 2KiB
The minimum I/O size of the underlying UBI and MTD devices. In our case, we are running the flash with no sub-page writes, so this is a 2KiB page.
-e 124KiB
Erase Block Size: UBI requires 2 minimum I/O units out of each Physical Erase Block (PEB) for overhead: 1 for maintaining erase count information, and 1 for maintaining the Volume ID information. The PEB size for the XO flash is 128KiB, so this leads to each Logical Erase Block (LEB) having 124KiB available for data.
-x lzo
Use LZO compression
-c 7849
The maximum size, in LEBs, of this file system. See calculations below for how this number is determined.
-d system
Use the contents of the system/ directory to generate the initial file system image. In this case the system directory is composed of the contents of the 767 JFFS image.

The output of the above command, system_ubifs.img is fed into the ubinize program to wrap it into a UBI image:

/usr/local/bin/ubinize -o system_ubi.img -m 2KiB -p 128KiB -s 2KiB ubinize.cfg


Resulting Image