Building embedded Linux systems-development tools
First, to establish the actual project work space
The Working Environment configuration script file (develenv), which reads as follows:
#start------------------------------------------------------------------------------------
#! /bin/bash
#设置环境变量
Export Project=daq-module
Export Prjroot=~/control-project/${project}
Export Target=arm-linux
Export Prefix=${prjroot}/tools
Export Target_prefix=${prefix}/${target}
Export Path=${prefix}/bin:${path}
#创建项目目录
mkdir ${prjroot} ${prjroot}/bootldr ${prjroot}/build-tools ${prjroot}/debug ${prjroot}/doc ${PRJROOT}/images ${ Prjroot}/kernel ${prjroot}/rootfs ${prjroot}/sysapps ${prjroot}/tmp ${prjroot}/tools
#创建build-tools Directory
mkdir ${prjroot}/build-tools/build-binutils ${PRJROOT}/BUILD-TOOLS/BUILD-BOOT-GCC ${prjroot}/build-tools/ BUILD-GLIBC ${PRJROOT}/BUILD-TOOLS/BUILD-GCC
#创建工具链所需要的include目录
Mkdir-p ${target_prefix}/include
#根文件系统的基本结构
mkdir ${prjroot}/rootfs/bin ${prjroot}/rootfs/dev ${prjroot}/rootfs/etc ${prjroot}/rootfs/lib ${PRJROOT}/rootfs/ Proc ${prjroot}/rootfs/sbin ${prjroot}/rootfs/tmp ${prjroot}/rootfs/usr ${prjroot}/rootfs/var
chmod 1777 ${prjroot}/rootfs/tmp
mkdir ${prjroot}/rootfs/usr/bin ${prjroot}/rootfs/usr/lib ${prjroot}/rootfs/usr/sbin
mkdir ${prjroot}/rootfs/var/lib ${prjroot}/rootfs/var/lock ${prjroot}/rootfs/var/log ${PRJROOT}/rootfs/var/run ${ Prjroot}/rootfs/var/tmp ${prjroot}/rootfs/boot
chmod 1777 ${prjroot}/rootfs/var/tmp
#修改搜索路径:
Export Path=${prefix}/sbin:${path}
CD $PRJROOT
#end------------------------------------------------------------------------------------
Second, the GNU Cross-platform development tool chain
Download the various components of the GNU tool chain: FTP://FTP.GNU.ORG/GNU
Prepare Build-tools directory (see script above)
The files in the directory include: binutils-2.10.1.tar.gz gcc-2.95.3.tar.gz glibc-2.2.3.tar.gz glibc-linuxthreads-2.2.3.tar.gz
Create a tool chain Program Overview:
1. kernel header File Settings
2. Binary Tool program settings
3. Boot Compiler settings
4.C link Library Settings
5. Complete Compiler settings
Third, kernel header file settings
Kernel Download: http://www.kernel.org
Download the kernel copy to the ${prjroot}/kernel directory.
$ tar xvzf linux-2.4.18.tar.gz or $ tar xvjf linux-2.4.18.tar.bz2
$ MV Linux linux-2.4.18
$ CD linux-2.4.18
Arm Kernel Patch
($ zcat. /patch-2.4.18-rmk5.gz | PATCH-P1)
$ make Arch=arm Cross_compile=arm-linux-menuconfig
After the kernel is configured, copy the kernel header file to the past.
$ cp-r include/linux/${target_prefix}/include
$ cp-r include/asm-arm/${target_prefix}/include/asm
$ cp-r include/asm-generic/${target_prefix}/include
Note: This example uses the arm target board, and if the PPC or i386 target board is used, the asm-arm must be replaced with ASM-PPC or asm-i386.
Four, the setting of Binutils
$ CD ${prjroot}/build-tools
$ tar xvzf binutils-2.10.1.tar.gz
Produce a binutils-2.10.1 directory
$ CD Build-binutils
$ .. /binutils-2.10.1/configure--target= $TARGET--prefix=${prefix}
$ make
$ make Install
Check to see if the installation results are correct:
$ ls ${prefix}/bin
Five, boot compiler settings
$ CD ${prjroot}/build-tools
$ tar xvzf gcc-2.95.3.tar.gz
Generate gcc-2.95.3 Directory
$ CD BUILD-BOOT-GCC
$ .. /gcc-2.95.3/configure--target= $TARGET--prefix=${prefix}--without-headers--with-newlib--enable-languages=c
$ make ALL-GCC
$ make INSTALL-GCC
Check the contents of ${prefix}/bin to see if the installation was successful and the file name of the compiler installed was ARM-LINUX-GCC.
Note: Native gcc3.2 and above cannot generate the bootstrap compiler, the solution is seen later.
Six, the link library's settings
$ CD ${prjroot}/build-tools
$ tar xvzf glibc-2.2.3.tar.gz
$ tar xvzf glibc-linuxthreads-2.2.3.tar.gz--directory=glibc-2.2.3
$ CD BUILD-GLIBC
$ CC=ARM-LINUX-GCC. /glibc-2.2.3/configure--host= $TARGET--prefix= "/usr"--enable-add-ons--with-headers=${target_prefix}/include
$ make
$ make Cross-compiling=yes Install_root=${target_prefix} prefix= "" Install
Make error, install generated two error, the solution is seen after.
$ CD ${target_prefix}/lib
#备份libc. So file
$ CP./libc.so./libc.so.orig
Modify the libc.so file to remove the absolute path inside, such as:/lib/libc.so.6--> libc.so.6
Seven, the full compiler setting
$ cd ${PRJROOT}/BUILD-TOOLS/BUILD-GCC
$ ... /gcc-2.95.3/configure--target= $TARGET--prefix=${prefix}--enable-languages=c,c++
$ make all
$ make install
Eight, the completion of the tool chain settings
$ CD ${prefix}/${target}/bin
$ file as ar gcc ld nm ranlib Strip
$ arm-linux-gcc-print-search-dirs
The information displayed:
Install:/home/tim/control-project/daq-module/tools/lib/gcc-lib/arm-linux/2.95.3/
Programs:/home/tim/control-project/daq-module/tools/lib/gcc-lib/arm-linux/2.95.3/:/home/tim/control-project/ daq-module/tools/lib/gcc-lib/arm-linux/:/usr/lib/gcc/arm-linux/2.95.3/:/usr/lib/gcc/arm-linux/:/home/tim/ control-project/daq-module/tools/arm-linux/bin/arm-linux/2.95.3/:/home/tim/control-project/daq-module/tools/ arm-linux/bin/
Libraries:/home/tim/control-project/daq-module/tools/lib/gcc-lib/arm-linux/2.95.3/:/usr/lib/gcc/arm-linux/ 2.95.3/:/home/tim/control-project/daq-module/tools/arm-linux/lib/arm-linux/2.95.3/:/home/tim/control-project/ daq-module/tools/arm-linux/lib/
The first entry in the programs line is ${prefix}/lib/gcc-lib/arm-linux/2.95.3, which contains the link libraries and utilities for GCC. Move binaries to this directory, the cross compiler uses them, Instead of using native tools.
$ mv as ar gcc ld nm ranlib strip ${prefix}/lib/gcc-lib/arm-linux/2.95.3
$ for file in as AR gcc/ld nm RANLIB Strip
> Do
> Ln-s ${prefix}/lib/gcc-lib/arm-linux/2.95.3/$file.
> Done
The problems I've encountered
Q:GLIBC compilation errors are as follows:
Error: ' Bus_isa ' undeclared
A: Refer to Http://www.ussg.iu.edu/hypermail/linux/kernel/0311.0/0529.html
The core of kernel-2.4.23 is replaced by Ctl_bus_isa Bus_isa
$ CP ${prjroot}/build-tools/glibc-2.2.3/sysdeps/unix/sysv/linux/arm/ioperm.c ${PRJROOT}/BUILD-TOOLS/GLIBC-2.2.3/ Sysdeps/unix/sysv/linux/arm/ioperm.c.orig
Modify the file under glibc source code SYSDEPS/UNIX/SYSV/LINUX/ARM/IOPERM.C
Replace Bus_isa with Ctl_bus_isa
Q:GLIBC compilation errors are as follows:
Make-c Manual Subdir_install
MAKE[2]: Entering directory '/home/tim/control-project/daq-module/build-tools/glibc-2.2.3/manual '
Language=c lc_all=c Makeinfo Libc.texinfo
./stdio.texi:3269:first argument to cross-reference May is empty.
./stdio.texi:3270:first argument to cross-reference May is empty.
Makeinfo:removing output file '/home/tim/control-project/daq-module/build-tools/glibc-2.2.3/manual/libc.info ' due to errors; Use--force to preserve.
MAKE[2]: * * * [Libc.info] Error 2
MAKE[2]: Leaving directory '/home/tim/control-project/daq-module/build-tools/glibc-2.2.3/manual '
MAKE[1]: * * * [Manual/subdir_install] Error 2
MAKE[1]: Leaving directory '/home/tim/control-project/daq-module/build-tools/glibc-2.2.3 '
Make: * * * [install] Error 2
A: Reference HTTP://WWW.CTAG.CN/BLOG/?Q=NODE/22
Make a backup before modifying the Stdio.texi file
$ CD ${prjroot}/build-tools/glibc-2.2.3/manual
$ CP Stdio.texi Stdio.texi.orig
Seems like I found the bug ...
In libc ' s stdio.texi lines 2491 and 2492 the combination @ref {, are not allowed, I changed this to a valid-a-argument. . Seems like GCC has now started compiling, which probably means that libc is sucessful the:-) *crossing
Sure ..... But as I stated, this isn't a "fix", it's a "hack" to make it work. I ' TS in the documentation, and I-there is a very small chance anybody'll look at that.
Untar the Glibc-packet, patch it and Re-tar before doing a "make".
Diff-ur glibc-2.1.3 glibc-2.1.3.new/
Diff-ur glibc-2.1.3/manual/stdio.texi Glibc-2.1.3.new/manual/stdio.texi
---glibc-2.1.3/manual/stdio.texi Wed Feb 08:02:56
+++ Glibc-2.1.3.new/manual/stdio.texi Sun Oct 6 14:46:3 9 2002
@@ -2487,8 +2487,10 @@ -2487,8 If You are are trying to read input this doesn ' t match a single, fixed
pattern, Be better out using a tool such as Flex to generate a
lexical scanner, or Bison to generate a parser, rather than G
-@code {scanf}. For more information about these tools, check @ref {,,,
-flex.info, flex:the lexical Scanner generator}, and @ref {,,,
+ @code {scanf}. For more information about these tools, @ref {Low-level
+i/o,,,
+flex.info, flex:the lexical Scanner generator }, and @ref {low-level I/O,
+,
Bison.info, the Bison Reference Manual}.
Q: Compilation cannot be made and cannot generate ARM-LINUX-GCC.
A: Use GCC versions of 3.2 and above
$ CD ${prjroot}/build-tools
$ tar xvzf glibc-2.2.3.tar.gz
$ tar xvzf glibc-linuxthreads-2.2.3.tar.gz--directory=glibc-2.2.3
$ mkdir Build-glibc-headers
$ CD Build-glibc-headers
$ .. /glibc-2.2.3/configure--host= $TARGET--prefix= "/usr"--enable-add-ons--with-headers=${target_prefix}/include
$ make Cross-compiling=yes Install_root=${target_prefix} prefix= "" Install-headers
To produce a fake Stubs.h file:
$ mkdir-p ${target_prefix}/include/gnu
$ Touch ${target_prefix}/include/gnu/stubs.h
Next, set up the bootstrap gcc compiler:
$ CD ${prjroot}/build-tools
$ tar xvzf gcc-2.95.3.tar.gz
Generate gcc-2.95.3 Directory
$ CD BUILD-BOOT-GCC
$ .. /gcc-2.95.3/configure--target= $TARGET--prefix=${prefix}--disable-shared--with-headers=${target_prefix}/include --with-newlib--enable-languages=c
$ make ALL-GCC
$ make INSTALL-GCC
Q: Prompt for missing features.h file.
A: Copy a past:
$ CP ${prjroot}/build-tools/glibc-2.2.3/include/features.h ${target_prefix}/include
Q: Cross-Compile program error
/lib/libc.so.6:in function ' pthread_attr_init@ @GLIBC_2.1 ':
/lib/libc.so.6 (. text+0xda5f0): Multiple definition of ' pthread_attr_init@ @GLIBC_2.1 '
/home/tim/control-project/daq-module/tools/arm-linux/lib/libpthread.so (. text+0xac): defined here
/lib/libc.so.6:in function ' pthread_cond_broadcast@ @GLIBC_2.3.2 ':
......
/home/tim/control-project/daq-module/tools/lib/gcc-lib/arm-linux/2.95.3/ld:cannot FIND/LIB/LIBC_NONSHARED.A
......
A: Forgot to modify the libc.so file:( How to modify? Boss, look above, right, say, every time recompile glibc and install, all want to modify this file.
Sometimes you need to modify the specs file:
$ cd $PREFIX/lib/gcc-lib/arm-linux/2.95.3
$ emacs Specs
The/lib/ld-linux.so.2 of the 20 line
Modify to {target_prefix}/lib/ld-linux.so.2 (combined system, change environment variable to real path)