加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ubifs入门介绍

发布时间:2020-12-15 06:11:03 所属栏目:百科 来源:网络整理
导读:? 第一、什么是ubifs? 由IBM、nokia工程师Thomas Gleixner,Artem Bityutskiy等人于2006年发起,致力于开发性能卓越、扩展性高的FLASH专用文件系统,以解决当前嵌入式环境下以FLASH作为MTD设备使用时的技术瓶颈。 关键字: UBI:一种类似于LVM的逻辑卷管理
? 第一、什么是ubifs?
由IBM、nokia工程师Thomas Gleixner,Artem Bityutskiy等人于2006年发起,致力于开发性能卓越、扩展性高的FLASH专用文件系统,以解决当前嵌入式环境下以FLASH作为MTD设备使用时的技术瓶颈。
关键字:
UBI:一种类似于LVM的逻辑卷管理层。主要实现损益均衡,逻辑擦除块、卷管理,坏块管理等。
UBIFS:基于UBI的FLASH日志文件系统。
有关ubifs的详细介绍,请参考:
http://www.linux-mtd.infradead.org/doc/ubi.html
http://www.linux-mtd.infradead.org/doc/ubifs.html
第二、为何使用ubifs?
第三、如何得到ubifs?
2.6.22以后,ubifs活跃于git管理工程中:
git://git.infradead.org/ubi-2.6.git
2.6.27以后,ubifs被整合进内核树中,用户只需下载最新内核即可获取ubifs支持。
第四、如何使用ubifs?
软件环境:
linux-2.6.28
arm-linux-gcc 3.4.5
硬件环境:
s3c2410
k9f1208
一、准备
1、内核
配置的时候选上
1)Device Drivers??--->Memory Technology Device (MTD) support??--->UBI - Unsorted block images??--->Enable UBI
2)File systems??--->Miscellaneous filesystems??--->UBIFS file system support
2、mtd-utils工具(flash_eraseall、ubiattach、ubimkvol)准备
1)下载(mtd-utils、zlib、lzo)源码
wget http://debian.mirror.inra.fr/debian/pool/main/m/mtd-utils/mtd-utils_20080508.orig.tar.gz
wget http://www.zlib.net/zlib-1.2.3.tar.gz
wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.03.tar.gz
2)编译安装zlib
tar xzvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
CC=arm-linux-gcc ./configure --shared --prefix=/usr/local/arm/3.4.5/arm-linux
make
make install
cd ..
3)编译安装lzo
tar xzvf lzo-2.03.tar.gz
cd lzo-2.03
CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/usr/local/arm/3.4.5/arm-linux
make
make install
cd ..
4)编译mtd-utils
tar xzvf mtd-utils_20080508.orig.tar.gz
cd mtd-utils-20080508
修改Makefile文件:
#CROSS=arm-linux-
修改为??CROSS=arm-linux-
BUILDDIR := $(CROSS:-=)
修改为??BUILDDIR := .
修改ubi-utils/Makefile文件:
添加? ? CROSS=arm-linux-
修改? ? ubi-utils/new-utils/Makefile文件:
添加? ? CROSS=arm-linux-
make WITHOUT_XATTR=1
ubi-utils子目录下生成我们需要的ubiattach、ubimkvol等文件(请确保是交叉编译所得)
3、mtd-utils工具(mkfs.ubifs、ubinize)准备
git-clone git://git.infradead.org/mtd-utils.git
cd mtd-utils/
make
mkfs.ubifs子目录下生成我们需要的mkfs.ubifs工具
ubi-utils/new-utils子目录下生成我们需要的ubinize工具
二、使用
1、使用ramfs或nfs启动系统,执行以下命令挂载ubifs:
1)flash_eraseall /dev/mtd4
2)ubiattach /dev/ubi_ctrl -m 4
3)ubimkvol /dev/ubi0 -N rootfs -s 50MiB
4)mount -t ubifs ubi0_0 /mnt或mount -t ubifs ubi0:rootfs /mnt
2、如果你想使用ubifs为rootfs,把文件系统内容解压到ubifs挂载目录下,并修改内核启动参数为:
console=ttySAC0 ubi.mtd=4 root=ubi0:rootfs rootfstype=ubifs
3、如果你想直接在bootloader下烧写ubifs映像,使用以下命令制作ubi烧写映像:
mkfs.ubifs -r rootfs -m 512 -e 15872 -c 3303 -o ubifs.img
ubinize -o ubi.img -m 512 -p 16KiB -s 256 ubinize.cfg
其中:
1)以上命令的参数可从ubifs挂载信息中提取:
UBI: attaching mtd4 to ubi0? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???
UBI: physical eraseblock size:? ?16384 bytes (16 KiB)? ?? ?? ?? ?? ?? ?? ?? ?? ?
UBI: logical eraseblock size:? ? 15872 bytes? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?
UBI: smallest flash I/O unit:? ? 512? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???
UBI: sub-page size:? ?? ?? ?? ???256? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???
UBI: VID header offset:? ?? ?? ? 256 (aligned 256)? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?
UBI: data offset:? ?? ?? ?? ?? ? 512? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???
UBI: attached mtd4 to ubi0? ?? ?? ?? ???
2)配置文件ubinize.cfg的内容为:
[ubifs]
mode=ubi
image=ubifs.img
vol_id=0
vol_size=50MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize
注:
? ? 其他nand flash下ubifs的使用方法类似(参数不同)。
=============================================================================
UBI文件系统简介
? ? ? ?? ???作者:

刘洪涛,华清远见嵌入式学院
金牌讲师。
? ? ? ?? ???在
linux-2.6.27以前,谈到Flash文件系统,大家很多时候多会想到cramfs、jffs2、yaffs2等文件系统。它们也都是基于文件系
统+mtd+flash设备的架构。linux-2.6.27后,内核加入了一种新型的flash文件系统UBI(Unsorted Block
Images)。这里简单介绍下UBI文件系统加入的原因,及使用方法。我也是刚接触到这个文件系统,可能有理解不对的地方,也请指正。
? ? ? ?? ???? ? ? ?? ?? ? 一、产生的背景
? ? ? ?? ???? ? ? ?? ?? ? FLASH具有的“先擦除再写入”、坏块、“有限的读写次数”等特性,目前管理FLASH的方法主要有:
? ? ? ?? ???1、采
用MTD+FTL/NFTL(flash 转换层/nand flash转换层)+
传统文件系统,如:FAT、ext2等。FTL/NFTL的使用就是针对FLASH的特有属性,通过软件的方式来实现日志管理、坏块管理、损益均衡等技
术。但实践证明,由于知识产权、效率等各方面因素导致本方案有一定的局限性。
? ? ? ?? ???2、采用硬件翻译层+传统文件系统的方案。这种方法被很多存储卡产品采用,如:SD卡、U盘等。这种方案对于一些产品来说,成本较高。
? ? ? ?? ???3、采用MTD+ FLASH专用文件系统,如JFFS1/2,YAFFS1/2等。它们大大提高了FLASH的管理能力,并被广泛应用。
? ? ? ?? ???JFFS2、YAFFS2等专用文件系统也存在着一些技术瓶颈,如:内存消耗大,对FLASH容量、文件系统大小、内容、访问模式等的线性依赖,损益均衡能力差或过渡损益等。在此背景下内核加入了UBI文件系统的支持。
? ? ? ?? ???二、用法
? ? ? ?? ???? ? ? ?? ?? ? 环境:omap3530处理器、??(128MByte 16 位NAND??Flash) 、linnux-2.6.28内核
? ? ? ?? ???1、配置内核支持UBIFS
? ? ? ?? ?? ???Device Drivers? ?--->Memory Technology Device (MTD) support??--->UBI - Unsorted block??images??--->Enable UBI
? ?? ? 配置mtd支持UBI接口
? ?? ? File??systems??--->Miscellaneous filesystems??--->UBIFS file system??support
? ?? ? 配置内核支持UBIFS文件系统
? ? ? ?? ???2、将一个MTD分区4挂载为UBIFS格式
? ? ? ?? ?? ???● flash_eraseall??/dev/mtd4??//擦除mtd4
? ? ? ?? ?? ?? ?? ???● ubiattach??/dev/ubi_ctrl -m 4??//和mtd4关联??
? ?? ?? ?? ?? ?● ubimkvol??/dev/ubi0 -N rootfs -s 100MiB //设定volume 大小(不是固定值,可以用工具改变)及名称??
? ?? ?? ?? ?? ?● mount -t ubifs??ubi0_0 /mnt/ubi或mount -t ubifs ubi0:rootfs /mnt/ubi
? ? ? ?? ???3、制作UBIFS文件系统
? ? ? ?? ???在制作UBI镜像时,需要首先确定以下几个参数:
? ? ? ?? ?? ???MTD partition size; //对应的FLASH分区大小
? ?? ? flash physical eraseblock size; // FLASH物理擦除块大小
? ?? ? minimum flash input/output unit size; //最小的FLASH输入输出单元大小
? ?? ? for NAND flashes - sub-page size; //对于nand flash来说,子页大小
? ?? ? logical eraseblock size.//逻辑擦除块大小
? ? ? ?? ???? ? ? ?? ?? ? 参数可以由几种方式得到
? ? ? ?? ???? ? ? ?? ?? ? 1)如果使用的是2.6.30以后的内核,这些信息可以通过工具从内核获得,如:mtdinfo –u。
? ? ? ?? ???? ? ? ?? ?? ? 2)之前的内核可以通过以下方法:
? ? ? ?? ?? ???● MTD partition size:从内核的分区表或cat /proc/mtd获得
? ?? ? ● flash physical eraseblock size:从flash芯片手册中可以得到FLASH物理擦除块大小,或cat /proc/mtd
? ?? ? ● minimum flash input/output unit size:
? ?? ?? ???1)nor flash:通常是1个字节
? ?? ?? ???2)nand falsh:一个页面
? ?? ? ● sub-page size:通过flash手册获得
? ?? ? ● logical eraseblock size:对于有子页的NAND FLASH来说,等于“物理擦除块大小-1页的大小”
? ? ? ?? ???3)也可以通过ubi和mtd连接时的产生的信息获取,如:
? ? ? ?? ???? ? ? ?? ?? ? #modprobe ubi??mtd=4? ?//ubi作为模块加载
? ? ? ?? ???? ? ? ?? ?? ? 或
? ? ? ?? ???? ? ? ?? ?? ? #ubiattach??/dev/ubi_ctrl -m 4??//通过ubiattach关联MTD
? ? 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
? ? ? ?? ???? ? ? ?? ?? ? 更详细的解释参见http://www.linux-mtd.infradead.org/doc/ubi.html#L_overhead
? ? ? ?? ???? ? ? ?? ?? ? #mkfs.ubifs??-r rootfs -m 2048 -e 129024 -c 812 -o ubifs.img
? ? ? ?? ?? ?? ???#ubinize -o ubi.img -m 2048 -p 128KiB -s 512 /home/lht/omap3530/tools/ubinize.cfg
? ? ? ?? ???? ? ? ?? ?? ? -r:制定文件内容的位置
? ? ? ?? ?? ?? ???-m:页面大小
? ? ? ?? ?? ?? ???-e:逻辑擦除块大小
? ? ? ?? ?? ?? ???-p:物理擦除块大小
? ? ? ?? ?? ?? ???-c:最大的逻辑擦除块数量
? ? ? ?? ?? ?? ???对我们这种情况,文件系统最多可以访问卷上的129024*812=100M空间
? ? ? ?? ?? ?? ???-s:最小的硬件输入输出页面大小,如:k9f1208为256(上下半页访问)
? ? ? ?? ???? ? ? ?? ?? ? 其中,ubinize.cfg的内容为:
? ? ? ?? ???? ? ? ?? ?? ? [ubifs]
? ? ? ?? ?? ?? ???mode=ubi
? ? ? ?? ?? ?? ???image=ubifs.img
? ? ? ?? ?? ?? ???vol_id=0
? ? ? ?? ?? ?? ???vol_size=100MiB
? ? ? ?? ?? ?? ???vol_type=dynamic
? ? ? ?? ?? ?? ???vol_name=rootfs
? ? ? ?? ?? ?? ???vol_flags=autoresize
? ? ? ?? ???4、利用uboot烧写、启动UBIFS镜像
? ? ? ?? ???1)烧写UBIFS镜像
? ? ? ?? ???? ? ? ?? ?? ? OMAP3??DevKit8000 # mmcinit
? ? ? ?? ?? ?? ???OMAP3??DevKit8000 # fatload mmc 0:1 81000000 ubi.img
? ? ? ?? ?? ?? ???reading??ubi.img
? ? ? ?? ?? ?? ???12845056??bytes read
? ? ? ?? ?? ?? ???OMAP3??DevKit8000 # nand unlock
? ? ? ?? ?? ?? ???device??0 whole chip
? ? ? ?? ?? ?? ???nand_unlock:??start: 00000000,length: 268435456!
? ? ? ?? ?? ?? ???NAND??flash successfully unlocked
? ? ? ?? ?? ?? ???OMAP3??DevKit8000 # nand ecc sw
? ? ? ?? ?? ?? ???OMAP3??DevKit8000 # nand erase 680000 7980000
? ? ? ?? ?? ?? ???NAND??erase: device 0 offset 0x680000,size 0x7980000
? ? ? ?? ?? ?? ???Erasing??at 0x7fe0000 -- 100% complete.
? ? ? ?? ?? ?? ???OK
? ? ? ?? ?? ?? ???OMAP3??DevKit8000 # nand write.i 81000000 680000 $(filesize) ? ? ? ?? ?? ?? ???NAND??write: device 0 offset 0x680000,size 0xc40000 ? ? ? ?? ?? ?? ???Writing??data at 0x12bf800 -- 100% complete. ? ? ? ?? ?? ?? ???12845056??bytes written: OK ? ? ? ?? ???? ? ? ?? ?? ? 烧写过程和烧写内核镜像的过程一致,所以UBI文件系统应该不像yaffs文件系统那样用到了nand的OOB区域。 ? ? ? ?? ???2)设置UBIFS文件系统作为根文件系统启动的参数 ? ? ? ?? ???? ? ? ?? ?? ? OMAP3 DevKit8000 # setenv??bootargs console=ttyS2,115200n8 ubi.mtd=4 root=ubi0:rootfs ? ? ? ?? ?? ?? ???rootfstype=ubifs??video=omapfb:mode:4.3inch_LCD ? ? ? ?? ?? ?? ???OMAP3 DevKit8000 # setenv??bootcmd nand read.i 80300000 280000 200000;bootm 80300000 ? ? ? ?? ???? ? ? ?? ?? ? 根文件系统的位置在MTD4上 ? ? ? ? ? ? ? ?? ???? ? ? ?? ?? ? 系统启动时会打印出如下和UBI相关的信息: ? ? ? ?? ???? ? ? ?? ?? ? Creating 5 MTD partitions on "omap2-nand": ? ? ? ?? ?? ?? ???0x00000000-0x00080000 :??"X-Loader" ? ? ? ?? ?? ?? ???0x00080000-0x00260000 :??"U-Boot" ? ? ? ?? ?? ?? ???0x00260000-0x00280000 :??"U-Boot Env" ? ? ? ?? ?? ?? ???0x00280000-0x00680000 :??"Kernel" ? ? ? ?? ?? ?? ???0x00680000-0x08000000 : "File??System" ? ? ? ?? ?? ?? ???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" ? ? ? ?? ?? ?? ???UBI: MTD device size:? ?? ?? ?? ?121 MiB ? ? ? ?? ?? ?? ???UBI: number of good PEBs:? ?? ???970 ? ? ? ?? ?? ?? ???UBI: number of bad PEBs:? ?? ?? ?2 ? ? ? ?? ?? ?? ???UBI: max. allowed volumes:? ?? ? 128 ? ? ? ?? ?? ?? ???UBI: wear-leveling threshold:? ? 4096 ? ? ? ?? ?? ?? ???UBI: number of internal volumes: 1 ? ? ? ?? ?? ?? ???UBI: number of user volumes:? ???1 ? ? ? ?? ?? ?? ???UBI: available PEBs:? ?? ?? ?? ? 0 ? ? ? ?? ?? ?? ???UBI: total number of reserved PEBs: 970 ? ? ? ?? ?? ?? ???UBI: number of PEBs reserved for bad PEB handling: 9 ? ? ? ?? ?? ?? ???UBI: max/mean erase counter: 2/0

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读