Monday, March 26, 2012

Building Boot2Gecko(B2G) on Ubuntu

Update: This documentation is out-of-date: Please read developer.mozilla.org/en-US/Firefox_OS/Building for latest information

You heard about Mozilla Boot2Gecko(B2G) mobile operating system. Boot2Gecko's Gaia user interface is developed entirely using HTML, CSS and Javascript web technologies. If you are an experienced web developer you can contribute to Gaia UI and develop new Boot2Gecko applications with ease. In this post I'll explain how to setup the Boot2Gecko (B2G) development environment on your personal computer.


You can run Boot2Gecko(B2G) inside an emulator or inside a Firefox web browser. Using Boot2Gecko(B2G) with QEMU emulator is very resource intensive, so we will focus on the later in this post. I'll assume you are comfortable with Mozilla build environment. So, get that pot of coffee brewing and prepare for a long night of hacking.


Building Boot2Gecko(B2G) Firefox App


Before you start, let us make sure that you have all the prerequisites for building Firefox on your computer. Please have a look at the build prerequisites for your Linux, Window and OSX operating system.




# Let get the source code 
# Download mozilla-central repository 

$ hg clone http://hg.mozilla.org/mozilla-central mozilla-central

# Download the Gaia source code 

$ git clone https://github.com/mozilla-b2g/gaia gaia

# Change directory and create our profile 

$ cd gaia 

$ make profile 


# Change directory into your mozilla-central directory

$ cd mozilla-central


# Create a .mozconfig file inside your mozilla-central directory: 

$ nano .mozconfig 
mk_add_options MOZ_OBJDIR=../b2g-build
mk_add_options MOZ_MAKE_FLAGS="-j9 -s"
ac_add_options --enable-application=b2g
ac_add_options --disable-libjpeg-turbo
ac_add_options --enable-b2g-ril
ac_add_options --with-ccache=/usr/bin/ccache 

# Build the Firefox B2G app and wait for the build to finish 

$ make -f client.mk build 


# Create a simple b2g bash script to launch B2G app; change paths you suit your environment
# Note: Have to use to -safe-mode option due to bug on my Ubuntu box 
 
#!/bin/sh 
export B2G_HOMESCREEN=http://homescreen.gaiamobile.org/
/home/arky/src/b2g-build/dist/bin/b2g -profile /home/arky/src/gaia/profile




If everything goes well. You should have boot2gecko running inside a firefox now.


Boot2Gecko running inside firefox on Ubuntu


Customizing Firefox B2G App

For better Boot2Gecko (B2G) experience, we will customize Firefox features offline cache and touch events using a custom Firefox profile.



Create a Custom Firefox Profile


You can use dist/bin/b2g -ProfileManager option to launch Firefox Profile Manager. Create a new profile called 'b2g'. Now we can add customizations to this new profile.


On Linux computers, the profile is created under ~/.mozilla/b2g/ directory. You can find the information about location of firefox profiles for your operating system here.



You launch B2G with your new custom profile using the '-P' option. Modify your B2G bash script and add the custom profile option. dist/bin/b2g -P b2g


Disable offline cache


Create a user.js file inside your custom 'b2g' firefox profile directory. Add the following line to disable offline cache.

user_pref('browser.cache.offline.enable', false);


Enabling Touch events


Add the following line in your user.js file inside your custom 'b2g' Firefox profile directory to enable touch events.

 user_pref('dom.w3c_touch_events.enabled', true);



That's it. You now have a Boot2Gecko(B2G) running inside Firefox on your computer. Happy Hacking!

