Scythal
12-24-2007, 10:07 AM
Some extra information to compile the Toolchain under Linux (tried with FC8). There are very good guides and interesting info out there, but I thought it would be nice to regroup the tiny bits that are scattered over so many places in one post.

The main process is detailed in this guide: http://code.google.com/p/iphone-dev/wiki/Building

The tricky part is getting the filesystem out of the firmware file used by iTunes, and the MacOSX10.4 part in the big xcode .dmg file (especially with Linux).

For the first one, I used the 1.1.2 firmware of the iPod, downloadable from this address (the same that can be used in the update to 1.1.2 part of jailbreak method):
http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPod/SBML/osx/bundles/061-4036.20071107.9g3DF/iPod1,1_1.1.2_3B48b_Restore.ipsw

Change the extension to .zip, and extract 022-3642-8.dmg.
The keys to decipher this version of the firmware (and older ones), are given on this page (http://www.touchdev.net/wiki/Decrypt_Firmware), but the vfdecrypt-iphone.tar.gz they provide doesn't work. Use the file in attachment instead. Download this file in the same directory as the .dmg file and compile the vfdecrypt.c program (for other firmwares, change the keys at the end):
gcc -o vfdecrypt vfdecrypt.c -lcrypto
Decipher the dmg file, for the 1.1.2 firmware (3B48b):
vfdecrypt 022-3724-1.dmg fw1.1.2.dmg 70e11d7209602ada5b15fbecc1709ad4910d0ad010bb9a9125 b78f9f50e25f3e05c595e2
or for the 1.1.1 (3A110a) firmware:
vfdecrypt 022-3642-8.dmg fw1.1.1.dmg d45b837ddd85bdae0ec82a033ba00ea03ceb8c827040034f75 54c65d6376472844b8dc6a
Now you have to read its contents. Personally I find the simplest is to use UltraISO to transform the .dmg to .iso, this program works with every .dmg file I have seen so far (even the xcode3.0), and works under Linux with Wine, which is not the case of TransMac (besides, TransMac can only copy files, not convert images). You can download this program from there: http://www.ezbsystems.com
Open the .dmg, then from the menu: Tool, Convert, choose Standard ISO.
But you can also extract the files right away, although I'd do that from the mounted iso to be sure.
Mount the .iso (I recommend putting this file in a safe place if you intend to use it, /usr/local/arm-apple-darwin would be a good idea):
mv fw1.1.2.iso /usr/local/arm-apple-darwin
mkdir /usr/local/arm-apple-darwin/fw1.1.2
mount -t hfsplus -o loop /usr/local/arm-apple-darwin/fw1.1.2.iso /usr/local/arm-apple-darwin/fw1.1.2
Maybe you want to put that in /etc/fstab since you'll need it mounted everytime you want to build an application. Or copy the files to your filesystem and discard the iso.

From there you can do the next step of the guide:
HAVENLY=/usr/local/arm-apple-darwin/fw1.1.2
For the second one, before going on with the guide, you have to download this big file from http://developer.apple.com. For that, you need to sign in (register if that's not already done), and follow the Developer Tools section and Xcode 2.5 Developer Tools links. It's a 902 MB file.

You can either use UltraISO again to extract the necessary file, or do it with the dd command.
With UltraISO, open the xcode25_8m2558_developerdvd.dmg file, and extract Packages/Packages/MacOSX10.4.Universal.pkg/Contents/Archive.pax.gz.
With dd,
dd if=xcode25_8m2558_developerdvd.dmg skip=1381744 | gunzip | pax -r

Note: As someone rightfully said on the google code page, you could take advantage of this 2nd method to download only the part you need instead of the 902 MB, using the http range header capability. To find out what the offsets are in the file, you can use this script:
od -t x1 xcode25_8m2558_developerdvd.dmg | grep '^[0-7]*000 1f 8b' > offsets.txt
awk '{ print $1 }' offsets.txt | while read x; do dd if=xcode.dmg skip=$((0$x / 512)) count=1 | gunzip | cpio -t | grep -q MacOSX10.4u.sdk && echo $((0$x / 512)); done 2>/dev/null
You will find out that 1381744 is the offset of the part we need, and 1441298 the offset of the next one.

Either way, extract the content to a temporary directory, that you will have to pass later to the ./configure --with-macosx-sdk=<directory> command in the guide:
gunzip -c Archive.pax.gz | cpio -i

Follow the rest of the guide, just be careful about the typo in the last steps:

../../llvm-gcc-4.0-iphone/configure --enable-llvm=`llvm-config --obj-root` \
--enable-languages=c,c++,objc,obj-c++ --target=arm-apple-darwin --enable-sjlj-exceptions \
--with-heavenly=$HEAVENLY --with-as=/usr/local/bin/arm-apple-darwin-as \
--with-ld=/usr/local/bin/arm-apple-darwin-ld

should read:

../../llvm-gcc-4.0-iphone/configure --enable-llvm=$LLVMOBJDIR \
--enable-languages=c,c++,objc,obj-c++ --target=arm-apple-darwin --enable-sjlj-exceptions \
--with-heavenly=$HEAVENLY --with-as=/usr/local/bin/arm-apple-darwin-as \
--with-ld=/usr/local/bin/arm-apple-darwin-ld

To test it, you can use this HelloWorld (http://ellkro.jot.com/WikiHome/HelloWorldSrc-0_30.zip?cacheTime=1190196505745) dummy application.

If you want to easily transfer the application files to the iPod, you can use sshfs to mount the iPod:

mkdir /mnt/ipod
sshfs -o transform_symlinks root@192.168.1.10:/ /mnt/ipod

akermar
12-24-2007, 10:39 AM
thanks for all the hard work you have put in im sure this will help a lot of people

daowna1911
01-01-2008, 12:28 AM
i can't get the mount line to work on Ubuntu. I've edited the /etc/fstab.
With any variation you can think of and I even added a symbolic link in /dev. Have you heard of any issues with ubuntu?

Scythal
01-01-2008, 03:12 AM
i can't get the mount line to work on Ubuntu. I've edited the /etc/fstab.
With any variation you can think of and I even added a symbolic link in /dev. Have you heard of any issues with ubuntu?
I tried with Ubuntu 7.10 and it worked like a charm.

ubuntu@ubuntu:~$ sudo -i
root@ubuntu:~# mkdir /mnt/fw
root@ubuntu:~# mount -t hfsplus -o loop $IPODFIRMWARE/fw1.1.2.iso /mnt/fw

(with $IPODFIRMWARE pointing to the iso directory, of course)
Maybe your ISO is corrupted, the md5 of mine is:

root@ubuntu:~# md5sum -b $IPODFIRMWARE/fw1.1.2.iso
b745236eedc00a78cb3cb0d463d98fa9

daowna1911
01-01-2008, 11:19 AM
I'm Using Ubuntu 7.10.
This is the result of running md5sum -b /usr/local/arm-apple-darwin/fw1.1.2.iso:

18d011bbf6389780887a1c0275490673 */usr/local/arm-apple-darwin/fw1.1.2.iso

I will note that the files are different. The 22-3642-8.dmg does not exist. I have 022-3724-1.dmg, 022-3751-2.dmg, and 022-3752-2.dmg.

daowna1911
01-01-2008, 01:19 PM
Ok, I had the wrong restore file. But I still can't get it to work. Now I'm getting this error from dmesg: unable to find HFS+ superblock. I think the .iso is bad used MagicIso to convert it. UltraIso says it doesn't the file type. Any idea?

Scythal
01-01-2008, 03:05 PM
Yes, I have an idea... I'm sorry but I left the key for the 1.1.1 firmware in the C sources, I guess it was late and I mixed them up :rolleyes:

I've put the new sources in attachment, now you can specify the key as parameter to avoid such confusion. I've modified the guide accordingly, with the line you have to enter for each firmware.

Sorry again!

In fact, I used the 1.1.1 firmware to build the toolchain the first time, I didn't re-do it entirely to test 1.1.2 as it shouldn't make a difference. If you do, please let us know.

mengder
01-03-2008, 02:06 PM
What's the HelloWorld for? sorry for this silly question,new to this area,

Scythal
01-03-2008, 02:46 PM
It means that you are using the cross-compiler instead of the native one. Maybe you added /usr/local/arm-apple-darwin/bin before /usr/bin (or wherever gcc is) in your path.

mengder
01-04-2008, 02:17 PM
It means that you are using the cross-compiler instead of the native one. Maybe you added /usr/local/arm-apple-darwin/bin before /usr/bin (or wherever gcc is) in your path.


how should i change the path use .profile or bash_profile
i get confused they are both said to set the path,the result of following different guides is i had both of them NOW, but i wanna know which one is really working.

one more question when i compile the helloworld, the following wrong information returned:

avid-ms-computer:~/toolchain/helloapp da$ make
arm-apple-darwin-gcc-4.0.1 -ObjC -framework CoreFoundation -framework Foundation -framework UIKit -framework LayerKit -o Hello hello.o HelloApplication.o
/usr/bin/ld: unknown architecture specification flag: -arch arm
/usr/bin/ld: Usage: /usr/bin/ld [options] file [...]
collect2: ld returned 1 exit status
make: *** [Hello] Error 1

and so did other make commands return like this, many thanks to you ,Scythal..