Loading kernel module in Android kernel

安稳与你 提交于 2019-12-03 05:55:28

Kernel modules (KO's) are much easier to work with than a static kernel - as long as the kernel has enabled them. The easiest way to tell is do an "adb shell lsmod". Second is to see if the kernel .config has enabled CONFIG_MODULES=y and CONFIG_MODULE_UNLOAD=y. Lots of info on the web about linux KO development.

Hummm, you're close but it looks like the makefile is screwy. First try to build the hello KO on your host for unit test, then build on your target. Here's a sample makefile I use on an OMAP36xx running gingerbread:

# Makefile for trivial android kernel module

obj-m += mod_hello.o

CROSS_COMPILE=/opt/distros/ARM/bin/arm-none-linux-gnueabi-
TARG_KDIR ?= /opt/android/dal/nook_kernel

HOST_KDIR=/lib/modules/$(shell uname -r)/build

# target creates:
#  .<obj>.o: CC command line for the .o, including dependencies
#  .<obj>.mod.o.cmd: CC command line for the mod.o, including dependencies
#  .<obj>.ko.cmd: LD command line which links the .o and .mod.o to create the .ko
target:
    @echo "Make module for target arm"
    make -C $(TARG_KDIR) M=$(PWD) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules

host:
    @echo "Make module for host"
    make -C $(HOST_KDIR) M=$(PWD) modules

clean:
    @echo "cleaning target"
    make -C $(TARG_KDIR) M=$(PWD) clean
    @echo "cleaning host"
    make -C $(HOST_KDIR) M=$(PWD) clean
user340

First check in the .config if the module support is enabled. (CONFIG_MODULES=y and CONFIG_MODULE_UNLOAD=y) if not enable them using menuconfig.

Then place your module on the root of the kernel source and add this to the main makefile you find at the root

core-y      := usr/ yourModule/

and this to the yourModule folders makefile

obj-m := yourModule.o
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!