Build a kernel driver for use with Android-x86

1,527 views
Skip to first unread message

Rich N

unread,
Jul 29, 2015, 9:29:33 PM7/29/15
to Android-x86
There is a lot of guidance out there for building a Linux driver, but I have a very specific problem. I have a device given to me that is loaded and running a specific version and build of Android-x86 (3.10.58-android-x86+), and I must compile a simple kernel driver that will load and run on the device. Can someone give me some guidance here?

Specifically:

1. Do I need the exact kernel source tree that was used to build the kernel running on the device, or just a generic one of the same version?
2. If I can use a generic kernel source tree of the same kernel version, how do I sync to that version in android-x86?
3. Assuming I have the correct source tree, do I need to do anything especially different from the usual Linux driver build process?

I don't have the original kernel source tree, and I have tried to find a matching kernel tree, but so far, my attempts have all ended with an insmod failure "Exec format error)" which is shown in the system log as "disagrees about version of symbol module_layout"

Can anyone help?

Rich

Povilas Staniulis

unread,
Jul 29, 2015, 9:53:22 PM7/29/15
to andro...@googlegroups.com
On 2015.07.30 04:29, Rich N wrote:
> There is a lot of guidance out there for building a Linux driver, but
> I have a very specific problem. I have a device given to me that is
> loaded and running a specific version and build of Android-x86
> (3.10.58-android-x86+), and I must compile a simple kernel driver that
> will load and run on the device. Can someone give me some guidance here?
>
> Specifically:
>
> 1. Do I need the exact kernel source tree that was used to build the
> kernel running on the device, or just a generic one of the same version?
For stability, it's best to build drivers against the same kernel source
tree.
While drivers built against the same version tree may work, but
stability is not guaranteed.

Your kernel version number matches the 3.10.y kernel:
http://git.android-x86.org/?p=kernel/common.git;a=shortlog;h=refs/heads/android-3.10.y

> 3. Assuming I have the correct source tree, do I need to do anything
> especially different from the usual Linux driver build process?
For in-tree drivers, just enable the driver you need in the config file
as a module (assuming that driver doesn't depend on a kernel feature
which cannot be built as a module - in that case, you'll have to rebuild
the kernel).
For out-of-tree drivers, you may have to change some settings in
Makefile to point to your kernel source.

Rich N

unread,
Jul 29, 2015, 10:14:24 PM7/29/15
to andro...@googlegroups.com
Thanks for the information - that is very helpful. If I want to sync to the android-3.10.y tag, how do I do that? Is that a branch-wide tag (so I could just change the default revision in the .repo/manifest.xml file) or is it a git tag in the kernel subproject - for which I would go into the kernel directory and use git checkout... ?





--
You received this message because you are subscribed to a topic in the Google Groups "Android-x86" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-x86/U8Rp156R2ak/unsubscribe.
To unsubscribe from this group and all its topics, 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.

Povilas Staniulis

unread,
Jul 29, 2015, 10:31:44 PM7/29/15
to andro...@googlegroups.com
On 2015.07.30 05:14, Rich N wrote:
Thanks for the information - that is very helpful. If I want to sync to the android-3.10.y tag, how do I do that? Is that a branch-wide tag (so I could just change the default revision in the .repo/manifest.xml file) or is it a git tag in the kernel subproject - for which I would go into the kernel directory and use git checkout... ?

It's a branch of the kernel repo.

Rich N

unread,
Jul 29, 2015, 10:40:05 PM7/29/15
to andro...@googlegroups.com
Ah thanks - actually, I see that the current latest android-x86 (lollipop branch) tag has the 3.10.y kernel, so I guess I can use that sync point.

Since my module is outside the kernel tree, my own Makefile points to the kernel project directory. However, there is no Module.symvers, so I figured I must build the kernel. So I did "make" in the kernel directory, but that ended in an error:

drivers/gpu/drm/i915/intel_ddi.c: 1538:18: error: 'struct intel_connector' has no member named 'hotplug_switch'

I have made no modifications to the source tree - did I forget a config step or something to be able to build the kernel?

R


--
You received this message because you are subscribed to a topic in the Google Groups "Android-x86" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-x86/U8Rp156R2ak/unsubscribe.

Rich N

unread,
Jul 29, 2015, 10:56:37 PM7/29/15
to andro...@googlegroups.com
I think I found the answer - the kernel config was somehow not using the default one. I went to the top of the android source tree and started 
"make kernel TARGET_PRODUCT=generic_x86"


Hopefully that will build the kernel and give me what I need - either way I will report back so this post will have a complete solution (or report the next problem).
R

Rich N

unread,
Jul 29, 2015, 11:07:21 PM7/29/15
to andro...@googlegroups.com
Well that was disappointing. The "make kernel" completed without error, but still there is no Module.symvers - at least not found by my driver build. Trying to insmod my module still gives the same load error. Perhaps I am missing something key in my Makefile - anyone have any ideas?

