本文主要记录制作过程,因为用到了很多脚本,所以具体ubifs制作并未深究,仅供参考。
—————————————————————————————————————————————————————————————————————————————
1.利用脚本将mtd-utils工具下载,生成ubinize.
它的作用是将mkfs.ubifs制作的映像转换为可以直接用nand write命令烧录的映像文件。
ubifs-jffs2.sh: (这个脚本主要是下载了mtd-utils相关软件包并压缩,编译,最后可以生成制作jffs2和ubifs映像文件的工具)#!/bin/sh #+-------------------------------------------------------------------------------------------- #|Description: This shell script used to download lzo,zlib,mtd-utils source code #| and cross compile it for ARM Linux, all is static cross compile. #| Author: GuoWenxue <guowenxue@gmail.com> #| ChangeLog: #| 1, Initialize 1.0.0 on 2011.04.12 #+-------------------------------------------------------------------------------------------- PRJ_PATH=`pwd` LZO="lzo-2.04" ZLIB="zlib-1.2.5" e2fsprogs_ver=1.42 mtd="mtd-utils-1.4.9" function decompress_packet() ( echo "+---------------------------------------------+" echo "| Decompress $1 now" echo "+---------------------------------------------+" ftype=`file "$1"` case "$ftype" in "$1: Zip archive"*) unzip "$1" ;; "$1: gzip compressed"*) if [ `expr "$1" : ".*.tar.*" ` ] ; then tar -xzf $1 else gzip -d "$1" fi ;; "$1: bzip2 compressed"*) if [ `expr "$1" : ".*.tar.*" ` ] ; then tar -xjf $1 else bunzip2 "$1" fi ;; "$1: POSIX tar archive"*) tar -xf "$1" ;; *) echo "$1 is unknow compress format";; esac ) # Download lzo source code packet if [ ! -s $LZO.tar.gz ] ; then wget http://www.oberhumer.com/opensource/lzo/download/$LZO.tar.gz fi # Decompress lzo source code packet if [ ! -d $LZO ] ; then decompress_packet $LZO.tar.* fi # Cross compile lzo cd $LZO if [ ! -s src/.libs/liblzo*.a ] ; then unset LDFLAGS ./configure --enable-static --disable-shared make fi cd - echo "+----------------------------------------+" echo "| Cross compile $ZLIB now " echo "| Crosstool: $CROSS" echo "+----------------------------------------+" # Download zlib source code packet if [ ! -s $ZLIB.tar* ] ; then #wget http://www.zlib.net/$ZLIB.tar.gz #wget http://www.imagemagick.org/download/delegates/$ZLIB.tar.bz2 #wget http://down1.chinaunix.net/distfiles/$ZLIB.tar.bz2 wget http://pkgs.fedoraproject.org/repo/pkgs/zlib/zlib-1.2.5.tar.bz2/be1e89810e66150f5b0327984d8625a0/$ZLIB.tar.bz2 fi # Decompress zlib source code packet if [ ! -d $ZLIB ] ; then decompress_packet $ZLIB.tar.* fi #Cross compile zlib cd $ZLIB if [ ! -s libz.a ] ; then unset LDFLAGS ./configure --static make fi cd - echo "+----------------------------------------+" echo "| Cross compile e2fsprogsV$e2fsprogs_ver now " echo "| Crosstool: $CROSS" echo "+----------------------------------------+" #e2fsprogs is for UBIFS, download e2fsprogs source code packet if [ ! -s e2fsprogs-$e2fsprogs_ver.tar.gz ] ; then wget http://nchc.dl.sourceforge.net/project/e2fsprogs/e2fsprogs/$e2fsprogs_ver/e2fsprogs-$e2fsprogs_ver.tar.gz fi # Decompress e2fsprogs source code packet if [ ! -d e2fsprogs-$e2fsprogs_ver ] ; then decompress_packet e2fsprogs-$e2fsprogs_ver.tar.* fi cd e2fsprogs-$e2fsprogs_ver if [ ! -s lib/libuuid.a ] ; then ./configure --enable-elf-shlibs make fi cd - echo "+----------------------------------------+" echo "| Cross compile mtd-utils now " echo "| Crosstool: $CROSS" echo "+----------------------------------------+" if [ ! -s ${mtd}.tar.bz2 ] ; then wget ftp://ftp.infradead.org/pub/mtd-utils/${mtd}.tar.bz2 fi decompress_packet ${mtd}.tar.bz2 # download mtd-utils source code #if [ ! -d mtd-utils* ] ; then #git clone git://git.infradead.org/mtd-utils.git #fi cd ${mtd} #Add the CROSS tool in file common.mk line=`sed -n '/CFLAGS ?= -O2 -g/=' common.mk ` if [ ! -z $line ] ; then sed -i -e ${line}s"|.*|CFLAGS ?= -O2 -g --static|" common.mk fi unset LDFLAGS unset CFLAGS set -x export CFLAGS="-DWITHOUT_XATTR -I$PRJ_PATH/$ZLIB -I$PRJ_PATH/$LZO/include -I$PRJ_PATH/e2fsprogs-$e2fsprogs_ver/lib" export ZLIBLDFLAGS=-L$PRJ_PATH/$ZLIB export LZOLDFLAGS=-L$PRJ_PATH/$LZO/src/.libs/ export LDFLAGS="-static -L $PRJ_PATH/e2fsprogs-$e2fsprogs_ver/lib $ZLIBLDFLAGS $LZOLDFLAGS" make set -x #strip nandwrite flash_erase nanddump #sudo cp nandwrite $INST_PATH/.nandwrite #sudo cp flash_erase $INST_PATH/.flash_erase #sudo cp nanddump $INST_PATH/.nanddump
如果你在执行这个脚本的出现了:
/usr/bin/ld: cannot find -lc
2.制作根文件系统
#!/bin/sh #=========================================== # Shell script body start here + #=========================================== CPU=s3c2440 rootfs_dir=rootfs partition_sizeM=40 image_name=ubifs-${CPU}.rootfs if [ ! -d $rootfs_dir ] ; then echo "Miss rootfs source code tree \"$rootfs_dir\" exit..." exit; fi #Default setting by UBIFS sub_page_size=512 vid_head_offset=512 #-m, minimum I/O unit size, it's 2K(the Page size) on K9F2G08, refer to "UBI: smallest flash I/O unit: 2048" page_size_in_bytes=2048 #echo "Page size [$page_size_in_bytes] bytes." #It's 64 pages per block on K9F2G08 pages_per_block=64 block_size_in_bytes=`expr $page_size_in_bytes \* $pages_per_block` #echo "[$pages_per_block] pages per block and [$block_size_in_bytes] bytes" #It's 2048 blocks on K9F2G08 blocks_per_device=2048 #echo "Blocks per device [$blocks_per_device]" #-e, logical erase block size, fixed on K9F2G08, refer to u-boot information "UBI: logical eraseblock size: 129024 bytes" # logical erase block size is physical erase block size minus 1 page for UBI logical_pages_per_block=`expr $pages_per_block - 1` logical_erase_block_size=`expr $page_size_in_bytes \* $logical_pages_per_block` #echo "Logical erase block size: [$logical_erase_block_size] bytes." # wear_level_reserved_blocks is 1% of total blcoks per device wear_level_reserved_blocks=`expr $blocks_per_device / 100` #echo "Reserved blocks for wear level [$wear_level_reserved_blocks]" #The rootfs partition size in bytes partition_size_in_bytes=`expr $partition_sizeM \* 1024 \* 1024` partition_physical_blocks=`expr $partition_size_in_bytes / $block_size_in_bytes` #echo "Partition size [$partition_size_in_bytes] bytes and [$partition_physical_blocks] blocks." #Logical blocks on a partition = physical blocks on a partitiion - reserved for wear level patition_logical_blocks=`expr $partition_physical_blocks - $wear_level_reserved_blocks` #echo "Logical blocks in a partition [$patition_logical_blocks]" #File-system volume = Logical blocks in a partition * Logical erase block size fs_vol_size=`expr $patition_logical_blocks \* $logical_erase_block_size` #echo "File-system volume [$fs_vol_size] bytes." config_file=rootfs_ubinize.cfg image_tmp=ubifs-${CPU}.img echo "" echo "Generating $image_name file by mkfs.ubifs..." set -x sudo /usr/local/bin/mkfs.ubifs -x lzo -m $page_size_in_bytes -e $logical_erase_block_size -c $patition_logical_blocks -r $rootfs_dir -o $image_tmp set +x echo echo "Generating configuration file..." echo "[ubifs-volume]" > $config_file echo "mode=ubi" >> $config_file echo "image=$image_tmp" >> $config_file echo "vol_id=0" >> $config_file echo "vol_size=$fs_vol_size" >> $config_file echo "vol_type=dynamic" >> $config_file echo "vol_name=rootfs" >> $config_file echo "vol_flags=autoresize" >> $config_file echo "vol_alignment=1" >> $config_file echo set -x sudo /usr/local/bin/ubinize -o $image_name -m $page_size_in_bytes -p $block_size_in_bytes -s $sub_page_size -O $vid_head_offset $config_file set +x sudo rm -f $image_tmp $config_file
rootfs_dir=rootfs
最后会生成ubifs-s3c2440.rootfs这个文件系统的映像文件,你也可以在脚本中改名字
<span style="font-family:Microsoft YaHei;font-size:10px;">CPU=s3c2440</span>
<span style="font-family:Microsoft YaHei;font-size:10px;">image_name=ubifs-${CPU}.rootfs</span>
—————————————————————————————————————————————————————————————————————————————
3.内核配置
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)
如果你出现了:UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 0:512, written 0 byte
Device Drivers --->
<*> Memory Technology Device (MTD) support --->
<*> NAND Device Support --->
[ ] Verify NAND page writes //不要选这个即可解决~
———————————————————————————————————————————————————————————————————————
4.uboot参数的修改
可以参考我的环境参数:(将MTDBLOCK6挂在为ubifs类型的根文件系统)
这里需要注意的是:
bubifs=tftp 30008000 ubifs-$cpu.rootfs;nand erase 8800000 2800000;nand write 30008000 8800000 $filesize
这里擦除一定要是整个分区的大小,这里分区是40M,所以这里的是0x2800000(20MB=0x1400000) 20MB=20*1024*1024然后再转化为16进制
不然你没擦干净,再重启的时候会出现:
error: ubi_io_read: error -1
—————————————————————————————————————————————————————————————
5.根文件系统的里面配置文件的小修改:
怕mdev自动挂载ubifs,所以改一下。
如果出现了文件系统不能挂载,则需要注意的就是uboot的参数。
一个是:
set bootargs 'console=ttyS0,115200 mem=64M ubi.mtd=6 root=ubi0:rootfs rootwait rootfstype=ubifs rw'
另一个是:
set bubifs 'tftp 30008000 rootfs.ubifs;nand erase8800000 28000000;nand write 30008000 8800000 900000'
分区写的地址一定要对
还有就是你的inittab这个脚本文件可能要修改一下,不要再挂载mtdblock6这个分区了。
—————————————————————————————————————————————————————————————————————————————
6.为啥要用这个ubifs文件系统呢?
当我们用jffs2 文件系统挂载一个分区的时候,传文件如果太大会有这种警告,而且我开发板还经常会有一些莫名其妙的问题,而且如果我文件一旦过大则会出现很多问题,现在需要做Qt项目,还有wifi 3G等项目,所以需要一个稳定的文件系统来支持:
如果是用ubifs则不会有这种情况
最后我贴一下我文件系统的mount信息,根文件系统是ubifs(mtdblock6),apps分区是jffs2(mtdblock7)类型的: