Sunday, September 16, 2012

Getting Heimdall to work with the SGH-T989

Apparently the version of the Samsung Galaxy S II used by T-Mobile is closely related to the Samsung Galaxy Tab 10.1, because I was able to use a forked version of Heimdall (the open-source Linux equivalent of the closed-source, binary-only, leaked-from-Samsung Odin) designed for the Galaxy Tab to get a copy of ClockWorkMod Touch Recovery loaded onto my phone.

The regular version of Heimdall (1.3.2 as of this writing) doesn't work with the T-Mobile SGSII (also known by the model number SGH-T989), but there is a bug report on the main Heimdall project's GitHub site which points at a forked version that will work if you massage it properly.

Within the forked version is a piece of code that checks a numeric device type ID. A few IDs are already allowed, but the program will bail on you if the device isn't in the list. Well, the SGH-T989 comes up as a number "30", which wasn't on the list. Here's a patch to fix it (assuming Blogger doesn't mangle things):

diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp
index 1faa626..7359a0d 100644
--- a/heimdall/source/BridgeManager.cpp
+++ b/heimdall/source/BridgeManager.cpp
@@ -1621,10 +1621,15 @@ bool BridgeManager::BeginSession(void)

int deviceType = setupSessionResponse.GetUnknown();

- // TODO: Work out what this value is... it has been either 180 or 0 for Galaxy S phones, 3 on the Galaxy Tab, 190 for SHW-M110S.
- if (deviceType != 180 && deviceType != 0 && deviceType != 3 && deviceType != 190)
+ /* TODO: Work out what this value is...
+ * it has been either 180 or 0 for Galaxy S phones,
+ * 3 on the Galaxy Tab,
+ * 30 on T-Mobile Galaxy S II (SGH-T989),
+ * 190 for SHW-M110S. */
+
+ if (deviceType != 180 && deviceType != 0 && deviceType != 3 && deviceType != 30 && deviceType != 190)
{
- Interface::PrintError("Unexpected device info response!\nExpected: 180, 0 or 3\nReceived:%d\n", deviceType);
+ Interface::PrintError("Unexpected device info response!\nExpected: 180, 0, 3, 30, or 190\nReceived:%d\n", deviceType);
return (false);
}
else


You really only need to add "&& deviceType != 30" into the right spot.

So, the basic basics:

  1. Download the forked version of Heimdall with "git clone git://github.com/marshray/Heimdall.git"
  2. Compile and install Heimdall:
    1. Enter the new "Heimdall" directory with "cd Heimdall"
    2. Read through the various README files, including the "Linux/README" one.
    3. Change into the "libpit" directory and run "./configure && make", then exit the directory upon success.
    4. Change into the "heimdall" directory and run "./configure && make". Upon a successful compile, run "sudo make install", then exit the directory.
    5. Change into the "heimdall-frontend" directory and run "qmake && make". Upon a successful compile, run "sudo make install", then exit the directory.
  3. Download a ClockWorkMod Touch Recovery image by visiting the ClockWorkMod ROM Manager site and finding the "Samsung T-Mobile Galaxy S2". Click on the download link in the second column ("6.0.1.2" as of this writing). For me, this saved as "recovery-clockwork-touch-6.0.1.2-hercules.img"
  4. Reboot your phone into Download Mode with the following procedure:
    1. Plug the USB cable into your phone if it isn't already connected.
    2. Press and hold down both volume keys, followed by holding down the power button. Keep holding down the power button until the phone reboots (a brief vibration happens)
    3. Release the power button but keep holding down the volume buttons (it's okay if you accidentally release the volume buttons momentarily)
    4. The phone will come up, and you can release the buttons.
    5. There will be a prompt saying you're about to enter Download Mode. Press the Volume Up button once to continue.
    6. At this point, you should be in "Odin Mode". (Note that there's a big warning not to reboot the phone when it's in this mode -- as far as I know, it's okay to reboot here unless you're actually transferring data. But, the phone will restart itself after a few minutes if it isn't told to do anything.)
  5. Now, go back to the command line on your Linux box, and run the command "heimdall detect" just to see if the phone is communicating with the computer.
  6. Note: Ideally, there would be a step here where we would dump the recovery image from the phone to make a backup, but apparently that isn't working. The phone is structured in a way that even a screwed up recovery image shouldn't cause insurmountable problems (it shouldn't affect the Download Mode, for instance), but if you're wary, don't proceed.
  7. Upload the recovery image by running "heimdall flash --recovery recovery-clockwork-touch-6.0.1.2-hercules.img". It should only take a few seconds, and the phone should reboot.
  8. To test the recovery image, you can either follow the same steps as outlined in step 4, but with the USB cable removed, or run the command "adb reboot recovery" from the Android SDK with the USB cable plugged in.