Xfce

Subdomains
 

Google TV and Native Libraries

  • October 5, 2012
  • Brian Tarricone

The Google TV runs a fairly unusual flavor of Android (at least the 2nd-gen ARM-based devices). I have a Sony Internet Player (not the Blu-Ray version), so what I’m about to write applies to that device, but maybe not any other, though it stands to reason that the other ARM-based GTVs are the same.

Phone-and-tablet Android doesn’t look much like a Linux desktop or server system. It uses the Linux kernel, to be sure, but a lot of the userspace libraries are custom. It even does not use Glibc, but a C library that Google wrote called Bionic. It’s fairly stripped down and lightweight, and while it implements most things you might need out of a standard libc, it does not pretend to be POSIX compliant.

Due to this, a Native Development Kit (NDK) is not yet available for the GTV. So the question remains: can we hack one together that works? The answer is… sorta.

From some simple investigation, I’ve learned that the Sony GTV is running a EGlibc 2.12.2, and probably a mostly-unmodified version of it. Someone with an @google.com email address stated that the reason for this was that they couldn’t get Chrome running against the Honeycomb version of Bionic.

With this knowledge in hand, I built a relatively standard arm-linux-gnueabi toolchain using crosstool-ng. Then I ‘adb pull’-ed the contents of /system/lib from my GTV and merged them with the new toolchain’s sysroot, copied some headers out of a stock NDK, and ended up with a sysroot that approximates what you’d find in platforms/ in a stock NDK, just without Bionic, and with EGlibc.

I didn’t get to modifying the NDK’s build system (it would need to be changed to find the new toolchain), so I built my native library manually, and got a simple “hello world” type app with a native lib. (It just calls a native method that returns a string, and displays the string on a label.)

One annoying thing is that the ABI string in the Sony GTV is set to “none”, so you have to unpack the APK, rename lib/armeabi-v7a/ to lib/none/, and repack and resign it. All of this means that this would be strictly hobbyist for now: no chance that you could distribute something in the Play Store. Not only does Google have to release an officially-working NDK, but they need to decide on an ABI string, and get Sony (etc.) to push updates out to their customers that update build.prop on the devices with the new ABI string.

There’s also the possibility that Google doesn’t want to create and officially support that much native drift between phone-and-tablet Android and GTV Android, and will wait until manufacturers are running a more-stock Android 4.x on GTV (that uses the 4.x version of Bionic) before releasing an NDK that works… in which case we’re at the mercy of Sony for updates, unless XDA or CyanogenMod wants to take a crack at it. My money’s on this scenario, unfortunately.

One of the main things people have been screaming for is a version of XBMC that runs on GTV. I have been able to get it to build using my hacked-together toolchain, but not actually to run. I ran into problems with runtime linking: the built binaries depend on a shared libstdc++ and libgcc_s, neither of which appear to be included on the GTV’s filesystem. I tried including them in the APK, but, weirdly, when the GTV unpacks the native libs from the APK at install time, it discards those two libraries. Static linking of those two may not be possible since XBMC’s APK includes a bunch of native libs. A possible solution would be to build all of libxbmc.so’s dependencies as static libs, and then just make one big static library.

But I haven’t had time to work on this over the past couple weeks…

Google TV and Native Libraries

  • October 5, 2012
  • Brian Tarricone

The Google TV runs a fairly unusual flavor of Android (at least the 2nd-gen ARM-based devices). I have a Sony Internet Player (not the Blu-Ray version), so what I’m about to write applies to that device, but maybe not any other, though it stands to reason that the other ARM-based GTVs are the same.

Phone-and-tablet Android doesn’t look much like a Linux desktop or server system. It uses the Linux kernel, to be sure, but a lot of the userspace libraries are custom. It even does not use Glibc, but a C library that Google wrote called Bionic. It’s fairly stripped down and lightweight, and while it implements most things you might need out of a standard libc, it does not pretend to be POSIX compliant.

From some simple investigation, I’ve learned that the Sony GTV is running a EGlibc 2.12.2, and probably a mostly-unmodified version of it. Someone with an @google.com email address stated that the reason for this was that they couldn’t get Chrome running against the Honeycomb version of Bionic.

Due to this, a Native Development Kit (NDK) is not yet available for the GTV. So the question remains: can we hack one together that works? The answer is… sorta.

With this knowledge in hand, I built a relatively standard arm-linux-gnueabi toolchain using crosstool-ng. Then I ‘adb pull’-ed the contents of /system/lib from my GTV and merged them with the new toolchain’s sysroot, copied some headers out of a stock NDK, and ended up with a sysroot that approximates what you’d find in platforms/ in a stock NDK, just without Bionic, and with EGlibc.

I didn’t get to modifying the NDK’s build system (it would need to be changed to find the new toolchain), so I built my native library manually, and got a simple “hello world” type app with a native lib. (It just calls a native method that returns a string, and displays the string on a label.)

One annoying thing is that the ABI string in the Sony GTV is set to “none”, so you have to unpack the APK, rename lib/armeabi-v7a/ to lib/none/, and repack and resign it. All of this means that this would be strictly hobbyist for now: no chance that you could distribute something in the Play Store. Not only does Google have to release an officially-working NDK, but they need to decide on an ABI string, and get Sony (etc.) to push updates out to their customers that update build.prop on the devices with the new ABI string.

There’s also the possibility that Google doesn’t want to create and officially support that much native drift between phone-and-tablet Android and GTV Android, and will wait until manufacturers are running a more-stock Android 4.x on GTV (that uses the 4.x version of Bionic) before releasing an NDK that works… in which case we’re at the mercy of Sony for updates, unless XDA or CyanogenMod wants to take a crack at it. My money’s on this scenario, unfortunately.

One of the main things people have been screaming for is a version of XBMC that runs on GTV. I have been able to get it to build using my hacked-together toolchain, but not actually to run. I ran into problems with runtime linking: the built binaries depend on a shared libstdc++ and libgcc_s, neither of which appear to be included on the GTV’s filesystem. I tried including them in the APK, but, weirdly, when the GTV unpacks the native libs from the APK at install time, it discards those two libraries. Static linking of those two may not be possible since XBMC’s APK includes a bunch of native libs. A possible solution would be to build all of libxbmc.so’s dependencies as static libs, and then just make one big static library.

But I haven’t had time to work on this over the past couple weeks…

