不能建立在Android的软糖的hello world内核模块 [英] Can't build hello world kernel module on Android JellyBean

查看:590
本文介绍了不能建立在Android的软糖的hello world内核模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立在Android软糖一个简单的内核模块。

I'm trying to build a simple kernel module on Android JellyBean.

code:

#include <linux/module.h>  /* Needed by all modules */
#include <linux/kernel.h>  /* Needed for KERN_ALERT */

MODULE_LICENSE("GPL");
MODULE_AUTHOR("test");
MODULE_DESCRIPTION("Android ko test");

int init_module(void)
{
   printk(KERN_ALERT, "Hello world\n");

   // A non 0 return means init_module failed; module can't be loaded.
   return 0;
}

void cleanup_module(void)
{
  printk(KERN_ALERT "Goodbye world 1.\n");
}

生成文件:

obj-m +=hello.o

KERNELDIR ?= ~/android/kernel
PWD := $(shell pwd)
CROSS_COMPILE=~/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-
ARCH=arm

default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules

clean:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) clean

输出:

make -C ~/android/kernel M=/home/test/testmod ARCH=arm CROSS_COMPILE=~/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- modules
make[1]: Entering directory `/home/test/android/kernel'

  ERROR: Kernel configuration is invalid.
         include/generated/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && make prepare' on kernel src to fix it.


  WARNING: Symbol version dump /home/test/android/kernel/Module.symvers
           is missing; modules will have no dependencies and modversions.

  CC [M]  /home/test/testmod/hello.o
In file included from <command-line>:0:
/home/test/android/kernel/include/linux/kconfig.h:4:32: error: generated/autoconf.h: No such file or directory
In file included from /home/test/android/kernel/arch/arm/include/asm/types.h:4,
                 from include/linux/types.h:4,
                 from include/linux/list.h:4,
                 from include/linux/module.h:9,
                 from /home/test/testmod/hello.c:1:
include/asm-generic/int-ll64.h:11:29: error: asm/bitsperlong.h: No such file or directory
In file included from /home/test/android/kernel/arch/arm/include/asm/posix_types.h:38,
                 from include/linux/posix_types.h:47,
                 from include/linux/types.h:17,
                 from include/linux/list.h:4,
                 from include/linux/module.h:9,
                 from /home/test/testmod/hello.c:1:
include/asm-generic/posix_types.h:70:5: warning: "__BITS_PER_LONG" is not defined
error, forbidden warning: posix_types.h:70
make[2]: *** [/home/test/testmod/hello.o] Error 1
make[1]: *** [_module_/home/test/testmod] Error 2
make[1]: Leaving directory `/home/test/android/kernel'
make: *** [default] Error 2

如果我按照建议的输出,并运行使oldconfig这个&功放;&安培;使prepare'的内核,它让我通过几十个内核配置是/否问题的。在此之后,编译仍然失败上下一个错误,这是一个关于bitsperlong.h

If I follow the suggestion in the output, and run 'make oldconfig && make prepare' on the kernel, it leads me through dozens of kernel config yes / no questions. After that, the compile still fails on the next error, which is about bitsperlong.h.

推荐答案

Android的推出目录下输出二进制文件。因此,例如,人们可以有输出/目标/产品/&lt;目标名称&gt; / OBJ / KERNEL_OBJ / $ ANDROID_PRODUCT_OUT / OBJ / KERNEL_OBJ / 如果 $ ANDROID_PRODUCT_OUT 定义。该目录可能有来自不同厂商的不同的名称,但简单地认为是一个包含目录的vmlinux

Android puts output binaries under out directory. So for example one can have out/target/product/<target name>/obj/KERNEL_OBJ/ or $ANDROID_PRODUCT_OUT/obj/KERNEL_OBJ/ if $ANDROID_PRODUCT_OUT is defined. This directory may have a different name from different vendors but simply that's the directory containing vmlinux.

所以,当你下编译Android的回购内核模块,就可以提交命令中包含你的模块目录中。

So when you compile a kernel module under Android repo, you should submit make command like below inside your module's directory.

make -C $ANDROID_PRODUCT_OUT/obj/KERNEL_OBJ/ M=`pwd` ARCH=arm CROSS_COMPILE=arm-eabi- modules

这篇关于不能建立在Android的软糖的hello world内核模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