summaryrefslogtreecommitdiff
path: root/content/blog/archlinux-macbook-a1211.md
diff options
context:
space:
mode:
Diffstat (limited to 'content/blog/archlinux-macbook-a1211.md')
-rw-r--r--content/blog/archlinux-macbook-a1211.md222
1 files changed, 222 insertions, 0 deletions
diff --git a/content/blog/archlinux-macbook-a1211.md b/content/blog/archlinux-macbook-a1211.md
new file mode 100644
index 0000000..d0ea094
--- /dev/null
+++ b/content/blog/archlinux-macbook-a1211.md
@@ -0,0 +1,222 @@
++++
+title = "Archlinux on a MacBook Pro 15'' Model A1211"
+categories = [ "Operating System", "Archlinux", "MacBook" ]
+date = "2018-11-06T16:20:39+02:00"
+thumbnail = "/images/blog/archlinux-macbook-a1211/macbook-A1211.jpg"
+draft = true
++++
+
+## History
+
+I got an old Mac from a collegue at work. Apple decided not to
+support those devices anymore, anyway, they date back to 2006.
+I find a pitty, because this Mac has a solid case, a pretty fast
+64-bit processor (sorry Archlinux32, no test machine for you) and
+a graphic chip which is not melting away like in later models..
+
+Here the specifications:
+
+* 2.3 GHz Intel Core 2 Duo
+* 2GB 667 DDR2 SDRAM
+* OSX 10.6.8
+* ATI Radeon X1600 256 MB RAM, 1440x900, 32 bit
+
+I didn't try any Sierra OSX hacks on old hardware and besides,
+Archlinux is a better choice for a developer on a Mac. Although
+there are still MacPorts for OSX 10.6.x (no Brew), it can be
+quite painful to get something compiled on a Mac OS that old.
+
+As we will later see, we want to keep OSX around for being able to
+change settings, extract some firmware, etc.
+
+## Installation
+
+### Prepare for dual installation
+
+TODO: Shrink OSX partition to 64GB, rest to free space
+
+Preapre the USB stick for installation.
+
+hdiutil convert -format UDRW -o archlinux-2018.09.01-x86_64.img archlinux-2018.09.01-x86_64.iso
+dd if=archlinux-2018.09.01-x86_64.dmg of=/dev/disk2 bs=1m
+
+### EFI boot
+
+I used [ReFIT for MAC](http://refit.sourceforge.net/) to improve the
+somewhat limited EFI environment of an early Mac (don't get me wrong, it's
+pretty impressive that such an old machine already had EFI, but nowadays this
+EFI shows it's age).
+
+The firmware is a 32-bit EFI, causing trouble all along. I didn't take
+ReFind, as I didn't expect 32-bit EFI to be supported, especially as I
+see now Tianocore failing to build with more modern 32-bit binutils and gcc.
+
+I installed a 32-bit GRUB onto the EFI partition as a second boot option
+along to OSX. This one then boots ArchLinux. This is easier than to try
+to load a 64-bit kernel from an 32-bit EFI environemnt with grub or
+even systemd-boot.
+
+### ATI VESA BIOS
+
+I didn't want to boot into legacy mode to make the VGA BIOS visible, so
+I got a nice problem during KMS switching in early booting stage: the
+graphical output just froze. The irony here is that modern Linux and Xorg
+don't care at all about the old VGA/VESA BIOS, but for KMS, where they rely
+on 16-bit firmware functions to program the video chip. Wonder, what will
+happen, if the BIOS disappears completly..
+
+
+So, all I got was a missing the following kernel and Xorg error messages:
+
+```
+[2.052705] [drm] initializing kernel modesetting (RV530 0x1002:0x71C5 0x106B:0x0080 0x00).
+[2.052742] radeon 0000:01:00.0: Invalid PCI ROM header signature: expecting 0xaa55, got 0xa1a1
+[2.052817] [drm:radeon_get_bios [radeon]] *ERROR* Unable to locate a BIOS ROM
+[2.052825] radeon 0000:01:00.0: Fatal error during GPU init
+[2.053037] radeon: probe of 0000:01:00.0 failed with error -22
+...
+[31.041] (EE) open /dev/dri/card0: No such file or directory
+```
+
+So this basically translates into: "I don't have a direct rendering interface,
+because there is no card, because there is no BIOS for the card'.
+
+The idea was to extract the VESA BIOS on a distribution which handles
+the KMS switching correctly (in my case an old Ubuntu 10).
+
+```
+dd if=/dev/mem of=vbios.bin bs=65536 skip=12 count=1
+```
+
+Verify that indeed you got the right firmware. There is error message:
+
+```
+[2.052742] radeon 0000:01:00.0: Invalid PCI ROM header signature: expecting 0xaa55, got 0xa1a1
+```
+
+so we expect to find that in the *vbios.bin* file:
+
+```
+hexdump -C vbios.bin | head -n 1
+00000000 55 aa 7d e9 7f 02 00 00 00 00 00 00 00 00 00 00 |U.}.............|
+```
+
+This firmware comes into */lib/firmware/radeon/vbios.bin* to be available during
+boot.
+
+The next problem was that the radeon driver didn't know about this firmware
+to load. There is a patch in https://bugs.freedesktop.org/show_bug.cgi?id=26891
+for older modules, but it also applies to modern radeon kernel drivers. All
+it does is load the *vbios.bin* file from the right place, when all the other
+options failed.
+
+Now, Archlinux needs the Radeon driver for KMS as early as possible, so
+I thought it's a nice idea to put it into the init-RAM-disk:
+
+So, I added to */etc/mkinitcpio.conf*:
+
+```
+MODULES=(radeon)
+FILES=(/usr/lib/firmware/radeon/vbios.bin)
+```
+
+My version of the module is [here](/text/blog/archlinux-macbook-a1211/radeon_bios.c), check
+out function *radeon_read_bios_from_firmware* and calling code.
+
+TODO: link the code of the module from somewhere.
+
+### "Total Darkness" after 10 minutes
+
+Everything was running smoothly.. for about 10 minutes. Then my LCD display
+just went pitch black.
+
+Setting the brightness manually didn't help:
+
+```
+xrandr --output LVDS --brightness 1
+```
+
+(it did work later though to set the brightness between 0.0 and 1.0)
+
+The trick is to tell the radeon module to handle the LCD backlight, not
+one of the funny Apple brightness modules. In */etc/modprobe.d/radeon.conf* put:
+
+```
+options radeon backlight=1
+```
+
+Also handy is the https://aur.archlinux.org/packages/brightd/, thought
+I think also systemd-backlight can nowadays save the brightness.
+
+### Function keys or special keys
+
+If you don't need the special volumes, brightness keys but instead the old
+Fxx function keys, add the following to */etc/modprobe.d/hid_apple.conf*:
+
+```
+options hid_apple fnmode=2
+```
+
+TODO: Functions keys or ACPI
+
+### Camera
+
+Here we come to iSight and why we need OSX around to extract the proper
+firmware.
+
+https://wiki.archlinux.org/index.php/Mac#Webcam has a really nice walkthrough.
+
+Short, you need https://aur.archlinux.org/packages/hfsprogs/ to mount the HFS
+partition. There you will find a file called *AppleUSBVideoSupport* in
+*/System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS*.
+
+You will also need https://aur.archlinux.org/packages/isight-firmware-tools/,
+with that one you extract a file *isight.fw* from *AppleUSBVideoSupport*.
+
+The udev rule in */etc/udev/rules.d/isight.rules* then makes sure the firmware
+is also loaded on startup.
+
+### Wifi
+
+Install *wireless-regdb* and make sure to enable the proper regulatory domain in
+*/etc/conf.d/wireless-regdom*:
+
+```
+WIRELESS_REGDOM="CH"
+```
+
+The regulatory domain has to be set properly, otherwise the Wifi works
+perfectly. Put in */etc/modprobe.d/regdom.conf*:
+
+```
+options cfg80211 ieee80211_regdom=CH
+```
+
+(CH is for Switzerland, pick your own country here)
+
+TODO: regdomain for WPA-supplicant, can it be done in userspace?
+
+### Fans and sensors
+
+macfanctl from AUR works nicely, lm_sensors no problems
+
+### Power consumption
+
+cpupower seems to work fine.
+
+TODO: issues with powertop and hard disk wake-up?
+
+### Mouse buttons
+
+TODO: load synaptic, configure at your gusto (double, triple finger clicks),
+for opening tabs in a browser, doing some X copy paste etc.
+TODO: Ctrl/Meta-Modifier shift if you want context menues
+
+## References
+
+* https://bugs.freedesktop.org/show_bug.cgi?id=26891: the patch to radeon.ko,
+ enabling loading of file as VESA bios.
+* https://bbs.archlinux.org/viewtopic.php?id=139511: some discussions about
+ the VESA radeon topic in the Archlinux forum.
+* https://wiki.archlinux.org/index.php/Mac#Webcam: how to make the camera work
+