Techie TODO

  • April 16, 2012
  • Brian Tarricone

In no particular order.

  • Start blogging again.
  • Suck less at Javascript, even if it’s a shitty language.
  • Learn jQuery, even if it’s just a library to make a shitty language less shitty.
  • Learn Rails properly.
  • Get back into open source dev.
  • Find a project/idea I can potentially monetize, and build and launch it.
  • Throw out my website entirely and start from scratch.
  • Stop running MacOSX all the time on my laptop and get back to using Linux as my primary desktop OS.

Techie TODO

  • April 16, 2012
  • Brian Tarricone

In no particular order.

  • Start blogging again.

  • Suck less at Javascript, even if it’s a shitty language.

  • Learn jQuery, even if it’s just a library to make a shitty language less shitty.

  • Learn Rails properly.

  • Get back into open source dev.

  • Find a project/idea I can potentially monetize, and build and launch it.

  • Throw out my website entirely and start from scratch.

  • Stop running MacOSX all the time on my laptop and get back to using Linux as my primary desktop OS.

Gentoo Linux on an 11? MacBook Air (October 2010)

  • December 6, 2010
  • Brian Tarricone

I just posted a page detailing my experience installing Gentoo on one of the new MacBook Air models (in my case the MacBookAir3,1 with 1.6GHz CPU, 128GB SSD, and 4GB RAM). Hopefully it’ll be useful for others.

Gentoo Linux on an 11” MacBook Air (October 2010)

  • December 6, 2010
  • Brian Tarricone

I just posted a page detailing my experience installing Gentoo on one of the new MacBook Air models (in my case the MacBookAir3,1 with 1.6GHz CPU, 128GB SSD, and 4GB RAM). Hopefully it’ll be useful for others.

Amazon MP3 Downloader on 64bit Gentoo Linux

  • December 26, 2009
  • Brian Tarricone

(This is going to be a bit of a narrative. If you’re impatient, scroll to the “How-To” section at the bottom of the post.)

Today I decided to download an MP3 album from Amazon. I actually wanted all the songs on the particular album, and noted that you save a couple bucks by downloading the whole album vs. downloading each individual song. So click through, and find that it requires the Amazon Download Manager thingo.

Lame, I think. I click the download link, and it actually gives me some buttons to choose from that have to do with Linux. Huh. Nice work. However, I assume it’s closed-source proprietary crap. But hey, why not give it a try.

My choices are two .deb files, one for Ubuntu Jaunty, and one for Debian 5, or two .rpm files, one for Fedora 11, and one for OpenSuse somethingorother.

So I grab the Ubuntu one. I’m on Gentoo, so I “emerge dpkg”, and then run “dpkg -x amazonmp3.deb .” in an empty directory. I look in usr/bin that it created, and find a binary. But it’s a 32bit binary.

Crap.

I run ‘ldd’ on it, and of course it needs gtk and a bunch of other stuff that I don’t have 32bit libraries for. Like boost.

So I think, ok, I can install a 32bit chroot. So I download the stage3 Gentoo i686 tarball and unpack it in /opt/gentoo32. I also “emerge schroot” in my regular system, and set that up. I recently found schroot while using Ubuntu at work. It’s awesome. Eventually the stage3 tarball finishes up, so I schroot into my new 32bit environment and “emerge libboost”. After it’s finished, I note a problem. Amazon’s binary is expecting some weird version of boost that has “gcc42″ in the filename. Also, I just installed boost 1.35, and it wants 1.34. Out of desperation, I try to make symlinks to the correct file names, assuming it probably won’t work. I was right: it doesn’t work. Balls.

Then I think… well, why not install a chroot of 32bit Ubuntu Jaunty? I “emerge debootstrap” and pray… yep, it’s in portage, excellent. I install it, schroot into it, and apt-get a bunch of the libboost packages, and… holy crap, it works.

How-To

Here’s a step-by-step. This is for Gentoo, but it should work equally well on any system where you can install debootstrap and chroot. The following instructions assume you’ve installed them already.

As root on the “main” system:

# mkdir -p /opt/ubuntu-jaunty-32
# debootstrap --arch i386 jaunty /opt/ubuntu-jaunty-32 http://archive.ubuntu.com/ubuntu/
# cat >/etc/schroot/chroot.d/jaunty32.conf
[ubuntu-jaunty-32]
type=directory
description=Ubuntu Jaunty (32-bit)
location=/opt/ubuntu-jaunty-32
priority=3
users=$USER
groups=$USER,root
root-users=root,$USER
root-groups=root,wheel
personality=linux32
run-setup-scripts=true
run-exec-scripts=true
aliases=jaunty
[hit ctrl+d]
# cat >/etc/schroot/mount-defaults
/proc		/proc		none	rw,bind 	0	0
/proc/bus/usb	/proc/bus/usb	none	rw,bind		0	0
/sys		/sys		none    rw,bind		0	0
/dev		/dev		none	rw,bind		0	0
/dev/pts	/dev/pts	none	rw,bind		0	0
/dev/shm	/dev/shm	none	rw,bind		0	0
/home		/home		none	rw,bind		0	0
/tmp		/tmp		none	rw,bind		0	0
/var/run/dbus	/var/run/dbus	none	rw,bind		0	0
/usr/portage	/usr/portage	none	rw,bind		0	0
[hit ctrl+d]
# schroot -c jaunty
(32bit)# groupadd -r staff
(32bit)# apt-get update
(32bit)# apt-get install sudo curl libglademm-2.4-1c2a xdg-utils libboost-date-time1.34.1 libboost-filesystem1.34.1 libboost-iostreams1.34.1 libboost-regex1.34.1 libboost-signals1.34.1 libboost-thread1.34.1
(32bit)# dpkg -i $DOWNLOAD_DIR/amazonmp3.deb

Note that I didn’t just type all this verbatim… this was just my memory of what I did. So if something’s missing, please leave a note in the comments and I’ll update this.

Next you can try running “amazonmp3″ to test it. If that works, you can go back out to your “real” system (just type “exit” in that shell), and do this:

# mkdir -p /usr/local/bin
# cat >/usr/local/bin/amazonmp3
#!/bin/bash
schroot -c jaunty -p /usr/bin/amazonmp3 -- "$@"
[hit ctrl+d]
# chmod +x amazonmp3

This creates a script in your “real” system that will chain to the 32bit amazonmp3 binary in your Jaunty chroot. You can set up your browser of choice to automatically launch this script when you download .amz files. At this point you can try running “amazonmp3″ from your “real” system (outside the chroot) and see if that works.

There are also a few other things:

  1. If you are running a system that uses GDM to log in, you may need to add /var/run/gdm to the bind mounts in the mount-defaults file or else apps started in your chroot won’t be able to connect to your X server.
  2. If you’re using non-default gtk2 theme engines on your “real” desktop”, you’ll need to install them in the chroot (via apt-get) as well. Well, ok, you don’t have to, but if you don’t, the Amazon app will look uglier than it should.
  3. Remember to always pass the “-p” option to schroot. If you don’t, the environment in the chroot will get reset, which means you’ll lose your DISPLAY env var, and you won’t be able to connect to the X server without manually setting it.
  4. When I first ran the apt-get command in the chroot, I got some weird errors at the end of the process about some packages not being configured because another package (gtk, I think) that it depended on hadn’t been configured yet. Just running the same apt-get command a couple times fixed it, strangely.
  5. Make sure your “real” system has /usr/local/bin in the PATH.

Anyhow, that’s it. Works like a charm.

Amazon MP3 Downloader on 64bit Gentoo Linux

  • December 26, 2009
  • Brian Tarricone

Update 2010/12/04: A commenter recommended clamz instead. I’ve installed it but not yet tried it, but it’s certainly easier than installing another OS in a chroot.

(This is going to be a bit of a narrative. If you’re impatient, scroll to the “How-To” section at the bottom of the post.)

Today I decided to download an MP3 album from Amazon. I actually wanted all the songs on the particular album, and noted that you save a couple bucks by downloading the whole album vs. downloading each individual song. So click through, and find that it requires the Amazon Download Manager thingo.

Lame, I think. I click the download link, and it actually gives me some buttons to choose from that have to do with Linux. Huh. Nice work. However, I assume it’s closed-source proprietary crap. But hey, why not give it a try.

My choices are two .deb files, one for Ubuntu Jaunty, and one for Debian 5, or two .rpm files, one for Fedora 11, and one for OpenSuse somethingorother.

So I grab the Ubuntu one. I’m on Gentoo, so I “emerge dpkg”, and then run “dpkg -x amazonmp3.deb .” in an empty directory. I look in usr/bin that it created, and find a binary. But it’s a 32bit binary.

Crap.

I run ‘ldd’ on it, and of course it needs gtk and a bunch of other stuff that I don’t have 32bit libraries for. Like boost.

So I think, ok, I can install a 32bit chroot. So I download the stage3 Gentoo i686 tarball and unpack it in /opt/gentoo32. I also “emerge schroot” in my regular system, and set that up. I recently found schroot while using Ubuntu at work. It’s awesome. Eventually the stage3 tarball finishes up, so I schroot into my new 32bit environment and “emerge libboost”. After it’s finished, I note a problem. Amazon’s binary is expecting some weird version of boost that has “gcc42” in the filename. Also, I just installed boost 1.35, and it wants 1.34. Out of desperation, I try to make symlinks to the correct file names, assuming it probably won’t work. I was right: it doesn’t work. Balls.

Then I think… well, why not install a chroot of 32bit Ubuntu Jaunty? I “emerge debootstrap” and pray… yep, it’s in portage, excellent. I install it, schroot into it, and apt-get a bunch of the libboost packages, and… holy crap, it works.

How-To

Here’s a step-by-step. This is for Gentoo, but it should work equally well on any system where you can install debootstrap and chroot. The following instructions assume you’ve installed them already.

As root on the “main” system:

# mkdir -p /opt/ubuntu-jaunty-32
# debootstrap --arch i386 jaunty /opt/ubuntu-jaunty-32 http://archive.ubuntu.com/ubuntu/
# cat >/etc/schroot/chroot.d/jaunty32.conf
[ubuntu-jaunty-32]
type=directory
description=Ubuntu Jaunty (32-bit)
location=/opt/ubuntu-jaunty-32
priority=3
users=$USER
groups=$USER,root
root-users=root,$USER
root-groups=root,wheel
personality=linux32
run-setup-scripts=true
run-exec-scripts=true
aliases=jaunty
[hit ctrl+d]
# cat >/etc/schroot/mount-defaults
/proc/procnonerw,bind 00
/proc/bus/usb/proc/bus/usbnonerw,bind00
/sys/sysnone    rw,bind00
/dev/devnonerw,bind00
/dev/pts/dev/ptsnonerw,bind00
/dev/shm/dev/shmnonerw,bind00
/home/homenonerw,bind00
/tmp/tmpnonerw,bind00
/var/run/dbus/var/run/dbusnonerw,bind00
/usr/portage/usr/portagenonerw,bind00
[hit ctrl+d]
# schroot -c jaunty
(32bit)# groupadd -r staff
(32bit)# apt-get update
(32bit)# apt-get install sudo curl libglademm-2.4-1c2a xdg-utils libboost-date-time1.34.1 libboost-filesystem1.34.1 libboost-iostreams1.34.1 libboost-regex1.34.1 libboost-signals1.34.1 libboost-thread1.34.1
(32bit)# dpkg -i $DOWNLOAD_DIR/amazonmp3.deb

Note that I didn’t just type all this verbatim… this was just my memory of what I did. So if something’s missing, please leave a note in the comments and I’ll update this.

Next you can try running “amazonmp3” to test it. If that works, you can go back out to your “real” system (just type “exit” in that shell), and do this:

# mkdir -p /usr/local/bin
# cat >/usr/local/bin/amazonmp3
#!/bin/bash
schroot -c jaunty -p /usr/bin/amazonmp3 -- "$@"
[hit ctrl+d]
# chmod +x amazonmp3

This creates a script in your “real” system that will chain to the 32bit amazonmp3 binary in your Jaunty chroot. You can set up your browser of choice to automatically launch this script when you download .amz files. At this point you can try running “amazonmp3” from your “real” system (outside the chroot) and see if that works.

