English

Efct16 Software Workshop

Overview

At #efct16 we had access to a community Fairphone 2 for a couple of days. Of course, we decided to play around with it a bit and switch the operating systems around for fun. This topic collects some notes on what was done, but note that replicating any of this is at your own risk - no guarantees that any data can be restored or that the phone will even boot (though it should).
The phone was running stock Fairphone OS 1.5.1 when we started; the device was not encrypted and there were no SD-card or SIMs present. This has not been tested in any other configuration (i.e. encryption). As I only had access to a Windows laptop on the trip, parts may be unique to windows systems.

(With apologies for taking ages to get round to completing some of the info)

3 Likes

Installing adb/fastboot/drivers on windows

Personally, I’m not a huge fan of downloading software and drivers from unofficial sources. Unfortunately, windows usually does not recognise Android Debug Bridge devices natively, so we have to a little bit more work. But here’s a guide to get everything we need from official download sources.

  1. Get just the Android command-line tools from the Google Android Studio Download page. You’ll probably need to scroll down a bit to get to the command-line tools only version.

  2. Install the package (take a note of where you install it), and at the end allow the installer to open the Android SDK manager.

  3. In the android SDK manager, uncheck all the options except for Tools > Android SDK Platform-tools and Extras > Google USB Driver and click Install packages.

  4. Find the folder where you installed the android SDK package in step 2. Open the file extras\google\usb_driver\android_winusb.inf with your favourite plain-text editor (wordpad or notepad will do).

  5. Add the FP2 to the ‘catalogue’ for the driver. If you’re on a 32bit Windows, paste the text below under [Google.NTx86]; on 64bit Windows it goes under [Google.NTamd64]. If you’re unsure, it doesn’t hurt to paste it under both. Note that I’ve not actually tested this on 64bit Windows - let me know if it doesn’t work! In case you’re wondering why there are two device ID’s listed below; the first is for Fairphone OS and the second is for Fairphone Open OS.

;FP2 %CompositeAdbInterface% = USB_Install, USB\VID_05C6&PID_9025&MI_01 %CompositeAdbInterface% = USB_Install, USB\VID_2AE5&PID_9039&MI_01

  1. When/if Windows complains it can’t find drivers, use the choose drivers from a list and then ‘have disk’ option (the exact wording depends on your windows version. Point at the directory that contains the file you’ve edited in step 5. Usually you’ll only have to do this once even though the device ID changes when you change between open and non-open Fairphone OS (as we’ve added in both device IDs)

  2. To save a lot of typing, add the location of adb.exe and fastboot.exe to your path: Search for environment variables in the control panel (or in the search box under start). There should be an option ‘Edit environment variables for your account’. Creat a new variable PATH and as value use the full path to where the platform tools are (this ends in android-sdk\platform-tools).

Enabling USB debugging

To activate USB debugging, you need to have access to the developer options under settings. If you don’t see developer options listed, go to ‘about phone’ and scroll down to the build number. Keep tapping the build number, at some point a tap countdown will be shown and eventually the phone will tell you that you’re now a developer. After this, you should be able to find the developer options menu, and enable USB debugging.

Testing whether it works and authorising

Connect the phone and open a command prompt on the computer (in windows search for cmd, or type cmd in the run dialogue - short cut is Win+r) and type adb devices. If the adb server on the computer wasn’t running already it will be started. The last line of the output should begin with the serial number of the phone. If it says ‘unauthorised’, unlock your phone: there will be a dialogue box asking whether you want to authorise the device. You can remember this setting, or remember to authorise again at the beginning of each session. When you flash any system image to the phone, you will need to go through this authorisation again (if the image you flash supports adb anyway).

Switching recovery to Fairphone Open OS recovery

The stock recovery in Fairphone OS 1.5.1 will allow us to do some basic things, such as clearing the cache partition, performing a factory reset, and installing a signed (i.e. official) system update. What it doesn’t allow us to do, is make a backup and install unofficial updates. The latter may be interesting if, for instance, you want install/update Xposed. If you want to know more about this, and as this topic is limited to the efct16 demo, I encourage you to search for more up-to-date (wiki) topics on the forum.

Fairphone open OS comes with a more powerful recovery option, called Team Win Recovery Project (TWRP). There is also a port available here, along with some more information about TWRP. Finally, if you want to discuss pros and cons, see this topic.
One important thing to note is that the Fairphone updater may not play nice with TWRP, so you may have to install system updates manually (which is also explained here).

  1. For the demonstration we used the TWRP version that is included in Fairphone Open OS 16.06. To use it, download a Fastboot image from the code.fairphone.com downloads page. As the links seem to have been cleared up since the release of the newer version, here’s a direct link to Fairphone Open OS 16.06 in case you need/want it. The name of the file you’re looking for ends in image-userdebug.zip.

  2. Unpack the zip file you’ve downloaded, but keep a copy of the zip file if you want to switch to Fairphone Open OS or want follow along the steps to Sailfish.

  3. Open a command line and navigate (cd followed by a directory name to enter it, use tab to auto-complete/cycle through file names. Use dir to list the contents of the current folder) to the folder in which the image has been unpacked.

  4. Make sure the phone is connected. If it is on, with USB-debugging enabled and has your computer authorised for adb, you can reboot into the bootloader (or fastboot mode) by typing adb reboot bootloader. If the phone is off, hold the volume_down button and the power button to boot into the bootloader. You will see a ‘Fairphone powered by Android’ screen - the phone will remain in this state and wait for commands.

  5. You can then flash the recovery image using this command: fastboot flash recovery recovery.img

  6. Reboot the phone by issuing the command fastboot reboot. If you want to go straight to the new recovery, press and hold the volume_up button on the phone before issuing the reboot command/during the reboot. If you want to go to recovery from a normally running system via adb, type adb reboot recovery. If the phone is off, hold volume_up whilst starting the phone.

Making a backup

If all went well, you’ve now accessed TWRP. If TWRP asks you whether you want to mount /system with write access, you can answer no. When TWRP is running, the part of the phone where user data is stored will also be visible in windows. As for the efct16 demonstration we don’t have an SD card, this would be a way to copy that data to the computer. This could also be done via adb. As TWRP does not currently support encryption, this may not work for encrypted data. For other things like apps, app settings, and the system in general, the TWRP backup is more useful. Choose the back up option, select all the partitions you want to backup (in the demo we skipped userdata as this is where the backup is stored if there is no SD-card, and there was no time to test whether this would be a problem). Options to consider are using compression (smaller files, takes more time) and calculating md5 sums (which is a good idea).

As flashing Fairphone Open OS wipes all the data from the phone, having the backup stored in the phone is not very useful. The phone memory should be visible in windows, so the TWRP folder can be copied over that way. Alternatively, if your computer is authorised for adb, you can copy the files from a command prompt: adb pull /storage/sdcard0/TWRP will copy the backup files from the phone to the directory that the command prompt is currently in.

Verifying MD5 sums

It’s always a good idea to check whether files copied from one device to the other were copied correctly. In linux and android, this can be done using the md5 command - the only argument you need is a filename. On Apple systems it appears to be md5sum. In Windows, the easiest way appears to be certUtils -hashfile <file> MD5, where <file> is the file for which you want to calculate the MD5 sum. The sum reported by these commands should be identical on both the source and the target system (ignoring any spaces).

For the backups made using TWRP, a file containing the MD5 sum of the file as it was created by TWRP is usually stored (unless you disable that option). It has the same name as the file that it contains the sum for, followed by .md5. To quickly view the output on the command line in windows, use the type command (the only argument being the md5 file you want to view).

Flashing Fairphone Open OS

This is essentially method 2 from the installation guide. We’re using method 2, as method 1 would result in a complaint from the phone that it can’t install an older version on top of a newer version (though apparently this check will be skipped in future when switching between Fairphone OS and Fairphone Open OS).

  1. In a command prompt, navigate to the folder where you downloaded the Fastboot image for Fairphone Open OS (the zip-file, not the extracted files).

  2. Enter fastboot mode (step 4 in this post)

  3. Flash Fairphone Open OS: fastboot -w update fp2-sibon-16.06.0-image-userdebug.zip

  4. Wait for the phone to restart on its own, this may take a while.

Fairphone Open OS will start with the first-run setup wizard. For the demonstration, we filled in all the data before proceeding to install Sailfish. You may also want to authorise your computer for adb again at this point, in case you want to use it when in recovery.

Installing Sailfish from recovery

At the time of writing, the main Sailfish installation discussion on this forum is in the topic over here. The downloads you’ll need, porting status, release notes and installation instructions for Sailfish are on the Mer wiki.

  1. Download the release for installation from TWRP recovery from the Mer wiki (the fastboot image I tried didn’t work in our specific setup). The file you’re looking for ends in ota.zip.
  2. Copy the downloaded zip-file to the phone. One way of doing this is from the command line: adb push <SailFish....-ota.zip> /sdcard (where the bit between and including <> should be replaced by the path to the zip file you just downloaded.
  3. Reboot into recovery (e.g. adb reboot recovery)
  4. In recovery, choose install, and navigate to where you copied the zip file (in the adb example it would be in /sdcard). Make sure
  • ‘zip file signature verification’ is disabled
  • writing to the system partition is enabled, but
  • wiping the system partition is disabled
    before installing the update.
  1. Reboot (if TWRP asks to root the system, continue without rooting by pressing the button above the slider).

Authorising adb from recovery

Adb is usually accessible when the phone is in recovery mode. If, for some reason, you can’t start the phone normally to authorise the computer that you’re connecting to, there is a way to authorise from TWRP. This doesn’t work on encrypted phones (at least using FPOOOS TWRP), as you need access to /data and the TWRP from FPOOS does not support encrypted /data partitions.

  • Start recovery
  • Copy %user%/adbkey.pub (this is the path on windows; adb should have been run at least once on your computer beforehand) to your phone using the file manager. I’ve put it in the root of the folder tree of the device that is exposed to the computer (which is typically /sdcard on the phone). The file system is made accessible from TWRP, at least when it wasn’t encrypted.
  • On the phone, open a command prompt and type cat /sdcard/adbkey.pub >> /data/misc/adb/adb_keys
  • On the computer stop the adb server: adb kill-server and then start it again, e.g. by adb devices - which should now be listed as authorised.
2 Likes

Restoring the phone to the original state

  • Copy the backup that you made earlier to the phone (start the phone in recovery mode, and copy the files via your computer’s file manager, or (if authorised) for instance adb push TWRP /sdcard
  • In TWRP go to MOUNT and uncheck system RO, so that we can write to the system partition.
  • Use TWRP to restore the backup.

If you also want the original recovery back:

  • Download the binary image for Fairphone OS
  • Unpack the files
  • When in the folder where the unpacked files are, do fastboot flash recovery ./AP/recovery.img
  • Done. (use fastboot reboot to reboot).

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.