记录一下如何下载android模拟器内核代码以及编译模拟器内核代码:
1.下载编译器内核代码
参考Android open source网站的Build kernel的步骤,http://source.android.com/source/building-kernels.html
1.在Ubuntu 终端运行如下命令:
mkdir kernel
cd kernel
git clone https://android.googlesource.com/kernel/goldfish.git
2.为模拟器checkout正确的分支:
经过第一步之后,kernel 目录下会有一个goldfish目录,然后在终端运行:
cd goldfish
git branch -a
/*************************************************/
*master (*master表示当前在master分支)
remotes/origin/HEAD -> origin/master
remotes/origin/android-goldfish-2.6.29
remotes/origin/android-goldfish-3.4
remotes/origin/linux-goldfish-3.0-wip
remotes/origin/master
*master (*master表示当前在master分支)
remotes/origin/HEAD -> origin/master
remotes/origin/android-goldfish-2.6.29
remotes/origin/android-goldfish-3.4
remotes/origin/linux-goldfish-3.0-wip
remotes/origin/master
/*************************************************/
此时查看goldfish目录下,除了.git目录,没有其他文件。然后运行下面的命令
git checkout -t origin/android-goldfish-2.6.29 -b goldfish
再运行git branch -a 会看到:
/*************************************************/
* goldfish
master
remotes/origin/HEAD -> origin/master
remotes/origin/android-goldfish-2.6.29
remotes/origin/android-goldfish-3.4
remotes/origin/linux-goldfish-3.0-wip
remotes/origin/master
master
remotes/origin/HEAD -> origin/master
remotes/origin/android-goldfish-2.6.29
remotes/origin/android-goldfish-3.4
remotes/origin/linux-goldfish-3.0-wip
remotes/origin/master
/*************************************************/
此时目录下已经可以看到kernel代码了。
3.为模拟器产生配置文件
make ARCH=arm goldfish_defconfig
或者
[Android4.1平台需要进行如下配置]
make ARCH=arm goldfish_armv7_defconfig
正确产生配置文件后,终端会提示如下信息:
/*******************************************/
#
# configuration written to .config
#
/*******************************************/
# configuration written to .config
#
/*******************************************/
4.编译内核
编译内核是需要用到交叉编译器,如果已经下载好Android的源代码,那么在Android源代码的目录里面有个prebuild目录,该目录下有已经编译好的交叉编译工具,如果没有下载android源代码,可以使用如下命令单独下载prebuild目录
git clone https://android.googlesource.com/platform/prebuild
下载完成之后可以运行如下命令进行编译【CROSS_COMPILE=YOUR_OWN_PREBUILD_PATH】
make ARCH=arm CROSS_COMPILE=/home/kaffeel/Android/WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
【如果编译4.1版本Android内核,需要使用最新编译器4.4.3,否则编译会出错】
即可开始编译;
编译完成会提示如下信息:
/********************************************/
SYSMAP System.map
SYSMAP .tmp_System.map
OBJCOPY arch/arm/boot/Image
Kernel: arch/arm/boot/Image is ready
AS arch/arm/boot/compressed/head.o
GZIP arch/arm/boot/compressed/piggy.gz
AS arch/arm/boot/compressed/piggy.o
CC arch/arm/boot/compressed/misc.o
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
/********************************************/
SYSMAP .tmp_System.map
OBJCOPY arch/arm/boot/Image
Kernel: arch/arm/boot/Image is ready
AS arch/arm/boot/compressed/head.o
GZIP arch/arm/boot/compressed/piggy.gz
AS arch/arm/boot/compressed/piggy.o
CC arch/arm/boot/compressed/misc.o
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
/********************************************/
编译完成后,Image文件会在arch/arm/boot/目录下。
5.测试编译的zmage
有两种方法进行测试:
1.直接运行模拟器
cd /home/kaffeel/Android/android-sdk/tools
./emulator -avd Android4.1 -kernel /home/kaffeel/Android/kernel/goldfish/arch/arm/boot/zImage
【其中-avd后的模拟器名字需要是事先建好的Android Virtual Device 的名字】
即可开始运行Android模拟器