43 comments:

  1. Hey Arky, building took ~1 hour the first time on ubuntu, but I'm having some issues with the bash script. I cannot find homescreen.html and I've used gaia/apps/homescreen/index.html instead
    Using these, the following errors appear:

    Cannot open socket for RIL!
    SmsDatabaseService: Opened database: sms 1
    SmsDatabaseService: Started transaction [object IDBTransaction] of type readonly
    SmsDatabaseService: Retrieving object store sms
    SmsDatabaseService: Could not get the last key from sms database. Probably empty database
    Could not load libcutils.so. Using fake propdb.
    Could not load libnetutils.so!
    SmsDatabaseService: Transaction [object IDBTransaction] completed.
    ======================= webapi+apps.js =======================
    Segmentation fault

    ReplyDelete
  2. There is no homesccreen.html at all ! what's wrong ?

    ReplyDelete
  3. Remus,

    Try using '-safe-mode' argument, it helped me launch b2g app.

    If you have an empty home. Make sure that the B2G_HOMESCREEN path is correct.

    ReplyDelete
  4. Arky, this is my b2g_launch.sh
    remuspop@p4330:~/Desktop/preferencesRefactor$ cat ~/mozilla/b2g_launch.sh
    #!/bin/sh
    export B2G_HOMESCREEN=file:///home/remuspop/mozilla/gaia/apps/homescreen/index.html
    /home/remuspop/mozilla/b2g-build/dist/bin/b2g -safe-mode

    I hope I'm using the right homescreen and the file I've used has it's path correct.

    Does b2g need to be built in a 64 bit environment? I've built it in a 32 one.

    ReplyDelete
    Replies
    1. I've checked the source of gaia/index.html, and found that

      document.location = 'apps/homescreen/index.html';

      that means, you just need to set B2G_HOMESCREEN=file:///some directory/gaia/index.html;

      but, while I set, there are still some errors as you pasted,

      Arky, could you tell me the reason?

      Or you can download the new source and check what has been changed!

      Delete
  5. Darn! There were some recent changes to homescreen. Trying to figure out the solution to the B2G empty homescreen problem.

    ReplyDelete
  6. Hello Arky, I have an answer for you but it's too long and I can't do a comment longer than 4096 characters on your site :)

    See https://wiki.mozilla.org/Gaia/HackingOffline

    It's just the copy-paste version of my comment for now.

    ReplyDelete
  7. There's a bug: https://bugzilla.mozilla.org/show_bug.cgi?id=739136 related to this Segmentation Fault. The proposed solution works fine. A tcp server listening on port 6200 is needed, so I just lanched netcat before launching the B2G script: nc -l localhost 6200, and worked fine too.

    ReplyDelete
  8. Really greate and impressive post, I really search this type of topic and really appreciate it...thanks
    Regards:
    Gap Infotech Team

    ReplyDelete
  9. Replace this part of the tutorial
    #!/bin/sh
    export B2G_HOMESCREEN=file:///home/arky/src/gaia/index.html
    /home/arky/src/b2g-build/dist/bin/b2g -safe-mode

    With this:
    /home/arky/src/b2g-build/dist/bin/b2g -safe-mode -profile /home/arky/src/gaia/profile
    And it will work

    ReplyDelete
  10. Thank you Alex, _AtilA_ for your valuable contributions.

    Please update your gaia and B2G code and rebuild boot2gecko desktop app to fix these problems.

    ReplyDelete
  11. Hi Arky,

    I am stuck at the homescreen with no clock and unable to slide to unlock.
    here are my script

    sicksand@awalfathi:~$ cat b2g.sh
    #!/bin/sh
    export B2G_HOMESCREEN=file:///home/sicksand/gaia/apps/homescreen/index.html
    /home/sicksand/b2g-build/dist/bin/b2g -safe-mode

    any comment? thanks in advanced

    ReplyDelete
    Replies
    1. Lot of things changed since this blog post was written.

      Tried to update you code and try.

      #!/bin/sh
      export B2G_HOMESCREEN=http://homescreen.gaiamobile.org/
      /home/arky/src/b2g-build/dist/bin/b2g -profile /home/arky/src/gaia/profile

      Delete
  12. hi Arky,

    Thanks for your post.
    In Gaia source there is no "Profile" folder by default. To get that we have to "make" Gaia.
    But while setting preferences xulrunner, xpcshell is giving "not found" error.
    Could you please let me know , what is the reason for that.

    Thanks,
    Praveen.

    ReplyDelete
    Replies
    1. Singapati, Have your tried running 'make profile' inside gaia directory?

      Delete
    2. Hey Arky, I got the same error here. There's actually a ./xulrunner/xpcshell from gaia, but it returns a not found error when I call it directly, I tried to chmod it (777) but nothing changes.

      Delete
    3. Please do file Gaia bug

      https://github.com/andreasgal/gaia/issues

      Delete
  13. Hi Arky! Thank you very much for the tutorial! I'm having some problems on this step:

    make -f client.mk build

    It returns this erros:

    configure: error: /usr/bin/ccache not found
    *** Fix above errors and then restart with "make -f client.mk build"
    make[2]: ** [configure] Erro 1
    make[2]: Saindo do diretório `/home/mateus/mozilla-central'
    make[1]: ** [../b2g-build/Makefile] Erro 2
    make[1]: Saindo do diretório `/home/mateus/mozilla-central'
    make: ** [build] Erro 2

    Do you have any what idea of what might be? I'm not very experient with compiling. :P

    Thanks anyway

    ReplyDelete
    Replies
    1. Do you have ccache program installed on your computer?

      Delete
    2. You were right, that whas the problem! I installed ccache and tried the build again. It took almost 2 hours, but it's not working yet... let's see, what this might be?

      ./b2g.sh: 3: ./b2g.sh: /home/remuspop/mozilla/b2g-build/dist/bin/b2g: not found

      Delete
    3. That doesn't help much. Can you provide more information.

      Delete
    4. This is the only information the terminal returns when I try to execute it :(

      I supose it's something wrong with this path, because I don't have any remuspop folder on my home directory. I do have the b2g-build/dist/bin on my /home/user, but the /b2g it's not in there.

      Delete
    5. Solved here! Thanks for the help. It's running as you said!

      Delete
  14. Now that everything it's working fine, I must ask... Are there different versions of Gaia on currently development? It might be a stupid question, but I couldn't find the gaia link to github you used on the arcticle, so I used this here:
    https://github.com/mozilla-b2g/gaia

    And besides that, I noted that the icons on your screen are diferent from mine (I have squared icons, without border). My friend also built it on his fedora, but his icons are rounded :P .

    ReplyDelete
    Replies
    1. Thank you for testing the B2G Desktop App build instructions.

      Boot2Gecko is a moving target, lot of things change quickly. Please report your gaia bugs here https://github.com/mozilla-b2g/gaia

      Delete
  15. Why not just upload the compiled version?
    Why make things so complicated?
    Compiling for Windows users is something way beyond possibilities of even experienced users.
    Same question about the builds (for Windows) of Firefox with GStreamer support ( https://bugzilla.mozilla.org/show_bug.cgi?id=422540 )
    Mozilla, fuck you.

    ReplyDelete
    Replies
    1. You have a wait some more time for pre-built Boot2Gecko desktop app, until then we have to compile it

      Delete
    2. I've been a long-time Mozilla supporter but also a critic. I think your point has merit Anonymous but your sign off, no matter how much it might make you feel better in the short term (trust me, I know!) isn't helpful in the long term.

      Arky could you explain why B2G binaries are not available yet? Are they perhaps too buggy? I can imagine that when a person is responsible for compiling their own binaries, they will likely get the picture that's it a hit-and-miss affair, especially at this early stage in the project, so there would be an inherent realisation for that compiler that the code is not actually ready for distribution as a compiled binary.

      I noticed though that automated builds of Firefox for Android are now up and running:

      http://armenzg.blogspot.com.au/2012/06/initial-automated-armv6-builds-for.html

      Is it possible that automated builds of B2G will happen soon since Firefox on Android shares a lot with B2G?

      Delete
    3. This blog post is for developers who would like to get early access to Boot2Gecko. I hope if you can build it and contribute patches.

      Only B2G team can shed some light on that. You can drop by #b2g IRC channel and talk to the developers anytime.

      Firefox For Android is now released. You can download Firefox Mobile for android directly from Google Play Store or from Mozilla Mobile sites.

      Delete
  16. Hi Arky!

    I was able to build and run FirefoxOS as a Linux-beginner under Ubuntu :-)

    With this shell-Script from you

    #!/bin/sh
    export B2G_HOMESCREEN=http://homescreen.gaiamobile.org/
    /home/arky/src/b2g-build/dist/bin/b2g -profile /home/arky/src/gaia/profile

    The app-icons are round, and the background is white.
    I hope this is the latest version??

    I cant click on an Icon, only with the right mouse, and then I can delete or move the icons.
    It would be great to start an app!

    Can you help me?
    Thanks, Patrick

    ReplyDelete
    Replies
    1. I am experiencing the same. I wish I could click on the icons and that they would just start working like an app.

      Delete
    2. I can reproduce the problem. Let me try to find a fix for this.

      Delete
  17. I think I got the same problem, "The connection was refused when attempting to contact homescreen.gaiamobile.org ....."

    ReplyDelete
    Replies
    1. Sein,Did you try to set the B2G_HOMESCREEN?

      "export B2G_HOMESCREEN=http://homescreen.gaiamobile.org/"

      Delete
  18. I got the following seg fault when I run B2G emulator. I built on Ubuntu 64-bit VM using https://github.com/mozilla-b2g/B2G. I try to identify where the problem is, some 32-bit libraries I installed (libX11.so, libGL.so, libOSMesa.so, etc), config files, or parameters setting?

    ————————————————————————————————
    ./run-emulator.sh: line 40: 23359 Segmentation fault (core dumped) ${DBG_CMD} $EMULATOR -kernel $KERNEL -sysdir $B2G_HOME/out/target/product/$DEVICE/ -data $B2G_HOME/out/target/product/$DEVICE/userdata.img -memory 512 -partition-size 512 -skindir $B2G_HOME/development/tools/emulator/skins -skin HVGA -verbose -gpu on -qemu $TAIL_ARGS

    ReplyDelete
    Replies
    1. Can you provide a traceback of the segmentation fault? It would help me debug the problem.

      Delete
  19. Hello,

    I am looking into Boot 2 Gecko , a mozilla's new mobile OS for web apps.

    I want to know is there any development kit , or development IDE preferrable ??

    ReplyDelete
  20. Hi I am new for B2G, i am using your article to run the application. I followed the steps properly but then too i am getting black color screen. Please help

    ReplyDelete
    Replies
    1. Sanjana, The B2G development is a moving target. Most of material here has already gone out-of-day.

      The latest and greatest information about B2G is available on https://wiki.mozilla.org/B2g

      Delete
  21. Tried to run the emulator but i get a blue screen which says "Something bad happened, but don't worry a new better error page is coming soon.. see bug 882186. I am not an expert with Linux and developing with it so I would appreciate if i can get some help with this issue.

    ReplyDelete

You can leave a comment here using your Google account, OpenID or as an anonymous user.

Popular Posts