[英]Build a Linux Kernel Module from a source tree
I'm trying to cross compile a Linux Kernel module (a driver) for linux-sunxi (Cubieboard 2, A20, Arm Cortex A8). 我正在尝试交叉编译linux-sunxi(Cubieboard 2,A20,Arm Cortex A8)的Linux内核模块(驱动程序)。 What I've done:
我所做的:
Read the article about how to build a kernel for A20: http://linux-sunxi.org/Linux_Kernel#Compilation . 阅读有关如何为A20构建内核的文章: http : //linux-sunxi.org/Linux_Kernel#Compilation 。 I've done it and the kernel has been built successfully.
我已经完成了,内核已经成功构建。
Tried to build my simple (just "Hello, World!") module using the following Makefile: 尝试使用以下Makefile构建我的简单(只是“ Hello,World!”)模块:
ifeq ($(KERNELRELEASE),) KERNELDIR = /home/nikita/linux-sunxi/output/lib/modules/3.4.61/build PWD =$(shell pwd) modules: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules clean: rm -rf *.o *.ko .tmp_versions *.mod.c modules.order Module.symvers else obj-m :=my_mod.o endif
I successfully used such a Makefile to build the kernel for the host (KERNELDIR=/lib/modules/$(CURRENT)/build). 我成功地使用了这样一个Makefile为主机构建内核(KERNELDIR = / lib / modules / $(CURRENT)/ build)。 But this is my first time I'm doing a cross-compilation using a kernel source tree for Linux headers.
但这是我第一次使用针对Linux标头的内核源代码树进行交叉编译。 And I have the following error:
而且我有以下错误:
CC [M] /home/nikita/Kernel_Study/linaro_first_module/my_mod.o
In file included from /home/nikita/linux-sunxi/arch/x86/include/asm/bitops.h:16:0,
from include/linux/bitops.h:22,
from include/linux/kernel.h:19,
from include/linux/cache.h:4,
from include/linux/time.h:7,
from include/linux/stat.h:60,
from include/linux/module.h:10,
from /home/nikita/Kernel_Study/linaro_first_module/my_mod.c:2:
/home/nikita/linux-sunxi/arch/x86/include/asm/arch_hweight.h: In function ‘__arch_hweight64’:
/home/nikita/linux-sunxi/arch/x86/include/asm/arch_hweight.h:53:42: error: expected ‘:’ or ‘)’ before ‘POPCNT64’
asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
^
/home/nikita/linux-sunxi/arch/x86/include/asm/alternative.h:93:18: note: in definition of macro ‘ALTERNATIVE’
"663:\n\t" newinstr "\n664:\n" /* replacement */ \
^
In file included from include/linux/cache.h:5:0,
from include/linux/time.h:7,
from include/linux/stat.h:60,
from include/linux/module.h:10,
from /home/nikita/Kernel_Study/linaro_first_module/my_mod.c:2:
/home/nikita/linux-sunxi/arch/x86/include/asm/processor.h: At top level:
/home/nikita/linux-sunxi/arch/x86/include/asm/cache.h:7:25: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
#define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
And a lot of other errors from the Linux source code... 还有Linux源代码中的许多其他错误...
I'm a new in Linux Kernel and device drivers, that's why I feel, I've missed something. 我是Linux内核和设备驱动程序的新手,这就是为什么我觉得我错过了一些东西。 In summary, what I did:
总之,我做了什么:
Cloned the source code repo. 克隆了源代码仓库。
Installed necessary packages. 已安装必要的软件包。
Configured the kmake: 配置了kmake:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun7i_defconfig
Built the tree: 建树:
make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage modules
Created the tree: 创建树:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install
Tried to make the module using the Makefile above. 尝试使用上面的Makefile制作模块。
Also, I know that it's not necessary to build a whole kernel tree to make a module. 另外,我知道没有必要构建整个内核树来创建模块。 It's just enough to have completed Linux headers.
仅需完成Linux标头即可。 Am I right?
我对吗?
And why make goes to /arch/x86/ ? 以及为什么make转到/ arch / x86 / ? I'm building this one for ARM...
我正在为ARM构建这个...
What have I missed? 我错过了什么?
It must be specified a compiler and an architecture I'm building the module for. 必须指定要为其构建模块的编译器和体系结构。 Just launch make with the following args:
只需使用以下参数启动make:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.