Thinking until the 2147483648'th second

About This

I think all of the files I linked to in some of my older posts are gone now. I am working on fixing them.

Sunday, May 24, 2009

Moved to

I have moved over to Check it out.

Wednesday, February 4, 2009

A Revitalized Blog

I stopped using this blog for a few reasons. I didn't work on anything interesting for a while, and when I did I started posting on my developer's blog over at However, I think I'm settling down on this blog again. I like blogger, and I don't think my gamedev blog will get me any more game development publicity.

So, cheers (raises a beer...). I've actually been getting some good stuff done on working with 3d graphics in scheme, so I should have ample material for some good posts. Until then, here's a teaser:

Tuesday, February 19, 2008

Re-creating the Apple TV harddrive from Scratch

Phew. For a second there I didn't think my AppleTV was going to make it.

I bought an ATV a few months ago and hacked it pretty seriously. At that point, I was trying to run the full Tiger version of OS X on it. I impatiently wiped the whole hard drive without backing up the recovery partition. Eventually, I decided I wanted to use ATV's interface, and I struggled a bit to get ATV re-installed without a Factory Restore. I finally got it working though, so I knew it *was* possible to get the ATV back up and running from scratch with *only* the OS.dmg from

You see, Apple released a big ATV update (from v1.1 to v2.0) just last week. You can rent HD movies with this update - which is awesome (albeit a little overpriced). I really wanted this update, but I couldn't do it the convenient way because my ATV was hacked. I tried the Safe Update but the DRM's are screwed up so you can't rent anything. I decided that it would be best to do a Factory Restore (manually, mind you) and let it update itself.

Easy, right? I did it once before, so it should be a piece of cake, right? Psh, like I can remember the nuances of disk images and partitions after months of not working with the stuff. I ended up wasting three nights trying to remember the exact layout of partitions and the precise format of system data that AppleTV requires. The thing that is so frustrating is that it is *not that hard* and should have only taken me an hour - but dammit, the thing is picky.

I never want to forget this again, so I'm documenting it here. So, you have a blank hard drive, and you want it to use it for the Apple TV? Get the OS.dmg from any torrent site, make sure your drive is physically compatible, then follow these steps *precisely*. Assuming /dev/disk1 is your disk.

(A quick note: Awkward TV's tutorial was a big help, but I had problems with a few of its instructions, specially the ones using diskutil to format the disk)

1. Connect your hard drive to a Macbook using an IDE-to-usb/firewire dongle.

2. Clear any partition information and create a new partition table:
gpt destroy /dev/disk1
gpt create /dev/disk1
3. Create the partitions using 'gpt'. There should be four partitions: EFI (200m), Recovery (400m), OSBoot (900m), Media (rest of the disk). The EFI and Recovery partitions can be completely blank, but those sizes must be exact.

Assuming, /dev/disk1 is your disk:
gpt add -b 40 -i 1 -s 409600 -t efi /dev/disk1
gpt add -b 409640 -i 2 -s 819200
-t 5265636F-7665-11AA-AA11-00306543ECAC /dev/disk1
gpt add -b 1228840 -i 3 -s 1843200 -t hfs /dev/disk1
gpt add -b 3072040 -i 4 -s *size* -t hfs /dev/disk1
You'll have to unmount the drive after every gpt command because OS X likes to automount drives.

4. Create the filesystems.
newfs_hfs /dev/disk1s2
newfs_hfs -J -v OSBoot /dev/disk1s3
newfs_hfs -J -v Media /dev/disk1s4
5. Remount the drives with ownerships enabled.
diskutil unmountDisk /dev/disk1
mount -t hfs /dev/disk1s3 /Volumes/OSBoot
mount -t hfs /dev/disk1s4 /Volumes/Media
6. Restore the system. You can use the command 'asr', but at this point it's easier to use disk utility, click on OSBoot, and restore OS.dmg to it. I also did 'Scan Image For Restory' under Images for safety before I restored it. This took me a while to trackdown; initially I just rsync'ed the files. Evidently the restore preserves something that it needs (the window server would just crash on me).

7. Depending on how you dumped the image into OSBoot, this may be needed. If you used Disk Utility, this is unneeded.
sudo bless --folder=/Volumes/OSBoot/System/Library/CoreServices
--file=/Volumes/OSBoot/System/Library/CoreServices/boot.efi --setBoot
There you are. You should be able to unmount the drive, stick in in your AppleTV and boot right up. I found the tools mentioned above *much* more reliable than Disk Utility (and its CLI equivalent diskutil). diskutil would screw up my partitions - randomly resize them, etc. which was a big pain.

Update: It seems that the bless command is unneeded, if using Disk Utility's restore at least. Note that you can also use the new ATV2 OS.dmg found here. (The next thing to do is to get the recovery partition back in order. I tried a few different set ups and couldn't get it working.)

Update #2: If you are doing this to upgrade to ATV2, make sure you also update your HDMI/DVI controller. This is something it would do automatically. You can see the controller update here:

Download the installer (called 'hdmiutil') and the update file, copy to your ATV, ssh in and run the update like so:
$ ./hdmiutil FW29050_20080205_dse_hex.sihex
You should get this message:
hdmiutil - HDMI Flash Utility Version 1.1000 (Mac)
For Programming Silicon Image's SiI1930 (DVI-HDMI) microcontroller.
Copyright (C) 2006-2008, NVIDIA Corporation. All Rights Reserved.
Using default I2C configuration on Mac platform.
Temporarily disabling hotplug interrupt processing...
Firmware Filename: FW29050_20080205_dse_hex.sihex

!!! Do not interrupt power or hotplug displays during flashing process. !!!
!!! This might take a while to complete (approx 5 min for each file) !!!

Sector Erase 0%........10%.......20%........30%.......40%........50%.......60%........70%.......80%........90%......100%

Programming 0%..........10%..........20%..........30%..........40%..........50%..........60%..... (goes till 100%)

OK - file FW29050_20080205_dse_hex.sihex firmware flashed successfully!
Re-enabling hotplug interrupt processing...
This will fix issues with playing HD over your HDMI/DVI cable (such as HDCP).

Update #3: Fixed a few typos, filled out the start positions for the partitions, and a few other minor updates. Glad you guys found this useful.

Random Notes

I work at Coptix

Ideas / To-do

  • Research .Mac style photo gallery for screenshots