[Mini2440] 编译 linux-2.6.32.2 内核

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Mini2440] 编译 linux-2.6.32.2 内核相关的知识,希望对你有一定的参考价值。

一 准备好开发环境

  需要创建一个 Ubuntu 虚拟机,并且安装好 VMwareTools 方便和 Windows 之间传文件。

  创建好一个 mini2440 的工作目录,后续所有 mini2440 相关的文件均存放在此目录下。

[email protected]:~$ mkdir -p workspace/mini2440

 

二 安装交叉编译器

  在 mini2440 工作目录下创建 package 目录,存放软件包。

[email protected]:~$ mkdir workspace/mini2440/package

  拷贝 mini2440光盘\Linux\arm-linux-gcc-4.4.3.tar.gz 到虚拟机 /home/user/workspace/mini2440/package 目录下。

  解压到 /opt 目录下并配置好环境变量.

[email protected]:~$ cd workspace/mini2440/package/
[email protected]:~/workspace/mini2440/package$ sudo tar zxf arm-linux-gcc-4.4.3.tar.gz -C /
[email protected]:~/workspace/mini2440/package$ cd
[email protected]:~$ echo "export PATH=\$PATH:/opt/FriendlyARM/toolschain/4.4.3/bin" >> .bashrc
[email protected]:~$ . .bashrc

  验证交叉编译器是否安装成功。

[email protected]:~$ arm-linux-gcc -v
/opt/FriendlyARM/toolschain/4.4.3/bin/arm-linux-gcc: 15: exec: /opt/FriendlyARM/toolschain/4.4.3/bin/.arm-none-linux-gnueabi-gcc: not found

  没有正确的显示版本号,百度查了一下,原因是虚拟机的 Ubuntu 是 64 位的,而此交叉编译器是 32 位的版本,要想正常使用,需要安装 32 位兼容库。

[email protected]:~$ sudo apt-get install lib32ncurses5
[email protected]:~$ sudo apt-get install lib32z1

  安装好兼容库之后,验证成功。

[email protected]:~$ arm-linux-gcc -v
Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /opt/FriendlyARM/mini2440/build-toolschain/working/src/gcc-4.4.3/configure --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu --target=arm-none-linux-gnueabi --prefix=/opt/FriendlyARM/toolschain/4.4.3 --with-sysroot=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --enable-languages=c,c++ --disable-multilib --with-arch=armv4t --with-cpu=arm920t --with-tune=arm920t --with-float=soft --with-pkgversion=ctng-1.6.1 --disable-sjlj-exceptions --enable-__cxa_atexit --with-gmp=/opt/FriendlyARM/toolschain/4.4.3 --with-mpfr=/opt/FriendlyARM/toolschain/4.4.3 --with-ppl=/opt/FriendlyARM/toolschain/4.4.3 --with-cloog=/opt/FriendlyARM/toolschain/4.4.3 --with-mpc=/opt/FriendlyARM/toolschain/4.4.3 --with-local-prefix=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
Thread model: posix
gcc version 4.4.3 (ctng-1.6.1) 

 

三 配置 linux 内核

  同样将 mini2440光盘\Linux\linux-2.6.32.2-mini2440-20150709.tgz 文件拷贝到虚拟机 /home/user/workspace/mini2440/package 目录下。

  解压开来,可以看到有很多的配置文件,当然还是挑自己板子搭配屏的配置文件。

[email protected]:~/workspace/mini2440/package$ tar zxf linux-2.6.32.2-mini2440-20150709.tgz -C ../
[email protected]:~/workspace/mini2440/package$ cd ../linux-2.6.32.2/
[email protected]:~/workspace/mini2440/linux-2.6.32.2$ ls
arch                  config_mini2440_s70d         drivers      net
block                 config_mini2440_t35          firmware     README
build.sh              config_mini2440_td35         fs           REPORTING-BUGS
config_mini2440_a70   config_mini2440_vga1024x768  include      samples
config_mini2440_a70i  config_mini2440_vga640x480   init         scripts
config_mini2440_h43   config_mini2440_vga800x600   ipc          security
config_mini2440_l80   config_mini2440_w35          Kbuild       sound
config_mini2440_n35   config_mini2440_x35          kernel       tools
config_mini2440_n43   COPYING                      lib          usr
config_mini2440_p35   CREDITS                      MAINTAINERS  virt
config_mini2440_p43   crypto                       Makefile
config_mini2440_s70   Documentation                mm

  开始配置,拷贝配置文件,执行 make menuconfig 生成对应 C 语言配置宏文件和 Makefile 编译宏控文件。

