Gentoo内核编译(MacBook Pro Late 2013)

硬件环境

在MacBook Pro上安装Gentoo Linux ( MacBook Pro 15" Late 2013 )后,对内核进行定制,以便能够充分发挥硬件性能。本文综合 MacBook Pro 15" Late 2013 内核编译的要点。

  • lspci -nn 输出:

MacBook Pro Late 2013 上执行 lspci -nn 输出
00:00.0 Host bridge [0600]: Intel Corporation Crystal Well DRAM Controller [8086:0d04] (rev 08)
00:01.0 PCI bridge [0604]: Intel Corporation Crystal Well PCI Express x16 Controller [8086:0d01] (rev 08)
00:01.1 PCI bridge [0604]: Intel Corporation Crystal Well PCI Express x8 Controller [8086:0d05] (rev 08)
00:14.0 USB controller [0c03]: Intel Corporation 8 Series/C220 Series Chipset Family USB xHCI [8086:8c31] (rev 05)
00:16.0 Communication controller [0780]: Intel Corporation 8 Series/C220 Series Chipset Family MEI Controller #1 [8086:8c3a] (rev 04)
00:1b.0 Audio device [0403]: Intel Corporation 8 Series/C220 Series Chipset High Definition Audio Controller [8086:8c20] (rev 05)
00:1c.0 PCI bridge [0604]: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express Root Port #1 [8086:8c10] (rev d5)
00:1c.2 PCI bridge [0604]: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express Root Port #3 [8086:8c14] (rev d5)
00:1c.3 PCI bridge [0604]: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express Root Port #4 [8086:8c16] (rev d5)
00:1c.4 PCI bridge [0604]: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express Root Port #5 [8086:8c18] (rev d5)
00:1f.0 ISA bridge [0601]: Intel Corporation HM87 Express LPC Controller [8086:8c4b] (rev 05)
00:1f.3 SMBus [0c05]: Intel Corporation 8 Series/C220 Series Chipset Family SMBus Controller [8086:8c22] (rev 05)
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK107M [GeForce GT 750M Mac Edition] [10de:0fe9] (rev a1)
01:00.1 Audio device [0403]: NVIDIA Corporation GK107 HDMI Audio Controller [10de:0e1b] (rev a1)
03:00.0 Network controller [0280]: Broadcom Inc. and subsidiaries BCM4360 802.11ac Wireless Network Adapter [14e4:43a0] (rev 03)
04:00.0 Multimedia controller [0480]: Broadcom Inc. and subsidiaries 720p FaceTime HD Camera [14e4:1570]
05:00.0 Non-Volatile memory controller [0108]: Samsung Electronics Co Ltd NVMe SSD Controller PM9A1/PM9A3/980PRO [144d:a80a]
06:00.0 PCI bridge [0604]: Intel Corporation DSL5520 Thunderbolt 2 Bridge [Falcon Ridge 4C 2013] [8086:156d]
07:00.0 PCI bridge [0604]: Intel Corporation DSL5520 Thunderbolt 2 Bridge [Falcon Ridge 4C 2013] [8086:156d]
07:03.0 PCI bridge [0604]: Intel Corporation DSL5520 Thunderbolt 2 Bridge [Falcon Ridge 4C 2013] [8086:156d]
07:04.0 PCI bridge [0604]: Intel Corporation DSL5520 Thunderbolt 2 Bridge [Falcon Ridge 4C 2013] [8086:156d]
07:05.0 PCI bridge [0604]: Intel Corporation DSL5520 Thunderbolt 2 Bridge [Falcon Ridge 4C 2013] [8086:156d]
07:06.0 PCI bridge [0604]: Intel Corporation DSL5520 Thunderbolt 2 Bridge [Falcon Ridge 4C 2013] [8086:156d]
08:00.0 System peripheral [0880]: Intel Corporation DSL5520 Thunderbolt 2 NHI [Falcon Ridge 4C 2013] [8086:156c]
  • lsusb (软件包 usbutils )输出:

MacBook Pro Late 2013 上执行 lsusb 输出
Bus 002 Device 003: ID 05ac:8406 Apple, Inc. Internal Memory Card Reader
Bus 002 Device 004: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter #这是我的USB千兆以太网卡
Bus 002 Device 002: ID 2109:0813 VIA Labs, Inc. VL813 Hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 008: ID 05ac:8289 Apple, Inc. Bluetooth Host Controller
Bus 001 Device 007: ID 05ac:820b Apple, Inc. Bluetooth HID Mouse
Bus 001 Device 006: ID 05ac:820a Apple, Inc. Bluetooth HID Keyboard
Bus 001 Device 004: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth)
Bus 001 Device 003: ID 2109:2813 VIA Labs, Inc. VL813 Hub
Bus 001 Device 005: ID 05ac:0262 Apple, Inc. Apple Internal Keyboard / Trackpad
Bus 001 Device 002: ID 0781:5571 SanDisk Corp. Cruzer Fit  #这是我的SanDisk U盘
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

USB快速以太网卡

我需要支持USB以太网卡:

Bus 002 Device 004: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter
内核配置支持USB快速以太网卡(Realtek RTL8153 Gigabit Ethernet Adapter)
Device Drivers --->
  [*] Network device support --->
    <*> USB Network Adapters --->
      <M> Multi-purpose USB Networking Framework
        <M> (Module from table)

