LWN.net Logo

Updating and rebuilding Android

By Jonathan Corbet
May 6, 2009
This is one in a series of articles on working with the Android Developer Phone (ADP1) device. In the previous episode, your editor went through the process of updating the software on the ADP1. This time around, we'll look at the latest software builds, then take a beginning look at the process of actually building new software for the device.

Your editor started by testing out the Android 1.5 images provided by HTC, the manufacturer of the ADP1. The provision of these images is a nice step forward by HTC; thus far, ADP1 owners have felt somewhat left out when new versions of the firmware have been released. This time around, they have the new software at about the same time as everybody else. The 1.5 update is done in the usual way: use the "adb" tool to copy it to /sdcard/update.zip on the phone, then reboot into the recovery image to actually install the new code. Two such iterations are required this time around; there is an update to the (closed-source) radio code which must be applied first.

Sidebar: USB cables

If, in the process of pushing updates to the ADP1, you get failures with "protocol error" messages, you're not alone. It turns out that the device is sensitive to noise introduced by low-quality USB cables; one needs a well-built cable for this task. Note: the cable packed with the ADP1 does not qualify as "well-built."

So what's new in Android 1.5? The biggest user-visible feature is almost certainly the on-screen keyboard. It's no longer necessary to open the keyboard to send a quick text message. The on-screen keyboard is somewhat painful for your fat-fingered editor to use when the phone is in the portrait orientation, but it works better in the landscape mode. One has to wonder, though, what inspired the Android developers to dedicate a significant chunk of scarce screen space to a "smiley" key. There are plenty of characters which would have been rather more useful in that position.

Beyond that, the 1.5 release includes "Latitudes" support for those of you who want to continuously report your real-world location to the Google mother ship. There are simple screen effects which come into play when switching between applications and orientations. Holding the power button gives quick access to "airplane mode." The camera is quite a bit more responsive. The zoom icons are smaller and more discrete. GPS acquisition is said to be faster; your editor has not had a chance to test that claim, but it would certainly be a welcome improvement. The orientation-awareness (turn the phone on its side and the display switches to landscape mode) that has been a feature of the JesusFreke builds for a while is now part of the core platform. And so on. Mostly small stuff, but it's enough to make for a nicer feel to the platform overall.

Speaking of the JesusFreke builds, the JFv1.50 build, based on 1.5, is also available; your editor promptly installed it. This build is basic Android 1.5 with a number of additions, including multitouch support, tethering support, an augmented init daemon, a whole set of busybox-based command-line utilities, and more; see the full list for the details. As usual, these builds add a number of nice features to the phone; anybody who is interested in really playing with the device will likely prefer the JF version of the software.

Remaking JF builds

Playing with new builds is fun, but this is free software. The real fun comes from rebuilding the software from the source, perhaps with specific changes. There are two levels at which this can be done. The first is to use the JesusFreke "build environments." Essentially, the build environment is a tarball containing the modifications made to create the JF image, along with the necessary scripts. There's a new kernel containing multitouch and unionfs support, along with the patches needed to create it. Busybox is found there, as are a number of other useful diagnostic tools, an ssh client, and more.

To create a new build, it is necessary to get the associated official build, place it within the build environment, then run make. With any luck, the end result is an update.zip file ready to be flashed into the phone.

One of the interesting things your editor learned from looking at the images (and from talking to Mr. Freke) is that the JF builds do not actually involve rebuilding much of the Android system. It's mostly a matter of unpacking an official build and making a few creative substitutions. The kernel has been remade, as has the browser application (to support multitouch zooming). Everything else is just a matter of shuffling files around. So the JF build environments can be useful for somebody else wanting to do the same kind of manipulations, but more extensive changes require building the system at a lower level.

Building Android from source

Remaking Android from the source code turns out to be a bit of a challenge. What follows here is a brief set of instructions derived from the Android "building for Dream" page, some hints helpfully provided by GeunSik Lim, and a fair amount of painful experience. In summary: most of the code needed to rebuild the platform is available, but (1) it's not a quick or simple process, and (2) there are a few pieces missing.

There's a number of tools which must be installed on a Linux system to rebuild the Android platform. These include flex, bison, git, and the Sun Java system. Beyond that, one must grab the repo tool. Repo is Google's answer to the problem of managing a whole set of related repositories; essentially it is a tool which sits on top of git and manages a whole set of git repositories in parallel. Once repo has been installed, the meta-repository is set up with a command like:

    repo init -u git://android.git.kernel.org/platform/manifest.git

This command pulls down the manifest file describing all the repositories needed to build the platform. Note that if a branch other than the trunk is desired, it must be obtained during this stage with the -b option; repo apparently cannot switch branches in an existing source tree.

One then obtains the code by running "repo sync" and going out for coffee.

Incidentally, when you go out for coffee, you need not hurry back. It's entirely possible to fly to a different continent, harvest the coffee by hand (after waiting for it to reach the perfect ripeness), fly home, and roast it yourself. You'll still probably have time for a second cup before the downloading of the source is complete. You are, after all, not just downloading a huge pile of source files. You are, instead, downloading over 100 independent git repositories, each containing a long trail of history - about 2.4GB worth of stuff. It takes a while. And, needless to say, some disk space.

To make things worse, you still don't have all the source; there are a few components of the binary platform for the ADP1 which have not been released as free software. You cannot download those binary components from anywhere; instead, what's needed is to obtain them from a working phone. To that end, the file vendor/htc/dream/extract-files.sh contains a script which will pull the needed components from a USB-connected ADP1 device. These components vary from files containing mixer settings to programs for controlling Bluetooth, the GPS receiver, firmware for the wireless network adapter, a camera control library, and more. The dream directory also contains a binary driver module (wlan.ko) for the WIFI adapter, despite the fact that said driver is open source and included in the distribution.

After that, it's a matter of copying build/buildspec.mk.default to buildspec.mk in the top-level directory, editing it to set TARGET_PRODUCT to htc_dream, and typing make. And going out for more coffee, of course. At the end of the process, with luck (a fair amount of luck may be required), there will be new system and boot images which can be flashed into the phone with the fastboot tool. A reboot will run the new code.

At that point, of course, there are some surprises to be found. One is that the newly built software is lacking a number of features found in an official build. The reason for this is simple: several of the applications which run on Android phones are not open source. These include the Gmail client (which your editor will happily do without), Maps (which cannot be done without, at least until AndNav progresses a little further), and more. These applications can generally be recovered by grabbing the associated package files from an official build and slipping them into the build environment. See this article for a terse description of how that is done.

It took your editor a little while to figure out another little surprise: despite the fact that the Android source tree includes a kernel repository, the build process does not actually build the kernel. One might think that it would be hard to miss something the size of a kernel build, but ... did your editor mention that the Android source tree is big? The Android build system which goes with this source tree is quite a piece of work; there must be people working full time on it, and they probably hate their lives.

Trying to figure out what is happening in an Android build requires digging through many thousands of lines of makefile rules. What your editor finally discovered is that the build system simply pulls a binary kernel from a special "prebuilt" repository (that repository also contains a cross-compiling toolchain for the creation of ARM executables). The kernel source tree, seemingly, is just there for show. Using something other than the prebuilt kernel requires making it separately and pointing a build-system variable at the location of the result.

It's clear that even people who remake Android are not, in general, expected to remake the kernel. It's clear that even people who remake Android are not, in general, expected to remake the kernel. The kernel repository pulled down by the repo command does contain the Android-specific patches, but it lacks nice things like branches (even "master" is missing) or tags. There are some remote branches with names like korg/android-msm-2.6.27 which contain lines of development for various kernel versions; the 2.6.27 one appears to be, as of this writing, the one which is best supported on real hardware. But, within those branches, there are (unlike the situation with the rest of the Android code) no tags associated with releases. Nothing in the repository will tell a developer which kernel was shipped with a given version of Android.

So it's hard to build a kernel which corresponds to the one found within an official release. But not impossible: most of the official releases include the git commit ID in the kernel version. So by digging down into the settings menus, your editor was able to determine that the HTC 1.5 build came from commit 8312baf. After checking out that commit, one can do a make msm_defconfig to configure the kernel properly. Then it's just a matter of setting the ARCH and CROSS_COMPILE environment variables and doing the build. If you have a 32-bit Linux environment, the prebuilt ARM toolchain provided with the Android source does the job just fine.

Once the kernel build is done, it's possible to build a new set of firmware images which can be loaded into the device with fastboot. That's easy to say, but it can be harder to do; the sources from the repository often do not build, and it's not always easy to get all the pieces together to make a working image for the ADP1. Making it possible for people outside of the core Android project to build and install the platform appears to be an afterthought, at best.

Android and the ADP1

In truth, Google does not really support the ADP1 as a system people can develop and run on; this situation was somewhat explained by Jean-Baptiste Queru, who is easily the most helpful Google developer on the mailing lists:

Yes, the ADP1 situation is currently unfortunate. We've had to pick priorities, the priority went to open-sourcing code out of Google, as that's something that only Googlers can do.

The truth is, ADP1 isn't a phone from Google. While Google has some influence on it (and provides a number of proprietary apps), It's neither manufactured nor distributed by Google, and that puts limits on the ways Google can support it (and espcially on how Google can not redistribute some of the ADP1-specific files).

So, while the ADP1 is one of the most open cellular phone platforms yet to appear, it does not, yet, represent a fully-open system in the way the OpenMoko phone does. Most people wanting to do things with this device are likely to end up starting with the official, binary builds and tweaking things around the edges, much like as has been done with the JF builds.

That said, there is a lot of fun to be had with this device. It's fully hackable at the kernel level now, and more hardware information is becoming available, which raises the hope of gaining more control over the low-level system in time. About the time the ADP1 becomes fully obsolete and unobtainable, we should have it figured out pretty well. With any luck at all, at least one of the devices which replaces it will be more open from the outset.


(Log in to post comments)

Updating and rebuilding Android

Posted May 7, 2009 4:16 UTC (Thu) by vmlinuz (subscriber, #24) [Link]

Just got one minor comment:

One has to wonder, though, what inspired the Android developers to dedicate a significant chunk of scarce screen space to a "smiley" key.
When you define a text entry widget in an Android application, you can hint to the system what sort of text is going to entered, and different keyboards are used for different purposes. If it's defined as a "short message" widget, it'll have a smiley button, if it's defined as a "URI" it'll have a .com button, and so on. It's actually a pretty neat feature, as a developer, because it gives your application a nice level of polish for essentially no work on your part.

Clean Build Systems

Posted May 7, 2009 6:35 UTC (Thu) by alex (subscriber, #1355) [Link]

It's sad to see the build system is such a prickly mess. Most
successful FLOSS projects have long since known that a hairy build
system is a barrier to entry for potential new contributors to the
code base.

That's to say nothing of the state there QA must be in. Being able to
automatically build a new image from source every time something is
checked in is basic QA functionality. I would of expected better from
the high flying whizz kids at the big G.

Clean Build Systems

Posted May 7, 2009 6:48 UTC (Thu) by dlang (✭ supporter ✭, #313) [Link]

remember, this isn't just building a single application, this is building an entire distribution (albeit a small one)

the fact that it was as easy as Jon made it sound to recreate (almost) the entire distribution is impressive.

even gentoo (which focuses on this area) takes as much, if not more effort to build a system from source.

as far as the time it takes to build, I suspect that the google people only rebuild their particular app when they change it, and they also probably have build farms of high-speed machiens (or at least a LOT of medium speed machines ;-) so that it takes less wall clock time.

Clean Build Systems

Posted May 7, 2009 18:48 UTC (Thu) by wookey (subscriber, #5501) [Link]

indeed - as these things go, that's relatively painless. (I know - I maintain the build system for balloonboard and it's a very hard thing to do well).

We (well, Jim Rayner actually) just built android for the balloon (which incidentally does produce a genuinely free platform, including GSM, although calling it a 'phone' would be a bit of stretch for most people).
http://balloonboard.org/balloonwiki/AndroidBalloon

Clean Build Systems

Posted May 9, 2009 22:25 UTC (Sat) by man_ls (subscriber, #15091) [Link]

The Gentoo people have got to a point where a relatively ignorant newcomer can follow the manual and get a running system in a couple of days. If our grumpy editor (being a kernel hacker and all) feels that the Android build process is painful then it clearly needs more polish.

Updating and rebuilding Android

Posted May 7, 2009 10:16 UTC (Thu) by bcopeland (subscriber, #51750) [Link]

The easiest way to update the kernel, in my experience, is to build it from the msm tree as our editor suggests, then take the HTC-supplied 1.5 initramfs (you can get it from the boot.img in the update zip file and unpack it with split_bootimg.pl). That way you don't have to bother with building any of the android userland.

After that you can simply turn on the phone while holding the back button and plugged into USB, then do 'fastboot boot your_bzImage their_boot.img-ramdisk.cpio' which will do a one-time boot of your kernel, then revert to the installed one on the next power cycle.

The android init setup seems to be somewhat tied to the kernel version so matching versions is good -- the 1.1 init will not work with the 2.6.29 kernel, for example. 1.5 does, sort of.

Updating and rebuilding Android

Posted May 7, 2009 10:38 UTC (Thu) by fb (subscriber, #53265) [Link]

Great article! I had been curious about how to build my own distribution, and now I can give it a try.

You should IMVHO at least mention that the most active image builder for the G1 these days is Haykuro. Another piece of information missing is that most of the G1/ADP hacking activity seems to be centered around XDA forums.

Updating and rebuilding Android

Posted May 7, 2009 12:41 UTC (Thu) by nbd (subscriber, #14393) [Link]

[shameless plug]
I'm working on integrating the Android software stack in OpenWrt. Much of the core of Android 1.5 is already running, but some work is still left to be done until it's usable.

Why am I doing this? Easy:
- OpenWrt is much easier to keep consistent across multiple platforms, because of the way it keeps kernel patches and configs (that's right, we don't fork entire kernel trees).
- OpenWrt allows you to integrate new packages by writing a small makefile and optionally throwing in some patches (which it also helps you create), so there's no need to fork the whole thing.
- OpenWrt allows you to shortcut parts of the build system, so you don't have to spend minutes (or hours, depending on your build machine's performance) waiting for a huge recompile just because you happened to change a core library, which forces a rebuild of build tools, which forces a rebuild of everything those tools generated.

My other goal is to keep the entire thing free of dependencies on external binaries where possible, and turn the Google-forked external libraries into OpenWrt makefiles and patches.

I'll try to keep people updated on my progress on my blog:
http://nbd.name/blog/?p=36
http://nbd.name/blog/?p=48
[/shameless plug]

Updating and rebuilding Android

Posted May 7, 2009 22:42 UTC (Thu) by dlang (✭ supporter ✭, #313) [Link]

the android people are accessing everything through git, so their 'forking' is not significantly different from your 'maintaining patches' (you have less stuff to move around, they use a tool that helps them merge with the original and provides them with some safety in terms of their changes still being correct)

Updating and rebuilding Android

Posted May 7, 2009 23:10 UTC (Thu) by nbd (subscriber, #14393) [Link]

It is different in that the OpenWrt patch structure encourages splitting up changes in a way that makes review for upstream merging easier.
Looking at random Google-forked git directories, all I see is uncommented auto-import commits without a readable commit message, without any indication as to what the changes are meant for or why they were added.
Stuff like that does not usually happen in OpenWrt-maintained patchsets.
I looked at jpeg, libxml2, bzip2 and a few others, and I found no useful information that could help with upstream merging at all.

Another issue is that in the android build system, you cannot build packages without making changes to them (you have to at least throw in some Android.mk files to replace the Makefiles), while in OpenWrt you can leave many packages as-is and use them with our package Makefiles and no patches at all

Updating and rebuilding Android

Posted May 7, 2009 23:34 UTC (Thu) by dlang (✭ supporter ✭, #313) [Link]

you can have a patch with a lousy explination, just like you have have a git commit with a lousy changelog. it's not a technical problem.

if you have the same people producing the commits and the patches they will probably have the same quality.

Updating and rebuilding Android

Posted May 7, 2009 23:47 UTC (Thu) by nbd (subscriber, #14393) [Link]

Here's an important difference:

If you're working on two separate features in an OpenWrt package, the build system generates a quilt patch stack for you to edit, which makes it very easy to keep things separated. This means the system actively encourages you to keep things organized by not forcing extra work on you to do the right thing.

If you maintain such a tree in git and you want to make changes to a feature that you already committed, you're either forced to rebase (which is bad for everybody that's pulling from you), or you have to live with the fact that the grouping of changes is lost in the process.

It does not only depend on the people working on it, but also what the tools encourage you to do, and especially what the common workflow of the tools you work with is.

Updating and rebuilding Android

Posted May 8, 2009 7:26 UTC (Fri) by dlang (✭ supporter ✭, #313) [Link]

no, you do your two different changes in different branches and then merge the two togeather.

if you need to change one of the features you make a change in that brance and do another merge.

Updating and rebuilding Android

Posted May 8, 2009 9:38 UTC (Fri) by nbd (subscriber, #14393) [Link]

Who actually does that?

Updating and rebuilding Android

Posted May 8, 2009 9:47 UTC (Fri) by dlang (✭ supporter ✭, #313) [Link]

the impression I get from watching projects that use git extensively is a lot of people.

remember that branching and merging is very cheap with git, keeping the separate development parts in separate branches lets you test them individually. it's only after you are sure that they are a permanent part of your central branch that you throw them away.

there are people who create separate branches for every different topic that they work on, even if they think it's only going to be a single patch.

Updating and rebuilding Android

Posted May 8, 2009 10:09 UTC (Fri) by nbd (subscriber, #14393) [Link]

What you describe still doesn't quite cover the amount of feature separation that I'm talking about. Yes, when you start implementing a feature separately, you still have some degree of separation by keeping it in a branch, but once you start pulling stuff into your master branch and merging back and forth between the master branch and the feature branches, that becomes lost too.
Or what about switching to a newer upstream version? Sure, you could go ahead and first rebase every single feature branch individually, then try to merge them back in the same order that they were merged initially (if you even kept that information and assuming that you didn't touch the same code parts in different branches), but again that's much more expensive than keeping a set of simple, readable patches around in the first place.

To sum things up:
- it is possible to do this with git, but it's more work and requires more discipline
- devs at google did not have time to do this part right, thus the result is a set of forks that due to their structure are not easy to merge back upstream
- even with patches or commits from less experienced developers, the same chaos does not happen in openwrt packages
- in openwrt you can get away with not having to fork a lot packages
- in android you have to fork every single package and if it's just for replacing the makefile with an Android.mk file
- in openwrt you have to pay less attention to how a package works internally, most autoconf based stuff can be handled with very few changes compared to a template makefile (often only changing the package name, description and download location)

In my opinion those differences are quite significant

Updating and rebuilding Android

Posted May 8, 2009 10:18 UTC (Fri) by dlang (✭ supporter ✭, #313) [Link]

you don't merge back from the main tree to the feature branch.

but the point is that I don't believe that the people who created the commits that you are complaining about would have done any better if they were patches. there was nothing in the tool that prevented them from doing things better. there are lots of kernel developers who would have helped them develop things (and comment them) if they had asked, but they weren't willing to reveal things.

getting things in patches would have probably been _far_ worse, as there would probably just be one big patch for each program (that _is_ the common thing to do when companies fork programs and then release their changes)

Updating and rebuilding Android

Posted May 8, 2009 10:31 UTC (Fri) by nbd (subscriber, #14393) [Link]

Really simple:
If the system lets you get away with having to do less changes to a package to get it working, then *of course* there are going to be fewer changes. People want to get stuff working, and make only the necessary changes.
Or are you really saying that build system and structure have *no* influence on the result? My experience says otherwise...

About making things public and involving kernel people: Yes, that would have helped for getting changes upstream, but it would not have helped to get the product out faster. The Kernel developer community is focusing on getting it done right, while their own development team has to focus on getting it done fast (or at all). Considering the amount of pressure on getting stuff to the market fast, there's only so much time you can spend on figuring out the right approach...

So how would getting things in patches have been far worse, if the patches themselves are under version control? Having patches under version control means that you have *at least* the same amount of information available that you have now, but with an extremely easy way of structuring things even more if you feel like it, which (using quilt) costs virtually no extra effort.

This on-screen keyboard you speak of

Posted May 7, 2009 15:20 UTC (Thu) by felixfix (subscriber, #242) [Link]

I have the non-ADP version of this phone. How does one get the 1.5 version -- is this still in development and not for release to customers? If I already have it, how does one activate the on-screen keyboard? I haven't seen any difference in apps which need a keyboard -- they still stare dumbly at me until I slide the keyboard open.

This on-screen keyboard you speak of

Posted May 7, 2009 15:23 UTC (Thu) by corbet (editor, #1) [Link]

Tap on a text-entry widget with your finger with the device closed to get the on-screen keyboard.

I'm not sure about 1.5 for G1 handsets. I thought that T-Mobile was rolling it out in the US, but I'm far from certain of that.

This on-screen keyboard you speak of

Posted May 7, 2009 16:19 UTC (Thu) by felixfix (subscriber, #242) [Link]

I tried both the contacts program and an independent program, neither of which did much other than move the cursor when I tapped.

Which of the various settings values corresponds to the 1.5 build? There are firmware (1.1), baseband (long weird string), kernel (2.6.25-01845), and build number (kila-user 1.1 plat-rc33 ...).

This on-screen keyboard you speak of

Posted May 7, 2009 16:22 UTC (Thu) by corbet (editor, #1) [Link]

"firmware (1.1)" means that you're running version 1.1 of the firmware.

This on-screen keyboard you speak of

Posted May 7, 2009 19:02 UTC (Thu) by fb (subscriber, #53265) [Link]

US Cupcake upgrade announcement http://forums.t-mobile.com/tmbl/board/message?board.id=An...

"End of the next week"

[...]

England should be getting it already http://www.t3.com/news/android-1-5-update-available-today...

[...]

FWIW, At the XDA forums there are (relatively) simple recipes to turn a G1 into a ADP.

This on-screen keyboard you speak of

Posted May 9, 2009 8:52 UTC (Sat) by erwbgy (subscriber, #4104) [Link]

T-Mobile UK sent out the update yesterday and using Jon's tip I now have an on-screen keyboard.

Copyright © 2009, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds