Loading kernel module in Android kernel

前端 未结 2 1052
慢半拍i
慢半拍i 2021-02-08 00:51

I am listing my problem here.

I have a Google Nexus one a.k.a. \"passion\" phone with me. Fastboot and adb tools are installed in the phone. And the boot loader is unl

相关标签:
2条回答
  • 2021-02-08 01:16

    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
    
    0 讨论(0)
  • 2021-02-08 01:23

    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
    
    0 讨论(0)
提交回复
热议问题