我正在尝试为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环境中的某些内容)。
答案 0 :(得分:0)
使用crosstool-NG构建一个新的工具链,但是将其配置为OABI而不是EABI。
请参阅Configuring crosstool-NG。
所有debian版本(适用于ARM)直到并包括Lenny都是OABI。
参考:https://wiki.embeddedarm.com/wiki/EABI_vs_OABI
即使你的工具链前缀是arm-none-eabi-
,它生成的二进制文件看起来像OABI
我有OABI二进制文件产生相同的readelf
输出,以及EABI二进制文件具有相同的readelf
输出(" UNIX - System V")到你想要的。
这个question描述了一个类似但相反的情况,即他的工具链正在生成EABI二进制文件,但他需要OABI。
显然,您的工具链是为了生成OABI而构建的,但使用了误导性的前缀
您需要使用crosstool-NG构建新的工具链,但需要为EABI而不是OABI配置它。
较新版本的crosstool-NG实际上通过强制选择EABI来使OABI配置变得困难,除非启用Use obsolete features
。
ADDENDUM
你说"但是为
OABI配置它而不是EABI。",但是如何?
使用crosstool-NG v1.18安装,我可以指定&建立
* Linux内核版本2.6.31.14,
* gcc版本4.3.2,
* binutils版本 2.18a 2.19.1a,
* glibc 2.8版。
为了取消选择 Target options
---> Use EABI
(取消选择意味着使用OABI),
我首先要选择Paths and misc options
---> Use obsolete features
。
在此版本的crosstool-NG中,会自动选择Use EABI
。
Use EABI
菜单项的说明包含:
Set up the toolchain so that it generates EABI-compliant binaries.
If you say 'n' here, then the toolchain will generate OABI binaries.
OABI has long been deprecated, and is now considered legacy.
由于在此版本的crosstool-NG中不推荐使用OABI,因此配置符号 ARCH_ARM_EABI_FORCE 处于活动状态,除非指定 Use obsolete features
。
答案 1 :(得分:0)
我在这里提取一些最终评论:
正如@sawdust建议的那样,我在以下CT-NG环境中使用EABI:
crosstool-NG version: 1.9.0
gcc 4.3.2
binutils 2.19.1
libc 2.8
gmp 4.3.2
mpfr 2.4.2
为了让GCC编译器能够编译,我不得不做几个黑客攻击!
即:
res_hconf.c
删除targets/src/glibc-2.8/nscd
(一次,在提取来源后)res_hconf
nscd/Makefile
stubs-32.h
中stubs-.h
创建~/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi//sys-root/usr/include/gnu
的软链接(构建开始后)。
我只需要下载正确的Linux内核并安装它。缺少的命令是:
make ARCH=arm kirkwood_defconfig
此后我只需使用make ARCH=arm menuconfig
来自定义内容。
gcc -v说:
Using built-in specs.
Target: arm-unknown-linux-gnueabi
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-unknown-linux-gnueabi --prefix=~/x-tools/arm-unknown-linux-gnueabi --with-sysroot=~/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi//sys-root --enable-languages=c,c++ --disable-multilib --with-arch=armv5te --with-tune=arm926ej-s --with-float=soft --disable-shared --with-pkgversion=crosstool-NG-1.9.0 --disable-sjlj-exceptions --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --with-gmp=~/ct-ng-build/targets/arm-unknown-linux-gnueabi/build/static --with-mpfr=~/ct-ng-build/targets/arm-unknown-linux-gnueabi/build/static --enable-threads=posix --enable-target-optspace --with-local-prefix=~/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi//sys-root --disable-nls --enable-symvers=gnu --enable-c99 --enable-long-long
Thread model: posix
gcc version 4.3.2 (crosstool-NG-1.9.0)
最后,为了生成SYSV模块,我不得不破解内核arch/arm/Makefile
以从EABI部分删除-mabi=aapcs-linux
设置。
现在错误是:
"modprobe: can't load module ntfs (kernel/fs/ntfs/ntfs.ko): unknown symbol in module, or unknown parameter
这是另一个问题:D
我仍然无法构建一个正常工作的内核模块(可能因为的黑客攻击!)但也可能是因为我没有兼容的内核 .config
对于NAS。
最后的改变是:
通过跟踪dmsg消息选择了更改。
现在可以加载生成的已编译内核模块(如果它们与已编译的内核兼容)。
(注意警告:当我从网络连接中锁定时,我开始添加iptables
模块时遇到了一些麻烦!小心!幸运的是,模块在重新启动时不会重新加载。) 强>