ubifs
无排序区块图像文件系统(Unsorted Block Image File System, UBIFS)是用于固态硬盘存储设备上,并与LogFS相互竞争,作为JFFS2的后继文件系统之一。真正开始开发于2007年,并于2008年10月第一次加入稳定版本于Linux核心2.6.27版。UBIFS最早在2006年由IBM与Nokia的工程师Thomas Gleixner,Artem Bityutskiy所设计,专门为了解决MTD(Memory Technology Device)设备所遇到的瓶颈。由于Nand Flash容量的暴涨,YAFFS等皆无法再去控制Nand Flash的空间。UBIFS通过子系统UBI处理与MTD device之间的动作。与JFFS2一样,UBIFS 建构于MTD device 之上,因而与一般的block device不兼容。
JFFS2运行在MTD设备之上,而UBIFS则只能工作于UBI volume之上。也可以说,UBIFS涉及了三个子系统:
1. MTD 子系统, 提供对flash芯片的访问接口, MTD子系统提供了MTD device的概念,比如/dev/mtdx,MTD可以认为是raw flash
2. UBI subsystem,为flash device提供了wear-leveling和 volume management功能; UBI工作在MTD设备之上,提供了UBI volume;UBI是MTD设备的高层次表示,对上层屏蔽了一些MTD不得不处理的问题,比如wearing以及坏块管理
3. UBIFS文件系统,工作于UBI之上
以下是UBIFS的一些特点:
Ø 可扩展性:UBIFS对flash 尺寸有着很好的扩展性; 也就是说mount时间,内存消耗以及I/O速度都不依赖与flash 尺寸(对于内存消耗并不是完全准确的,但是依赖性非常的低); UBIFS可以很好的适应GB flashes; 当然UBI本身还有扩展性的问题,无论如何 UBI/UBIFS都比JFFS2的可扩展性好,此外如果UBI成为瓶颈,还可以通过升级UBI而不需改变UBIFS
Ø 快速mount:不像JFFS2,UBIFS在mount阶段不需要扫描整个文件系统,UBIFS mount介质的时间只是毫秒级,时间不依赖与flash的尺寸;然而UBI的初始化时间是依赖flash的尺寸的,因此必须把这个时间考虑在内
Ø write-back 支持: 回写或者叫延迟写更准确些吧,同JFFS2的write-through(立即写入内存)相比可以显著的提高文件系统的吞吐量。
Ø 异常unmount适应度:UBIFS是一个日志文件系统可以容忍突然掉电以及unclean重启; UBIFS 通过replay 日志来恢复unclean unmount,在这种情况下replay会消耗一些时间,因此mount时间会稍微增加,但是replay过程并不会扫描整个flash介质,所以UBIFS的mount时间大概在几分之一秒。
Ø 快速I/O - 即使我们disable write-back(可以在unmount时使用-o sync mount选项), UBIFS的性能仍然接近JFFS2; 记住,JFFS2的同步I/O是非常惊人的,因为JFFS2不需要在flash上维护indexing data结构, 所以就没有因此而带来的负担; 而UBIFS恰恰是有index数据的。 UBIFS之所以够快是因为UBIFS提交日志的方式:不是把数据从一个地方移动到另外一个位置,而只是把数据的地址加到文件系统的index,然后选择不同的eraseblock作为新的日志块,此外还有multi-headed日志方式等技巧。
Ø on-the_flight compression - 存储在flash介质上的数据是压缩的;同时也可以灵活的针对单个文件来打开关闭压缩; 例如,可能需要针对某个特定的文件打开压缩,或者可能缺省方式下支持压缩,但是对多媒体文件则关闭压缩。
Ø 可恢复性 - UBIFS可以从index破坏后恢复; UBIFS中的每一片信息都有一个header来描述,因此可以通过扫描这个flash介质来重构文件系统,这点和JFFS2非常类似;想像一下,如果你擦出了FAT文件系统的FAT表,那么对于FAT FS是致命的错误,但是如果擦除UBIFS的index,你人然可以重构文件系统,当然这需要一个特定的用户空间程序来做这个恢复
完整性 - UBIFS通过写checksum到flash 介质上来保证数据的完整性,UBIFS不会无视损坏文件数据或meta-data; 缺省的情况,UBIFS仅仅检查meta-data的CRC,但是你可以通过mount选项,强制进行data CRC的检查
修改根文件系统目录
将etc/mdev.conf文件中的下面两行注释掉。
[luxibao@centos etc]$ vim mdev.conf
sd[a-z][0-9] 0:0 0777 @(mount /dev/$MDEV /mnt/usb)
sd[a-z] 0:0 0777 $(umount /mnt/usb)
#ub[a-z][0-9] 0:0 0777 @(mount /dev/$MDEV /mnt/usb) #第一处需要注释的地方
#ub[a-z] 0:0 0777 $(umount /mnt/usb) #第二处需要注释的地方
mmcblk[0-9]p[0-9] 0:0 0777 @(mount /dev/$MDEV /mnt/sdc)
mmcblk[0-9] 0:0 0777 $(umount /mnt/sdc)
将etc/inittab文件中的下面两行注释掉。
[luxibao@centos rootfs]$ cd etc/
[luxibao@centos etc]$ ls
dropbear fstab hostname init.d issue passwd protocols TZ
dropbear-0.53.1 group hosts inittab mdev.conf profile shadow
[luxibao@centos etc]$ vim inittab
.....
#Mount our apps/info partition
#null::wait:/bin/mount -o sync,noatime,ro -t jffs2 /dev/mtdblock6 /apps #第一处需要注释的地方
#null::wait:/bin/mount -o sync,noatime,ro -t jffs2 /dev/mtdblock7 /info #第二处需要注释的地方
添加内核对ubifs的支持
[luxibao@centos linux-3.0]$ export TERM=vt100
[luxibao@centos linux-3.0]$ make menuconfig
Device Drivers --->
<*> Memory Technology Device (MTD) support --->
<*> Enable UBI - Unsorted block images --->
--- Enable UBI - Unsorted block images
(4096) UBI wear-leveling threshold (NEW)
(1) Percentage of reserved eraseblocks for bad eraseblocks handling (NEW)
< > MTD devices emulation driver (gluebi) (NEW)
[ ] UBI debugging (NEW)
File systems --->
[*] Miscellaneous filesystems --->
<*> UBIFS file system support
[*] Extended attributes support
[*] Advanced compression options
[*] LZO compression support (NEW)
[*] ZLIB compression support (NEW)
[ ] Enable debugging support (NEW)
[luxibao@centos linux-3.0]$ make
前面在制作mkfs.jffs2工具的同时制作了一个mkfs.ubifs工具,这个工具就是用来制作ubifs映像的一个工具
[luxibao@centos rootfs]$ cd mtd-utiles/
[luxibao@centos mtd-utiles]$ cd mtd-utils-1.4.9
[luxibao@centos mtd-utils-1.4.9]$ ls
common.mk flash_lock jffs-dump.c nftldump.o
compr.c flash_lock.c lib nftl_format
compr.h flash_lock.o load_nandsim.sh nftl_format.c
compr_lzo.c flash_otp_dump make_a_release.sh nftl_format.o
compr_lzo.o flash_otp_dump.c MAKEDEV rbtree.c
compr.o flash_otp_dump.o Makefile rbtree.h
compr_rtime.c flash_otp_info mcast_image.h rbtree.o
compr_rtime.o flash_otp_info.c mkfs.jffs2 recv_image
compr_zlib.c flash_otp_info.o mkfs.jffs2.1 recv_image.c
compr_zlib.o flash_otp_lock.c mkfs.jffs2.c recv_image.o
COPYING flash_otp_write.c mkfs.jffs2.o rfddump
device_table.txt flash_unlock mkfs.ubifs rfddump.c
docfdisk flash_unlock.c mtd_debug rfddump.o
docfdisk.c flash_unlock.o mtd_debug.c rfdformat
docfdisk.o ftl_check mtd_debug.o rfdformat.c
doc_loadbios ftl_check.c mtd-utils.spec rfdformat.o
doc_loadbios.c ftl_check.o nanddump serve_image
doc_loadbios.o ftl_format nanddump.c serve_image.c
feature-removal-schedule.txt ftl_format.c nanddump.o serve_image.o
fectest.c ftl_format.o nandtest summary.h
flashcp include nandtest.c sumtool
flashcp.c jffs2dump nandtest.o sumtool.c
flashcp.o jffs2dump.c nandwrite sumtool.o
flash_erase jffs2dump.o nandwrite.c tests
flash_eraseall jffs2reader nandwrite.o ubi-utils
flash_erase.c jffs2reader.c nftldump
flash_erase.o jffs2reader.o nftldump.c
[luxibao@centos mtd-utils-1.4.9]$ cd mkfs.ubifs/
[luxibao@centos mkfs.ubifs]$ ls
compr.c crc16.c devtable.c lpt.c mkfs.ubifs.c ubifs.h
compr.h crc16.h devtable.o lpt.h mkfs.ubifs.h ubifs-media.h
compr.o crc16.o hashtable lpt.o mkfs.ubifs.o
COPYING defs.h key.h mkfs.ubifs README
[luxibao@centos mkfs.ubifs]$ sudo cp mkfs.ubifs /usr/bin/
因为mkfs.ubifs工具制作的文件系统映像,在uboot中烧录这种映像文件的方式过于复杂,既要使uboot支持nandflash分区,又要在uboot中激活这个分区,再通过ubi write命令烧录这个映像。所以我们换一种比较容易的方式来移植这个文件系统
在制作mkfs.jffs2和mkfs.ubifs工具时,其实还有一个ubinize工具是同时生成的,它的作用是将mkfs.ubifs制作的映像转换为可以直接用nand write命令烧录的映像文件。
[luxibao@centos mkfs.ubifs]$ cd ..
[luxibao@centos mtd-utils-1.4.9]$ cd ubi-utils/
[luxibao@centos ubi-utils]$ ls
dictionary.c libubigen.a ubiattach.o ubimkvol.c ubirmvol
dictionary.o libubigen.c ubicrc32 ubimkvol.o ubirmvol.c
include libubigen.o ubicrc32.c ubinfo ubirmvol.o
libiniparser.a libubi_int.h ubicrc32.o ubinfo.c ubirsvol
libiniparser.c libubi.o ubidetach ubinfo.o ubirsvol.c
libiniparser.o LICENSE.libiniparser ubidetach.c ubinize ubirsvol.o
libscan.a mtdinfo ubidetach.o ubinize.c ubiupdatevol
libscan.c mtdinfo.c ubiformat ubinize.o ubiupdatevol.c
libscan.o mtdinfo.o ubiformat.c ubirename ubiupdatevol.o
libubi.a ubiattach ubiformat.o ubirename.c ubiutils-common.c
libubi.c ubiattach.c ubimkvol ubirename.o ubiutils-common.
[luxibao@centos ubi-utils]$ sudo cp ubinize /usr/bin/
[luxibao@centos rootfs]$ sudo sh build_ubifs.sh
Decompress rootfs packet and update rootfs version...
Generating rootfs-ubifs.bin file by mkfs.ubifs...
+ sudo mkfs.ubifs -x lzo -m 2048 -e 129024 -c 490 -r rootfs -o rootfs-ubifs.img
+ set +x
Generating configuration file...
+ sudo ubinize -o rootfs-ubifs.bin -m 2048 -p 128KiB -s 512 -O 512 rootfs_ubinize.cfg
+ sudo chmod a+x rootfs-ubifs.bin
+ cp rootfs-ubifs.bin ../../../../bin/
+ set +x
[luxibao@centos rootfs]$ ls
build_ubifs.sh mtd-utiles rootfs rootfs.jffs2 rootfs-ubifs.bin
[luxibao@centos rootfs]$ du -h rootfs-ubifs.bin
添加uboot对ubifs支持
[fl2440@lingyun]# set bubifs 'tftp 30008000 rootfs-ubifs.bin;nand erase 1000000 4000000;nand write 30008000 1000000 a00000'
[fl2440@lingyun]# set bootargs_ubifs 'console=ttyS0,115200 mem=64M ubi.mtd=2 root=ubi0:rootfs rootwait rootfstype=ubifs rw'
[fl2440@lingyun]# set bootargs 'console=ttyS0,115200 mem=64M ubi.mtd=2 root=ubi0:rootfs rootwait rootfstype=ubifs rw'
[fl2440@lingyun]# set bootargs 'console=ttyS0,115200 mem=64M ubi.mtd=2 root=ubi0:rootfs rootwait rootfstype=ubifs rw'
[fl2440@lingyun]# set bootcmd_rootfs 'nand read 30008000 100000 400000;bootm 30008000'
[fl2440@lingyun]# set bootcmd 'run bootcmd_rootfs'
[fl2440@lingyun]# save
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x60000 -- 100% complete.
Writing to Nand... Done
下载内核和rootfs.ubifs
[fl2440@lingyun]# run bkr
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:51
could not establish link
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.2; our IP address is 192.168.1.168
Filename 'linuxrom-s3c2440.bin'.
Load address: 0x30008000
Loading: T #################################################################
#################################################################
###########################
done
Bytes transferred = 2301552 (231e70 hex)
NAND erase: device 0 offset 0x100000, size 0x8000000
Skipping bad block at 0x005c0000
Skipping bad block at 0x031a0000
Erasing at 0x80e0000 -- 100% complete.
OK
NAND write: device 0 offset 0x100000, size 0x800000
Skip bad block 0x005c0000
8388608 bytes written: OK
[fl2440@lingyun]# run bubifs
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:51
could not establish link
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.2; our IP address is 192.168.1.168
Filename 'rootfs-ubifs.bin'.
Load address: 0x30008000
Loading: T #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#############################
done
Bytes transferred = 9961472 (980000 hex)
NAND erase: device 0 offset 0x1000000, size 0x4000000
Skipping bad block at 0x031a0000
Erasing at 0x4fe0000 -- 100% complete.
OK
NAND write: device 0 offset 0x1000000, size 0xa00000
10485760 bytes written: OK
启动引导
[fl2440@lingyun]# boot
NAND read: device 0 offset 0x100000, size 0x400000
4194304 bytes read: OK
## Booting kernel from Legacy Image at 30008000 ...
Image Name: Linux Kernel
Created: 2016-07-23 1:17:21 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2301488 Bytes = 2.2 MiB
Load Address: 30008040
Entry Point: 30008040
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
Linux version 3.0.0 (leiyuxing@centos6.7.localdomain) (gcc version 4.5.4 (Buildroot 2012.08) ) #9 Sat Jul 23 09:17:07 CST 2016
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: SMDK2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, Copyright 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: console=ttyS0,115200 mem=64M ubi.mtd=2 root=ubi0:rootfs rootwait rootfstype=ubifs rw
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60112k/60112k available, 5424k reserved, 0K highmem
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
DMA : 0xffc00000 - 0xffe00000 ( 2 MB)
vmalloc : 0xc4800000 - 0xf6000000 ( 792 MB)
lowmem : 0xc0000000 - 0xc4000000 ( 64 MB)
modules : 0xbf000000 - 0xc0000000 ( 16 MB)
.init : 0xc0008000 - 0xc0029000 ( 132 kB)
.text : 0xc0029000 - 0xc0453000 (4264 kB)
.data : 0xc0454000 - 0xc0477d60 ( 144 kB)
.bss : 0xc0477d84 - 0xc04afaf0 ( 224 kB)
SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS:85
irq: clearing pending ext status 00080800
irq: clearing subpending status 00000003
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttyS0] enabled
Calibrating delay loop... 201.52 BogoMIPS (lpj=503808)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
gpiochip_add: gpios 288..303 (GPIOK) failed to register
gpiochip_add: gpios 320..334 (GPIOL) failed to register
gpiochip_add: gpios 352..353 (GPIOM) failed to register
NET: Registered protocol family 16
S3C Power Management, Copyright 2004 Simtec Electronics
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C244X: Clock Support, DVS off
bio: create slab <bio-0> at 0
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
Advanced Linux Sound Architecture Driver Version 1.0.24.
cfg80211: Calling CRDA to update world regulatory domain
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
NetWinder Floating Point Emulator V0.97 (extended precision)
NTFS driver 2.1.30 [Flags: R/W].
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 117
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
s3c2440-uart.0: ttyS0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: ttyS1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: ttyS2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
loop: module loaded
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 46 at 0x0000005c0000
Bad eraseblock 397 at 0x0000031a0000
Creating 6 MTD partitions on "NAND":
0x000000000000-0x000000100000 : "mtdblock0 u-boot 1MB"
0x000000100000-0x000001000000 : "mtdblock1 kernel 15MB"
0x000001000000-0x000005000000 : "mtdblock2 rootfs 64MB"
0x000005000000-0x00000a000000 : "mtdblock3 apps 80MB"
0x00000a000000-0x00000d000000 : "mtdblock4 data 48MB"
0x00000d000000-0x000010000000 : "mtdblock5 backup 48MB"
UBI: attaching mtd2 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: max. sequence number: 0
UBI: volume 0 ("rootfs") re-sized from 490 to 502 LEBs
UBI: attached mtd2 to ubi0
UBI: MTD device name: "mtdblock2 rootfs 64MB"
UBI: MTD device size: 64 MiB
UBI: number of good PEBs: 511
UBI: number of bad PEBs: 1
UBI: number of corrupted PEBs: 0
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: 511
UBI: number of PEBs reserved for bad PEB handling: 5
UBI: max/mean erase counter: 1/0
UBI: image sequence number: 378407341
UBI: background thread "ubi_bgt0d" started, PID 699
dm9000 Ethernet Driver, V1.31
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
s3c2410_udc: debugfs dir creation failed -19
mousedev: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
i2c /dev entries driver
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
ALSA device list:
No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
lib80211: common routines for IEEE802.11 drivers
Registering the dns_resolver key type
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
UBIFS: mounted UBI device 0, volume 0, name "rootfs"
UBIFS: file system size: 61931520 bytes (60480 KiB, 59 MiB, 480 LEBs)
UBIFS: journal size: 8257536 bytes (8064 KiB, 7 MiB, 64 LEBs)
UBIFS: media format: w4/r0 (latest is w4/r0)
UBIFS: default compressor: lzo
UBIFS: reserved for root: 0 bytes (0 KiB)
VFS: Mounted root (ubifs filesystem) on device 0:12.
Freeing init memory: 132K
usb 1-1: new full speed USB device number 2 using s3c2410-ohci
usb 1-1: device descriptor read/64, error -62
usb 1-1: device descriptor read/64, error -62
usb 1-1: new full speed USB device number 3 using s3c2410-ohci
usb 1-1: device descriptor read/64, error -62
usb 1-1: device descriptor read/64, error -62
usb 1-1: new full speed USB device number 4 using s3c2410-ohci
usb 1-1: device not accepting address 4, error -62
usb 1-1: new full speed USB device number 5 using s3c2410-ohci
usb 1-1: device not accepting address 5, error -62
hub 1-0:1.0: unable to enumerate USB device on port 1
Copyright (C) 2016 Reagan
root login: root
Password:
>: ls
apps data etc init linuxrc proc sbin tmp var
bin dev info lib mnt root sys usr
>:
到此制作完成