Hacking b2g on Raspberry Pi
This page is intended for folks who are interested in building and running b2g on Raspberry Pi devices.
Building b2g for RPi
Install the b2g build prerequisites. For the time being, only linux is supported as a build environment. Note that Ubuntu 12.04 is the best-supported development OS. If you're not running Ubuntu 12.04 on your development machine, you can install it as virtual machine and build in there.
A b2g build environment consumes a fair amount of disk space, between 15-20 GB. Please make sure you have enough free space on your development machine (or VM).
To build b2g for your RPi, first download the b2g helper scripts
git clone https://github.com/mozilla-b2g/B2G.git
Next configure b2g for your Raspberry Pi
cd B2G ./config.sh rpi
The config.sh step can take quite a while, because it downloads a large amount of data. Once that finishes, build b2g
./build.sh
This step also takes some time, because it's building an entire operating system. When your build finishes, it's time to flash it onto an SD card for your RPi.
Preparing to flash b2g onto your SD card
Eventually Mozilla will host prebuilt b2g images for the Raspberry Pi. For now, you'll need to build your own image by following the steps above.
Flashing an image requires the following
- an SD card with a capacity of at least 4GB
- a machine with an SD card reader/writer
- a linux host OS on which you have superuser privileges
An Ubuntu 12.04 OS is recommended for building, but any linux distribution is OK for flashing an image. If you're running Ubuntu 12.04 in a VM, that's perfectly fine: you can mirror your build into your host OS and then flash from your host.
If you built b2g in your host OS, you can skip the following instructions.
To mirror your b2g build into your host OS, first find out your guest VM's IP address by running the following command within your guest VM
ifconfig
You'll see a line printed that says something like inet addr:AAA.BBB.CCC.DDD
. That AAA.BBB.CCC.DDD
is your guest VM's IP address.
Next, on your linux host, install sshfs. On ubuntu, use the command
sudo apt-get install sshfs
Other distributions require similar commands. You also need to enable "other users" to access your sshfs mounts. (The other user will be superuser, when you flash your image following the instructions below.) First run the command
sudo gedit /etc/fuse.conf
Then find the line that reads
# user_allow_other
And edit it to
user_allow_other
Save the file by pressing Ctrl-s and then close the editor.
Finally, mount your guest VM's build image by running the following commands
mkdir B2G sshfs $user@$AAA.BBB.CCC.DDD:/home/$user/$B2G B2G -o allow_root
Be sure to replace $user
with your username in your guest VM, and $AAA.BBB.CCC.DDD
with your guest VM's IP address that you found following the instructions above.
To ensure that your build has been mirrored correctly, run the following command in your host OS
ls B2G
You should see listed all the files and directories from your B2G/ directory in your guest VM.
Flashing b2g onto an SD card
You only need to follow these steps once. After your SD card is prepared for the first time, you can update it with new build files without removing it from your RPi. Those partial-update steps are described below.
To flash an SD card with a B2G build for the first time, run the commands below. (If you built in a guest VM, be sure to follow the steps above to mirror your build into your host machine.)
cd $B2G sudo ./flash.sh -f
You have to run the flash.sh command as superuser because it directly writes to your SD card block device. Follow the instructions and prompts presented by flash.sh
to complete the setup process.
When the flashing script finishes, your SD card is ready. Congratulations! Remove it from your host machine, insert it into your Raspberry Pi and start up b2g! :)
Rebuilding b2g and updating your RPi
To update your B2G build directory to the latest sources, run the following commands
cd $B2G ./repo sync ./build.sh
You can sync these files to your RPi using the regular b2g update commands. The commands are
./flash.sh
: update the system and data files./flash.sh system
: update the system files./flash.sh data
: update the data files./flash.sh gecko
: update the b2g runtime./flash.sh gaia
: update the gaia apps and data
You can also flash your SD card anew at any time by following the instructions above. But this should usually not be necessary.