Julian Simioni

Installing Gentoo on a Macbook Pro, Part 3

| Comments

Since last time I’ve made steady progress on various fronts.

WiFi

I actually spent quite a bit of time fiddling with wifi to get it working, when in reality it was quite simple. I am now running linux 3.3, so support for the BCM4331 chip is included by default in the linux kernel. Firmware has to be downloaded and installed, but fortunately the instructions at the b43 driver page work perfectly. The one catch is that in addition to the CONFIG_B43 and CONFIG_B43_PHY_HT kernel options to actually enable the drivers, CONFIG_BCMA is required as well.

After this, wifi worked great, although 802.11n support does not yet exist. I installed wicd and everything worked fine. Initially I was running into issues with wicd asking for a password each time I logged into KDE, but adding wicd to the default runlevel fixed that, and now my computer will automatically connect to wifi networks on startup (assuming of course there is no ethernet connection and there is an unsecured or previously configured wireless network nearby).

Annoying Startup Chime

Thusfar, every time I boot or reboot (quite often when testing kernel things!) my laptop has made the infamous startup chime. Apparently the only way to turn this off is to boot into OS X and set the volume to 0. Fortunately, I had my untouched OS X install on the original hard drive, and it is possible to boot from an external hard drive via USB. So I was able to boot into OS X once just to mute the volume. I actually went through all the initial setup steps, maybe I didn’t even need to go that far, and just lower the volume immediately.

FaceTime Camera

I didn’t see much use even enabling support for the built in camera until I learned there is a google chat plugin that allows you to do video chatting over gmail. With minimal work I was able to get everything running quickly.

The webcam section of the Macbook Pro Gentoo wiki page instructions were all I had to follow. A few steps there are apparently redundant for the newer models, here’s what I did:

1.) Enable kernel support. The only option required is CONFIG_USB_VIDEO_CLASS. I built it as a module.

2.) Unmask and install media-video/isight-firmware-tools. I unmasked version 1.6.

3.) Extract the firmware file. This requires the firmware file from Mac OS X itself. Fortunately I have my original OS X installation on an external hard drive. I had to build the HFS and HFS+ kernel modules, but I was able to easily grab this file. It can be found at

System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS/AppleUSBVideoSupport

Then it’s a simple task to extract the relevant firmware

ift-extract --apple-driver AppleUSBVideoSupport

4.) It’s possible to immediately test if everything is working via mplayer. I first had to enable the v4l and v4l2 use flags and recompile, but once done the webcam should display with the following command:

mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -fps 20 -vo x11

I didn’t have to setup any dbus rules to create any device nodes.

5.) Finally, simply unmasking and installing www-plugins/google-talkplugin allowed me to video chat via gmail in Firefox.

Intel Graphics

I haven’t made any functional modifications since last time, booting still works fine using simple patches that allow setting the number of lvms channels manually. However I spent some time digging into the actual development work being done here. First I found the intel-gfx mailing list while browsing the mailing lists on freedesktop.org. I came across a bug report with a cleaner set of patches. It turns out that even with enhanced lvms channel detection, the Macbook Pro still doesn’t behave, so a patch adds a quirk entry as a workaround.

It looks like these changes will likely make it into the 3.5 kernel, which is a ways out, but at least progress is being made. Hopefully in the next couple days I will rework my branch of kernel patches to include these much nicer patches. As an added bonus, I now know where the development for these drivers happens. In the future I’ll keep watching that mailing list as well as the git repos of Dave Airlie and Daniel Vetter.

Todo

So far the laptop is working quite well and I have successfully been able to use it as a laptop is meant to be used: by going out and actually using it for real work for extended periods away from home. Battery life is only ok at the moment. However I’ve gotten to the point where I only have a few things left to get working, even if some of them will be a major project.

  • Suspend/hibernate. I’ve fooled with this a bit but still have to hard-reset the laptop any time it goes to sleep (which unfortunately happens whenever I close the lid currently).

  • Graphics switching. I still intend to, eventually at least, be able to switch between the integrated Intel graphics and dedicated AMD graphics at will.

  • Backlight adjustment. I tried a patch for this but it still stays pegged at the max. This should be a big helper for battery life.

  • Tweak Intel graphics kernel parameters. There are various parameters out there that reportedely improve battery life significantly.

  • Debug a USB issue. The last few boots I noticed that for about 5 seconds after the KDE login screen is displayed, no input devices work. Even the capslock key does not light up. This could be related to the fact that I’ve usd an extra USB mouse for these last few boots.

  • Disable the trackpad while typing. I didn’t think it would be an issue, but while typing, I often nudge the trackpad and cause Bad Things to happen. There is a fix out there to disable the trackpad while typing.

