编译内核时,需要在PC机上进行编译才能下载到开发板上去,但两个平台不一样,需要我们自己实现这个功能。
[klaus@localhost linux-3.0.1]$ make
make: /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc:命令未找到
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/lex.zconf.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
scripts/kconfig/conf --silentoldconfig Kconfig
make: /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc:命令未找到
CHK include/linux/version.h
UPD include/linux/version.h
CHK include/generated/utsrelease.h
UPD include/generated/utsrelease.h
Generating include/generated/mach-types.h
CC kernel/bounds.s
/bin/sh: /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc: 没有那个文件或目录
make[1]: *** [kernel/bounds.s] 错误 1
make: *** [prepare0] 错误 2
交叉编译器,一般可以有两种Buildroot和Crosstool-ng,另一篇文章中会涉及Crosstool-ng的制作,buildroot是一个使用uclibc制作的交叉编译器,可以用来编译u-boot、Linux内核,和根文件的制作,比较适合。
下载地址:https://buildroot.org/
切换到选择界面来
[klaus@localhost opt]$ ls
buildroot-2012.08 buildroot-2012.08.tar.bz2 rh
[klaus@localhost opt]$ cd buildroot-2012.08/
[klaus@localhost buildroot-2012.08]$ ls
arm920t board boot CHANGES Config.in configs COPYING dl docs fs linux Makefile output package support target toolchain
[klaus@localhost buildroot-2012.08]$ export TERM=vt100
[klaus@localhost buildroot-2012.08]$ make menuconfig
根据自己的开发板需求,这里用的s3c2440是arm920t类型的版本,更改配置
也可以将Package Selection for the target/Libraries/Compression and decompression下的lzo和zlib选上(性能比较好)。
...
in sectioning `Bugs' differ
/opt/buildroot-2012.08/output/toolchain/gcc-4.5.4/gcc/doc/service.texi:6: warning: node up `Service' in menu `Bugs' and in sectioning `Top' differ
make[2]: *** [doc/gcc.info] 错误 1
make[2]: 离开目录“/opt/buildroot-2012.08/output/toolchain/gcc-4.5.4-initial/gcc”
make[1]: *** [all-gcc] 错误 2
make[1]: 离开目录“/opt/buildroot-2012.08/output/toolchain/gcc-4.5.4-initial”
make: *** [/opt/buildroot-2012.08/output/toolchain/gcc-4.5.4-initial/.compiled] 错误 2
修改版本
[klaus@localhost buildroot-2012.08]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)
Copyright © 2015 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
[klaus@localhost buildroot-2012.08]$ vim .config
...
BR2_GCC_SUPPORTS_FINEGRAINEDMTUNE=y
BR2_GCC_VERSION="4.5.4"
#修改成自己的版本
BR2_EXTRA_GCC_CONFIG_OPTIONS=""
...
可以直接用yum安装。类似可能还会有其他缺少,可直接安装1。
[klaus@localhost buildroot-2012.08]$sudo yum install ncurses-devel
...
验证中 : ncurses-devel-5.9-13.20130511.el7.x86_64 5/8
验证中 : ncurses-5.9-13.20130511.el7.x86_64 6/8
验证中 : ncurses-libs-5.9-13.20130511.el7.x86_64 7/8
验证中 : ncurses-base-5.9-13.20130511.el7.noarch 8/8
更新完毕:
ncurses-devel.x86_64 0:5.9-14.20130511.el7_4
作为依赖被升级:
ncurses.x86_64 0:5.9-14.20130511.el7_4 ncurses-base.noarch 0:5.9-14.20130511.el7_4 ncurses-libs.x86_64 0:5.9-14.20130511.el7_4
完毕!
[klaus@localhost buildroot-2012.08]$
busybox取消不了的原因是某处还占用着它,在System configuration里面,这里不选择初始化busybox即可。
...
shared library, skipping
/opt/buildroot-2012.08/arm920t/usr/bin/arm-unknown-linux-uclibcgnueabi-ldconfig: can't resolve /usr/X11R6/lib in chroot .: No such file or directory
/opt/buildroot-2012.08/arm920t/usr/bin/arm-unknown-linux-uclibcgnueabi-ldconfig: skipping /usr/X11R6/lib: No such file or directory
( \
echo "NAME=Buildroot"; \
echo "VERSION=2012.08"; \
echo "ID=buildroot"; \
echo "VERSION_ID=2012.08"; \
echo "PRETTY_NAME=\"Buildroot 2012.08\"" \
) > /opt/buildroot-2012.08/output/target/etc/os-release
[klaus@localhost buildroot-2012.08]$
[klaus@localhost ~]$ cd /opt/
[klaus@localhost opt]$ ls
buildroot-2012.08 buildroot-2012.08.tar.bz2 rh
[klaus@localhost opt]$ cd buildroot-2012.08/
[klaus@localhost buildroot-2012.08]$ ls
arm920t board boot CHANGES Config.in configs COPYING dl docs fs linux Makefile output package support target toolchain
[klaus@localhost buildroot-2012.08]$ cd arm920t/usr/bin/
[klaus@localhost bin]$ ls
aclocal arm-linux-gcc-4.8.5 arm-linux-objdump arm-unknown-linux-uclibcgnueabi-cpp arm-unknown-linux-uclibcgnueabi-ldconfig autom4te
aclocal-1.11 arm-linux-gcc-ar arm-linux-ranlib arm-unknown-linux-uclibcgnueabi-elfedit arm-unknown-linux-uclibcgnueabi-ldd automake
arm-linux-addr2line arm-linux-gcc-nm arm-linux-readelf arm-unknown-linux-uclibcgnueabi-g++ arm-unknown-linux-uclibcgnueabi-nm automake-1.11
arm-linux-ar arm-linux-gcc-ranlib arm-linux-size arm-unknown-linux-uclibcgnueabi-gcc arm-unknown-linux-uclibcgnueabi-objcopy autoreconf
arm-linux-as arm-linux-gcov arm-linux-strings arm-unknown-linux-uclibcgnueabi-gcc-4.8.5 arm-unknown-linux-uclibcgnueabi-objdump autoscan
arm-linux-c++ arm-linux-gprof arm-linux-strip arm-unknown-linux-uclibcgnueabi-gcc-ar arm-unknown-linux-uclibcgnueabi-ranlib autoupdate
arm-linux-cc arm-linux-ld arm-unknown-linux-uclibcgnueabi-addr2line arm-unknown-linux-uclibcgnueabi-gcc-nm arm-unknown-linux-uclibcgnueabi-readelf ifnames
arm-linux-c++filt arm-linux-ld.bfd arm-unknown-linux-uclibcgnueabi-ar arm-unknown-linux-uclibcgnueabi-gcc-ranlib arm-unknown-linux-uclibcgnueabi-size ldconfig
arm-linux-cpp arm-linux-ldconfig arm-unknown-linux-uclibcgnueabi-as arm-unknown-linux-uclibcgnueabi-gcov arm-unknown-linux-uclibcgnueabi-strings ldd
arm-linux-elfedit arm-linux-ldd arm-unknown-linux-uclibcgnueabi-c++ arm-unknown-linux-uclibcgnueabi-gprof arm-unknown-linux-uclibcgnueabi-strip libtool
arm-linux-g++ arm-linux-nm arm-unknown-linux-uclibcgnueabi-cc arm-unknown-linux-uclibcgnueabi-ld autoconf libtoolize
arm-linux-gcc arm-linux-objcopy arm-unknown-linux-uclibcgnueabi-c++filt arm-unknown-linux-uclibcgnueabi-ld.bfd autoheader m4
以简单的hello.c文件,我们编译查看现象如何
[klaus@localhost 公共]$ ls
hello.c
[klaus@localhost 公共]$ /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-g
arm-linux-g++ arm-linux-gcc-4.8.5 arm-linux-gcc-nm arm-linux-gcov
arm-linux-gcc arm-linux-gcc-ar arm-linux-gcc-ranlib arm-linux-gprof
[klaus@localhost 公共]$ /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc hello.c -o hello
[klaus@localhost 公共]$ file hello
hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
[klaus@localhost 公共]$ du -h hello
8.0K hello
[klaus@localhost 公共]$ /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc hello.c -o hello -static
[klaus@localhost 公共]$ file hello
hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
[klaus@localhost 公共]$ du -h hello
60K hello
[klaus@localhost 公共]$ /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-strip hello
[klaus@localhost 公共]$ file hello
hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped
[klaus@localhost 公共]$ du -h hello
20K hello
[klaus@localhost 公共]$