world leader in high performance signal processing
Trace: » ubifs

Unsorted Block Image File System (UBIFS)

Since YAFFS is not so good with large devices (such as NAND), the UBIFS project was started. While it can be used on many flash devices, it is commonly seen when working with NAND flashes.

The UBIFS homepage can be found at http://www.linux-mtd.infradead.org/doc/ubi.html.

Partitioning

The method for managing MTD partition tables is documented in the Partitioning document. Here we will focus on just using the default partition scheme .

Kernel Settings

Please consult the MTD document for relevant kernel settings for the higher MTD layers. If you plan on using UBIFS, these options will need be built into your kernel.

You will also need enable support for the UBIFS filesystem itself.

Device Drivers   --->
  Memory Technology Device(MTD) support  --->
    UBI - Unsorted block images --->
      <*> Enable UBI
      <*> MTD devices emulation driver(gluebi)(NEW)
File systems   --->
  Miscellaneous filesystems  --->
    <*> UBIFS file system support

uClinux-dist Settings

Root file systems image rootfs.ubifs will automatically be created for you when you enable UBIFS support in your kernel. See the images document for more information.

If you wish to create your own file system images, just use the mkfs.ubifs program. Once you've compiled the uClinux distribution, you can find it under user/mtd-utils/mkfs.ubifs. Make sure you use the right parameter for your NAND. Here on bf548 ezkit, we use UBIFS_LEB_SIZE 129024, which can be read from the output of ubiattach command.

mkfs.ubifs --squash-uids -m 2048 -e 129024 -c 1024 -d romfs -D device_table-min.txt -o images/rootfs.ubifs

And you need select some other utilities for ubifs to operate on nand flash.

Flash Tools  --->
  mtd-utils  --->
    [*] ubifs utilities

Kernel Messages

In the kernel log we see the NAND device and its partitions being detected on the BF548-EZKIT:

BF5xx on-chip NAND FLash Controller Driver, Version 1.2 (c) 2007 Analog Devices, Inc.
bf5xx-nand bf5xx-nand.0: page_size=256, data_width=8, wr_dly=3, rd_dly=3
NAND device: Manufacturer ID: 0x20, Chip ID: 0xda (ST Micro NAND 256MiB 3,3V 8-bit)
Creating 2 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x00000000-0x00400000 : "Linux Kernel"
0x00400000-0x10000000 : "File System"

Formatting under the Blackfin

Creating UBIFS filesystems on the Blackfin board needs following steps.

  • Check the partition table:
    root:/> cat /proc/mtd
    dev:    size   erasesize  name
    mtd0: 00040000 00020000 "bootloader(nor)"
    mtd1: 00400000 00020000 "linux kernel(nor)"
    mtd2: 00bc0000 00020000 "file system(nor)"
    mtd3: 00400000 00020000 "linux kernel(nand)"
    mtd4: 0fc00000 00020000 "file system(nand)"
    mtd5: 00040000 00010000 "bootloader(spi)"
    mtd6: 001c0000 00010000 "linux kernel(spi)"
  • read ubi info by using ubinfo.
    root:/> ubinfo
    UBI version:                    1
    Count of UBI devices:           0
    UBI control device major/minor: 10:62
  • After recognizing this device, do ubiformat to define the format that this nand flash needs. Different flash has different page size, it must match the designed usage.
