Android Kernel Development - Kernel compilation and Hello World
Introduction
Due to the lack of the material that clearly kick off the android kernel development , hopefully it will gives the clearer guide to develop your own android driver and debugging it.
p.s. Due to the version differential, this article is not ensure all of the Android Version , SDK version, source code , and Emulator is compatible , however, the door of research is always opened, just feel free to contact me and play together :P
All the materials are also saved in the VM , you can just directly leverage the existing VM Image for development or alternatively, as a research and studying, follow the following guide to create your own workplace.
Android kernel didn't have dynamically insmod like the other linux, so this tutorial is trying to build a new Android Kernel and make test our kernel driver as well.
Android studio
Android ndk-r10
Android SDK
Goldfish v3.10
VMWare 15
- Install a Android Studio in your Ubuntu
- Install a latest android SDK
- Install a emulator by Android studio as following:
- Download the R10(suggested version) Android NDK for compiling your Android Kernel
- Goldfish is a kernel that opensource by Google, and it is packed with INSMOD and RMMOD for dynamically installing the driver and removing as well.
- First of all, open your terminal, and execute the following command:
Just create a directory and change to there.
ARCH and CROSS_COMPILE have to be as same as the kernel config (arm and arm-linux-androidebi-)
Just check it out, is there a hello.ko comes out , after compilation
First of all , we check the existence of device
Second, we have to push (moving) the system drier file , to the disk of android emulator.
Reference:
https://developer.android.com/ndk/
Android kernel didn't have dynamically insmod like the other linux, so this tutorial is trying to build a new Android Kernel and make test our kernel driver as well.
Material
Ubuntu 18.04.2 LTSAndroid studio
Android ndk-r10
Android SDK
Goldfish v3.10
VMWare 15
Prepare the environment
- Install a Ubuntu VM- Install a Android Studio in your Ubuntu
- Install a latest android SDK
- Install a emulator by Android studio as following:
- Download the R10(suggested version) Android NDK for compiling your Android Kernel
Compile the goldfish kernel
- Goldfish is a kernel that opensource by Google, and it is packed with INSMOD and RMMOD for dynamically installing the driver and removing as well.
- First of all, open your terminal, and execute the following command:
cd ~
mkdir kernel
cd kernel
git clone http://android.googlesource.com/kernel/goldfish.git
git branch -a
Afterward, check all the branch it has
p.s. I have test with 3.10 pure version.
- We could check out by the following command:
git checkout remotes/origin/android-goldfish-3.10
- We set the compile path and emulator path into the environment variable
- The NDK is used for compile the Goldfish
- The emulator is used for testing
After the variable set, we could enter the command
make goldfish_armv7_defconfig
make menuconfig
So that you're able to custom your kernel configuration right now
In this tutorial we want to create a kernel with Loadable kernel module capability
so we enable the option that 'Enable loadable module support'
press 'esc' twice for quiting and saving the config
Enter the following command in current directory
gedit Makefile
After that, just simple enter 'make' command for building the kernel, mostly it usually compile perfectly. As the following output, mean the kernel compile success
Next, we could use that newer kernel for launching the emulator! such an exciting moment!
Compile our hello driver
Just create a directory and change to there.
Create the Makefile in the directory, as following
ARCH and CROSS_COMPILE have to be as same as the kernel config (arm and arm-linux-androidebi-)
Just check it out, is there a hello.ko comes out , after compilation
Testing
With the emulator, we connect the adb to the device (adb should be installed along with android studio, so we could just simply enter 'adb' command on the terminal.First of all , we check the existence of device
Second, we have to push (moving) the system drier file , to the disk of android emulator.
Thirdly, we connect to the shell of emulator, by using gdb shell command
and change directory to our destination (/data/local/tmp/) and install it on the the system
So, In the example, we just print out that, says, hello Tencent
https://developer.android.com/ndk/
Comments
Post a Comment