Installing Gentoo on a Macbook Pro, Part2

| Comments

It’s been a couple days since I could sit down with my fancy new Macbook, but last night and today I’ve made some good progress. After part 1 I a nearly booting sytem, but not quite everthing was working yet. While I could get a kernel to load from grub2, it would hang almost immediately. Also grub2 was clearly misconfigured, as it was spewing many errors about missing commands, and I had to manually type in the path to my kernel image on each boot.

I didn’t know enough about grub2 to hope to debug things there yet, and I was sick of the long cycle of waiting for the livecd to load, mounting filesystems required to chroot, and then making changes, so I hoped to be able to simply get a kernel to boot. As it turns out, this was not too hard.

The first main thing I did that was helpful was to set up a local git copy of the kernel code, since I knew I would be applying various patches eventually. I fiddled around with various versions from 3.1 onward, including the latest code merged as part of the newly opened 3.4 window. I actually found that the only key thing required to boot is to ensure that kernel modesetting was not enabled by default for the i195 driver (CONFIG_DRM_I915_KMS): when it’s enabled the kernel would hang unrecoverably (somtimes not even alt+sysrq+b worked) either a few seconds into boot if the i915 driver is conmpiled into the kernel, or after Gentoo prints the line “waiting for uevents to be processed”, if built as a module.

Unfortunately I wasted a lot of time because I borrowed a kernel config used by Ubuntu. It had almost every single kernel option built as a module, including AHCI and ext2/¾ support. Of course those had to be built into the kernel to finish booting. I wasted a lot of time disabling various modules, and eventually copied my Gentoo config from gentoo-sources-3.2.1 and modified it. One slightly confusing thing was finding the correct ethernet driver. Despire lspci listing the name as NetExtreme, it is actually the Tigon3 driver that is needed (CONFIG_TIGON3), NOT either of the NetExtremeII drivers (CONFIG_BNX2 or CONFIG_BNX2X).

After this, I was able to fully boot just fine. Next I spent about 20 minutes filling /var/lib/portage/world with all the packages I wanted, ran an eix-sync, an an emerge -eav world. Despite including firefox, chromium, libreoffice, and about 800 other packages, this finished in only about 4 hours!

I fiddled around a bit with starting X, and determined it will take a lot of work. GRUB’s error messages were bugging me, so I decided to fix them first, since it might help me learn a bit about EFI and GRUB2. I read a good amount of the GRUB2 manual, crafted a mail to the gentoo-user mailing list, and finally stumbled across renergy’s forum post that worked perfectly.

