Alternate Android firmware on Samsung Galaxy S

Vincent Bernat

I have bought a Sam­sung Gal­axy S An­droid phone some time ago. One of the first things that you try to do with such a phone is to switch to some al­ter­nate firmware (the coined term is “ROM”), like CyanogenMod. Flash­ing a firmware is a whole new uni­verse. You are told about a lot of pro­pri­etary tools, you need to down­load a lot of things from MegaUpload and friends and no­body re­ally ex­plains what is go­ing on un­der the hood. I was a bit lost at first.

I will not pro­vide a step-by-step guide since I can­not af­ford to stay up-to-date. Such a guide is usu­ally posted on some fo­rum. It as­sumes you are run­ning Win­dows and pro­vides ap­pro­pri­ate down­load links. You must fol­low it (and check that it is re­cent enough). I will just pro­vide you some back­ground to un­der­stand these guides.

Android firmwares#

There are sev­eral An­droid firmwares. Most of them are spe­cific to a given phone (or its close vari­a­tions). They can be sorted in three cat­egories:

  1. Of­fi­cial firmwares from the phone man­u­fac­turer in­clude a ker­nel with ap­pro­pri­ate driv­ers and, usu­ally, a cus­tom­ized in­ter­face (HTC Sense for HTC, TouchWiz for Sam­sung). Some man­u­fac­tur­ers will lag a lot be­hind An­droid sched­ule and you may not get all the new shiny features.

  2. Mod­i­fied firmwares are built from the of­fi­cial firmwares. They usu­ally add a lot of hacks on top of the orig­i­nal firmware, re­move some cruft but are still closely re­lated to the of­fi­cial firmware.

  3. Firmwares built from An­droid Open Source Project (the open source ver­sion of An­droid) do not share any­thing with the of­fi­cial firmware ex­cept some bits re­lated to the ker­nel (driv­ers, hacks).

Darky ROM#

Darky ROM is a mod­i­fied firmware. It takes the orig­i­nal firmware from Sam­sung, adds a cus­tom ker­nel (based on the source of the of­fi­cial ker­nel), adds a lot of hacks, some ad­di­tional ap­pli­ca­tions and re­moves some un­wanted cruft. This is a very nice firmware which is quite snappy. This is a drop-in re­place­ment for the de­fault firmware: you will only get im­provements.

CyanogenMod#

CyanogenMod is a firmware built from AOSP. It sup­ports sev­eral de­vices and pro­vides a uni­fied firmware on all of them. Sup­port for the Sam­sung Gal­axy S is re­cent and is not present in the sta­ble build. How­ever, some RC build is now avail­able. Be sure to read the FAQ (most no­tably the part say­ing that you need to in­stall from Froyo 2.2 be­cause the boot­loader pro­vided by Sam­sung with Gin­ger­bread 2.3 is not com­pat­i­ble). You can also grab some in­for­ma­tion from the wiki.

The ma­jor draw­back of us­ing this firmware in­stead of go­ing for a mod­i­fied firmware like Darky ROM is that the bat­tery life may suck. I now need to charge my phone ev­ery day in­stead of once ev­ery two days. On the plus side, you get a very clean firmware with a lot of fea­tures and al­most no cruft. For ex­am­ple, the no­ti­fi­ca­tion bar can be cus­tom­ized and OpenVPN is avail­able out of the box.

Up­date (2011-07)

Af­ter a few weeks, the bat­tery life is sim­i­lar to what the orig­i­nal firmware pro­vides. Maybe it was just a cal­i­bra­tion problem.

More­over, al­most ev­ery­thing is open source (if you do not in­stall Google apps). You can see this firmware as an open source dis­tri­bu­tion for your phone. There is no need to down­load ran­dom files linked from a ran­dom fo­rum to make it work. There is no pack­age man­ager, though. De­spite the bad bat­tery life, I pre­fer this firmware.

Prerequisites#

Be­fore try­ing to flash a new firmware, there are some tools that you need to have. Note that you do not need root ac­cess to flash a new firmware.

Download & recovery mode#

Be­fore try­ing to in­stall any firmware, you must check that your phone can ac­cess down­load and re­cov­ery modes. The down­load mode al­lows you to flash any new firmware, even if the cur­rent firmware does not boot at all. As long as this mode is avail­able, there is very lit­tle chance that you brick your phone. To ac­cess these modes, you need to use the “three-but­ton combo.” Here are the steps (your phone should not be plugged):

  1. Power off the phone (wait for the phone to vibrate).
  2. Hold the “Vol­ume down” but­ton for down­load mode. Hold the “Vol­ume up” but­ton for re­cov­ery mode.
  3. Hold the “Home” button.
  4. Hold the “Power” but­ton. The phone will start.
  5. Once you have the Sam­sung logo dis­played on the screen, re­lease the “Power” button.
  6. Only re­lease the two other but­tons when you en­ter the re­cov­ery mode or down­load mode. The re­cov­ery mode dis­plays a menu. The down­load mode dis­plays a big yel­low An­droid logo.

If af­ter ten tries, you are un­able to ac­cess these modes, maybe they have been dis­abled. Keep read­ing, there is a solution.

Heimdall#

Heim­dall is a tool to flash a new firmware to your phone. This is not a manda­tory tool but you will have to use it if some­thing goes wrong. Most guides will tell you to use Odin. It is a leaked Sam­sung tool run­ning on Win­dows only. You can use Heim­dall instead.

$ git clone https://github.com/Benjamin-Dobell/Heimdall.git
Cloning into Heimdall...
remote: Counting objects: 423, done.
remote: Compressing objects: 100% (271/271), done.
remote: Total 423 (delta 220), reused 332 (delta 138)
Receiving objects: 100% (423/423), 5.91 MiB | 962 KiB/s, done.
Resolving deltas: 100% (220/220), done.
$ cd Heimdall/heimdall
$ sudo apt-get install libusb-1.0-0-dev
$ ./configure && make
[…]
$ sudo cp 60-heimdall-galaxy-s.rules /etc/udev/rules.d
$ sudo /etc/init.d/udev reload

You need to use this tool while in down­load mode. You can test it, while in down­load mode, with:

$ ./heimdall print-pit

This will dis­play the par­ti­tion ta­ble of your phone. This is en­light­en­ing to know what it contains:

  • IBL+PBL is the boot loader, be ex­tra care­ful with it;
  • PIT is the par­ti­tion table;
  • EFS con­tains some im­por­tant data like IEMEI, be ex­tra care­ful with it;
  • SBL is the sec­ond boot loader;
  • SBL2 is the backup of the sec­ond boot loader;
  • PARAM con­tains some im­ages used at var­i­ous stages of the boot process;
  • KERNEL is the kernel;
  • RECOVERY is the backup of the kernel;
  • FACTORYFS con­tains /system file sys­tem which is some kind of root file system;
  • DBDATA con­tains /data file sys­tem which is the data­base to store ap­pli­ca­tion pa­rameters;
  • CACHE con­tains /cache file sys­tem which con­tains the Dalvik cache;
  • MODEM con­tains the firmware for the modem.

As we will see, Heim­dall is able to flash any of these par­ti­tions with flash sub­command.

adb#

adb stands for An­droid De­bug Bridge. Among other things, this tool al­lows you to drive your phone through the USB con­nec­tion. You can get a shell, re­boot into down­load or re­cov­ery mode, push files to your An­droid de­vice, etc.

To get this tool, you need to down­load the full An­droid SDK.

$ tar zxvf ~/download/android-sdk_r11-linux_x86.tgz
$ cd android-sdk-linux_x86
$ tools/android update sdk
[select Android SDK Platform-tools]
$ platform-tools/adb shell
# uname -a
Linux localhost 2.6.35.7-I9000XWJVH-CL184813 #Dark_Core_2.4 PREEMPT Mon May 16 15:02:38 EEST 2011 armv7l GNU/Linux

The im­por­tant com­mands are:

  • shell to get a shell on the device;
  • reboot recovery to re­boot in re­cov­ery mode;
  • reboot download to re­boot in down­load mode;
  • push to put a file on the phone;
  • pull to re­trieve a file;
  • install to in­stall an ap­pli­ca­tion from its APK;
  • logcat to see the logs and what hap­pens, very useful!

Restore download mode#

If your phone is miss­ing down­load mode, you can re­cover it with the help of adb and heimdall. You need to grab some of­fi­cial firmware and ex­tract boot.​bin and Sbl.​bin from it.

$ adb reboot download
$ heimdall flash --primary-boot ~/download/boot.bin --secondary-boot ~/download/Sbl.bin

Be ex­tra care­ful here. You may brick your phone. Dou­ble check that you grab the cor­rect files and that they are re­ally for your phone (there ex­ists some vari­ants). It worked for me.

Installing a new firmware#

While you can switch from one firmware to an­other with­out los­ing your data, it is bet­ter to wipe your sys­tem and your data be­fore switch­ing firmware. This means that you will lose all your ap­pli­ca­tions and the data in­side them (list of con­tacts, SMS, pref­er­ences). How­ever, noth­ing will ever mod­ify your data in the in­ter­nal SD card or in the ex­ter­nal SD card (which are both in­side the phone). They usu­ally con­tain your mu­sic and your photos.

There are two ways to in­stall a firmware:

  1. via Heimdall, or
  2. us­ing the recovery.

Heimdall#

When a guide tells you to use Odin, you can use Heim­dall in­stead. Odin takes a TAR file. You should un­tar it and use its con­tent with Heim­dall. For example:

