自己建个交叉编译器,编译新kernel
今天收拾屋子,发现2440的破板子落了厚厚的一层灰了,拿出来发现还能用,就索性重新玩了一下,不知道是用的编译器太老还是怎么的,编译不过去了
- [root@T-bagwell linux-2.6]# arm-linux-gcc -v
- Reading specs from /usr/local/arm/3.3.2/lib/gcc-lib/arm-linux/3.3.2/specs
- Configured with: ../gcc-3.3.2/configure --target=arm-linux --with-cpu=strongarm1100 --prefix=/usr/local/arm/3.3.2 i686-pc-linux-gnu --with-headers=/work/kernel.h3900/include --enable-threads=pthreads --enable-shared --enable-static --enable-languages=c,c++
- Thread model: posix
- gcc version 3.3.2
复制代码代码是git从kernel上clone下来的,结果编译的过程中出现了一些小问题,然后索性自己想了一下,重新弄一下编译器吧,就从ftp.gnu.org上down了个最新的release的版本
然后编译gcc,用新的gcc编译linuxkernel,生成zImage,然后扔在板子上跑了一下,发现能跑,发一下心得
首先做一下binutils
- [root@T-bagwell binutils-2.21]# ./configure --build=i686-pc-linux-gnu --target=arm-linux --prefix=/usr/local/arm/gcc-4.6.0/ --disable-nls --enable-shared --disable-multilib
- [root@T-bagwell binutils-2.21]# make configure-host
- [root@T-bagwell binutils-2.21]# make
- [root@T-bagwell binutils-2.21]# make install
- [root@T-bagwell binutils-2.21]# cp -vp include/libiberty.h /usr/local/arm/gcc-4.6.0/include
复制代码然后安装mpc,mpfr,gmp,要不会报错
- configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
- Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
- their locations. Source code for these libraries can be found at
- their respective hosting sites as well as at
- ftp://gcc.gnu.org/pub/gcc/infrastructure/. See also
- http://gcc.gnu.org/install/prerequisites.html for additional info. If
- you obtained GMP, MPFR and/or MPC from a vendor distribution package,
- make sure that you have installed both the libraries and the header
- files. They may be located in separate packages.
复制代码下载并安装gmp.mpfr,mpc就可以了
- [root@T-bagwell mnt]# wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
- [root@T-bagwell mnt]# wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
- [root@T-bagwell mnt]# wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
- [root@T-bagwell mnt]# tar zxvf mpc-0.8.1.tar.gz
- [root@T-bagwell mnt]# tar jxvf gmp-4.3.2.tar.bz2
- [root@T-bagwell mnt]# tar jxvf mpfr-2.4.2.tar.bz2
复制代码然后接着开始编译
- [root@T-bagwell mnt]# cd gmp-4.3.2
- [root@T-bagwell gmp-4.3.2]# ./configure --prefix=/usr/local/ --enable-shared
- [root@T-bagwell gmp-4.3.2]# make;make install
- [root@T-bagwell gmp-4.3.2]# cd ..;cd mpfr-2.4.2
- [root@T-bagwell mpfr-2.4.2]# ./configure --prefix=/usr/local/ --enable-shared --with-gmp=/usr/local/lib
- [root@T-bagwell mpfr-2.4.2]# make;make install
- [root@T-bagwell mpfr-2.4.2]# cd ..;cd mpc-0.8.1
- [root@T-bagwell mpc-0.8.1]# ./configure --prefix=/usr/local --with-gmp=/usr/local/lib --with-mpfr=/usr/local/lib
- [root@T-bagwell mpc-0.8.1]# make;make install
- [root@T-bagwell mpc-0.8.1]# cd ..
复制代码然后编译gcc
- [root@T-bagwell gcc-build]# AR=ar LDFLAGS="-Wl,-rpath,/usr/local/lib" ../gcc-4.6.0/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-linux --prefix=/usr/local/arm/gcc-4.6.0 --disable-shared --enable-static --enable-languages=c --without-headers --disable-threads --disable-multilib --disable-nls --disable-decimal-float --disable-libgomp --disable-libmudflap --disable-libssp --without-headers --with-newlib
- [root@T-bagwell gcc-build]# make all-gcc all-target-libgcc
- [root@T-bagwell gcc-build]# make install-gcc install-target-libgcc
复制代码这样,交叉编译器就做好了,看一下
- [root@T-bagwell gcc-build]# arm-linux-gcc -v
- Using built-in specs.
- COLLECT_GCC=arm-linux-gcc
- COLLECT_LTO_WRAPPER=/usr/local/arm/gcc-4.6.0/libexec/gcc/arm-linux/4.6.0/lto-wrapper
- Target: arm-linux
- Configured with: ../gcc-4.6.0/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-linux --prefix=/usr/local/arm/gcc-4.6.0 --disable-shared --enable-static --enable-languages=c --without-headers --disable-threads --disable-multilib --disable-nls --disable-decimal-float --disable-libgomp --disable-libmudflap --disable-libssp --without-headers --with-newlib
- Thread model: single
- gcc version 4.6.0 (GCC)
- [root@T-bagwell gcc-build]# ls /usr/local/arm/gcc-4.6.0/bin/
- addr2line arm-linux-c++filt arm-linux-gcov arm-linux-objcopy arm-linux-strings event_rpcgen.py objcopy phar phpize strip
- ar arm-linux-cpp arm-linux-gprof arm-linux-objdump arm-linux-strip gprof objdump phar.phar ranlib
- arm-linux-addr2line arm-linux-elfedit arm-linux-ld arm-linux-ranlib as ld pear php readelf
- arm-linux-ar arm-linux-gcc arm-linux-ld.bfd arm-linux-readelf c++filt ld.bfd peardev php-cgi size
- arm-linux-as arm-linux-gcc-4.6.0 arm-linux-nm arm-linux-size elfedit nm pecl php-config strings
- [root@T-bagwell gcc-build]#
复制代码可以交叉编译一下linuxkernel试试
- [root@T-bagwell gcc-build]# cd /media/mnt/linux-2.6/
- [root@T-bagwell linux-2.6]# git branch
- LiuQi
- master
- * s3c2440
- [root@T-bagwell linux-2.6]#
- [root@T-bagwell linux-2.6]# cp arch/arm/configs/mini2440_defconfig /media/mnt/linux-2.6/KERNEL_OBJ/.config
- [root@T-bagwell linux-2.6]# make ARCH=arm CROSS_COMPILE=arm-linux- O=/media/mnt/linux-2.6/KERNEL_OBJ zImage
复制代码编译完成以后,可以看一下编译出来以后的文件
- [root@T-bagwell linux-2.6]# file KERNEL_OBJ/arch/arm/boot/compressed/vmlinux
- KERNEL_OBJ/arch/arm/boot/compressed/vmlinux: ELF 32-bit LSB executable, ARM, version 1, statically linked, not stripped
- [root@T-bagwell linux-2.6]#
复制代码搞定
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论