如何编译Android内核

根据XDA-Developer上的文章翻译,原文连接:http://forum.xda-developers.com/showthread.php?t=1774035

建立内核编译环境和第一次编译内核:

1.

Ubuntu 10.04 64-Bit(推荐)

Ubuntu 12.04 64-Bit

注意:不要使用Ubuntu 12.04编译AOSP ROMs,但可以用于编译内核

如果你想使用虚拟机软件安装Ubuntu,用于编译内核,不要使用Virtualbox.因为使用Virtualbox可能会遭遇网络等等…问题.我建议使用VMWare Player,因为它可以免费使用: http://www.vmware.com

2.

安装最新的更新,然后重启:

1 $ sudo apt-get update

2 $ sudo apt-get dist-upgrade

3 $ sudo reboot

3.

然后我们要下载并安装最新Java 6 JDK,寻找JavaSE 6 Update33或更新版本,不要下载JDK7.我下载的是下面这个文件:

1 Linux x64 68.69 MB jdk-6u33-linux-x64.bin

下面假设你下载的JDK文件在如下文件夹下:

~/Downloads

安装JDK:

 1 $ cd ~/Downloads

 2 $ sudo chmod +x jdk-6u33-linux-x64.bin

 3 $ ./jdk-6u33-linux-x64.bin

 4 $ sudo mv jdk1.6.0_33 /usr/lib/jvm/jdk1.6.0_33

 5 $ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_33/bin/javac 1

 6 $ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_33/bin/java 1

 7 $ sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_33/bin/javaws 1

 8 $ sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.6.0_33/bin/jar 1

 9 $ sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk1.6.0_33/bin/javadoc 1

10 $ sudo update-alternatives --config javac

11 $ sudo update-alternatives --config java

12 $ sudo update-alternatives --config javaws

13 $ sudo update-alternatives --config jar

14 $ sudo update-alternatives --config javadoc

15 $ java --version

16 $ ls -la /etc/alternatives/java*

接下来你可以选择重启,这是比较安全的做法:

1 $ sudo reboot

4.

安装需要的文件以编译Android

Ubuntu 10.04:

1 $ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc

Ubuntu 12.04:

1 $ sudo apt-get update

2 $ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 git

3 $ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

4 $ sudo reboot

5.

配置USB接口

1 $ sudo gedit /etc/udev/rules.d/51-android.rules

这个文件应该有如下内容:

 1 # adb protocol on passion (Nexus One)

 2 SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>"

 3 # fastboot protocol on passion (Nexus One)

 4 SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>"

 5 # adb protocol on crespo/crespo4g (Nexus S)

 6 SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>"

 7 # fastboot protocol on crespo/crespo4g (Nexus S)

 8 SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"

 9 # adb protocol on stingray/wingray (Xoom)

10 SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="<username>"

11 # fastboot protocol on stingray/wingray (Xoom)

12 SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="<username>"

13 # adb protocol on maguro/toro (Galaxy Nexus)

14 SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>"

15 # fastboot protocol on maguro/toro (Galaxy Nexus)

16 SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="<username>"

17 # adb protocol on panda (PandaBoard)

18 SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="<username>"

19 # fastboot protocol on panda (PandaBoard)

20 SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="<username>"

21 # usbboot protocol on panda (PandaBoard)

22 SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="<username>"

23 # usbboot protocol on panda (PandaBoard ES)

24 SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="<username>"

6.

当编译一个内核,你只需要从这里开始。手工从git选择适当branch,我使用下面的文件作为例子,每次访问git源,选择合适branch:

https://android.googlesource.com/device/samsung/crespo

1 $ mkdir ~/Documents/kernel

2 $ cd ~/Documents/kernel

3 $ git clone https://android.googlesource.com/device/samsung/crespo -b ics-plus-aosp

然后从https://android.googlesource.com/kernel/samsung.git选择branch

1 $ cd crespo

2 $ git clone https://android.googlesource.com/kernel/samsung.git -b android-samsung-3.0-ics-mr1

7.

确认工具链在你的环境变量中:

a)默认、简单的解决方案

1 $ git clone https://android.googlesource.com/platform/prebuilt -b ics-plus-aosp

2 $ export PATH=$(pwd)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH

   $(pwd)是目前存在可用的工作目录

b)Bandwidth-friendly解决方案:

你也能下载工具链至别的目录,但首先写下你的工作目录:

1 mkdir ~/Documents/toolchain

2 cd ~/Documents/toolchain

3 $ git clone https://android.googlesource.com/platform/prebuilt -b ics-plus-aosp

4 export PATH=~/Documents/toolchain/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH

我们必须在这里指定工具链位置的绝对路径,而不是相对路径

现在我们回到工作目录:

1 cd ~/Documents/kernel/crespo

8.

现在让我们build内核

1 $ export ARCH=arm

2 $ export SUBARCH=arm

3 $ export CROSS_COMPILE=arm-eabi-

4 $ cd samsung

5 $ make ARCH=arm herring_defconfig (maybe ARCH=arm is unneeded here but added it to be sure)

6 $ make

9.

现在你需要将它放入刷机包中

 

常见问题及解决方案

-避免下载内核源码到目录可能需要root/superuser权限

该问题的原因是我下载所有源码至'~/Documents'目录。这将节省许多时间但可能导致文件属性及权限混乱。

-什么是'herring',这不应该是crespo吗?

不,当然不是。Herring是公示名,而crespo是Nexus S的开发代号,crespo代号是你在build内核时应该记住的。

 

令人感兴趣的文件和路径

<kernel_directory>/samsung/arch/arm/mach-s5pv210/cpu-freq.c
Overclocking
Voltages

 

源码连接

Ezekeel的内核源码:https://github.com/Ezekeel/GLaDOS-nexus-s-ics

包括:

  • BLN
  • BLX
  • Custom Voltage
  • Deep Idle
  • Live OC
  • Touchwake
  • USB OTG
  • Voodoo

适用于S5PV210的Samsung IDLE2的相关:http://forum.xda-developers.com/showthread.php?p=28959134

你可能感兴趣的:(android)