Archive for September, 2008

So I Made My iPhone Say Hello, World…

…with the open source toolchain. It was a real pain until I decided to focus on the easy way. Then it wasn’t hard at all.

For reference, the hard way is on iphone-dev. I spent most of a frustrating, unsuccessful day with that page and its thousands of comments, especially extracting the SDK from the 1GB XCode binaries – you want version 2.5, not a newer version, and use PowerISO to extract it. For what it’s worth, there looks to be an easier way for Cygwin on Windows.

The Easy Way

But the really easy way is to install the development tools on your iPhone.

This requires:

  • a “jailbroken” phone – so you can install open software on it.

    I used Windows QuickPwn and it was easy. Works with the 2.1 firmware, too…

  • a Wi-Fi connection – and get the IP address of your iPhone:
    • open the iPhone Settings application
    • tap Wi-Fi
    • tap the (>) button to the right of your active connection
    • note the IP Address – probably something like, which I use below
  • an SSH client of your choice – Linux and Mac come with ssh clients.

    Windows users can download PuTTY or use the Cygwin Unix layer on top of Windows. Developers running Windows may also want to grab WinSCP for its “Keep Remote Directory Up To Date” feature (more on that in another post).

After the Jailbreak

After your phone is jailbroken, open the Cydia application. It is like the AppStore, but for open software.

Tap “Featured Applications”, then flick to the bottom, and tap OpenSSH, then tap Install, tap Confirm.

When the installation completes, go back to Cydia, tap Search in the bottom-right, and type toolchain. Tap iPhone 2.0 Toolchain, then Install then Confirm. This is a pretty big iPhone application – over 40MB expanded! So, while your iPhone is working on that, let’s go back to the desktop machine.

You should now be able to use ssh (or PuTTY…) from your desktop computer to connect to your iphone, using root as the user, your iPhone’s IP address for the host, and alpine for the password. If you’re using a graphical SSH client like PuTTY, follow its prompts. On Mac/Linux/Cygwin, open a terminal, and type:

      ssh root@
      root@'s password:              [type alpine]

The first time you connect, it may take about 30 seconds, then you should then see a Unix command-line prompt from the iPhone, and it will end with a “#” – which means you are the “root” or administrative user. You’re the boss – congratulations!

First thing you should do as boss is make sure nobody else can be boss – change your password! (No, really, change it now – here’s how…)

    Changing password for root.
    New password:               
    Retype new password:        

Don’t forget this password. :-D If you do, you’ll probably have to jailbreak the phone again to reset it.

After the Toolchain is Installed

OK, so you can ssh into your iPhone, and you’ve installed the toolchain (that installation has completed on your phone, right?).

So, on your desktop with the ssh window into your iPhone, type:

    echo 'main() { printf("Hello, iPhone!\n"); }' > hello.c
    gcc hello.c -o hello
    ldid -S hello

And your phone should say:

    Hello, iPhone!

When I first did this, it was late at night, and I forgot the ldid -S hello, so instead of “Hello, World”, I got:

    # ./hello

The iPhone will only run “signed” code, and since ./hello was not signed, the iPhone killed it. The “ldid -S PROGRAM” signs the program for you. Turns out the iPhone doesn’t care what signature is on the file, just that it is marked with a signature…

So there you go: a usable toolchain on your iPhone, waiting for you to write the next great iPhone program. For real development, you’ll want to use your desktop development environment and something like sshfs, rsync, or WinSCP to copy the files to the iPhone as you edit them, but more on that later… Updated: More is now available for Windows/WinSCP and Linux/sshfs

Comments (55)

So I Just Saw a New iPhone Book

…coming from O’Reilly – the next version of the Open Source Application Development book. Looks like this is the one to get:

iPhone Open Application Development: Write Native Applications Using the Open Source Tool Chain

And Amazon (above) has it for $26.39 preorder – lots better than the $39 direct from O’Reilly.

Leave a Comment

So I Don’t Agree…

So, I don’t agree to be bound by the Apple iPhone Developers SDK

Edit: Apple has lifted the NDA, so I don’t need to agree.

I want to develop applications for the iPhone. I think the App Store
is a great delivery mechanism. I love the phone – it’s a great
interface, a great technology, and it’s in the hands of millions of
consumers – an emerging market and platform with great potential.

I just can not agree to the limitations imposed by Apple’s SDK.

I’m posting this so I can remember the details of why I cannot agree to the Agreement, to call on Apple to resolve the problems, and to call on other developers to help solve the problem.

The Agreement would:

  1. Require me not to share information with anyone but my contractors or employees who are also bound by the NDA (is it time to start an iPhone development company in which anyone can be a contractor?)
  2. Require me not to disable or interfere with any verification or security mechanism of anything produced by Apple, or enable anyone else to do so. Either with the SDK or through other means. Is this intended to prevent jailbreaking? Seems like this one clause could prevent Jonathan Zdziarski from accepting this NDA.

    I wonder how these iPhone SDK Books pass legal muster? Special license from Apple? How does one get such a special license?

There are other restrictions, too, but these cripple the sharing of information within the community and extend far beyond use of the SDK.

There are some restrictions that make sense, such as preserving Apple’s right to develop competing applications, avoiding the complications of media licensing within your application, etc.

Some are clearly intended to protect the cell phone network partner – like limiting bandwidth use (to levels determined by Apple as needed).

But Apple has retained the right to arbitrarily refuse entry to any application – quite the anti-competitive stance for a monopolist!

Nathan Willis has an article on analyzing additional problems with the SDK agreement, in the context of writing GPL software.

And to put the icing on the cake, SDK apps are intentionally crippled by license:

  1. You cannot develop anything with non-SDK APIs. This limits you to writing in your app directory, etc.
  2. You cannot develop anything that will execute code, including plugins or interpreting code, except through the SDK APIs and built-in interpreters.

