Thursday, June 5, 2014

Build Android 4.2 AOSP project for Nexus 4


Make Your OWN Android AOSP System for Nexus 4



Build and Install AOSP JellyBeans Platform for Nexus 4 (Code named Mako)

Before start, make sure your already have a 64-bit linux system used for development! By saying 64-bit, I'm not kidding, because I've tried using my 32-bit poor Centos and failed with endless problems. Finally I found out only 64-bit development systems are supported by JellyBeans now! So get yourself a 64-bit linux system, or if you're a guy who likes hacking around and get the luck to successfully build a JB platform on 32-bit system, please let me know and share the happiness with you!
And please read through the standard android document from AOSP if you've never built an Android image before.
Guess you are out of patience to get your hands dirty to setup your nexus 4 running your own system. OK. let's start by downloading the latestest android system which integrated mako target. Your can find all the Android platforms in AOSP here The one I use is android-4.2.2_r1, which is the latest version when writing this article. I assume you've known how to download the source from AOSP. Otherwise, read the AOSP document Downloading the Source Tree.
Besides the platform source code, we need the driver binaries in order to run system on real devices. Official binaries can be downloaded from Google's Nexus driver page. Download and extract the vendor drivers of "Nexus 4 binaries for Android 4.2.2 (JDQ39)" on that page. Details about how to extract the proprietary binary drivers refer to the Obtaining proprietary binaries part. You'd better do this before build the platform, or you have to make clober and rebuild the whole system, which takes lots of time!
It's time to give birth to the new image now!
$ . build/envsetup.sh
$ lunch full_mako-eng
$ make -j[N]
Now we have our own system image at .../out/target/product/mako. We'll use fastboot to flash the system image. This requires a unlocked bootloader. The default bootloader is locked, but you can turn it to unlocked in the fastboot mode(press and hold both Volumn Up and Power or adb reboot-bootloader) by
fastboot oem unlock

Flash all in one single command: this writes boot, recovery and system images to corresponding partitions together. "-w" option can wipe cache partition and data.
cd out/target/product/mako 
fastboot -w flashall

Build Linux Kernel and Create Boot Image (Kernel + Init Ramdisk)

The kernel sources support nuxus 4 (mako) are in the Qualcomm MSM project, the latest kernel source can be downloaded:
git clone https://android.googlesource.com/kernel/msm -b android-msm-mako-3.4-jb-mr1.1
Now config and build the kernel: the built kernel will be output at arch/arm/boot/zImage
export CROSS_COMPILE=arm-linux-androideabi-
export ARCH=arm
make mako_defconfig
make -j[N]
You'll probably have an compile error if you following the instruction to this point.
drivers/gpu/msm/adreno.c:433:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]
error, forbidden warning: adreno.c:433
make[3]: *** [drivers/gpu/msm/adreno.o] Error 1
This is caused by warn config stack frame size in the kernel. Therefore you need to make menuconfig and reconfig the CONFIG_FRAME_WARN value which located at Kernel hacking->Warn for stack frames larger than (needs gcc 4.4).
The tricky part is to make boot image using the kernel image built previously. Actually, the boot image consists of kernel image and init ramdisk image. Yes, we also need the ramdisk image so as to make the boot image. The approach is to extract the ramdisk image and kernel configuration file from the official boot.img in Google's factory image for nexus 4. This can be done by using abootimg tool. Some articles recommend "split_bootimg.pl", but doesn't work for nexus 4 or for me.
To extract kernel config file, kernel image and ramdisk image from official boot image: the outputs are bootimg.cfg zImage initrd.img respectively.
abootimg -x boot.img
Remove the bootsize property in bootimg.cfg as our kernel image can be larger than the one from the factory image. Now we can create our boot image by:
abootimg --create myboot.img -f boot.cfg -k [path-to-your-zImage] -r initrd.img
Verify the boot image without flashing it:
fastboot boot myboot.img
You can root Android by modify the official ramdisk image. First, un-gzip and un-cpio the official ramdisk image extracted from boot.img.
mkdir ramdisk && cd ramdisk
gunzip -c ../initrd.img | cpio -i
Edit default.prop file in the ramdisk, set "ro.secure=1" to "ro.secure=0".
Repack the ramdisk:
find . | cpio -o -H newc | gzip > ../myramdisk.gz
Now create the insecure boot image with this ramdisk image, which allows you to login as root.
abootimg --create myboot-rooted.img -f boot.cfg -k [path-to-your-zImage] -r myramdisk.gz
Flash your rooted boot image by
fastboot flash boot myboot-rooted.img

Check your kernel version when your Android system started!

References:

  • http://nosemaj.org/howto-build-android-nexus-4
  • http://forum.xda-developers.com/showthread.php?t=2131953

No comments:

Post a Comment