简体   繁体   English

从源代码树构建Linux内核模块

[英]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: 我所做的:

  1. 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. 我已经完成了,内核已经成功构建。

  2. 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: 总之,我做了什么:

  1. Cloned the source code repo. 克隆了源代码仓库。

  2. Installed necessary packages. 已安装必要的软件包。

  3. Configured the kmake: 配置了kmake:

     make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun7i_defconfig 
  4. Built the tree: 建树:

     make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage modules 
  5. Created the tree: 创建树:

     make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install 
  6. 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.

相关问题 针对内核源代码树构建Linux内核模块? - Building Linux Kernel Module against kernel source tree? 如何在没有内核源代码树的情况下构建外部内核模块 - how to Build external kernel module without kernel source tree 如何将参数从makefile传递到Linux内核模块源代码 - How to pass parameters from makefile to Linux kernel module source code 如何保持 Linux 内核模块构建的 asm 输出 - How to keep asm output from Linux kernel module build 超出树内核模块:多个模块,单个Makefile,相同的源文件,不同的构建选项 - Out of tree kernel modules: Multiple module, single Makefile, same source file, different build options 如何在单个 Makefile 中构建具有多个源文件的多个 linux 内核模块? - How to build multiple linux kernel module with multiple source files in a single Makefile? 如何使用预构建的内核输出目录构建Linux内核模块? - How to build a linux kernel module against with a prebuilt kernel output directory? Linux出树模块构建问题 - Linux out of tree module build issue 使用单独的输出目录构建树外 linux 内核模块 - Building an out-of-tree linux kernel module with separate output directory 针对文件系统上的任何内核源代码树编译树外内核模块 - Compiling out-of-tree kernel module against any kernel source tree on the filesystem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM