<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Bluish Coder: fxos</title>
 <link href="http://bluishcoder.co.nz/tag/fxos/atom.xml" rel="self"/>
 <link href="http://bluishcoder.co.nz/"/>
 <updated>2018-12-17T08:49:52+13:00</updated>
 <id>http://bluishcoder.co.nz/</id>
 <author>
   <name>Bluishcoder</name>
   <email>admin@bluishcoder.co.nz</email>
 </author>

 
 <entry>
   <title>Update on Tor on Firefox Proof of Concept</title>
   <link href="http://bluishcoder.co.nz/2014/06/13/update-to-tor-on-firefox-proof-of-concept.html"/>
   <updated>2014-06-13T18:00:00+12:00</updated>
   <id>http://bluishcoder.co.nz/2014/06/13/update-to-tor-on-firefox-proof-of-concept</id>
   <content type="html">&lt;p&gt;Yesterday I &lt;a href=&quot;http://bluishcoder.co.nz/2014/06/12/using-tor-with-firefox-os.html&quot;&gt;wrote about Tor on Firefox OS&lt;/a&gt;. Further testing showed an issue when switching networks - a common thing to happen when carrying a mobile device. The &lt;code&gt;iptables&lt;/code&gt; rule I was using didn&#39;t exclude the &lt;code&gt;tor&lt;/code&gt; process itself from having traffic redirected. When a network switch occurred &lt;code&gt;tor&lt;/code&gt; would attempt to reestablish connections and this would fail.&lt;/p&gt;

