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.
Note: There are several models with the name Samsung Galaxy S2. The one that works with these instructions is the GT-i9100. Other variants, including GT-i9100G are not supported (yet) as the hardware is different. See issue 215
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
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
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
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.
Reboot the phone to recovery mode:
$ adb reboot recovery
Then follow the onscreen instructions for making a backup image. The backup image will be stored on the phone's internal SD card.
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!