ubifs文件系统挂载及同步

发布时间:2015-08-30 14:10:35   来源:文档文库   
字号:

UBIFS分区制作及UBIFS烧写和启动 (转载)

相关命令工具

ubiattach version 1.0 - a tool to attach MTD device to UBI.

Usage: ubiattach   

[-m ] [-d ]

[--mtdn=] [--devn ]

Example 1: ubiattach /dev/ubi_ctrl -m 0 - attach MTD device 0 (mtd0) to UBI

Example 2: ubiattach /dev/ubi_ctrl -m 0 -d 3 - attach MTD device 0 (mtd0) to UBI and

and create UBI device number 3 (ubi3)

-d, --devn=  the number to assign to the newly created UBI       device(the number is assigned automatically if this is not specified)

-m, --mtdn=  MTD device number to attach

-O, --vid-hdr-offset            VID header offset (do not specify this unless you really know what you do and the optimal defaults will be used)

-h, --help                      print help message

-V, --version                   print program version

ubimkvol version 1.0 - a tool to create UBI volumes.

Usage: ubimkvol  [-h] [-a ] [-n ] [-N ] [-s ] [-S ] [-t ] [-V] [-m] [--alignment=][--vol_id=] [--name=] [--size=] [--lebs=] [--type=] [--help] [--version] [--maxavsize]

Example: ubimkvol/dev/ubi0 -s 20MiB -N config_data - create a 20 Megabytes volume

named "config_data" on UBI device /dev/ubi0.

-a, --alignment=   volume alignment (default is 1)

-n, --vol_id=      UBI volume ID, if not specified, the volume ID

will be assigned automatically

-N, --name=             volume name

-s, --size=            volume size volume size in bytes, kilobytes (KiB)

or megabytes (MiB)

-S, --lebs=       alternative way to give volume size in logical

eraseblocks

-m, --maxavsize               set volume size to maximum available size

-t, --type=   volume type (dynamic, static), default is dynamic

-h, -?, --help                print help message

-V, --version                 print program version

The following is a compatibility option which is deprecated, do not use it

-d, --devn=             UBI device number - may be used instead of the UBI

device node name in which case the utility assumes

that the device node is "/dev/ubi"

ubidetach version 1.0 - a tool to remove UBI devices (detach MTD devices from UBI)

Usage: ubidetach [-d ] [-m ] [--devn ] [--mtdn=]

Example 1: ubidetach /dev/ubi_ctrl -d 2 - delete UBI device 2 (ubi2)

Example 2: ubidetach /dev/ubi_ctrl -m 0 - detach MTD device 0 (mtd0)

-d, --devn=  UBI device number to delete

-m, --mtdn=  or altrnatively, MTD device number to detach -

this will delete corresponding UBI device

-h, --help                      print help message

-V, --version                   print program version

ubiformat version 1.0 - a tool to format MTD devices and flash UBI images

Usage: ubiformat  [-h] [-V] [-y] [-q] [-v]

[-x ] [-E ] [-s ] [-O ] [-n]

[--help] [--version] [--yes] [--verbose] [--quiet]

[--ec=] [--vid-hdr-offset=]

[--ubi-ver=] [--no-volume-table]

Example 1: ubiformat /dev/mtd0 -y - format MTD device number 0 and do

not ask questions.

Example 2: ubiformat /dev/mtd0 -q -e 0 - format MTD device number 0,

be quiet and force erase counter value 0.

-s, --sub-page-size=  minimum input/output unit used for UBI

headers, e.g. sub-page size in case of NAND

flash (equivalent to the minimum input/output

unit size by default)

-O, --vid-hdr-offset=  offset if the VID header from start of the

physical eraseblock (default is the next

minimum I/O unit or sub-page after the EC

header)

-n, --no-volume-table        only erase all eraseblock and preserve erase

counters, do not write empty volume table

-f, --flash-image=     flash image file

-e, --erase-counter=  use  as the erase counter value for all

eraseblocks

-y, --yes                    assume the answer is "yes" for all question

this program would otherwise ask

-q, --quiet                  suppress progress percentage information

-v, --verbose                be verbose

-x, --ubi-ver=          UBI version number to put to EC headers

(default is 1)

-h, -?, --help               print help message

-V, --version                print program version

使用实例

将一个MTD分区挂载为UBIFS格式 

● flash_eraseall /dev/mtd5 //擦除mtd5 

● ubiattach /dev/ubi_ctrl -m 5 -d 0 //UBI和mtd5关联 ->ubi0

● ubimkvol /dev/ubi0 -n 0 -N rootfs0 -s 256MiB //创建分区ubi0_0设定volume 大小

