Jun 052011

I had been wanting to understand the ARM architecture for a long time. A recent comment by Chris increased my thirst and here I am at 7AM on Sunday writing this post. No I did not get up early for this, I am late to bed. I spent the night setting up my development board and developing a few benchmarks to understand the architecture of Cortex A8 installed in the iPhone. I have split this post into parts for the ease of reading. The first part just describes how to use the iPhone as a development vehicle.

Setting up my development board

While it will be more customary to use a development board for benchmarking a core, I decided to use an iPhone 3GS because I could buy one easily from cragislist. I will first describe the steps I followed for anyone else who is interested.

For reference: I bought a Mac and paid my $100 to Apple’s developer program last year in the hope that having spent the money will inspire me to write some apps. That money could finally come in handy last night except that it didn’t. The first thing I tried was to write an iPhone app for benchmarking the iPhone in the Xcode SDK. I used a template application and made an app to run some simple loop tests at launch and display results as a list. I was disappointed by the variation in results which was caused due to the disturbance form the GUI. Furthermore, using a the Xcode SDK and GUI interface made me feel like I had no control over optimizations. Thus, I set out to look for an alternative method to understand the iPhone.


photo 2 photo 1

The above is a picture of m iPhone application. Each row corresponds to a different size of array being brought into the core for processing. The first column is the log base 2 of the array size in bytes.The later numbers are the mach time (described below) taken to run the loop. You can see the run-to-run variation is as high as 2x, e.g, look at line 7 in both pictures.

Following are the steps I eventually followed to setup an iPhone as a development board.

1. Jailbreak your iPhone. There are literally a million tutorials online and the procedure varies depending on the version of the iOS you have. Fortunately, I had not updated my 3GS beyond iOS 4.0.1 so I was able to jailbreak it using the jailbreakme.com website within minutes. This creates an icon called Cydia on my Springboard. (By the way, it is legal in the US to jailbreak a device you own.)

2:  Setup Cydia: When you open Cydia for the first time, it will ask “Who are you?”. Answer developer to gain access to the packages you will need for this tutorial. If you miss this step (like I did), go in the Manage tab in Cydia and click on the Setting button in top left to get back to this.

photo 1

3. Install OpenSSH: Go to the Search tab in Cydia and search OpenSSH.

photo 2

Click on it and click the install button on the next screen. Restart the iphone after installing OpenSSH to run the SSH server. photo 4

4. Find phone’s IP address:  Go into Setting, go to Wi-Fi; find the wi-fi network you are connected to; click on the small blue right-arrow next to the network you are connected to for details. This will take you to a screen which shows the ip address.

photo 3

5. Test SSH:

Mac already comes with SSH clients installed. On Windows, you must install putty or another SSH client.

hostname: iPhone’s IP address
username: root
password: alpine

Once inside the iPhone, play around a bit and see how everything is structured.

6. Install more packages (optional): I installed the following packages in Cydia to ease development effort:

top to monitor running processes
adv-cmds to get commands like ps
wget to be able to download files from websites
nano to edit text files on the iPhone

7. Choose a compiler.

For Mac: Install Xcode from Apple’s website which comes with a compiler that you can use. The compiler can be run as:

/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++ -O3 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -o $(TARGET) $(SRC)


Note that the iPhone SDK folder name depends on your version of Xcode that you install. You may have to change this command based on what its callled on your computer.

Replace the $(TARGET) with the name of the output executable and $(SRC) with the name of the C/C++ source file to compile.

Mac’s work-flow will be as follows: Create, edit, and compile on computer, SCP it to the phone, and ssh into the phone to run the binary.

For Windows/Linux: Install and use gcc-iphone using these instructions.

Windows work-flow will be as follows: edit on computer, SCP file to the phone, ssh into the phone, compile, and run.

I have a Mac so I will use the former (so the Mac computer did pay by saving me the extra 30 minutes to install iphone-gcc).

8. Write hello.cpp and compile. I wrote a hello world program and compiled it using the command.  Note: this a.out is for the ARM architecture and iOS. It does not run on your Mac.

#include <stdio.h>

int main(int argc, char **argv){
print(“Hello world});

10. scp the binary to any folder your phone. I used the Mac’s command line scp as shown in the screenshot below.

You can use WinSCP on Windows to do the same.

Two points specific to my setup: (1) I created a Program folder in the home directory of root for the binaries, and (2) I also setup keys to SSH/SCP without a password (see this to setup password less login).

11. Run the program and see hello world print!

Screen shot 2011-06-05 at 12.17.07 PM

Now we have a working development board for ARM.

Learning from my development board

I use the following command to find some basic information.

sysctl hw

The following is what the 3GS printed on the terminal:

Screen shot 2011-06-05 at 12.09.59 PM

The printed text is as follows:

hw.ncpu: 1
hw.byteorder: 1234
hw.memsize: 265289728
hw.activecpu: 1
hw.physicalcpu: 1
hw.physicalcpu_max: 1
hw.logicalcpu: 1
hw.logicalcpu_max: 1
hw.cputype: 12
hw.cpusubtype: 9
hw.cpu64bit_capable: 0
hw.cpufamily: 214503012
hw.cacheconfig: 1 1 1 0 0 0 0 0 0 0
hw.cachesize: 265289728 32768 262144 0 0 0 0 0 0 0
hw.pagesize: 4096
hw.busfrequency: 100000000
hw.busfrequency_min: 100000000
hw.busfrequency_max: 100000000
hw.cpufrequency: 600000000
hw.cpufrequency_min: 600000000
hw.cpufrequency_max: 600000000
hw.cachelinesize: 64
hw.l1icachesize: 32768
hw.l1dcachesize: 32768
hw.l2cachesize: 262144

hw.memfrequency: 200000000
hw.memfrequency_min: 200000000
hw.memfrequency_max: 200000000
hw.prffrequency: 100000000
hw.prffrequency_min: 100000000
hw.prffrequency_max: 100000000
hw.fixfrequency: 24000000
hw.tbfrequency: 24000000
hw.packages: 1
hw.optional.floatingpoint: 1
hw.optional.watchpoint: 0
hw.optional.breakpoint: 0
hw.machine = iPhone2,1
hw.model = N88AP
hw.ncpu = 1
hw.byteorder = 1234
hw.physmem = 265289728
hw.usermem = 224841728
hw.pagesize = 4096
hw.epoch = 1
hw.vectorunit = 0
hw.busfrequency = 100000000
hw.cpufrequency = 600000000
hw.cachelinesize = 64
hw.l1icachesize = 32768
hw.l1dcachesize = 32768
hw.l2settings = 1
hw.l2cachesize = 262144
hw.tbfrequency = 24000000
hw.memsize = 265289728
hw.availcpu = 1

I have highlighted the lines I was looking for.

Coming attractions

I will post Part 2 in a few hours which describes how I tested my iPhone using my own micro-benchmarks. We will discover the latency of arithmetic operations, cache access latencies, memory access latencies, and memory structure using less than five lines of C code.

  8 Responses to “Tips for iPhone App developers: Development board setup (Part 1)”

  1. [...] if it will help you but I recently cross compiled C for the ARM inside an iphone. Link to tutorial: http://www.futurechips.org/chip-…This answer .Please specify the necessary improvements. Edit Link Text Show answer summary [...]

  2. Amazing blog! Is your theme custom made or did you download it from somewhere?
    A theme like yours with a few simple tweeks would really make my blog stand out.
    Please let me know where you got your design. Thank you

  3. Pretty section of content. I just stumbled upon your
    weblog and in accession capital to assert that I acquire actually enjoyed account your blog posts.

    Anyway I will be subscribing to your feeds and even I achievement you access consistently quickly.

  4. I have read so may content concerning the blogger
    lovers however this ost is in fact a good paragraph,keep it

  5. The key to getting pregnant is knowing when you’re ovulating. If you know you’re ovulating late in a given month, you can get pregnant, even if you ovulate as late as day 24 of your menstrual cycle. Physical signs of impending ovulation include thin, stretchy cervical mucus, Dr.
    motorcycle led driving lights http://www.everlink2008.com/6-3-Inch-DC-10-30V-51W-Motorcycle-LED-Driving-Lights-21.html

  6. Amazing! Its actually awesome article, I have got much clear idea about
    from this paragraph.

  7. Whether or not this could possibly be a wedding anniversary ring, precious stone wristbands or even a precious stone pendant, virtually any necklaces can give importance to a special occasion to suit your needs plus your beloved. Because wonderful a new clich as it might seem to be, precious gems are a women’s companion. With all the current designs available on the web plus retailers, discovering special designs might take considerably from a pocket. Apart from the form of a wedding ring, there is also to be critical concerning excellence of the precious stone. The store could have extravagant designs, yet on the sacrifice of quality. There are also different colored precious gems, and a few designs could possibly be imbedded which has a particular birthstone. There exists a wide selection to select from. Apart from these factors, you must be practical in getting which necklaces, without having damaging your wallet an excessive amount of.
    Salomon Speedcross 3 CS http://www.trailonfoot.com/k9012-salomon-speedcross-3-cs-uomo-trail-running-shoes-grigio-arancione-2016-designer.html

  8. Coloration. The degree of coloration, or even “yellowness”, with the diamond can vary from stone in order to stone. You’ll need to know what color to decide on from the coloration scale from lighting in order to dim. The colour you pick needs to be proven about tone: bear in mind, which diamond is supposed to be put on as well as showed off, therefore it should look great about whoever’s using it.
    salomon ski boots sizing http://www.onrunfoot.com/online-v7024-salomon-speedcross-3-cs-mens-trail-running-shoes-black-yellow-red.html

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>