So, what’s a conscientious objector to do?

  1. Skip the iPhone. Go to Android. (Android is probably a good option even if you do iPhone development…). You’ll be stuck developing for an emulator until actual hardware comes out, hopefully in late 2008, but then you get an open linux environment.
  2. Ignore the overbearing restrictions. Develop applications on the SDK, share information, and move forward anyway. Risk the Wrath of Steve, even though this approach is probably best for Apple and the iPhone community. Note that this in NO WAY constitutes legal advice, and you do this at your own risk. Heh.

    Of course, you could also just follow the restrictions, and not share anything with the community, too… But that’s not acceptable!

  3. Stick to Web development. There are lots of interesting libraries and APIs available, and nobody can tell you what (not to) develop. You can target non-iPhone platforms at the same time, but you don’t get access to most of the interesting iPhone features, like the touchscreen and accelerometer, to say nothing of basic functionality like local storage and offline use.
  4. Stick to open iPhone Development. This lets you get at all the good stuff on the iPhone – all the internal APIs that Apple actually uses, no restrictions on what your application can do – but you can only deploy to jailbroken phones. No AppStore for you!
  5. Or maybe, just maybe…

  6. Can you have the best of both worlds? Maybe you have a friend who is already an iPhone SDK developer. You can stay on the open side of the fence, and your friend can port it to the SDK. Note that the sharing has to be one-way – your partner can’t give you SDK information unless you accept the NDA – but this could be a way to do open development but keep the AppStore door open.
  7. Note that even with this way around the restrictions, the SDK and AppStore do
    restrict what your application can do, can be, and can look like. Not much you can do about it if you want to publish in the App Store, but at least you can still develop completely open software…
  8. And one final candidate:

  9. Can you do the “partner” method on your own? Can you develop open applications without the SDK, and bring them in from the cold on your own, without violating the NDA? Hmm. My read of it says that unless you’re writing software that interferes with security of Apple products, you’re OK. So you mooch off the jailbreakers, but if you don’t write the jailbreak software, you’re compliant. And you share with the community information that is already public (i.e., once those books come out).

Thoughts? I’d love to get feedback on this…

Comments (10)

So I Got a New Phone…

I’ve had a Motorola RAZR V3t for a few years -
Motorola got it right with the small, thin half-inch (OK, 0.6″) form factor, though the phone operating system could use some work (OK, it is a piece of…work).

Then my wife’s T-Mobile MDA (Windows CE “smartphone”) broke, so we needed to get a new phone. Yeah, my wife’s phone breaks, but you notice that /I/ got a new phone. I’m still not sure how I worked that one! (But it gets better later!)

T-Mobile really didn’t have any interesting options for new phones. Maybe when their phone based on Google’s Android comes out. But I get good service from T-Mobile in my basement home office (“the dungeon”).

Meanwhile, the iPhone is definitely the most interesting phone available right now. Thin, half-inch form factor (.46″ = 11.6mm), though I worry about that touchscreen getting scratches in my pocket. For my geeky side (do I have another side?) it has a real Unix operating system for development. Remind me to tell you about my Zaurus experience sometime. Original iPhone or 2G? Go original – 3G wouldn’t be any faster on T-Mobile’s network, and it’s a lot more expensive – cheaper initial cost, but more expensive contract required. Those monthly payments add up!

So, I needed a T-Mobile iPhone – (sorry, AT&T). Mobile Unlimited is a T-Mobile reseller that will sell you a “gently used” iPhone with a T-Mobile contract. Looks like they may be selling new iPhones with T-Mobile contract now. Prices are pretty high.

So, I picked up a scratch-and-dent (or, backscratched and front corner hairlined) iPhone off eBay, and first order of business was to unlock it (enable it to use other carriers – specificaly T-Mobile) and while I was at it, to “jailbreak” it, so I could install other software (there’s that geeky side again).

I needed to do the unlock and jailbreak from within Linux or Windows. So with the help of Google, I found the QuickPwn tool (pronounced “Quick-Pone”) from the iPhone Dev Group (no affiliation with Apple).

Here’s what I did:

  • get the latest iTunes
  • Download QuickPwnGUI ( I used version 1.2.0 ( SHA1 = 8e1ed2ce9e7e473d38a9dc7824a384a9ac34d7d0)
  • Download bootloaders (I found them at “RAR” format is an archive like “ZIP” – you can extract it with a great free archive manager called 7-zip:
  • Connect your phone to the computer and make sure it is recognized by iTunes. Leave your phone connected to iTunes for the remaining steps. I upgraded to the latest firmware (2.0.2), because QuickPwnGUI said it could unlock that version. Note that there is usually some lag between Apple releasing a new firmware version and the iPhone community being able to unlock it, so if your firmware version is too new, you may need to downgrade it in order to unlock/jailbreak your phone.
  • Start QuickPwnGUI
    • Follow directions – and when prompted to hold down the Home button, don’t release it when you complete the first step – keep holding it down until told to release it.
    • Be patient – the required rebooting can take a long time.
    • Choose Jailbreak & Unlock
    • Decide whether you want to keep your Apple boot logo, or replace it with a similar pineapple (a pwnapple?). If you take the pineapple, I’m not sure how to restore the apple – you may have to restore to original firmware.
    • path to firmware: iTunes stored mine in C:\Documents and Settings\MY_PROFILE_NAME\Application Data\Apple Computer\iTunes\iPhone Software Updates – change MY_PROFILE_NAME as needed.

My phone (eventually) rebooted, and everything worked, and I had a T-Mobile iPhone.

And my wife has a RAZR V3t. Excellent!

Comments (112)