● mount -t ubifs ubi0_0 /mnt/ubi或mount -t ubifs ubi0:rootfs0 /mnt/ubi //挂载

烧写UBIFS文件系统映像

U-Boot烧写ubifs:(mmc)

#mmcinit

#fatload mmc 0:1 81000000 ubi.img

#nand unlock

#nand ecc sw

#nand erase 680000 7980000

#nand write.i 81000000 680000 $(filesize)

NFS文件系统上烧写

法一,使用ubiformat工具

./ubiformat -q /dev/mtd5 -f ubi.img  

法二,不必烧写映像,将ROOTFS打包,解压到UBIFS

ubiattach /dev/ubi_ctrl -m 5 -d 0

ubimkvol /dev/ubi0 -n 0 -N rootfs -s 128MiB

mount -t ubifs ubi0_0 /mnt/ubi0

tar -jxv -C /mnt/ubi0 rootfs.tar.bz2

umount /mnt/ubi0

UBI文件系统启动

设置UBIFS文件系统作为根文件系统启动的参数

#setenv bootargs console=ttyAM0,115200n8 ubi.mtd=5 root=ubi0:rootfs rootfstype=ubifs init=linuxrc

# setenv bootcmd nand read.i 80300000 280000 200000\;bootm 80300000

UBIFS

一、 UBIFS 简介

IBMnokia工程师Thomas GleixnerArtem Bityutskiy等人于2006年发起,致力于开发性能卓越、扩展性高的FLASH专用文件系统,以解决当前嵌入式环境下以FLASH作为MTD设备使用时的技术瓶颈,

开发背景:

FLASH特性:

FLASH是一类电可擦出可编程存储体,在使用方式上与硬磁盘最大不同是:

FLASH文件系统所必须的关键技术:

1. 由于FLASH先擦除后写的特性决定,必须(或者说所被公认为)采用异地更新策略(out-of-place update)。相关问题讨论可参考:

http://www.linux-mtd.infradead.org 文档 A Brief Introduction to the Design of UBIFS

2. 采用异地更新策略就必须(或者说所被公认为)采用日志文件系统来管理。

3. 采用日志文件系统就必须(或者说所被公认为)实现垃圾回收(garbage collection)

4. 由于FLASH的物理擦除块(Physical Erase Block)只有有限次有效擦除,所以必须(或者说所被公认为)采用负载平衡(我比较喜欢翻译为损益均衡”——一个经济学术语)(Wear-Leveling)技术,即保证上的(几乎)所有 PEB的擦除次数趋向于均衡化,从而避免小部分PEB大大先于其他PEB掉。

当前嵌入式FLASH解决方案多采用:

1.  无文件系统直接使用FLASH:缺点很明显

2. 采用传统文件系统,如ext2,ext3, FAT16/32, dosCramfs 等:这些文件系统本来是为传统的磁盘体开发的,他们无法高效的管理以FLASH作为介质的文件系统,特别是在FLASH的使用寿命上。于是出现了第3中方案。

3. 采用FTLNFTLflash 转换层/nand flash转换层)+ 传统文件系统:FTL的使用就是针对FLASH的特有属性,通过硬件的方式来实现日志管理、损益均衡等技术。但实践证明,由于各方面因素导致本方案有一定的局限性。

4. FLASH专用文件系统,如JFFS12YAFFS等,他们从一定程度上缓解了flash使用上的技术瓶颈。但也仍然存在诸多问题:如内存消耗大,对 FLASH容量、文件系统大小、内容、访问模式等的线性依赖,损益均衡能力差活过渡损益。随作FLASH容量逐渐暴涨(我见到的资料已经有 64GFLASH已经实用化),JFFSYAFFS几乎无法管理如此大的FLASH——虽然JFFS目前还在改进中,但前途不看好,一个很好的例子 JFFS的主要开发者大多倒向了UBIFS。:) 

UBI:一种类似于LVM的逻辑卷管理层。主要实现损益均衡,逻辑擦除块、卷管理,坏块管理等。

UBIFS:基于UBIFLASH日志文件系统。

有关ubifs的详细介绍,请参考:

http://www.linux-mtd.infradead.org/doc/ubi.html

http://www.linux-mtd.infradead.org/doc/ubifs.html

二、使用UBIFS前的准备

1. 获取 ubifs:

   2.6.22以后,ubifs活跃于git管理工程中

  git://git.infradead.org/ubi-2.6.git

   2.6.27以后,ubifs被整合进内核树中,用户只需下载最新内核即可获取ubifs支持。

2. 配置linux内核 2.6.28 以上 kernel 已经包含 ubifs, 早期的kernel 还得去官网上找找,我的就是 2.6.28)

    配置的时候选上

   1)Device Drivers  --->Memory Technology Device (MTD) support  --->UBI - Unsorted block images  --->Enable UBI

   2)File systems  --->Miscellaneous filesystems  --->UBIFS file system support

    这样我们的内核就支持UBIFS文件系统了

