一.在内核选项中配置好ubifs
在配置的时候选上
1)Device Drivers --->Memory Technology Device (MTD) support --->UBI - Unsorted block images --->Enable UBI
Device Drivers
Memory Technology Device (MTD) support
UBI - Unsorted block images
2)File systems --->Miscellaneous filesystems --->UBIFS file system support
File systems
Miscellaneous filesystems
UBIFS file system support
二.编译用户工具
mtd-utils工具(flash_eraseall、ubiattach、ubimkvol)准备
1)下载(mtd-utils、zlib、lzo)源码
wgethttp://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-20080508
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-
在mtd-utils-20080508/ubi-utils/目录下面
make WITHOUT_XATTR=1
ubi-utils子目录下生成我们需要的ubiattach、ubimkvol等文件(请确保是交叉编译所得)
好了,将这个工具拷贝到/usr/sbin目录下面
三.使用步骤
由于没有提供flash_eraseall 用户工具,我们擦除nandflash只能在U_boot控制台下擦除了
(1)在U_boot控制台下擦除nandflash
(2)挂载nfs文件系统,在nfs文件系统下执行下面操作
(3)ubiattach /dev/ubi_ctrl -m 3
/ # ubiattach /dev/ubi_ctrl -m 3
UBI: attaching mtd3 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: empty MTD device detected
UBI: create volume table (copy #1)
UBI: create volume table (copy #2)
UBI: attached mtd3 to ubi0
UBI: MTD device name: "user"
UBI: MTD device size: 34 MiB
UBI: number of good PEBs: 2176
UBI: number of bad PEBs: 0
UBI: max. allowed volumes: 92
UBI: wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 0
UBI: available PEBs: 2151
UBI: total number of reserved PEBs: 25
UBI: number of PEBs reserved for bad PEB handling: 21
UBI: max/mean erase counter: 0/0
UBI: background thread "ubi_bgt0d" started, PID 393
UBI device number 0, total 2176 LEBs (34537472 bytes, 32.9 MiB), available 2151 LEBs (34140672 bytes, 32.6 MiB), LEB size 15872 bytes (15.5 KiB)
(4)mdev -s
这样我们可以在/dev目录下看见ubi0设备了
(5)ubimkvol /dev/ubi0 -N ubifs -s 15MiB
/ # ubimkvol /dev/ubi0 -N ubifs -s 15MiB
Volume ID 0, size 991 LEBs (15729152 bytes, 15.0 MiB), LEB size 15872 bytes (15.5 KiB), dynamic, name "ubifs", alignment 1
(6)mount -t ubifs ubi0:ubifs /mnt
/ # mount -t ubifs ubi0:ubifs /mnt
UBIFS: default file-system created
UBIFS: background thread "ubifs_bgt0_0" started, PID 402
UBIFS: mounted UBI device 0, volume 0, name "ubifs"
UBIFS: file system size: 15538688 bytes (15174 KiB, 14 MiB, 979 LEBs)
UBIFS: journal size: 777728 bytes (759 KiB, 0 MiB, 49 LEBs)
UBIFS: default compressor: LZO
UBIFS: media format 4, latest format 4
(7)下面就可以创建我们的文件系统了
/ # cp -af bin/ usr/ etc/ root/ home/ sbin/ /mnt
/ # cd /mnt
/mnt # mkdir sys/ dev/ var/ mnt/ proc/ tmp/
/mnt # cd dev
由于我们的sep4020上不能自刷新,所以创建了一个ubi0节点
/mnt/dev # mknod ubi0 c 254 0
/mnt/dev # mknod console c 5 1
(8)重启启动开发板,切换到U_boot控制台界面下设置bootargs参数
set bootargs console=ttyS0,115200 ubi.mtd=3 root=ubi0:ubifs rootfstype=ubifs
(9)重新启动开发板,就会看见下面的启动信息