Replicant 4.2 on Samsung S3

Since November 2013 I have been using Replicant on my Samsung S3 as an alternative OS. The experience has been good for everyday use. The limits (due to non-free software components) compared to a “normal” S3 (running vendor ROM or CyanogenMod) is lack of GPS/wifi/bluetooth/NFC/frontcamera functionality — although it is easy to get some of that working again, including GPS, which is nice for my geocaching hobby. The Replicant software is stable for being an Android platform; better than my Nexus 7 (2nd generation) tablet which I got around the same time that runs an unmodified version of Android. The S3 has crashed around ten times in these four months. I’ve lost track of the number of N7 crashes, especially after the upgrade to Android 4.4. I use the N7 significantly less than the S3, reinforcing my impression that Replicant is a stable Android. I have not had any other problem that I couldn’t explain, and have rarely had to reboot the device.

The Replicant project recently released version 4.2 and while I don’t expect the release to resolve any problem for me, I decided it was time to upgrade and learn something new. I initially tried the official ROM images, and later migrated to using my own build of the software (for no particular reason other than that I could).

Before the installation, I wanted to have a full backup of the phone to avoid losing data. I use SMS Backup+ to keep a backup of my call log, SMS and MMS on my own IMAP server. I use oandbackup to take a backup of all software and settings on the phone. I use DAVDroid for my contacts and calendar (using a Radicale server), and reluctantly still use aCal in order to access my Google Calendar (because Google does not implement RFC 5397 properly so it doesn’t work with DAVDroid). Alas all that software is not sufficient for backup purposes, for example photos are still not copied elsewhere. In order to have a complete backup of the phone, I’m using rsync over the android debug bridge (adb). More precisely, I connect the phone using a USB cable, push a rsyncd configuration file, start the rsync daemon on the phone, forward the TCP/IP port, and then launch rsync locally. The following commands are used:

jas@latte:~$ cat rsyncd.conf
address 127.0.0.1
uid = root
gid = root
[root]
path = /
jas@latte:~$ adb push rsyncd.conf /extSdCard/rsyncd.conf
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
0 KB/s (57 bytes in 0.059s)
jas@latte:~$ adb root
jas@latte:~$ adb shell rsync --daemon --no-detach --config=/extSdCard/rsyncd.conf &
jas@latte:~$ adb forward tcp:6010 tcp:873
jas@latte:~$ sudo rsync -av --delete --exclude /dev --exclude /acct --exclude /sys --exclude /proc rsync://localhost:6010/root/ /root/s3-bup/
...

Now feeling safe that I would not lose any data, I remove the SIM card from my phone (to avoid having calls, SMS or cell data interrupt during the installation) and follow the Replicant Samsung S3 installation documentation. Installation was straightforward. I booted up the newly installed ROM and familiarized myself with it. My first reaction was that the graphics felt a bit slower compared to Replicant 4.0, but it is hard to tell for certain.

After installation, I took a quick rsync backup of the freshly installed phone, to have a starting point for future backups. Since my IMAP and CardDav/CalDav servers use certificates signed by CACert I first had to install the CACert trust anchors, to get SMS Backup+ and DAVDroid to connect. For some reason it was not sufficient to add only the root CACert certificate, so I had to add the intermediate CA cert as well. To load the certs, I invoke the following commands, selecting ‘Install from SD Card’ when the menu is invoked (twice).

adb push root.crt /sdcard/
adb shell am start -n "com.android.settings/.Settings\"\$\"SecuritySettingsActivity"
adb push class3.crt /sdcard/
adb shell am start -n "com.android.settings/.Settings\"\$\"SecuritySettingsActivity"

I restore apps with oandbackup, and I select a set of important apps that I want restored with settings preserved, including aCal, K9, Xabber, c:geo, OsmAnd~, NewsBlur, Google Authenticator. I install SMS Backup+ from FDroid separately and configure it, SMS Backup+ doesn’t seem to want to restore anything if the app was restored with settings using oandbackup. I install and configure the DAVdroid account with the server URL, and watch it populate my address book and calendar with information.

After organizing the icons on the launcher screen, and changing the wallpaper, I’m up and running with Replicant 4.2. This upgrade effort took me around two evenings to complete, with around half of the time consumed by exploring different ways to do the rsync backup before I settled on the rsync daemon approach. Compared to the last time, when I spent almost two weeks researching various options and preparing for the install, this felt like a swift process.


