Android 入门 -- 编译内核

来源:互联网 发布:阿里云企业邮箱 免费版 编辑:程序博客网 时间:2024/04/28 19:13
Android的源代码中并没有包含内核的源代码,本文介绍在MacOSX下如何下载编译Android的内核。在编译内核之前,请先了解如何编译Android源码,参看博文:Android 入门 - 编译源码(MacOSX)

一、准备工作

1.1、安装最新的XCODE

XCODE是MacOSX下的开发工具,安装之后,开发需要的各种环境基本就具备了,不需要再各自去下载。如:git,gcc等等。

1.2、安装GoAgent

googlesource站点在国内不能访问,需要翻墙才能访问。建议安装GoAgent来翻墙。
安装步骤:略,可从网上搜索解决。

1.3、设置代理

# export http_proxy=localhost:8087# export https_proxy=localhost:8087
localhost:8087是你的GoAgent代理的地址与端口。

1.4、创建大小写敏感的磁盘映象

  1. 创建一个大小写敏感的磁盘映象,100G,映象根据实际大小占据磁盘空间,所以,大点没有关系,命令:
    # hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 100g ~/android-kernel.dmg
  2. 挂载磁盘,可在Finder里双击“个人”主目录的android-kernel.dmg.sparseimage,即可挂载一个UNNAME的磁盘,按“右键”更名为android。实际路径为:/Volumes/android-kernel。

二、下载内核源码

2.1、获取内核版本信息

有两种方法获取Android内核版本,都需要运行模拟器:
# emulator -cpu-delay 0
a). 在模拟器里查看内核版本
进入 应用 -> 设置  -> 关于手机  ->内核版本,即可查看到此Android的内核版本。
b). 用adb shell 连接模拟器命令查看
# adb shell# cd proc# cat version
得到Android 4.4的内核版本为“Linux version 3.4.0-gd853d22”

2.2、下载源码

# cd /Volumes/android-kernel/# mkdir source# cd source# git clone https://android.googlesource.com/kernel/goldfish.git

2.3、查看源码版本

# cd goldfish# git branch -a
结果如下:
* master  remotes/origin/HEAD -> origin/master  remotes/origin/android-3.10  remotes/origin/android-goldfish-2.6.29  remotes/origin/android-goldfish-3.10  remotes/origin/android-goldfish-3.4  remotes/origin/linux-goldfish-3.0-wip  remotes/origin/master

2.4、Check out 3.4版本

# git checkout remotes/origin/android-goldfish-3.4

三、编译

3.1、初始化配置

# export PATH=/Volumes/android/source/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.7/bin/:$PATH# vi Makefile
修改如下内容:
ARCH ?= $(SUBARCH)CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)改成:ARCH ?=armCROSS_COMPILE ?=arm-eabi-

3.2、除错

Mac下编译会出现一些错误:
# cp /Volumes/android/source/external/elfutils/libelf/elf.h scripts/mod# vi scripts/mod/mk_elfconfig.c
将 include <elf.h> 修改为 include "elf.h"。

# vi scripts/mod/modpost.h
将 include <elf.h> 修改为 include "elf.h"。

3.3、编译

# make goldfish_armv7_defconfig# make -j16
编译完成后,会在最后显示如下内容:
...  OBJCOPY arch/arm/boot/zImage  Kernel: arch/arm/boot/zImage is ready

4、运行

运行如下指令:
# emulator -kernel arch/arm/boot/zImage
运行结果如下图:





0 0
原创粉丝点击