Building Android Kernel for the Nexus 5 — AOSP(6.0.1)

来源:互联网 发布:华为办公网络 编辑:程序博客网 时间:2024/05/23 01:45

Useful links:
http://softwarebakery.com/building-the-android-kernel-on-linux
https://source.android.com/source/building-kernels.html
https://android.googlesource.com/kernel/msm

*** UPDATED Jan/18/2016 ***

[[ STAGE SEPARATED ]]

-In this article we are going to build a kernel and join it with the AOSP or build it standalone.
-The Kernel was not updated from android-5.1.0_r1->android-5.1.0_r3. It’s the same.
-Both Hardware and Software talk to each other seamlessly via the kernel.
-There are a few reasons you would want to build your own kernel.
1.) Adding features that are not available in stock.
b.) Yes that means editing source to your liking if that is your wish.
c.) Even merging with other master branches.
d.) Or you simply just want to make it your own.

[[ STAGE ONE ]]

2.) Install the following below:
b.) ‘build-essential‘ includes ‘dpkg-dev‘, ‘g++‘, ‘gcc‘, ‘libc6-dev‘, ‘make‘.
-Some we have and some we do not. Issue:
$ sudo apt-get install android-tools-adb android-tools-fastboot
$ sudo apt-get install build-essential abootimg git

3.) Check this page out for a low down of which kernel to build. Link
b.) Ours is for hammerhead device, binary location:device/lge/hammerhead-kernel, source location:kernel/msm, build config:hammerhead_defconfig

c.) From our previous AOSP build, the kernel was located in
workingDir/device/lge/hammerhead-kernel‘. The file is ‘zImage-dtb

d.) Checking your version of kernel: copy line below
dd if=zImage-dtb bs=1 skip=$(LC_ALL=C od -Ad -x -w2 zImage-dtb | grep 8b1f | cut -d ‘ ‘ -f1 | head -1) | zgrep -a ‘Linux version’

4.) Here is the android source kernel location. Here
b.) Let’s close in a bit. Straight to the recent release. Here
c.) As of this writing, 5.1.0_r1 was updated to 5.1.0_r3(3/25/2015) but the kernel is still the same -mr1.
d.) Remember your ‘workingDir‘ from previous AOSP build?
-Back out of it until you hit your $HOME directory. OR:
$ cd $HOME

f.) You could also grab other kernels here… say Nexus 6, Nexus 7 (grouper), Nexus 10.
g.) Grab the kernel source: Put it inside ‘kernel‘ folder.
$ git clone https://android.googlesource.com/kernel/msm \
––branch android-msm-hammerhead-3.4-marshmallow-mr1 kernel

Now we wait for it to complete.

[[ STAGE TWO ]]

1.) Downloading a prebuilt gcc.
2.) Check Google’s gcc instructions. Link
3. You are still in $HOME: Issue this:
$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6
b.) Once its done, a new folder named ‘arm-eabi-4.6‘ would have been created.

4.) Time to add the prebuilt toolchain to our path.
a.) You can also add these 4 lines into your .bashrc file.
b.) Issue this:
$ export PATH=~/arm-eabi-4.6/bin:$PATH

c.) Then issue these three:
$ export ARCH=arm
$ export SUBARCH=arm
$ export CROSS_COMPILE=arm-eabi-

d.) If you added these files into your .bashrc, reload it. ** DOT **
$ . ~/.bashrc

5.) Building the hammerhead kernel. Build from top or jump in ‘kernel‘ and ‘make hammerhead_config‘.
$ make -C kernel hammerhead_defconfig
$ make -C kernel

b.) Now you wait.
c.) It should be like the image below when its done.
kernelmakedone
d.) The kernel should be in ‘kernel/arch/arm/boot/‘ named ‘zImage-dtb‘.

[[ STAGE THREE ]]

1.) Google Android source says:
The kernel binary is output as: `arch/arm/boot/zImage` It can be copied into the Android source tree in order to build the matching boot image.

2.) We can deal with the kernel two ways. 1) Include with new AOSP, 2) Standalone boot.img file.

b.) We include with a new AOSP build at folder: ‘workingDir/device/lge/hammerhead-kernel
c.) Make a folder(OldKernel), move your old zImage-dtb inside there ^^^ to -> ‘~/OldKernel

3.) First let’s move the old zImage-dtb. While in ‘workingDir/device/lge/hammerhead-kernel
$ mv zImage-dtb ~/OldKernel/zImage-dtbOLDER
b.) Then move the newly compiled kernel it its place. ** Notice the *space then *single dot. **
$ cp ~/kernel/arch/arm/boot/zImage-dtb .
$ chmod 775 zImage-dtb

4.) Back out to ~/workingDir
$ cd ~/workingDir

5.) Remember ‘make clean‘ from previous article? Your out/ folder will be wiped.
$ make clean << ===== THIS IS NOT NECESSARY. You can skip if you recently built aosp.
$ . build/envsetup.sh
$ lunch aosp_hammerhead-userdebug

6.) Build again – Remember N=# of cpus picked for VM.
$ make -jN

myownkernelbuild

Look at the screenshot below. Notice the kernel version: it matches my terminal.
Screenshot_2015-03-26-19-26-33

7.) The Second way is to have ‘boot.img‘ flashed via ‘fastboot‘ by itself without redoing entire AOSP build.
b.) We are going to utilize the existing Hammerhead factory images to build our new boot image.
c.) Grab factory image from Google. I’m assuming you’re in ‘workingDir‘ folder.
$ wget https://dl.google.com/dl/android/aosp/hammerhead-lmy47d-factory-6c1ad81e.tgz

d.) We are after .zip file within .tgz file.
$ tar -xzf hammerhead-lmy47d-factory-6c1ad81e.tgz
$ cd hammerhead-lmy47d
$ unzip image-hammerhead-lmy47d.zip

Change folders to the output of the AOSP Build. $ cd ~/workingDir/out/target/product/hammerhead 
If you did not build aosp, just extract the boot.img from a Google Nexus Image archive. Link

e.) Now extract the files within boot.img
$ abootimg -x boot.img
– Couple files were spit out. bootimg.cfgzImageinitrd.img.

f.) You should still be under ‘hammerhead-lmy47d‘ folder.
– Remember that kernel we built from source? Let’s pull it to our local folder. ** Notice the single dot **
$ cp ~/kernel/arch/arm/boot/zImage-dtb .

g.) Let’s edit bootimg.cfg file.
$ gedit bootimg.cfg
-See the first line? bootsize = 0x…… – Delete it and bring everything up one line.
-Save file then exit.

h.) Time to create your own myboot.img file. 
$ abootimg ––create myboot.img -f bootimg.cfg -k zImage-dtb -r initrd.img
-We pulled the kernel locally, the other two files were extracted by abootimg.
-After the command above you should have a myboot.img file inside hammerhead folder folder.
bootimgcreated

8.) Boot into fastboot then try the new myboot.img file.
$ adb reboot-bootloader <—- If you were still at home screen.
$ fastboot boot myboot.img <—- Pay close attention, there is no flash mode. You’re simply booting to testmyboot.img
-Simply reboot and you’re back to your old boot.img.

9.) Test some calls, send some messages, visit the web. If it looks functional then flash it.
$ fastboot flash boot myboot.img <—- Now flash makes it stick.
-This time myboot.img is permanent until you flash another.

— We are done — One or two images might not match but the point is there.
*** UPDATED Jan/18/2016 ***


原文地址: https://dcrin3.com/unscrambled/?p=756

0 0