How to create driver

860 views
Skip to first unread message

blues

unread,
Nov 7, 2008, 6:46:45 PM11/7/08
to android-platform
I need to create a driver. Like those /dev/smd0 and /dev/smd27.
My driver will be very similar to those smd drivers, it will just talk
to different smd channel.

My question is: do I have to rebuild the whole source tree, and flash
the image to the device? Or can I just make a driver binary module,
and adb push to the phone, and install it (like insmod driver.o)?

Please understand I am a newbie to linux...

Gergely Kis

unread,
Nov 10, 2008, 3:25:45 AM11/10/08
to android-...@googlegroups.com
Hi,

Android has 2 parts: kernel and userland.

In order to include a new kernel driver, you will have to rebuild it,
because the Android kernel has been configured without module support.
Also, you won't find any "insmod" command on an Android image I think.
So in any case you will at least have to create a kernel with module
support enabled.

Also, you will probably need to recompile the userland (system.img and
data.img), because you will need to include the components, which will
bridge your device file to Java using some protocol.

Best Regards,
Gergely

Jay Freeman (saurik)

unread,
Nov 10, 2008, 4:18:46 AM11/10/08
to android-...@googlegroups.com
Android is configured with kernel modules, and even comes with insmod. I use
this to load ext2.ko on the G1 in order to add Debian to it as a more viable
userland: http://www.saurik.com/id/10. -J

--------------------------------------------------
From: "Gergely Kis" <gerge...@gmail.com>
Sent: Monday, November 10, 2008 12:25 AM
To: <android-...@googlegroups.com>
Subject: Re: How to create driver

blues

unread,
Nov 10, 2008, 2:34:55 PM11/10/08
to android-platform
Thanks.
I saw insmod on the phone. Great...
I guess I don't need to build any image. From java, I can just access
my driver as a char device.


On Nov 10, 1:18 am, "Jay Freeman \(saurik\)" <sau...@saurik.com>
wrote:
> Android is configured with kernel modules, and even comes with insmod. I use
> this to load ext2.ko on the G1 in order to add Debian to it as a more viable
> userland:http://www.saurik.com/id/10. -J
>
> --------------------------------------------------
> From: "Gergely Kis" <gergely....@gmail.com>
> Sent: Monday, November 10, 2008 12:25 AM
> To: <android-...@googlegroups.com>
> Subject: Re: How to create driver
>
> ...
>
>
>
> > Android has 2 parts: kernel and userland.
>
> > In order to include a new kernel driver, you will have to rebuild it,
> > because the Android kernel has been configured without module support.
> > Also, you won't find any "insmod" command on an Android image I think.
> > So in any case you will at least have to create a kernel with module
> > support enabled.
>
> > Also, you will probably need to recompile the userland (system.img and
> > data.img), because you will need to include the components, which will
> > bridge your device file to Java using some protocol.
>
> > Best Regards,
> > Gergely- Hide quoted text -
>
> - Show quoted text -

blues

unread,
Nov 10, 2008, 6:58:55 PM11/10/08
to android-platform
I have a more detailed question here: How to build the driver module
with the tool chain from android source tree.

I have use git downloaded the whole source tree. Now how can I just
compile one .c file file into a driver module file? So I can push to
phone and use insmod to link into the kernel. I hope I don't have to
build the whole image.

More specifically, I hope I can get a command line like this:

/somePath/gcc -someCommands -c myDriver.c

Thanks,Blues

On Nov 10, 1:18 am, "Jay Freeman \(saurik\)" <sau...@saurik.com>
wrote:
> Android is configured with kernel modules, and even comes with insmod. I use
> this to load ext2.ko on the G1 in order to add Debian to it as a more viable
> userland:http://www.saurik.com/id/10. -J
>
> --------------------------------------------------
> From: "Gergely Kis" <gergely....@gmail.com>
> Sent: Monday, November 10, 2008 12:25 AM
> To: <android-...@googlegroups.com>
> Subject: Re: How to create driver
>
> ...
>
>
>
> > Android has 2 parts: kernel and userland.
>
> > In order to include a new kernel driver, you will have to rebuild it,
> > because the Android kernel has been configured without module support.
> > Also, you won't find any "insmod" command on an Android image I think.
> > So in any case you will at least have to create a kernel with module
> > support enabled.
>
> > Also, you will probably need to recompile the userland (system.img and
> > data.img), because you will need to include the components, which will
> > bridge your device file to Java using some protocol.
>
> > Best Regards,

Jay Freeman (saurik)

unread,
Nov 10, 2008, 7:02:03 PM11/10/08
to android-...@googlegroups.com
You mean build your own driver? I am sorry, I don't know how to build your
own driver. I knew for an older version of the Linux kernel, but have since
forgotten and they changed it anyway. Normally you are supposed to use
Kbuild, but setting up the kernel build tree has a number of steps. When I
get more requests for a guide on that I might write one. -J

--------------------------------------------------
From: "blues" <blues_...@yahoo.com>
Sent: Monday, November 10, 2008 3:58 PM
To: "android-platform" <android-...@googlegroups.com>

Jay Freeman (saurik)

unread,
Nov 10, 2008, 7:03:49 PM11/10/08
to android-...@googlegroups.com
Wow. Ok, I'm unsubscribing myself from this mailing list. Not having
[android-platform] in front of the messages is apparently too much for me to
handle. I'm sorry, I suck. -J

--------------------------------------------------
From: "Jay Freeman (saurik)" <sau...@saurik.com>
Sent: Monday, November 10, 2008 4:02 PM

fred

unread,
Nov 11, 2008, 8:15:52 AM11/11/08
to android-platform
Hi,

on my emulator (version 1.0r1), Loadable kernel modules are not
enabled by default. It seems to be different on the phone. To check
this out, you can try to run lsmod, and see if it prints an error
message.

In any case, if you just want to built one driver, you could do the
following :

get the kernel source from here : http://code.google.com/p/android/downloads/list
.

Then set up a cross-compiler toolchain (tutorial here
http://www.upche.org/doku.php?id=wiki:android2).

Then using a kernel module makefile (I'll copy paste one below), it's
just a matter of login in the toolchain and typing make).

I've successfully built several modules for Android this way (before
the whole tree got opensourced), albeit only for the emulator ...

Fred.

Makefile :

obj-m := android_driver.o

KDIR := /tmp/kernel_src_dir
PWD := $(shell pwd)

default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
Reply all
Reply to author
Forward
0 new messages