There are also a few other things:

  1. If you are running a system that uses GDM to log in, you may need to add /var/run/gdm to the bind mounts in the mount-defaults file or else apps started in your chroot won’t be able to connect to your X server.

  2. If you’re using non-default gtk2 theme engines on your “real” desktop”, you’ll need to install them in the chroot (via apt-get) as well. Well, ok, you don’t have to, but if you don’t, the Amazon app will look uglier than it should.

  3. Remember to always pass the “-p” option to schroot. If you don’t, the environment in the chroot will get reset, which means you’ll lose your DISPLAY env var, and you won’t be able to connect to the X server without manually setting it.

  4. When I first ran the apt-get command in the chroot, I got some weird errors at the end of the process about some packages not being configured because another package (gtk, I think) that it depended on hadn’t been configured yet. Just running the same apt-get command a couple times fixed it, strangely.

  5. Make sure your “real” system has /usr/local/bin in the PATH.

Anyhow, that’s it. Works like a charm.

New Laptop (aka Gentoo On MacBook Pro 5,5)

  • July 6, 2009
  • Brian Tarricone

NB: I’ve cleaned up this guide and moved it, and I’ll continue to update it there. This blog post will not get any more updates.

Those of you who have chatted with me over the past… er… 18 months or so… know I’ve been wanting a new laptop for a while. Those of you who have chatted with me over the past 6 months know that I’d settled on a 13” MacBook, but I wanted to wait until Apple’s next refresh/update before making the purchase.

Apple updated their laptop line at WWDC in June 2009, and I was pretty much perfectly sold on the 13” MacBook Pro (one of the “updates” was to rebrand the 13” aluminum unibody MacBooks as Pro models).

I was in Maryland for a wedding, and decided to take advantage of the lower tax rate (than California’s) and my sister’s educational discount (she’s a teacher). As a nice bonus of the edu pricing, I also got a free 8GB iPod Touch (which I really like a lot more than I expected to).

So ok, enough background.

Vital stuff: this describes my experience installing Linux on a June 2009 era MacBook Pro 13”. DMI reports that this model name is “MacBookPro5,5”. This guide may work for other similar systems, or it may not.

lspci output for this laptop:

00:00.0 Host bridge: nVidia Corporation Device 0a82 (rev b1)
00:00.1 RAM memory: nVidia Corporation Device 0a88 (rev b1)
00:03.0 ISA bridge: nVidia Corporation Device 0aae (rev b3)
00:03.1 RAM memory: nVidia Corporation Device 0aa4 (rev b1)
00:03.2 SMBus: nVidia Corporation Device 0aa2 (rev b1)
00:03.3 RAM memory: nVidia Corporation Device 0a89 (rev b1)
00:03.4 RAM memory: nVidia Corporation Device 0a98 (rev b1)
00:03.5 Co-processor: nVidia Corporation Device 0aa3 (rev b1)
00:04.0 USB Controller: nVidia Corporation Device 0aa5 (rev b1)
00:04.1 USB Controller: nVidia Corporation Device 0aa6 (rev b1)
00:06.0 USB Controller: nVidia Corporation Device 0aa7 (rev b1)
00:06.1 USB Controller: nVidia Corporation Device 0aa9 (rev b1)
00:08.0 Audio device: nVidia Corporation Device 0ac0 (rev b1)
00:09.0 PCI bridge: nVidia Corporation Device 0aab (rev b1)
00:0a.0 Ethernet controller: nVidia Corporation MCP79 Ethernet (rev b1)
00:0b.0 IDE interface: nVidia Corporation Device 0ab5 (rev b1)
00:10.0 PCI bridge: nVidia Corporation Device 0aa0 (rev b1)
00:15.0 PCI bridge: nVidia Corporation Device 0ac6 (rev b1)
00:16.0 PCI bridge: nVidia Corporation Device 0ac7 (rev b1)
02:00.0 VGA compatible controller: nVidia Corporation Device 0863 (rev b1)
03:00.0 Network controller: Broadcom Corporation BCM4322 802.11a/b/g/n Wireless LAN Controller (rev 01)
04:00.0 FireWire (IEEE 1394): Agere Systems Device 5901 (rev 07)

Install Media

I decided to put Gentoo (the x86_64 version) on it. So, I grabbed the latest minimal installer (dated 20090618) and booted it. I was disappointed to find that the keyboard didn’t work after boot, so I couldn’t go anywhere with it. I Googled around a bit, but wasn’t able to find anything (except for the possibility of the usbhid driver failing to load due to an unrecognised option, which I thought a bit unlikely). After some head-scratching, I downloaded the install/live CD of Ubuntu 9.04, and booted that. To my happiness, the keyboard was working fine.

rEFIt

Backing up a little… Before booting the Linux CD, first I installed rEFIt from inside MacOS X. I didn’t burn the rEFIt bootable CD; I just went ahead and used the Mac installer which did the job without rebooting. After that I could still boot other CDs by holding down the “c” key while booting, but if I didn’t, I got a nifty boot menu with MacOS X listed.

Dual Boot

I decided I wanted to keep my MacOS X partition, so I fired up Disk Utility and resized the HFS+ MacOS partition down to 40GB. Yes, amazingly, current Leopard (10.5.7) Disk Utility can resize the startup volume while MacOS is running, without needing to use the installer DVD or reboot at all. It just resizes it live and you’re done. It was very quick, too.

BIOS Mode and Partitioning

I’ve read various sources that said that the proprietary nvidia drivers would not work with the machine in native EFI mode (though this seems to suggest otherwise, but I haven’t tried it), so it would have to be booted in BIOS mode. Unfortunately, this makes partitioning the drive a little annoying, as I wanted to keep MacOS X to dual-boot. The GPT partition table layout has a legacy MBR mode for booting BIOS-mode OSes (in our case, grub is the legacy OS).

The MBR compatibility mode only supports four primary partitions, and no extended partitions, so the partition with your kernel on it needs to be one of the first four. Since Apple takes up the first two partition slots (I’m told MacOS X will boot without the first partition, but it’s unclear as to whether or not missing that partition will screw up Apple-supplied updates later), that leaves two left. Plenty. Three and four ended up being /boot (96MB), and / (around 60GB). Initially, I was debating leaving out the swap partition, but Linux’s suspend to disk (aka hibernate) requires a swap partition, so I allocated 4GB for it. The rest of the space I allocated for /home. I used ext3 for the root and home partitions, since I don’t trust ext4 yet, and tools for manipulating ext4 volumes from other OSes are currently nonexistent. For the boot partition I used ext2, and set ‘noauto’ in the mount options so it doesn’t get mounted unless I tell it to. Note that all of these partitions should be primary partitions. GPT doesn’t use anything else. Grub will only be able to see my first two Linux partitions (/boot and /), but that’s fine, as the kernel will be on /boot, and once Linux comes up it will know how to read the real GPT partition table to find the rest of the partitions.

GPT Resync

After partitioning, I rebooted and selected the GPT/MBR partition table sync item from the rEFIt boot menu. This turned out to be unnecessary for me (I think gparted did it for me?), but this might be needed in some cases.

Gentoo Install

After partitioning, I pretty much followed the normal Gentoo install procedure (downloading a stage3 tarball, unpacking it to the root partition, chrooting, setting up a new kernel and various stuff, installing grub, and rebooting). It was remarkably painless. After the reboot, the rEFIt boot menu had an entry for Linux (with a cute penguin icon) next to the MacOS X entry, so I selected that and booted.

Kernel

I started off with the gentoo-sources-2.6.30-r1 kernel (and just today updated to -r2 with no trouble). Here’s my kernel config. I set up the uvesafb framebuffer console driver, which seems to work great.

Video

I installed nvidia-drivers-180.60. Previous versions did not compile against the 2.6.30 kernel. I created a minimal /etc/X11/xorg.conf file that only had 4 lines in it to set the video driver to “nvidia” and let the X server auto-config the rest. It appears to work fine; came up the first time at 1280x800 automatically. I didn’t test the external monitor support, as I don’t have any DisplayPort devices, and I didn’t buy the DVI adapter.

Display Backlight

The backlight didn’t work at first, because it looks for specific MBP models, and this new laptop has a newer model number. I simply patched the ‘mbp-nvidia-bl’ driver (update: see below for a better patch) in the kernel to add “MacBookPro5,5” as a recognised model. However, the backlight controls for some reason do not work while X is running. I suspect the nvidia driver to be at fault here, but more investigation is needed. I’m going to give nouveau a try at some point to see if this fixes any issues (though of course I’ll lose 3D accel with that).

Update (2009/07/14): The ‘nvclock’ program is able to set the backlight brightness while X is running, so I ‘ported’ the code that does that to the kernel driver. It’s not the best patch in the world, but it’s here if you want to give it a try. I’m told that this is not really a correct way of fixing the problem, as it’s not reasonable to poke at memory addresses owned/reserved by another driver (nvidia, in this case). So expect that some weirdness might occur if you use my patch.

Keyboard Illumination

The keyboard illumination works. The ‘applesmc’ driver detects it and creates a LED-class device (you can see it in /sys/class/leds). The ‘pommed’ daemon is supposed to support this, but I haven’t tried it yet because it requires patching to support the “MacBookPro5,5” string. Otherwise I can manually set the keyboard lighting via the sysfs interface (just to verify it works). The ‘pommed’ daemon will monitor the light sensor and adjust the keyboard brightness accordingly. I needed to patch it to get it to recognise the new model string. Apparently upstream already has a patch and support will work in the next release. I also patched it to increase some ridiculously-stupid battery-wasting 200ms timeouts into equally-useful 2s timeouts. Ideally it shouldn’t poll at all, but I don’t care enough to put in the work to make that happen.

Touchpad

The touchpad works with the ‘bcm5974’ kernel driver and xf86-input-synaptics X.org driver. Note that to make X.org correctly use the synaptics driver when you aren’t providing an xorg.conf file, you need a very recent version of the hal-info package (otherwise it will use the evdev driver). I also have a custom .fdi file to specify some extra options for the driver. Left click works, and 2-finger clicking for right click and 3-finger clicking for middle click work as well. Two-finger horizontal and vertical scrolling work fine. One major annoyance is drag and drop: with MacOS running, I can click and hold with my thumb, and drag with my index finger (while keeping my thumb still). With Linux, I have to click and drag with the same finger, which is very awkward. I filed a feature request about this.

WiFi

The WiFi works, but unfortunately not with the open source ‘b43’ driver, as that driver does not yet support Broadcom 802.11n chipsets. Broadcom provides a closed-source proprietary driver which seems to work decently, though the speeds I’m getting aren’t great, and it has a lot of trouble finding my 5GHz 11n AP sometimes (it finds the 2.4GHz 11g AP just fine though). Udev initially assigned the device the “eth1” name, which I didn’t like, so I edited /etc/udev/rules.d/70-persistent-net.rules to change it to “wlan0”. NetworkManager works, though intermittently it won’t be able to find any APs (despite the fact that “iwlist wlan0 scan” shows APs). I anxiously await support from the ‘b43’ driver.

When compiling the Broadcom ‘wl’ driver, be sure to read the README on their website. The compilation is a little weird as they only provide a stub Makefile for use with the kernel’s build system. You’ll probably want to add ‘wl’ to /etc/conf.d/modules (or /etc/modules.autoload.d/kernel-2.6) to get loaded on startup. You may want to add ‘b43’ and ‘ssb’ to the blacklist in /etc/modprobe.d to be safe. If even the ssb driver gets loaded (even if b43 is not loaded), wl won’t work.

One oddity: wl requires the full suite of lib80211 helper modules, including the crypto ones. For some reason these don’t get built properly unless you compile another driver into the kernel that needs them, like CONFIG_HOSTAP (you can just compile it as a module).

Bluetooth

The bluetooth chipset is detected, using the standard ‘btusb’ driver. I haven’t tested functionality yet because Bluez 4 is giving me issues.

iSight Camera

The iSight works just fine with the ‘uvcvideo’ module. Interestingly, on this laptop I did not have to extract the firmware from Apple’s MacOS X driver. Oddly, sometimes the driver for it fails to load properly, complaining about not finding a “video chain” or something similar, but removing and reloading the driver usually fixes it (very occasionally a reboot seems to be required).

Sound

I haven’t been able to get sound to work yet. The snd-hda-intel driver appears to detect the device, and I can unmute it and change the volume, but playing .wav files using aplay doesn’t produce sound. I didn’t get any output from the dual-purpose audio in/out jack either. I’ve tried the patch here, as well as trying ALSA’s git repository, but no luck. My current guess is that Apple decided to use a new sound chip. I filed an issue report with ALSA here. My bug hasn’t appeared to gain any attention, but someone else’s post to alsa-devel has gotten some response, so it looks like this is being worked on.

