首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ARM架构下内核模块的交叉编译

ARM架构下内核模块的交叉编译
EN

Stack Overflow用户
提问于 2013-02-11 13:23:05
回答 2查看 11.4K关注 0票数 3

我正在尝试从linux x86机器上为ARM创建一个.ko文件。我尝试了以下Makefile:

代码语言:javascript
复制
1 obj-m +=helloworldtest_module.o 
2 modules_install:
3     make ARCH=$(ARCH) CC=$(CROSS_COMPILER) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
4 clean:
5     make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

..。但我在命令提示符中输入make -f Makefile ARCH=arm CROSS_COMPILER=arm-linux-gnueabi-gcc时出错,如下所示:

代码语言:javascript
复制
make ARCH=arm CC=arm-linux-gnueabi-gcc -C /lib/modules/3.2.0-29-generic/build M=/home/terenesas/sample modules
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-29-generic'
  CC [M]  /home/terenesas/sample/helloworldtest_module.o
In file included from /usr/src/linux-headers-3.2.0-29-generic/arch/arm/include/asm/types.h:4:0,
                 from include/linux/types.h:4,
                 from include/linux/list.h:4,
                 from include/linux/module.h:9,
                 from /home/terenesas/sample/helloworldtest_module.c:2:
include/asm-generic/int-ll64.h:11:29: fatal error: asm/bitsperlong.h: No such file or directory
compilation terminated.
make[2]: *** [/home/terenesas/sample/helloworldtest_module.o] Error 1
make[1]: *** [_module_/home/terenesas/sample] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-29-generic'
make: *** [modules_install] Error 2

我做错什么了?

EN

回答 2

Stack Overflow用户

发布于 2013-02-11 14:28:58

快速修复,更改为:

代码语言:javascript
复制
#include <asm/bitsperlong.h>

至:

代码语言:javascript
复制
#include <asm-generic/bitsperlong.h>
票数 2
EN

Stack Overflow用户

发布于 2013-07-21 03:32:56

shell uname -r意味着这个Makefile将为您的主机(X86)系统而不是ARM构建模块。

您需要指定ARM内核的源目录。你可以使用下面的Makefile来交叉编译你的模块。

Makefile:

代码语言:javascript
复制
CC=$(CROSS_COMPILE)gcc
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
    obj-m := modulename.o 

# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else

    KERNELDIR ?= /path/to/kernel/linux
    PWD  := $(shell pwd)

default:
    ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules

clean:
    ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
endif
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14806353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档