How to build a new kernel module?

623 views
Skip to first unread message

soh...@bu.edu

unread,
Apr 1, 2019, 9:50:04 PM4/1/19
to Android-x86
I am trying to build a Kernel module for the LineageOS port of Android-x86 project. Before going in to the kernel module issue, does Android-x86 build the Linux kernel at all? Because, I tried the CustomizeKernel instruction, it does not seem to do much.

I have the following Makefile:
   
   2 KERNEL_DIR=/mnt/harddisk/android-x86/lineageos/out/target/product/android_x86/obj/kernel/
   3 
   4 
   5 obj-m += android_module.o
   6 
   7 PWD := $(shell pwd)
   8 
   9 all:
  10     make ARCH=x86 -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules

The kernel module is extremely simple:

   1 #include<linux/module.h>
   2 #include<linux/kernel.h>
   4 int init_module(void)
   5 {
   6   printk(KERN_INFO "Hello android kernel...\n");
   7     return 0;
   8 }
   9 
  10 void cleanup_module(void)
  11 {
  12     printk(KERN_INFO "Goodbye android kernel...\n");
  13 }

However, I get the following error:

make ARCH=x86 -C /mnt/harddisk/android-x86/lineageos/out/target/product/android_x86/obj/kernel/ SUBDIRS=/mnt/harddisk/android-x86/android_module modules
make[1]: Entering directory '/mnt/harddisk/android-x86/lineageos/out/target/product/android_x86/obj/kernel'
make -C /mnt/harddisk/android-x86/lineageos/kernel O=/mnt/harddisk/android-x86/lineageos/out/target/product/android_x86/obj/kernel/. modules
make -C /mnt/harddisk/android-x86/lineageos/out/target/product/android_x86/obj/kernel KBUILD_SRC=/mnt/harddisk/android-x86/lineageos/kernel \
-f /mnt/harddisk/android-x86/lineageos/kernel/Makefile modules
test -e include/generated/autoconf.h -a -e include/config/auto.conf || ( \
echo >&2; \
echo >&2 "  ERROR: Kernel configuration is invalid."; \
echo >&2 "         include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 "         Run 'make oldconfig && make prepare' on kernel src to fix it."; \
echo >&2 ; \
/bin/false)
mkdir -p /mnt/harddisk/android-x86/android_module/.tmp_versions ; rm -f /mnt/harddisk/android-x86/android_module/.tmp_versions/*
make -f /mnt/harddisk/android-x86/lineageos/kernel/scripts/Makefile.build obj=/mnt/harddisk/android-x86/android_module
make[4]: *** No rule to make target '/mnt/harddisk/android-x86/android_module/android_module.c', needed by '/mnt/harddisk/android-x86/android_module/android_module.o'.  Stop.
/mnt/harddisk/android-x86/lineageos/kernel/Makefile:1607: recipe for target '_module_/mnt/harddisk/android-x86/android_module' failed
make[3]: *** [_module_/mnt/harddisk/android-x86/android_module] Error 2
Makefile:152: recipe for target 'sub-make' failed
make[2]: *** [sub-make] Error 2
Makefile:24: recipe for target '__sub-make' failed
make[1]: *** [__sub-make] Error 2
make[1]: Leaving directory '/mnt/harddisk/android-x86/lineageos/out/target/product/android_x86/obj/kernel'
Makefile:10: recipe for target 'all' failed
make: *** [all] Error 2 

Any idea how to build a kernel module? 

Chih-Wei Huang

unread,
Apr 1, 2019, 10:22:57 PM4/1/19
to Android-x86
Isn't the message clear?
You have to build the kernel (so the kernel config is created)
before build the module.

In fact building an external module in android-x86 is simple.
Just put your module to a subdir in external/kernel-drivers/,
add (just copy) an Android.mk for it.

<soh...@bu.edu> 於 2019年4月2日 週二 上午9:50寫道:
> --
> You received this message because you are subscribed to the Google Groups "Android-x86" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to android-x86...@googlegroups.com.
> To post to this group, send email to andro...@googlegroups.com.
> Visit this group at https://groups.google.com/group/android-x86.
> For more options, visit https://groups.google.com/d/optout.



--
Chih-Wei
Android-x86 project
http://www.android-x86.org
Reply all
Reply to author
Forward
0 new messages