5 Steps to Upgrade From a Hacked iPhone to an iPhone 3G

I know what you’re thinking: “Matt, I hacked my original iPhone. Now I want to share in the iPhone 3G fun, but I’m worried that something horrible will happen if I upgrade to the iPhone 3G.”

Buck up, fellow iPhone hacker. I’ll tell you how to upgrade from your hacked Apple phone and keep all the settings you love from your original iPhone. The good news is that it’s not hard and there’s a set of five steps that will combine the comfort of your old settings with the joy of the new 3G iPhone. I’ll lead you through the steps.

1. Upgrade iTunes and sync your old hacked iPhone

Upgrade to iTunes 7.7 (or whatever the latest version is). Plug your hacked iPhone into your computer and make sure that you sync. When you sync, a backup of your iPhone’s settings data is stored in iTunes. Recharge the power in your old hacked iPhone and turn it off. If you want to be ultra-safe, see my post about how to backup iPhone data.

2. Buy an iPhone 3G

This step is time-consuming, but not hard. Apple has a page for its stores and after 9 p.m. you can check the Apple iPhone availability to find a store that has the new iPhone 3G. Hint: if there are multiple stores in your area, call each to see which has the shortest wait. When you buy the iPhone 3G, you don’t need to mention to the salespeople that your previous phone was hacked. Just buy the iPhone 3G and let them activate the phone in the store.

3. Restore the backup of your hacked iPhone to your iPhone 3G

(If you decide to “start fresh” with your new iPhone 3G and don’t want to restore contacts, bookmarks, music, etc. from your old phone, skip this step.)

Resist the temptation to start immediately customizing your iPhone 3G. You’re just going to override any changes when you restore your old iPhone’s settings anyway. In particular, make sure you keep the passlock (where you have to type a PIN to unlock your iPhone) off for the time being. Go home and plug your new iPhone 3G into the same computer with iTunes 7.7 where you did a sync on your old iPhone. iTunes will ask if you want to register your iPhone. I registered my iPhone, but I don’t think it was necessary — looking back, I think iTunes asked me to register to get permission to send me email offers. Next, iTunes will ask if you want to try 60 days free of MobileMe. I didn’t want that, so I declined. Only after those two offers did iTunes ask if I wanted to set up the new iPhone 3G as a new phone or restore from a backup. The choice looks like:

iTunes offers to restore iPhone

Choose to restore from a backup and the last sync of your old hacked iPhone should be offered as a choice. Let iTunes restore the backup data and settings from your hacked iPhone to your new iPhone 3G. Once it’s done, pretty much everything should be like it was on your hacked iPhone. The iPhone 2.0 firmware adds some new options, so make sure you explore the settings menu and set any new options the way that you want. Also, if your iPhone is configured to fetch email, your email passwords on the new iPhone 3G will be empty. You will need to re-enter your email passwords.

Finally, if you want to use the Apple App Store, you may need to add a credit card or authorize your computer to purchase things, even if you only want to download free applications. I have a personal policy not to put my data where I can’t get it back out, so I tend to buy MP3s instead of buying music with proprietary Digital Rights Management (DRM) from the Apple Store. As a result, my computer had never been authorized to buy things from the Apple Store. To authorize your computer, in the iTunes program click Store->Authorize Computer… and enter your Apple ID. Once your computer is authorized, you might need to click Store->Check for Purchases… if you tried to download an application from the App Store before your computer was authorized.

4. Upgrade your old iPhone to firmware version 2.0

The iPhone running software version 2.0 has been hacked, so there’s no need to keep running old firmware on your old hacked iPhone. Plug your old hacked iPhone into the computer running iTunes 7.7 and make sure that iTunes is running. Under the “Devices” entry on the left hand side of iTunes, when you click on the iPhone device, you should see a screen with a “Check for Update” button. Click that button. I was running firmware version 1.1.1 and at first it offered me firmware version 1.1.4. So I exited iTunes, restarted iTunes, and clicked “Check for Update” again. Then it offered me firmware version 2.0. Click to install firmware version 2.0 on the old hacked iPhone.

5. Erase the settings and data on your old iPhone

