(Created page with " == What is Unsorted Block Image (UBI)? == The Unsorted Block Image File System (UBIFS) is designed to operate on raw flash devices. It was first introduced into the 2.6.27 L...")
(Added boot messages)
 
Line 169: Line 169:
  
 
<PRE>
 
<PRE>
 
+
NAND device: Manufacturer ID: 0x98, Chip ID: 0xda (Toshiba NAND 256MiB 3,3V 8-bit)
 +
NAND device: 256MiB, SLC, page size: 2048, OOB size: 64
 +
Scanning device for bad blocks
 +
3 cmdlinepart partitions found on MTD device orion_nand
 +
Creating 3 MTD partitions on "orion_nand":
 +
0x000000000000-0x000000100000 : "uboot"
 +
0x000000100000-0x000000700000 : "uImage"
 +
0x000000700000-0x000010000000 : "root"
 +
UBI: attaching mtd2 to ubi0
 +
UBI: scanning is finished
 +
UBI: attached mtd2 (name "root", size 249 MiB) to ubi0
 +
UBI: PEB size: 131072 bytes (128 KiB), LEB size: 129024 bytes
 +
UBI: min./max. I/O unit sizes: 2048/2048, sub-page size 512
 +
UBI: VID header offset: 512 (aligned 512), data offset: 2048
 +
UBI: good PEBs: 1992, bad PEBs: 0, corrupted PEBs: 0
 +
UBI: user volume: 1, internal volumes: 1, max. volumes count: 128
 +
UBI: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 988891692
 +
UBI: available PEBs: 0, total reserved PEBs: 1992, PEBs reserved for bad PEB handling: 40
 +
UBI: background thread "ubi_bgt0d" started, PID 663
 +
UBIFS: mounted UBI device 0, volume 0, name "rootfs", R/O mode
 +
