UBI FS by chrisatds


									UBI – Unsorted Block Images
        Artem Bityutskiy <artem.bityutskiy@nokia.com>

• A new technology for flash devices
• Designed by IBM
• Publicly accessible Git tree
• GPL license
• More information at www.linux-mtd.infradead.org

1. Linux MTD overview
2. UBI overview
Linux MTD overview
                              MTD overview
• MTD stands for Memory Technology Devices
• MTD is a Linux subsystem (drivers/mtd/)
• MTD provides uniform access to various flash devices
• MTD provides a generic API for that
• MTD provides an “MTD device” abstraction

             JFFS2         character device (/dev/mtd0)

                               MTD device, MTD API

          NAND    NOR     DataFlash     AG-AND      OneNAND   ECC’d NOR
                                             MTD device

• MTD device consists of eraseblocks
• Eraseblock size varies, typically 32-128 Kilobytes
• Eraseblocks may be written to , but not re-written
• Whole eraseblock has to be erased first
• Then it is possible to write there





  Eraseblock, 128K


                                             MTD device
                        MDT device vs Block device

Block device                                    MTD device
• Consists of sectors                           • Consists of eraseblocks
• Sectors are small (512, 1024 bytes)           • Eraseblocks are larger (32-128 Kilobytes)
• 2 operations: read and write                  • 3 operations: read, write and erase
• Bad sectors are hidden by hardware            • Bad eraseblocks are not hidden
• Sectors do not get worn out                   • Eraseblocks get worn-out after 104-105

                        MTD device is more difficult to handle
                                   MTD partitions

• Flash chip may be split on several MTD partitions
• MTD partition is a set of consecutive eraseblocks
• MTD partitions is a physical flash area

      Partition 1 (e.g., initfs)             Partition 2 (e.g., rootfs)   … so on

                     Drawbacks of MTD partitions

• MTD partitions are static – now way to change them “on-flight”
• Do not provide wear-leveling for the whole chip



               Partition 1                      Partition 2
                                                Bad blocks
UBI overview
        UBI layer

Flash File System (e.g., UBIFS)

          UBI layer

          MTD layer


          Physical flash
                             Logical Volumes

• UBI provides logical volumes instead of MTD partitions
• UBI volumes are in a way similar to LVM volumes
• UBI volumes may be dynamically created, deleted and re-sized

       Volume A             Volume B
                        Volume B               Volume C    Volume C

   … and so on “C”“C”40logical logical eraseblocks
   Delete volume B “B” - size 20 eraseblock
   Re-size volume “A” – logical logical eraseblocks
    Re-size volume to
   Create UBI volume to 10 size 15 eraseblocks

                                MTD device (physical

• UBI does wear-leveling across whole MTD device!
• Wear-leveling is done by UBI, not by the UBI user!


   Boot volume            RootFS volume                    DataStorage volume

                             MTD device (physical flash)
                     UBI volume vs. MTD partition

              MTD partition                                     UBI volume

• Consists of physical eraseblocks (PEB)        • Consists of logical eraseblocks (LEB)
• Does not implement wear-leveling              • Implements wear-leveling
• Admits of bad PEBs                            • Devoid of bad LEBs

                                   Advantages of UBI

• Allows dynamic volume creation, deletion and re-sizing  more flexibility
• Eliminates the “wear” problem  simpler software
• Eliminates bad eraseblocks problem  simpler software
                                       How it works

• LEBs are mapped to PEBs
• Any LEB may be mapped to any PEB

                                             Return 0xFFs

                     Static Volume A data                            Volume B

             LEB 0 LEB 1 LEB 2 LEB 3        LEB 4           LEB 0 LEB 1 LEB 2

      UBI layer

      PEB 0 PEB 1 PEB 2 PEB 3 PEB 4 PEB 5 PEB 6 PEB 7 PEB 8 PEB 9 PEB 10

                          Re-map LEB
                          Move data
 Low erase counter
                                         MTD High erase counter
                             Bad eraseblocks handling

• UBI volumes are devoid of bad eraseblocks
• UBI does proper error recovery transparently

       Write more data

 The data have been successfully written!

                                                            An UBI volume

                                                   Re-map the LEB to to PEB
                                                  Write newcoming datathisthis PEB

                    Partially filled
               Mark this PEB s bad                                 Bad physical      Empty physical
      No panic!physical eraseblock become PEB
                Recover the data to
      Write error! The eraseblock’s a good bad!                     eraseblock        Eraseblock
                               UBI interfaces

•   UBI character devices:
    1. /dev/ubi0, /dev/ubi1, … – UBI devices: volume create, delete, re-size, and get
       device description operations
    2. /dev/ubi0_0, /dev/ubi0_1, … - UBI volumes: read, write, update, and get
       volume description operations
•   UBI sysfs interface: /sys/class/ubi
•   UBI in-kernel interface: include/linux/mtd/ubi.h
                       Volume update operation

• Useful for software updates
• Volume is in “corrupted” state if update is interrupted
• “Corrupted” volumes are not usable and must be updated
                Static and dynamic UBI volumes

• Dynamic volumes are read-write
• Static volumes are read-only
• Static volumes are protected by CRC-32 checksum

To top