As an Android operating system built on the Linux kernel, its compilation and porting are very similar to Embedded Linux, both in terms of process and technology. So the first chapter of the study is the Android system porting and compiling.
The main steps are:
1. Using the Git tool to download, execute the following command:
[Email protected]:~/android$ mkdir kernel
[Email protected]:~/android$ CD kernel
[Email protected]:~/android/kernel$ git clone http://android.googlesource.com/kernel/goldfish.git
Also after a long wait, in the kernel directory there is a common directory, the Linux kernel code is here.
2. After the download is complete, you can view the downloaded kernel code version:
[Email protected]:~/android/kernel$ CD Common
[Email protected]:~/android/kernel/common$ git branch
android-2.6.36
3. The above is the kernel source code on the main line, and now we need the kernel for the simulator, so we need checkout goldfish version:
[Email protected]:~/android/kernel/common$ git branch-a
* android-2.6.36
Remotes/origin/head-origin/android-2.6.36
remotes/origin/android-2.6.35
remotes/origin/android-2.6.36
remotes/origin/archive/android-2.6.25
remotes/origin/archive/android-2.6.27
remotes/origin/archive/android-2.6.29
remotes/origin/archive/android-2.6.32
remotes/origin/archive/android-gldfish-2.6.29
remotes/origin/archive/android-goldfish-2.6.27
Select android-gldfish-2.6.29:
[Email protected]:~/android/kernel/common$ git checkout remotes/origin/archive/android-gldfish-2.6.29
Three. Compile the kernel code.
1. Export the cross-compilation tool directory to the $PATH environment variable:
[Email protected]:~/android/kernel/common$ export path= $PATH: ~/android/prebuilt/linux-x86/toolchain/ Arm-eabi-4.4.3/bin
2. Modify the following two behaviors of the makefile file under the common directory:
# ARCH = (subarch)
# cross_compile?=
ARCH = Arm #体系结构为arm
Cross_compile = arm-eabi-#交叉编译工具链前缀, refer to ~/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin directory
3. Start compiling:
[Email protected]:~/android/kernel/common$ make Goldfish_defconfig
[Email protected]:~/android/kernel/common$ make
After compiling successfully, you can see the following two lines:
Objcopy Arch/arm/boot/zimage
Kernel:arch/arm/boot/zimage is ready
You can also perform make menuconfig to configure the compile options before you execute the makes command.
Four. Run the compiled kernel in the emulator.
1. Before starting the emulator, set the emulator directory to the environment variable $path:
[Email protected]:~/android$ export path= $PATH: ~/android/out/host/linux-x86/bin
2. Set the ANDROID_PRODUCT_OUT environment variable:
[Email protected]:~/android$ Export Android_product_out=~/android/out/target/product/generic
3. In the background, specify the kernel file to start the emulator:
[Email protected]:~/android$ emulator-kernel./kernel/common/arch/arm/boot/zimage &
4. Connect the emulator with the ADB tool, view the kernel version information, and see if the kernel running on the emulator is the kernel we just compiled:
[Email protected]:~/android$ adb shell
At this point, if the adb shell command is run for the first time, you will see the following output, and then run the ADB shell command again without having to worry about it.
* Daemon not running. Start it now on Port 5037 *
* Daemon started successfully *
Error:device offline
To switch to the proc directory:
[Email protected]:/# CD proc
[Email Protected]:/proc # cat Version
Linux version 2.6.29-gb0d93fb-dirty ([email protected]) (GCC version 4.4.3 (gcc)) #1 Fri June 3 23:17:24 HKT 2011
You can configure success as soon as you follow the steps
Android Driver Development Chapter I Caprice