I spent some time researching how to get the various non-free components running. This is of course sub-optimal, and the Replicant project does not endorse non-free software. Alas there aren’t any devices out there that meets my requirements and use only free software. Personally, I feel using a free core OS like Replicant and then adding some non-free components back is a better approach than using CyanogenMod directly, or (horror) the stock ROM. Even better is of course to not add these components back, but you have to decide for yourselves which trade-offs you want to make. The Replicant wiki has a somewhat outdated page on Samsung S3 firmware. Below are my notes for each component, which applies to Replicant 4.2 0001. You need to first prepare your device a bit using these commands, and it is a good idea to reboot the device after installing the files.

adb root
adb shell mount -o rw,remount /system
adb shell mkdir /system/vendor/firmware
adb shell chmod 755 /system/vendor/firmware

GPS: The required files are the same as for Replicant 4.0, and using the files from CyanogenMod 10.1.3 works fine. The following commands load them onto the device. Note that this will load code that will execute on your main CPU which is particularly bothersome. There seems to exist a number of different versions of these files, CyanogenMod have the same gpsd and gps.exynos4.so in version 10.1.3 and 10.2 but the libsecril-client.so differs between 10.1.3 and 10.2. All files differ from the files I got with my stock Samsung ROM on this device (MD5 checksums in my previous blog). I have not investigated how these versions differs or which of them should be recommended. I use the files from CyanogenMod 10.1.3 because it matches the Android version and because the files are easily available.

adb push cm-10.1.3-i9300/system/bin/gpsd /system/bin/gpsd
adb shell chmod 755 /system/bin/gpsd
adb push cm-10.1.3-i9300/system/lib/hw/gps.exynos4.so /system/lib/hw/gps.exynos4.so
adb push cm-10.1.3-i9300/system/lib/libsecril-client.so /system/lib/libsecril-client.so
adb shell chmod 644 /system/lib/hw/gps.exynos4.so /system/lib/libsecril-client.so

Bluetooth: Only one file has to be installed, apparently firmware loaded onto the Bluetooth chip. Cyanogenmod 10.1.3 and 10.2 contains identical files, which has a string in it “BCM4334B0 37.4MHz Class1.5 Samsung D2”. The file I got with my stock ROM has a string in it “BCM4334B0 37.4MHz Class1.5 Samsung M0”. I don’t know the difference, although I have seen that D2 sometimes refers to the US version of a Samsung device. My device is the international version, but it seems to work anyway.

adb push cm-10.1.3-i9300/system/bin/bcm4334.hcd /system/vendor/firmware/bcm4334.hcd
adb shell chmod 644 /system/vendor/firmware/bcm4334.hcd

Front Camera: Two files has to be installed, apparently firmware loaded onto the Camera chip. CyanogenMod 10.1.3 and 10.2 contains identical files, which has a string in it “[E4412 520-2012/08/30 17:35:56]OABH30”. The file I got with my stock ROM has a string in it “[E4412 533-2012/10/06 14:38:46]OABJ06”. I don’t know the difference.

adb push cm-10.1.3-i9300/system/vendor/firmware/fimc_is_fw.bin /system/vendor/firmware/fimc_is_fw.bin
adb push cm-10.1.3-i9300/system/vendor/firmware/setfile.bin /system/vendor/firmware/setfile.bin
adb shell chmod 644 /system/vendor/firmware/fimc_is_fw.bin /system/vendor/firmware/setfile.bin

NFC: I’m happy that I got NFC to work, this was one of my main issues with Replicant 4.0 (see my earlier blog post). Only one file is needed, however CyanogenMod does not seem to distribute it so you have to get it from your stock ROM or elsewhere. The md5 of the file I have is b9364ba59de1947d4588f588229bae20 (and no I will not send it to you). I have tested it with the YubiKey NEO and the Yubico Authenticator app.

adb push clockworkmod/blobs/ee6/7188ca465cf01dd355a92685a42361e113f886ef44e96d371fdaebf57acae /system/vendor/firmware/libpn544_fw.so
adb shell chmod 644 /system/vendor/firmware/libpn544_fw.so

Wifi: I haven’t gotten wifi to work, although I have not tried very hard. Loading the CyanogenMod firmwares makes my device find wireless networks, but when I try to authenticate (WPA-PSK2), I get failures. Possibly some other files has to be loaded as well.

Update: This blog post has been updated since initial posting to use rsync over adb instead of USB tethering, and to mention that I got the ROM building to work.