root:/> ubiformat /dev/mtd4 -s 512 -O 512 
ubiformat: mtd4 (NAND), size 264241152 bytes (252.0 MiB), 131072 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
...
  • Attach the mtd partition 4 file system(nand) to ubi device /dev/ubi_ctrl:
    root:/> ubiattach /dev/ubi_ctrl -m 4 
    UBI: attaching mtd4 to ubi0
    UBI: physical eraseblock size:   131072 bytes (128 KiB)
    UBI: logical eraseblock size:    129024 bytes
    UBI: smallest flash I/O unit:    2048
    UBI: sub-page size:              512
    UBI: VID header offset:          512 (aligned 512)
    UBI: data offset:                2048
    UBI: attached mtd4 to ubi0
    UBI: MTD device name:            "file system(nand)"
    UBI: MTD device size:            252 MiB
    UBI: number of good PEBs:        2016
    UBI: number of bad PEBs:         0
    UBI: max. allowed volumes:       128
    UBI: wear-leveling threshold:    4096
    UBI: number of internal volumes: 1
    UBI: number of user volumes:     0
    UBI: available PEBs:             1992
    UBI: total number of reserved PEBs: 24
    UBI: number of PEBs reserved for bad PEB handling: 20
    UBI: max/mean erase counter: 8/2
    UBI: image sequence number: 0
    UBI: background thread "ubi_bgt0d" started, PID 346
    UBI device number 0, total 2016 LEBs (260112384 bytes, 248.1 MiB), available 1992 LEBs (257015808 bytes, 245.1 MiB), LEB size 129024 bytes (126.0 KiB)
  • make volumn:
    root:/> ubimkvol /dev/ubi0 -s 20MiB -N ubifs0 
    Volume ID 0, size 163 LEBs (21030912 bytes, 20.1 MiB), LEB size 129024 bytes (126.0 KiB), dynamic, name "ubifs0", alignment 1
    root:/> Make first volumn on ubi0 divice, its filesystem named ubifs0.
  • Then check the partition table again, you will see one more line shown:
    root:/> cat /proc/mtd
    dev:    size   erasesize  name
    mtd0: 00040000 00020000 "bootloader(nor)"
    mtd1: 00400000 00020000 "linux kernel(nor)"
    mtd2: 00bc0000 00020000 "file system(nor)"
    mtd3: 00400000 00020000 "linux kernel(nand)"
    mtd4: 0fc00000 00020000 "file system(nand)"
    mtd5: 00040000 00010000 "bootloader(spi)"
    mtd6: 001c0000 00010000 "linux kernel(spi)"
    mtd7: 0140e800 0001f800 "ubifs0"

    Attention, here this feature needs above MTD devices emulation driver(gluebi) feature is configured.

  • Mount as UBIFS:
    root:/> mount -t ubifs ubi0:ubifs0 /mnt
    UBIFS: default file-system created
    UBIFS: mounted UBI device 0, volume 0, name "ubifs0"
    UBIFS: file system size:   19869696 bytes (19404 KiB, 18 MiB, 154 LEBs)
    UBIFS: journal size:       1032193 bytes (1008 KiB, 0 MiB, 8 LEBs)
    UBIFS: media format:       w4/r0 (latest is w4/r0)
    UBIFS: default compressor: lzo
    UBIFS: reserved for root:  938494 bytes (916 KiB)
    root:/> cp /bin/pwd /mnt
    root:/> while [ 1 ]; do md5sum /mnt/pwd ; done
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    ...
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    606173cda24b6b309137a19963b473f7  /mnt/pwd
    ^C
    
    root:/> umount /mnt
    UBIFS: un-mount UBI device 0, volume 0
  • You can also flash the rootfs.ubifs into another nand ubifs1 by using ubiupdatevol :
    root:/> ubimkvol /dev/ubi0 -s 20MiB -N ubifs1 
    Volume ID 1, size 163 LEBs (21030912 bytes, 20.1 MiB), LEB size 129024 bytes (126.0 KiB), dynamic, name "ubifs1", alignment 1
    root:/> ubiupdatevol /dev/ubi0_1 rootfs.ubifs 
  • After all, remember do deattach the mtd partition from ubi device /dev/ubi_ctrl:
    ubidetach /dev/ubi_ctrl -m 4
    UBI: mtd4 is detached from ubi0

If you want to use this ubifs partition to boot up kernel as rootfs, then in u-boot use bootargs like following.( here the example is on bf548 ezkit, adjust the proper serial port for other boards)

 set bootargs ubi.mtd=4 root=ubi0:ubifs1 rw rootfstype=ubifs earlyprintk=serial,uart1,57600 console=ttyBF1,57600


The bootup message is like:

BF5xx on-chip NAND FLash Controller Driver, Version 1.2 (c) 2007 Analog Devices, Inc.
bf5xx-nand bf5xx-nand.0: page_size=256, data_width=8, wr_dly=3, rd_dly=3
NAND device: Manufacturer ID: 0x20, Chip ID: 0xda (ST Micro NAND 256MiB 3,3V 8-bit)
Creating 2 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x000000000000-0x000000400000 : "linux kernel(nand)"
0x000000400000-0x000010000000 : "file system(nand)"
UBI: attaching mtd4 to ubi0
UBI: physical eraseblock size:   131072 bytes (128 KiB)
UBI: logical eraseblock size:    129024 bytes
UBI: smallest flash I/O unit:    2048
UBI: sub-page size:              512
UBI: VID header offset:          512 (aligned 512)
UBI: data offset:                2048
ata1.00: ATA-6: TOSHIBA MK4032GAX, AD101A, max UDMA/100
ata1.00: 78140160 sectors, multi 16: LBA48 
ata1.00: configured for UDMA/66
blk_queue_max_hw_segments: set to minimum 1
scsi 0:0:0:0: Direct-Access     ATA      TOSHIBA MK4032GA AD10 PQ: 0 ANSI: 5
sd 0:0:0:0: [sda] 78140160 512-byte logical blocks: (40.0 GB/37.2 GiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
 sda: sda1 sda2
sd 0:0:0:0: [sda] Attached SCSI disk
UBI: attached mtd4 to ubi0
UBI: MTD device name:            "file system(nand)"
UBI: MTD device size:            252 MiB
UBI: number of good PEBs:        2016
UBI: number of bad PEBs:         0
UBI: max. allowed volumes:       128
UBI: wear-leveling threshold:    4096
UBI: number of internal volumes: 1
UBI: number of user volumes:     2
UBI: available PEBs:             1666
UBI: total number of reserved PEBs: 350
UBI: number of PEBs reserved for bad PEB handling: 20
UBI: max/mean erase counter: 11/2
UBI: image sequence number: 0
UBI: background thread "ubi_bgt0d" started, PID 232
...
UBIFS: mounted UBI device 0, volume 1, name "ubifs1"
UBIFS: file system size:   19611648 bytes (19152 KiB, 18 MiB, 152 LEBs)
UBIFS: journal size:       9033728 bytes (8822 KiB, 8 MiB, 71 LEBs)
UBIFS: media format:       w4/r0 (latest is w4/r0)
UBIFS: default compressor: lzo
UBIFS: reserved for root:  0 bytes (0 KiB)
VFS: Mounted root (ubifs filesystem) on device 0:12.
...