The next task was perhaps the most daunting: get a desktop environment working. Oddly enough, for the most basic case at least, it was not that hard. Initially, I was wondering how things would work at all. Any attempts to enable modesetting by default in the i915 driver lead to hangs during boot. Yet, using the i915 module at all seems to require kernel modesetting. As it turns out, the trick is to first disable the Radeon graphics card, since presumably the two interfere if you aren’t careful. Mike Dentifrice’s blog has perfect instructions for this. The following steps are all it took:

  1. Start with a Linux 3.3.1 kernel. Using my existing linux git repo, I added another remote for linux-stable pointing to git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
  2. Apply the lvds_dual_channel and apple_bl patches. Few others seem to have shared their work, so I pushed a branch with the patches to my linux github repo.
  3. Build and install the kernel. Make sure the i915 driver is compiled into the kernel and kernel modesetting is enabled by default. In other words, set the following config options: CONFIG_DRM_I915=y CONFIG_DRM_I915_KMS=y
  4. Update your grub.cfg to disable the Radeon card and pass required parameters to the kernel. The menuentry for my kernel ended up looking like this: menuentry ‘Gentoo GNU/Linux, with Linux 3.1.1-00002-g77b9830’ –class gentoo –class gnu-linux –class gnu –class os $menuentry_id_option ‘gnulinux-3.1.1-00002-g77b9830-advanced-1f2dc33c-2639-42f9-8502-9c7d3f24e7ec’ { load_video set gfxpayload=keep insmod gzio insmod part_gpt insmod ext2 set root=‘hd0,gpt1’ # switch gmux to IGD outb 0x728 1 outb 0x710 2 outb 0x740 2 #powers down ATI outb 0x750 0 if [ x$feature_platform_search_hint = xy ]; then search –no-floppy –fs-uuid –set=root –hint-bios=hd0,gpt1 –hint-efi=hd0,gpt1 –hint-baremetal=ahci0,gpt1 1f2dc33c-2639-42f9-8502-9c7d3f24e7ec else search –no-floppy –fs-uuid –set=root 1f2dc33c-2639-42f9-8502-9c7d3f24e7ec fi echo ‘Loading Linux 3.1.1-00002-g77b9830 …’ linux /boot/vmlinuz-3.1.1-00002-g77b9830 root=/dev/sda1 ro i915.lvds_channels=2 reboot=pci acpi_backlight=vendor }

Pretty easy, right? Well there’s some problems. Linux 3.1.1 isn’t exactly the newest. Among other things, it doesn’t support the Macbook Pro’s wireless card. Fortunately there’s a patch for that. But it would be nice to be able to use a newer kernel with all the latest updates, right? Plus, all that power in the Radeon graphics card is going to waste all the time. I’ll have to conquer those hurdles another day.

Since I had a working desktop environment now, I decided quickly to see how things were working. Firefox and Amarok worked just fine, but when I tried to watch a few minutes of Firefly, I realized there was no sound! I fiddled with model=mb5 and other settings in /etc/modprobe.d/alsa.conf but it turns out all I had to do was enable SND_HDA_CODEC_CIRRUS. It’s the only Intel HDA coded that’s required actually.

Stay tuned as there clearly will be a part 3 (at least) in the near future.

Installing Gentoo on a Macbook Pro, Part1

| Comments

Today I purchased a brand new Macbook Pro from the Apple store in Palo Alto. It’s a 15” model with the following specs:

  • 2.5GHz Quad-core Intel Core i7 CPU
  • 4GB 1333MHz DDR3 RAM
  • 750GB SATA HD @ 5400RPM
  • Intel HD Graphics 3000
  • AMD Radeon HD 6770M with 1GB GDDR5 RAM

dmidecode identifies it as MacBookPro8,2, and the lspci output is as follows

00:00.0 Host bridge: Intel Corporation 2nd Generation Core Processor Family DRAM Controller (rev 09)
00:01.0 PCI bridge: Intel Corporation Xeon E3-1200/2nd Generation Core Processor Family PCI Express Root Port (rev 09)
00:01.1 PCI bridge: Intel Corporation Xeon E3-1200/2nd Generation Core Processor Family PCI Express Root Port (rev 09)
00:16.0 Communication controller: Intel Corporation 6 Series/C200 Series Chipset Family MEI Controller #1 (rev 04)
00:1a.0 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Universal Host Controller #5 (rev 05)
00:1a.7 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #2 (rev 05)
00:1b.0 Audio device: Intel Corporation 6 Series/C200 Series Chipset Family High Definition Audio Controller (rev 05)
00:1c.0 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 1 (rev b5)
00:1c.1 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 2 (rev b5)
00:1c.2 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 3 (rev b5)
00:1d.0 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Universal Host Controller #1 (rev 05)
00:1d.7 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #1 (rev 05)
00:1f.0 ISA bridge: Intel Corporation HM65 Express Chipset Family LPC Controller (rev 05)
00:1f.2 IDE interface: Intel Corporation 6 Series/C200 Series Chipset Family 4 port SATA IDE Controller (rev 05)
00:1f.3 SMBus: Intel Corporation 6 Series/C200 Series Chipset Family SMBus Controller (rev 05)
01:00.0 VGA compatible controller: Advanced Micro Devices [AMD] nee ATI Whistler XT [AMD Radeon HD 6700M Series]
01:00.1 Audio device: Advanced Micro Devices [AMD] nee ATI Turks HDMI Audio [Radeon HD 6000 Series]
02:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM57765 Gigabit Ethernet PCIe (rev 10)
02:00.1 SD Host controller: Broadcom Corporation NetXtreme BCM57765 Memory Card Reader (rev 10)
03:00.0 Network controller: Broadcom Corporation BCM4331 802.11a/b/g/n (rev 02)
04:00.0 FireWire (IEEE 1394): Agere Systems FW643 PCI Express 1394b Controller (PHY/Link) (rev 08)

Additionally I made the following upgrades:

  • Replaced the stock HD with an Intel SDD 520
  • Upgraded to 8GB RAM

Setting up for installation

I of course started with the Gentoo Wiki page on the Macbook Pro, which appears to be lacking information on the latest models. I knew a couple things going in from my earlier research.

  • I wanted to use EFI, not BIOS emulation. Besides being new and fancy, you cannot use the integrated Intel HD 3000 graphics when using BIOS emulation.
  • I’m not really interested in any form of dual booting, Linux is all I need. I knew this would make things considerably easier.
  • It would be hard, but eventually I wanted to get suspend, hibernate, etc working nicely

My first roadblock was almost immediate: I normally use a USB stick loaded with a recent Gentoo minimal installer. However none of the tools on this installer support the new GPT partition layout, which is requied for booting with EFI.

The Gentoo Wiki suggests using gparted, and I happened to have a somewhat old gparted CD. Unfortunately, this old version didn’t work: it couldn’t figure out where to mount the CD media. No problem, I can download the latest version (0.12.0-5) and try that.

I had to spend a minute to figure out how to eject the old gparted CD though. It was easy enough: reboot and hold down the mouse button.

After booting into the newer gparted CD, everything worked fine. X loaded without any issues and ethernet was working, so I was able to continue on from within the gparted environment.

Or so I thought. It turns out gparted (reasonably) was using the x86 architecture, so I couldn’t chroot into the Gentoo install. Booting from my trusty USB stick also didn’t work, but fortunately I had been downloading a LiveCD of Ubuntu 11.10. Unfortunately, it was a 32 bit image. I downloaded a 64 bit image, and that didn’t work either. Then I checked and the new Ubuntu 12.04 daily build LiveCDs include a Mac specific version. This didn’t work. Neither did the standard 64 bit Ubuntu 12.04 daily. Neither did a weekly snapshot of the Gentoo minimal amd64 installer. Finally I tried the Gentoo 2012 amd64 multilib LiveDVD. It didn’t work when booting with the standard options (garbled X output), but when I booted using the -nofb option, KDE loaded up fine, except that the mouse didn’t work. Switching to the console I was able to set a root password and start SSHD to complete the installation remotely, which is my usual method.

Sidetrack setup

When I install Gentoo I usually diverge a bit from the instructions and install some key utilities. In this case I simply installed htop, eix, vim, dmidecode, and pciutils. None of these are huge packages, but I definitely got a feel of how fast working on this machine is going to be. I imagine it’s mostly the SSD, but htop reminded me that thanks to hyperthreading, Linux sees a total of 8 cores :)

Initial Kernel config

My first pass at the kernel config was fairly quick. I removed some things I knew I didn’t need, and followed the suggestions on the kernel config page from the Gentoo Wiki article. I wasn’t too concerned with getting every little piece of hardware working right away. Mostly learning GRUB2, which I had never used before, and booting with EFI was my main concern.

GRUB2 installation

Before starting, I took a long look at the Gentoo GRUB 2 guide (work in progress) and the GRUB 2 Gentoo wiki page. I noticed a couple interesting things. I knew that GRUB 2 suggests using a small script to generate the bootloader configuration, instead of manually editing a file like with GRUB1. But I didn’t know that GRUB2 seems to keep this configuration all over the place. A little annoying to be honest. Also, everything I read suggested creating a separate partition (using FAT32 as the filesystem), for bootloader related stuff. I preferred just using a single big filesystem in the past, and had done the same back when partitioning the SSD earlier. I decided to attempt to make things work with one partition, knowing I could always go back and make a new partition with gparted if I had to.

So I added a package.keywords entry for grub2, set GRUB_PLATFORMS=“efi-64” in /etc/make.conf, and installed grub2. I fooled around for a bit, rebooted once and got nowhere. So I decided to boot back into gparted and add a 200MB partition at the end. Following the Gentoo GRUB 2 guide, I set it as bootable, and then then basically folowed exactly the instructions in the EFI section. I booted, and things seemed fairly close to working: GRUB2 was detected by EFI, and loaded, but it failed saying module “normal” was not found. I fiddled around again, and this time I landed right into a GRUB menu. I fiddld around a bit, but wasn’t able to get linux to boot. I realized that when I ran grub2-mkconfig I didn’t have /sys properly mounted as it says right in the guide. After that, grub at least showed a menu with a correct detection of my kernel. However, attempting to boot lead to the following:

  • an error message “no suitable modes found”
  • a warning about booting “in blind mode”
  • a garbled screen that looks like it may have been the start of a linux kernel boot (there was the teltale yellow from the tux penguin at the top), but likely resulted in a panic

After some searching, I found the Ubuntu UEFI Booting wiki page had a section on video issues. I tried to load the efi_gop module, but it wasn’t found until I specified the full path to the module. Then I needed to load a module it depended on, again specifying the full path. This lead me to believe that something in GRUB2 wasn’t configured quite right. After loading this module I can start to boot linux, however it failed fairly quickly with the following error:

[drm:intel_dsm_pci_probe] *ERROR* failed to get supported _DSM functions

I hoped that at the very least this meant that I had finally progressed to kernel configuration issues, so I started looking at kernel patches. I knew ahead of time of quite a few patches mentioned on Benjamin Lee’s blog, so I got to work applying those. They didn’t compile, but there is apparently a patch to make them work on my current kernel (gentoo-sources-3.2.1-r2).

After making some good progress, I called it a day.