免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1196 | 回复: 0
打印 上一主题 下一主题

Linux on MacBook [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-09-14 21:52 |只看该作者 |倒序浏览

Linux on MacBook
From
http://www.jasonparekh.com/?page_id=9
I’ve recently switched from OS X to Kubuntu on my MacBook. On this page, you’ll find info on my configuration along with how I got different things working. The modifications here should/will work for the MacBook, but some may work for the MacBook Pro.
I’d like to hear from anyone (any distro) that has gotten suspend/sleep to work (really interested in suspend-to-RAM, but if you’ve gotten suspend-to-disk to work reliably, please leave a comment as well). Thanks!
Changes to this page

Configuration
I have a white MacBook (the base model) running Kubuntu Edgy (really no different than Ubuntu). I chose to compile a vanilla 2.6.18 kernel due to the higher number of merged in
Mactel
patches. I think most of the below patches will work with a
Mactel
-patched 2.6.17 kernel as well. Please check their SVN for the latest patches to apply to your kernel.
Compiling/installing a kernel is a breeze in Ubuntu (and Debian), so don’t be afraid. You can find a quick HOWTO in /usr/share/doc/kernel-package/README.gz. I will post a section here on compiling your own kernel soon (hopefully within the next week).
Triple boot
I was debating whether or not to just dual boot (Linux and Windows), or triple boot (Linux, Windows, and OS X). For the former, my arguments are I’d get more space (although I already upgraded to a 120GB HD, I don’t like wasted space) and I didn’t plan on going back into OS X often. The arguments for the latter are I’d like to try new (free) OS X apps (the community is growing pretty fast, and I’d love to go back to OS X if some of the areas are improved) and I may need to occassionally do firmware upgrades. I could install OS X on an external hard drive, but I realized 120GB is plenty, and a 20GB partition won’t kill me (that is a lot, but I do plan on installing a good amount of apps). So, I went with an installation of Linux, Windows, and OS X.
I installed all three by following many of the HOWTOs online, so I won’t discuss that here.
VMware
After installation, one thing I highly recommend is to install VMware on Linux and use raw partition virtualization. This allows you to reuse the same Windows installation for both virtualization and native booting. Why is this useful? I need to boot directly to Windows to play games, but mostly use it just for development or once in a while, Office. I didn’t want to have two Windows installations (ew!), so I opted for this. Works very well, although there are a couple things you need to do:

  • Use Hardware configurations in Windows so you don’t have to worry about different hardware being found constantly between virtualized and native boots.
  • Use the generic IDE controller drivers on Windows, and IDE virtualization for the HD on VMware. (more on this below)

If I recall, I would keep getting a BSOD on XP boot up. To fix this, I had to modify my configuration so VMware used a virtual IDE disk controller instead of SCSI. Here is the basic process:

  • Install VMware
  • Create a new virtual machine
  • Change Virtual Machine Configuration to Custom
  • Change Guest Operating System to Microsoft Windows, and Version to Windows XP Professional (or whichever version you use)
  • Keep the name the same (or change it if you want), Next
  • Change Number of Processors to Two
  • I unchecked Make this virtual machine private, but it’s up to you
  • Set however much memory you want
  • I use bridged networking along with another host-only networking (added separately)
  • Keep the BusLogic adapter (we’ll have to change this in the descriptor files manually)
  • Change Disk to Use a physical disk
  • Next
  • Finish

Now, we’ll change the descriptor files to use a virtual IDE disk controller:
/var/lib/vmware/Virtual Machines/Windows XP Professional/Windows XP Professional.vmx: (bolded parts changed)
config.version = "8"
virtualHW.version = "4"
scsi0.present = "FALSE
memsize = “256″
ide0:0.present = “TRUE”
ide0:0.fileName = “Windows XP Professional 2.vmdk”
ide0:0.writeThrough = “TRUE”
ide0:0.deviceType = “rawDisk”
ide1:0.present = “TRUE”
ide1:0.fileName = “/dev/hda”
ide1:0.deviceType = “cdrom-raw”
floppy0.startConnected = “FALSE”
floppy0.fileName = “/dev/fd0″
Ethernet0.present = “TRUE”
displayName = “Windows XP Professional 2″
guestOS = “winxppro”
priority.grabbed = “normal”
priority.ungrabbed = “normal”
powerType.powerOff = “hard”
powerType.powerOn = “hard”
powerType.suspend = “hard”
powerType.reset = “hard”
/var/lib/vmware/Virtual Machines/Windows XP Professional/Windows XP Professional.vmdk: (bolded parts changed)
# Disk DescriptorFile
version=1
CID=6a2d474c
parentCID=ffffffff
createType="fullDevice"
# Extent description
RW 234441648 FLAT "/dev/sda" 0
# The Disk Data Base
#DDB
ddb.virtualHWVersion = "4"
ddb.geometry.cylinders = "14593"
ddb.geometry.heads = "255"
ddb.geometry.sectors = "63"
ddb.geometry.biosCylinders = "14593"
ddb.geometry.biosHeads = "255"
ddb.geometry.biosSectors = "63"
ddb.adapterType = "ide
You may have different values for some of the fields, but you should only change the keys/values I have bolded.
At this point, if you install the fresh copy of XP and boot, you may or may not get a BSOD. Please let me know which it is. If you get a BSOD, you should boot into XP natively and install a registry patch called
mergeide.reg
. If that doesn’t fix it, there still may be more to do (I remember trying different suggestions from the VMware forum, but unfortunately I didn’t keep a log. The good news is, it WILL eventually work as I have a working solution (just not exactly sure how I get here :) ).
Trackpad / Touchpad
The following works on a 2.6.18 kernel, and most likely a 2.6.17 kernel patched with the latest
Mactel
patches.
By default, the generic X mouse driver (mouse) is used. This won’t let you use cool features like two-finger scrolling, two/three-finger taps (right/triple click respectively), etc. So, you need to use the synaptics driver, but this isn’t trivial to do. The appletouch kernel module needs to be loaded before the usbhid module, otherwise the usbhid mode will act as the driver for the trackpad (it is USB after all). To do this, I blacklist both drivers, and load them manually in the order I want. (Please do let me know if there is a better way of ordering the modules):
/etc/modprobe.d/appletouch: (create)
blacklist appletouch
blacklist usbhid
/etc/modules: (append)
# appletouch should load before usbhid so it claims the trackpad
appletouch
usbhid
bigbluevan on the ubuntuforums (
specific post
) also recommends:
The only modification I had to make was that, in addition to what is posted at the above URL, I also needed to add “blacklist tsdev” to /etc/modprobe.d/appletouch
I realized that it was loading the ts0 device due to what it was saying in /proc/bus/input/devices, you need to make sure it only lists mouseX and eventX — if it has tsX then it means you should blacklist it.
Then, we have to load the synaptics driver for X (this includes a lot of options that I’ve found work well for me):
/etc/X11/xorg.conf: (insert after EndSection of the Configured Mouse)
Section "InputDevice"
Identifier "Synaptics Touchpad"
Driver "synaptics"
Option "CorePointer"
Option "Device" "/dev/input/mouse1"
Option "Protocol" "auto-dev"
Option "LeftEdge" "100"
Option "RightEdge" "1100"
Option "TopEdge" "50"
Option "BottomEdge" "300"
Option "FingerLow" "20"
Option "FingerHigh" "30"
Option "MaxTapTime" "150"
Option "MaxTapMove" "90"
Option "MaxDoubleTapTime" "180"
Option "VertScrollDelta" "25"
Option "HorizScrollDelta" "30"
Option "VertTwoFingerScroll" "true"
Option "HorizTwoFingerScroll" "true"
Option "FastTaps" "true"
Option "TapButton2" "3"
Option "TapButton3" "2"
Option "MinSpeed" "0.5"
Option "MaxSpeed" "3.5"
Option "AccelFactor" "0.35"
EndSection
Also, we should advise X to load this driver before the Configured Mouse:
/etc/X11/xorg.conf: (Before Input Device "Configured Mouse")
InputDevice "Synaptics Touchpad"
Great! Now we have the cool capabilities provided by the synaptics driver. However, I found some issues with the appletouch driver on the MacBook. You can read more about them here:
appletouch (Linux kernel driver for Apple trackpads) changes
. I created a patch that fixes the jumpiness of the mouse pointer and better detection of multiple fingers (improves two-finger scrolling/multiple finger taps). Grab the patch:
Patch for appletouch driver (patches on top of Mactel changes)

Fan Control
The applesmc kernel module allows us to view/modify the fan speed of the MacBook. The modification you can make is to turn off the automatic scaling, and specific a fixed fan speed. However, I’d rather have the scaling and specify the minimum speed. By default, you can view the minimum speed, but no modifications can be made. I’ve made a quick patch to let you change this:
MacBook Minimum Fan Speed Patch
. You must patch with Mactel’s applesmc.patch first. Check out /sys/devices/platform/applesmc/fan:
sudo -c sh "echo 3000 > /sys/devices/platform/applesmc/fan0_minimum_speed"
If you want to set this on startup, you can try
MacBook minimum fan init.d script
(in your /etc/init.d), followed by:
sudo update-rc.d macbook-fan defaults
Headphone sensing and Microphone
With the changes mentioned here, these will function properly: (haven’t tested SPDIF)

  • Internal speakers
  • Headphone jack (meaning you’ll hear audio through the headphones, and the internal speakers will be muted)
  • Microphone
  • Line-in

The current (2006/11/12) state of ALSA for the MacBook (and MBP, ..?) is pretty strange: If you’re using a vanilla kernel, chances are your headphone sensing works (when you plug in headphones, your internal laptop speakers mute and you hear audio from your headphones). If you’re using a mactel-patched kernel (or the generic Ubuntu kernel, maybe other distros that prepatch with mactel), chances are your microphone has the ability to work (you have to toggle between Line-in and Mic on the ALSA mixer for it to work), but your headphone sensing doesn’t (when you plug in headphones, you hear audio from both the internal speakers and the headphones).
After screwing around with the ALSA driver source code, the Windows driver files, and the Microsoft and Intel spec sheets, I’ve found a solution that allows for both the microphone and the headphone sensing to work! That’s the good news. The bad news is I’m not completely sure why it works (I haven’t spent time looking through the general portions of the ALSA driver code, just focused on the pin config stuff). Also, you still need to toggle between Line-in and Mic to get the microphone to work (there is a way around this if you don’t plan on using the line-in jack on your laptop).
If you just want a working solution, you can probably skip near the end (although you’ll still need knowledge of recompiling the kernel). If you want to learn how I went about this, keep reading..
I did a lot of Googling to figure out the current state of the driver, but unfortunately there wasn’t much info available. The people who got the Mac Mini sound working in Linux initially found the pin config for each pin widget in the Windows driver metadata files (inf and ini), so that’s where I started. I saved some hassle of needing to extract the Boot Camp drivers since Apple saves the drivers in c:\Program Files\Macintosh Drivers for Windows XP after installation.
First get your sound card’s subsystem id:
cat /proc/asound/card0/codec\#0 | grep Subsystem
Then, check c:\Program Files\Macintosh Drivers for Windows XP\SigmaTel\wdm\AppleBoards.bld (I suggest mounting your Windows partition) to see which board INI file applies to your card. I’m pretty sure the MacBooks have subsystem 0x100, so they’ll use board6.ini (mine does). BTW, I later found that this level of detail is pretty much useless as you can get it to work without exact pin configs (guess ALSA has some slack on the spec?). Scroll down to [HKR\Settings\pin] and you can see all the values for the config of each pin widget. The ALSA driver will need these pin config values as well (in patch_sigmatel.c). If you want to decompose each value to figure out exactly what it means, refer to the
PinConfig.doc found on the right sidebar
and the
Intel HDA Programmers Reference Manual
. From these documents, you can figure out which of the widgets are assigned to which function (mic, line-in, internal speaker, SPDIF in, SPDIF out, etc.). The part I don’t fully understand: the internal speaker is on widget 0×0c, but to get the headphone sensing working, we place the internal speaker’s pin config value on widget 0×0d (for the rest of the widgets, copy them over exactly).
The line-in works as well (tested it out). But, if you don’t care about it, you can disable it allowing the mic to work from boot without needing to toggle between the mic and line-in. To do this, use a pin config of 0x400000F0 (this disables it) for the line-in (0×0f widget).
So, now to the actual code we’ll be changing. I’ll be working on the Ubuntu 6.10 (Edgy) kernel, but the approach is very similar for all (including non-mactel patched kernels).
First, we’ll check out the board6.ini (scroll down to find this snippet):
[HKR\Settings\pin]
[HKR\Settings\Pin\0A]
CfgDflt = dword: 0x0321E230
Action = hex: 01,0A,81,0C,81,10,85,51,05,21
[HKR\Settings\Pin\0B]
CfgDflt = dword: 0x03A1E020
Bias = hex: FF,04
[HKR\Settings\Pin\0C]
CfgDflt = dword: 0x9017E110
[HKR\Settings\Pin\0D]
CfgDflt = dword: 0x400000FD
[HKR\Settings\Pin\0E]
CfgDflt = dword: 0x400000FE
Action = hex: 01,10,81,0A,81,0C
[HKR\Settings\Pin\0F]
CfgDflt = dword: 0x0381E021
Action = hex: 09,0F
[HKR\Settings\Pin\10]
CfgDflt = dword: 0x1345E240
[HKR\Settings\Pin\11]
CfgDflt = dword: 0x13C5E22E
[HKR\Settings\Pin\15]
CfgDflt = dword: 0x400000FC
[HKR\Settings\Pin\1B]
CfgDflt = dword: 0x400000FB
Here, you can see each pin widget NID (0A through 1B) and the pin config for each. First, we make sure the NIDs match up in sound/pci/hda/patch_sigmatel.c (line 151 in the Ubuntu 2.6.17-10 kernel):
static hda_nid_t stac922x_pin_nids[10] = {
0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
0x0f, 0x10, 0x11, 0x15, 0x1b,
};
Yup, good to go! Next, let’s start replace each pin config (sound/pci/hda/patch_sigmatel.c, line 373):
static unsigned int d945gtp5_pin_configs[10] = {
0x0221401f, 0x01011012, 0x01813024, 0x01014010,
0x01a19021, 0x01016011, 0x01452130, 0x40000100,
0x02a19320, 0x40000100,
};

static unsigned int macbook_pin_configs[10] = {
0x0321E230, 0x03A1E020, 0x400000FD, 0x9017E110,
0x400000FE, 0x0381E021, 0x1345E240, 0x13C5E22E,
0x400000FC, 0x400000FB,
};
I copied the d945gtp5_pin_configs (which the mactel patch assigns to the Macs) to a new array (called macbook_pin_configs. Then, I replace the values from board6.ini, with one exception. Now the strange thing: the pin config 0x9017E110 that should go with widget 0x0c (according to board6.ini) I’ve put on widget 0x0d (and the reverse). This allows the headphone sensing to work (if you copy ALL pin configs directly, I don’t think the sensing will work–it didn’t for me). Maybe some one can explore the usage of these pin configs in the ALSA code further in detail to figure out why?
If you’re sure you’ll never use the line-in jack, you can place a 0x400000F0 value for its pin config (in the above, it’s the 0x0381E021), and your mic will work from boot without the need to toggle anything.
Now, just make sure the driver will use this new pin config array instead of the old (line 395 assuming you’ve pasted the above pin configs):
[STAC_MACMINI] = macbook_pin_configs,
That’s basically everything you need to do for both mic and headphone sensing to work. Recompile the kernel or the module and install, and you’re good to go!
Once a boot, you must toggle the Input Source on the sound card’s mixer, so set it to Line and then back to Mic. A quick shell approach would be:
amixer sset 'Input Source' 'Line'
amixer sset 'Input Source' 'Mic'
The instructions are for the stock Ubuntu kernel, but I run a vanilla 2.6.18, so I may have missed somethings–please let me know if it doesn’t work for you. Here are some quick things to check for (go in alsamixer):

  • Make sure Front is unmuted. Select it, and press m (make sure it doesn’t say MM below the bar).
  • Toggle Line/Mic. The above amixer lines should have worked, but as a backup go to Input So (really Input Source) and press UP ARROW to select Line, and then DOWN ARROW to reselect Mic.
  • Press F4 and make sure Capture is being captured. Select it, and tap the SPACE BAR (make sure it says CAPTUR below the bar).

Bluetooth
From the Ubuntu forums, it seems like bluetooth itself works fine with Linux on the MacBook, yet I couldn’t get it working on Kubuntu Edgy (particularly kbtobexclient wouldn’t see any devices). I took the recommendation of someone on the forums and installed
kdebluetooth 1.0 beta 2
from source (using stow, of course). Now, kbtobexclient sees my device and I’m able to send files.
MacBook LED
Download:
MacBook LED v01
Apple decided we don’t need an LED indicator for disk activity. I decided we do (damn Apple and their extremely minimal designs). Using the SPDIF out, we now have one (albeit it’s on the side of the MacBook :)
This script will let you monitor either disk or network activity through the LED inside the headphone jack (which serves as optical out). I thought it would be a fun, quick little hack, and it was :)
How it works: It’s a bash script that polls (ew!) the proc filesystem for either disk activity (/proc/diskstats) or network activity (/proc/net/dev). It even has the ability to filter down to a particular device (done by grepping the device). Once activity is found, it enables the SPDIF out through amixer (part of alsa-utils package), and once it is idle again, it disables SPDIF out. The polling interval is pretty small (200ms), so it performs as well as a real HDD indicator.


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/22778/showart_382040.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP