Adding custom kernel modules to the build process

2,448 views
Skip to first unread message

StefanS

unread,
Mar 5, 2012, 6:06:24 AM3/5/12
to andro...@googlegroups.com
Dear group,

because some devices may need kernel modules which will never make it into the mainline kernel (or shouldn't be there anyway), I have developed a simple solution to add custom (extra) kernel modules.

After much trial and error, here is what I have come up with:
1) attached is a patch for kernel/Android.mk
2) you need to create a directory containing
2a) your kernel module source files
2b) a kernel Makefile containing a list of all source files with .c replaced by .o, for example if your module has source1.c and source2.c, write:
----- Makefile -----
obj-m += source1.o source2.o
----- Makefile -----
2c) an Android.mk containing
----- Android.mk ------
LOCAL_PATH := $(my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := my-custom-kernel-module-name
EXTRA_KERNEL_MODULE_PATH_$(LOCAL_MODULE) := $(LOCAL_PATH)
----- Android.mk ------
(replace my-custom-kernel-module-name with a sensible name for your module, without whitespaces).
3) add you kernel module (the name you gave if in step 2c) to AndroidBoard.mk (before the line with "include $(...)"):
----- AndroidBoard.mk ------
[...]
TARGET_EXTRA_KERNEL_MODULES := module1 module2 module3
[...]

As an example, see my github, where I have added three custom kernel modules: https://github.com/seidler2547/android-x86-ibm-thinkpad-x41t/

Since I'm kind of rubbish with make, feel free to suggest improvements. The current solution has these advantages:
 - simple integration
 - modules are built in parallel (with -jX), BUT installed sequentially, since each modules_install rewrites the modules.dep, and it's not a good idea to do this in parallel

It is not integrated well with the Android build system, but neither is the kernel build itself, and for good reasons. So I think this an acceptable solution.

Stefan
kmod.patch

rvdb

unread,
Mar 5, 2012, 6:20:04 AM3/5/12
to Android-x86
Stefan,

> because some devices may need kernel modules which will never make it into
> the mainline kernel (or shouldn't be there anyway)
I know, I can think of one :-)

You probably already would have guessed, that I am going to use this.
Thanks for adding this functionality.

Greetings Rene

Corvus

unread,
Mar 6, 2012, 2:49:21 AM3/6/12
to Android-x86
Thanks Stefan this will help us...

Corvus

StefanS

unread,
Mar 6, 2012, 3:19:44 AM3/6/12
to andro...@googlegroups.com
On Mon, Mar 5, 2012 at 12:20, rvdb <rene.van....@gmail.com> wrote:
> Stefan,
>
>> because some devices may need kernel modules which will never make it into
>> the mainline kernel (or shouldn't be there anyway)
> I know, I can think of one :-)
>
> You probably already would have guessed, that I am going to use this.
I thought so :)

> Thanks for adding this functionality.

Let me know if it works for you, then we can maybe commit this to the repo.

Stefan

Meerio

unread,
Mar 6, 2012, 4:15:21 AM3/6/12
to Android-x86
ok, i'm a complete noob, but this means that I can install nvidia
drivers (and broadcom sta) using this process?because nvidia gpus are
not supported yet by android x86..
>  kmod.patch
> 1KVisualizzaScarica

StefanS

unread,
Mar 6, 2012, 4:30:20 AM3/6/12
to andro...@googlegroups.com
On Tue, Mar 6, 2012 at 10:15, Meerio <them...@gmail.com> wrote:
> ok, i'm a complete noob, but this means that I can install nvidia
> drivers (and broadcom sta) using this process?because nvidia gpus are
> not supported yet by android x86..
GPUs are only partially handled by the kernel, for use in Android you
need the MESA drivers as well, which are a lot more complex.
Broadcom wifi drivers are also already included afaik, so no benefit
there in my opinion.

Stefan

> --
> You received this message because you are subscribed to the Google Groups "Android-x86" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-x86...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-x86?hl=en.
>

Meerio

unread,
Mar 6, 2012, 5:13:15 AM3/6/12
to Android-x86
broadcom included drivers don't work.. i modprobe the wl driver,but
when i switch back to the de It conflicts with video rom..(this
computer sucks)
by the way thanks for the explanation!:)