[email protected]:~/workspace/mini2440/linux-2.6.32.2$ make distclean
[email protected]:~/workspace/mini2440/linux-2.6.32.2$ cp config_mini2440_x35 .config [email protected]:~/workspace/mini2440/linux-2.6.32.2$ make menuconfig HOSTCC scripts/basic/fixdep HOSTCC scripts/basic/docproc HOSTCC scripts/basic/hash HOSTCC scripts/kconfig/conf.o scripts/kconfig/conf.c: In function ‘conf_sym’: scripts/kconfig/conf.c:159:6: warning: variable ‘type’ set but not used [-Wunused-but-set-variable] int type; ^ scripts/kconfig/conf.c: In function ‘conf_choice’: scripts/kconfig/conf.c:231:6: warning: variable ‘type’ set but not used [-Wunused-but-set-variable] int type; ^ scripts/kconfig/conf.c:307:4: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result] fgets(line, 128, stdin); ^ scripts/kconfig/conf.c: In function ‘conf_askvalue’: scripts/kconfig/conf.c:105:3: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result] fgets(line, 128, stdin); ^ HOSTCC scripts/kconfig/kxgettext.o *** Unable to find the ncurses libraries or the *** required header files. *** make menuconfig requires the ncurses libraries. *** *** Install ncurses (ncurses-devel) and try again. *** /home/user/workspace/mini2440/linux-2.6.32.2/scripts/kconfig/Makefile:186: recipe for target scripts/kconfig/dochecklxdialog failed make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1 Makefile:454: recipe for target menuconfig failed make: *** [menuconfig] Error 2
  报错了,百度查了一下,原来是缺少 ncurses 库导致,安装好库之后,成功配置。
[email protected]:~/workspace/mini2440/linux-2.6.32.2$ sudo apt-get install libncurses

  进入图形化配置界面后,直接按 esc 退出即可,配置项已经拷贝到最终的配置文件 .config 文件中了,执行 make menuconfig 的作用,只是去自动生成 Makefile 和 c 语言宏控文件。

 

四 编译内核

  配置 ok 了,要开始编译内核了。

[email protected]:~/workspace/mini2440/linux-2.6.32.2$ make
  CHK     include/linux/version.h
  UPD     include/linux/version.h
  Generating include/asm-arm/mach-types.h
  CHK     include/linux/utsrelease.h
  UPD     include/linux/utsrelease.h
  SYMLINK include/asm -> include/asm-arm
  CC      kernel/bounds.s
/opt/FriendlyARM/toolschain/4.4.3/libexec/gcc/arm-none-linux-gnueabi/4.4.3/cc1: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
/home/user/workspace/mini2440/linux-2.6.32.2/./Kbuild:35: recipe for target kernel/bounds.s failed
make[1]: *** [kernel/bounds.s] Error 1
Makefile:982: recipe for target prepare0 failed
make: *** [prepare0] Error 2

  可是又报错了,提示说是找不到 libstdc++.so.6 这个库。安装一下试试:

[email protected]:~/workspace/mini2440/linux-2.6.32.2$ sudo apt-get install lib32stdc++6

  库安装好了之后,果然可以开始编译了。

[email protected]:~/workspace/mini2440/linux-2.6.32.2$ make
... ... ... ...
  CC      kernel/exit.o
  CC      kernel/itimer.o
  TIMEC   kernel/timeconst.h
Cant use defined(@array) (Maybe you should just omit the defined()?) at kernel/timeconst.pl line 373.
/home/user/workspace/mini2440/linux-2.6.32.2/kernel/Makefile:129: recipe for target kernel/timeconst.h failed
make[1]: *** [kernel/timeconst.h] Error 255
Makefile:878: recipe for target kernel failed
make: *** [kernel] Error 2

  可是又报错了,看提示说 ‘defined(@array)‘语法有问题,kernel/timeconst.pl 文件中 373 行 "if (!defined(@val)) {" 修改为 "if ([email protected]) {" 后编译成功。

diff --git a/kernel/timeconst.pl b/kernel/timeconst.pl
index eb51d76..0461239 100644
--- a/kernel/timeconst.pl
+++ b/kernel/timeconst.pl
@@ -370,7 +370,7 @@ if ($hz eq --can) {
        }
 
        @val = @{$canned_values{$hz}};
-       if (!defined(@val)) {
+       if (!@val) {
                @val = compute_values($hz);
        }
        output($hz, @val);

  编译成功提示如下,同时会在 arch/arm/boot/ 目录下生成 zImage 内核镜像文件。

[email protected]:~/workspace/mini2440/linux-2.6.32.2$ make
  CHK     include/linux/version.h
make[1]: include/asm-arm/mach-types.h is up to date.
  CHK     include/linux/utsrelease.h
  SYMLINK include/asm -> include/asm-arm
  CALL    scripts/checksyscalls.sh
  CHK     include/linux/compile.h
  Kernel: arch/arm/boot/Image is ready
  Kernel: arch/arm/boot/zImage is ready
  Building modules, stage 2.
  MODPOST 16 modules
[email protected]:~/workspace/mini2440/linux-2.6.32.2$ ls -l arch/arm/boot/zImage 
-rwxrwxr-x 1 user user 2330052 11月 25 03:10 arch/arm/boot/zImage

 















以上是关于[Mini2440] 编译 linux-2.6.32.2 内核的主要内容,如果未能解决你的问题,请参考以下文章

mini2440 使用uClibc编译静态程序

mini2440 busybox编译

[Mini2440 - 011] 配置编译 linux-2.6 内核

mini2440 编译工具链(gcc)安装

mini2440 官方linux-2.6内核文件zImage编译

[Mini2440 - 008] 安装 arm-linux-gcc 交叉编译器