Update (2009/07/10): There’s now experimental support for the Cirrus Logic codec in the hda-cirrus branch of Takashi Iwai’s sound-unstable-2.6 tree. I imagine this’ll end up in 2.6.31 or .32. I haven’t tried it yet, but it’s been reported to work on the MacBookPro5,5 (and was indeed the motivation for writing the codec support).

Update (2009/07/12): The new driver works for me, though the sound-unstable-2.6 tree is based on 2.6.31rc1 as of this writing, so it’s a little bit of a pain because neither the Broadcom wl driver nor the nvidia binary driver compile correctly against it. I whipped up a couple patches and submitted them to Gentoo’s bug tracker (for broadcom-sta, for nvidia-drivers), so hopefully they’ll get included in the portage tree soon (and presumably added to future releases). Here’s my new kernel config; you just need hda-intel with Cirrus Logic codec support. You could also compile it into the kernel, but I’ve left it as modules for now.

Suspend/Hibernate

Untested.

Update (2009/07/16): I wish I’d tested this first off, because suspend at least worked perfectly out of the box. No tweaks necessary. I just installed pm-utils and suspended via HAL (using xfce4-power-manager in my case). I imagine calling ‘pm-suspend’ from the command line would work as well.

Miscellaneous

Shutdown and reboot do not work. The system just halts and locks up. You’ll need to hold down the power button for 5 seconds to shut it off. On a rare occasion shutdown will actually power off the unit, but reboot has never worked. I suspect that dropping the BIOS emulation and booting in EFI mode will solve this problem.

USB works fine for mass storage devices, at least. The SD card reader is detected as a usb-storage device, and works as it should.

Firewire drivers load (I used the kernel’s “new” firewire stack) and detect the chipset just fine, but I don’t have any devices to test it with.

This laptop has an accelerometer (aka Apple Motion Sensor). It appears to work; I can read the machine’s orientation via sysfs, but I don’t know if there are any daemons that will watch it and park the heads on the hard drive if the laptop gets shaken/dropped. There are also other nifty things you can do with it that I haven’t tried.

All things considered, I’m pretty happy. I haven’t gotten to a point where I can give meaningful battery life numbers, but I’ll try to get to that soon. The machine seems to run pretty cool and quiet, even while compiling for a while. My only major outstanding issue is sound.

BIOS mode vs. EFI mode

In order to get shutdown and reboot working, I’ve been trying to boot in EFI mode, with no success yet. I’ve tried the latest SVN versions of grub2, but I’ve had a lot of trouble. rEFIt only seems to find grub.efi if I put it on the HFS+ MacOS X partition; if put it on the Linux partition, it doesn’t work. Running rEFIt’s EFI console and poking at the disk partitions seems to indicate that it’s failing to read the ext3 partitions for some reason.

Grub2 otherwise just seems very buggy. The config file parsing doesn’t appear to work (when grub2 loads, it prints messages about “menuentry” being an invalid command). Despite the fact that linux.mod is loaded, “linux” isn’t being recognised as a valid command. In fact, after I use many commands once, successive uses claim that the command is invalid. Even the “help” command doesn’t work (fortunately, hitting the tab key lists valid commands). I’ve mostly given up on grub2. One of the nice things about grub2 is that, if you boot in BIOS mode, you can dump your main and video BIOS images which grub2 can later load/emulate on bootup in EFI mode, which presumably would allow the nvidia drivers to work correctly.

So next I’ll be giving elilo a try. It apparently doesn’t have support for loading BIOS images, but maybe I can get that to work eventually.

New Laptop (aka Gentoo On MacBook Pro 5,5)

  • July 6, 2009
  • Brian Tarricone

NB: I’ve cleaned up this guide and moved it, and I’ll continue to update it there. This blog post will not get any more updates.

Those of you who have chatted with me over the past… er… 18 months or so… know I’ve been wanting a new laptop for a while. Those of you who have chatted with me over the past 6 months know that I’d settled on a 13″ MacBook, but I wanted to wait until Apple’s next refresh/update before making the purchase.

Apple updated their laptop line at WWDC in June 2009, and I was pretty much perfectly sold on the 13″ MacBook Pro (one of the “updates” was to rebrand the 13″ aluminum unibody MacBooks as Pro models).

I was in Maryland for a wedding, and decided to take advantage of the lower tax rate (than California’s) and my sister’s educational discount (she’s a teacher). As a nice bonus of the edu pricing, I also got a free 8GB iPod Touch (which I really like a lot more than I expected to).

So ok, enough background.

Vital stuff: this describes my experience installing Linux on a June 2009 era MacBook Pro 13″. DMI reports that this model name is “MacBookPro5,5″. This guide may work for other similar systems, or it may not.

lspci output for this laptop:

00:00.0 Host bridge: nVidia Corporation Device 0a82 (rev b1)
00:00.1 RAM memory: nVidia Corporation Device 0a88 (rev b1)
00:03.0 ISA bridge: nVidia Corporation Device 0aae (rev b3)
00:03.1 RAM memory: nVidia Corporation Device 0aa4 (rev b1)
00:03.2 SMBus: nVidia Corporation Device 0aa2 (rev b1)
00:03.3 RAM memory: nVidia Corporation Device 0a89 (rev b1)
00:03.4 RAM memory: nVidia Corporation Device 0a98 (rev b1)
00:03.5 Co-processor: nVidia Corporation Device 0aa3 (rev b1)
00:04.0 USB Controller: nVidia Corporation Device 0aa5 (rev b1)
00:04.1 USB Controller: nVidia Corporation Device 0aa6 (rev b1)
00:06.0 USB Controller: nVidia Corporation Device 0aa7 (rev b1)
00:06.1 USB Controller: nVidia Corporation Device 0aa9 (rev b1)
00:08.0 Audio device: nVidia Corporation Device 0ac0 (rev b1)
00:09.0 PCI bridge: nVidia Corporation Device 0aab (rev b1)
00:0a.0 Ethernet controller: nVidia Corporation MCP79 Ethernet (rev b1)
00:0b.0 IDE interface: nVidia Corporation Device 0ab5 (rev b1)
00:10.0 PCI bridge: nVidia Corporation Device 0aa0 (rev b1)
00:15.0 PCI bridge: nVidia Corporation Device 0ac6 (rev b1)
00:16.0 PCI bridge: nVidia Corporation Device 0ac7 (rev b1)
02:00.0 VGA compatible controller: nVidia Corporation Device 0863 (rev b1)
03:00.0 Network controller: Broadcom Corporation BCM4322 802.11a/b/g/n Wireless LAN Controller (rev 01)
04:00.0 FireWire (IEEE 1394): Agere Systems Device 5901 (rev 07)

