It is assumed you've already setup your build environment and cloned the repositories.
It is advisable to follow the instructions in the order presented.
Putting Your Phone in Development Mode
Before you plug your phone into your USB port, put it USB dev mode.
Under Settings > Applications > Development, turn on USB debugging.
Then, plug it in.
Creating a local copy of the original Android system
The phone ships with numerous binary blobs that B2G requires as well. It is therefore recommended, to create a local copy of the phone's Android system directories:
$ mkdir sgs2-android
$ cd sgs2-android
$ adb pull /system system
$ adb pull /vendor vendor
Backing up the original Android system on the phone
Before you flash B2G onto the phone, it's highly recommended to create a backup of the original Android system on the phone. This is so that you can always go back to Android and retrieve the binary blobs in case you lose your local copy in
ANDROID_FSDIR (that was our
/sgs2-android directory we created in the previous step).
You'll want to back up your phone's factory image before attempting to build or flash anything to it. As it happens, the builds or flash process itself can be unstable and you don't want to end up with a brick.
These instructions assume that you have already installed
From some other directory than where you have B2G or NDK/SDK installed:
$ cd /tmp $ wget http://cmw.22aaf3.com/c1/recovery/recovery-clockwork-18.104.22.168-galaxys2.tar $ tar xvf recovery-clockwork-*tar $ adb reboot download
When your phone is in "download" mode, it's ready to be flashed using Odin protocol.
To Flash Clockworked (and backup image):
With your phone in "download" mode, run the following:
$ heimdall flash --kernel zImage
Next, reboot the phone to recovery mode.
$ adb reboot recovery
With the phone in recovery mode, follow the on-screen instructions to make a backup image. The backup image will be stored on the phone's internal SD card.
Building and flashing the kernel
Do NOT run any of the following commands as root! From the directory to where you've cloned your git repositories:
$ cd B2G
$ make sync
Important: Do not proceed until the
adb pull commands from the previous section have completed. You can run the
make sync command in parallel with
adb pull, but the
make config-galaxy-s2 command below kills the
adb server, which will cause the pulls to abort prematurely.
Next, you will setup your build directory with the binary blobs necessary for building for your device.
ANDROIDFS_DIR should be set to the path you saved the Android system files to above. With your device connected via USB and running:
$ export ANDROIDFS_DIR=sgs2-android
$ make config-galaxy-s2
or for ICS
$ make config-galaxy-s2-ics
Now we can build the kernel:
$ make kernel
Once that's done, reboot the phone into download mode:
$ adb reboot download
Once you see the download screen, flash the kernel with the following command (these instructions assume that you have already installed heimdall).
$ heimdall flash --kernel boot/kernel-android-galaxy-s2/arch/arm/boot/zImage
Building and flashing B2G
Now we can build B2G. When you're building for the first time, you will also have to build the Gonk target (this is not required on subsequent builds):
$ make gonk
Then, you can build and flash B2G in one go, but MAKE SURE YOUR DEVICE IS CONNECTED:
$ make flash
ALTERNATIVELY, if you prefer to do each step on your own:
Once you're done building, reboot the phone into download mode and flash the B2G image onto the phone:
$ adb reboot download
$ make flash-only
Reset your adb
Now is a good time to point adb to the right place. It should be in
The best way is to add that directory (above adb) to your path so makefiles can find it.
Building and flashing the Gaia frontend only
Gaia is part of the B2G image, but it can be updated separately.
Assuming you're in the root of B2G repo, pull files from the remote repo and merge them to your local repo:
$ cd gaia
$ git pull origin master
$ cd ..
Then you can update Gaia on the phone with the following commands:
$ make install-gaia
Building and flashing Gecko only
In case you make changes to Gecko and want to put those on the device, you don't have to go through the entire flash cycle. The following steps will live-update Gecko running on the phone:
$ make install-gecko
$ make kill-b2g
Forcing the Git repo into clean state
Sometimes it's necessary to do this - but cloning a fresh repo and running
make sync takes too much time.
$ make mrproper
Important: This will reset your B2G repository completely. It will appear as if you just checked out. You will lose all local modifications and files not tracked by Git!