One nice thing about the iPhone’s firmware version 2.0 is that it adds a “secure wipe” that attempts to erase all data completely from your iPhone. That means you can sell the old iPhone or give it to a friend without worrying about all those crazy pictures you took, the 1-900 numbers in your contacts, the SMS messages that reveal things you want to keep private, etc. Here’s how to erase everything on your old iPhone. Eject the phone in iTunes, disconnect the phone from the computer, then press Settings, then General, then Reset, then Erase All Content and Settings, then Erase iPhone. You may have to confirm a couple times that yes, you really want to wipe your iPhone. The process takes about an hour, so I connected my iPhone to a cable that was plugged into a power outlet to ensure that the iPhone wouldn’t run out of power in the middle of wiping it.

When the iPhone is finished erasing itself, it’s suitable for giving to a family member or selling on eBay or whatever.

iPhone 3G: Come on in, the Water’s Fine!

If you read all the press on Friday, it sounded like a full-out iPocalypse as Apple’s in-store activation of the iPhone failed, which left a bunch of people steamed. I left a Summize search for [iphone] up in my browser; there were probably 10K+ twitters on Friday that mentioned the iPhone.

By afternoon I noticed that Twitter complaints about the activation and 2.0 firmware were dying off, so my wife and I decided to do a “date night” to wait in line for an iPhone at Valley Fair Mall in Santa Clara. We showed up at 3 p.m., waited in line for two hours and 45 minutes, and had our iPhones ready and activated by 6 p.m. The line moved slower than last year because this year Apple required that you activate the phones in the store. If you don’t want to wait in long lines, a good strategy for Apple products is just to show up later in the day after the initial surge subsides. Last year we waited until evening to buy our first iPhone and the line was only five people long.

Here’s what you need to know: the activation issues were resolved by Friday afternoon, and most of the lines at Apple stores should be pretty manageable now. Apple provides a page to check local iPhone availability. The page looks like this:

Locations to buy iPhone

All three Apple stores in Silicon Valley have iPhones in stock, for example. If there are multiple stores in your area (check this page for Apple store locations and phone numbers), call each one to see who has the shortest line.

I like my iPhone 3G a lot, and plan to do several iPhone-related posts. The main thing you need to know right now is that any snafus on Friday were temporary, and it should be pretty doable to get an iPhone 3G now if you want one.

Hack your iPhone: toolchains and cross-compilers

The iPhone can run “web apps” very easily. These web apps are really just specially-crafted web pages that take advantage of the iPhone’s built-in web browser. Such web apps can be very cool, but they don’t provide the full functionality that you can get from an actual executable program running on the iPhone. A “native app” that runs on the iPhone can read the iPhone’s built-in accelerometer, for example.

So lots of people want to write independent/third-party native apps that run on the iPhone. The problem is that while Apple hasn’t squashed the development of native apps, they haven’t helped, either. For example, Apple hasn’t provided a toolchain to compile programs for the iPhone.

What is a toolchain?

Yeah, I know, it’s been I while since I had my compiler class too. Here’s a rough diagram of what happens when you compile source code into a program:

Compilation process: compiler to assembler to linker

Here’s the process as I recall it. You write code in high-level computer languages such as C, C++, or Objective-C. That gets piped through a compiler (“gcc” in this diagram), which creates assembly code targeted for a certain type of machine architecture such as Intel x86, PowerPC (PPC), or ARM. Most desktop machines, including newer Apple computers, use Intel or Intel-compatible chips. Older Apple computers use PowerPC chips. ARM chips are embedded in lots of popular consumer electronics devices (e.g. the iPod and iPhone).

Now you’ve got assembly code for a particular type of computer chip. That code is processed through an assembler (“as” in this diagram), which spits out actual machine code (also called “object code”) of zeros and ones. In some cases that code can be executed directly. However, usually you have multiple files of object code to combine, or you need to link in built-in functions from system libraries. A linker (“ld” in this diagram) pulls all the object code into one executable program that a user can run.

So what is a toolchain? Roughly, a toolchain is a set of programs that allow you to compile source code into a program. It can include the programs that I just mentioned, plus a host of other programs such as “make” or a debugger that make compiling programs easier.

