There are countless tutorials online on how to jailbreak your iPhone, but among all those it's hard to find information on how to safely restore your already jailbroken iPhone back to its original state. Even less on how to do it so you can still jailbreak/unlock your phone in the future.
After a lot of searching, reading multiple forum posts and sorting through outdated, incomplete, irrelevant and incorrect information, these are the steps that allowed me to restore jailbroken iPhone 3G with firmware version 3.1.2 and keep it at that firmware revision. Your mileage may vary.
Short back-story... My wife just bought used iPhone 3G that was already jailbroken by previous owner. Upon closer examination it appeared that the phone owner was a bit of a command line hacker and had plenty of software installed that regular user wouldn't even know what to do with. I also had some concerns about possible backdoors since I noticed VNC and OpenSSH servers installed on the phone. Jailbreak gives root user privileges on the device and, combined with just these applications alone, previous owner would have unrestricted access to screen, storage and any command execution. I decided to completely erase all traces of jailbreak and any third party applications, just in case.
Luckily, iTunes gives you just such option as soon as you plug your iPhone into your computer. Just click the restore button in iTunes and it will return your phone to its virginal state (or restore your previous backup, if you had one). Unlucky for us, by default it forces you to upgrade to latest OS version (3.1.3) and modem firmware (05.12.01), which at this time is very problematic (some say impossible) to jailbreak and unlock. After some looking around I found that you can force iTunes to restore from specific firmware file if you hold Shift key in Windows, or Option/Alt key in Mac while clicking on restore button. I found the firmware restore file here and a multitude of good tutorials on jailbreaking and unlocking iPhone here and here.
Here are the steps for impatient:
- download firmware version 3.1.2 from here or here, it should be saved as .ipsw file
- make sure to choose firmware for your model of iPhone/iPod Touch
- open iTunes and connect your device
- hold Shift key (Alt/Option key on Mac) and click "Restore"
- a file dialog will open and let you choose the downloaded .ipsw file
- wait until the firmware is restored
- you will be prompted to activate your phone, this step requires SIM card of official iPhone carrier