Archive for the ‘iphone’ Category

munin-node running on the iPhone

Friday, September 24th, 2010

Since it’s Friday, here’s another completely waste of time experiment: Would it be possible to get munin-node running on the iPhone. As Perl exists for the jailbroken iPhone, the answer is obvious: Of Course!

I used my good old jailbroken first generation iPhone “2G”, and started by adding the Perl for iPhone apt repo, and then installed the necessary packages for a basic munin node, that is make, p5-Net-Server, p5-Pod-Compiler and p5-Pod-Simple. In the process, I moved /usr/local to /var/usr_local, and /opt to /var/opt, and symlinked them back, to save precious place on the root filesystem.

To get make things working without warnings, I added a line

                   iphoneos  Unix

to /usr/local/lib/perl5/5.10.0/Module/, around line 36, together with darwin (and reported this as an upstream bug).

Then I downloaded the latest munin stable release, unpacked it, and looked over the INSTALL file for a node-only installation from source. The setup was very easy. I just configured munin to run as the “mobile” user and group in Makefile.config, and ran

make install-common-prime install-node-prime install-plugins-prime
/opt/munin/sbin/munin-node-configure --shell --families=contrib,auto | sh

Finally I added my local munin master to /etc/opt/munin/munin-node.conf, made sure it ran as user and group “mobile”, and started munin with


That’s it. No magic at all. Thank you, Perl! If you try this, remember to kill munin-node afterwards, or your battery won’t last.

Here’s a test run

Syncing your iPhone media database os 3.x from Fedora 12

Tuesday, January 5th, 2010

So, Apple’s attempt to lock iPhone/iPod users to iTunes failed. Again. A solution for syncing from free Unix like platforms has existed for a few months now. Apple, please. Continuing this cat-and-mouse game is stupid. Stop it. Accessing the phones from other platforms than iTunes is fair usage.

This is how I got syncing my iPhone media database os 3.x from Fedora 12 to work. This is based on marcan’s blog. All kudos to marcan, the libgpod hackers and others who helped to hack the ipodhash. Please read his blog entry. The following concludes step 1-5 on a fedora 12 system.

Update: Got rhythmbox working on one box in addition to gtkpod.
Update: Rebuilt packages for f12, backported from f13. Latest packages here. Exchange “libiphone” with “libimobiledevice” in the following. Since all packages are more or less clean backports from f13, this will probably work out of the box on f13 :-)

In the following, I use sudo to gain root access.

If you have not got libusb installed yet, just install it. You also want gtkpod to do the actual ipod transfer.

sudo yum install libusb gtkpod

Get new versions of libiphone and dependencies from rawhide

sudo yum --enablerepo rawhide install usbmuxd-devel libplist-devel libiphone-devel ifuse

Set up usbmuxd. For security reasons, usbmuxd should run as its own user. (This is no longer necessary in newer packages. The rpm postscript adds the user if it’s not added already.)

sudo useradd -r -c "usbmuxd daemon user" -d /media -s /bin/false usbmuxd

Edit /lib/udev/rules.d/85-usbmuxd.rules as root, and add OWNER=”usbmuxd”.

ACTION=="add", SUBSYSTEM=="usb", OWNER="usbmuxd", ...

You can also add “-v -v” to the RUN string, to get more syslog info. run sudo tail -f /var/log/messages in a separate window to see for example how plugging and unplugging happen.

Force a udev rules reload (should happen automatically, actually).

sudo udevadm control --reload-rules

Edit /etc/fuse.conf as root, and add a line


Now check that you can mount and umount your ipod via ifuse. Inside, you should see iTunes database files. You will need to do this to get gtkpod to access your phone. Plug the phone, and do

sudo mkdir /media/iphone
sudo chown $(whoami) /media/iphone
ifuse /media/iphone/
ls /media/iphone/iTunes_Control/iTunes/
fusermount -u /media/iphone

Download and install a preview version of libgpod from

Now, you need some setup on the phone

ifuse /media/iphone
mkdir /media/iphone/iTunes_Control/Device

Read the uuid of your phone (some 40 characters string), then use ipod-read-sysinfo-extended with that value.

sudo lsusb -v | grep -i iSerial
ipod-read-sysinfo-extended your_uuid_string /media/iphone
ls -sh /media/iphone/iTunes_Control/Device/SysInfoExtended
fusermount -u /media/iphone

/media/iphone/iTunes_Control/Device/SysInfoExtended should now be an 20k+ xml file.

If you have come this far without errors, you can start gtkpod, plug and mount (ifuse) your phone, and sync. Remember to unmount (fusermount -u) the phone before unplugging it.

As my iPhone had not yet been synced with iTunes (and probably never will). I got a HashInfo file from, and put it into iTunes_control/Device. Then I cleared out the content of the database (removed Music/*, iTunesCDB, iTunesDB, all .ext files and the .itlp directory). Finally I let gtkpod reinit the database, and hey presto, syncs like a dream. The usbmuxd sync is also a lot faster than the sshfs method I used for the iPhone os v2.x.

As expected, amarok-1.4 is still broken, and can’t use the changed libgpod, and since it has no upstream support, this will probably never be fixed. I’ll miss amarok-1.4, but I can live with gtkpod. Perhaps some day even amarok2 will become usable.

Installing gvfs-afc from rawhide, I got rhythmbox syncing with my i686 box at home, but not with my x86_64 box at work. I haven’t been able to track down why*. With rhythmbox, you don’t have to use ifuse. It will happily pick up the phone via gvfs when it’s plugged. Press Cancel on the camera stuff, and don’t use ifuse and gvfs-afc at the same time. Rhythmbox can’t transfer other content than music, so if you want to transfer video or other stuff, you need to use gtkpod/ifuse.

I’d like feedback from others getting rhythmbox working on x86_64.

Great thanks to marcan and teuf for excellent help on irc.

Update: This is resolved. gvfs does not support home on NFS. It works with no problems with an account with home on local disk on the x86_64 box.

Running native X applications locally on your iPhone

Tuesday, November 17th, 2009

I have a few times missed running the other X11 app on my iPhone. Recently i found iX11 that actually is a local X server for the iPhone. Then, there’s nothing missing. All we have to do is to start compiling.

As always, all kudos goes to Saurik for his awsome work on porting the userland.

I still run a 2.x version of the iPhone OS because I like to sync music and stuff from Linux. The following may not work at all on 3.x. You also need a jailbroken iPhone. Nothing of this will work on a “clean” phone. You will probably also use the ssh server to upload source files and run commands. Doing this with a local terminal is possible, though extremely cumbersome.

The following will give you some basic X11 apps, running locally on your iPhone. You will need some basic UNIX skills, like knowing how to unpack and compile a source package. There’s no deep magic involved, though. If this breaks your phone in any way, you’ll keep all the parts. You’re on your own. Don’t blame anyone but yourself.

Video uploaded to YouTube

Install the following packages with apt-get. Don’t bother to start up cydia. That will only slow you down

x11 xeyes xau xcb xcb-proto xext xextproto xmu xproto xt xtrans
ldid make gawk ed sed vim wget gzip tar

I also tend to use the backgrounder quite a lot, to start up things without using an external shell. Use apt-get again, and install


For source archives, I extracted sources from Fedora 11′s source packages, as they were handy, though I guess upstream sources would work as well.

Before you start, run the following as root to to turn off code signing checks.

sysctl -w security.mac.proc_enforce=0
sysctl -w security.mac.vnode_enforce=0

Now log in or su to the build user (ie. mobile). Download all the source packages to a convenient directory, like /var/mobile/src. I started out with the following packages:

libXdmcp and xauth – to test apps from another X workstation.

libXpm and libXaw – these are basic building blocks

xterm xbitmaps xsetroot twm – some basic user apps

Before compiling, the tool chain needs to find your local header files and stuff. The straigtforward approach is as follows:

export CPPFLAGS=-I/var/include
export CPP=/usr/bin/cpp
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
./configure -build=arm-apple-darwin9.4.1
su root -c "make install"

Start by compiling and installing libXdmcp and xauth. Then as root, cp xauth to /usr/bin. Now you can test xeyes on a X workstation.

$ ssh -X mobile@iphone xeyes

If this works, you’ll get four bonus points, and may take a break. Then compile and install libXpm and libXaw. This will take some time, perhaps an hour or more. There is a missing link in /usr/local/lib, so symlink libXaw.a to libXaw7.a. Does this mean that dynamically linking does not work? I don’t know. You may answer in the comments below.

Now, fire up vim and patch /usr/include/X11/Xpoll.h to ignore the tests on CSRG_BASED and BSD, and always ‘include <sys/param.h>’ and ‘typedef long fd_mask’. Simple!

Then you can build some user apps, xterm, xbitmaps, xsetroot, twm. Finally, since Christmas is coming, compile xsnow:

tar xvzf xsnow-1.42.tar.gz; cd xsnow-1.42
gcc -O2 -I/var/include -I/var/include/arm -c -o xsnow.o xsnow.c
gcc -O2 -I/var/include -I/var/include/arm -c -o toon_root.o toon_root.c
gcc -o xsnow -O2 -L/usr/local/lib xsnow.o toon_root.o -lXext -lX11 -lm -lXpm
su root -c "cp xsnow /usr/local/bin"

Remember to ldid the binaries and libraries afterwards, and turn off code signing. in a root shell, do

for i in  /usr/bin/xauth /usr/local/bin/* /usr/local/lib/*dylib /usr/local/lib/*la; do ldid -S $i ;done
sysctl -w security.mac.proc_enforce=1
sysctl -w security.mac.vnode_enforce=1

Now make the fun begin: Start iX11, and in another shell, do

export DISPLAY=localhost:0
twm &
xsetroot -solid midnightblue
xsnow &
xterm -bg black -fg wheat &

Next: OpenOffice?

Update: Built fvwm as well. A bit more user friendly than old twm.
Update: Captured a video and posted it on YouTube.

Downgrading the iPhone OS from version 3 to 2.2.1

Thursday, July 23rd, 2009

Earlier this summer, I had the mixed enjoyment of upgrading my jailbroken first generation (“2G”) iPhone from OS version 2.2.1 to 3.0. The upgrade/jailbreak worked as expected without problems using the QuickPwn/redsn0w tool from the dev-team. The new iPhone functionality in version 3.0 is described all over the net, so I don’t need to reiterate here. It was better. I quite liked it.

Now, what Apple of course did again was to break existing compatibility with available free software tools. They changed the iPod database format again. I had a quick look at the files generated from iTunes, and found that it is now based on sqlite with some propriatory functions added. Sqlite is not the worst format to work with, so over time, this may be a change for the better. Worse, but not unexpected, was that they have kept the scramble algorithm they introduced in 2.x, and removed the hacked support for older versions of the library. There was also another file that looked like it kept some cryptographic info. I found Héctor Martín Cantero on IRC and presented some of the files, and he produced a blog posting with his views on the changes.

While we may hope for more openness from Apple in the time to come (yeah, right), or that the always busy hackers either hack the iTunes DB format again, patch around the changes or produce a good alternative player (yes, I very well know about PwnPlayer and dTunes), I’ll stay with 2.2.1. So I downgraded.

And that was quite a bit of work, and took me some hours. I got friendly help on one of the many iPhone related IRC channels, and found a forum post with some of the information needed. It had some errors, but had enough information to get me through.

The downgrade path, which probably will only work on first generation (“2G”) iPhones, is:

Use the 3.0 beta 5 QuickPwn jailbreak toolkit from the dev-team on the device upgraded to 3.0. This will give you a non-working device that will ask you to connect to iTunes on a pink (indicates a beta version, I guess) background. Then use iTunes in normal repair (not DFU mode as described in the forum post) to downgrade (restore) to beta 3, then beta 2, then back to 2.2.1, and finally re-jailbreak that.

The main problem here was of course to find that I had to use a “normal” iTunes restore, and not DFU mode to do the downgrade. Secondly, finding the files necessary took quite a bit of time. They are still available on the web, and Google will find them for you, but it was quite a pain to get the all the parts needed.

Using an US iPhone/iPod power adapter in Europe

Thursday, July 2nd, 2009

I bought my iPhone from the US before it got available in Norway. The power adapter was of course US type, and did not fit into our European style wall sockets. So I bought a third party made-in-China power adapter, and was content. Now, the other day, being a little too rough with it, I pulled out the contact pins!

broken el-cheapo adapter

In no position to get them back, my eyes fell on the originial US power adapter, and wondered if I could buy something that could make it fit in the wall socket, as the adapter supports the whole 100-240 Volt range without modifications.

Original US iPhone/iPod adapter

At this time my oldest son (8) enters and, being the son of his father, start fiddling with the parts. -What happens if I pull here? *Click*


Aha! The wall socket connector is an opt in replacement, and rejoice! The common connector is matching a standard accessory cable. Finally, Apple did something right.

wall socket connector removed standard accessory cable problem solved

Problem solved.

Amarok 1.4 for Fedora 11

Thursday, June 11th, 2009

I recently upgraded from F10 to F11. Except a couple of small issues (bz#496586, bz#504980), the upgrade was completely painfree, using preupgrade. Well done, release team!

As expected, the version of amarok that comes with F11, 2.0.2, is still unable to pick up FUSE mounted devices, because it falls back on HAL, and HAL works on hardware, not FUSE based software mounts. In short, I can’t sync my iphone from amarok. Again.

I forwardported amarok-1.4.10 from Fedora 9. The port was quite simple. Just add a few #include here and fix a few method calls there.

The patch, source rpms, and x86_64 and i586 rpms are available at

Update: I had to scratch the ipod db on the phone and rebuild it, but except that, things seems to work as expected.
Update: Packages for f12 available.

Syncing music from Linux to the iPhone firmware 2.x

Wednesday, February 25th, 2009

Well, it happened. And the solution was simpler than one would think.

Wrapping an iPhone script in beautiful colors

Friday, November 21st, 2008

I found somebody had got perl in a more or less usable state on the iPhone fw 2.x. So I was able to make my calendar sync script work again. From the command line. Now what about wrapping your shell or perl or [insert your favourite scripting language here] script with a beautiful splash screen and an icon to start it from the SpringBoard.

Easy! You need

  • A graphic designer, who can produce
  • an icon.png, and
  • a splash screen saved as Default.png

Stuff these, (no, not the designer) together with your in a new directory /Applications/ Than add an XML file called Info.plist. There’s a boilerplate below, shamelessly stolen from a reply on this blog post. Finally, use for example BossPrefs to respring, and you’re done. Tap the icon and watch the splash screen while the script runs in the background.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">

iPhone OS v2.1

Monday, October 20th, 2008

Yeah, yeah, Apple haters, I know, didn’t you just tell me.

I just upgraded my iPhone to firmware/os/whatever version 2.1. Everybody I knew with an iPhone asked why I haden’t upgraded yet. So I did. What a dissapointment! Apple has encrypted the media library hashes, and the encryption is not broken yet, so I can no longer sync my music from Linux. This means all other Linux users I know with an iPhone syncs via Windows or OSX. Loosers!

The correct thing to do is of course not to play cat and mouse with Apple by deassembling iTunes, as somebody has started doing, but write something that works instead. Luckily somebody did. dTunes and PwnPlayer does the job. Especially the latter has great potential. I know, I’ve tested it. It seems it will even be released as Free Software in the end. There is still hope.

How I made the iPhone sync my calendar over air

Monday, August 18th, 2008

Some days ago a friend of mine upgraded his iPhone to firmware 2.0, and boasted modestly on how he could sync his MS Exchange Calendar over air. Note that working calendar sync, and even by air is, of course, the holy grail of all mobile equipment, even for sales people.

Some months ago, I used the quite crude tool called ical2sqlite and some simple perl scripting, and built a proof-of-concept one-way sync from an ical source (OpenXchange) to the iPhone calendar via a Linux box. Now, recently I tested Saurik’s awsome porting work of a more or less complete Debian based GNU/Darwin userland, with dpkg, apt-get and a complete GCC based tool chain. Then the thought awoke: The hack should be doable again, and this time with nothing but the iPhone. No cross compilers. No helping computers. Just a simple over air sync.

And some hours later, it was done. The hard bits:

  • The standard C++ libraries lacked a symlink. This gave confusing linker errors.
  • GNU autotools do not support the iPhone “unix” environment yet. Thus, it was a bit difficult to get the standard configure script to understand the underlying platform, and it took a bit of guessing and trying to force through a working string.
  • Find and fix a WIN32 related bug in the ical source. (The bug is fixed in version 0.31, but I could not get that to build)

I have only tested the following on a “standard” jail-breaked iPhone, running sshd on firmware 1.1.4. You need to know the root password. Google it up and change it if you have not done so already. Note that some of the steps may take quite some time.

Also note that this is not for the faint hearted first time iPhone users. This receipe will probably brick your phone, make random calls to your friends and call them unmentionable names, spring to pieces, and hurt your uncle Bob with the shards. If something breaks, you may keep all the parts. Don’t blame me. You have been warned. On the other hand, if you know some UNIX, this is just simple downloading, patching, compiling and scriping, and no rocket science.

Remember that this is a one-way sync. All info in your iPhone calendar will be erased, and replaced with the contents of the ical source.

Start with making sure the phone does not autolock, to prevent it going into “sleep” mode, so you don’t break your network connection while it’s at its most exciting (yaaawn).

From the Apptapp installer, install Perl. Then install Cydia. This may take som time, so make yourself som coffee while you wait. Follow the on-screen instrucions.

Quit the AppTapp installer, and start Cydia. Install Tapp, wget, SQLite v3, iPhone-headers, patch, libgcc, ssh, gcc, bison, flex and make. Did I forget something? Probably. This will take a while, so drink some of the coffee while waiting.

You should now have a somewhat semi-complete GNU-like build environment on a kind-of computer that is almost, but not completely different from a GNU-based UNIX-like system.

If you haven’t done this already, change the root password. The info is all over the net.

Now log into the phone using ssh. (If you are of the kind of people that likes to hurt themselves, it might also be doable via a local console shell.)

$ ssh root@iphone

Add a missing symlink for libstdc++

# cd /usr/lib
# ln -s libstdc++.6.0.4.dylib libstdc++.dylib

Change user to mobile

# su - mobile

Now we are ready for some serious work. First, we need to get a working version of FreeAssociation, that is, libical. Note that the newer version 0.31 won’t compile because of some bison/yacc issue. If you find a solution to this, add a comment or send me a mail.

$ wget

Unpack the source

$ tar xvzf libical-0.30.tar.gz

Get a small patch that moves an error related to WIN32 away from our context

$ wget
$ patch -P0 < icaltimezone.nowin32.patch

The source needs perl to build, so add it to your path first.

$ export PATH=$PATH:/opt/iphone/bin # perl is there

Then configure and build the source.

$ cd libical-0.30
$ ./configure -build=arm-apple-darwin9.0.0d1

Have another cup while waiting. Fun, isn't it? Then Build the binaries.

$ make

Have yet another cup. Take a walk. Visit a friend you haven't seen for a while. Then return to your compilation. If you're lucky, it's finished.

Exit to root. Then install the binaries. They will go to /usr/local.

$ exit
# cd ~mobile/libical-0.30
# make install

libical is unable to use the iPhone's own timezone database, so install it's own

# cd zoneinfo
# make install

So, we have a complete libical. The next step is to get that hideous thingie called ical2sqlite. Become the mobile user again, download and unpack the source.

# su - mobile
$ export PATH=$PATH:/opt/iphone/bin
$ wget
$ tar xvzf ical2sqlite_0.1.orig.tar.gz

Now, configure and build the source. Have your coffee pot ready.

$ cd ical2sqlite
$ ./configure -build=arm-apple-darwin9.0.0d1 && make

Exit to root and install the binary

$ exit
# cd ~mobile/ical2sqlite
# make install

The binary bits are now ready. Time for some scripting action.

# su - mobile
$ wget
$ chmod +x update_calendar
$ vi update_calendar

You know how to use the vi editor, right? You should at least change username, password, timezone and zuluoffset according to your calendar settings. Correct timezone and zuluoffset=0 worked well with my settings. For more info about the script, see my previous posting.

Then, you are ready to try the magic. From Cydia, install MobileTerminal. Start the terminal. Run the script

$ ./update_calendar

You're done, and might want to check the calendar.

To access this without starting a shell, I used the tool "Tapp". Now, what I want is a tool that makes this available as a Springboard icon, but without building a complete package. I think Erica Sadun's tool "Launch" can do this, but it is not available for firmware 1.1.4.

Next stop: Make a real two-way sync? That would take som serious programming. I'm not serious.