What is a cross-compiler?

Look back at the diagram above. Typically someone on (say) a newer Apple computer would have an Intel chip inside. So gcc would output assembly code for an Intel chip, and that assembly code would eventually be transformed into an executable program that runs on a Intel chip. That lets you compile and run programs on your own computer.

But nothing in the diagram above says that you have to output assembly code for the same type of computer chip as the machine that you’re running. For example, an Intel-based Apple computer could translate source code into assembly code for an ARM-based machine architecture. That’s called “cross-compiling,” because you’re compiling your code across for a different type of chip.

Why would you want to cross-compile anything? Well, iPods and iPhones are based on ARM chips. Can you imagine trying to compile source code on one of those little devices? It would be a real pain. Cross-compiling solves that problem: you can compile code on a desktop machine for (say) the iPhone, then figure out how to copy your executable program over to the iPhone, and figure out some way to run your program.

What does this have to do with the iPhone?

It’s possible (but currently difficult) to make a working toolchain for Apple computers that cross-compiles code so that the iPhone can run it. Once you have a cross-compiling toolchain, you can write code that runs on the iPhone.

Unfortunately, Apple hasn’t provided any documentation on the application programming interface (API) or system libraries that would allow people to write native applications for the iPhone. Luckily, dedicated people have helped to produce not only a toolchain but also to fill in documentation on the system APIs that the iPhone supports. In the same way that Apple desktop machines have a framework called AppKit, the iPhone has a user-interface (UI) framework called UIKit.

More reading about toolchains/cross-compiling

If you dig deeper into nearly anything I just said about toolchains or cross-compiling, you’ll discover that it’s more complicated than I just laid out. For example, libraries of built-in system functions don’t have to be statically combined into a program. It’s possible to wait until the program is being loaded to execute before linking in a library. And so-called “binutils” provide lots of functionality other than compilation. For an overview of the compilation process, see the book Running Linux for a good description. To learn about linking vs. loading, I enjoyed this Linux Journal article. You can read more about GCC or binutils on the official GNU site. And of course Wikipedia provides a variety of strong articles about the GNU tool chain, linkers, and crosscompiling.

Hack your iPhone: install applications with Installer.app and AppTapp

(By the way, when I talk about “hacking” your iPhone, I mean closer to “modding”. I’m interested in running third-party native applications on my iPhone, and don’t care as much about unlocking the iPhone to work with other carriers.)

I’m amazed at the pace of iPhone hacking. Even a week ago, you’d see multi-step guides to installing apps on an iPhone. Now there’s a program (Installer.app) with a front-end called AppTapp that does everything in a nice graphical user interface (GUI) for you. You don’t have to type a single command, but you will need an Apple computer (either Intel-based or PowerPC-based works).

Disable automatic sync in iTunes

First, plug your iPhone into your computer so that iTunes comes on. On the left-hand side of the screen under “Devices” click on your iPhone, and then on the page that comes up, click so that “Automatically sync when this iPhone is connected” is OFF. It looks like this:

Disable the synchronization in iTunes

(By the way, to grab a screenshot of a window on a Mac and save it to the desktop, you need to hit Command-Shift-4, then the space bar, then click a window. Sheesh.)

Download and run AppTapp

The combination of AppTapp and Installer.app lets you add applications to your iPhone with almost no effort:

– Make sure that iTunes isn’t running. Plug your iPhone into your Apple computer and make sure that iTunes didn’t start running.
– Download AppTapp to your Apple computer from http://iphone.nullriver.com/beta/
– Run it.

That’s pretty much it. iPhone Atlas has the best walkthrough I’ve seen if you want more details about AppTapp/Installer.app or what to do after you’ve run AppTapp. The short version is to update Installer.app first (touch the “Update” tab). Next you want to install the Launcher program (you can only see 16 icons on your iPhone, so installing Launcher ensures that one of those first 16 icons can access other applications).

After that, you’ve got a lot of options. The “Community Sources” package will give you even more choices for applications to install. Installing “OpenSSH” and “BSD Subsystem” is also recommended. Finally, if you install the MobileTerminal application, you can experience the joy of typing “ls” on your iPhone. Walking around with UNIX in your pocket is very nice. 🙂 See the iPhone Atlas guide for screenshots and more info.

