Installing LineageOS 15.1 with microG on a Samsung Galaxy S5 (klte, SM-G900F)

This is a brief report on how to flash LineageOS 15.1 with microG on a Samsung Galaxy S5 (klte, SM-G900F). I use Heimdall on Linux (Ubuntu 16.04.3 LTE) in order to first install the TWRP Recovery tool and then the desired LineageOS 15.1. Note that the procedure works for the version of the Galaxy S5 that is called SM-G900F by Samsung and klte by the Cyanogen and Lineage communities.

Preparation

Before we can boot the Galaxy S5 into recovery mode, we need to activate the developer options menu. Go to Settings -> About Device and tap seven times on the item Build Number. Then go to Settings -> Developer Options and allow USB Debugging (adb).

If you wish to backup the factory software that is installed on the Galaxy S5, you should insert a formatted micro SD card with about 4.5GB free space, or you need that amount of free space in your internal flash memory.

Required Tools

On Linux, we need the Android Debug Bridge (adb) which can be installed on Ubuntu 16.04.3 LTS by

sudo apt-get install libusb-dev adb

We also need the Heimdall tool in order to flash a recovery image to the Galaxy S5. Unfortunately, Ubuntu 16.04.3 LTS provides only version 1.4.1, but for the Galaxy S5, Heimdall 1.4.2 is required. We therefore download Heimdall-v1.4.2.tar from the Gihub Release Page. In order to compile it, we need the following prerequisites on Ubuntu 16.04.3 LTS:

sudo apt-get install build-essential cmake zlib1g-dev qt5-default libusb-1.0-0-dev libgl1-mesa-glx libgl1-mesa-dev

We find a place at which to unpack the sources and then build Heimdall as follows.

tar -xf Heimdall-v1.4.2.tar
cd Heimdall-v1.4.2
md build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make
sudo cp bin/heimdall /usr/local/bin

(Remember that the last step, simply copying the binary to /usr/local/bin is frowned upon because this way the apt package management tool does not know the executable is there nor where it comes from. In any case,

heimdall version

now displays v1.4.2. If it does not, perhaps your PATH ought to be configured so that /usr/local/bin takes precendence over /usr/bin, or you perhaps have the Ubuntu version of Heimdall installed which can be removed with

sudo apt-get remove heimdall-flash heimdall-flash-frontend

Downloads

We download Lineage 15.1 with microG from this repository (for me the build lineage-15.1-20180813-microG-klte.zip works well) and the matching Super User tools addonsu-15.1-arm-signed.zip from their extras page. Our recovery tool in order to deploy the new OS is TWRP. The version twrp-3.2.2-0-klte.img.tar from this repository worked for me.

Installing a Recovery Tool and Flashing the OS

Power off the S5. Then start it in download mode by pressing [home]+[power]+[volume down] and then confirm by pressing [power up]. Connect the Galaxy S5 with your PC via the USB cable and type

sudo heimdall print-pit --no-reboot

You ought to see a blue progress bar on the Galaxy S5 and the partition information printed to your Linux console. This confirms that Heimdall and your Galaxy S5 work together as expected. Disconnect the USB cable and power down the phone. Unpack the twrp-3.2.2-0-klte.img.tar by

tar -xf twrp-3.2.2-0-klte.img.tar

in order to obtain the recovery.img. Start the Galaxy S5 in download mode once more by pressing [home]+[power]+[volume down] and then [volume up]. Now we flash the recovery image by

sudo heimdall flash --RECOVERY recovery.img --no-reboot

You should see a blue progress bar on the phone and a success message in the Linux console. Now you can power down the phone and then boot it in recovery mode by pressing [home]+[power]+[volume up]. As soon as the blue text appears, you can release the buttons. The phone boots into the TWRP recovery tool.

In TWRP, swipe in order to confirm that the phone will be modified (note that a hardware counter in the phone will irreversibly be increased once you flash a new OS, and Symsung will most likely refuse to help you with any software issues as a consequence).

First, you may wish to backup the factory software that is installed on the phone. Therefore, select Backup in TWRP and tick all partitions. Choose the micro SD card as the target for the backup and confirm. With

adb shell

you can traverse the file tree on the Galaxy S5 in order to localize the backup that TWRP has written. In my case, it is located at /external_sd/TWRP/BACKUPS/(seriia-no)/(date-time-devicecode)/ and contains 26 files, among them boot.emmc.win, boot.emmc.win.sha2 and so on, which contain images of the partitions of the factory software. Note that with other versions of Android, the /external_sd might be called differently. You can use

adb pull (path-on-phone) .

in order to copy the files to your PC. You may wish to google a bit in order to find a more convenient way to copy entire directories with adb.

Once you are sure the backup has safely arrived on the PC, you can tap on the back icon (bottom left) in TWRP, go back to the main menu, select Wipe and Adcanced Wipe and wipe the cache, dalvik cache, system, data and internal storage partitions (but not the micro SD card). We copy the zip files with the new OS to the Galaxy S5 by

sudo adb push lineage-15.1-20180813-microG-klte.zip /external_sd/
sudo adb push addonsu-15.1-arm-signed.zip           /external_sd/

go back to the TWRP main menu and use TWRP to install these two zip files. Then select Reboot in TWRP, and your new Lineage 15.1 with micro G is live.

Advertisements

Installing Lineage 14.1 with microG on a Samsung Galaxy S2 (i9100)

This is a brief summary of how I was able to flash Lineage 14.1 with microG on an old Samsung Galaxy S2 (i9100, i.e. the model GT-9100). Unfortunately, the instructions on the Lineage Website are incorrect for the i9100.

Preparation

Before we can boot the i9100 into recovery mode, we need to activate the developer options menu. Go to Settings -> About Phone and tap seven times on the item Build Number. Then go to Settings -> Developer Options and allow Android Debugging (adb).

Tools

I have a Linux PC with Ubuntu 16.04.3 LTS, and I have heimdall version v1.4.1 and the Android Debug Bridge adb version 1:6.0.1+r16-3 installed.

Downloads

  1. The micro-G project release a special build of Lineage with micro G. From their download page I obtained the July 12, 2018 build of Lineage 14.1 with microG in a zip file lineage-14.1-20180712-microG-i9100.zip.
  2. I also plan to get root access, and so I install the matching addonsu-14.1-arm-signed.zip super user tools for Lineage 14.1 from their extras page.
  3. I usually use the TWRP recovery in order to flash new OS’ to smartphones. It turns out that I need an old version of TWRP: twrp-3.0.2-1-i9100.img from the past releases of TWRP (deatils see below).
  4. We also need a custom partition table I9100_1.5GB-System_6GB-Data_512MB-Preload_by-the.gangster.pit from here,
  5. and a version of the Lanchon REPIT partitioning tool lanchon-repit-20170115-system\=1G-data\=same-sdcard\=max-preload\=min+wipe-i9100.zip from here.

Booting into a Custom Recovery (TWRP)

The first difficulty with the i9100 is that it is not enough to use its download mode to flash a recovery partition in order to boot into a custom recovery tool such as TWRP. The stock kernel of the phone simply does not boot into a custom recovery. We need to flash a custom kernel first, before we can even use TWRP. For this, we extract the image boot.img of the boot partition that contains the Lineage kernel from the lineage-14.1-20180712-microG-i9100.zip zip file. This kernel will be able to boot into a custom recovery. Note that this already increases the counter of how many times the i9100 was flashed and voids the warranty.

I understand that the next time I flash a new system to the i9100, this step will be unnecessary (as it then runs the Lineage 14.1 kernel as opposed to the stock kernel), but I have not tested this yet.

The next difficulty is that the boot.img we so obtained, is too large for the boot partition of the stock i9100. This is where we need the custom partition table I9100_1.5GB-System_6GB-Data_512MB-Preload_by-the.gangster.pit.

I also found out by trial and error that current versions of TWRP fail in this setup. The version 3.0.2 that I list in the Downloads section above works. I cannot tell whether the more recent versions of TWRP are simply broken for the i9100 or whether they are merely incompatible with the Lineage kernel in the boot.img that I am using.

Now we install a custom recovery. Power off the phone. Start it in download mode with [home]+[volume down]+[power] and confirm with [volume up]. Connect the USD cable to the computer and run the command

sudo heimdall flash --repartition --pit I9100_1.5GB-System_6GB-Data_512MB-Preload_by-the.gangster.pit --KERNEL boot.img --RECOVERY twrp-3.1.0-0-i9100.img --no-reboot

from the Linux console. Now we can reboot the phone into our custom recovery mode by pressing [home]+[volume up]+[power]. TWRP is up and running on the i9100.

Flashing Lineage 14.1 with micro-G

Note that at this stage, the i9100 has its flash memory partitioned with the preliminary partition layout. In particular, it does not have a data partition. We need to repartition again with Lanchon REPIT before we can flash the final system.

The Lanchon REPIT tool gets its instructions of how to repartition from its own file name (funny method of getting the configuration to the phone, but why not). So we rename it and transfer it to the /tmp directory of the i9100. Connect the USB cable to the computer and run the following commands in a Linux console.

mv lanchon-repit-20170115-system\=1G-data\=same-sdcard\=max-preload\=min+wipe-i9100.zip lanchon-repit-20180715-system=1G+wipe-data=6G+wipe-sdcard=max+wipe-preload=min+wipe-i9100.zip

sudo adb push lanchon-repit-20180715-system\=1G+wipe-data\=6G+wipe-sdcard\=max+wipe-preload\=min+wipe-i9100.zip /tmp/

Then we can use the TWRP menus in order to install this zip file. The repartitioning takes a minute or two and should finish without any errors. Now the i9100 has got the usual partitions Dalvik/ART Cache, Cache, System, Data and Internal Storage.

Then we copy the Lineage 14.1 zip archive and super user tools to the internal flash memory of the i9100:

sudo adb push lineage-14.1-20180712-microG-i9100.zip /sdcard1/
sudo adb push addonsu-14.1-arm-signed.zip /sdcard1/

and use the TWRP menus in order to install these two zip files. Now we can reboot, and Lineage 14.1 with micro-G is up and running in the i9100.

Root Access

In the new Lineage 14.1, go to Settings -> About 7.1.2 and tap seven times on the item Build Number in order to activate the developer options menu. Then go back to Settings -> Developer Options and enable superuser access. I usually allow adb connections superuser access as well.

Credits

Getting this procedure to work took me about five failed attempts although I had already flashed a Galaxy S3 (i9300) and an S5 (klte). This was mainly because the instructions on the Lineage pages are incorrect and it took a while to collect all the bits and pieces from various sources. The XDA Developers Forum provided some key hints in order to solve the remaining riddles. Thank you!

 

Using Arduino as an ISP to Program a Standalone ATmega 328P (Including Fuses)

The advantage of the Arduino architecture is that you can set up the development environment in no time. It probably takes you less than 10 minutes until the microcontroller (MC) finally blinks your first LED. This ease of use has made Arduino so popular among hobbyists. At some point, however, you wish to go beyond Arduino, produce standalone prototypes that may not require the USB connection nor the boot loader. You may also wish to tinker with the fuses that configure the MC at the hardware level and use clocks other than Arduino’s 16 MHz. In this project, we

  • turn Arduino into an ISP (in-system programmer) that can program other Atmel MCs
  • assemble a standalone setup of an ATmega 328P with an external 16Mhz crystal oscillator on a breadboard
  • flash an Arduino program (sketch) onto this ATmega 328P
  • change the fuse settings of the ATmega 328P

Continue reading “Using Arduino as an ISP to Program a Standalone ATmega 328P (Including Fuses)”