以及 通过USB Tethering方式共享Android的Internet连接 所使用的 Gentoo linux - Android USB Tethering 所以还需要内核 USB Network Adapters 驱动支持,启用 Host for RNDIS and ActiveSync devices

显卡

由于 MacBook Pro 15" Late 2013 具备了Intel集成显卡和NVIDIA显卡,所以如果准备使用开源驱动(intel开源驱动和 Nouveau 开源驱动),则应该将两个显卡的支持都编译,即使只准备使用其中之一。因为这样编译了两个显示驱动,依然可以通过 vga_switcheroo 进行切换,而且这样也可以通过关闭其中一个显卡来节约能耗。

采用Intel显卡可以延长电池使用时间,不过这需要启动进入 macOS 系统,然后使用 gfxCardStatus 来强制使用Intel显卡,然后使用 vga_switcheroo 来关闭NVIDIA显卡。

不幸的是,Intel显卡不支持多显示器。也就是说,如果需要使用多个显示器,不建议使用Intel显卡,即使它比较节约电池耗电。

使用NVIDIA的显卡也有限制,你不能控制显示屏的背光,而且停止x server将会进入黑屏,此时就必须重启主机。(确实如此,之前一直困扰给我的问题,看来是一个NVIDIA的限制)要么就使用显示登录管理器,也就是终止X server之后,显示管理器会自动再启动一个新的X server,避免进入黑屏。

使用NVIDIA显卡可以支持多显示器, ZaphodHeads 功能,或者简单地使用 xrandr

我在编译内核完内核执行 make modules_install 有一个报错:

depmod: WARNING: /lib/modules/6.1.12-gentoo-xcloud/video/nvidia-drm.ko needs unknown symbol drm_compat_ioctl

看起来是私有Nivida驱动会提供,执行 Gentoo NVIDIA驱动 之后就没有这个WARNING了

备注

设备驱动实在太繁杂了,内核大多数代码和配置开关都是有关驱动的,很多设备闻所未闻。我尽量削减配置,这样可以将内核精简,并且减少编译时间(即使是模块不占内存空间但是编译时间太长了)

内核配置

处理器相关内核配置
Processor type and features  --->
  [ ] Symmetric multi-processing support  #MBP只有一个处理器,我关掉了SMP支持
  [ ] Enable MPS table  #对于不支持ACPI的旧型号处理器需要,新型特别是64位处理器有ACPI支持,MADT和DSDT会覆盖MPS table
  [*] x86 CPU resource control support # Intel RDT技术 以及 AMD QoS 技术
  [ ] Support for extended (non-PC) x86 platforms # 标准PC无需此选项,支持non-PC 64位x86系统才需要打开(Numascale NumaChip / ScaleMP vSMP / SGI Ultraviolet)
  [*] Intel Low Power Subsystem Support # Intel低功耗子系统支持
  [ ] AMD ACPI2Platform devices support # AMD的ACPI支持,对于AMD系列处理器才需要
  [*] EFI runtime service support 
  [*] EFI stub support
Apple MBP相关内核配置
Device Drivers  --->
  Input device support  --->
    [*] Mice  --->
      # For trackpad support
      <*> Apple USB BCM5974 Multitouch trackpad support
  Hardware Monitoring support  --->
    # Motion, light sensor, keyboard backlight
    <*> Apple SMC (Motion sensor, light sensor, keyboard backlight)
  Graphics support  --->
    <*> Intel 8xx/9xx/G3x/G4x/HD Graphics
    Backlight & LCD device support  --->
      # Screen backlight
      <*>     Apple Backlight Driver
  X86 Platform Specific Device Drivers  --->
    <*>   Apple Gmux Driver  #这个配置当前只支持屏幕背光控制,但是以后可能会支持混合显卡,是苹果笔记本特定硬件支持
  Multimedia support  --->
    Media USB Adapters  --->
      # Webcam
      <M>   USB Video Class (UVC) #我这里没有设置成功,似乎还有依赖选项没有打开
  Sound card support  --->
    Advanced Linux Sound Architecture  --->
      PCI sound devices  --->
        <M>   Intel HD Audio  --->
          [*]   Build HDMI/DisplayPort HD-audio codec support
          [*]   Build Cirrus Logic codec support
  USB support  --->
    # USB 3.0 (for integrated keyboard/trackpad)
    <*>  xHCI HCD (USB 3.0) support
Power management and ACPI options --->
  ACPI (Advanced Configuration and Power Interface) Support  --->
    <*>   Smart Battery System
  • 确保以下选项没有选择,以便使用Broadcom私有无线驱动:

Apple MBP需要关闭的选项(以便使用私有驱动)
Networking support  --->
  Wireless  --->
    < >   Generic IEEE 802.11 Networking Stack (mac80211)
Device Drivers  ---> 
  Network device support  --->
    Wireless LAN  --->
      < >   Broadcom 43xx wireless support (mac80211 stack)
      < >   Broadcom IEEE802.11n embedded FullMAC WLAN driver
  Sonics Silicon Backplane  --->
    < > Sonics Silicon Backplane support

内核编译安装以后,立即完成 Gentoo Linux在MacBook Pro配置WifiGentoo NVIDIA驱动 ,因为这两者都是私有软件,需要作为模块编译到内核。

参考