If you want to impress your fellow geeks, Lights Off was the first native game for the iPhone and it also looks great. My brother and I had a similar “turn the lights out” game when we were growing up, but it was called Merlin. Now you can play this game on much prettier handheld appliance. 🙂

More Resources

If you’re a Windows person and can’t beg/borrow a Mac from anyone, you might check out iBrickr. It lets you manage ringtones and applications on your iPhone.

If you don’t want to go the AppTapp/Installer.app way on a Mac, you might also check out iFuntastic. iFuntastic lets you tinker with all kinds of things, from ring tones to applications to multiple “home screens.” Each home screen can have a different set of icons. Version 3 was released just a few days ago and the new version adds PowerPC support.

As always, back up your data first, and any of this could (in theory) break your iPhone. I don’t think anything I’ve mentioned would get you in trouble with lawyerfolk, but if you’re worried, you can always play it safe and stick with the built-in applications on the iPhone. If you see errors above or know of another interesting way to install native third-party applications on an iPhone, please mention it in the comments.

Hack your iPhone: back up your data

If you want to hack your iPhone, be prepared for the notion that you can lose all your data or (worst case) turn your iPhone into a useless brick — thus the origin of the word “bricking” a device. Normally if things go awry, the worst that will happen is that you have to restore your iPhone to its initial pristine state. That means that you’d lose your settings and data on the iPhone. So before proceeding with hacking your iPhone, make sure you save off your data as follows.

Windows users

Back up contacts – I don’t use Outlook or Outlook Express, so my contacts are stored using the Windows Address Book (found with Start->Programs->Accessories->Address Book). I exported my contacts as a WAB (Windows Address Book) file and a CSV (comma-separated value) file. Added: in iTunes, plug in your iPhone, click on the iPhone device, then under the “Info” tab, look for the “Contacts” section. Make sure that you check the box for “Sync contacts with:” and select “Windows Address Book”.

Back up photos – On my Windows XP system, iTunes doesn’t copy photos to my desktop computer (annoying!). And each time I plugged in the iPhone, a different dialog window would pop up (also annoying). It looked like this:

Microsoft wizard to suck down camera images

It turns out that these two annoyances cancel out. 🙂 Go ahead and run the “Microsoft Scanner and Camera Wizard” and you can import the pictures on your iPhone and move them to your Windows computer pretty easily.

Back up settings – This sounds horribly low tech, but grab a blank piece of paper and walk through your “Settings” application on the iPhone and just write down each setting. It’s boring, but in 10-15 minutes you’ve got a record of every setting on your iPhone, so it won’t hurt if you have to restore your iPhone to a pristine state. Added: Any time you sync your iPhone to iTunes, iTunes also saves your settings, but I prefer to have a paper backup just in case.

Back up music – I don’t buy music from iTunes; I use MP3s from my music collection. So I had copies of the music on my iPhone somewhere else and didn’t worry about backing up my music.

Back up bookmarks – I use Firefox for my normal bookmarks and Internet Explorer for my iPhone bookmarks. I don’t have that many iPhone bookmarks, so I didn’t worry about saving a safe copy somewhere else. Added: in iTunes, plug in your iPhone, click on the iPhone device, then under the “Info” tab, look for the “Web Browser” section. I checked the checkbox for “Sync bookmarks with:” and selected “Internet Explorer”. Once IE has your iPhone bookmarks, then in Internet Explorer you can click File, then “Import and Export…” to open a wizard. Click “Next”, then “Export Favorites…” and “Next”. The following screen lets you export some or all of IE’s bookmarks (called Favorites). If you don’t change anything, you’ll select all the bookmarks, so just click “Next”, and then you can specify a file where the exported bookmarks will be saved.

Mac users

I assume that your iPhone syncs files to your Apple computer. To be cautious, make backups of whatever data you can by copying photos/file data to an extra-safe location. Any Apple users want to chime in with more specific advice?

Ready to go!

Okay, your data is backed up — you’re all set to begin hacking your iPhone. I’ve only had good experiences so far, but remember that things can go wrong. So back up that data first!