Install Media

I decided to put Gentoo (the x86_64 version) on it. So, I grabbed the latest minimal installer (dated 20090618) and booted it. I was disappointed to find that the keyboard didn’t work after boot, so I couldn’t go anywhere with it. I Googled around a bit, but wasn’t able to find anything (except for the possibility of the usbhid driver failing to load due to an unrecognised option, which I thought a bit unlikely). After some head-scratching, I downloaded the install/live CD of Ubuntu 9.04, and booted that. To my happiness, the keyboard was working fine.

rEFIt

Backing up a little… Before booting the Linux CD, first I installed rEFIt from inside MacOS X. I didn’t burn the rEFIt bootable CD; I just went ahead and used the Mac installer which did the job without rebooting. After that I could still boot other CDs by holding down the “c” key while booting, but if I didn’t, I got a nifty boot menu with MacOS X listed.

Dual Boot

I decided I wanted to keep my MacOS X partition, so I fired up Disk Utility and resized the HFS+ MacOS partition down to 40GB. Yes, amazingly, current Leopard (10.5.7) Disk Utility can resize the startup volume while MacOS is running, without needing to use the installer DVD or reboot at all. It just resizes it live and you’re done. It was very quick, too.

BIOS Mode and Partitioning

I’ve read various sources that said that the proprietary nvidia drivers would not work with the machine in native EFI mode (though this seems to suggest otherwise, but I haven’t tried it), so it would have to be booted in BIOS mode. Unfortunately, this makes partitioning the drive a little annoying, as I wanted to keep MacOS X to dual-boot. The GPT partition table layout has a legacy MBR mode for booting BIOS-mode OSes (in our case, grub is the legacy OS).

The MBR compatibility mode only supports four primary partitions, and no extended partitions, so the partition with your kernel on it needs to be one of the first four. Since Apple takes up the first two partition slots (I’m told MacOS X will boot without the first partition, but it’s unclear as to whether or not missing that partition will screw up Apple-supplied updates later), that leaves two left. Plenty. Three and four ended up being /boot (96MB), and / (around 60GB). Initially, I was debating leaving out the swap partition, but Linux’s suspend to disk (aka hibernate) requires a swap partition, so I allocated 4GB for it. The rest of the space I allocated for /home. I used ext3 for the root and home partitions, since I don’t trust ext4 yet, and tools for manipulating ext4 volumes from other OSes are currently nonexistent. For the boot partition I used ext2, and set ‘noauto’ in the mount options so it doesn’t get mounted unless I tell it to. Note that *all* of these partitions should be primary partitions. GPT doesn’t use anything else. Grub will only be able to see my first two Linux partitions (/boot and /), but that’s fine, as the kernel will be on /boot, and once Linux comes up it will know how to read the real GPT partition table to find the rest of the partitions.

GPT Resync

After partitioning, I rebooted and selected the GPT/MBR partition table sync item from the rEFIt boot menu. This turned out to be unnecessary for me (I think gparted did it for me?), but this might be needed in some cases.

Gentoo Install

After partitioning, I pretty much followed the normal Gentoo install procedure (downloading a stage3 tarball, unpacking it to the root partition, chrooting, setting up a new kernel and various stuff, installing grub, and rebooting). It was remarkably painless. After the reboot, the rEFIt boot menu had an entry for Linux (with a cute penguin icon) next to the MacOS X entry, so I selected that and booted.

Kernel

I started off with the gentoo-sources-2.6.30-r1 kernel (and just today updated to -r2 with no trouble). Here’s my kernel config. I set up the uvesafb framebuffer console driver, which seems to work great.

Video

I installed nvidia-drivers-180.60. Previous versions did not compile against the 2.6.30 kernel. I created a minimal /etc/X11/xorg.conf file that only had 4 lines in it to set the video driver to “nvidia” and let the X server auto-config the rest. It appears to work fine; came up the first time at 1280×800 automatically. I didn’t test the external monitor support, as I don’t have any DisplayPort devices, and I didn’t buy the DVI adapter.

Display Backlight

The backlight didn’t work at first, because it looks for specific MBP models, and this new laptop has a newer model number. I simply patched the ‘mbp-nvidia-bl’ driver (update: see below for a better patch) in the kernel to add “MacBookPro5,5″ as a recognised model. However, the backlight controls for some reason do not work while X is running. I suspect the nvidia driver to be at fault here, but more investigation is needed. I’m going to give nouveau a try at some point to see if this fixes any issues (though of course I’ll lose 3D accel with that).

Update (2009/07/14): The ‘nvclock’ program is able to set the backlight brightness while X is running, so I ‘ported’ the code that does that to the kernel driver. It’s not the best patch in the world, but it’s here if you want to give it a try. I’m told that this is not really a correct way of fixing the problem, as it’s not reasonable to poke at memory addresses owned/reserved by another driver (nvidia, in this case). So expect that some weirdness might occur if you use my patch.

Keyboard Illumination

The keyboard illumination works. The ‘applesmc’ driver detects it and creates a LED-class device (you can see it in /sys/class/leds). The ‘pommed’ daemon is supposed to support this, but I haven’t tried it yet because it requires patching to support the “MacBookPro5,5″ string. Otherwise I can manually set the keyboard lighting via the sysfs interface (just to verify it works). The ‘pommed’ daemon will monitor the light sensor and adjust the keyboard brightness accordingly. I needed to patch it to get it to recognise the new model string. Apparently upstream already has a patch and support will work in the next release. I also patched it to increase some ridiculously-stupid battery-wasting 200ms timeouts into equally-useful 2s timeouts. Ideally it shouldn’t poll at all, but I don’t care enough to put in the work to make that happen.

Touchpad

