summaryrefslogtreecommitdiff
path: root/content/blog/archlinux-macbook-a1211.md
blob: 9fec1fa666db6087d0b69435c6772d5ff23929bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
+++
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 think, it's 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

Managers might like to use only one mouse. Also keyboard fanatics may
be happy by just switching off the mousepad completly.

The one button mouse is a disaster for people being used to Xorg copy-
paste or Oberon enthusiasts used to three buttons.

Two finger scrolling is nice, but per default only for up and down.
I enable it also to left and right. Besides, the keyboard is missing
PageUp, PageDown keys, which is a usability nightmare when you want to
scroll bigger source code files or web pages (yes, I know there is Fn-Page,
but having Ctrl, Alt, Meta and Fn all on the same spot doesn't make it
easier to find the right one).

Change */etc/X11/xorg.conf.d/50-synaptics.conf* as follows to your likings:
```
Section "InputClass"
	Identifier "Touchpad Catchall"
	Driver "synaptics"
	MatchIsTouchpad "on"
	Option "TapButton1" "0"
	Option "TapButton2" "3"
	Option "TapButton3" "2"
	Option "VertTwoFingerScroll" "1"
	Option "HorizTwoFingerScroll" "1"
	Option "ClickFinger2" = 0
	Option "ClickFinger3" = 0
EndSection
```

*TabButton1=1* only leads to all kind of frantic behaviour, because I
touch the touchpad by accident. *ClickButton* and *TapButton* for the
second and third button are just completly useless. Either no menu
appears for TapButton or a menu appears for ClickFinger, but I can no
longer to copy-pastes.

The default modifiers Ctrl, Alt, Meta don't do anything with the mouse
or just very weird stuff, like Alt-2-fingers jumps to the beginning of
my text.

For now, I choose TapButtons for copy-paste, as this is the function
I need most often.

TODO: For mouse button 2 and three I changed the modifiers for Ctrl and Alt.

## 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