Creating android kernel module in emulator is really painful. So here I want to show you how to create a loadable module.
Most the configuration is the same with my previous post here:
And if you read this post before you read mine, it will be a really big help.
But if you only follow his paper, you will fail with my environment.
I also created a video here. If you prefer to watch videos, it will be a good choice.
So before we start, there are several things we need to do.
First, go to the goldfish/arch/arm/configs/goldfish_armv7_defconfig file and add these lines at the end.
Also, if you just add these lines and start compile the kernel, you will get a lot of errors. So you will want to delete these configurations. Simply add “#” before the line.
To make it better, add this at the beginning.
# CONFIG_IPV6 is not set
When you finish these things, you are done with the environment. Go to the goldfish/drivers and create a directory. Let’s make it “helloworld”. To make it clear, you can create this directory anywhere you want. But here we make it in the drivers directory.
Under the “helloworld”, you need to create several files.
The first one is hello.c.
The second one is Makefile.
obj-m := hello.o
Then all you need to do is type “make” in the terminal in this directory. And you will get several files here. What you need is the “hello.ko”. Start the emulator now.
emulator -show-kernel -kernel arch/arm/boot/zImage -avd kernelEXP -no-boot-anim -no-skin -no-audio -no-window -qemu -monitor unix:/tmp/qemuSocket,server,nowait -s
Push the “hello.ko” to the /data/local/tmp. Then insert the module and remove it. You will see this.
Let’s take a look at the second one. This kind of kernel module is built into the kernel so it will get loaded when you start the kernel and no need to load it manually.
Same here. Go to the goldfish/drivers directory and create the “helloword” directory. In this case, you have to make it here because we need to change the “Kconfig” and “Makefile” under the “drivers” directory.
First, in this “helloworld” directory, create “hello.c”.
The second one is Kconfig.
The third one is “Makefile”.
obj-y := hello.o
Then go to the “Kconfig” under the “drivers” directory and add this:
Go to the “Makefile” under the “drivers” directory and add this:
“obj-y += helloworld/”
After you finish all these things, go to the goldfish directory and do this to compile the whole kernel.
make goldfish_armv7_defconfig && make -j8
Now you get the new kernel, start it. Check this:
The module is loaded automatically!
Finally, we make it here! To be honest, in order to figure out how to set those configuration files, it took me several days. I asked many people and it just didn’t work on my machine. So be patient and move on.