$ ./heimdall flash --repartition --pit s1_odin_20100512.pit \
>                  --factoryfs factoryfs.rfs \
>                  --cache cache.rfs --dbdata dbdata.rfs \
>                  --param param.lfs --modem modem.bin \
>                  --kernel zImage --secondary-boot Sbl.bin
Claiming interface again...   Success
Setting up interface...   Success
Beginning session...
Handshaking with Loke...   Success

Uploading PIT
PIT upload successful
Uploading SBL
100%
SBL upload successful
Uploading KERNEL
100%
KERNEL upload successful
Uploading MODEM
100%
MODEM upload successful
Uploading PARAM
100%
PARAM upload successful
Uploading FACTORYFS
100%
FACTORYFS upload successful
Uploading DBDATAFS
100%
DBDATAFS upload successful
Uploading CACHE
100%
CACHE upload successful
Ending session...
Rebooting device...

You may be in­ter­ested to up­date your mo­dem us­ing Heim­dall. This is usu­ally in­de­pen­dent of the firmware you want to use. Also, no need to pro­vide a PIT file if you do not want to repar­ti­tion. Heim­dall can read the cur­rent one and flash only one of the par­titions.

Recovery mode#

The base re­cov­ery shipped with the Sam­sung Gal­axy S does not have a lot of op­tions. More­over, it may be locked and will ac­cept to in­stall only signed firmwares. Most firmwares come with ClockWorkMod, a more ad­vanced re­cov­ery. Once you get it, you will be able to use any ZIP file to in­stall a new firmware.

My ad­vice is to try to get ClockWorkMod as soon as pos­si­ble. If you are root, you can in­stall ROM Man­ager that will in­stall it for you. If you are not root, most cus­tom firmwares will pro­vide ClockWorkMod. There­fore, you can in­stall a cus­tom firmware with Heim­dall. There ex­ists spe­cial firmwares just for this, like EZbase. If you want to in­stall CyanogenMod, be sure to down­load a Froyo firmware, not a Gin­ger­bread one.

Keep in mind that the re­cov­ery is lo­cated in­side the ker­nel. It is not self-con­tained in the boot­loader (un­like down­load mode). If you do not want to flash a whole firmware (and lose ev­ery­thing on your phone) just to get the re­cov­ery, you can just flash the kernel.

The ClockWorkMod re­cov­ery comes with a util­ity to backup your whole phone. This way, you can eas­ily re­store your pre­vi­ous firmware if you do not like the cur­rent one. This is what is called a Nan­droid backup.

Lagfix#

A lot of guides will tell you to en­able or dis­able lag­fix. Sam­sung shipped the Gal­axy S with some crappy filesys­tem called RFS (which is some kind of “en­hanced” FAT). It is slow and seems re­spon­si­ble for some lags that may hap­pen on the in­ter­face. A lag­fix is a way to re­place this filesys­tem by some­thing bet­ter, like EXT4 or YAFFS2. The process is pretty straight­for­ward and con­sists of back­ing up all the par­ti­tions to the SD card, re­for­mat it with an­other filesys­tem and re­store the backup.

The lag­fix may be ap­plied au­to­mat­i­cally with some firmware (like CyanogenMod) or you may re­quest it in the re­cov­ery mode (most mod­i­fied firmwares work this way). In this case, it will be ap­plied au­to­mat­i­cally on the next boot. You should dis­able it be­fore in­stalling an­other firmware with the re­cov­ery mode (no need if you in­stall it with Heimdall).

Applications#

You can find many free (as in free speech) ap­pli­ca­tions for An­droid. Un­for­tu­nately, An­droid Mar­ket does not al­low one to use this cri­te­ria as a fil­ter. F-Droid is an al­ter­nate mar­ket fea­tur­ing only FOSS ap­pli­cations.

Here is a short se­lec­tion of free ap­pli­cations:

  • ADW.Launcher is a home re­place­ment app. It is very con­fig­urable and themable.
  • K-9 Mail is a very nice email client.
  • Xab­ber is a XMPP/Jabber client.
  • ConnectBot is an SSH client (as well as a terminal).
  • DroidWall is an ap­pli­ca­tion fire­wall (us­ing Net­fil­ter). It lets you se­lect which ap­pli­ca­tion can ac­cess the In­ter­net de­pend­ing on your con­nec­tion (wifi or 3G).
  • Bar­code Scan­ner de­codes 1D/2D bar­code in­clud­ing QR codes.
  • OsmAnd is a re­place­ment for Google Maps us­ing OpenStreetMap. The free ver­sion on An­droid Mar­ket is out-dated. Buy the “plus” ver­sion or down­load it through F-Droid.

An­other must-have ap­pli­ca­tion is Ti­ta­nium Backup which al­lows you to backup any ap­pli­ca­tion with data. Un­for­tu­nately, this is not a free (as in free speech) ap­plication.