&lt;p&gt;A fix for this is to exclude &lt;code&gt;tor&lt;/code&gt; from the &lt;code&gt;iptables&lt;/code&gt; rules or to use rules for specific processes only. The processes that belong to an Firefox OS application be be viewed with &lt;code&gt;b2g-ps&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;APPLICATION    SEC USER     PID   PPID  VSIZE  RSS     NAME
b2g              0 root      181   1     494584 135544 /system/b2g/b2g
(Nuwa)           0 root      830   181   55052  20420  /system/b2g/plugin-container
Built-in Keyboa  2 u0_a912   912   830   67660  26048  /system/b2g/plugin-container
Vertical         2 u0_a1088  1088  830   103336 34428  /system/b2g/plugin-container
Usage            2 u0_a4478  4478  830   65544  23584  /system/b2g/plugin-container
Browser          2 u0_a26328 26328 830   75680  21164  /system/b2g/plugin-container
Settings         2 u0_a27897 27897 830   79840  28044  /system/b2g/plugin-container
(Preallocated a  2 u0_a28176 28176 830   62316  18556  /system/b2g/plugin-container
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Unfortunately the &lt;code&gt;iptables&lt;/code&gt; that ships with Firefox OS doesn&#39;t seem to support the &lt;code&gt;--pid-owner&lt;/code&gt; option for rule selection so I can&#39;t select specifically the &lt;code&gt;tor&lt;/code&gt; or application processes. I can however select based on &lt;code&gt;user&lt;/code&gt; or &lt;code&gt;group&lt;/code&gt;. Each application gets their own &lt;code&gt;user&lt;/code&gt; so the option to redirect traffic for applications can use that. I wasn&#39;t able to get this working reliably though so I switched to targeting the &lt;code&gt;tor&lt;/code&gt; process itself.&lt;/p&gt;

&lt;p&gt;In my writeup I ran &lt;code&gt;tor&lt;/code&gt; as root. I need to run as a different user so that I can use &lt;code&gt;--uid-owner&lt;/code&gt; on &lt;code&gt;iptables&lt;/code&gt;. Firefox OS inherits the Android method of users and groups where specific users are hardcoded into the system. Since this is a proof of concept and I want to get things working quickly I decided to pick an existing user, &lt;code&gt;system&lt;/code&gt;, and run &lt;code&gt;tor&lt;/code&gt; as that. By setting the &lt;code&gt;User&lt;/code&gt; option in the Tor configuration file I can have Tor switch to that user at run time. Nothing is ever that easy though as  user does not have permission to do the many things that &lt;code&gt;tor&lt;/code&gt; requires. It can&#39;t create sockets for example.&lt;/p&gt;

&lt;p&gt;Enter &lt;a href=&quot;https://www.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.2/capfaq-0.2.txt&quot;&gt;Linux capabilities&lt;/a&gt;. It is possible to grant a process certain capabilities which give it the right to perform priviledged actions without being a superuser. There is an existing &lt;a href=&quot;https://trac.torproject.org/projects/tor/ticket/8195&quot;&gt;Tor trac ticket&lt;/a&gt; about this and I used the &lt;a href=&quot;https://trac.torproject.org/projects/tor/attachment/ticket/8195/captest.c&quot;&gt;sample code in that ticket&lt;/a&gt; to modify &lt;code&gt;tor&lt;/code&gt; to keep the required capabilities when it switches user, I put the code I cobbled together to patch &lt;code&gt;tor&lt;/code&gt; in &lt;a href=&quot;http://bluishcoder.co.nz/b2g/tor.patch&quot;&gt;tor.patch&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To use this change the &lt;code&gt;Building tor&lt;/code&gt; section of my &lt;a href=&quot;http://bluishcoder.co.nz/2014/06/12/using-tor-with-firefox-os.html&quot;&gt;original post&lt;/a&gt; to use these commands:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cd $HOME/build
$ wget https://www.torproject.org/dist/tor-0.2.4.22.tar.gz
$ cd tor-0.2.4.22
$ curl http://bluishcoder.co.nz/b2g/tor.patch | patch -p1
$ ./configure --host=arm-linux-androideabi \
              --prefix=$HOME/build/install \
              --enable-static-libevent
$ make
$ make install
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Change the Tor configuration file to switch the user to &lt;code&gt;system&lt;/code&gt; in the &lt;code&gt;Packaging Tor for the device&lt;/code&gt; section:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;DataDirectory /data/local/tor/tmp 
SOCKSPort 127.0.0.1:9050 IsolateDestAddr
SOCKSPort 127.0.0.1:9063
RunAsDaemon 1
Log notice file /data/local/tor/tmp/tor.log
VirtualAddrNetwork 10.192.0.0/10
AutomapHostsOnResolve 1
TransPort 9040
DNSPort 9053
User system
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I&#39;ve also changed the location of the data files to be in a &lt;code&gt;tmp&lt;/code&gt; directory which needs to be given the &lt;code&gt;system&lt;/code&gt; user owner. Change the steps in &lt;code&gt;Running tor&lt;/code&gt; to:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ adb shell
# cd /data/local/tor
# mkdir tmp
# chown system:system tmp
# ./tor -f torrc &amp;amp;
# iptables -t nat -A OUTPUT ! -o lo
            -m owner ! --uid-owner system \
            -p udp --dport 53 -j REDIRECT --to-ports 9053 
# iptables -t nat -A OUTPUT ! -o lo \
           -m owner ! --uid-owner system \
            -p tcp -j REDIRECT --to-ports 9040
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now tor should work in the presence of network switching. I&#39;ve updated the &lt;a href=&quot;http://bluishcoder.co.nz/b2g/b2g_tor.tar.gz&quot;&gt;b2g_tor.tar.gz&lt;/a&gt; to include the new &lt;code&gt;tor&lt;/code&gt; binary, the updated configuration file, and a couple of shell scripts that will run the &lt;code&gt;iptables&lt;/code&gt; commands to redirect traffic to &lt;code&gt;tor&lt;/code&gt; and to cancel the redirection.&lt;/p&gt;

&lt;p&gt;As before the standard disclaimer applies:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;All files and modifications described and provided here are at your own risk. This is a proof of concept. Don&#39;t tinker on devices you depend on and don&#39;t want to risk losing data. These changes are not an official Mozilla project and do not represent any future plans for Mozilla projects.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;This is probably as far as I&#39;ll take things for now with this proof of concept and see what happens from here after using it for a while.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Using Tor with Firefox OS</title>
   <link href="http://bluishcoder.co.nz/2014/06/12/using-tor-with-firefox-os.html"/>
   <updated>2014-06-12T18:00:00+12:00</updated>
   <id>http://bluishcoder.co.nz/2014/06/12/using-tor-with-firefox-os</id>
   <content type="html">&lt;p&gt;&lt;em&gt;Update&lt;/em&gt; - Please read my &lt;a href=&quot;http://bluishcoder.co.nz/2014/06/13/update-to-tor-on-firefox-proof-of-concept.html&quot;&gt;followup post&lt;/a&gt; for some additional information and updated steps on building and installing &lt;code&gt;tor&lt;/code&gt; on Firefox OS.&lt;/p&gt;

&lt;p&gt;Please read the disclaimer at the end of this article. This is a proof of concept. It&#39;s a manual process and you shouldn&#39;t depend on it. Make sure you understand what you are doing.&lt;/p&gt;

&lt;p&gt;I&#39;m a fan of &lt;a href=&quot;https://www.torproject.org/&quot;&gt;Tor&lt;/a&gt;. The Tor site explains what it does:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Tor is free software and an open network that helps you defend against traffic analysis, a form of network surveillance that threatens personal freedom and privacy, confidential business activities and relationships, and state security.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I make my personal website available as a Tor hidden service accessible from &lt;a href=&quot;http://mh7mkfvezts5j6yu.onion/&quot;&gt;mh7mkfvezts5j6yu.onion&lt;/a&gt;. I try to make other sites I&#39;m involved with also have a presence over Tor. I do a fair amount of my browsing over the Tor network for no reason other than I can and it limits the opportunity for people snooping on my data.&lt;/p&gt;

&lt;p&gt;I want to be able to use Tor from Firefox OS. In particular I want it embedded as low level as possible so I have the option of all traffic going over Tor. I don&#39;t want to have to configure socks proxies.&lt;/p&gt;

&lt;p&gt;Firefox OS doesn&#39;t allow native applications. The low level underlying system however is based on Linux and Android and can run native binaries. Starting with a rooted Firefox OS install I built Tor and used &lt;code&gt;iptables&lt;/code&gt; to reroute all network traffic to work over it. This is a first step and is what this article demonstrates how to get going so power users can try it out. My next step would be to investigate integrating it into the build system of Firefox OS and providing ways to start/stop it from the OS interface.&lt;/p&gt;

&lt;p&gt;The first stage of building is to have an &lt;a href=&quot;http://www.kandroid.org/ndk/docs/STANDALONE-TOOLCHAIN.html&quot;&gt;Android standalone toolchain&lt;/a&gt; installed. I describe how to do this in my &lt;a href=&quot;http://bluishcoder.co.nz/2013/05/09/building-wasp-lisp-and-mosref-for-android.html&quot;&gt;Wasp Lisp on Android&lt;/a&gt; post or you can use &lt;a href=&quot;http://bluishcoder.co.nz/nixos/standalone-ndk/default.nix&quot;&gt;a Nix package&lt;/a&gt; I created for use with the &lt;a href=&quot;http://nixos.org/nix&quot;&gt;Nix package manager&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Building libevent&lt;/h2&gt;

&lt;p&gt;Tor requires &lt;a href=&quot;http://libevent.org/&quot;&gt;libevent&lt;/a&gt; to build. I&#39;m using static libraries to make creating a standalone &lt;code&gt;tor&lt;/code&gt; binary easier. The following will build &lt;code&gt;libevent&lt;/code&gt; given the standalone toolchain on your path:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cd $HOME
$ mkdir build
$ cd build
$ wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
$ tar xvf libevent-2.0.21-stable.tar.gz
$ cd libevent-2.0.21-stable
$ ./configure --host=arm-linux-androideabi \
              --prefix=$HOME/build/install \
              --enable-static --disable-shared
$ make
$ make install
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Building zlib&lt;/h2&gt;

&lt;p&gt;Tor requires &lt;a href=&quot;http://www.openssl.org/&quot;&gt;openssl&lt;/a&gt; which in turn requires &lt;a href=&quot;http://zlib.net/&quot;&gt;zlib&lt;/a&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cd $HOME/build
$ wget http://zlib.net/zlib-1.2.8.tar.gz
$ tar xvf zlib-1.2.8.tar.gz
$ cd zlib-1.2.8
$ CC=arm-linux-androideabi-gcc ./configure --prefix=$HOME/build/install --static
$ make
$ make install
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Building openssl&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;$ cd $HOME/build
$ wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz
$ tar xvf openssl-1.0.1h.tar.gz
$ cd openssl-1.0.1h
$ CC=arm-linux-androideabi-gcc ./Configure android no-shared --prefix=$HOME/build/install
$ make
$ make install
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Building tor&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;$ cd $HOME/build
$ wget https://www.torproject.org/dist/tor-0.2.4.22.tar.gz
$ cd tor-0.2.4.22
$ ./configure --host=arm-linux-androideabi \
              --prefix=$HOME/build/install \
              --enable-static-libevent
$ make
$ make install
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Packaging Tor for the device&lt;/h2&gt;

&lt;p&gt;To run on the Firefox OS device I just installed the &lt;code&gt;tor&lt;/code&gt; binary and a configuration file that enables transaparent proxing as per the &lt;a href=&quot;https://trac.torproject.org/projects/tor/wiki/doc/TransparentProxy&quot;&gt;Tor documentation&lt;/a&gt; on the subject. I put these in a directory that I push to an easily accessible place on the device:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ mkdir $HOME/build/device
$ cd $HOME/build/device
$ cp $HOME/build/install/bin/tor .
$ cat &amp;gt;torrc
  ...contents of configuration file...
$ adb push $HOME/build/device /data/local/tor
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The configuration file is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;DataDirectory /data/local/tor
Log notice file /data/local/tor/tor.log
RunAsDaemon 1
SOCKSPort 127.0.0.1:9050 IsolateDestAddr
SOCKSPort 127.0.0.1:9063
VirtualAddrNetwork 10.192.0.0/10
AutomapHostsOnResolve 1
TransPort 9040
DNSPort 9053
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Running tor&lt;/h2&gt;

&lt;p&gt;I haven&#39;t integrated &lt;code&gt;tor&lt;/code&gt; into the device at all so for this proof of concept I &lt;code&gt;adb shell&lt;/code&gt; into it to run it and configure the &lt;code&gt;iptables&lt;/code&gt; to redirect traffic:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ adb shell
# cd /data/local/tor
# ./tor -f torrc &amp;amp;
# iptables -t nat -A OUTPUT ! -o lo -p udp --dport 53 -j REDIRECT --to-ports 9053 
# iptables -t nat -A OUTPUT ! -o lo -p tcp -j REDIRECT --to-ports 9040
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Testing&lt;/h2&gt;

&lt;p&gt;The device should now be sending traffic over Tor. You can test by visiting sites like &lt;a href=&quot;http://whatismyip.com&quot;&gt;whatismyip.com&lt;/a&gt; or &lt;a href=&quot;http://icanhazip.com&quot;&gt;icanhazip.com&lt;/a&gt; to see if it reports a different IP address and location to what you normally have. You can also try out hidden services like &lt;a href=&quot;http://mh7mkfvezts5j6yu.onion/&quot;&gt;mh7mkfvezts5j6yu.onion&lt;/a&gt; which should show this site.&lt;/p&gt;

&lt;h2&gt;Removing&lt;/h2&gt;

&lt;p&gt;Killing the Tor process and removing the &lt;code&gt;iptables&lt;/code&gt; entries will set the network back to normal:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ adb shell ps|grep tor
$ adb shell
# kill ...process id of tor...
# iptables -t nat -F
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can optionally delete the &lt;code&gt;/data/local/tor&lt;/code&gt; directory to remove all tor files:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ adb shell rm -r /data/local/tor
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Future&lt;/h2&gt;

&lt;p&gt;This is just a proof of concept. Don&#39;t depend on this. You need to restart Tor and the &lt;code&gt;iptables&lt;/code&gt; commands on reboot. I&#39;m not sure how well interaction with switching to/from WiFi and GSM works. Ideally Tor would be integrated with Firefox OS so that you can start and stop it as a service and maybe whitelist or blacklist sites that should and shouldn&#39;t use Tor. I hope to do some of this over time or hope someone else gets excited enough to work on it too.&lt;/p&gt;

&lt;p&gt;Another privacy aspect I&#39;d like to investigate is whether TextSecure (or a similar service) could be &lt;a href=&quot;http://threatpost.com/inside-the-textsecure-cyanogenmod-integration&quot;&gt;integrated in the way it&#39;s done in CyanogenMod&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;&quot;The result is a system where a CyanogenMod user can choose to use any SMS app they&#39;d like, and their communication with other CyanogenMod or TextSecure users will be transparently encrypted end-to-end over the data channel without requiring them to modify their work flow at all.&quot;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt; Ideally my end goal would be to have something close to that described in the &lt;a href=&quot;https://blog.torproject.org/blog/mission-impossible-hardening-android-security-and-privacy&quot;&gt;hardening Android post&lt;/a&gt; on the Tor Project blog.&lt;/p&gt;

&lt;p&gt;I&#39;m not sure how possible that is though. But Firefox OS is open source, easy to build and hack on, and runs on a lot of devices, including &lt;a href=&quot;http://bluishcoder.co.nz/2014/06/11/dual-booting-android-and-firefox-os.html&quot;&gt;multi booting on some&lt;/a&gt;. Adding things like this to build your own custom phone OS that runs web applications is one of the great things the project enables. Users should feel like they can dive in and try things rather than wait for an OS release to support it (in my opinion of course).&lt;/p&gt;

&lt;h2&gt;Test Builds&lt;/h2&gt;

&lt;p&gt;A tar file containing a precompiled &lt;code&gt;tor&lt;/code&gt; and the &lt;code&gt;torrc&lt;/code&gt; is available at &lt;a href=&quot;http://bluishcoder.co.nz/b2g/b2g_tor.tar.gz&quot;&gt;b2g_tor.tar.gz&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Disclaimer&lt;/h2&gt;

&lt;p&gt;All files and modifications described and provided here are at your own risk. Don&#39;t tinker on devices you depend on and don&#39;t want to risk losing data. These changes are not an official Mozilla project and do not represent any future plans for Mozilla projects.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Dual Booting Android and Firefox OS on the Nexus 5</title>
   <link href="http://bluishcoder.co.nz/2014/06/11/dual-booting-android-and-firefox-os.html"/>
   <updated>2014-06-11T18:00:00+12:00</updated>
   <id>http://bluishcoder.co.nz/2014/06/11/dual-booting-android-and-firefox-os</id>
   <content type="html">&lt;p&gt;I&#39;ve gone through periods of using a &lt;a href=&quot;http://www.mozilla.org/en-US/firefox/os/&quot;&gt;Firefox OS&lt;/a&gt; phone as my main device but I&#39;ve usually fallen back to Android due to needing to use some Android only programs and I don&#39;t like carrying two phones around. Today I decided to investigate how to get dual boot Android with custom Firefox OS builds. Thankfully it was actually pretty easy.&lt;/p&gt;

&lt;p&gt;The boot manager I used to get this to work is &lt;a href=&quot;https://play.google.com/store/apps/details?id=com.tassadar.multirommgr&quot;&gt;MultiROM Manager&lt;/a&gt;, available from the Play store for rooted phones. The source is for MultiROM Manager is &lt;a href=&quot;https://github.com/Tasssadar/multirom/&quot;&gt;available on github&lt;/a&gt;. The phone I used was the Nexus 5. The instructions here assume you are familiar with &lt;code&gt;adb&lt;/code&gt; and &lt;code&gt;fastboot&lt;/code&gt; already.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Be aware that all these changes may lose the data you have on the device if you haven&#39;t already unlocked the boot loader and rooted the device.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;Make a backup of your Android settings and applications&lt;/h2&gt;

&lt;p&gt;With the device plugged in and visible from &lt;code&gt;adb&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ adb backup -apk -shared -all
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This can be restored later if needed with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ adb restore backup.ab
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Unlock the bootloader&lt;/h2&gt;

&lt;p&gt;The Nexus 5, and other Google devices, make it easy to unlock the bootloader. With the device plugged in and visible from &lt;code&gt;adb&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ adb reboot bootloader
$ fastboot oem unlock
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Follow the screen instructions. This will erase everything on the device!&lt;/p&gt;

&lt;h2&gt;Rooting the Nexus 5&lt;/h2&gt;

&lt;p&gt;I used &lt;a href=&quot;http://cfautoroot.com/&quot;&gt;CF-Auto-Root&lt;/a&gt;. I downloaded the &lt;a href=&quot;http://www.devfiles.co/download/dEHWyjmo/CF-Auto-Root-hammerhead-hammerhead-nexus5.zip&quot;&gt;version for the Nexus 5&lt;/a&gt; and used &lt;code&gt;fastboot&lt;/code&gt; to boot the image inside of it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ unzip CF-Auto-Root-hammerhead-hammerhead-nexus5.zip
$ fastboot boot image/CF-Auto-Root-hammerhead-hammerhead-nexus5.img
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The device will reboot and perform the steps necessary to root it.&lt;/p&gt;

&lt;h2&gt;Install MultiROM Manager&lt;/h2&gt;

&lt;p&gt;Install &lt;a href=&quot;https://play.google.com/store/apps/details?id=com.tassadar.multirommgr&quot;&gt;MultiROM Manager&lt;/a&gt; from the Play store. Run the app and choose &lt;code&gt;Install&lt;/code&gt; after ticking the &lt;code&gt;MultiROM&lt;/code&gt;, &lt;code&gt;Recovery&lt;/code&gt; and &lt;code&gt;Kernel&lt;/code&gt; check boxes. Follow the onscreen instructions.&lt;/p&gt;

&lt;h2&gt;Build Firefox OS&lt;/h2&gt;

&lt;p&gt;The Mozilla Developer Network has &lt;a href=&quot;https://developer.mozilla.org/en-US/Firefox_OS/Building_and_installing_Firefox_OS&quot;&gt;instructions for building Firefox OS&lt;/a&gt;. Assuming all the pre-requisites are installed the steps are:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ git clone git://github.com/mozilla-b2g/B2G b2g
$ cd b2g
$ ./config.sh nexus-5
$ PRODUCTION=1 MOZILLA_OFFICIAL=1 ./build.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Don&#39;t flash the device from here. We&#39;ll create a MultiROM compatible ROM file to boot from.&lt;/p&gt;

&lt;h2&gt;Create Firefox OS ROM file&lt;/h2&gt;

&lt;p&gt;Create a directory to hold the ROM contents and copy the results of the build into it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ mkdir rom
$ cd rom
$ rsync -rL ../out/target/product/hammerhead/system .
$ rsync -rL ../out/target/product/hammerhead/data .
$ cp ../out/target/product/hammerhead/boot.img .
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For the &lt;code&gt;rsync&lt;/code&gt; copy I deliberately choose not to copy symbolic links and to instead re-copy the original file. I had difficulty getting symbolic links working and need to investigate.&lt;/p&gt;

&lt;p&gt;An Android ROM requires a &lt;code&gt;META-INF&lt;/code&gt; directory containing a script that performs the update process. The following commands create this directory, copy the binary to run the script and the script itself:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ mkdir -p META-INF/com/google/android/
$ cp ../tools/update-tools/bin/gonk/update-binary META-INF/com/google/android/
$ curl http://bluishcoder.co.nz/b2g/updater-script &amp;gt;META-INF/com/google/android/updater-script
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The updater script is one I wrote based on existing ones. It&#39;s pretty easy to follow if you want to read and change it.&lt;/p&gt;

&lt;p&gt;The final step is to ZIP the directories, sign them and push to a directory on the device:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ zip -r9 b2g.zip *
$ java -jar ../prebuilts/sdk/tools/lib/signapk.jar \
            ../build/target/product/security/testkey.x509.pem \
            ../build/target/product/security/testkey.pk8 \
             b2g.zip signed_b2g.zip
$ adb push signed_b2g.zip /sdcard/
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Install Firefox OS ROM&lt;/h2&gt;

&lt;p&gt;Boot into recovery mode by pressing volume down and the power on button at the same time  (or run &lt;code&gt;adb reboot recovery&lt;/code&gt;). From the recovery menu choose &#39;Advanced&#39; followed by &#39;MultiROM&#39;, then &lt;code&gt;Add ROM&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Make sure &lt;code&gt;Android&lt;/code&gt; is selected and &lt;code&gt;Don&#39;t Share&lt;/code&gt; is chosen for &quot;Share Kernel with Internal ROM&quot;. Click &lt;code&gt;Next&lt;/code&gt;, choose &lt;code&gt;Zip file&lt;/code&gt; and select the file we created in the signing step previously. Swipe to confirm as requested.&lt;/p&gt;

&lt;p&gt;If this succeeds, Reboot and touch the screen during the &#39;Auto boot&#39; display to get the list of ROMS to run. Choosing the one we just installed should boot Firefox OS.&lt;/p&gt;

&lt;h2&gt;Other ROMs&lt;/h2&gt;

&lt;p&gt;With MultiROM you can install other ROMS and even &lt;a href=&quot;http://www.ubuntu.com/phone&quot;&gt;Ubuntu Touch&lt;/a&gt;. I&#39;d like to get &lt;a href=&quot;http://bluishcoder.co.nz/2012/06/11/building-inferno-os-for-android-phones.html&quot;&gt;Inferno OS&lt;/a&gt; running under MultiROM as well so I can boot between all the operating systems I like to tinker with on one device.&lt;/p&gt;

&lt;h2&gt;Try it&lt;/h2&gt;

&lt;p&gt;I&#39;ve placed a complete Firefox OS ROM for use with MultiROM on the Nexus 5 in &lt;a href=&quot;https://mega.co.nz/#!OFwDDY7B!EqofLz_EGDN3yjz5AaotSQW5PfnZ8CP4VvcdlWOVkQA&quot;&gt;b2g_nexus5.zip&lt;/a&gt;. This was built from B2G &lt;code&gt;master&lt;/code&gt; branch so may be broken in various aspects (The camera doesn&#39;t work for example) but will allow you to try the multi boot process out if you can&#39;t do builds. This is not an official Mozilla build and was generated by me personally. Use at your own risk.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Running Firefox OS on Nexus S</title>
   <link href="http://bluishcoder.co.nz/2013/04/22/running-firefox-os-on-nexus-s.html"/>
   <updated>2013-04-22T20:00:00+12:00</updated>
   <id>http://bluishcoder.co.nz/2013/04/22/running-firefox-os-on-nexus-s</id>
   <content type="html">&lt;p&gt;Update: 2013-05-07: Minor changes to deal with new and rebased patches.&lt;/p&gt;

&lt;p&gt;Last year I posted about how to &lt;a href=&quot;http://bluishcoder.co.nz/2012/03/20/building-and-running-b2g-on-nexus-s.html&quot;&gt;build and run B2G on the Nexus S&lt;/a&gt;. Much has changed since then and this post attempts to provide up to date instructions on building Firefox OS and installing the latest &lt;a href=&quot;https://wiki.mozilla.org/Gaia&quot;&gt;Gaia&lt;/a&gt; version.&lt;/p&gt;

&lt;p&gt;I wrote &#39;attempts&#39; because the support for the Nexus S bitrots frequently due to (I assume) most development effort going towards developer devices and devices that intend to be shipped. These instructions worked for me on my Nexus S and gives me a phone that can use Wifi, make calls, use 3G data, take photo&#39;s, record video and install applications.&lt;/p&gt;

&lt;h2&gt;Getting the source&lt;/h2&gt;

&lt;p&gt;The main source repository is on github, &lt;a href=&quot;https://github.com/mozilla-b2g/b2g&quot;&gt;https://github.com/mozilla-b2g/b2g&lt;/a&gt;. The first step is to clone this repository. I clone this into a directory called &lt;code&gt;nexus-s&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ git clone git://github.com/mozilla-b2g/B2G nexus-s
$ cd nexus-s
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Create a file in this directory called &lt;code&gt;.userconfig&lt;/code&gt; containing the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;export CC=gcc-4.6
export CXX=g++-4.6
export HIDPI=1
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The first two entries are required if you are building on Ubuntu 12.10 to use gcc version 4.6, which you must install. B2G does not build using gcc version 4.7.&lt;/p&gt;

&lt;p&gt;The last entry, &lt;code&gt;HIDPI&lt;/code&gt;, results in applications using the correct resources for the screen size on the Nexus S. Without this many things will be scaled incorrectly.&lt;/p&gt;

&lt;h2&gt;Configuring&lt;/h2&gt;

&lt;p&gt;Once the source is obtained you need to pull down the sub-repositories required for the Nexus S. This step downloads multiple gigabytes of data and can take a long time:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nexus-s$ BRANCH=v1-train ./config.sh nexus-s
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note the use of the &lt;code&gt;BRANCH&lt;/code&gt; environment variable. This configures our build to use the relatively stable &lt;code&gt;v1-train&lt;/code&gt; branch. This branch gets regular updates but tends to be better tested than &lt;code&gt;master&lt;/code&gt; which is often broken for not-quite-supported devices like the Nexus S.&lt;/p&gt;

&lt;p&gt;Although we are using the &lt;code&gt;v1-train&lt;/code&gt; we are going to use the &lt;code&gt;master&lt;/code&gt; branch of Gaia so we get the latest and greatest user interface. We&#39;ll change to this later.&lt;/p&gt;

&lt;h2&gt;Gecko changes&lt;/h2&gt;

&lt;p&gt;The branch of Gecko that &lt;code&gt;v1-train&lt;/code&gt; uses has some bugs on the Nexus S. To fix this we need to apply some patches. The first is &lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=832653&quot;&gt;bug 832653&lt;/a&gt;, video playback broken on Nexus S. The patches relevant to Gecko from this bug that need to be applied are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://bugzilla.mozilla.org/attachment.cgi?id=734988&quot;&gt;Fix graphic buffer crash&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The following set of commands downloads these patches and applies them in a branch of the Gecko tree that the &lt;code&gt;config.sh&lt;/code&gt; step previously obtained:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nexus-s       $ cd gecko
nexus-s/gecko $ git checkout -b nexus-s m/v1-train
nexus-s/gecko $ curl -k -L https://bug832653.bugzilla.mozilla.org/attachment.cgi?id=734988 &amp;gt;p1.patch
nexus-s/gecko $ patch -p1 &amp;lt;p1.patch
nexus-s/gecko $ git commit -a -m &quot;Nexus S patches&quot;
nexus-s/gecko $ cd ..
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Gonk changes&lt;/h2&gt;

&lt;p&gt;Part of &lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=832653&quot;&gt;bug 832653&lt;/a&gt; makes a change to the low level Gonk layer of B2G. This is in the libstagefright video decoding libraries. The change is to prevent output buffer starvation which results in video decoding stopping after a few frames. The required patch is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://bugzilla.mozilla.org/attachment.cgi?id=735002&quot;&gt;Fix output buffer starvation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;To apply this patch:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nexus-s                 $ cd frameworks/base
nexus-s/frameworks/base $ git checkout -b nexus-s 
nexus-s/frameworks/base $ curl -k -L https://bugzilla.mozilla.org/attachment.cgi?id=735002 &amp;gt;p1.patch
nexus-s/frameworks/base $ patch -p1 &amp;lt;p1.patch
nexus-s/frameworks/base $ git commit -a -m &quot;Nexus S patches&quot;
nexus-s/frameworks/base $ cd ../..
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Gaia changes&lt;/h2&gt;

&lt;p&gt;There are Gaia changes required as part of &lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=869289&quot;&gt;bug 869289&lt;/a&gt; as well. This change prevents the error where videos are not listed if the thumbnail cannot be generated:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://bug869289.bugzilla.mozilla.org/attachment.cgi?id=746196&quot;&gt;List videos even if thumbnail generation fails&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;We also want to be on the Gaia &lt;code&gt;master&lt;/code&gt; branch to get the latest and greatest code. The following comands switch to this branch and apply our patch:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nexus-s      $ cd gaia
nexus-s/gaia $ git checkout -b nexus-s mozillaorg/master
nexus-s/gaia $ curl -k -L https://bug869289.bugzilla.mozilla.org/attachment.cgi?id=746196 &amp;gt;p1.patch
nexus-s/gaia $ patch -p1 &amp;lt;p1.patch
nexus-s/gaia $ git commit -a -m &quot;Nexus S video app thumbnail fix&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There is a bug related to video recording on the Nexus S. To fix this we need a patch from &lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=832638&quot;&gt;bug 832638&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://bugzilla.mozilla.org/attachment.cgi?id=704241&quot;&gt;Set video recording profile in camera app&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;To apply this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nexus-s/gaia $ curl -k -L https://bugzilla.mozilla.org/attachment.cgi?id=704241 &amp;gt;p2.patch
nexus-s/gaia $ patch -p1 &amp;lt;p2.patch
nexus-s/gaia $ git commit -a -m &quot;Nexus S video recording fix&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Building&lt;/h2&gt;

&lt;p&gt;Now that all the required changes have been made we can build:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nexus-s $ ./build.sh 
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Installing&lt;/h2&gt;

&lt;p&gt;Once the build is complete you should be able to flash the Nexus S with the results. Note that this completely wipes everything on your phone:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nexus-s $ ./flash.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The phone should reboot after this step with Firefox OS installed and prompting for information from the &quot;First Run&quot; app.&lt;/p&gt;

&lt;h2&gt;New Zealand changes&lt;/h2&gt;

&lt;p&gt;Some New Zealand sites don&#39;t detect Firefox OS and serve their mobile versions. This can be changed by adding overrides to &lt;code&gt;gaia/build/ua-override-prefs.js&lt;/code&gt;. I add the entries in &lt;a href=&quot;http://cd.pn/b2gnzuaoverride.txt&quot;&gt;b2gnzuaoverride.txt&lt;/a&gt; to this file to get stuff.co.nz, mega.co.nz and trademe.co.nz serving the correct mobile site. Once added to this file, reinstall Gaia on the phone.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nexus-s $ ./flash.sh gaia
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Updating&lt;/h2&gt;

&lt;p&gt;To update the source to latest versions we need to &#39;rebase&#39; our changes on top of the most recent repository changes. The following steps will do this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nexus-s $ git pull
nexus-s $ ./config.sh nexus-s
nexus-s $ cd gecko
nexus-s/gecko $ git rebase m/v1-train
nexus-s/gecko $ cd ../gaia
nexus-s/gaia  $ git rebase mozillaorg/master
nexus-s/gaia  $ cd ..
nexus-s $ ./build.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You may need to do some fixing up of merge conflicts if changes have occurred to the areas we&#39;ve patched.&lt;/p&gt;

&lt;p&gt;To flash the phone, overwriting everything on it, including all user data:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nexus-s $ ./flash.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To flash the phone, keeping (most of...) your existing user data:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nexus-s $ ./flash.sh system
nexus-s $ ./flash.sh gecko
nexus-s $ ./flash.sh gaia
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that flashing gaia might remove some of your installed application icons. You&#39;ll need to reinstall those apps to fix that.&lt;/p&gt;
</content>
 </entry>
 
 
</feed>