The touchpad works with the ‘bcm5974′ kernel driver and xf86-input-synaptics X.org driver. Note that to make X.org correctly use the synaptics driver when you aren’t providing an xorg.conf file, you need a very recent version of the hal-info package (otherwise it will use the evdev driver). I also have a custom .fdi file to specify some extra options for the driver. Left click works, and 2-finger clicking for right click and 3-finger clicking for middle click work as well. Two-finger horizontal and vertical scrolling work fine. One major annoyance is drag and drop: with MacOS running, I can click and hold with my thumb, and drag with my index finger (while keeping my thumb still). With Linux, I have to click and drag with the same finger, which is very awkward. I filed a feature request about this.

WiFi

The WiFi works, but unfortunately not with the open source ‘b43′ driver, as that driver does not yet support Broadcom 802.11n chipsets. Broadcom provides a closed-source proprietary driver which seems to work decently, though the speeds I’m getting aren’t great, and it has a lot of trouble finding my 5GHz 11n AP sometimes (it finds the 2.4GHz 11g AP just fine though). Udev initially assigned the device the “eth1″ name, which I didn’t like, so I edited /etc/udev/rules.d/70-persistent-net.rules to change it to “wlan0″. NetworkManager works, though intermittently it won’t be able to find any APs (despite the fact that “iwlist wlan0 scan” shows APs). I anxiously await support from the ‘b43′ driver.

When compiling the Broadcom ‘wl’ driver, be sure to read the README on their website. The compilation is a little weird as they only provide a stub Makefile for use with the kernel’s build system. You’ll probably want to add ‘wl’ to /etc/conf.d/modules (or /etc/modules.autoload.d/kernel-2.6) to get loaded on startup. You may want to add ‘b43′ and ‘ssb’ to the blacklist in /etc/modprobe.d to be safe. If even the ssb driver gets loaded (even if b43 is not loaded), wl won’t work.

One oddity: wl requires the full suite of lib80211 helper modules, including the crypto ones. For some reason these don’t get built properly unless you compile another driver into the kernel that needs them, like CONFIG_HOSTAP (you can just compile it as a module).

Bluetooth

The bluetooth chipset is detected, using the standard ‘btusb’ driver. I haven’t tested functionality yet because Bluez 4 is giving me issues.

iSight Camera

The iSight works just fine with the ‘uvcvideo’ module. Interestingly, on this laptop I did not have to extract the firmware from Apple’s MacOS X driver. Oddly, sometimes the driver for it fails to load properly, complaining about not finding a “video chain” or something similar, but removing and reloading the driver usually fixes it (very occasionally a reboot seems to be required).

Sound

I haven’t been able to get sound to work yet. The snd-hda-intel driver appears to detect the device, and I can unmute it and change the volume, but playing .wav files using aplay doesn’t produce sound. I didn’t get any output from the dual-purpose audio in/out jack either. I’ve tried the patch here, as well as trying ALSA’s git repository, but no luck. My current guess is that Apple decided to use a new sound chip. I filed an issue report with ALSA here. My bug hasn’t appeared to gain any attention, but someone else’s post to alsa-devel has gotten some response, so it looks like this is being worked on.

Update (2009/07/10): There’s now experimental support for the Cirrus Logic codec in the hda-cirrus branch of Takashi Iwai’s sound-unstable-2.6 tree. I imagine this’ll end up in 2.6.31 or .32. I haven’t tried it yet, but it’s been reported to work on the MacBookPro5,5 (and was indeed the motivation for writing the codec support).

Update (2009/07/12): The new driver works for me, though the sound-unstable-2.6 tree is based on 2.6.31rc1 as of this writing, so it’s a little bit of a pain because neither the Broadcom wl driver nor the nvidia binary driver compile correctly against it. I whipped up a couple patches and submitted them to Gentoo’s bug tracker (for broadcom-sta, for nvidia-drivers), so hopefully they’ll get included in the portage tree soon (and presumably added to future releases). Here’s my new kernel config; you just need hda-intel with Cirrus Logic codec support. You could also compile it into the kernel, but I’ve left it as modules for now.

Suspend/Hibernate

Untested.

Update (2009/07/16): I wish I’d tested this first off, because suspend at least worked perfectly out of the box. No tweaks necessary. I just installed pm-utils and suspended via HAL (using xfce4-power-manager in my case). I imagine calling ‘pm-suspend’ from the command line would work as well.

Miscellaneous

Shutdown and reboot do not work. The system just halts and locks up. You’ll need to hold down the power button for 5 seconds to shut it off. On a rare occasion shutdown will actually power off the unit, but reboot has never worked. I suspect that dropping the BIOS emulation and booting in EFI mode will solve this problem.

USB works fine for mass storage devices, at least. The SD card reader is detected as a usb-storage device, and works as it should.

Firewire drivers load (I used the kernel’s “new” firewire stack) and detect the chipset just fine, but I don’t have any devices to test it with.

This laptop has an accelerometer (aka Apple Motion Sensor). It appears to work; I can read the machine’s orientation via sysfs, but I don’t know if there are any daemons that will watch it and park the heads on the hard drive if the laptop gets shaken/dropped. There are also other nifty things you can do with it that I haven’t tried.

All things considered, I’m pretty happy. I haven’t gotten to a point where I can give meaningful battery life numbers, but I’ll try to get to that soon. The machine seems to run pretty cool and quiet, even while compiling for a while. My only major outstanding issue is sound.

BIOS mode vs. EFI mode

In order to get shutdown and reboot working, I’ve been trying to boot in EFI mode, with no success yet. I’ve tried the latest SVN versions of grub2, but I’ve had a lot of trouble. rEFIt only seems to find grub.efi if I put it on the HFS+ MacOS X partition; if put it on the Linux partition, it doesn’t work. Running rEFIt’s EFI console and poking at the disk partitions seems to indicate that it’s failing to read the ext3 partitions for some reason.

Grub2 otherwise just seems very buggy. The config file parsing doesn’t appear to work (when grub2 loads, it prints messages about “menuentry” being an invalid command). Despite the fact that linux.mod is loaded, “linux” isn’t being recognised as a valid command. In fact, after I use many commands once, successive uses claim that the command is invalid. Even the “help” command doesn’t work (fortunately, hitting the tab key lists valid commands). I’ve mostly given up on grub2. One of the nice things about grub2 is that, if you boot in BIOS mode, you can dump your main and video BIOS images which grub2 can later load/emulate on bootup in EFI mode, which presumably would allow the nvidia drivers to work correctly.

So next I’ll be giving elilo a try. It apparently doesn’t have support for loading BIOS images, but maybe I can get that to work eventually.