Table of contents
- 1. Putting Your Phone in Development Mode
- 2. Creating a local copy of the original Android system
- 3. Building and flashing the kernel
- 4. Backing up the original Android system on the phone
- 5. Building and flashing B2G
- 6. Forcing the Git repo into clean state
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 /system/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
or for ICS
$ make config-galaxy-s2-ics
cat: sgs2-android/system/build.prop: No such file or directory. Your device has unknown firmware!, check to see if the default adb is in your $PATH, and if so, set it to the gonk adb instead (usually located in
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
or for ICS
$ heimdall flash --kernel boot/kernel-android-galaxy-s2-ics/arch/arm/boot/zImage
If you see an error from libusb: -3, then:
$ sudo heimdall flash --kernel boot/kernel-android-galaxy-s2/arch/arm/boot/zImage
or for ICS
$ sudo heimdall flash --kernel boot/kernel-android-galaxy-s2-ics/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 (that was our
/sgs2-android directory we created in the previous step).
If the phone is switched on and running android, boot the phone into recovery mode with
$ adb reboot recovery
Alternatively, if the phone is switched off, press and hold Power, Home, and Volume Up.
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 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!