Building BusyBox from source

January 15, 2012 in AOSP

One nice thing to include with an AOSP ROM is BusyBox, which is collection of Unix utilities such as vi, cp, wget, etc…  Checkout the BusyBox website for more information.  Building BusyBox from source isn’t too hard, and while you could just grab a compiled binary from somewhere else, it’s nice to know how to do yourself so that you can always keep on the most current version.

  1. Install an ARM cross compiler.  Download and install the IA32 GNU/Linux Installer binary from here.  In this case, the binary is called arm-2008q1-126-arm-none-linux-gnueabi.bin.
    1. Make the installer executable:  chmod ~/Downloads/arm-2008q1-126-arm-none-linux-gnueabi.bin
    2. Launch the installer:  ~/Downloads/arm-2008q1-126-arm-none-linux-gnueabi.bin
    3. Accept all of the defaults (though you may want to change the install directory).
  2. The installer should set the PATH for you, but for me it didn’t do it.  You can verify by running “echo $PATH“.  If it doesn’t, add it manually.
    1. Open ~/.bashrc with gedit:  gedit ~/.bashrc
    2. Add the following to the file, adjusting your path as needed:  export PATH=$PATH:/home/jon/CodeSourcery/Sourcery_G++_Lite/bin
    3. Save and exit gedit
    4. Log out and log back in for that PATH change to take effect
  3. We need to clone the repository.  For this example we’ll use ~/code for our initial location.
    1. cd ~/code
    2. git clone git://busybox.net/busybox.git
  4. Next, we need to checkout the most recent branch.  Currently that is 1_19_stable.
    1. git checkout remotes/origin/1_19_stable
  5. Now we set up the configuration.
    1. cd ~/code/busybox
    2. make menuconfig
      1. Enable the following setting:  BusyBox Settings -> Build Options -> Build BusyBox as a static binary (no shared libs)
      2. Set the following equal to “arm-none-linux-gnueabi-”:  BusyBox Settings -> Build Options -> Cross compiler prefix
      3. Enable the following setting:  BusyBox Settings -> General Configuration -> Don’t use /usr
      4. Exit and save
  6. There is currently an issue where BusyBox will fail to compile due to missing mtd header file.  Here is a workaround for now:
    1. cp -r /usr/include/mtd ~/code/busybox/include/
    2. gedit ~/code/busybox/include/mtd/ubi-user.h
      1. Below this line “#include <linux/types.h>” add the following lines:
        1. #ifndef __packed
        2. #define __packed __attribute__((packed))
        3. #endif
    3. Save and exit gedit
  7. Now, make BusyBox.
    1. cd ~/code/busybox
    2. make

There will now be a busybox binary in ~/code/busybox.

References:


Building AOSP on Ubuntu 11.10

January 15, 2012 in AOSP

AOSP does not come with any proprietary code, which means that closed source vendor supplied drivers are not part of AOSP.  However, Google has worked out agreements with vendors to provide driver binaries for the flagship devices.  Driver binaries can be found here.  In order to run an AOSP build on a device, these drivers need to be downloaded and put into the AOSP directory before building.

  1. Download all of the drivers for your device.  Extract each one and copy the extraction scripts to your root AOSP folder.  For these instructions, we will assume the Nexus S binaries.  Adjust paths as needed.
    1. tar -zxf ~/Downloads/akm-crespo-iml74k-48d943ee.tgz
    2. cp ~/Downloads/extract-adm-crespo.sh ~/code/aosp
    3. Repeat the process for the remaining drivers.
  2. Run the extraction scripts from the AOSP root directory.
    1. ~/code/aosp/extract-adm-crespo.sh
    2. Read the agreement, and type “I ACCEPT” when prompted.
    3. After the script finishes, remove it:  rm ~/code/aosp/extract-adm-crespo.sh
    4. Repeat for each remaining driver script.
  3. You are now ready to build AOSP.  This can take anywhere from 30 minutes to several hours depending on your build system.
    1. cd ~/code/aosp
    2. . build/envsetup.sh
    3. lunch
    4. Choose the correct device from the list.
    5. If you created the “make_aosp” alias from the previous instructions, then run:
      1. make_aosp -jX otapackage (where ”X” is 2 times the number of cores available.  So for a quad core processor, you would run:  make_aosp -j8 otapackage)
      2. Otherwise, run:  make CC=gcc-4.4 CXX=g++-4.4 -jX otapackage

