移植环境(红色粗字体字为修改后内容,蓝色粗体字为特别注意内容)
1,主机环境:VMare下CentOS 5.5 ,1G内存。
2,集成开发环境:Elipse IDE
3,编译编译环境:arm-linux-gcc v4.4.3,arm-none-linux-gnueabi-gcc v4.5.1。
4,开发板:mini2440,2M nor flash,128M nand flash。
5,u-boot版本:u-boot-2009.08
6,linux 版本:linux-2.6.32.2
7,参考文章:
嵌入式linux应用开发完全手册,韦东山,编著。
Mini2440 之Linux 移植开发实战指南
http://linux.chinaunix.net/techdoc/system/2009/08/24/1131864.shtml
接上篇,问题的解决
解题思路:用tar 压缩我自己做的rootfs根文件系统打包, 这个系统是可以启动到NFS的,所以东西是全的。然后用nand flash 工具将nand flash的mtdblock3分区格式化后挂载,再将打包的rootfs下所有子目录和文件解压到此分区。
【4】挂载分区测试
按照之前内核引导参数的设定方式,将u-boot的bootgars参数设为nfs启动
[root@mini2440 /]#mount -t yaffs /dev/mtdblock1 /mnt/yaffs
yaffs: dev is 32505857 name is "mtdblock1" rw
yaffs: passed flags ""
mount: mounting /dev/mtdblock1 on /mnt/yaffs failed: Invalid argument
[root@mini2440 /]#mount -t yaffs /dev/mtdblock0 /mnt/yaffs
yaffs: dev is 32505856 name is "mtdblock0" rw
yaffs: passed flags ""
mount: mounting /dev/mtdblock0 on /mnt/yaffs failed: Invalid argument
[root@mini2440 /]#umount /mnt/yaffs
[root@mini2440 /]#mount -t yaffs /dev/mtdblock2 /mnt/yaffs
yaffs: dev is 32505858 name is "mtdblock2" rw
yaffs: passed flags ""
[root@mini2440 /]#ls -a /mnt/yaffs
. .. lost+found
[root@mini2440 /]#umount /mnt/yaffs
[root@mini2440 /]#mount -t yaffs /dev/mtdblock3 /mnt/yaffs
yaffs: dev is 32505859 name is "mtdblock3" rw
yaffs: passed flags ""
[root@mini2440 /]#ls -a /mnt/yaffs
. .. lost+found
[root@mini2440 /]#cat proc/mtd
dev: size erasesize name
mtd0: 00040000 00020000 "boot"
mtd1: 00020000 00020000 "param"
mtd2: 00500000 00020000 "kernel"
mtd3: 07aa0000 00020000 "rootfs"
mtd4: 08000000 00020000 "nand"
[root@mini2440 /]#
根据挂载的反馈信息,可以确定mtdblock0和mtdblock1分别是u-boot和其参数的分区而不能够被挂载,mtdblock2和mtdblock3分别是内核kernel和根文件系统rootfs分区能够被挂载。虽然成功挂载了yaffs文件系统,但不能从中读取因存在的文件信息。
【5】制作在nand flash操作工具mtd-utils工具
参考文章
mtd-utils工具的编译和使用
mtd-utils 及 i-utils 交叉编译
mtd-utils交叉编译
UBI文件系统简介
在ubuntu 10.04上交叉编译编译 mtd-utils
交叉编译libz, lzo, mtd-utils的脚本
对于mtd-utils工具的编译,可谓是费了不少周折,着重参考了上面几篇文章,可以用以下两种办法来解决其libz,lzo,uuid库的依赖问题
<1>手动安装mtd-utils所需要的库
A ,下载源代码:
zlib和lzo是编译mtd-utils所需库文件,需提前交叉编译完成,以供mtd-utils编译时调用
zlib:
http://www.zlib.net/zlib-1.2.5.tar.gz
http://www.dnaphp.com/downloads/server/linux/30-zlib-1-2-5-tar
lzo:
http://www.oberhumer.com/opensource/lzo/download/,这里下载是lzo-2.05.tar.gz
E2fsprogs:
http://e2fsprogs.sourceforge.net/,这里下载的是e2fsprogs-1.41.14.tar.gz
mtd-utils:
ftp://ftp.infradead.org/p /mtd-utils/
下载后
[root@localhost linux-test]# cd mtdtools
[root@localhost mtdtools]# ls
e2fsprogs-1.41.14.tar.gz mtd-utils-1.4.4.tar.bz2
lzo-2.05.tar.gz zlib-1.2.5.tar.gz
可以在打开的页面中下载最新版本,分别对其进行解压
[root@localhost mtdtools]# tar -zxf zlib-1.2.5.tar.gz
[root@localhost mtdtools]# tar -zxf lzo-2.05.tar.gz
[root@localhost mtdtools]# tar -jxf mtd-utils-1.4.4.tar.bz2 -C ./
B,编译安装zlib
[root@localhost linux-test]# cd zlib-1.2.5
[root@localhost zlib-1.2.5]#CC=arm-linux-gcc ./configure --enable-static --disable-shared --prefix=/usr/local/arm/4.4.3/arm-none-linux-gnueabi
[root@localhost zlib-1.2.5]# make
[root@localhost zlib-1.2.5]# make install
检查: zconf.h 和 libz.a 都安装到了工具链目录.
其中-prefix指定zlib的安装路径,需要指定到交叉编译器所在路径,而且是与命令执行的bin文件夹同一级别的目录下而非软连接的bin目录!
C,编译安装lzo
[root@localhost zlib-1.2.5]# cd ../lzo-2.05
[root@localhost lzo-2.05]#CC=arm-linux-gcc ./configure --host=arm-linux --enable-static --disable-shared --prefix=/usr/local/arm/4.4.3/arm-none-linux-gnueabi
[root@localhost lzo-2.05]# make
[root@localhost lzo-2.05]# make install
检查:liblzo2.a 已经拷贝到工具链的lib目录.
解决错误现象:error: lzo/lzo1x.h: No s h file or director
D,编译安装e2fsprogs
配置e2fsprogs
[root@localhost e2fsprogs-1.41.14]#CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/usr/local/arm/4.4.3/arm-none-linux-gnueabi
编译
[root@localhost e2fsprogs-1.41.14]# make
安装,因为我们只需要 uuid 库, 所以不需要完全安装, 查看 Makefile文件, 所以只执行make install-libs
[root@localhost e2fsprogs-1.41.14]# make install-libs
检查,可以在工具链目录看到, uuid/uuid.h 文件已经安装. libuuid.a 已经安装.
解决错误现象:uuid/uuid.h: No s h file or directory
E,编译安装mtd-uitls
进入到mtd-uitls目录所在的目录,在make时需要指定交叉编译工具
[root@localhost lzo-2.05]# cd ../mtd-utils-1.4.4
[root@localhost mtd-utils-1.4.4]# mkdir mtd_install
[root@localhost mtd-utils-1.4.4]# export CROSS=arm-linux-
[root@localhost mtd-utils-1.4.4]# export WITHOUT_XATTR=1
[root@localhost mtd-utils-1.4.4]# export DESTDIR=./mtd_install
需要指定WITHOUT_XATTR=1 是由于在编译 mkfs.jffs2使其不调用acl.h而是用zlib的库,否则出现
sys/acl.h:mkfs.jffs2.c:69:21: error: sys/acl.h: No s h file or directory
直接编译:
make
make install
检查1:mtdtools/mtd-utils-1.4.4/arm-linux(即所指定的CROSS)目录已经拷贝了所有mtd-utils的工具.
检查2:file flash_erase
flash_erase: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
上面信息有两点要注意, 第一是使用静态/动态库,第二是没有striped/not triped。
这里strip是用来去除编译出来的命令中的debug信息的。
如果file出的信息是dynamically linked 和stripped ,那么要在目标板上执行此程序,需要将编译器的lib目录下所有库文件复制到目标板的lib目录下,如果不想使用库文件,就要编译成静态链接方式:
查看mtd-utils-1.4.4的common.mk 文件,发现有 CFLAGS ?= -O2 -g 编译选项。
所以再加上一个选项:
export CFLAGS="-static -O2 -g"
重新运行make 和 make install 后发现
file flash_erase
flash_erase: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
遗留问题1
显然采用-static方式编译后,仍然是动态链接方式,这个问题目前也是悬而未决。
目前也只能采用复制库的方式。
F,去掉调试信息:
在当前目录的mtd_intall/usr/sbin下运行
arm-linux-strip * //注意*前面有一空格
再次检查:file flash_erase
flash_erase: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), stripped
完成, 编译出来的工具如: flash_eraseall, ubimkvol, ubiattach 等都可以独立运行而不需要链接库文件。
下面是有关trip一些用法:
strip经常用来去除目标文件中的一些符号表、调试符号表信息,以减小程序的大小,在rpmbuild包的最后就用到。
其支持的选项如下:
>strip -h
用法:strip <选项> 输入文件
从文件中删除符号和节
选项为:
-I --input-target=<bfdname> Assume input file is in format <bfdname>
-O --output-target=<bfdname> Create an output file in format <bfdname>
-F --target=<bfdname> Set both input and output format to <bfdname>
-p --preserve-dates Copy modified/access timestamps to the output
-R --remove-section=<name> Remove section <name> from the output
-s --strip-all Remove all symbol and relocation information
-g -S -d --strip-debug Remove all debugging symbols & sections
--strip-unneeded Remove all symbols not needed by relocations
--only-keep-debug Strip everything but the debug information
-N --strip-symbol=<name> Do not copy symbol <name>
-K --keep-symbol=<name> Do not strip symbol <name>
--keep-file-symbols Do not strip file symbol(s)
-w --wildcard Permit wildcard in symbol comparison
-x --discard-all Remove all non-global symbols
-X --discard-locals Remove any compiler-generated symbols
-v --verbose List all object files modified
-V --version Display this program's version number
-h --help Display this output
--info List object formats & architectures supported
-o <file> Place stripped output into <file>
strip:支持的目标: elf32-i386 a.out-i386-linux efi-app-ia32 elf32-little elf32-big elf64-alpha ecoff-littlealpha elf64-little elf64-big elf32-littlearm elf32-bigarm elf32-hppa-linux elf32-hppa elf64-ia64-little elf64-ia64-big efi-app-ia64 elf32-m68k a.out-m68k-linux elf32-powerpc aixcoff-rs6000 elf32-powerpcle ppcboot elf64-powerpc elf64-powerpcle aixcoff64-rs6000 elf32-s390 elf64-s390 elf32-sparc a.out-sparc-linux elf64-sparc a.out-sunos-big elf64-x86-64 pe-i386 pei-i386 srec symbolsrec tekhex binary ihex trad-core
目标文件分为:可重定位文件、可执行文件、共享文件
strip的默认选项会去除.symbol节的内容以及.debug节的内容,因此尽量只对可执行文件执行strip而不要对静态库或动态库等目标文件strip。
可见无论是静态库(libxxx.a)还是动态库(libxxx.so)还是可执行文件(如test),去掉一些符号信息后都减小了很多,但如果这时再链接这两个库的话是编不过的,因此,如果不是指定特殊的strip选项的话,还是尽量不要对库文件strip,只对链接后的可执行文件strip就可以了(如果也不调试)。
<2>制作脚本文件,使其自动生成mtd-utils工具。
A,在mtdtools目录下新建一个文件mtdtools_build.sh,将下面内容复制其中,此文件我在GuoWenxue博主的基础上做了一些改动经过调试运行完成。
#!/bin/sh
#+----------------------------------------------------------------------------+
#|decription: This shell script is used to download lzo,zlib,e2fsporgs,
#| mtd-utils source code and cross compile it for ARM Linux,
#| all is static cross compile.
#| Author: GuoWenxue <[email protected]>
#| Modified: singleboy <[email protected]>
#| ChangeLog:
#| 1, Initialize 1.0.1 on 2011.06.16
#+----------------------------------------------------------------------------+
PRJ_PATH=`pwd`
#CROSS=arm-linux-
CROSS=arm-none-linux-gnueabi-
#COMPILER_PATH=/usr/local/arm/4.4.3/arm-none-linux-gnueabi
#COMPILER_PATH=/usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi
CC=${CROSS}gcc
AR=${CROSS}ar
LD=${CROSS}ld
STRIP=${CROSS}strip
NM=${CROSS}nm
RANLIB=${CROSS}ranlib
OBJDUMP=${CROSS}objdump
export CC=${CC}
export AR=${AR}
export LD=${LD}
export STRIP=${STRIP}
export NM=${NM}
export RANLIB=${RANLIB}
export OBJDUMP=${OBJDUMP}
LZO="lzo-2.05"
ZLIB="zlib-1.2.5"
E2FSPROGS="e2fsprogs"
function decompress_packet()
(
echo "+----------------------------------------+"
echo "| Decompress $1 now"
echo "+----------------------------------------+"
if [ `ls $1 | grep "tar.bz2"` ] ; then
set -x
tar -xjf $1
set +x
fi
if [ `ls $1 | grep "tar.gz"` ] ; then
set -x
tar -xzf $1
set +x
fi
)
echo "+----------------------------------------+"
echo "| Cross compile $ZLIB now "
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
fi
# Decompress zlib source code packet
if [ ! -d $ZLIB ] ; then
decompress_packet $ZLIB.tar.*
fi
#Cross compile zlib
cd $ZLIB
echo "first clean the middle object files befor compiling in case of incompatible compiled error"
make clean
if [ ! -s libz.a ] ; then
unset LDFLAGS
./configure --static
make
fi
cd -
echo "+----------------------------------------+"
echo "| Cross compile $LZO now "
echo "+----------------------------------------+"
# 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
echo "first clean the middle object files befor compiling in case of incompatible compiled error"
make clean
if [ ! -s src/.libs/liblzo*.a ] ; then
unset LDFLAGS
./configure --host=arm-linux --enable-static --disable-shared \
CC=${CROSS}gcc AR=${AR} LD=${LD} \
NM=${NM} RANLIB=${RANLIB} STRIP="${STRIP}" OBJDUMP=${OBJDUMP}
make
fi
cd -
echo "+----------------------------------------+"
echo "| Cross compile $E2FSPROGS now "
echo "+----------------------------------------+"
# Download e2fsprogs source code packet
if [ ! -s $E2FSPROGS.tar* ] ; then
#wget http://cdnetworks-kr-1.dl.sourceforge.net/project/e2fsprogs/e2fsprogs/1.41.14/e2fsprogs-1.41.14.tar.gz
git clone git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
fi
# Decompress e2fsprogs source code packet
if [ ! -d $E2FSPROGS ] ; then
decompress_packet $E2FSPROGS.tar.*
fi
#Cross compile e2fsprogs
cd $E2FSPROGS
# echo "first make clean the middle object files"
echo "first clean the middle object files befor compiling in case of incompatible compiled error"
# make clean
if [ ! -s libuuid.a ] ; then
unset LDFLAGS
./configure --host=arm-linux --enable-static --disable-shared \
CC=${CROSS}gcc AR=${AR} LD=${LD} \
NM=${NM} RANLIB=${RANLIB} STRIP="${STRIP}" OBJDUMP=${OBJDUMP}
make
fi
cd -
echo "+----------------------------------------+"
echo "| Cross compile mtd-utils now "
echo "+----------------------------------------+"
if [ -s mtd-utils.tar.* ] ; then
decompress_packet mtd-utils.tar.*
fi
# download mtd-utils source code
if [ ! -d mtd-utils ] ; then
git clone git://git.infradead.org/mtd-utils.git
fi
#Add the CROSS tool in file mtd-utils/common.mk
#head -1 mtd-utils/common.mk | grep "CROSS=${CROSS}"
#if [ 0 != $? ] ; then
# echo "Modify file mtd-utils/common.mk"
# sed -i -e 1i"CROSS=${CROSS}" mtd-utils/common.mk
#fi
cd mtd-utils
echo "first clean the middle object files befor compiling in case of incompatible compiled error"
make clean
unset LDFLAGS
export CFLAGS="-DWITHOUT_XATTR -I$PRJ_PATH/$ZLIB -I$PRJ_PATH/$LZO/include -I$PRJ_PATH/$E2FSPROGS/lib/"
export ZLIBLDFLAGS=-L$PRJ_PATH/$ZLIB
export LZOLDFLAGS=-L$PRJ_PATH/$LZO/src/.libs
export E2FSPROGSLDFLAGS=-L$PRJ_PATH/$E2FSPROGS/lib
export LDFLAGS=-static
make CROSS=${CROSS}
echo "now build the mtd-utils tools directory to install"
if [ ! -d usrdir ] ; then
mkdir usrdir
echo "the directory to install is usrdir"
fi
make CROSS=${CROSS} DESTDIR=./usrdir install
# remove the debug infomation with trip command
# BUILDDIR=${CROSS%-}
# echo "now entering ${BUILDDIR} ..."
# cd ${BUILDDIR}
echo "now entering the directory usrdir/usr/sbin"
cd usrdir/usr/sbin
echo "now remove the debug infomation with trip command"
${CROSS}strip *
file *
echo "now the mtd-utils has been made completely and you can copy the tools in ./usrdir/usr/sbin/ to your target directory/usr/sbin/"
cd -
cd -
说明,这个脚本arm-none-linux-gnueabi-gcc v 4.5.1版本中执行成功,但是在arm-linux-gcc(arm-none-linux-gnueabi-gcc v4.4.3)没有执行成功,出现“Unknown mandatory EABI object attribute 44”错误,目前还未查清原因。
以下是脚本在v4.5.1版本运行的部分信息:
[root@localhost mtdtools]#./mtdtools_build.sh
... ...
now entering the directory usrdir/usr/sbin
now remove the debug infomation with trip command
arm-none-linux-gnueabi-strip:flash_eraseall: File format not recognized
docfdisk: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
doc_loadbios: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
flashcp: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
flash_erase: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
flash_eraseall: Bourne shell script text executable
flash_info: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
flash_lock: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
flash_otp_dump: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
flash_otp_info: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
flash_unlock: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
ftl_check: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
ftl_format: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
jffs2dump: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
mkfs.jffs2: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
mtd_debug: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
nanddump: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
nandtest: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
nandwrite: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
nftldump: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
nftl_format: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
recv_image: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
rfddump: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
rfdformat: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
serve_image: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
sumtool: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.16, statically linked, for GNU/Linux 2.6.16, stripped
now the mtd-utils has been made completely and you can copy the tools in ./usrdir/usr/sbin/ to your target directory/usr/sbin/
/root/linux-test/mtdtools/mtd-utils
/root/linux-test/mtdtools/mtd-utils/usrdir/usr/sbin
[root@localhost mtdtools]# ls mtd-utils/arm-none-linux-gnueabi/
compr_lzo.o flash_erase ftl_format nanddump rfddump
compr.o flash_info jffs2dump nandtest rfdformat
compr_rtime.o flash_lock lib nandwrite serve_image
compr_zlib.o flash_otp_dump mkfs.jffs2 nftldump sumtool
docfdisk flash_otp_info mkfs.jffs2.o nftl_format ubi-utils
doc_loadbios flash_unlock mkfs.ubifs rbtree.o
flashcp ftl_check mtd_debug recv_image
[root@localhost mtdtools]#
其中mkfs.ubifs目录中存放的是制作ubifs文件系统映像的工具,ubi-utils目录中存放的是ubifs文件系统的操作工具。
接下来,将回到前面遗留问题即mtdblock分区加载和挂载根目录问题