3. UBIFS工具

   mtd-utils工具中提供了对UBIFS的支持,所以我们需要下载和编译这些工具,下载以下几个文件

    1)下载mtd-utils

    wget http://debian.mirror.inra.fr/debian/pool/main/m/mtd-utils/mtd-utils_20080508.orig.tar.gz

    tar xzvf mtd-utils_20080508.orig.tar.gz

    cd mtd-utils-20080508

    2)编译mtd-utils (主要是修改工具链)

     修改Makefile文件:

     #CROSS=arm-linux-

       修改为  CROSS=arm-marvell-linux-gnueabi-

     BUILDDIR := $(CROSS:-=)

       修改为  BUILDDIR := .

       修改ubi-utils/Makefile文件:

       添加    CROSS=arm-marvell-linux-gnueabi-

       修改    ubi-utils/new-utils/Makefile文件:

       添加    CROSS=arm-marvell-linux-gnueabi-

     make WITHOUT_XATTR=1

    3 ubi-utils子目录下生成我们需要的ubiattachubimkvol等文件(请确保是交叉编译所得 

    mkfs.ubifs子目录下生成我们需要的mkfs.ubifs工具,通过这个工具我们能打包一个文件夹,生成UBIFS系统镜像,

     我是使用 nfs 启动, 直接解压文件到 flash 上,所以并没有使用 mkfs.ubifs工具.

     另外网络上很多文正提到 zliblzo 这两个库,但是我并没有使用到。

. 如何使用UBIFS

1. 使用nfs启动系统, 首先建立设备节点:

    mknod   /dev/ubi_ctrl c 10 58

    mknod /dev/ubi0 c 250 0

2 执行以下命令挂载ubifs

   1)flash_eraseall /dev/mtd4                 #擦出分区

   2)ubiattach /dev/ubi_ctrl -m 4             #建立关联

   3)ubimkvol /dev/ubi0 -N rootfs -s 450MiB   #创建容量, -s 是设置大小

   4)mount -t ubifs ubi0_0 /mnt               # 也可以:mount -t ubifs ubi0:rootfs /mnt

. uboot 如何支持 UBIFS 为根文件系统启动:

setenv bootargs console=ttyS0,115200 ubi.mtd=4 root=ubi0_0 rootfstype=ubifs ip=192.168.1.101:192.168.1.100::255.255.255.0::usb0:on

下面附上一个我自己通过 nfs 启动以后, 烧写 kernel 和文件系统的脚本。

#!/bin/sh

TestResult()

{

if [ $? -ne 0 ]; then

        echo "$1 faild please check the file" 

        exit 1

else

        echo "$1 OK !!!" 

        echo " " 

fi

}

#Erase the flash partition

echo "--------------Erase the flash partitin----------------"

/mtd-utils/usr/sbin/flash_eraseall /dev/mtd3

/mtd-utils/usr/sbin/flash_eraseall /dev/mtd4

echo "--------------Install kernel and software to flash----------------"

/bin/dd if=/zImage of=/dev/mtdblock3

mkdir -p /mountpoint

mknod   /dev/ubi_ctrl c 10 58

mknod /dev/ubi0 c 250 0

/mtd-utils/ubi/ubiattach /dev/ubi_ctrl -m 4

TestResult "/mtd-utils/ubi/ubiattach /dev/ubi_ctrl -m 4"

/mtd-utils/ubi/ubimkvol /dev/ubi0 -N rootfs -s 450MiB

TestResult "/mtd-utils/ubi/ubimkvol /dev/ubi0 -N rootfs -s 450MiB"

/bin/mount -t ubifs ubi0_0 /mountpoint

TestResult "/bin/mount -t ubifs ubi0_0 /mountpoint"

echo "tar xvf /fs.tar -C /mountpoint please wait"

tar xf /FSSoftware.tar -C /mountpoint

sync

/bin/umount /mountpoint

echo "----------------------------------------------------------------"

echo "         Please set uboot environment:   "

echo "setenv bootargs console=ttyS0,115200 ubi.mtd=4 root=ubi0_0 rootfstype=ubifs ip=192.168.1.101:192.168.1.100::255.255.255.0::usb0:on"

echo "----------------------------------------------------------------"

exit 0

 

另外 ubifs 是一个异步的文件系统, 所以为了掉电的时候数据能保存完整, 最好使用-o sync 挂载文件系统。

本文来源:https://www.2haoxitong.net/k/doc/5bdcf2e6a417866fb94a8e80.html

《ubifs文件系统挂载及同步.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式