Wednesday, August 10, 2011

Using UBIFS with CRAMFS(2)

As emphasized here, there is better (faster) method of creating UBI file system on our FLASH. We can prepare UBI volume image file with mkfs.ubifs + ubinize and populate it to our FLASH when we format the memory with ubiformat.

First create a ubi file system image with mkfs.ubifs

$ cd /home/user/nfsroot/usr
$ mkfs.ubifs -v -q -r local -m 2048 -e 258048 -c 4020 -o usrlocal.ubifs

mkfs.ubifs
      root:        local/
      min_io_size: 2048
      leb_size:    258048
      max_leb_cnt: 4020
      output:      usrlocal.ubifs
      jrn_size:    8388608
      reserved:    0
      compr:       lzo
      keyhash:     r5
      fanout:      8
      orph_lebs:   1
      super lebs:  1
      master lebs: 2
      log_lebs:    4
      lpt_lebs:    2
      orph_lebs:   1
      main_lebs:   206
      gc lebs:     1
      index lebs:  5
      leb_cnt:     216
      UUID:        910D9091-011A-4F91-AAE8-A70F1930CA08
Success!

Note that the parameter values should match with the ones we would get when we execute ubiattach on our device, such as minimum I/O unit size, size of logical erase block, maximum logical erase block count. Please refer to the previous post.

Next, we can create a ubi volume image from the file system image (usrlocal.ubifs) just created. To do that, we need to prepare configuration file, ubinize.cfg:

[ubifs]
mode=ubi
image=usrlocal.ubifs
vol_id=0
vol_type=dynamic
vol_name=usrlocal
vol_flag=autoresize

The reason we need this is that the ubinize is designed to create multiple, heterogeneous file system on a same volume image. So, fire up ubinize to create a volume image :

$ ubinize -v -o usrlocal.ubi -m 2048 -p 256KiB ubinize.cfg

ubinize: LEB size: 258048
ubinize: PEB size: 262144
ubinize: min. I/O size: 2048
ubinize: sub-page size: 2048
ubinize: VID offset: 2048
ubinize: data offset: 4096
ubinize: UBI image sequence number: 2101116498
ubinize: loaded the ini-file "ubinize.cfg"
ubinize: count of sections: 1

ubinize: parsing section "ubifs"
ubinize: mode=ubi, keep parsing
ubinize: volume type: dynamic
ubinize: volume ID: 0
ubinize: volume size was not specified in section "ubifs", assume minimum ...
ubinize: volume name: usrlocal
ubinize: volume alignment: 1
ubinize: autoresize flags found
ubinize: adding volume 0
ubinize: writing volume 0
ubinize: image file: usrlocal.ubifs

ubinize: writing layout volume
ubinize: done

Note here that the -p parameter value denotes the physical erase block size, which is different from the logical erase block size.

Now, put this ubi volume image (usrlocal.ubi) to SD card, mount it on our device to be available for ubiformat.

At the device side, unmount and detach the partition first if the ubi partition is attached and mounted as previous post:

# umount /usr/local
# ubidetach /dev/ubi_ctrl -d 0

All we have to do is just execute ubiformat utility with the prepared volume image

# ubiformat -y /dev/mtd3 -f /mnt/sdcard/usrlocal.ubi

ubiformat: warning!: your MTD system is old and it is impossible to detect ...
ubiformat: assume sub-page to be 2048
ubiformat: mtd3 (nand), size 1065353216 bytes (1016.0 MiB), 4064 eraseblocks ...
libscan: scanning eraseblock 4063 -- 100 % complete
ubiformat: 4064 eraseblocks have valid erase counter, mean value is 1
ubiformat: flashing eraseblock 217 -- 100 % complete
ubiformat: formatting eraseblock 4063 -- 100 % complete

Here we assume that the target partition is /dev/mtd3 and the ubi volume image is located at /mnt/sdcard. The warnig message about sub-page size is because we use MLC FLASH which has no sub-page.

And that's it!. UBI volume is just created with formatting. We can attach and mount the volume as before:

# ubiattach /dev/ubi_ctrl -m 3
# mount -t ubifs ubi0:usrlocal /usr/local

No comments:

Post a Comment