UBIFS: LEB size: 129024 bytes (126 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
 +
UBIFS: FS size: 249919488 bytes (238 MiB, 1937 LEBs), journal size 9033728 bytes (8 MiB, 71 LEBs)
 +
UBIFS: reserved for root: 0 bytes (0 KiB)
 +
UBIFS: media format: w4/r0 (latest is w4/r0), UUID 57A8A50F-A285-4BB5-A671-651CB920EDDA, small LPT model
 +
VFS: Mounted root (ubifs filesystem) readonly on device 0:11.
 
</PRE>
 
</PRE>

Latest revision as of 14:05, 13 April 2014

What is Unsorted Block Image (UBI)?

The Unsorted Block Image File System (UBIFS) is designed to operate on raw flash devices. It was first introduced into the 2.6.27 Linux Kernel in October 2008.

UBIFS works on an Unsorted Block Image (UBI) device which provides tracking of bad flash blocks and wear leveling. UBI works on top of MTD.

For further information see :

Obtaining details of the Flash Device

Before we can start building UBIFS and UBI images, we need to know details of the flash device fitted on the Seagate GoFlex Home. This can be achieved by running mtdinfo -a on our target device, i.e. the GoFlex Home.

Pay particular attention to the Eraseblock size, Sub-page size, Minimum input/output unit size and the number of eraseblocks for the partition where our UBIFS will reside.

# mtdinfo -a
Count of MTD devices:           3
Present MTD devices:            mtd0, mtd1, mtd2
Sysfs interface supported:      yes

mtd0
Name:                           uboot
Type:                           nand
Eraseblock size:                131072 bytes, 128.0 KiB
Amount of eraseblocks:          8 (1048576 bytes, 1024.0 KiB)
Minimum input/output unit size: 2048 bytes
Sub-page size:                  512 bytes
OOB size:                       64 bytes
Character device major/minor:   90:0
Bad blocks are allowed:         true
Device is writable:             true

mtd1
Name:                           uImage
Type:                           nand
Eraseblock size:                131072 bytes, 128.0 KiB
Amount of eraseblocks:          48 (6291456 bytes, 6.0 MiB)
Minimum input/output unit size: 2048 bytes
Sub-page size:                  512 bytes
OOB size:                       64 bytes
Character device major/minor:   90:2
Bad blocks are allowed:         true
Device is writable:             true

mtd2
Name:                           root
Type:                           nand
Eraseblock size:                131072 bytes, 128.0 KiB
Amount of eraseblocks:          1992 (261095424 bytes, 249.0 MiB)
Minimum input/output unit size: 2048 bytes
Sub-page size:                  512 bytes
OOB size:                       64 bytes
Character device major/minor:   90:4
Bad blocks are allowed:         true
Device is writable:             true

Building an UBIFS

Make a ZLIB compressed (-x zlib) UBI filesystem image with a minimum I/O unit size of 2048 bytes (-m 2048), a logical erase block (LEB) size of 131072 bytes and a maximum logical erase block count of 1992:

# mkfs.ubifs -v -x zlib -m 2048 -e 129024 -c 1992 -r rootfs/ rootfs.ubifs.img
mkfs.ubifs
	root:         rootfs/
	min_io_size:  2048
	leb_size:     129024
	max_leb_cnt:  1992
	output:       rootfs.ubifs.img
	jrn_size:     8388608
	reserved:     0
	compr:        zlib
	keyhash:      r5
	fanout:       8
	orph_lebs:    1
	space_fixup:  0
	super lebs:   1
	master lebs:  2
	log_lebs:     5
	lpt_lebs:     2
	orph_lebs:    1
	main_lebs:    459
	gc lebs:      1
	index lebs:   11
	leb_cnt:      470
	UUID:         57A8A50F-A285-4BB5-A671-651CB920EDDA
Success!

Building an UBI Image

Next, we build an UBI image containing the above filesystem as one volume. Create a configuration file called ubi.cfg containing the following :

[ubifs]
mode=ubi
image=rootfs.ubifs.img
vol_id=0
vol_size=200MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize
# ubinize -v -o rootfs.ubi.img -m 2048 -p 128KiB -s 512 -O 512 ubi.cfg
ubinize: LEB size:                  129024
ubinize: PEB size:                  131072
ubinize: min. I/O size:             2048
ubinize: sub-page size:             512
ubinize: VID offset:                512
ubinize: data offset:               2048
ubinize: UBI image sequence number: 1674295640
ubinize: loaded the ini-file "ubi.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: 209715200 bytes
ubinize: volume name: rootfs
ubinize: volume alignment: 1
ubinize: autoresize flags found
ubinize: adding volume 0
ubinize: writing volume 0
ubinize: image file: rootfs.ubifs.img

ubinize: writing layout volume
ubinize: done

Flashing

It is advisable not to use nandwrite to flash an UBI image. For more information, see here.

The recommended method is to use ubiformat as this not only preserves the erase counters used for wear leveling, it prevents ECC errors on some NAND flash devices.

ubiformat is not available from the bootloader, thus you need to undertake this task on a bootable GoFlex Home. I normally boot using root NFS to carry out this operation.

From the shell on the GoFlex Home:

# flash_erase /dev/mtd2 0 0 
# ubiformat /dev/mtd2 -s 512 -O 512 -f rootfs.ubi.img

Testing

You can test an newly flashed image prior to loading it as the root filesystem (i.e. while using root NFS).

First attach the desired MTD partition to UBI using the ubiattach command. Once this is successful, you can mount the UBIFS.

ubiattach -p /dev/mtd2
mount -t ubifs /dev/ubi0_0 /mnt/ubifs/

Boot Messages

Below is the kernel messages of a system booting from the above UBIFS :

NAND device: Manufacturer ID: 0x98, Chip ID: 0xda (Toshiba NAND 256MiB 3,3V 8-bit)
NAND device: 256MiB, SLC, page size: 2048, OOB size: 64
Scanning device for bad blocks
3 cmdlinepart partitions found on MTD device orion_nand
Creating 3 MTD partitions on "orion_nand":
0x000000000000-0x000000100000 : "uboot"
0x000000100000-0x000000700000 : "uImage"
0x000000700000-0x000010000000 : "root"
UBI: attaching mtd2 to ubi0
UBI: scanning is finished
UBI: attached mtd2 (name "root", size 249 MiB) to ubi0
UBI: PEB size: 131072 bytes (128 KiB), LEB size: 129024 bytes
UBI: min./max. I/O unit sizes: 2048/2048, sub-page size 512
UBI: VID header offset: 512 (aligned 512), data offset: 2048
UBI: good PEBs: 1992, bad PEBs: 0, corrupted PEBs: 0
UBI: user volume: 1, internal volumes: 1, max. volumes count: 128
UBI: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 988891692
UBI: available PEBs: 0, total reserved PEBs: 1992, PEBs reserved for bad PEB handling: 40
UBI: background thread "ubi_bgt0d" started, PID 663
UBIFS: mounted UBI device 0, volume 0, name "rootfs", R/O mode
UBIFS: LEB size: 129024 bytes (126 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
UBIFS: FS size: 249919488 bytes (238 MiB, 1937 LEBs), journal size 9033728 bytes (8 MiB, 71 LEBs)
UBIFS: reserved for root: 0 bytes (0 KiB)
UBIFS: media format: w4/r0 (latest is w4/r0), UUID 57A8A50F-A285-4BB5-A671-651CB920EDDA, small LPT model
VFS: Mounted root (ubifs filesystem) readonly on device 0:11.