That’s it.  After a bit of time, the build will finish and you’ll have a flashable zip file that you can flash from recovery.  The zip file will be located in ~/code/aosp/out/target/product/crespo and in my case is named full_crespo-ota-eng.jon.zip.  Yours will be named similarly.

This zip file contains pure AOSP, so there are no Google apps included.  Additionally, it contains the stock recovery which will replace any custom recovery you may have put on your device.  We’ll eventually get to rooting, compiling and adding busybox, removing the default recovery, and re-signing the package.  But for now, this gives you pure AOSP.

References

Downloading AOSP source code

January 15, 2012 in AOSP

Downloading AOSP source code can take a while to complete depending on your internet connection.  The source code is multiple gigabytes.  Google has good instructions for downloading the source code here, which is what these instructions will be based off.

  1. If you don’r already have a ~/bin directory, create one.
    1. mkdir ~/bin
  2. By default, ~/bin should be added to your PATH automatically in Ubuntu 11.10.  To ensure it is,
    1. Open ~/.profile in gedit:  gedit ~/.profile
    2. Verify that the following section is in the file, and add it if it isn’t:
  3. Download the repo tool and make it executable.
    1. curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
    2. chmod a+x ~/bin/repo
  4. Create a folder to hold AOSP.  For these instructions, we will be using ~/code/aosp but you can adjust this as needed.
    1. mkdir ~/code/aosp
    2. cd ~/code/aosp
  5. Initialize the repo.
    1. repo init -u https://android.googlesource.com/platform/manifest
  6. Check out the branch of AOSP that you want to work with.  A list of branches and the devices they correspond to can be found here.  For this example, we’ll be downloading the branch to build Crespo (a.k.a. the Nexus S) so we’ll use the android-4.0.3_r1 branch.
    1. repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.3_r1
  7. Now synchronize the repository.  This can take anywhere from an hour to several hours depending on your internet connection.
    1. repo sync
  8. After the sync completes, load the public key into the GnuPG key database.
    1. gpg –import
  9. Copy and paste the following, and then press Ctrl-D to exit:–––––BEGIN PGP PUBLIC KEY BLOCK–––––
    Version: GnuPG v1.4.2.2 (GNU/Linux)mQGiBEnnWD4RBACt9/h4v9xnnGDou13y3dvOx6/t43LPPIxeJ8eX9WB+8LLuROSV
    lFhpHawsVAcFlmi7f7jdSRF+OvtZL9ShPKdLfwBJMNkU66/TZmPewS4m782ndtw7
    8tR1cXb197Ob8kOfQB3A9yk2XZ4ei4ZC3i6wVdqHLRxABdncwu5hOF9KXwCgkxMD
    u4PVgChaAJzTYJ1EG+UYBIUEAJmfearb0qRAN7dEoff0FeXsEaUA6U90sEoVks0Z
    wNj96SA8BL+a1OoEUUfpMhiHyLuQSftxisJxTh+2QclzDviDyaTrkANjdYY7p2cq
    /HMdOY7LJlHaqtXmZxXjjtw5Uc2QG8UY8aziU3IE9nTjSwCXeJnuyvoizl9/I1S5
    jU5SA/9W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F99faDMTV3+2SAOGvytOX6KjKVzKOSsfJQ
    hN0DlsIw8hqJc0WISQQYEQIACQUCSedYRAIbDAAKCRDorT+BmrEOeCUOAJ9qmR0l
    EXzeoxcdoafxqf6gZlJZlACgkWF7wi2YLW3Oa+jv2QSTlrx4KLM=
    =Wi5D
    –––––END PGP PUBLIC KEY BLOCK–––––

You are now ready to build AOSP.

References:

Setting up Ubuntu 11.10 to build Android Open Source Project

January 14, 2012 in AOSP

