Wednesday, 22 February 2017

Building and Flashing AOSP for Device ( Nexus 5 hammerhead )

Hello Guys hope you are doing well!!!.
How to build AOSP for real device let say Nexus 5 (Hammerhead). In my previous blog, I had given info for AOSP download and build for Emulator. But building AOSP for a real device and flashing it is quite different. Today I am going to discuss it step by step.

Pre requisites:
Before proceeding for Downloading and building

1. GIT has to be installed
2. Make sure the following packages are installed in the system
- gcc-multilib                         --> sudo apt-get install gcc-multilib
- bison                                    --> sudo apt-get install bison
- flex                                        --> sudo apt-get install flex
- lib32z1 and lib32z1-dev         --> sudo apt-get install lib32z1 lib32z1-dev

Downloading and building:

Step 1. Choose Right Source code
Based on your available Test device and its binary file (device driver) , Download the respective source code. Please follow this link 


Open above link search for your device and then find the corresponding AOSP branch code. Let say for Nexus 5 (hammerhead) I have chosen Marshmallow (android-6.0.1_r77).

Step 2 Download the AOSP code
Please follow my previous blog for download.

Step 3. Download the binaries file

Open following link

and search for your device binaries. In my case I have Nexus 5 (hammerhead) and I have selected android-6.0.1_r77 this AOSP branch . So code Name is M4B30Z.
After successful download of device driver binary , extract it (say /u dir) and
 go to root folder of your AOSP code base. cd ../<AOSP code>/
Run this scripts from there.
  • sh /u/extract-broadcom-hammerhead.sh
  • sh /u/extract-qcom-hammerhead.sh
  • sh /u/extract-lge-hammerhead.sh
run each command one by one  and hit enter slowly and at the end you have to enter  I Accept for T&C.  After successful this operation  check your <aosp code> folder there you find one new folder named as vendor. This folder contain all binaries for your device.

Step 4. Build the source code
Use following command for building. For more detail on build command follow my previous blog.
> source build/envsetup.sh
>lunch
> select your lunch argument. For me it is 19 (aosp_hammerhead-userdebug).
>make -j4 (or -j16 based on your RAM and CPU core)
Once the build is complete, the system.img file can be found at out/target/product/hammerhead

Step 5. Flash Image into device

After building successful system image, We can flash now. Connect your Test device via USB cable and give following command in your terminal

  1. <aosp-working-dir> ./adb reboot bootloader 
  2. <aosp-working-dir> ./fastboot flash boot /path_of_your_boot_image 
  3. <aosp-working-dir> ./fastboot flash system /path_of_your_system.img 
  4. <aosp-working-dir> ./fastboot flash userdata /path_of_your_userdata.img 
  5. <aosp-working-dir> ./fastboot flash recovery /path_of_your_recovery.img 
  6. <aosp-working-dir> .fastboot reboot 
Happy Coding !!!
Thanks
Saurabh

Note:- Please proved your comment and suggestion for my post. It will energize me.

3 comments:

  1. Very useful information that you have shared and it is very useful to me.Thanks for sharing the information with us.

    best mobile app development company in chennai

    ReplyDelete
  2. Hi thanks for this information.i have extracted the binaries and accepted the agreement for this three, but in lunch menu i could not able to see the "aosp_hammerhead-userdebug".what will be the issue please help me out.

    ReplyDelete
  3. I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts. בניית וילה

    ReplyDelete

Build a Custom Kernel Module for Android

Hi Guys!!!Hope you are doing well !!!. Today I will describe how you can write a custom kernel module(Hello world) for Android and load it a...