Makefile:
=========

obj-m := mymodule.o

KDIR := /home/rich/android-x86/kernel

PWD   := $(shell pwd)

MODS = kmod

.PHONY: default

default: $(MODS)

kmod:
        $(MAKE) -C $(KDIR) M=$(PWD) modules

=================

Povilas Staniulis

unread,
Jul 30, 2015, 3:47:41 PM7/30/15
to Android-x86, rich....@gmail.com
Kernel binaries stored in out/target/product/x86/obj/kernel
Module.symvers should be there.

Rich N

unread,
Jul 30, 2015, 6:20:57 PM7/30/15
to Android-x86, rich....@gmail.com
OK, so just to make sure I didn't foul any configs up by accident, I started over. Here is what I did:

1. I followed the steps on http://www.android-x86.org/getsourcecode to set up my build machine and do a repo init for the lollipop-x86 branch.
    $repo init -u http://git.android-x86.org/manifest -b lollipop-x86
  $repo sync

2. I followed the steps on http://www.android-x86.org/documents/customizekernel to build the generic kernel and modules:
    $ make kernel TARGET_PRODUCT=generic_x86
3. After thge build (which didn't seem to do anything) I looked in  out/target/product/generic_x86 for output, but all that is there are two files, "clean_steps.mk" and "previous_build_config.mk" and nothing else.

Did I miss a step? Do I need to build the ISO before I can build the kernel by itself?

Rich

Rich N

unread,
Jul 30, 2015, 6:53:12 PM7/30/15
to Android-x86, Rich N
Just in case I can't build the kernel without building the ISO, I went ahead and tried the default build:
   $ make iso_img TARGET_PRODUCT=android_x86

​But that​ failed with this:

...
Header: out/target/product/generic_x86/obj/include/libsonivox/jet.h
host C: acp <= build/tools/acp/acp.c
Import includes file: out/host/linux-x86/obj32/STATIC_LIBRARIES/libhost_intermediates/import_includes
host C: libhost_32 <= build/libs/host/CopyFile.c
build/libs/host/CopyFile.c: In function 'isSameFile':
build/libs/host/CopyFile.c:87:43: warning: unused parameter 'pSrcStat' [-Wunused-parameter]
 static bool isSameFile(const struct stat* pSrcStat, const struct stat* pDstStat)
                                           ^
build/libs/host/CopyFile.c:87:72: warning: unused parameter 'pDstStat' [-Wunused-parameter]
 static bool isSameFile(const struct stat* pSrcStat, const struct stat* pDstStat)
                                                                        ^
build/libs/host/CopyFile.c: In function 'printNotNewerMsg':
build/libs/host/CopyFile.c:105:42: warning: unused parameter 'src' [-Wunused-parameter]
 static void printNotNewerMsg(const char* src, const char* dst, unsigned int options)
                                          ^
build/libs/host/CopyFile.c: In function 'copyFileRecursive':
build/libs/host/CopyFile.c:530:69: warning: unused parameter 'isCmdLine' [-Wunused-parameter]
 static int copyFileRecursive(const char* src, const char* dst, bool isCmdLine, unsigned int options)
                                                                     ^
host StaticLib: libhost_32 (out/host/linux-x86/obj32/STATIC_LIBRARIES/libhost_intermediates/libhost.a)
Export includes file: build/tools/acp/Android.mk -- out/host/linux-x86/obj32/EXECUTABLES/acp_intermediates/export_includes
host Executable: acp (out/host/linux-x86/obj32/EXECUTABLES/acp_intermediates/acp)
Install: out/host/linux-x86/bin/acp
target Prebuilt:  (out/target/product/generic_x86/system/bin/monkey)
target Prebuilt:  (out/target/product/generic_x86/system/usr/share/bmd/RFFspeed_501.bmd)
target Prebuilt:  (out/target/product/generic_x86/system/usr/share/bmd/RFFstd_501.bmd)
target Prebuilt:  (out/target/product/generic_x86/system/bin/bmgr)
target Prebuilt:  (out/target/product/generic_x86/system/bin/ime)
target Prebuilt:  (out/target/product/generic_x86/system/bin/input)
target Prebuilt:  (out/target/product/generic_x86/system/bin/pm)
target Prebuilt:  (out/target/product/generic_x86/system/bin/svc)
/bin/bash: prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.8/bin/x86_64-linux-android-gcc: No such file or directory
make: *** [out/target/product/generic_x86/obj/lib/crtbegin_so.o] Error 127


What's going on? I haven't done anything custom at all - does the lollipop-x86 branch head of line not build? Did I do something wrong?

Rich

Chih-Wei Huang

unread,
Jul 30, 2015, 9:46:49 PM7/30/15
to Android-x86, Rich N
Are you sure you use the correct command
pasted the real log you got?

2015-07-31 6:52 GMT+08:00 Rich N <rich....@gmail.com>:
> Just in case I can't build the kernel without building the ISO, I went ahead
> and tried the default build:
> $ make iso_img TARGET_PRODUCT=android_x86

The command looks correct. (suggest add -jX)

Though I suggest to use the lunch method.
The target path is not correct.
Should be out/target/product/x86/.....

Note the only valid targets of lollipop-x86
is android_x86 and android_x86_64,
not generic_x86.

Rich N

unread,
Jul 30, 2015, 10:51:10 PM7/30/15
to Chih-Wei Huang, Android-x86
Hm, seems like maybe we should mention on the custimizekernel web page, that target "generic_x86" is no good for lollipop-x8. What branch(es) *is* it good for?

Anyway, taking what Chih-Wei said, I started over from a fresh repo. I still don't know if I need to build the ISO before I can just build the kernel, so I tried to just build the (lollipop-x86) kernel:

   $ make kernel TARGET_PRODUCT=android_x86

That ended badly too:

including ./vendor/intel/houdini/Android.mk ...
patching file Makefile
Hunk #1 succeeded at 126 with fuzz 2.
patching file src/wl/sys/wl_linux.c
Hunk #1 succeeded at 215 (offset -20 lines).
patching file src/wl/sys/wl_linux.c
Hunk #1 FAILED at 910.
Hunk #2 FAILED at 3235.
Hunk #3 succeeded at 3295 with fuzz 2 (offset -113 lines).
Hunk #4 FAILED at 3463.
3 out of 4 hunks FAILED -- saving rejects to file src/wl/sys/wl_linux.c.rej
make: *** [kernel/drivers/net/wireless/wl/Makefile] Error 1
make: *** Deleting file `kernel/drivers/net/wireless/wl/Makefile'


So I just tried to build the ISO (in parallel as suggested):

    $ make -j2 iso_img TARGET_PRODUCT=android_x86

​But one again, no joy:

host C++: libaapt_32 <= frameworks/base/tools/aapt/AaptAssets.cpp
patching file Makefile
Hunk #1 succeeded at 126 with fuzz 2.
patching file src/wl/sys/wl_linux.c
Hunk #1 succeeded at 215 (offset -20 lines).
patching file src/wl/sys/wl_linux.c
Hunk #1 FAILED at 910.
Hunk #2 FAILED at 3235.
Hunk #3 succeeded at 3295 with fuzz 2 (offset -113 lines).
Hunk #4 FAILED at 3463.
3 out of 4 hunks FAILED -- saving rejects to file src/wl/sys/wl_linux.c.rej
make: *** [kernel/drivers/net/wireless/wl/Makefile] Error 1
make: *** Deleting file `kernel/drivers/net/wireless/wl/Makefile'
make: *** Waiting for unfinished jobs....
frameworks/base/tools/aapt/AaptAssets.cpp:1244:1: warning: unused parameter 'bundle' [-Wunused-parameter]
 AaptAssets::slurpResourceZip(Bundle* bundle, const char* filename)

 ^

Unless there is still something I am doing wrong, I have to assume something wrong with lollipop-x86, so I am going to try again with kitkat-x86 branch.

Rich​

Rich N

unread,
Jul 30, 2015, 11:54:09 PM7/30/15
to Chih-Wei Huang, Android-x86
I decided to try one more time, to just build the lollipop-x86 ISO from a clean repo, using only the steps mentioned on the web page and in Chih-Wei's earlier comment on this thread:

$ . build/envsetup.sh
$ lunch android_x86-eng
$ m -j2 iso_img

And this time the build is progressing in what looks like a normal fashion. It will be a while before I know whether it will succeed, but one thing is for certain - with the lollipop-x86 branch, using lunch seems to be the (only?) way to configure the build (might be a bug in the lollipop-x86 branch config files?)

THAT is good lesson learned here - more later...

Rich

Rich N

unread,
Jul 31, 2015, 6:14:55 AM7/31/15
to Chih-Wei Huang, Android-x86
Well, it did build for a while, but ended with the same result as before:

patching file src/wl/sys/wl_linux.c
Hunk #1 succeeded at 215 (offset -20 lines).
patching file src/wl/sys/wl_linux.c
Hunk #1 FAILED at 910.
Hunk #2 FAILED at 3235.
Hunk #3 succeeded at 3295 with fuzz 2 (offset -113 lines).
Hunk #4 FAILED at 3463.
3 out of 4 hunks FAILED -- saving rejects to file src/wl/sys/wl_linux.c.rej
make: *** [kernel/drivers/net/wireless/wl/Makefile] Error 1
make: *** Deleting file `kernel/drivers/net/wireless/wl/Makefile'
make: *** Waiting for unfinished jobs....
rm out/target/product/x86/gen/STATIC_LIBRARIES/libmesa_dri_common_intermediates/xmlpool/de.po out/target/product/x86/gen/STATIC_LIBRARIES/libmesa_dri_common_intermediates/xmlpool/nl.po out/target/product/x86/gen/STATIC_LIBRARIES/libmesa_dri_common_intermediates/xmlpool/fr.po out/target/product/x86/gen/STATIC_LIBRARIES/libmesa_dri_common_intermediates/xmlpool/es.po out/target/product/x86/gen/STATIC_LIBRARIES/libmesa_dri_common_intermediates/xmlpool/sv.po
make: Leaving directory `/home/rich/android-x86-lollipop'

#### make failed to build some targets (45:05 (mm:ss)) ####


If no one has any other suggestions, I"ll start all over and try with the kitkat-x86  branch.

Rich N

unread,
Jul 31, 2015, 3:50:17 PM7/31/15
to Chih-Wei Huang, Android-x86
OK,
With the latest in the kitkat branch, everything built exactly as advertised. Unfortunately, the current kernel claims to be 4.0.8 (really?) when I do a make kernelversion in the kernel project directory. Since I need 3.10.y, what options do I have? lollipop branch appears to be broken due to a bad patch file (see above). Is there a prior kitkat tag I can use that has the 3.10.y kernel?
R

Povilas Staniulis

unread,
Jul 31, 2015, 4:14:06 PM7/31/15
to Android-x86, cwh...@android-x86.org, rich....@gmail.com
To replace the kernel (the easy way), you can do this:

mv kernel kernel.old (or: rm -r kernel)
git clone http://git.android-x86.org/kernel/common.git -b android-3.10.y kernel

Also, have you considered upgrading the kernel on your Android x86 device to version 4.0.8 instead ?
It's not that hard as it seems.

Mauro Rossi

unread,
Jul 31, 2015, 4:22:33 PM7/31/15
to Android-x86, cwh...@android-x86.org, rich....@gmail.com
It's just a workaround, but if you don't explicitly need wl (broadcom hybrid) wireless driver, 
you could avoid the wl_linux.c building error by creating a new kernel config file in kernel/arch/x86/config having 


# CONFIG_WL is not set

instead of

CONFIG_WL=m

then you build with following command

make -j4 iso_img  TARGET_PRODUCT=android_x86 TARGET_KERNEL_CONFIG=[new_defconfig_file_name]

Rich N

unread,
Jul 31, 2015, 4:32:31 PM7/31/15
to Mauro Rossi, Android-x86, Chih-Wei Huang
That would be a good idea - except that even with the CONFIG_WL not set, the kernel build still tries to apply the patches in linux-recent.patch found in kernel.drivers/net/wireless/wl. This patch file will not apply, which causes the kernel build error. I am going to either try to fix the patch file, or do as Povilas suggested, and pull in the 3.10.y kernel into the (working build) of kitkat.

Not sure which way is better/easier...

R

Rich N

unread,
Aug 1, 2015, 9:55:18 AM8/1/15
to Mauro Rossi, Android-x86, Chih-Wei Huang
To round out this topic - I finally got my driver to load on my 3.10.y kernel device. I want to summarize the main issues and resolution here:

1. The 3.10.y kernel tree in the current lollipop head of line (same as at http://git.android-x86.org/kernel/common.git -b android-3.10.y) is broken - the linux-recent.patch file does not seem to be intended for the contained version of wl_linux.c. I worked around this by examining the original, patched and rejected changes and manually applying the patches as best as I could, then created a new patch file and used that in the build process. Since the original patch wasn't really matched with the current source file, I had to guess - so I am not including the updated patch here, because it's probably wrong. I suspect there is a fixed/better 3.10 kernel tree that could be applied here, but my hack allows the kernel to build, which is all I needed.

2. Once I had the Module.symvers, my driver built and loaded without issue as one would expect. It does raise the question, why don't we provide a package or something with the android-x86 kernel includes and symvers like regular linux distros do? I can understand that maybe nobody has the time, or maybe not too many people are building externally built, loadable kernel modules, but it would have been a nice time savings. Maybe just include a default Module.symvers in git?

3. I had a lot of trouble trying to figure out how to sync to the correct Android and/or kernel version. Kudos and many thanks to those that chimed in here and tried to help, especially Povilas, whose info actually got me to the finish line. Isn't there some central place or technique where one can get a list of android-x86 tags or something?

SO a few issues, that in hindsight seem simple, but stumbling in the dark as I did - pretty frustrating. If someone can suggest anything I can do to make it easier for the next guy (other than simply posting this topic) let me know - I'd be glad to help android-x86.

thanks,
Rich
Reply all
Reply to author
Forward
0 new messages