Skip to content

Instantly share code, notes, and snippets.

@surma
Created August 6, 2012 23:22
Show Gist options
  • Save surma/3279521 to your computer and use it in GitHub Desktop.
Save surma/3279521 to your computer and use it in GitHub Desktop.
Journey to my own Android ROM

Motivation

  • Make testing new releases easy for me. No tedious reinstalling of my common apps
  • Some graphical customizations for nerdcred
  • Ability to patch things
  • Deeper understanding

Plan

  • Be as vanilla as possible for easy version upgrade
  • Steal device specific stuff from CyanogenMod, give credit, maybe even understand it and patch something
  • Stay modular so ROM is easily ported to other devices
  • Own rom which has all my default apps installed (and maybe installs non-free apps automatically if they have been bought?), but the list of installed apps is easliy configured

Anti-Scare-Tactics

As it turns out, it is hard to brick a device to the point where only the manufacturer can rescue it. By flashing ROMs you do only exactly that: Flash ROMs. Recovery and bootloader are not touched in the process. Since your recovery is most likely ClockworkMod, you have a really nice interface (and adb shell access) if something goes wrong.

If for some reason you manage to destroy CWM as well, you still got fastboot. With fastboot you can still flash disk images (though not copy single files like with CWM and adb). Stock images of all the necessary partitions can usually be found.

If you destroy fastboot, you're most likely screwed, and you got no one to blame but yourself.

Hardware

Here's a list of the hardware I own. The bold ones are retired and can be used as testing devices (i.e. it doesn't hurt if they get bricked).

Of course, initial development and testing will be done inside the emulator.

Downloading and installing

First run: Building AOSP

Downloading took quite a while, but I could boot the resulting image just fine in the emulator. It was missing all the Google Apps and also the Play Store. I expected GApps to be missing, not the Play Store though.

Intermezzo: Offline Copy

To make start-from-scratch faster and easier, make a local mirror of both the CM and AOSP repositroy.

repo init -u <repo url> --mirror [-b branch]
repo sync

For CM, I chose the ics branch (because there is no master, which is the default). It said that a repo is about 10Gig each, so this might take a while.

For some reason, the sync seems to hang indefinitely sometimes or skips some repositories. I just kept restarting the sync until nothing changed anymore.

CM is only listing those repositories in the manifest.xml which are needed for that particular branch being checked out. This makes switching branches after cloning not work. For that reason I turned to the other extreme and wrote a small bash script to clone every missing repository of CM :

github_forall.sh

This script executes a given command for every repo URL of CyangogenMod's Github. To clone every repo they own, execute:

./github_forall.sh CyanogenMod git clone --mirror

At the point of writing this will use 32Gigs and a lot of time.

Second run: Building CM9 (ICS)

repo init -u /home/surma/android/mirros/cm/CyanogenMod/android.git -b ics
repo sync
. build/envsetup.sh
lunch full-eng
make -j12

Third run: Building CM for bravo

The initial procedure stays the same. However, after lunch cyanogen_bravo-eng, the proprietary files have to be prepared and ROM Manager has to be downloaded.

cd device/htc/bravo
./extract-files.sh

Troubleshooting

Setup & Compiling errors

repo init [...] && repo sync fails when using my local mirror

I encountered this error when some repositories were not successfully cloned. Do repo sync on your local mirrors as long as something is happening.

make fails with cannot find -lGL

This error indicates that one particular step in the AOSP setup guide has been left out. A simple sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so ought to fix it.

I ain't got a launcher

I had this with CM. Just restart make and you should be fine.

Sources

Open Questions

  • How do I make a disk image which is reflashable with fastboot?
  • How do I change the specs of the automatically generated VM?

Glossary

ClockworkMod (CWM)

CyanogenMod (CM)

Android Open Source Project (AOSP)

ROM

Stock ROM

Android Debug Bridge (adb)

Fastboot

Recovery

Gingerbread (GB)

Ice Cream Sandwich (ICS)

Launcher

ROM Update Utility (RUU)

Apps 2 SD (A2SD)

#!/bin/bash
set -e
if [ "$#" -le 1 ]; then
echo "Usage: $0 <github name>"
exit 1
fi
GHNAME=$1
shift
NUM_REPOS=$(curl -i https://api.github.com/users/$GHNAME | grep public_repos | grep -Eo '[0-9]+')
if [ ! -f repos_$GHNAME.txt ]; then
for i in $(seq $[$NUM_REPOS / 50 + 1]); do
curl https://api.github.com/users/$GHNAME/repos >> repos_$GHNAME.txt
done
fi
cat repos_$GHNAME.txt | grep clone_url | cut -d\" -f 4 | while read line; do
$@ $line || true
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment