OpenMoko

My work on the Openmoko project

Openmoko was a project aiming to create an open-source smartphone, including the hardware design. It ran from about 2007, before largely fizzling out in 2010. The idea of receiving a box containing a phone, hardware schematics and an appropriate screwdriver appealed to me, so when the second model - the GTA02 “Freerunner” - went on sale, I jumped in. Here's the story of what I did, as told through pages from my old blog.

OpenMooCow

The first code I wrote for the Freerunner was an “advanced accelerometer and audio system testing framework” known as OpenMooCow. This was a silly program which makes your phone moo like a cow when you turn it upside down. Completely useless, but a lot of fun, and a nice introduction to programming in an embeded environment. It was my first ever mobile phone “app”, and as of 2020 remains my only one.

Becoming a kernel hacker

I'd had an ambition to work on Linux kernel code for a while, by my experience was limited to some unsuccessful messing around trying to get rfkill to work on my old laptop. As it happens, the feature I wanted was later added by Matthew Garrett, and requires some WMI magic, so I never stood a chance with that as a beginning project. But with Openmoko, I had an opportunity to learn with some documented hardware, working on an accelerated graphics driver for the Freerunner's SMedia Glamo3362 chip.

A group of developers from the Openmoko community signed up to work on the project, including making a non-disclosure agreement to get access to the documentation for the Glamo chip. Since the company making the chip no longer exists, the data sheets have since been made public.

Just before the Second Cambridge Openmoko User's Meeting, I started hacking around in the kernel code for the Glamo driver. I wrote a simple module which did little more than switching on the chip's 3D engine. When this was later referred to as “promising initial work” in one of the monthly community updates, it was a very welcome boost. But this was only the very first baby step in a journey of a thousand miles.

For a bit of background, read this page which I wrote to explain how DRI and DRM related to one another. Note that “DRM” in this context means “direct rendering manager”, not “digital restrictions management”. To make the graphics acceleration available to the operating system, a kernel module is needed which can manage the memory of the graphics chip. During my period of peak activity on this project, between about February and August 2009 (the same time as I was finishing off my PhD thesis - coincidence?), I managed to get most of that stuff working, and stabilised it, including some bits to make font rendering work. I added the necessary interface code to the already excellent “user mode” Glamo3362 driver written by Lars-Peter Clausen based on previous work by Graeme Gregory. The result was that the X.org driver worked as before, but with the hardware being managed by the kernel rather than the driver itself.

About this time, I started work on a Mesa 3D driver. I actually would have preferred to work exclusively on 3D graphics from the start, but the KMS stuff needed to be done as well. The insides of Mesa are very complicated - more complicated than all the DRM/X.org stuff in fact. I eventually got enough of a Mesa driver written to get glClear() to work, in other words to fill the screen with colour via the accelerated driver.

I made a summary of how to install the complete DRI stack, which you can still find online.

The last big achievement I made before I stopped working on Openmoko was to use the Glamo chip's interrupt mechanism to allow processes to be sent to sleep while waiting for their graphics commands to finish. Combined with some tuning of internal memory FIFOs, the results were pretty impressive - over 90 frames per second full-screen filling with negligible CPU usage!

End of the project

The whole Openmoko project fizzled out in quite a big way, but I was already struggling for time before that happened. I'd just started a new job in a different country, which involved a free and open-source software project of its own, and that used up a lot of my motivation for programming outside of work for a while.

Openmoko continues in some way, and I'm still very interested in using open hardware and free software on my phone. It seems I don't have much luck here: first I switched to N900/Maemo, for which Nokia ended support almost immediately after my device was delivered. Then I switched to Jolla/Sailfish, which stopped making hardware altogether. I tried switching to LineageOS, but managed to brick a supposedly un-brickable phone (fortunately not an expensive one). I'm now using a regular Android phone, while hoping there's a change for the better.

While it lasted, working on this project was immensely challenging but equally rewarding and educational. I didn't have any meaningful kernel experience before I started, but the knowledge is easier to gain than you might think. If you've run into a kernel-related problem that you'd really like solved then, if you can program confidently (read “can get complicated stuff with C pointers right first time”), I urge you to give it a go yourself, no matter how “forbidden” the project may be!