歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

arm+linux fl2440 根文件系統移植(三)

jffs2文件系統
一、添加內核對jffs2的支持
[shaocongshuai@Centos-shaocongshuai linux-3.0.2]$ make menuconfig

File systems --->
[*] Miscellaneous filesystems --->
<*> Journalling Flash File System v2 (JFFS2) support
(0) JFFS2 debugging verbosity (0 = quiet, 2 = noisy)
[*] JFFS2 write-buffering support
[shaocongshuai@Centos-shaocongshuai linux-3.0.2]$ make
然後再將linuxrom-s3c2440.bin文件上傳到tftp上。
二、制作mkfs.jffs2mkfs.ubifs工具
[shaocongshuai@Centos-shaocongshuai opt]$ mkdir mtd-utiles
[shaocongshuai@Centos-shaocongshuai opt]$ cd mtd-utiles/
[shaocongshuai@Centos-shaocongshuai mtd-utiles]$ vim build.sh
#!/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 <[email protected]>
#| 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
wgethttp://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
#wgethttp://www.zlib.net/$ZLIB.tar.gz
#wgethttp://www.imagemagick.org/download/delegates/$ZLIB.tar.bz2
#wget
http://down1.chinaunix.net/distfiles/$ZLIB.tar.bz2
wgethttp://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
wgethttp://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
wgetftp://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
[shaocongshuai@Centos-shaocongshuai mtd-utiles]$ sh build.sh
: command not found
: command not found
: command not found
: command not found
'uild.sh: line 18: syntax error near unexpected token `
'uild.sh: line 18: `function decompress_packet()
出現如上錯誤時,則執行
[shaocongshuai@Centos-shaocongshuai mtd-utiles]$ dos2unix build.sh
dos2unix是將Windows格式文件轉換為Unix、Linux格式的實用命令。Windows格式文件的換行符為\r\n ,而Unix&Linux文件的換行符為\n. dos2unix命令其實就是將文件中的\r\n 轉換為\n。
而unix2dos則是和dos2unix互為孿生的一個命令,它是將Linux&Unix格式文件轉換為Windows格式文件的命令。
[shaocongshuai@Centos-shaocongshuai mtd-utiles]$ sh build.sh
出現如下:
.......
CHK include/version.h
LD ftl_format
/usr/bin/ld: cannot find -lc
collect2: ld returned 1 exit status
make: *** [/opt/mtd-utiles/mtd-utils-1.4.9/ftl_format] Error 1
+ set -x
這可能是缺少相應的libc.so的庫文件
[shaocongshuai@Centos-shaocongshuai mtd-utiles]$ sudo yum install -y glibc-static
[shaocongshuai@Centos-shaocongshuai mtd-utiles]$ ls
build.sh e2fsprogs-1.42 e2fsprogs-1.42.tar.gz lzo-2.04 lzo-2.04.tar.gz mtd-utils-1.4.9 mtd-utils-1.4.9.tar.bz2 zlib-1.2.5 zlib-1.2.5.tar.bz2
[shaocongshuai@Centos-shaocongshuai mtd-utiles]$ cd mtd-utils-1.4.9
[shaocongshuai@Centos-shaocongshuai mtd-utils-1.4.9]$ ls
common.mk compr_zlib.c doc_loadbios.c flash_eraseall flash_otp_dump.o flash_unlock.o jffs2dump load_nandsim.sh mkfs.jffs2.o nanddump.o nftldump.c recv_image rfdformat.o tests
compr.c compr_zlib.o doc_loadbios.o flash_erase.c flash_otp_info ftl_check jffs2dump.c make_a_release.sh mkfs.ubifs nandtest nftldump.o recv_image.c serve_image ubi-utils
compr.h COPYING feature-removal-schedule.txt flash_erase.o flash_otp_info.c ftl_check.c jffs2dump.o MAKEDEV mtd_debug nandtest.c nftl_format recv_image.o serve_image.c
compr_lzo.c device_table.txt fectest.c flash_lock flash_otp_info.o ftl_check.o jffs2reader Makefile mtd_debug.c nandtest.o nftl_format.c rfddump serve_image.o
compr_lzo.o docfdisk flashcp flash_lock.c flash_otp_lock.c ftl_format jffs2reader.c mcast_image.h mtd_debug.o nandwrite nftl_format.o rfddump.c summary.h
compr.o docfdisk.c flashcp.c flash_lock.o flash_otp_write.c ftl_format.c jffs2reader.o mkfs.jffs2 mtd-utils.spec nandwrite.c rbtree.c rfddump.o sumtool
compr_rtime.c docfdisk.o flashcp.o flash_otp_dump flash_unlock ftl_format.o jffs-dump.c mkfs.jffs2.1 nanddump nandwrite.o rbtree.h rfdformat sumtool.c
compr_rtime.o doc_loadbios flash_erase flash_otp_dump.c flash_unlock.c include lib mkfs.jffs2.c nanddump.c nftldump rbtree.o rfdformat.c sumtool.o
[shaocongshuai@Centos-shaocongshuai mtd-utils-1.4.9]$ ls mkfs.ubifs/
compr.c compr.h compr.o COPYING crc16.c crc16.h crc16.o defs.h devtable.c devtable.o hashtable key.h lpt.c lpt.h lpt.o mkfs.ubifs mkfs.ubifs.c mkfs.ubifs.h mkfs.ubifs.o README ubifs.h ubifs-media.h
[shaocongshuai@Centos-shaocongshuai mtd-utils-1.4.9]$ file mkfs.jffs2
mkfs.jffs2: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, not stripped
[shaocongshuai@Centos-shaocongshuai mtd-utils-1.4.9]$ sudo cp mkfs.jffs2 /usr/local/bin/
[shaocongshuai@Centos-shaocongshuai mtd-utils-1.4.9]$ mkfs.jffs2 -V
mkfs.jffs2: error!: revision 1.60
[shaocongshuai@Centos-shaocongshuai mtd-utils-1.4.9]$ mkfs.jffs2
mkfs.jffs2: error!: Usage: mkfs.jffs2 [OPTIONS]
Make a JFFS2 file system image from an existing directory tree
Options:
-p, --pad[=SIZE] Pad output to SIZE bytes with 0xFF. If SIZE is
not specified, the output is padded to the end of
the final erase block
-r, -d, --root=DIR Build file system from directory DIR (default: cwd)
-s, --pagesize=SIZE Use page size (max data node size) SIZE (default: 4KiB)
-e, --eraseblock=SIZE Use erase block size SIZE (default: 64KiB)
-c, --cleanmarker=SIZE Size of cleanmarker (default 12)
-m, --compr-mode=MODE Select compression mode (default: priortiry)
-x, --disable-compressor=COMPRESSOR_NAME
Disable a compressor
-X, --enable-compressor=COMPRESSOR_NAME
Enable a compressor
-y, --compressor-priority=PRIORITY:COMPRESSOR_NAME
Set the priority of a compressor
-L, --list-compressors Show the list of the avaiable compressors
-t, --test-compression Call decompress and compare with the original (for test)
-n, --no-cleanmarkers Don't add a cleanmarker to every eraseblock
-o, --output=FILE Output to FILE (default: stdout)
-l, --little-endian Create a little-endian filesystem
-b, --big-endian Create a big-endian filesystem
-D, --devtable=FILE Use the named FILE as a device table file
-f, --faketime Change all file times to '0' for regression testing
-q, --squash Squash permissions and owners making all files be owned by root
-U, --squash-uids Squash owners making all files be owned by root
-P, --squash-perms Squash permissions on all files
-h, --help Display this help text
-v, --verbose Verbose operation
-V, --version Display version information
-i, --incremental=FILE Parse FILE and generate appendage output for it

三、制作映像文件

[shaocongshuai@Centos-shaocongshuai fl2440]$ ls
3rdparty bootloader driver kernel program rootfs
[shaocongshuai@Centos-shaocongshuai fl2440]$ mkfs.jffs2 -n -s 2048 -e 128KiB -d rootfs -o rootfs.jffs2 --pad=0x1400000
[shaocongshuai@Centos-shaocongshuai fl2440]$ ls
3rdparty bootloader driver kernel program rootfs rootfs.jffs2
[shaocongshuai@Centos-shaocongshuai fl2440]$ du -sh rootfs.jffs2
20M rootfs.jffs2
各參數的意義:
(1)-r :指定根文件系統目錄.
(2)-o : 指定輸出的根文件系統名.
(3)-s : 指定flash每一頁的大小;
(3)-e : 指定flash的檫除塊的大小,預設是64KB.
要注意,不同的flash, 其page size和block size會不一樣.,如果是K9F2G08U0M,在它的datasheet上有說明:

1 Page = (2K+64)Bytes
1 Block = (2K+64)Bytes = (128K+4K) Bytes
1 Device = (2K+64)B * 64Pages * 2048 Blocks = 2112 Mbits
所以上面指定: "s 2048 -e 128KiB"。
如果是K9F1208U0C,在它的datasheet上有說明:

則上面指定: "s 512 -e 16KiB"
(5)如果掛載後會出現類似:CLEANMARKER node found at 0x0042c000 has totlen 0xc != normal 0x0 的警告,則加上-n
就會消失。
(5) -n 指明不添加清除標記(nand flash有自己的校檢塊,存放相關的信息。)
如果掛載後會出現類似下面的警告,則加上-n就會消失:
CLEANMARKER node found at 0x0042c000 has totlen 0xc != normal 0x0
通過下面的方式可以對rootfs.jffs2映像文件中的內容進行修改,如果沒有必要可以不用
Copyright © Linux教程網 All Rights Reserved