Building cyanogenmod from source

Cyanogenmod 5.0.7 stable has just been released for the Dream, Magic, Nexus One and Droid phones.  This is a great alternative to get Android 2.1 Eclair, especially to G1 (aka Dream) owners, who are still stuck with Android 1.6 — that is likely not going to change, due to the way the flash storage of the Dream is partitioned, not leaving enough room for a full 2.1 software update.

For the brave, it is also possible to build a Cyanogen ROM from source.  However, I haven’t been able to find any complete guide how to do that, so here’s one quick recap how it can be done.

It’s recommended to use Linux for the build process.  Ubuntu 8.04 or later will do.  You need the following packages:

sudo apt-get install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev
This is for a 32-bit installation, on a 64-bit system they may have different names or you may have to install the 32-bit version from certain packages.  Ubuntu 9.10 and later doesn’t include Java5 from Sun anymore, but the Jaunty repositories can be used — just add the following lines to /etc/apt/sources.list:
deb http://us.archive.ubuntu.com/ubuntu/ jaunty multiverse
deb http://us.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse
You also need the repo tool to fetch and manage Android source repositories:
curl http://android.git.kernel.org/repo > ~/bin/repo
chmod 755 ~/bin/repo
Once all the tools above are installed you can grab the Cyanogen Eclair repository:
mkdir cm
cd cm
repo init -u git://github.com/cyanogen/android.git -b eclair-ds
repo sync
This will clone all git repositories needed for the build.  It takes some time, so relax and have a coffee or two…  You can also use this time to install the Android SDK if you haven’t done so before, since you will need adb to access your phone.  Make sure the tools folder from the unpacked SDK is in your PATH.
Once you have the repositories you’ve got to extract the proprietary HTC files from your device.  Hook your phone up to your PC via USB.  Make sure your computer can see it:
% adb devices
List of devices attached
HT851N000044    device
Then you can go ahead and fetch the files:
cd vendor/htc/dream_sapphire
./extract_files.sh
If you don’t have your phone at hand you can also download an official HTC firmware and get the necessary files from it.  Go to htc.com and get signed-dream_devphone_userdebug-img-150275.zip.  You can use unyaffs to unpack system.img after you uncompressed the zip file, and then you can copy all necessary files from the folder it was extracted into.
Then go back to your build root, set up the build environment and choose your build target:
cd ../../..
source build/envsetup.sh
lunch
If you use zsh envsetup.sh may fail, but you can simply
unsetopt NOMATCH
in your shell and you’re good to go.  You can build everything with a simple
m
If you only need the OTA-format update zip use:
TARGET_NO_RADIOIMAGE=true make otapackage
One drawback of this process is that it produces an image that barely fits onto the G1 even after repartitioning it with the Danger SPL — there won’t be enough space left for Google applications like Gmail, Market and Talk.  I haven’t been able to find any clue how “official” Cyanogenmod images are built so that it remains slim enough to make Google’s applications also fit onto the phone — the xbin folder contains a squashfs image that spares some megabytes, but it is not enough in itself.  If you install this image you have just built, the Google applications won’t fit.  Perhaps the key is some build option which optimizes for size — if you figure it out, let me know.
Happy hacking!

2 Responses to Building cyanogenmod from source

  1. Thanks for the clear explanation… I am having a problem building for Passion/NexusOne, in that it dies on the BusyBox compilation, and even when I can get it past that step it never creates any .img files in the out folder.

    Any thoughts? Some more information posted here:
    http://forum.xda-developers.com/showthread.php?p=6959321#post6959321

  2. Pingback: Nilvec » Testing an Android image built from source

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">