Migration environment
1. Host environment: CentOS 5.5 under VMare, 1G memory.
2. Integrated development environment: Eclipse IDE
3. Compilation environment: arm-linux-gcc v4.4.3, arm-none-linux-gnueabi-gcc v4.5.1.
4. Development board: mini2440, 2M nor flash, 128M nand flash.
5.u-boot version: u-boot-2009.08
6. Linux version: linux-2.6.32.2
7. References:
嵌入式linux应用开发完全手册,韦东山,编著。
Mini2440 Linux Porting Development Practical Guide
http://linux.chinaunix.net/techdoc/system/2009/08/24/1131864.shtml
Continuing from the previous article, problem solving
Solution: Use tar to compress the rootfs file system I made myself. This system can be booted to NFS, so everything is complete. Then use the nand flash tool to format the mtdblock3 partition of the nand flash and mount it, and then unzip all subdirectories and files under the packaged rootfs to this partition.
[4] Mount partition test
According to the previous kernel boot parameter setting method, set the bootgars parameter of u-boot to nfs boot
[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 /]#
According to the feedback information of the mount, it can be determined that mtdblock0 and mtdblock1 are the partitions of u-boot and its parameters respectively and cannot be mounted, while mtdblock2 and mtdblock3 are the partitions of kernel and root file system rootfs respectively and can be mounted. Although the yaffs file system is mounted successfully, the existing file information cannot be read from it.
【5】Mtd-utils tool for NAND flash operation
References
Compilation and use of mtd-utils tools
Cross-compilation of mtd-utils and i-utils
mtd-utils cross-compilation
Introduction to UBI File System
Cross-compile mtd-utils on Ubuntu 10.04
Cross-compile scripts for libz, lzo, mtd-utils
It took a lot of effort to compile the mtd-utils tool. I focused on the above articles and used the following two methods to solve the dependency problem of libz, lzo, and uuid libraries:
<1>Manually install the libraries required by mtd-utils
A, download the source code:
zlib and lzo are library files required to compile mtd-utils. They need to be cross-compiled in advance so that they can be called when compiling 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
can:
http://www.oberhumer.com/opensource/lzo/download/ , here is lzo-2.05.tar.gz
E2fsprogs:
http://e2fsprogs.sourceforge.net/ , here is e2fsprogs-1.41.14.tar.gz
mtd-utils:
ftp://ftp.infradead.org/p /mtd-utils/
After downloading
[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
You can download the latest version on the opened page and decompress it separately
[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. Compile and install 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
Check: zconf.h and libz.a are both installed in the toolchain directory.
The -prefix specifies the installation path of zlib, which needs to be specified to the path where the cross compiler is located, and it should be in the same directory as the bin folder where the command is executed, not the soft-linked bin directory!
C, compile and install 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
Check: liblzo2.a has been copied to the toolchain's lib directory.
Solution: error: lzo/lzo1x.h: No sh file or director
D. Compile and install 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
Compile
[root@localhost e2fsprogs-1.41.14]# make
installation, because we only need the uuid library, so there is no need to install it completely, check the Makefile file, so just execute make install-libs
[root@localhost e2fsprogs-1.41.14]# make install-libs
Check and you can see in the toolchain directory that the uuid/uuid.h file has been installed. libuuid.a has been installed.
Solve the error phenomenon: uuid/uuid.h: No sh file or directory
E, compile and install mtd-uitls
Enter the directory where the mtd-uitls directory is located. When making, you need to specify the cross-compilation tool
[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
The reason why WITHOUT_XATTR=1 needs to be specified is that when compiling mkfs.jffs2, it does not call acl.h but uses the zlib library. Otherwise,
sys/acl.h:mkfs.jffs2.c:69:21: error: sys/acl.h: No s h file or directory
Compile directly:
make
make install
Check 1: All mtd-utils tools have been copied to the mtdtools/mtd-utils-1.4.4/arm-linux (the specified CROSS) directory.
检查2:file flash_erase
flash_erase: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
There are two points to note in the above information, the first is the use of static/dynamic libraries, and the second is not striped/not triped.
Here strip is used to remove debug information from the compiled command.
If the information output by file is dynamically linked and stripped, then to execute this program on the target board, you need to copy all library files in the compiler's lib directory to the target board's lib directory. If you do not want to use the library files, you must compile it into static link mode:
Checking the common.mk file of mtd-utils-1.4.4, I found the CFLAGS ?= -O2 -g compilation option.
So add an option:
export CFLAGS="-static -O2 -g"
After re-running make and make install, I found
file flash_erase
flash_erase: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
Remaining issue 1
: Obviously, after compiling with -static mode, it is still dynamically linked. This issue is currently unresolved.
Currently, the only way is to copy the library.
F, remove debugging information:
Run under mtd_intall/usr/sbin in the current directory
arm-linux-strip * //Note that there is a space in front of *
再次检查:file flash_erase
flash_erase: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), stripped
Completed, compiled tools such as flash_eraseall, ubimkvol, ubiattach, etc. can run independently without linking library files.
Here are some usages of trip:
Strip is often used to remove some symbol table and debugging symbol table information in the target file to reduce the size of the program. It is used at the end of the rpmbuild package.
The supported options are as follows:
>strip -h
Usage: strip
Target files are divided into: relocatable files, executable files, and shared files.
The default strip option will remove the contents of the .symbol section and the .debug section. Therefore, try to strip only executable files instead of stripping target files such as static libraries or dynamic libraries.
It can be seen that whether it is a static library (libxxx.a), a dynamic library (libxxx.so) or an executable file (such as test), the size is greatly reduced after removing some symbol information, but if these two libraries are linked at this time, they cannot be compiled. Therefore, if no special strip option is specified, try not to strip the library file, and only strip the linked executable file (if you do not debug it either).
<2>Create a script file to automatically generate the mtd-utils tool.
A. Create a new file mtdtools_build.sh in the mtdtools directory and copy the following content into it. I made some changes to this file based on the GuoWenxue blogger's code and completed it after debugging and running.
#!/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 <guowenxue@gmail.com>
#| Modified: singleboy <singleboy@163.com>
#| 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 -
Note: This script is successfully executed in arm-none-linux-gnueabi-gcc v 4.5.1, but not in arm-linux-gcc (arm-none-linux-gnueabi-gcc v4.4.3), and an "Unknown mandatory EABI object attribute 44" error occurs. The reason has not yet been determined.
The following is some information about the script running in version 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]#
The mkfs.ubifs directory contains tools for making ubifs file system images, and the ubi-utils directory contains tools for operating ubifs file systems.
Next, we will return to the previous legacy issue, that is, the mtdblock partition loading and root directory mounting problem.
Previous article:Linux-2.6.32.2 kernel porting on mini2440 (Part 4) --- Root file system creation (3)
Next article:u-boot-2009.08 transplantation on mini2440 (Part 2) --- Adding NOR flash function
Recommended ReadingLatest update time:2024-11-16 07:48
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- IEEE 754 floating point hexadecimal conversion tool
- Disassembling the world's first automotive LiDAR
- How to Design an RF Power Amplifier
- The simulation of multiplication floating point IP in quartus, has anyone used it?
- LED downlight replacement dimmable power supply
- There are some problems with the PFC circuit power-on process. Please consult
- LM358 audio amplifier circuit (loudspeaker)
- CircuitPython OLED Watch/Bracelet
- Research on the process of long and short printed plug products
- [TI recommended course] #[High Precision Laboratory] Magnetic Sensor Technology#