Setting up Ubuntu to build Android Open Source Project (AOSP) is not very difficult, and now that AOSP recently added support for Ubuntu 11.10 it will be more appealing to people who like to run on the latest Ubuntu release.  However, there are some gaps in the documentation to build AOSP on Ubuntu 11.10 successfully, so these instructions seek to fix that.  The 64-bit version of Ubuntu is the recommended version for compiling AOSP, and unless you have a compelling reason to stay on a 32-bit version, it is the best way to go.  With the latest version of Android, Ice Cream Sandwich (ICS), the system requirements for building AOSP have increased significantly.  To successfully build AOSP, your system should have:

  • 4gb of RAM or more.  It may be possible to build AOSP with less than 4gb of RAM, but you will subject your hard drive to considerable swapping.
  • 25gb of free disk space or more.  If you will only be building one branch of AOSP, then 25gb will be sufficient.  But if you plan to build more than one branch, for instance building for multiple devices, you will need more than 25gb.  Additionally, if you plan to make use of caching to improve build performance (and you should if you can), then you should give yourself at least another 50gb of free space on top of that.
  • A processor with multiple cores.  A single core processor would be able to build AOSP, but the build time will be decreased significantly with more cores available.
  • Optionally, a second physical hard drive.  It’s been suggested that having AOSP source code on one physical drive, and the build output on a separate physical drive, will improve build performance.

If you don’t have a dedicated system to install Ubuntu on just for AOSP, you can install it as a virtual machine.  VirtualBox and VMware Player are both cost free virtualization options.  If you do install Ubuntu into a virtual machine, give it access to as many CPU cores and as much RAM as you can.  Even fast systems can take an hour or more to build ICS on the first build.

Google has good instructions for setting up the build environment here which is what these instructions are based from.  A fresh OS installation is assumed for these instructions, but should work on existing installs.  Commands are run from the terminal.

  1. Make sure Ubuntu is up to date.  If you have any kernel updates, now might be a good time to reboot and let those updates take effect.
    1. sudo apt-get update
    2. sudo apt-get upgrade
  2. Install Java.  Ubuntu is no longer able to distribute Sun’s Java due to a licensing change, so it can’t be installed through apt.  Download Sun’s JDK version 6 update 30 directly from Sun here.  Be sure to download the Linux x64 .bin file.  After it downloads, run the following commands.
    1. sudo chmod a+x ~/Downloads/jdk-6u30-linux-x64.bin
    2. sudo cp ~/Downloads/jdk-6u30-linux-x64.bin /usr/lib
    3. cd /usr/lib
    4. sudo ./jdk-6u30-linux-x64.bin
    5. sudo mv /usr/lib/jdk1.6.0_30/ /usr/lib/jvm/
    6. Determine if any other JVMs are installed, and count how many, if any.
      1. sudo update-alternatives ––config java
      2. sudo update-alternatives ––install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_30/jre/bin/java 1 (Note the number 1 is used here if no previous JVMs have been installed.  Otherwise, this number should be 1 more than the number of JVMs installed.)
      3. sudo update-alternatives ––config java (Be sure to select Sun’s Java.)
    7. We need create symbolic links to a few Java binaries in /usr/bin
      1. cd /usr/bin
      2. sudo ln -s /usr/lib/jvm/jdk1.6.0_30/bin/javac
      3. sudo ln -s /usr/lib/jvm/jdk1.6.0_30/bin/jar
      4. sudo ln -s /usr/lib/jvm/jdk1.6.0_30/bin/javadoc
  3. We need  to ensure that the AOSP build process can locate the JDK, so we will set a variable it uses to locate the JDK.
    1. Open .bashrc in gedit:  gedit ~/.bashrc
    2. Add the following lines:
      1. ANDROID_JAVA_HOME=/usr/lib/jvm/jdk1.6.0_30
      2. export ANDROID_JAVA_HOME
    3. Save and exit gedit
  4. Install the required packages for building.
    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 lib32readline-gplv2-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc
  5. Install libX11
    1. sudo apt-get install libx11-dev:i386
  6. Install GCC 4.4, since AOSP has some incompatibilities with the included GCC 4.6 in Ubuntu 11.10.
    1. sudo apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib gcc-4.4-multilib
  7. Since we want to use GCC 4.4 instead of GCC 4.6 to build AOSP, we should make an alias rather than specify which GCC to use when we run make in AOSP.
    1. Open ~/.bashrc in gedit:  gedit ~/.bashrc
    2. Paste the following line:  alias make_aosp='make CC=gcc-4.4 CXX=g++-4.4'
    3. Save and exit gedit
  8. Create a symbolic link for libX11.
    1. sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so
  9. Configure USB access
    1. sudo touch /etc/udev/rules.d/51-android.rules
    2. sudo gedit /etc/udev/rules.d/51-android.rules
    3. Paste the follow in the empty file and save, then close gedit (be sure to replace <username> with your username):  # adb protocol on passion (Nexus One) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e12″, MODE=”0600″, OWNER=”<username>” # fastboot protocol on passion (Nexus One) SUBSYSTEM==”usb”, ATTR{idVendor}==”0bb4″, ATTR{idProduct}==”0fff”, MODE=”0600″, OWNER=”<username>” # adb protocol on crespo/crespo4g (Nexus S) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e22″, MODE=”0600″, OWNER=”<username>” # fastboot protocol on crespo/crespo4g (Nexus S) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e20″, MODE=”0600″, OWNER=”<username>” # adb protocol on stingray/wingray (Xoom) SUBSYSTEM==”usb”, ATTR{idVendor}==”22b8″, ATTR{idProduct}==”70a9″, MODE=”0600″, OWNER=”<username>” # fastboot protocol on stingray/wingray (Xoom) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”708c”, MODE=”0600″, OWNER=”<username>” # adb protocol on maguro/toro (Galaxy Nexus) SUBSYSTEM==”usb”, ATTR{idVendor}==”04e8″, ATTR{idProduct}==”6860″, MODE=”0600″, OWNER=”<username>” # fastboot protocol on maguro/toro (Galaxy Nexus) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e30″, MODE=”0600″, OWNER=”<username>” # adb protocol on panda (PandaBoard) SUBSYSTEM==”usb”, ATTR{idVendor}==”0451″, ATTR{idProduct}==”d101″, MODE=”0600″, OWNER=”<username>” # fastboot protocol on panda (PandaBoard) SUBSYSTEM==”usb”, ATTR{idVendor}==”0451″, ATTR{idProduct}==”d022″, MODE=”0600″, OWNER=”<username>”
  10. Open gedit and paste the following at the end of the file, then save and close:
    1. Open .bashrc in gedit:  gedit ~/.bashrc
    2. Paste the following at the end of the file:  export USE_CCACHE=1
    3. Save and exit gedit
  11. Set the CCACHE size.  The CCACHE size should be between 50-100gb, depending on how many branches you intend to build.
    1. prebuilt/linux-x86/ccache/ccache -M 50G
  12. Download the Android SDK for Linux from here and then extract it.  For purposes of these instructions, we will use ~/code folder for holding the Android SDK and later AOSP, but you can change it to any location you prefer.
    1. tar -zxf ~/Downloads/android-sdk_r16-linux.tgz -C ~/code
  13. Run the Android SDK Manager and install everything under Android 4.0.3 (API 15).  Also install Android SDK Tools and Android SDK Platform-tools.
    1. ~/code/android-sdk-linux/tools/android
  14. Now we need to add ~/code/android-sdk-linux/platform-tools to the PATH.  We need to use the full path to platform-tools, so adjust your path accordingly.
    1. Open .bashrc in gedit:  gedit ~/.bashrc
    2. Paste the following line at the end of the file:  export PATH=$PATH:/home/jon/code/android-sdk-linux/platform-tools:/home/jon/code/android-sdk-linux/tools
    3. Paste the following line at the end of the file below the one from above:  alias sudo=’sudo env PATH=$PATH’
    4. Save and exit gedit

Your Ubuntu system is now ready to download and build AOSP.  You’ll need to log out and log back in for the PATH variables to take effect.  Very good instructions for downloading AOSP can be found here.

References: