GPS on Replicant 6

I use Replicant on my main Samsung S3 mobile phone. Replicant is a fully free Android distribution. One consequence of the “fully free” means that some functionality is not working properly, because the hardware requires non-free software. I am in the process of upgrading my main phone to the latest beta builds of Replicant 6. Getting GPS to work on Replicant/S3 is not that difficult. I have made the decision that I am willing to compromise on freedom a bit for my Geocaching hobby. I have written before how to get GPS to work on Replicant 4.0 and GPS on Replicant 4.2. When I upgraded to Wolfgang’s Replicant 6 build back in September 2016, it took some time to figure out how to get GPS to work. I prepared notes on non-free firmware on Replicant 6 which included a section on getting GPS to work. Unfortunately, that method requires that you build your own image and has access to the build tree. Which is not for everyone. This writeup explains how to get GPS to work on a Replicant 6 without building your own image. Wolfgang already explained how to add all other non-free firmware to Replicant 6 but it did not cover GPS. The reason is that GPS requires non-free software to run on your main CPU. You should understand the consequences of this before proceeding!

The first step is to download a Replicant 6.0 image, currently they are available from the replicant 6.0 forum thread. Download the file and flash it to your phone as usual. Make sure everything (except GPS of course) works, after loading other non-free firmware (Wifi, Bluetooth etc) using "./ i9300 all" that you may want. You can install the Geocaching client c:geo via fdroid by adding as a separate repository. Start the app and verify that GPS does not work. Keep the file around, you will need it later.

The tricky part about GPS is that the daemon is started through the init system of Android, specified by the file / Replicant ships with the GPS part commented out. To modify this file, we need to bring out our little toolbox. Modifying the file on the device itself will not work, the root filesystem is extracted from a ramdisk file on every boot. Any changes made to the file will not be persistent. The file / is stored in the boot.img ramdisk, and that is the file we need to modify to make a persistent modification.

First we need the unpackbootimg and mkbootimg tools. If you are lucky, you might find them pre-built for your operating system. I am using Debian and I couldn’t find them easily. Building them from scratch is however not that difficult. Assuming you have a normal build environment (i.e., apt-get install build-essentials) try the following to build the tools. I was inspired by a post on unpacking and editing boot.img for some of the following instructions.

git clone
cd android_system_core/
git checkout cm-13.0 
cd mkbootimg/
gcc -o ./mkbootimg -I ../include ../libmincrypt/*.c ./mkbootimg.c
gcc -o ./unpackbootimg -I ../include ../libmincrypt/*.c ./unpackbootimg.c
sudo cp mkbootimg unpackbootimg /usr/local/bin/

You are now ready to unpack the boot.img file. You will need the replicant ZIP file in your home directory. Also download the small patch I made for the file: Save the patch as replicant-6-gps-fix.diff in your home directory.

mkdir t
cd t
unzip ~/ 
unpackbootimg -i ./boot.img
mkdir ./ramdisk
cd ./ramdisk/
gzip -dc ../boot.img-ramdisk.gz | cpio -imd
patch < ~/replicant-6-gps-fix.diff 

Assuming the patch applied correctly (you should see output like "patching file" at the end) you will now need to put the ramdisk back together.

find . ! -name . | LC_ALL=C sort | cpio -o -H newc -R root:root | gzip > ../new-boot.img-ramdisk.gz
cd ..
mkbootimg --kernel ./boot.img-zImage \
--ramdisk ./new-boot.img-ramdisk.gz \
--second ./boot.img-second \
--cmdline "$(cat ./boot.img-cmdline)" \
--base "$(cat ./boot.img-base)" \
--pagesize "$(cat ./boot.img-pagesize)" \
--dt ./boot.img-dt \
--ramdisk_offset "$(cat ./boot.img-ramdisk_offset)" \
--second_offset "$(cat ./boot.img-second_offset)" \
--tags_offset "$(cat ./boot.img-tags_offset)" \
--output ./new-boot.img

Reboot your phone to the bootloader:

adb reboot bootloader

Then flash the new boot image back to your phone:

heimdall flash --BOOT new-boot.img

The phone will restart. To finalize things, you need the non-free GPS software components glgps, and gps.cer. Before I used a complicated method involving to extract these files from a CyanogenMod 13.x archive. Fortunately, Lineage OS is now offering downloads containing the relevant files too. You will need to download some files, extract them, and load them onto your phone.

mkdir lineage
cd lineage
unzip ../
adb root
adb wait-for-device
adb remount
adb push system/bin/glgps /system/bin/
adb push system/lib/hw/ /system/lib/hw/
adb push system/bin/gps.cer /system/bin/

Now reboot your phone and start c:geo and it should find some satellites. Congratulations!

13 Replies to “GPS on Replicant 6”

  1. Hi Simon, I am continuing the tread on proprietary GPS blob from the replicant wiki forum. Yesterday I was, thanks to you, able to get permanent file with uncommented last lines. However, the GPS still does not work. the GPS icon etc is there but no signal whatever app I tried. I remember that it worked when I was on replicant 4.2. Now I read that you were talking about the recovery image from replicant? I am confused…Does the GPS really works on your device? Thanks in advance for your feedback.

    • Hi Thomas. Yes GPS works for me with the latest replicant-6 builds. Did you install /system/bin/glgps etc? Try ‘adb shell’ and ‘ps|grep gps’. You should see ‘glgps’ running.

      You talked about not being able to flash boot.img, why was that? And you mentioned you used TWRP, so maybe you want to try the replicant recovery image instead.


      • Thanks for your quick reply.
        yes indeed glgps is running but I am not picking any gps signal with 3 different apps and even when I am on the street.
        I could not use fastboot to flash boot.img, so my idea was to copy it into the replicant6-i9300 and rezip the whole distrib and install with TWRP (because it does not ask for signature). However, I realized that I could use heimdal to inly flash the boot.img file.

        • What does ‘adb logcat|grep -i gps’ show? You should see something related to acquiring GPS information.

          Indeed fastboot does not work on the S3! I describe how to use heimdall in my post.


          • Yes thank you, your blog is bookmarked forever now :-).
            Now GPS is working, I did a full factory reset… I think I have played to much with directories and files permissions.
            Thanks forever!

  2. Hurray! Thanks for confirming, always good to hear that the instructions are reproducible.


  3. Thank you very much for your effort and explanations!

    I could follow al steps until I had to download LineageOS 13 for i9300. I went to, which led me to, that contains the same as

    Problem is that there are no “experimental” (they were only available for 2 months since the LineageOS started) but “nightly” builds, which only have the file “build.prop” in system directory.

    I searched in those mentioned sites and in Also in, but no luck.

    Any idea where I can download a “proper” and official archived LineageOS 13 (I mean, with all files)?

    PS:I don’t trust custom/unofficial ROMS, but I guess XDA-Developers could be a good place to check (

  4. Thank you very much for your instructions! They work like a charm.

    My problem is that I didn’t realize LineageOS experimental builds would be available only for two months ( and as I didn’t download any, now I can’t find one. I’ve been downloading Android 6 and CM 12 ROMs for two days and no one has those files (they’re meant to flash them directly from “update zip” option in the recovery) so I can’t get the needed files.

    Does anyone know a place to download an official (or valid, at least) ROM with those files for the i9300?

  5. I think I’ve just found one: Slim 6 for i9300 ( It has almost all the files (no


    Copied ./system/lib/hw/ to ./system/lib/hw/ but I don’t have the proper USB cable to copy files via adb to the device. I’ll report my progresses.

  6. Trying the trick of copying ./system/lib/hw/ to ./system/lib/hw/ didn’t work my problem out.

    After 3 days searching the web I couldn’t find neither a ROM that contains that file ( nor the file itself. 🙁

  7. I finally figured out how to get needed files. Actually, just bumped into it:

    Downloaded last (14.1) NIGHTLY LineageOS file for i9300. At the present moment they’re releasing 7.*(Nougat), not 6.* (Marshmallow) versions, but following previous instructions got all needed files to upload them to the phone following Simon’s instructions.

    Unfortunately, I have opened SatSat and OsMand~ apps for a while now and S3 can’t find any satellites (I’m indoors, but the phone is near the window that faces a wide open space).

    Recently, my phone fell down and broke the screen glass. Don’t know if GPS sensors have been affected.

  8. Finally got it working (I guess: GPS apps work). I’ll have to try it’s accuracy outdoors, but it finds satellites pretty fast indoors.

    I MUST WARN YOU: Installing proprietary firmwares is always dangerous because you don’t know what the firmware does. I think it’s specially dangerous installing proprietary firmwares of unknown ROMs. If you do so, do it at your own risk!

    I downloaded CRDroid Marshmallow ROM ( and followed instructions (I couldn’t get to work but I didn’t need it) and pushed all GPS-related files I found:

    (from the mounted “system”)
    adb push ./bin/glgps /system/bin/
    4366 KB/s (1930424 bytes in 0.431s)
    adb push ./bin/gps.cer /system/bin/
    291 KB/s (15014 bytes in 0.050s)
    adb push ./bin/ /system/bin/
    2 KB/s (113 bytes in 0.046s)
    adb push ./etc/gps.conf /system/etc/
    5 KB/s (263 bytes in 0.046s)
    adb push ./etc/gps.xml /system/etc/
    33 KB/s (1591 bytes in 0.046s)
    adb push ./etc/permissions/android.hardware.location.gps.xml /system/etc/permissions/
    20 KB/s (942 bytes in 0.044s)
    adb push ./lib/hw/ /system/lib/hw/
    2494 KB/s (59032 bytes in 0.023s)


  9. WARNING: Installing proprietary blobs is dangerous because you don’t know what those blobs do and if you install them incorrectly you can brick your phone. Even more if you don’t know or trust the people that provide those blobs. Use the following instructions at your own risk!

    As I couldn’t find any LineageOS 13 EXPERIMENTAL zip to download (those had all the needed files and I trust LineageOS project) I finally downloaded one Marshmallow ROM (Android 6.0) for i9300 I could find (I don’t know if they’re worth my trust, but took thje risk): crdroid (

    Followed the instructions explained in, executed “adb remount rw /system” (without “”) and adb “pushed” every “*gps*” file I could find in my mounted system to the same directory with the same name in the /system’s phone.

    Restarted and GPS programs finds satellites pretty fast (SatSat, for instance). I tested it indoors and it’s not as accurate as I would like. I’ll have to test it outdoors.

Leave a Reply

Your email address will not be published. Required fields are marked *