在Ubuntu 14.04上构建Android内核模块时出错

时间:2015-07-02 22:13:39

标签: android makefile linux-kernel kernel-module

我正在尝试构建一个hello world内核模块并将其加载到我的google nexus 5.我已经成功构建了整个android内核,以此来检查以确保我的内核文件是有序的。这是我从git中检出的内核版本:

git clone https://android.googlesource.com/kernel/msm -b android-msm-hammerhead-3.4-lollipop-release

这是我的模块,hello-1.c:

#include <linux/module.h>   /* Needed by all modules */
#include <linux/kernel.h>   /* Needed for KERN_INFO */
#include <linux/init.h>     /* Needed for the macros */

static int hello3_data __initdata = 3;

static int __init hello_3_init(void)
{
    printk(KERN_INFO "Hello, world %d\n", hello3_data);
    return 0;
}

static void __exit hello_3_exit(void)
{
    printk(KERN_INFO "Goodbye, world 3\n");
}

module_init(hello_3_init);
module_exit(hello_3_exit);

我使用以下Makefile创建此模块:

obj-m := hello-1.o

KDIR = ~/kernel2/
COMPDIR = ~/linaro3/bin/arm-eabi-

all:
    $(MAKE) ARCH=arm CROSS_COMPILE=$(COMPDIR) -C $(KDIR) M=$(shell pwd)     modules
clean:
    $(MAKE) -C $(KDIR) M=$(shell pwd) clean

这是我的Makefile的输出:

make ARCH=arm CROSS_COMPILE=~/linaro3/bin/arm-eabi- -C ~/kernel2/ M=/home/isaac/modules modules
make[1]: Entering directory `/home/isaac/kernel2'
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "__aeabi_unwind_cpp_pr1" [/home/isaac/modules/hello-1.ko] undefined!
WARNING: "printk" [/home/isaac/modules/hello-1.ko] undefined!
  CC      /home/isaac/modules/hello-1.mod.o
/home/isaac/modules/hello-1.mod.c:8:1: error: variable '__this_module' has initializer but incomplete type
/home/isaac/modules/hello-1.mod.c:9:2: error: unknown field 'name' specified in initializer
/home/isaac/modules/hello-1.mod.c:9:2: warning: excess elements in struct initializer [enabled by default]
error, forbidden warning: hello-1.mod.c:9
make[2]: *** [/home/isaac/modules/hello-1.mod.o] Error 1
make[1]: *** [modules] Error 2
make[1]: Leaving directory `/home/isaac/kernel2'
make: *** [all] Error 2

但是,我实际上在我的内核根文件夹中运行了make menuconfig,并启用了可加载模块支持,强制模块加载,已检查模块卸载和强制模块卸载。这适用于其他stackoverflow线程上的人,但对我不起作用。如果作为评论发布,我可以回答有关细节的进一步问题。谢谢!

0 个答案:

没有答案