13 Replies to “Replicant 4.2 on Samsung S3”

  1. Thanks for sharing your experience! It’s true that 4.2 is slower than 4.0 on the Galaxy S 3. I was a bit disappointed to see it too. Graphics would need some work, but I’m way too busy currently to do it.

    Thanks for mentioning the firmwares pages, I simply forgot to update them along with the 4.2 release.

    About GPS: is libsecril-client.so really necessary? I thought it was only used by the audio module. Note that there is source code for it, that was apparently released by mistake by Samsung (it’s free software still): https://github.com/CyanogenMod/android_hardware_samsung/tree/cm-10.2/ril/libsecril-client

    About NFC: Apparently, the CyanogenMod developers have their devices working fine without the loaded firmware. It really depends on which firmware version was burned in the chip on the factory and I know mine won’t work without the loaded firmware. Note that the loaded firmware is in the form of a library that runs on the CPU while it should only be a static array. I’ll modify Replicant to request a static firmware instead and provide a command line to extract only the static firmware from the .so at some point in the future. One shouldn’t have to run proprietary code on the CPU to load a firmware on a chip.

    • Thanks for your work on Replicant!

      Graphics does seem slower, but it is still usable. There is some lag when using the onscreen keyboard, which is probably the worst consequence — but still seems OK.

      My gpsd (from cm 10.1.3) is linked against libsecril-client.so. If I remove the library and try to start gpsd, I get a linker error:

      soinfo_link_image(linker.cpp:1673): could not load library “libsecril-client.so” needed by “/system/bin/gpsd”; caused by load_library(linker.cpp:771): library “libsecril-client.so” not foundCANNOT LINK EXECUTABLE

      Regarding NFC, it just won’t enable itself if I don’t have the library file. I noticed CM had a commit removing the library and doing something else instead, and that was part of the 10.1.3 CHANGES file (for vendor/samsung), so I was expecting that to be in Replicant 4.2? Anyway it would be great to move this firmware into a static file instead of a library, but it is probably more important to work on other things (improve graphics, more devices, etc).

      /Simon

    • Funny you would ask, video recording doesn’t seem to work in replicant 4.2. It worked fine in replicant 4.0 so it is probably just a small problem. I filed a bug about it:

      http://redmine.replicant.us/issues/873

      I have some videos captured with replicant 4.0 using the same phone (back camera), and they are H264 MPEG4-AVC 1280×720 30.3fps 4:2 YUV. There is a setting to switch between resolutions. I’ve been using the default which seems to be 1280×720. Switching to “1020p” is possible, and once I get video recording to work I can try to do a HD video.

      Is there any reason HD shouldn’t work?

      /Simon

  2. By the way, you could probably work around the GPS issue with free software using a bluetooth GPS receiver and a dedicated application that’s in F-Droid!

    • Thanks, I’ll try CalDavSyncAdapter (version 1.8 :-)). I recall that there was a reason I settled for DAVDroid with my Radicale server instead of CalDavSyncAdapter, but for my Google Apps account, I see no reason why I couldn’t use CalDavSyncAdapter. aCal is really painful since it loses the calender sometimes when there is no network connectivity.

    • I have now installed CalDavSyncAdapter 1.8 and I was able to sync against two of my Google calendars.

      For reference, as username I used my Google account email address ‘simon@josefsson.org’, as password a newly generated app-specific password, and a URL in the form of: https://www.google.com/calendar/dav/simon@josefsson.org/events

      The other calendar was a shared calendar, which required me to find the calendar ID for it (shown if you click settings on the calendar) and it looked like this:
      https://www.google.com/calendar/dav/asmkl3mk3kfic72ks91@group.calendar.google.com/events

      Typing in these URLs and the password is not simple on a touch screen, but possible.

      I have tried adding things on the web (they show up on the device), removing that entry on the phone (it is gone on the web), and adding things on the phone (it shows up on the web), and removing that item on the web (it is gone from the phone). So early testing seems fine. I have removed aCal from my home screen now. Thank you!

      /Simon

  3. Pingback: Replicant 4.2 0002 and NFC on I9300 | Simon Josefsson's blog

  4. Hello,

    I try to make the gps work, but even after having installed the required files (those of ,cm-10.1.3-i9300) no application seems to be able to use it.

    I launch gpsd from a terminal on the S3, it seems to work.

    Do you recall all the steps you had to perform to make an application use the gps ?

    Thanks in advance for your help.

    Regards

    • For me it works automatically after a reboot. Just copy the firmware files, and the executable, and make sure to chmod it as described. Good luck 🙂

  5. Pingback: GPS on Replicant 6 – Simon Josefsson's blog