diziet: (Default)
2022-03-02 11:51 pm
Entry tags:

3D printed hard case for Fairphone 4

About 4 years ago, I posted about making a 3D printed case for my then-new phone. The FP2 was already a few years old when I got one and by now, some spares are unavailable - which is a problem, because I'm terribly hard on hardware. Indeed, that's why I need a very sturdy case for my phone - a case which can be ablative when necessary.

With the arrival of my new Fairphone 4, I've updated my case design. Sadly the FP4 doesn't have a notification LED - I guess we're supposed to be glued to the screen and leaving the phone ignored in a corner unless it lights up is forbidden. But that does at least make the printing simpler, as there's no need for a window for the LED.

Source code: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=reprap-play.git;a=blob;f=fairphone4-case.scad;h=1738612c2aafcd4ee4ea6b8d1d14feffeba3b392;hb=629359238b2938366dc6e526d30a2a7ddec5a1b0

And the diagrams (which are part of the source, although I didn't update them for the FP4 changes: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=reprap-diagrams.git;a=tree;f=fairphone-case;h=65f423399cbcfd3cf24265ed3216e6b4c0b26c20;hb=07e1723c88a294d68637bb2ca3eac388d2a0b5d4

big pictures )

diziet: (Default)
2022-02-23 11:36 pm
Entry tags:

Rooting an Eos Fairphone 4

Last week I received (finally) my Fairphone 4, supplied with a de-googled operating system, which I had ordered from the E Foundation’s shop in December. (I’m am very hard on hardware and my venerable Fairphone 2 is really on its last legs.)

I expect to have full control over the software on any computing device I own which is as complicated, capable, and therefore, hazardous, as a mobile phone. Unfortunately the Eos image (they prefer to spell it “/e/ os”, srsly!) doesn’t come with a way to get root without taking fairly serious measures including unlocking the bootloader. Unlocking the bootloader wouldn’t be desirable for me but I can’t live without root. So.

I started with these helpful instructions: https://forum.xda-developers.com/t/fairphone-4-root.4376421/

I found the whole process a bit of a trial, and I thought I would write down what I did. But, it’s not straightforward, at least for someone like me who only has a dim understanding of all this Android stuff. Unfortunately, due to the number of missteps and restarts, what I actually did is not really a sensible procedure. So here is a retcon of a process I think will work:

Unlock the bootloader

The E Foundation provide instructions for unlocking the bootloader on a stock FP4, here https://doc.e.foundation/devices/FP4/install and they seem applicable to the “Murena” phone supplied with Eos pre-installed, too.

NB tht unlocking the bootloader wipes the phone. So we do it first.

So:

  1. Power on the phone, with no SIM installed
  2. You get a welcome screen.
  3. Skip all things on startup including wifi
  4. Go to the very end of the settings, tap a gazillion times on the phone’s version until you’re a developer
  5. In the developer settings, allow usb debugging
  6. In the developer settings, allow oem bootloader unlocking
  7. Connect a computer via a USB cable, say yes on phone to USB debugging
  8. adb reboot bootloader
  9. The phone will reboot into a texty kind of screen, the bootloader
  10. fastboot flashing unlock
  11. The phone will reboot, back to the welcome screen
  12. Repeat steps 3-9 (maybe not all are necessary)
  13. fastboot flashing unlock_critical
  14. The phone will reboot, back to the welcome screen

Note that although you are running fastboot, you must run this command with the phone in “bootloader” mode, not “fastboot” (aka “fastbootd”) mode. If you run fastboot flashing unlcok from fastboot you just get a “don’t know what you’re talking about”. I found conflicting instructions on what kind of Vulcan nerve pinches could be used to get into which boot modes, and had poor experiences with those. adb reboot bootloader always worked reliably for me.

Some docs say to run fastboot oem unlock; I used flashing. Maybe this depends on the Android tools version.

Initial privacy prep and OTA update

We want to update the supplied phone OS. The build mine shipped with is too buggy to run Magisk, the application we are going to use to root the phone. (With the pre-installed phone OS, Magisk crashes at the “patch boot image” step.) But I didn’t want to let the phone talk to Google, even for the push notifications registration.

  1. From the welcome screen, skip all things except location, date, time. Notably, do not set up wifi
  2. In settings, “microg” section
    1. turn off cloud messaging
    2. turn off google safetynet
    3. turn off google registration (NB you must do this after the other two, because their sliders become dysfunctional after you turn google registration off)
    4. turn off both location modules
  3. In settings, location section, turn off allowed location for browser and magic earth
  4. Now go into settings and enable wifi, giving it your wifi details
  5. Tell the phone to update its operating system. This is a big download.

Install Magisk, the root manager

(As a starting point I used these instructions https://www.xda-developers.com/how-to-install-magisk/ and a lot of random forum posts.)

You will need the official boot.img. Bizarrely there doesn’t seem to be a way to obtain this from the phone. Instead, you must download it. You can find it by starting at https://doc.e.foundation/devices/FP4/install which links to https://images.ecloud.global/stable/FP4/. At the time of writing, the most recent version, whose version number seemed to correspond to the OS update I installed above, was IMG-e-0.21-r-20220123158735-stable-FP4.zip.

  1. Download the giant zipfile to your computer
  2. Unzip it to extract boot.img
  3. Copy the file to your phone’s “storage”. Eg, via adb: with the phone booted into the main operating system, using USB debugging, adb push boot.img /storage/self/primary/Download.
  4. On the phone, open the browser, and enter https://f-droid.org. Click on the link to install f-droid. You will need to enable installing apps from the browser (follow the provided flow to the settings, change the setting, and then use Back, and you can do the install). If you wish, you can download the f-droid apk separately on a computer, and verify it with pgp.
  5. Using f-droid, install Magisk. You will need to enable installing apps from f-droid. (I installed Magisk from f-droid because 1. I was going to trust f-droid anyway 2. it has a shorter URL than Magisk’s.)
  6. Open the Magisk app. Tell Magisk to install (Magisk, not the app). There will be only one option: patch boot file. Tell it to patch the boot.img file from before.
  7. Transfer the magisk_patched-THING.img back to your computer (eg via adb pull).
  8. adb reboot bootloader
  9. fastboot boot magisk_patched-THING.img (again, NB, from bootloader mode, not from fastboot mode)
  10. In Magisk you’ll see it shows as installed. But it’s not really; you’ve just booted from an image with it. Ask to install Magisk with “Direct install”.

After you have done all this, I believe that each time you do an over-the-air OS update, you must, between installing the update and rebooting the phone, ask Magisk to “Install to inactive slot (after OTA)”. Presumably if you forget you must do the fastboot boot dance again.

After all this, I was able to use tsu in Termux. There’s a strange behaviour with the root prompt you get apropos Termux’s request for root; I found that it definitely worked if Termux wasn’t the foreground app…

You have to leave the bootloader unlocked. Howwever, as I understand it, the phone’s encryption will still prevent an attacker from hoovering the data out of your phone. The bootloader lock is to prevent someone tricking you into entering the decryption passkey into a trojaned device.

Other things to change

  • Probably, after you’re done with this, disable installing apps from the Browser. I will install Signal before doing that, since that’s not in f-droid because of mutual distrust between the f-droid and Signal folks. The permission is called “Install unknown apps”.

  • Turn off “instant apps” aka “open links in apps even if the app is not installed”. OMG WTF BBQ.

  • Turn off “wifi scanning even if wifi off”. WTF.

  • I turned off storage manager auto delete, on the grounds that I didn’t know what the phone might think of as “having been backed up”. I can manage my own space use, thanks very much.

There are probably other things to change. I have not yet transferred my Signal account from my old phone. It is possible that Signal will require me to re-enable the google push notifications, but I hope that having disabled them in microg it will be happy to use its own system, as it does on my old phone.

diziet: (Default)
2018-05-01 02:54 pm
Entry tags:

Termux ssh proxy config snippets

Really I ought to get my vpn up on my phone, but that's work. In the meantime so I can ssh into my phone, I have done this (which is a bit of a bodge, but very easy):

Install termux, and termux:widget. Inside termux, install termux-exec. (You may need to install the sshd explicitly too. Arrange for your termux to be able to ssh to your colo with ssh colo, by putting something like this in your .ssh/config on the phone:

Host chiark
  User ijackson
  Hostname login.chiark.greenend.org.uk
Put this script on the phone in .shortcuts/proxy and make it executable:
#! /bin/bash
sshd
ssh -v -R NNNN:localhost:8022 chiark head -1
where NNNN was a random port number. On my laptop, where I want to be able to ssh to the phone, add the following to .ssh/config:
Host star-wolf
 User android
 ProxyCommand ssh ijackson@chiark nc -q0 localhost NNNN
Add a "widget" to one of the home screen pages to invoke that. (Hold down a finger on an empty bit of the relevant home screen page; select "Widgets"; find Termux in the list, the rest is obvious.)

After copying ssh keys about appropriately, it all works nicely. If you don't have a shell account that you are happy to let your phone have control over, you could probably restrict the key; the syntax for this is left as an exercise to the reader :-).

diziet: (Default)
2018-02-01 08:06 pm
Entry tags:

3D printed hard case for Fairphone 2

I made my new phone a case, using our 3D printer.

Source code for the case is here:

https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=reprap-play.git;a=blob;f=fairphone-case.scad;h=5636d285cd83acc866289f21a581fb3b77e9d5a4;hb=00f6e6b886700261cade1e42b9c3e195be99f4d2
git://git.chiark.greenend.org.uk/~ianmdlvl/reprap-play.git

https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=reprap-diagrams.git;a=tree;f=fairphone-case;h=513bf1585ee20d8b9f8193c91d42e3cf19416c43;hb=refs/heads/master
git://git.chiark.greenend.org.uk/~ianmdlvl/reprap-diagrams.git

Thanks to [personal profile] ceb for the multi-print-job technique for multiple colours, which I used for the notification LED window.

big pictures )
diziet: (Default)
2018-02-01 04:20 pm
Entry tags:

Fairphone, Fairphone Open, backups, etc.

I recently acquired a Fairphone 2. I'm running ‘Fairphone Open OS’ (FPOOS) which is the version without the big blob of Google spyware. I thought I would write up some of my experiences.

This is written from the perspective of someone who is completely new to having a smartphone. When I started I didn't know anything really about Android.

Software Freedom

My phone is not running fully Free Software, but then neither is my laptop. I decided that was too high a bar. FPOOS has binaries for the phone baseband and hardware support. The phone baseband has complete access to the phone, and is probably full of bugs, so the security is not brilliant. I won't be using this phone as my TCB.

I get my apps from f-droid (almost exclusively). f-droid is useful
but very annoyingly it has no reviews system, rating system, and not
even something like Debian's popcon. So picking apps is a bit of a
crapshoot.

Apps I would recommend

  • Osmand+
  • Signal. You have to get this from https://signal.org/android/apk/
  • AnySoftKeyboard
  • Satstat
  • Termux (if you want to use this a lot, get a bluetooth keyboard)
  • Lightning (lightweight web browser; I turn JS off)

Notes on the shape of an android system AFAICT

I am no expert on Android but as an old Unix hand I found many things confusing.

Android is in some sense a Linux system but the filesystem organisation and operating system is not like a normal Unix.

The primary structure is an OS core, with ‘apps’. Each app has a uid, and a private data area for its stuff. Apps communicate with the OS and with each other via IPC facilities; there are standard ways of doing this. It all seems to be done via Java libraries.

SELinux is heavily used in addition to the traditional Unix permissions and POSIX ACLs.

The filesystem layout is quite different. Each app is in /data/data/. Apps store their settings and often their data in their private area. (The internal app name looks like a reversed domain name - this is Java influence.)

The partitions include a boot partition, a system partition which contains the OS and all app code and data, and a ‘storage’ partition which Android thinks of as an sdcard (even if it isn't). This is mounted on /sdcard but that is actually a weird FUSE view. On my FP2 the underlying storage is actually in /storage/emulated/0. (I don't know what happens if you have an actual sd card too.)

The storage is the user-visibile part of the filesystem and contains subdiredctories like DCIM, Download, etc. An example of the storage's use is that the camera app puts all the pictures you take there. The storage is shared amongst all apps; every app that has the ‘Storage’ permission can access it.

Backups

I'm a weirdo who thinks their computing devices should be fully backed up. Not ‘synced to the cloud’ - actually backed up.

This is moderately easy to do with TWRP. TWRP is a pre-boot environment. The stock FPOOS image from Fairphone comes with it (albeit a slightly out of date version at the time of writing). You use it by rebooting with a vulcan nerve pinch (phone off; volume up plus power on, release volume up when FP logo shows). It then offers to let you back up.

The backup does not include the storage partition. It is put into the storage partition, in a directory called TWRP.

There it can be read by any app on your phone, so to avoid leaking all the secrets of your phone to every app, you could use the encryption feature in TWRP. This is rather annoying because AFAICT it means you have to manually enter an encryption key. Instead, I used chmod as root in Termux to make the TWRP directory inaccessible. This has to be done in the real storage area, not the FUSE mount (see above), because the FUSE view discards permission changes.

(AFAICT recent versions of TWRP support backing up to an attached computer instead.)

Using TWRP I was able to successfully backup my whole phone and restore it onto a replacemnt (see below) - apart from the media aka ‘storage’, which you have to do separately.

FPOOS TWRP has a bug in that the file boot.emc.win gets the wrong permissions in the backup so that it's not accessible via MTP. You can work around this with Termux, or you can access the files via adb (see below) which, if you say ‘adb root’ bypasses permissions.

Access from a computer

You can get files onto and off your phone with a microusb cable and a protocol called MTP. With the phone connected to the computer, you will get a notification saying ‘usb for charging’, tapping which will let you select ‘MTP (Media Transfer Protocol)’. You can then use programs in Debian like ‘gmtp’ to browse the storage area.

Annoyingly, if you have ‘become a developer’ (by tapping the build number at the bottom of ‘About phone’ repeatedly), the option to switch the charging to USB is then buried in the Developer Options. Look for ‘Select USB Configuration’ about 45% of the way through. This is probably some kind of bug.

Also by turning the phone off you can boot it into a debugging mode and then access the whole phone via ‘adb’ on a computer. This is how I made my most recent backup: I used ‘adb root’ and ‘adb pull’ to fetch the backup made by TWRP, and the other contents of the storage, onto my computer. I then deleted the massive map files that Osmand+ had downloaded from the backup.

thephone.coop are rather poor

I had to buy my FP2 from ‘thephone.coop’ because Fairphone themselves were (and still are AIUI) out of stock. This was not good. ‘thephone.coop’ are terribly disorganised. I won't list all of the daft things they did but as a helldesk they are truly hellish.

I wanted to buy the phone outright rather than on some kind of 2-year-long comes-with-a-sim deal. This wasn't made easy, but I did find it in the ‘business’ section of their website.

The badness of ‘thephone.coop”s customer support became relevant in large part because my first handset was faulty: it was crashy, using the built-in apps eg the camera, even. Luckily ‘thephone.coop’ replaced it without too much fuss.

The replacemnt handset seemed crashy too. Amazingly ‘thephone.coop’ do not have a stress test app or anything. After a lot of struggling I was able to satisfy myself that this was a software problem: one of my other attempts at backups involved ‘oandbackup’, and that seems to have been responsible.