linux booting on ubifs partitions

November 8, 2010

[Warning: This post is a backup recovery from my previous Wordpress blog. All content was automatically converted accessing a MySQL database using a Python script (details). Mostly are in Portuguese but if you are interest I can translate to English. If you found any problem dont’t hesitate to contact me in comments.]

UBIFS is relatively new on embedded systems but my guess is that they'll become the standard on embedded market. To start, the first step is enable UBIFS support in kernel. I exaggerated on some debug options, fell free to avoid:

CONFIG_MTD_UBI=y CONFIG_MTD_UBI_WL_THRESHOLD=4096 CONFIG_MTD_UBI_BEB_RESERVE=1 CONFIG_MTD_UBI_DEBUG=y CONFIG_MTD_UBI_DEBUG_MSG=y CONFIG_UBIFS_FS=y CONFIG_UBIFS_FS_LZO=y CONFIG_UBIFS_FS_ZLIB=y

Next I used a simple rootfs - basically busybox + mtd-utils - to create/format the partitions, suppose that you kernel divided the memory in the following parts:

# cat /proc/mtd mtd0: 00300000 00020000 "bootloader" * mtd1: 00500000 00020000 "nand.kernel" ** mtd2: 00100000 00020000 "nand.ramdisk" mtd3: 06400000 00020000 "nand.system"

*,** The bootloader and nand.kernel I flashed via u-boot.

  1. The first time

This is only needed when you create the partition for the first time. Steps are erasing the flash, detaching the UBI [if it was previously attached], format on UBI model, attach again, creating the volume (specifying a name) and finally mounting.

flash_eraseall /dev/mtd3

ubidetach /dev/ubi_ctrl -m 3
ubiformat /dev/mtd3 -y
ubiattach /dev/ubi_ctrl -m 3
ubimkvol /dev/ubi0 -N system -m
mount -t ubifs ubi0:system /mnt/ubi

[ copy your rootfs ]

umount /mnt/ubi

system is the name that I choose for partition, could be any.

  1. Editing

Suppose that you need edit some files on your UBIFS , then you only need:

ubiattach /dev/ubi_ctrl -m 3
mount -t ubifs ubi0:system /mnt/ubi
  1. Boot

In order to boot, you need add some parameters to u-boot.

setenv bootargs 'console=ttymxc0,115200 rootfstype=ubifs ubi.mtd=3 root=ubi0:system init=...'