Aug 29

I’ve spent the last couple of weeks playing around with Mozilla’s Firefox OS (aka Boot to Gecko or B2G) project as part of my research to prototype an Apache Cordova / Adobe PhoneGap implementation for Firefox OS. I’ll be going through the steps that I had to follow to set up my notebook to build Firefox OS and also the steps required to deploy Firefox OS onto a mobile device.

You should have a solid understanding of using Git and some level of comfort with flashing a mobile device before attempting to build & install Firefox OS. Currently Firefox OS can only be built on Linux or Mac OSX. This article will detail the steps that I used to build Firefox OS on Mac OSX; if you require instructions on how to build on Linux or just want more info you can find it on Mozilla’s Boot to Gecko wiki.

Part 1 – Set Up

First you will need to make sure that you have all the necessary software & tools.

  • XCode 4 & XCode Command Line Tools
  • minimum of 20GB of free hard disk space
  • compatible mobile device (Samsung Nexus S, Samsung Galaxy Nexus, Samsung Galaxy S2) with Ice Cream Sandwich (Android 4.0) installed

If you updated your XCode from version 3 to 4 or if you have a Developer folder in your root directory, you will need to rename the Developer folder otherwise you will run into this issue 777831 when running the Firefox OS bootstrap script.

You will need to run the bootstrap script which will check if you have all of the necessary tools for building Firefox OS.

Open the terminal window and type:

curl -fsSL https://raw.github.com/mozilla-b2g/B2G/master/scripts/bootstrap-mac.sh | bash

There are addition steps required if you plan on building for the Samsung Galaxy S2. I used the Samsung Nexus S as my target mobile device. More details on the additional steps required for the Samsung Galaxy S2 or more info regarding setting up your computer for building Firefox OS can be found here.

Part 2 – Get the Firefox OS code

Next you will need to retrieve the code base from GitHub. If you’re planning to simply build & install Firefox OS you can just clone Mozilla’s repository, but if you’re planning to do some development I would strongly suggest that you fork Mozilla’s repo.

In your terminal window, navigate to the folder where you want to place the Firefox OS code and then type:

git clone https://github.com/mozilla-b2g/B2G.git

Once the code has been completely cloned onto your computer, you will need to navigate into the B2G directory and configure the build for your target device. To configure the build you will need to run the config.sh script and specify the device that you wish to target. In my case I used:

./config.sh nexus-s

The list of device name parameters can be found under the “Configuring B2G for your device section” and additional information on retrieving the code or configuring the Firefox OS emulator can be on the Preparing for your first B2G build page.

Part 3 – Building the code

To build the code you simply type the following command in your terminal window:

./build.sh

Based on my experiences with building Firefox OS, building without any additional parameters to the build script failed every time. If the build fails, you can add the following parameters to help pinpoint where the build process failed.

./build.sh -j1 showcommand

The -j1 parameter tells the build script to use only a single core in your computer’s CPU while the showcommand parameter will display logging of the commands being executed in the terminal window.

A few other things that the #B2G IRC channel suggested:

  • clearing the build cache:
    ccache -C
  • explicitly setting the size of the build cache:
    ccache -M --max-size=20G

    Which is used to set the size of the build cache to 20GB (I ended up setting the –max-size=0 which sets the cache size to unlimited).

Eventually I was able to get a successful build after repeatedly updating my local code repository over the span of 4 days. I also had to use the -j2 parameter on the build script after the repository updates for the build to succeed.

./build.sh -j2

If you are able to successfully build Firefox OS; you should see something like this:

More details on building the code can be found on MDN’s Building Boot to Gecko article.

Part 4 – Installing Firefox OS onto a device

To install your build of Firefox OS onto your device you need to use the flash script.

./flash.sh

If your device gets stuck on screen displayed in the image above; then an error most likely occurred during the flashing process.

You can use the following sequence of commands to get a look at the error log.

./run-gdb.sh

Once you see the (gdb) command prompt, use the continue command.

After using the continue command, you should be returned to the (gdb) command prompt where you can then use the backtrace command to get the output of the log.

With the output of the log, you should be able to get help from the #b2g irc on irc.mozilla.org. The best way to get help is to create a www.pastebin.com of your log output and then link to the pastebin when asking for help on the #b2g irc.

If the flashing is successful, you should see the Firefox OS lock screen on your device.

Additional Resources

All documentation regarding Firefox OS can be found on the MDN’s Firefox OS (Boot 2 Gecko) page.

Leave a Reply