简体   繁体   中英

Error when compiling Linux kernel 3.2 for ARM

I am following this tutorial to compile Linux kernel 3.2 for ARM and emulate with QEMU:

https://balau82.wordpress.com/2012/03/31/compile-linux-kernel-3-2-for-arm-and-emulate-with-qemu/

I am following the below steps:

  1. wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.tar.bz2
  2. tar xjf linux-3.2.tar.bz2
  3. export ARCH=arm
  4. export CROSS_COMPILE=arm-linux-gnueabi-
  5. cd linux-3.2
  6. make vexpress_defconfig
  7. make all
  8. cd ..
  9. arm-linux-gnueabi-gcc -static init.c -o init
  10. echo init|cpio -o --format=newc > initramfs
  11. qemu-system-arm -M vexpress-a9 -kernel linux-3.2/arch/arm/boot/zImage -initrd initramfs -serial stdio -append "console=tty1"

My problem is when I try step 7 (make all), this problem happens:

include/linux/compiler-gcc.h:94:30: fatal error: linux/compiler-gcc5.h: No such file or directory
compilation terminated.
/home/ramy/QEMU_Learn/kernel/linux-3.2/./Kbuild:35: recipe for target 'kernel/bounds.s' failed
make[1]: *** [kernel/bounds.s] Error 1
Makefile:985: recipe for target 'prepare0' failed

I am working Ubuntu operating system, and I am using Linaro tool chain to compile the kernel.

I have also checked the PATH variable and here is the result:

$ printenv | grep PATH

XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ramy/gcc-arm-none-eabi-5_3-2016q1/bin
MANDATORY_PATH=/usr/share/gconf/ubuntu.mandatory.path

Your kernel version (3.2.0) is too old and not compatible with used gcc (gcc-5). You may use gcc-4 to compile kernel, or use newer kernel version.

Your kernel has special include in linux/compiler-gcc.h header http://lxr.free-electrons.com/source/include/linux/compiler-gcc.h?v=3.2#L91

 91 #define __gcc_header(x) #x
 92 #define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
 93 #define gcc_header(x) _gcc_header(x)
 94 #include gcc_header(__GNUC__)

It will include different files for different gcc versions ( GNUC is major version of gcc). It supports gcc-3 and gcc-4, but not gcc-5:

http://lxr.free-electrons.com/source/include/linux/?v=3.2

C file  compiler-gcc.h  3705 bytes
C file  compiler-gcc3.h 631 bytes
C file  compiler-gcc4.h 2073 bytes
C file  compiler-intel.h    746 bytes
C file  compiler.h  8628 bytes

You may try to rewrite compiler-gcc4.h to compiler-gcc5.h , but you should understand how to do this. You may not just copy gcc4 to gcc5, there will incorrect macro.

The compiler-gcc5.h was added only to linux kernel version 3.18: http://lxr.free-electrons.com/source/include/linux/compiler-gcc5.h?v=3.18 (not in 3.17 http://lxr.free-electrons.com/source/include/linux/compiler-gcc5.h?v=3.17 )

Older linaro compiler (before gcc-5) is https://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/

And according to JJ Hakala comment, there is the compiler-gcc5 header in last version of 3.2.* kernel, the 3.2.81: https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.81.tar.gz - just change wget command and tar xjf to this version and retry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM