Cross-compiling BusyBox to run on the Intel Atom Z3745 inside an ASUS MeMO Pad (ME176C)

I recently acquired the very inexpensive ASUS MeMO Pad (ME176C). It’s a surprisingly great device with an excellent screen and, best of all, a powerful Intel Atom Z3745 inside. The tablet comes with Android 4.4 (KitKat), however I want to run Ubuntu LTS from a chroot. I soon discovered I needed to compile BusyBox from source in order to achieve this.

You should root your tablet following the instructions on XDA Forums. I strongly advise you grab the latest RootZenPhone from the official page. I initially bricked the tablet using 1.4.6r, but had success with 1.4.6.8r. Make sure to back up all of your important information as you may have to factory reset in case the rooting fails.

Prerequisites

You will need Ubuntu 14.04 LTS (Trusty). If you are running a different operating system the steps may still work, however you will need to tweak package names.

Android NDK

In order to cross-compile BusyBox, we’ll need the Android NDK. Grab whatever is the latest revision (10d at the time of writing) and make sure to pick the correct architecture for your computer. If you are downloading from a terminal, please familiarise yourself with the Terms & Conditions on the NDK page.

cd /tmp
wget http://dl.google.com/android/ndk/android-ndk-r10d-linux-x86_64.bin
chmod a+x android-ndk-*.bin
./android-ndk-*.bin

BusyBox from source

Let’s get started by cloning the BusyBox repisitory:

# If you don't have Git installed:
#
#     sudo apt-get install -y git-core

cd /tmp
git clone git://git.busybox.net/busybox.git

We’ll need to check out a stable release. At the time of writing, I had success compiling 1.23.0:

cd /tmp/busybox
git checkout 1_23_0

With the Android NDK in place, we need to edit the default configuration file to set the correct paths and flags:

cd /tmp/busybox

# Export a shell variable for easy access to the Android NDK path:
export ANDROID_NDK_ROOT=$( echo -n /tmp/android-ndk-*/ )

# Configure the cross-compiler prefix used by BusyBox:
sed 's!^\(CONFIG_CROSS_COMPILER_PREFIX=\).*!\1"'$ANDROID_NDK_ROOT'toolchains/x86-4.8/prebuilt/linux-x86_64/bin/i686-linux-android-"!' -i configs/android_ndk_defconfig

# Configure the cross-compiler root:
sed 's!^\(CONFIG_SYSROOT=\).*!\1"'$ANDROID_NDK_ROOT'platforms/android-19/arch-x86"!' -i configs/android_ndk_defconfig

# Configure CFLAGS for the Intel Atom:
sed 's!^\(CONFIG_EXTRA_CFLAGS=\).*!\1"-DANDROID -D__ANDROID__ -DSK_RELEASE -march=atom -m32 -ffast-math -mfpmath=sse -ftree-loop-if-convert -fschedule-insns -fsched-pressure -O2"!' -i configs/android_ndk_defconfig

The file we modified needs to be copied so BusyBox can read it:

make android_ndk_defconfig

There are several issues when cross-compiling BusyBox. We need to turn options associated with them off to avoid compilation errors:

# If you don't have ncurses headers installed:
#
#     sudo apt-get install -y libncurses5-dev

make menuconfig

With the graphical menu on-screen, make sure the following options are configured as instructed:

  • disable

    Coreutils ---> touch -> Add support for -h

  • enable

    Login/Password Management Utilities ---> Use internal crypt functions

  • disable

    Linux System Utilities ---> mdev

  • enable

    Linux System Utilities ---> mount

  • enable

    Linux System Utilities ---> umount

  • disable

    Networking Utilities ---> udhcp client (udhcpc)

The default state of those options should be the inverse of what we need them configured at. As you turn an option on, additional ones may present themselves – make sure to leave those untouched.

Tip: <Esc><Esc> gets you to the previous screen. <Tab> let’s you highlight the Exit button.

Exit and save the configuration with the new options.

Patching BusyBox

There are several compilation errors at this time should you attempt to run make.

mount and umount

We are in luck as there is a patch in Tias Guns’ repository:

cd /tmp/busybox
wget https://raw.githubusercontent.com/tias/android-busybox-ndk/835af752d00bb025bc8857d92b3af9de7a902cbc/patches/003-mount-umount-fsck-df.patch
patch -N -p1 < 003-mount-umount-fsck-df.patch

GNUisms not available…

We are in luck again as there is a patch in Tias Guns’ repository:

cd /tmp/busybox
wget https://raw.githubusercontent.com/tias/android-busybox-ndk/835af752d00bb025bc8857d92b3af9de7a902cbc/patches/012-mempcpy.patch
patch -N -p1 < 012-mempcpy.patch

Let’s build

All it should take now is:

make

# Let's verify it all went fine:
#
#     file busybox
#
# The output should be identical to:
#
#     busybox: ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped

Get BusyBox on the MeMO Pad

Prerequisites

In order to be able to copy the new busybox binary to the tablet, we need to enable USB debugging.

  • Open Settings > About > Software Information
  • Tap continuously on Build number until you turn Developer mode on
  • Re-open Settings > Developer options
  • Enable USB debugging
udev rules

Connect the MeMO Pad to your computer. You will get prompted to authorise the connection on the tablet – accept after reviewing.

You may then discover that you haven’t got permissions to access the tablet using adb. To verify the device is recognised:

# If you don't have adb installed:
#
#     sudo apt-get install -y android-tools-adb

adb kill-server
adb devices

If you see lots of question signs under the device name (e.g., ????????), we need to do one last thing – configure the correct permissions when hot-plugging. With the tablet still connected to the computer:

lsusb

# Review the list of attached devices and locate the ASUS MeMO Pad.
# Copy the string after "ID " and paste it in place of the `$REPLACE_ME` variable below.
# The line should look something like:
#
#     export MEMOPAD_ID="0b05:5507"

export MEMOPAD_ID="$REPLACE_ME"

echo -e '# ASUS MeMO Pad 7 (ME176C):\nSUBSYSTEM=="usb", ATTRS{idVendor}=="'${MEMOPAD_ID%:*}'", ATTRS{idProduct}=="'${MEMOPAD_ID#*:}'", MODE="0664", GROUP="plugdev"' | sudo tee -a /etc/udev/rules.d/60-android.rules

sudo udevadm control --reload-rules
sudo service udev restart

Unplug and plug the MeMO Pad. Verify the question signs have disappeared and the device is recognised correctly.

Push BusyBox to the MeMO Pad

cd /tmp/busybox
adb push ./busybox /sdcard/

The binary is on the tablet now, but it requires executable permissions. Use adb to start a shell:

# On your computer:
adb shell

# You will find yourself logged as a regular user on the MeMO Pad.
# To be able to set executable permissions, you need to gain root access:
su

# Approve the request in SuperSU.

# Copy the binary to a new location where we can make it executable.
#
# NOTE: mv does not work and will report 'Cross-device link' failure, hence we use cp instead:
cp /sdcard/busybox /data/local/busybox-1.23.0

# Modify the binary permissions to make it executable:
chmod 555 /data/local/busybox-1.23.0

exit

# We are now back logged as a regular user on the MeMO Pad
exit

# On your computer let's verify it all went fine:
adb shell /data/local/busybox-1.23.0 | head -n1

# The output should be identical to:
#
#     BusyBox v1.23.0 (2015-01-03 12:55:15 UTC) multi-call binary.

Happy hacking!

Day X: Giving up on Firefox OS

The Experiment

I recently decided to give Firefox OS a try and ordered a Flame developer reference phone. This will be an attempt at a blog series capturing my first 30 days of usage. I will do my best to blog as frequently as I can, usually once or twice a week as I get more accustomed to the new platform.

The Experience (or lack thereof)

Going back to the end of August, I was pretty excited to be getting an upgrade from an old and dying Android-based phone to the Flame running Firefox OS, the fresh and exciting OS. My enthusiasm was cooled down fairly quickly once I discovered the OS is still pretty much unfinished and had many bugs. Shortly thereafter a got a Twitter mention saying I should be trailing Firefox OS 2.x as it will offer a much better experience. What did I have to lose, I obviously wasn’t happy with the stock 1.3 version?

So one day I got my USB cable, flashed the phone with Firefox OS 2.1 and started over. No apps, no contacts, no accounts… a clean slate.

Bugs, bugs, bugs

I was hoping Firefox OS would be pretty stable after reaching version 2.x when it comes to be basics. Things like making or picking up a phone call surely must be tested with each code change introduced? Automated tests, CI, etc.? I was unpleasantly surprised to find out that this is not the case. The dialer, for example, broke fairly frequently making it impossible to make a phone call. To this day I can’t answer incoming calls as well, the slider to pick up does not work. The latter one has persisted across multiple OS updates.

Is it the case that there are automated tests and bugs have been caught and ignored? If so, why are such changes allowed to be accepted to the nightlies [1] before being finished?

Another annoying issue is the low output volume you get when you plug-in earphones. It will just not go any higher than 10-20% no matter what the UI says. As you unplug your earphones the phone then goes into party-mode with the built-in speaker tearing itself at 100%.

Then there is the network time bug. The phone never correctly synchronises its clock with the network. On Android, connected to the same network, resetting the date & time and then syncing from the network always works. On Firefox OS you get a random date, usually within the past 3-4 days, and a random time. Needless to say this wreaks havoc in pretty much all apps, from the Call Log, to Messaging and E-mail. Just as an example, a missed call from 5 minutes ago may be shown several swipes down with calls from yesterday.

The list goes on and the above is just a fraction of the really frustrating ones. The OS feels like an experiment that is largely unfinished.

[1] I get that nightlies are meant for testing, however introducing unfinished changes seems like a bad practise. Firefox recently introduced Electrolysis, a big change to run web content in a separate process from Firefox itself. This was turned off by default and is a good model to follow – if an update is unfinished or breaks things, hide it behind a flag.

Battery

Power consumption on the phone is what you would expect it to be and the battery can last you for a good 24 hours with low to moderate usage. That is by no means great, however at this price range is to be expected.

There is a nasty bug, though, which sometimes prevents the phone from charging. I thought charging would have been handled at the hardware level, however the OS appears to have control over this. A restart usually helps. If you are using a non-standard charger, the phone would sometimes get stuck at the boot screen and begin to vibrate. This doesn’t happen every time and a restart usually helps.

Marketplace

If I have to sum it up in one word: poor. Apps are rarely polished and you get wrappers around a website’s mobile version. A good example is Soundcloud which is just m.soundcloud.com behind a pretty icon. As you switch away from the app, the music stops. So yeah, no Soundcloud on the background whilst composing your super important e-mails.

Core Applications

In the month that I have been using 2.x Calendar never did work. E-Mail still can’t open or forward attachments. Firefox, the built in browser, has gotten somehow worse. I still haven’t figured out how to use tabs.

There is a handy ‘Usage’ app which is supposed to track your mobile data plan usage. For me it rarely works and reports there is no SIM inserted the majority of the time.

For whatever reason you now also get a global ‘Search the web’ box at the top which is a shortcut to Firefox. It picks up on the app and will change appearance. You would be fooled to think it’s actually part of the app itself, but it isn’t. I can’t remember how many times I’ve tried to look up contacts in the wrong search box.

Developers, developers, developers

It’s a shame the platform is so unappealing. I was not once tempted to fire up Vim and work on an app exclusively for Firefox OS. This is part of the problem the platform has – HTML5 apps are good enough and you don’t go the extra mile to add polish for Firefox OS.

The Conclusion

I have made up my mind. It pains me to say I will be going back to Android. Firefox OS is not ready for the end-user and it’s not appealing to me as a developer. It has it’s place in emerging markets, but once you compare it to anything else it doesn’t stand a chance.

The logical question to ask is then can you fix the ugly and the broken? You most probably can but it will take discipline.

  • Don’t ship broken code globally, never, not even in nightlies. If you are asking developers to create apps for your platform, they must have confidence in how reliable it is.
  • If you introduced an issue by accident, fix it as quickly as you can. Bugzilla is filled with cases of Firefox browser bugs being open for 5+ years. Is history going to repeat itself and will Firefox OS suffer from the same fate?
  • Polish, polish, polish. When I pick up a phone with Firefox OS, I want it to look finished. I don’t want my notifications screen to be filled with double-escaped HTML messages. Yes, ‘<span>’s actually appear in notifications and that issue hasn’t been fixed in weeks.

I will keep my Flame around and will likely come back to revisit Firefox OS in a couple of months. Perhaps then it will be a more mature platform with less teething problems.

Day 2-7: Using Firefox OS

The Experiment

I recently decided to give Firefox OS a try and ordered a Flame developer reference phone. This will be an attempt at a blog series capturing my first 30 days of usage. I will do my best to blog as frequently as I can, usually once or twice a week as I get more accustomed to the new platform.

The Bad & Ugly

In the last week of usage, there have been more bad things than good. This post may come across as negative, but in reality I am satisfied with the phone and OS at its early stage of development.

Multitasking

You can switch between apps by holding the ‘Home’ button. The phone will vibrate (cannot be turned off) before displaying apps as ‘cards’.

The multitasking interface in Firefox OS

From this interface you can close an app either by tapping on the (x) icon or by flicking the thumbnail from the bottom. Both methods will work only half the time. When it doesn’t work, you open an app from the list at random instead.

E-Mail

Let’s start with the most frequently used app… or what used to be the most frequently used app. E-mail is bad at mail. I have noticed a lot of issues around scrolling the contents of an e-mail. It gets so bad, you can’t read your messages after the first paragraph. I still haven’t figured out if attachments are supported at all, there is no way to open them.

Notifications. They pile up on your lock screen if you have multiple accounts and disappear at once when you open the app. They will disappear even if you didn’t look at the account with new messages in it. What is particularly annoying is after you receive a new notification, if you archive or delete the message on your computer, the notification on the phone will persist. So, yeah…

Call log

This should be called something else as it doesn’t do what the title suggests. Notifications for missed calls show up on the lock screen, but then are nowhere to be found in the call log. I have had numerous follow-ups from people asking me why I didn’t return their call… what call?! Outgoing calls are rarely logged as well.

Browser

Firefox, of course. If you are looking for customisations, you won’t find them, though:

The Settings page in Firefox browser

You will receive mobile-optimised versions of websites more often than not. In Firefox, unlike Chrome for Android, you cannot spoof the user-agent to request a desktop version instead. You are stuck with whatever the author has chosen to display for mobile devices.

Sharing a link is pre-configured to open up E-mail as if other options do not exist. In doing so, the E-mail app will sometimes get very confused and report ‘you are not set up to receive e-mail’.

On heavier pages Firefox is slow. As you are trying to zoom in a region, the browser will decide to do a reflow. You end up on a random region instead. Opening links, scrolling, etc. generally feels clunky instead of smooth.

Then there’s the overly sensitive issue which makes you navigate to pages just by flicking through an article.

Twitter

This app is basically Twitter for Mobile. You’ll get the same experience if you spoof your Chrome user-agent to a mobile device or visit twitter.com in Safari, etc. The only difference is the app supports web activities:

We’ve also implemented support for a feature unique to Firefox OS: Web Activities. This lets you tweet photos directly out of any app that also supports web activities such as the built-in photos app.

source

Twitter on Firefox OS is usable, but definitely lacks behind its iOS and Android counterparts. No notifications for mentions, direct messages, etc.

YouTube

Just as above, YouTube is nothing more than a wrapper around the mobile version of youtube.com… but actually worse. The app displays a small area at the bottom which is meant to toggle navigation controls for apps which don’t behave correctly.

YouTube app showing a 'black' area at the bottom to toggle implicit navigation controls YouTube app with expanded implicit navigation controls

The Rest

Next time I’ll be reviewing marketplace apps and sharing more thoughts on the young Firefox OS.

Day 1: Setting Up (Firefox OS series)

The Experiment

I recently decided to give Firefox OS a try and ordered a Flame developer reference phone. This will be an attempt at a blog series capturing my first 30 days of usage. I will do my best to blog as frequently as I can, usually once or twice a week as I get more accustomed to the new platform.

Mobile Data, voice mail, etc.

I started playing with the phone and was surprised to find it had managed to auto-configure mobile data (APN access), voice mail, MMS, etc. I am guessing this is largely dependant on the mobile carrier, but I am glad Firefox OS picked up on those. In the past, when dealing with Android, I’ve had to go through long Customer Support calls to receive the correct settings for my device as text messages.

E-Mail

The very first app I launched was E-Mail. Unlike Android, Firefox OS does not have a notion of system-wide accounts. Setting up mailboxes is, therefore, specific to the Mail app.

'New Account' screen in Mail

I use Google Apps for Business with two-factor authentication and was curious if the app will pick up on that. I entered my work e-mail, my regular password and after a little while was prompted to use an ‘application-specific password’. I created one in my Google security profile and Mail was then able to fully set up the account, incl. IMAP and SMTP over SSL/TLS.

Using Mail has been a bit of a pain. There is no easy way to archive e-mails. I’m still unsure how message deletion is handled, are they sent to the Bin? Drafts are stored locally and if you wish to continue writing on a different device, your best bet is to e-mail the draft to yourself. Handling multiple accounts is a pain and switching between them is 4 taps away. Gmail accounts are set up using IMAP and as such you will get notifications of new messages with a delay (poll interval configurable, no push notifications). I haven’t figured out how to open attachments yet.

Overall, using Mail on Firefox OS feels like a step backwards… a big one at that.

Calendar

As before, setting up accounts is specific to the app. When adding calendars from Google, you’ll be sent to the Google profile log in page where you’ll have to enter your full e-mail address and password. If using two-factor authentication, you’ll have to enter the temporary PIN as well. This is different from setting up accounts on E-Mail where application-specific passwords are required.

The default view in Calendar

The default month view doesn’t leave a lot of space for any events to be shown at the bottom. There are no animations, transitions or any other niceties. For example, in week view swiping from any edge will move a week forward/backward. The new events replace old ones and sometimes it’s difficult to tell if anything changed. In day view the unnecessary big font size cuts event titles rather short and makes landscape view preferred… which does not work.

I rarely use the calendar on my phone and I have a feeling I’ll be using less of it in the future.

Contacts

This should come as no surprise, importing contacts is app-specific. You must go through the process of logging into your Google profile once again. Furthermore, I couldn’t find an option to sync with Google so importing is a one-off thing. Yes, it feels a lot like owning an ancient Nokia phone and importing from SIM.

Summary

The experience hasn’t been great so far and the stock apps are disappointing. However, given we are talking about Firefox OS 1.4, it is too early to judge. The platform is open so anyone can contribute and improve.

Next time I’ll be setting up Twitter and apps I use frequently.

Day 0: Flame Unboxing

The Experiment

I recently decided to give Firefox OS a try and ordered a Flame developer reference phone. This post and the ones following will be an attempt at a blog series capturing my first 30 days of usage. I will do my best to blog as frequently as I can, usually once or twice a week as I get more accustomed to the new platform.

Why a Firefox OS-based device?

I have been a long-time Android user (and recently an iPhone user by accident). I own a Samsung Galaxy S I phone which I have been successfully patching to the latest Android version using Cyanogenmod. During the years, however, I have owned all the successors to the original Galaxy S. My wife owns a Galaxy S4 mini and seems happy with it.

Although in the past patching has worked reasonably well, recent versions of Android are too demanding of the ancient hardware I was using. This prompted me to look around for a new phone. After a lot of soul-searching, I decided I don’t want yet another Android-based phone. I was ready for something new, open and extensible.

I still have an HP TouchPad lying around the flat which dual-boots into Android and webOS. I believe web-based OS’es that embrace open and modern technologies are the way to go. So… what options do I have?

The Flame developer reference phone

As soon as Mozilla made the announcement, I knew I wanted to own a Flame device. It’s a mid-tier phone which runs the latest Firefox OS. An OS that I might actually like… and with prices as low as £100 it’s a great value for money.

If you haven’t seen the specs, here’s a quote from the announcement:

Qualcomm MSM8210 Snapdragon, 1.2GHZ Dual core processor 4.5” screen (FWVGA 854×480 pixels) Cameras: Rear: 5MP with auto-focus and flash / Front: 2MP Frequency: GSM 850/900/1800/1900MHz UMTS 850/900/1900/2100MHz 8GB memory, MicroSD slot 256MB – 1GB RAM (adjustable by developer) A-GPS, NFC Dual SIM Support Battery capacity: 1,800 mAh WiFi: 802.11 b/g/n, Bluetooth 3.0, Micro USB

A word of caution

The Flame phone as ordered from Everbuying ships from Singapore (manufactured in China). If you are shipping to a EU member country, your order may be subject to import taxes. Depending on where you live, you may also need to provide proof-of-payment as the supplier will likely declare your order as ‘no commercial value’ (which is a red flag for customs). Bring your PayPal receipt or wire transfer papers with you.

Unboxing, please!

Right, let’s get on with it, shall we?


The Flame phone box with T2Mobile label at the front The Flame phone box at a slightly different angle The Flame phone box up-close

As the phone arrived, it had the T2Mobile logo at the front. Wat?

Mozilla worked closely with T2Mobile in creating the phone, which offers developers a means of configuring the RAM of the handset using the phone’s software so they can emulate a variety of Firefox OS devices that will be released throughout the coming year.

T2Mobile will also be charged with rolling out the software updates of Firefox OS, and even offer you a means of trying out different release channels, so that you can even install nightly builds right from your device.

source

Mystery solved.

The box itself is nothing to marvel at. It’s plain, it’s simple and the only interesting element to it is the orange screen of the phone illustration. It also feels very light.


The other side of the Flame phone box showing the device specs

Once you turn the box, the back reveals the phone specs and what’s included in the box.


The box unwrapped showing the front of the Flame phone

The box opens and reveals the front of the phone. Nothing fancy here, you’ve got your screen protective cover that peels off and an access to the bottom half of the box.


The back of the Flame phone The full back of the Flame phone

The back of the phone reveals a slot for an SD card and two SIM cards (2G+3G). The phone OS itself allows you to choose which one will be used for calls, mobile data, etc. The battery is not inserted into the phone at this point.


The contents of the bottom half of the Flame phone box

The bottom half of the box contains the phone’s back cover, micro-USB cable and earphones (quality not tested).


The full contents of the Flame phone box The label on the battery which reads 'alcatel onetouch'

The full contents of the box. The Firefox OS sticker is a nice addition.

A close-up of the battery reveals a label ‘alcatel onetouch’. My best guess is the Flame phone is a modification of the Alcatel One Touch Fire and they didn’t spend the time to re-brand the battery. So Mozilla teams up with T2Mobile to bring us an Alcatel One Touch Fire variation that has ‘ThunderSoft (R)’ as a boot screen… feels like a Frankenstein’s creation.


The first welcome screen of Firefox OS, selecting a language The second welcome screen of Firefox OS, selecting a wi-fi network

With the battery in place, I accidentally held the phone at the top which prompted a boot. The OS was fairly quick to start (and so are subsequent reboots). The first-time use screens prompt to select a language and a wi-fi network. English (UK) is not an option.


The phone's homescreen after first-time set up

…and there we have it, a working Firefox OS on a Flame phone. Time to set up mail, calendar, contacts and all the social goodies one is accustomed to.