我正在尝试为linux-sunxi(Cubieboard 2,A20,Arm Cortex A8)交叉编译Linux内核模块(驱动程序) . 我做了什么:
-
阅读有关如何为A20构建内核的文章:http://linux-sunxi.org/Linux_Kernel#Compilation . 我已经完成了它并且内核已经成功构建 .
-
尝试使用以下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
我成功地使用了这样的Makefile来为主机构建内核(KERNELDIR = / lib / modules / $(CURRENT)/ build) . 但这是我第一次使用Linux头文件的内核源代码树进行交叉编译 . 我有以下错误:
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)
还有Linux源代码中的很多其他错误......
我是Linux内核和设备驱动程序的新手,这就是为什么我觉得,我错过了什么 . 总之,我做了什么:
-
克隆源代码仓库 .
-
安装了必要的包 .
-
配置了kmake:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun7i_defconfig
- 建树:
make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage modules
- 创建了树:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install
- 尝试使用上面的Makefile制作模块 .
另外,我知道没有必要构建一个完整的内核树来创建一个模块 . 它就足以完成Linux头文件了 . 我对吗?
为什么make转到/ arch / x86 /?我正在为ARM构建这个...
我错过了什么?
1 回答
必须指定一个编译器和我正在构建模块的架构 . 只需使用以下args启动make: