JFFS2 images over UBI layer

From Compulab Mediawiki
Revision as of 12:31, 1 July 2009 by Mike (talk | contribs) (1 revision(s))
Jump to: navigation, search

On this page we assume, that you have MTD utils installed as described in Linux Development for XScale modules article.

Kernel support

In order to get UBI and UBI GLUE driver working you need to enable them in kernel configuration. In kernel configuration choose "Device Drivers -> Memory Technology Device (MTD) support -> UBI - Unsorted block images" menu and enable "Enable UBI" and "Emulate MTD devices" options.

┌─────────────────────────────────── UBI - Unsorted block images ────────────────────────────────────┐
│  Arrow keys navigate the menu.  <Enter> selects submenus --->.  Highlighted letters are hotkeys.   │
│  Pressing <Y> includes, <N> excludes, <M> modularizes features.  Press <Esc><Esc> to exit, <?> for │
│  Help, </> for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < > module capable         │
│                                                                                                    │
│ ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ │
│ │             <*> Enable UBI                                                                     │ │
│ │             (4096) UBI wear-leveling threshold (NEW)                                           │ │
│ │             (1)   Percentage of reserved eraseblocks for bad eraseblocks handling (NEW)        │ │
│ │             [*]   Emulate MTD devices                                                          │ │
│ │                   *** UBI debugging options ***                                                │ │
│ │             [ ]   UBI debugging (NEW)                                                          │ │
│ │                                                                                                │ │
│ └────────────────────────────────────────────────────────────────────────────────────────────────┘ │
├────────────────────────────────────────────────────────────────────────────────────────────────────┤
│                                  <Select>    < Exit >    < Help >                                  │
└────────────────────────────────────────────────────────────────────────────────────────────────────┘

Now you can build the kernel with UBI support including the UBI GLUE driver.

User space tools

In this section we will use X as the MTD partition number attached to UBI, Y as the emulated MTD partition number and we assume that there were no MTD partitions attached to UBI before.
To prepare the NAND for use with UBI, you should take the following steps:

  • Erase the MTD partition that will be used for UBI volume(s):
> flash_eraseall /dev/mtdX
  • Attach the MTD partition to UBI:
> ubiattach /dev/ubi_ctrl -m X -O 2048
  • Create UBI volume:
> ubimkvol /dev/ubi0 -m -N <ubi volume name>
  • Update the new UBI volume with JFFS2 image:
> ubiupdatevol /dev/ubi0_0 <path to JFFS2 image>

If you want to use the new UBI volume as the root filesystem on your device, you should change the root parameter of kernel command line to boot from emulated MTD partition Y (which is UBI volume): root=/dev/mtdblockY and add ubi.mtd=X,2048 parameter, so the MTD partition containing the new UBI volume will be attached on kernel boot prior to root filesystem mount.

JFFS2 image eraseblock size

UBI layer is using some part of NAND's physical erase block for it's own needs (e.g. bad blocks handling), therefore it provides a logical eraseblock for filesystem use. The logical eraseblock size is smaller than the physical, so when you construct the JFFS2 image, as described in section JFFS2 images, you should set the eraseblock parameter to UBI's logical eraseblock size.
The UBI logical eraseblock size can be obtained by invoking the command:

> cat /sys/class/ubi/ubiX/eraseblock_size

Where X is the UBI device number.

See also