Millions of phones are thrown away each year, very few are recycled and the pollution this e-waste creates is significant. There can be many reasons for consumers to throw away their phones. The asbence of updates from the phone’s manufacturer can be one of them. There are several projects that aim to extend the life of mobile phones, PostmarketOS is one of them.
But a lot of these devices have quite powerful system on chip, even 10 year old phones have a decent computing power for today’s use cases. So what if we could reuse them for other purposes? And more importantly, “can android e-waste run Nerves?”
This post describes the steps I took to have nerves running on an old Fairphone2. The phone features a Qualcomm Snapdragon 801 with 4 cores running at 2.26Ghz, 2GB LPDDR3 RAM and up to 32Gb of eMMC storage. Being a phone, it also has an LTE modem with dual sim, which can be useful for some projects.
“It’s just buildroot”
Nerves uses buildroot underneath, so before jumping into nerves itself, getting the phone to boot a buildroot system is the first priority.
In order to run Linux on such a device, you need 3 things minimum:
- A kernel that actually boots on the device
- A device tree
- A root filesystem that the kernel can run an init script from
Fortunately, the Fairphone 2’s core functions are supported in PostmarketOS and there is a linux kernel fork specifically for this type of soc available here that also includes the proper devicetree.
Looking into how PostmarketOS works, I managed to find the kernel configuration they used. At first I just used it in my buildroot config. I added a few things later on but the necessary config remains the same. You can find my buildroot port for the Fairphone2 here
Booting buildroot on the Fairphone2
All Android devices rely on a particular partition table. Some devices will not boot if you tamper with it. Usually, the stock bootloader will look for a bootable Android kernel on the partition labeleled boot
and then will mount the system
partition to boot android. The stock bootloader will most likely ignore what you flash on the boot partition unless it’s a valid Android kernel.
Once again, the amount of information you can get from the Postmarketos wiki is quite valuable. What they do, for the Fairphone2, is flash a 2nd level bootloader called lk2nd on the boot partition. It’s a bootloader that the stock bootloader launches… And that second bootloader scans for an extlinux.conf file on one of the other phone partitions. You can find more info about lk2nd on it’s github page
Note that lk2nd should only be used on devices that it supports…
So all we need is to flash lk2nd on the boot partition, then flash our buildroot image on one of the other partitions of the phone and we should be good to go…
I used buildroot to create an img file containing the complete filesystem (including /boot) and proceeded to flash it on the phone using fastboot. Wich got me to a login prompt
Creating the Fairphone2 Nerves System
I reused the same kernel config I had to use for my buildroot port, and compared the nerves_defconfig from the raspberrypi system with the one I used in the buildroot port to cherry pick what I needed in this new system.
I then proceeded to adapt a few files:
- fwup config files
- fw_env.config
- erlinit.config
You can find the whole system here
Booting Nerves
The workflow is slightly different. We will not be using an SD card, and we must use fastboot to flash the device the first time.
After flashing lk2nd on the boot partition, I proceeded to build a simple nerves firmware using this system. In order to have an img file that I could flash, I used:
mix firmware.image
Then flashed the file on the userdata partition. This is only needed the first time or in case you mess up your firmware and need to start from scratch. After that, with your phone connected to your computer using USB, you should be good to go with the usual mix firmware && mix upload.
You should end up with the Nerves prompt on your phone screen.
What’s next
Alghouth I managed to make the modem work in buildroot, I still haven’t got a chance to get it to work in Nerves. There are also several sensors on the Fairphone2 that are not used at the moment (accelerometer/gyro). So there is still a bit of work to do in order to really use the whole potential of the device.
Wifi is already supported, and the touchscreen allows you to build kiosk applications quite easily.
What about other devices
This journey got me into many rabbit holes. I learnt a ton about linux, Android, buildroot and Nerves in the process. As soon as I got buildroot to work on the Fairphone2, I knew that if an Android device is supported by PostmarketOS, then we can run Nerves on it. A complete list of booting devices can be found on their wiki.
I didn’t suddenly decide to port Nerves on the Fairphone2 by myself. It turns out that in December 2024, I met a guy living in my city. His business is to create the first circular computer. The company is called citronics and his first prototype is… using a Fairphone2. When we met, I told him I’d try to run Nerves on his device.
I have at least two other old Android devices supported by PostmarketOS in my drawer, and I’m sure you also have a bunch of them in yours… So let’s put Nerves on all the things!