【发布时间】:2017-09-16 21:45:10
【问题描述】:
我正在尝试为我的DNS-320L NAS 构建一个内核模块。
我已经在 Debian lenny chroot 环境中构建了 crosstool-ng,但是在我编译了我的内核模块并尝试安装它之后,我得到:
insmod: error inserting 'kernel/net/ip4/ipip.ko': -1 Invalid module format
当我使用 readelf 检查一个工作内核模块时,我得到:
~/ct-ng-build$ readelf -h ~/ct-ng-build/kernel/orig/ipip.ko
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: ARM
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 6696 (bytes into file)
Flags: 0x5000000, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 51
但我的模块有一些不同之处:
~/ct-ng-build$ readelf -h ~/ct-ng-build/kernel/modules/lib/modules/2.6.31.8/kernel/net/ipv4/ipip.ko
ELF Header:
Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: ARM
ABI Version: 0
Type: REL (Relocatable file)
Machine: ARM
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 6280 (bytes into file)
Flags: 0x600, GNU EABI, software FP, VFP
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 23
Section header string table index: 20
我的cross_compile环境是:
$ echo $CROSS_COMPILE
arm-none-eabi-
make CROSS_COMPILE=${CROSS_COMPILE} INSTALL_PATH=~/ct-ng-build/kernel/install INSTALL_MOD_PATH=~/ct-ng-build/kernel/modules INSTALL_FW_PATH=~/ct-ng-build/kernel/firmware
我的 gcc 编译好了:
$ ${CROSS_COMPILE}gcc -v
Using built-in specs.
Target: arm-none-eabi
Configured with: ~/ct-ng-build/targets/src/gcc-4.3.2/configure --build=x86_64-build_unknown-linux-gnu --host=x86_64-build_unknown-linux-gnu --target=arm-none-eabi --prefix=~/x-tools/arm-none-eabi --with-local-prefix=~/x-tools/arm-none-eabi/arm-none-eabi//sys-root --disable-multilib --disable-libmudflap --with-sysroot=~/x-tools/arm-none-eabi/arm-none-eabi//sys-root --with-newlib --enable-threads=no --disable-shared --with-pkgversion=crosstool-NG-1.9.0 --with-arch=armv5te --with-tune=arm926ej-s --disable-__cxa_atexit --with-gmp=~/ct-ng-build/targets/arm-none-eabi/build/static --with-mpfr=~/ct-ng-build/targets/arm-none-eabi/build/static --enable-target-optspace --disable-nls --enable-symvers=gnu --enable-languages=c,c++
Thread model: single
gcc version 4.3.2 (crosstool-NG-1.9.0)
任何想法如何将 OS/ABI 设置为“UNIX - System V”并将标志设置为“0x5000000,Version5 EABI”而不是“Arm”和“0x600,GNU EABI,软件 FP,VFP”?
还是有其他问题?
谢谢!
--- 编辑 ---- 我专门尝试针对我现有的 NAS 操作系统:
Kernel 2.6.31.8 #1 armv5tel
C library gcc-4.3-mt-1.44.0
# /lib/libc-2.8.so
GNU C Library stable release version 2.8, by Roland McGrath et al.
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.3.2.
到目前为止,我只能使用 crosstool-ng-1.9.0 构建一个 crosstool-ng 环境,但它生成了上面的二进制文件。
我尝试按照 3.17.2 ARM Options 设置 -mabi=apcs-gnu,但 C 库无法编译并出现奇怪的“缺少标头”错误(我可能会再试一次 - 可能与我的 chroot 环境有关)。
【问题讨论】:
-
原始工具链是使用特定版本的 crosstool-NG 构建的,并不意味着您必须这样做。您确实希望匹配目标的 C 库类型(例如 glibc 或 uClibc)和版本号,并使用相同内核版本的内核头文件。工具链组件的版本号可能有一些余地,例如gcc 编译器和 binutils,但 crosstool-NG 应该允许你指定你想要的版本,只要你在那个时间段内不会太旧或太新。
-
我已经尝试编译 crosstool-ng-13.2,但它无法编译 gcc 4.3.2 和 gcc 4.3.3 共享编译器(以及最终编译器)。我将再次尝试编译 19.0。 (之前编译过——至少ct-ng构建过程保留了x-tools目标目录下的日志和配置)。
-
您需要仔细检查您的工具链是否真的适用于 EABI,而不是 OABI。我为内核模块做了类似的
readelf,它产生了与您的“工作内核模块”基本相同的结果。我生成该模块的工具链是用于 EABI。 IOW 我的回答是倒退的,stackoverflow.com/questions/10780648/… 似乎证实了这一点。但是您的工具链前缀arm-none-eabi-与它是 OABI 的想法相矛盾。 -
我已恢复为针对“arm-none-linux-gnu”的 crosstool-NG-1.9.0(根据上面的 eabi 工具链),但它现在无法编译工具链!我在 C 库中收到“内部编译器错误”。我将从新的 tarball 源和新的 1.9.0 arm-none-linux 示例配置中再次尝试。
标签: arm linux-device-driver cross-compiling nas