On 6 Mar, 10:30, StefanS <andr...@stefanseidel.info> wrote:

rvdb

unread,
Mar 7, 2012, 5:03:46 AM3/7/12
to Android-x86
Stefan,

So far so good.
First I converted 4 simple modules to use the new setup, no problems.
Then I even converted crystalhd.ko
(driver for Broadcom HD device, it is in kernel staging, but much to
old)
This is a bit more complex (about 7 c sources, one module)
The normal makefile in this directory is also working !
So for me its perfect.

Now all the wetab changes, can be in a device tree, no need for
patching
anything in the android-x86 tree.
I am happy :-)

Greetings Rene
N.B. back to accelerated video playback, using gpu video_overlay.

On Mar 6, 9:19 am, StefanS <andr...@stefanseidel.info> wrote:

Chih-Wei Huang

unread,
Mar 9, 2012, 11:25:13 AM3/9/12
to andro...@googlegroups.com
Personally I think it's not a good idea to
build an out-of-tree kernel module.
Anyway, the patch seems to be harmless
and useful to someone. So let's do it.

2012/3/5 StefanS <and...@stefanseidel.info>:

--
Chih-Wei
Android-x86 project
http://www.android-x86.org

Rishi Ranjan

unread,
Nov 25, 2014, 5:43:53 PM11/25/14
to andro...@googlegroups.com
I tried adding virtualbox guest additions as per the instruction. I see that obj/vboxguest.kmodule/ is created but my module does not get added to ls system/lib/modules/3.10.58-android-x86+/extra/. 


I am looking at build/core/tasks/kernel.mk to see why it was not created. 

Can someone help me to figure out what I am doing wrong?



On Tuesday, July 31, 2012 2:36:16 PM UTC-7, malc0mn wrote:
I would like to add to this for anybody who's not that familiar with compiling on linux themselves and who would like to make use of this handy feature:

1. You should add the kernel module folder to /device/<brand>/<product>/<folder here> of the source tree. Let's take an example from android-x86.org, if you would be compiling for the eeepc product:

$ make iso_img TARGET_PRODUCT=eeepc

the files should then go in:

 /device/asus/eeepc/<your module dir> 

The AndroidBoard.mk file that needs adjusting is in there as well.

2. Don't blindly check the kernel module folder's contents for files ending in *.c and add them to the Makefile as *.o. Better is to check the original Makefile to find out which objects it generates (i.e. the original obj-m variable) since some of the *.c files are merely includes for the module.

I found it a bit ambiguous / confusing in the original post ;-)


Cheers,

mlc.

Rishi Ranjan

unread,
Nov 25, 2014, 7:08:36 PM11/25/14
to andro...@googlegroups.com
Please ignore my last comment. There was a issue with my Include path. I am recompiling it. 

Rishi Ranjan

unread,
Nov 25, 2014, 11:20:50 PM11/25/14
to andro...@googlegroups.com
The thing that worked for me was to leave the Makefile in Kbuild format. So instead of "obj-m += source1.o source2.o", I added my .o files in format "obj-y += source1.o source2.o".

Chih-Wei Huang

unread,
Nov 26, 2014, 2:24:27 AM11/26/14
to Android-x86
What benefit can we get by adding the vbox guest additions?
If it's useful, we can integrate it into the codebase.
Thanks!
> --
> 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 http://groups.google.com/group/android-x86.
> For more options, visit https://groups.google.com/d/optout.

Rishi Ranjan

unread,
Nov 26, 2014, 11:52:46 PM11/26/14
to andro...@googlegroups.com
vbox guest additions help in things like creating a shared folder from host PC, using the GPU of host PC by guest etc. 

I am using it to install the system applications on guest so that I can pass parameters between guest and host. 

I think there are following issues with integrating guest additions with androidx86 code base: 

1. Guest additions are tightly coupled with Virtualbox release. So to integrate the additions with code base, there has to be a configuration parameter to specify the virtualbox version and the code has to be pulled in at compile time. 
2. The virtualbox code is distributed under GPL license so not sure if it can be added to androidx86 code base. 

Thanks,
Rishi
Reply all
Reply to author
Forward
0 new messages