This article provides instructions on how to build B2G OS for Flame devices using a Mac OS X system as your build platform.
Preparing the build environment
The first step is to install build prerequisites as usual. Then install binutils, so that the objdump
command is available for debug builds:
brew install binutils
Create a disk image using the case-sensitive, journaled HFS+ file system and mount the image using the following commands.
hdiutil create -volname 'B2Gos' -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 40g ~/B2Gos.sparseimage open ~/B2Gos.sparseimage cd /Volumes/B2Gos/
Note: Because the image has been created as a "sparse" image, only disk blocks that are actually used take up physical space on your physical media. This means that a 40 gigabyte image, such as the one above, will not actually take up 40 gigabytes of space. Instead, it will gradually get larger as you write more and more data to it.
Clone the B2G repository
Of course, before you can start your first build, you need to clone the B2G repository. It's important to note that this doesn't fetch everything. It simply pulls down the build system and setup utilities. Most of the actual code is in Mozilla's main Mercurial repository; those files will be retrieved later in the setup process.
To clone the repository, use git:
git clone git://github.com/mozilla-b2g/B2G.git
After that's done (which should only take a minute with a fast connection), cd
into the B2G directory:
cd B2G
Configuring B2G for flame
Once you've retrieved the core B2G build system, you need to configure it for the device on which you plan to install it; in this case, that's "flame". Run the following command from within the B2G directory:
./config.sh flame-kk
It's at this point that the majority of the code will be downloaded. This is around 15 GB of source code, so it will take a long time, even if you have a fast Internet connection. Even with high-performance broadband, this can take an hour or so.
Note: Seriously, this will take a very long time if you're on a slow Internet connection. Keep that in mind (as well as any per-megabyte fees you may have to pay on your connection) before doing this step.
Back up important device files
Before beginning the install process, it's important to make a backup of certain key files on the device. These will be needed if you ever need to re-flash the device.
At this point, connect your Flame if it isn't already connected; the configure process will need to access it. Use the adb devices
command to check to see if it's connected:
adb devices -l
This will list any Android or B2G compatible devices that are connected. If yours isn't listed, something's not connected properly.
Once the device is confirmed to be connected, you can make the backup using the following commands:
mkdir flame-backup cd flame-backup adb pull /system system adb pull /data data
To note, if you are building for the first time, you will want to be on the latest version of the flame base image; see https://developer.mozilla.org/en-US/B2G_OS/Phone_guide/Flame/Updating_your_Flame#Full_flash_to_the_latest_base_image for more details.
Working around a Mac OS X build problem
There's a problem that can happen when building on Mac OS X. This is a solution devised by the Mozilla community; it has been tested on Mac OS X 10.9.4 "Mavericks."
Non-existent mkfs.vfat
You need to install a port of dosfstools
so you can use the image.
brew create https://github.com/sv99/dosfstools-osx.git
Then edit the formula brew
will use to build the dosfstools
software:
require "formula"
class Dosfstools < Formula
homepage "https://github.com/sv99/dosfstools-osx"
url "https://github.com/sv99/dosfstools-osx.git"
sha1 ""
def install
system "make", "install"
end
end
Now you're ready to install it:
brew install dosfstools
Changing configuration to work around bugs
There are some build system bugs that prevent building on Mac OS X under certain circumstances. Those circumstances are:
- Bug 1039223 - Build for flame fails complaining of missing dt.img
- Bug 1027682 - [Flame][Build] Failed to build on Mac OS X 10.9, elf.h file not found
Use your favorite text editor to create a file named .userconfig
in the B2G directory. The following content should to into the .userconfig
file:
# .userconfig for Flame build 14.08.2014
# osx repo change
# Bug 1039223 - Build for flame fails complaining of missing dt.img
# https://bugzilla.mozilla.org/show_bug.cgi?id=1039223
pushd device/qcom/common/dtbtool
patch -N << EOF
--- a/dtbtool/dtbtool.c
+++ b/dtbtool/dtbtool.c
@@ -616,7 +616,7 @@ int main(int argc, char **argv)
extract "qcom,msm-id" parameter
*/
while ((dp = readdir(dir)) != NULL) {
- if ((dp->d_type == DT_REG)) {
+ if ((dp->d_type == DT_REG||dp->d_type == DT_UNKNOWN)) {
flen = strlen(dp->d_name);
if ((flen > 4) &&
(strncmp(&dp->d_name[flen-4], ".dtb", 4) == 0)) {
EOF
popd
# Bug 1027682 - [Flame][Build] Failed to build on Mac OS X 10.9, elf.h file not found
# https://bugzilla.mozilla.org/show_bug.cgi?id=1027682
if [[ ! -e /usr/local/include/elf.h ]]; then
cp "${B2G_DIR}/external/elfutils/libelf/elf.h" /usr/local/include
echo "Bug 1027682: elf.h copied into /usr/local/include"
fi
# Disable First Time User experience
export NOFTU=1
echo "NOFTU = ${NOFTU}"
# Enable gaia developer mode
export DEVICE_DEBUG=1
echo "DEVICE_DEBUG = ${DEVICE_DEBUG}"
# Keeping both debug and non-debug objects
#export GECKO_PATH=${B2G_DIR}/mozilla-inbound
echo "GECKO_PATH = ${GECKO_PATH}"
export B2G_DEBUG=1
echo "B2G_DEBUG = ${B2G_DEBUG}"
#export GECKO_OBJDIR=${GECKO_PATH}/objdir-gonk
if [[ "${B2G_DEBUG}" != "0" ]]; then
export GECKO_OBJDIR=${GECKO_OBJDIR}-debug
fi
echo "GECKO_OBJDIR = ${GECKO_OBJDIR}"
Start your first build
Now you're finally ready to build! Just kick it off the way you do for any B2G OS build:
./build.sh