Dunedan / mbp-2016-linux

State of Linux on the MacBook Pro 2016 & 2017
2.1k stars 109 forks source link

MacBook 12-inch, 2017 (MacBook 10,1 Retina) #99

Closed marbetschar closed 5 years ago

marbetschar commented 5 years ago

How to determine which of this is applicable for the MacBook 12", 2017...? I already got Linux running on this machine, but only with the bare minimum: Display, Trackpad and Keyboard.

Love to get Bluetooth up & running as a next step. How to figure out which exact hardware device is builtin and where/how to check if there is any driver/firmware available?

Would love to get some pointers to head into the right direction.

FWIW: I'm currently running a custom spin of Manjaro Linux, with the macbook12-apple-spi driver preinstalled.

leifliddy commented 5 years ago

@marbetschar there's already an open thread for bluetooth issues, please continue the discussion there https://github.com/Dunedan/mbp-2016-linux/issues/29

To summarize what the current status is: bluetooth should work out-of-the-box with on the MacBook10,1 on kernels 4.20 and below

Just make sure your kernel config includes the following: CONFIG_BT_HCIUART_SERDEV=y CONFIG_BT_HCIUART_BCM=y

For kernel 5.x, you'll need to apply this patch: https://lkml.org/lkml/2019/3/31/344

**no firmware needs to be loaded for this bluetooth device

If you need help with anything, don't be afraid to ask.

marbetschar commented 5 years ago

@leifliddy thanks for the quick response! Love to try the provided kernel config ... but as I've never done that before I have no clue where to put it :speak_no_evil:

Any chance you can get me a brief explanation of the steps need to be taken?

leifliddy commented 5 years ago

@marbetschar first find which kernel you are currently using. Could you post the output of 'uname -r' You'll find the corresponding kernel config under /boot Search this file for those kernel config options

ie

[root@black ~]# uname -r
5.0.5-200.fc29.x86_64
[root@black ~]# egrep 'CONFIG_BT_HCIUART_SERDEV|CONFIG_BT_HCIUART_BCM' /boot/config-5.0.5-200.fc29.x86_64 
CONFIG_BT_HCIUART_SERDEV=y
CONFIG_BT_HCIUART_BCM=y
marbetschar commented 5 years ago

Kernel:

# uname -r
4.20.17-1-MANJARO

But I can't find any corresponding config file:

# ls -l /boot
insgesamt 51668
drwxr-xr-x 5 root root     4096  1. Jan 1970  efi
drwxr-xr-x 5 root root     4096  7. Apr 17:38 grub
-rw-r--r-- 1 root root 32306719  6. Apr 14:13 initramfs-4.20-x86_64-fallback.img
-rw-r--r-- 1 root root 12398380  6. Apr 14:13 initramfs-4.20-x86_64.img
-rw-r--r-- 1 root root  2219520 26. Mär 12:11 intel-ucode.img
-rw-r--r-- 1 root root       22 19. Mär 19:07 linux420-x86_64.kver
drwxr-xr-x 2 root root     4096  6. Apr 00:55 memtest86+
-rw-r--r-- 1 root root      709  6. Apr 15:01 refind_linux.conf
-rw-r--r-- 1 root root  5957504 19. Mär 19:07 vmlinuz-4.20-x86_64

Does it work if I just add a new file with the flags in it?

leifliddy commented 5 years ago

sorry, I'm not familiar with Manjaro. Ok, try this:

cat /lib/modules/$(uname -r)/build/.config

does this file exist?

marbetschar commented 5 years ago

Indeed, it does:

$ egrep 'CONFIG_BT_HCIUART_SERDEV|CONFIG_BT_HCIUART_BCM' /lib/modules/$(uname -r)/build/.config
CONFIG_BT_HCIUART_SERDEV=y
CONFIG_BT_HCIUART_BCM=y

FWIW: In GNOME settings I'm able to switch bluetooth on. But next time I'm going to the very same panel it's again switched off:

Bildschirmfoto vom 2019-04-07 19-20-33

leifliddy commented 5 years ago

could you post the output of the following two commands?

hciconfig dmesg | egrep -i 'bluetooth|hci_uart| dw-apb-uart|brcmfmac|8250|ttys'

marbetschar commented 5 years ago
hciconfig
bash: hciconfig: Command not found.

(seems to be deprecated. Seems it's no longer in bluez-utils and I was not able to install bluez-utils-compat due to a PGP verification error)

dmesg | egrep -i 'bluetooth|hci_uart| dw-apb-uart|brcmfmac|8250|ttys'
[    1.006334] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    1.015331] sched_clock: Marking stable (1018250819, -2931442)->(1027618675, -12299298)
[    6.692869] Bluetooth: Core ver 2.22
[    6.692887] Bluetooth: HCI device and connection manager initialized
[    6.692892] Bluetooth: HCI socket layer initialized
[    6.692894] Bluetooth: L2CAP socket layer initialized
[    6.692897] Bluetooth: SCO socket layer initialized
[    6.793133] dw-apb-uart.2: ttyS0 at MMIO 0x9282b000 (irq = 21, base_baud = 115200) is a 16550A
[    6.793218] serial serial0: tty port ttyS0 registered
[    6.809703] dw-apb-uart.3: ttyS1 at MMIO 0x9282c000 (irq = 20, base_baud = 3000000) is a 16550A
[    6.809786] serial serial1: tty port ttyS1 registered
[    6.946732] Bluetooth: HCI UART driver ver 2.3
[    6.946734] Bluetooth: HCI UART protocol H4 registered
[    6.946735] Bluetooth: HCI UART protocol BCSP registered
[    6.946751] Bluetooth: HCI UART protocol LL registered
[    6.946752] Bluetooth: HCI UART protocol ATH3K registered
[    6.946765] Bluetooth: HCI UART protocol Three-wire (H5) registered
[    6.946797] Bluetooth: HCI UART protocol Intel registered
[    6.946834] Bluetooth: HCI UART protocol Broadcom registered
[    6.946846] Bluetooth: HCI UART protocol QCA registered
[    6.946847] Bluetooth: HCI UART protocol AG6XX registered
[    6.946848] Bluetooth: HCI UART protocol Marvell registered
[    6.962933] hci_uart_bcm serial1-0: Unexpected ACPI gpio_int_idx: -1
[    6.962936] hci_uart_bcm serial1-0: Unexpected number of ACPI GPIOs: 0
[    6.962940] hci_uart_bcm serial1-0: No reset resource, using default baud rate
[    7.192802] usbcore: registered new interface driver brcmfmac
[    7.325659] brcmfmac: brcmf_fw_alloc_request: using brcm/brcmfmac4350c2-pcie for chip BCM4350/5
[    7.328776] brcmfmac 0000:02:00.0: Direct firmware load for brcm/brcmfmac4350c2-pcie.txt failed with error -2
[    7.628600] brcmfmac: brcmf_fw_alloc_request: using brcm/brcmfmac4350c2-pcie for chip BCM4350/5
[    7.628623] brcmfmac 0000:02:00.0: Direct firmware load for brcm/brcmfmac4350c2-pcie.clm_blob failed with error -2
[    7.628625] brcmfmac: brcmf_c_process_clm_blob: no clm_blob available (err=-2), device may have limited channels available
[    7.629123] brcmfmac: brcmf_c_preinit_dcmds: Firmware: BCM4350/5 wl0: Nov 26 2015 03:48:57 version 7.35.180.133 (r602372) FWID 01-c45b39d6
[    7.662052] brcmfmac 0000:02:00.0 wlp2s0: renamed from wlan0
[    9.176098] Bluetooth: hci0: command 0xfc18 tx timeout
[    9.214055] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    9.214056] Bluetooth: BNEP filters: protocol multicast
[    9.214060] Bluetooth: BNEP socket layer initialized
[   17.069640] Bluetooth: hci0: BCM: failed to write update baudrate (-110)
[   17.069645] Bluetooth: hci0: Failed to set baudrate
[   19.202953] Bluetooth: hci0: command 0x0c03 tx timeout
[   27.096214] Bluetooth: hci0: BCM: Reset failed (-110)
leifliddy commented 5 years ago

Damn, I had no idea that hciconfig was deprecated, I normally use bluetoothctl anyway. I was just looking for a simple way to see if the bluetooth device was registered. I can see in the dmesg output, that it's not. Is your system using grub to boot and are you using an HFS+ ESP partition?

Could you post the output of the following commands: gdisk /dev/nvme0n1 -l efibootmgr -v

Here's what they look like on my system: The EF00 partition on my system is not actually being used. The next time I reinstall linux on this system, I'll remove it. The AF00 partition in mounted under /boot/efi

Number  Start (sector)    End (sector)  Size       Code  Name
   1             256           51455   200.0 MiB   EF00  
   2           51456          102655   200.0 MiB   AF00  Linux HFS+ ESP
   3          102656          364799   1024.0 MiB  8300  
   4          364800         2413823   7.8 GiB     8200  
   5         2413824       122138111   456.7 GiB   8300 
[root@mac ~]# efibootmgr -v
BootCurrent: 0000
Timeout: 2 seconds
BootOrder: 0000
Boot0000* Fedora    HD(2,GPT,90ceb047-008b-43be-803c-4b3eb18f0786,0xc900,0xc800)/File(\EFI\fedora\shimx64.efi)
marbetschar commented 5 years ago

It's a dualboot environment with macOS on an encrypted partition. Also installed Linux on an encrypted 120 GB LUKS partition. The goal is to use a 80 GB VeraCrypt partition as an additional encrypted, shared place for macOS and Linux.

$ sudo gdisk /dev/nvme0n1 -l
GPT fdisk (gdisk) version 1.0.4

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/nvme0n1: 122138133 sectors, 465.9 GiB
Model: APPLE SSD AP0512J                       
Sector size (logical/physical): 4096/4096 bytes
Disk identifier (GUID): E64F8F55-87E0-4C03-98E8-6FD467DA5483
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 5
First usable sector is 6, last usable sector is 122138127
Partitions will be aligned on 1-sector boundaries
Total free space is 19 sectors (76.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1               6           76805   300.0 MiB   EF00  EFI System Partition
   2           76806        73259366   279.2 GiB   AF0A  NoName
   3        73259367       102523388   111.6 GiB   8300  
   4       102523392       122105343   74.7 GiB    0700  
   5       122105360       122138127   128.0 MiB   AB00  Booter
$ efibootmgr -v
BootCurrent: 0001
BootOrder: 0001,0000
Boot0000* Manjaro   HD(1,GPT,cdd0289c-ec1a-4167-933a-615e4aa98245,0x6,0x12c00)/File(\EFI\Manjaro\grubx64.efi)
Boot0001* rEFInd Boot Manager   HD(1,GPT,cdd0289c-ec1a-4167-933a-615e4aa98245,0x6,0x12c00)/File(\EFI\refind\refind_x64.efi)
Boot0081* Recovery OS   PciRoot(0x0)/Pci(0x1c,0x0)/Pci(0x0,0x0)//HD(2,GPT,24e9ecac-7dc3-4791-af34-981c1481dad6,0x12c06,0x45d964b)/VenMedia(be74fcf7-0b7c-49f3-9147-01f4042e6842,d7b8b164425fe446b9533f249428580f)/File(\836F48FA-091E-45A2-9ED9-DF2891294479\boot.efi)
Boot0082*   PciRoot(0x0)/Pci(0x1c,0x0)/Pci(0x0,0x0)//HD(2,GPT,24e9ecac-7dc3-4791-af34-981c1481dad6,0x12c06,0x45d964b)/VenMedia(be74fcf7-0b7c-49f3-9147-01f4042e6842,46c84fc81b985742b6a6ef7ac029fbd5)/File(\836F48FA-091E-45A2-9ED9-DF2891294479\System\Library\CoreServices\boot.efi)
BootFFFF*   PciRoot(0x0)/Pci(0x1c,0x0)/Pci(0x0,0x0)//HD(3,GPT,33af8ae5-0810-4b3f-8c33-98ce5f6617d6,0x5ef2e10,0xef8000)/File(\System\Library\CoreServices\boot.efi)
leifliddy commented 5 years ago

Hmmm...I'm wondering what would happen if you tried changing the boot order so that boot entry 0000 (grub) boots by default. efibootmgr -o 0000,0001

The use of rEFInd is the one thing that stands out as being different from my system. Although, there could be something different with the Macbook10,1 models vs the Macbook8,1 + 9,1 models. Just to be sure, you could also try booting Fedora 29 from a usb stick, bluetooth should just work with kernels 4.20 and below.

Wait...which partition is mounted under /boot/efi? Is it the EF00 partition?

marbetschar commented 5 years ago

I can't think of why rEFInd would cause a bluetooth issue. I can see the point of figuring out the system differences, but from my point of view I'd prefer not tinkering with the partitions to get bluetooth working ;)

One point of confusion might be the fact, that my MacBook is refered to as "MacBook 10,1 Retina" - it is not a MacBook Pro, just a regular MacBook 12-inch from 2017. From what I know there seems to be a MacBook Pro out there actually beeing a "MacBookPro 10,1" from mid 2012. Maybe this is what causes the confusion?

UPDATE: Sorry, didn't see your question. Yes, regarding it's size the /boot/efi should be the EF00 partition:

$ df -h
Dateisystem    Größe Benutzt Verf. Verw% Eingehängt auf
dev             3.9G       0  3.9G    0% /dev
run             3.9G    1.4M  3.9G    1% /run
/dev/dm-0       110G     11G   94G   11% /
tmpfs           3.9G     83M  3.8G    3% /dev/shm
tmpfs           3.9G       0  3.9G    0% /sys/fs/cgroup
tmpfs           3.9G     48M  3.8G    2% /tmp
/dev/nvme0n1p1  300M     36M  264M   12% /boot/efi
tmpfs           788M     24M  764M    3% /run/user/1000
marbetschar commented 5 years ago

@leifliddy I've read through the https://github.com/Dunedan/mbp-2016-linux/issues/29# a bit. From the current point of work, what is the suggested path forward in terms of the kernel version & bluetooth? Shall I upgrade to v5.x, or use the LTS version (4.19)?

Currently I'm using 4.20, because it was the only one which allowed me to install the system due to the removal of the cipher aes-xts-plain-64.

But as 4.20 is EOL anyways it may not make a lot of sense putting any more effort in this kernel version to get bluetooth running?

leifliddy commented 5 years ago

I have a macbook9,1 (12 inch 2016), and bluetooth has been working fine for ages.

If you look at this thread https://github.com/Dunedan/mbp-2016-linux/issues/29 teancum has a macbook9,1 but couldn't get bluetooth working with Manjaro, but he did get it working with Fedora. It seems that there is something off with the way that Manjaro is setup.

And the one glaring difference between Manjaro and Fedora is the lack of the AF00 (HFS+ ESP) efi partition and the use of rEFInd vs grub. Although rEFInd would likely be the key suspect. It could be the kernel parameters is uses or any number of things.

I would try booting from a Fedora 29 usb stick and see if that works. That would let us know whether the issue lies with the Manjaro or whether it's a Macbook10,1 driver issue.

Or you could try changing the boot order so that grub boots by default (Boot0000). The worst case scenario is that the system doesn't boot (but I doubt that would happen) In any case it's fairly easy to boot from a rescue usb stick and change the boot order back.

leifliddy commented 5 years ago

@marbetschar For the sake of being thorough could check to see if all of these kernel options are configured?

cat /lib/modules/$(uname -r)/build/.config | egrep 'CONFIG_SERIAL_8250_LPSS|CONFIG_BT_HCIUART_BCM|CONFIG_BT_HCIUART_SERDEV|CONFIG_SERIAL_DEV_BUS|CONFIG_SERIAL_DEV_CTRL_TTYPORT|CONFIG_SERIAL_8250_DW'
leifliddy commented 5 years ago

@marbetschar I might have some time this week to install Manjaro on my Macbook9,1 and play around with it.

marbetschar commented 5 years ago
$ cat /lib/modules/$(uname -r)/build/.config | egrep 'CONFIG_SERIAL_8250_LPSS|CONFIG_BT_HCIUART_BCM|CONFIG_BT_HCIUART_SERDEV|CONFIG_SERIAL_DEV_BUS|CONFIG_SERIAL_DEV_CTRL_TTYPORT|CONFIG_SERIAL_8250_DW'
CONFIG_BT_HCIUART_SERDEV=y
CONFIG_BT_HCIUART_BCM=y
CONFIG_SERIAL_8250_DW=m
CONFIG_SERIAL_8250_LPSS=y
CONFIG_SERIAL_DEV_BUS=y
CONFIG_SERIAL_DEV_CTRL_TTYPORT=y
leifliddy commented 5 years ago

this is what I see on my system

CONFIG_BT_HCIUART_SERDEV=y
CONFIG_BT_HCIUART_BCM=y
CONFIG_SERIAL_8250_DW=y
CONFIG_SERIAL_8250_LPSS=m
CONFIG_SERIAL_DEV_BUS=y
CONFIG_SERIAL_DEV_CTRL_TTYPORT=y
marbetschar commented 5 years ago

@leifliddy if you're able to test Manjaro, this would be awesome! If you like, you can use one of the isos I've built to get a quick install: https://github.com/marbetschar/Manjaro-Linux-on-MacBook-12

Just downloaded Fedora29 and will test it right now - but I suspect the keyboard and trackpad won't work since the apple-spi driver is WIP, and I do not have any usb keyboard or mouse available right now.

UPDATE: Yeah, Trackpad & Keyboard are not working after booting Fedora29. Probably able to test this tomorrow.

leifliddy commented 5 years ago

Hmmm....some people have stated in that they needed to change CONFIG_SERIAL_8250_DW=m to CONFIG_SERIAL_8250_DW=y to get bluetooth to work. I need to research this a bit more....

marbetschar commented 5 years ago

FWIW: I've installed the bcm4350-firmware using yay after the initial install. You can find the details here: https://forum.manjaro.org/t/macbook-12-2017-challenge-the-quest-for-drivers/82098/19?u=marbetschar

@leifliddy thank you very much for providing a hand! I highly appreciate your efforts.

leifliddy commented 5 years ago

@marbetschar so bluetooth is working now?!?

marbetschar commented 5 years ago

@leifliddy no its not 🤣 just wanted to say thank you for your time 😄

leifliddy commented 5 years ago

@marbetschar I was going to say...that this is a hci uart bluetooth device and doesn't require any firmware. The functions are derived from acpi methods. Cool, no worries hopefully we can figure this out : )

leifliddy commented 5 years ago

@marbetschar could post the output of the following commands? lsmod | grep 8250 lsinitrd /boot/initramfs-4.20-x86_64.img | grep 8250

marbetschar commented 5 years ago
$ lsmod | grep 8250
8250_dw                28672  0

@leifliddy lsinitrd seems not to be installed. Which package does contain this command?

leifliddy commented 5 years ago

@marbetschar dracut

marbetschar commented 5 years ago

@leifliddy dracut seems not to be available for Arch:

leifliddy commented 5 years ago

hmmm...maybe it's called lsinitcpio for Manjaro

marbetschar commented 5 years ago

$ lsinitcpio /boot/initramfs-4.20-x86_64.img | grep 8250 does not output anything

leifliddy commented 5 years ago

Interesting, I would try generating a new initramfs-4.20-x86_64.img and adding the 8250_dw module to it. With Manjaro, you would use mkinitcpio to do this. 8250_dw seems to be a pretty important module related to the Macbook's bluetooth device. If that adding the module to initramfs doesn't work, I would try compiling a new kernel and include the 8250_dw module in the kernel (CONFIG_SERIAL_8250_DW=y). I'll play around with Manjaro tomorrow....

marbetschar commented 5 years ago

@leifliddy just booted Fedora 29 and there Bluetooth seems to work. At least GNOME is reporting the Bluetooth state as "On".

marbetschar commented 5 years ago

Added the 8250_dw module to the initramfs, but it did not help in any way. Here's what I've done:

Deinstalled the not needed firmware:

$ sudo pacman -R bcm4350-firmware

Added module to /etc/mkinitcpio.conf:

...
MODULES="8250_dw"
...

Built initramfs:

$ sudo mkinitcpio -P
==> Building image from preset: /etc/mkinitcpio.d/linux420.preset: 'default'
  -> -k /boot/vmlinuz-4.20-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-4.20-x86_64.img
==> Starting build: 4.20.17-1-MANJARO
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [autodetect]
  -> Running build hook: [modconf]
  -> Running build hook: [block]
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [encrypt]
  -> Running build hook: [filesystems]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-4.20-x86_64.img
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux420.preset: 'fallback'
  -> -k /boot/vmlinuz-4.20-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-4.20-x86_64-fallback.img -S autodetect
==> Starting build: 4.20.17-1-MANJARO
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [modconf]
  -> Running build hook: [block]
==> WARNING: Possibly missing firmware for module: wd719x
==> WARNING: Possibly missing firmware for module: aic94xx
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [encrypt]
  -> Running build hook: [filesystems]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-4.20-x86_64-fallback.img
==> Image generation successful

Checked if module is in initramfs:

$ lsinitcpio /boot/initramfs-4.20-x86_64.img | grep 8250
usr/lib/modules/4.20.17-1-MANJARO/kernel/8250_dw.ko

Rebooted the machine and tested Bluetooth in GNOME settings. Also looked at the dmesg output: the baudrate error is still there:

$ dmesg |grep Bluetooth
[    7.213117] Bluetooth: Core ver 2.22
[    7.213606] Bluetooth: HCI device and connection manager initialized
[    7.213611] Bluetooth: HCI socket layer initialized
[    7.213613] Bluetooth: L2CAP socket layer initialized
[    7.213618] Bluetooth: SCO socket layer initialized
[    7.366822] Bluetooth: HCI UART driver ver 2.3
[    7.366824] Bluetooth: HCI UART protocol H4 registered
[    7.366825] Bluetooth: HCI UART protocol BCSP registered
[    7.366841] Bluetooth: HCI UART protocol LL registered
[    7.366842] Bluetooth: HCI UART protocol ATH3K registered
[    7.366851] Bluetooth: HCI UART protocol Three-wire (H5) registered
[    7.366885] Bluetooth: HCI UART protocol Intel registered
[    7.366922] Bluetooth: HCI UART protocol Broadcom registered
[    7.366932] Bluetooth: HCI UART protocol QCA registered
[    7.366933] Bluetooth: HCI UART protocol AG6XX registered
[    7.366934] Bluetooth: HCI UART protocol Marvell registered
[    9.130544] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    9.130546] Bluetooth: BNEP filters: protocol multicast
[    9.130549] Bluetooth: BNEP socket layer initialized
[    9.437501] Bluetooth: hci0: command 0xfc18 tx timeout
[   17.544208] Bluetooth: hci0: BCM: failed to write update baudrate (-110)
[   17.544213] Bluetooth: hci0: Failed to set baudrate
[   19.677517] Bluetooth: hci0: command 0x0c03 tx timeout
[   27.574141] Bluetooth: hci0: BCM: Reset failed (-110)

Will try to build a new Kernel now....

marbetschar commented 5 years ago

@leifliddy just stumpled accross the CONFIG_SPI_DW_PCI Kernel config. Do you think this is needed? Just looked familiar in terms of the whole SPI, DW and PCI stuff :)

As of now it is set like follows in my system - what's the value on your end with working Bluetooth?

$ cat /lib/modules/$(uname -r)/build/.config | grep 'CONFIG_SPI_DW_PCI'
CONFIG_SPI_DW_PCI=m

BTW: Kernel with the flags CONFIG_SERIAL_8250_DW=y and CONFIG_SERIAL_8250_LPSS=m is compiling now...

leifliddy commented 5 years ago

Good work so far, your're moving pretty fast! I don't see 'CONFIG_SPI_DW_PCI' in any of my (Fedora) 4.20 or 5.0 kernel configs.

[root@black boot]# grep CONFIG_SPI_DW_PCI config-*
[root@black boot]# 
marbetschar commented 5 years ago

@leifliddy compiled the kernel and installed it. Unfortunately Bluetooth is still not working :( Any other ideas?

After booting I can see the following output:

$ uname -a
Linux Shira 4.20.17-1-MANJARO #1 SMP PREEMPT Mon Apr 8 20:28:14 UTC 2019 x86_64 GNU/Linux
$ cat /lib/modules/$(uname -r)/build/.config | egrep 'CONFIG_SERIAL_8250_LPSS|CONFIG_BT_HCIUART_BCM|CONFIG_BT_HCIUART_SERDEV|CONFIG_SERIAL_DEV_BUS|CONFIG_SERIAL_DEV_CTRL_TTYPORT|CONFIG_SERIAL_8250_DW'
CONFIG_BT_HCIUART_SERDEV=y
CONFIG_BT_HCIUART_BCM=y
CONFIG_SERIAL_8250_DW=y
CONFIG_SERIAL_8250_LPSS=m
CONFIG_SERIAL_DEV_BUS=y
CONFIG_SERIAL_DEV_CTRL_TTYPORT=y
$ dmesg |grep Blue
[    7.365295] Bluetooth: Core ver 2.22
[    7.365314] Bluetooth: HCI device and connection manager initialized
[    7.365319] Bluetooth: HCI socket layer initialized
[    7.365321] Bluetooth: L2CAP socket layer initialized
[    7.365324] Bluetooth: SCO socket layer initialized
[    7.566516] Bluetooth: HCI UART driver ver 2.3
[    7.566518] Bluetooth: HCI UART protocol H4 registered
[    7.566519] Bluetooth: HCI UART protocol BCSP registered
[    7.566533] Bluetooth: HCI UART protocol LL registered
[    7.566534] Bluetooth: HCI UART protocol ATH3K registered
[    7.566545] Bluetooth: HCI UART protocol Three-wire (H5) registered
[    7.566567] Bluetooth: HCI UART protocol Intel registered
[    7.566607] Bluetooth: HCI UART protocol Broadcom registered
[    7.566626] Bluetooth: HCI UART protocol QCA registered
[    7.566627] Bluetooth: HCI UART protocol AG6XX registered
[    7.566628] Bluetooth: HCI UART protocol Marvell registered
[    9.672212] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    9.672214] Bluetooth: BNEP filters: protocol multicast
[    9.672218] Bluetooth: BNEP socket layer initialized
[    9.815791] Bluetooth: hci0: command 0xfc18 tx timeout
[   17.709153] Bluetooth: hci0: BCM: failed to write update baudrate (-110)
[   17.709158] Bluetooth: hci0: Failed to set baudrate
[   19.842570] Bluetooth: hci0: command 0x0c03 tx timeout
[   27.735879] Bluetooth: hci0: BCM: Reset failed (-110)
marbetschar commented 5 years ago

Seems Bluetooth is finally working!!! :tada: :tada:

For this, I compiled a custom Kernel - based on the Manjaro linux420.

I changed set flags in config.x86_64 like:

CONFIG_BT_HCIUART_SERDEV=y
CONFIG_BT_HCIUART_BCM=y
CONFIG_SERIAL_8250_DW=y
CONFIG_SERIAL_8250_LPSS=y
CONFIG_SERIAL_DEV_BUS=y
CONFIG_SERIAL_DEV_CTRL_TTYPORT=y

And applied the patch of christophgysin: https://github.com/christophgysin/linux/commit/b8c43916bafe6dc8de1aed5ae1cbc76cf7bad374

After compiling and booting with the new kernel, Bluetooth state was shown as "On" and I was able to connect to my iPhone.

@leifliddy thank you so much for your help!! Need now to figure out a way to get Bluetooth running on the LTS Kernel 4.19 and/or the latest Kernel.

leifliddy commented 5 years ago

@marbetschar That is excellent work, really impressed that you got it working!!! I'm wondering what specific action was responsible for bluetooth to start working. The macbook 10,1 doesn't use the 8250_lpss module (CONFIG_SERIAL_8250_LPSS), so the kernel options are essentially the same as you were using on the previous attempt.

I'm wondering if the patch alone was responsible. There have been a number of complaints listed in https://github.com/Dunedan/mbp-2016-linux/issues/29 where the bluetooth controller doesn't always come online at boot time on the macbook 12 inch models. Your dmesg logs are almost identical to the ones that tencum posted:

[    7.978779] Bluetooth: hci0: command 0xfc18 tx timeout
[   16.042789] Bluetooth: hci0: BCM: failed to write update baudrate (-110)
[   16.042793] Bluetooth: hci0: Failed to set baudrate
[   18.090886] Bluetooth: hci0: command 0x0c03 tx timeout
[   26.282855] Bluetooth: hci0: BCM: Reset failed (-110)

I wondering if applying this patch would help at all. I'm going to suggest that to teancum...

marbetschar commented 5 years ago

Thank you for the kind words 🙏🏼

Mhm, those are exactly my thoughts. Wondering if applying the patch would be enough.

Will test these assumptions against a newer Manjaro Kernel (4.19) - but there I think another patch should be applied?

leifliddy commented 5 years ago

Do you still have the previous kernel installed? Do you know you how to patch hci_bcm.c and then build the hci_uart.ko module? If not, I can give you clear instructions on how to do it...

marbetschar commented 5 years ago

@leifliddy which kernel do you mean with "previous"...? I still have the linux420 kernel with the flags and patch applied as described here. Do you mean this one?

Not sure if I know how to create a patch, but I know how to apply an existing patch like this. What's the goal?

FWIW: I'm able to build against a "fresh" Manjaro kernel at any time based upon their kernel repositories. That said, it's easy to test different scenarios on my MacBook. Only downside is compiling of a kernel takes ages (2-3h).

marbetschar commented 5 years ago

Got an idea which may get us closer in tracking this down:

As of now we know:

First conclusion: Either Manjaro applies some configuration/patch/whatever which breaks Bluetooth - or Fedora29 does so to fix Bluetooth.

Furthermore we assume:

  1. CONFIG_SERIAL_8250_LPSS is not needed for Bluetooth
  2. CONFIG_SERIAL_8250_DW is needed for Bluetooth, but configure it as m is probably enough
  3. A patch needs to be applied in order to get Bluetooth working

Based upon this we declare the next actions: The assumptions 1. & 2. are easy to test for me. I just need some time to properly compiling and testing the kernels.

@leifliddy for 3. I'm out. Don't know the inner workings well enough to track this down. If you have time to help out on this, this would be awesome!!

My theory here is: If there's a patch which needs to be applied, this patch was applied to Fedora29. To figure out which patch this is, we should be able to compare the repos. As long as they are targeting the same base kernel version we should be able to pinpoint in which patch the magic happens right?

Here are the source codes of the corresponding kernels:

Not quite sure if all of those assumptions I've made are correct. Just a best guess based upon my current knowledge.

UPDATE: Here's the current output of dmesg. Please note there is still a baudrate error - but Bluetooth is working after system boot.

$ dmesg |grep luetooth
[    6.598641] Bluetooth: Core ver 2.22
[    6.598664] Bluetooth: HCI device and connection manager initialized
[    6.598669] Bluetooth: HCI socket layer initialized
[    6.598671] Bluetooth: L2CAP socket layer initialized
[    6.598676] Bluetooth: SCO socket layer initialized
[    6.754955] Bluetooth: HCI UART driver ver 2.3
[    6.754957] Bluetooth: HCI UART protocol H4 registered
[    6.754959] Bluetooth: HCI UART protocol BCSP registered
[    6.754974] Bluetooth: HCI UART protocol LL registered
[    6.754975] Bluetooth: HCI UART protocol ATH3K registered
[    6.754985] Bluetooth: HCI UART protocol Three-wire (H5) registered
[    6.755025] Bluetooth: HCI UART protocol Intel registered
[    6.755063] Bluetooth: HCI UART protocol Broadcom registered
[    6.762564] Bluetooth: HCI UART protocol QCA registered
[    6.762566] Bluetooth: HCI UART protocol AG6XX registered
[    6.762567] Bluetooth: HCI UART protocol Marvell registered
[    7.367082] Bluetooth: hci0: BCM: failed to write update baudrate (-16)
[    7.367084] Bluetooth: hci0: Failed to set baudrate
[    7.480373] Bluetooth: hci0: BCM: chip id 92
[    7.480988] Bluetooth: hci0: BCM: features 0x2f
[    7.482485] Bluetooth: hci0: BCM4350C0 UART 37.4 MHz Gamay Murata UHE
[    7.482488] Bluetooth: hci0: BCM (003.001.126) build 1492
[    7.482510] bluetooth hci0: Direct firmware load for brcm/BCM.hcd failed with error -2
[    7.482545] Bluetooth: hci0: BCM: Patch brcm/BCM.hcd not found
[    9.141449] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    9.141454] Bluetooth: BNEP filters: protocol multicast
[    9.141463] Bluetooth: BNEP socket layer initialized
[   14.901253] Bluetooth: RFCOMM TTY layer initialized
[   14.901265] Bluetooth: RFCOMM socket layer initialized
[   14.901275] Bluetooth: RFCOMM ver 1.11
[   63.066903] Bluetooth: hci0: unknown advertising packet type: 0x20
[   63.067557] Bluetooth: hci0: unknown advertising packet type: 0x24
[   63.135620] Bluetooth: hci0: unknown advertising packet type: 0x20
[   63.136096] Bluetooth: hci0: unknown advertising packet type: 0x24
[   63.193041] Bluetooth: hci0: unknown advertising packet type: 0x10
[   63.467295] Bluetooth: hci0: unknown advertising packet type: 0x14
[   63.599613] Bluetooth: hci0: unknown advertising packet type: 0x14
[   63.737000] Bluetooth: hci0: unknown advertising packet type: 0x13
[   64.847217] Bluetooth: hci0: unknown advertising packet type: 0x10
[   64.847966] Bluetooth: hci0: unknown advertising packet type: 0x14
leifliddy commented 5 years ago

Can you try this compiling the hci_uart kernel module for the 4.20.17-1 kernel? First, install the linux-headers package for the 4.20.17-1-MANJARO kernel

Boot system with stock 4.20.17-1 kernel **If you're not booted to this kernel then just replace '$(uname -r)' below with the full kernel name Then download the kernel source tarball from https://www.kernel.org/

wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.20.17.tar.xz

extract the drivers/bluetooth directory cd to bluetooth directory backup the hci_bcm.c file (optional)

cp  hci_bcm.c hci_bcm.c.orig

replace the Makefile with this one

obj-m       += hci_uart.o
hci_uart-y  := hci_ldisc.o
hci_uart-m  += hci_serdev.o
hci_uart-m  += hci_h4.o
hci_uart-m  += hci_bcsp.o
hci_uart-m  += hci_ll.o
hci_uart-m  += hci_ath.o
hci_uart-m  += hci_h5.o
hci_uart-m  += hci_intel.o
hci_uart-m  += hci_bcm.o
hci_uart-m  += hci_qca.o
hci_uart-m  += hci_ag6xx.o
hci_uart-m  += hci_mrvl.o
hci_uart-objs   := $(hci_uart-y)

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

put the contents of this patch in a file called patchfile (or whatever you want to call it) https://github.com/christophgysin/linux/commit/b8c43916bafe6dc8de1aed5ae1cbc76cf7bad374.patch now patch hci_bcm.c

patch < patchfile

compile hci_uart.ko module

[root@mac bluetooth]# make
make -C /lib/modules/4.20.16-200.fc29.x86_64/build M=/root/4.20.bluetooth modules
make[1]: Entering directory '/usr/src/kernels/4.20.16-200.fc29.x86_64'
  CC [M]  /root/4.20.bluetooth/hci_ldisc.o
  CC [M]  /root/4.20.bluetooth/hci_serdev.o
  CC [M]  /root/4.20.bluetooth/hci_h4.o
  CC [M]  /root/4.20.bluetooth/hci_bcsp.o
  CC [M]  /root/4.20.bluetooth/hci_ll.o
  CC [M]  /root/4.20.bluetooth/hci_ath.o
  CC [M]  /root/4.20.bluetooth/hci_h5.o
  CC [M]  /root/4.20.bluetooth/hci_intel.o
  CC [M]  /root/4.20.bluetooth/hci_bcm.o
  CC [M]  /root/4.20.bluetooth/hci_qca.o
  CC [M]  /root/4.20.bluetooth/hci_ag6xx.o
  CC [M]  /root/4.20.bluetooth/hci_mrvl.o
  LD [M]  /root/4.20.bluetooth/hci_uart.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /root/4.20.bluetooth/hci_uart.mod.o
  LD [M]  /root/4.20.bluetooth/hci_uart.ko
make[1]: Leaving directory '/usr/src/kernels/4.20.16-200.fc29.x86_64'

compress module (optional)

xz hci_uart.ko

install module

cp hci_uart.ko.xz /lib/modules/$(uname -r)/kernel/drivers/bluetooth/

reboot...

leifliddy commented 5 years ago

This patch was never applied to the Fedora kernel. Fedora isn't going to apply custom patches to anything, it's just the stock kernel. The patches you see for the links you posted are just the cumulative patches that make up each minor release version: kernel 4.18.1, 4.18.2 and so on. The only difference between the Manjaro and Fedora kernels should be the kernel config.

The kernel config is going to specify which modules are:

  1. built-in to the kernel (CONFIG_BT_HCIUART_BCM=y)
  2. compiled as modules (CONFIG_BT_HCIUART_BCM=m)
  3. or left out

The modules themselves should be EXACTLY the same. That's the whole point of having a versioning system. Kernel 4.20.17 is going to have the same patchset regardless of what distro it's running on

BTW that baudrate error message is normal, everyone seems to get that error.

marbetschar commented 5 years ago

@leifliddy thanks for the clarification! Was already wondering why everyone seems to patching instead of upstreaming to get the stuff fixed once and for all :stuck_out_tongue_winking_eye:

In regards of Bluetooth: If I got this straight, the basic idea is to simply apply the patch without changing anything of the default Manjaro Kernel configuration, right?

Just messed up my Manjaro install because of a silly mistake. Will do a fresh install based upon my previous work with Kernel v4.20 so we can take it from there.

UPDATE: Since v4.20 is already end of life, I assume this test case is simply to track things down and apply the knowledge to the v4.19 and v5.x series afterwards, right?

leifliddy commented 5 years ago

@marbetschar right, so the idea is to patch the module (aka driver), compile it, and install it. If you look at your kernel config, all of the modules being built (*=m) are going to physically reside on your system under:

/lib/modules/$(uname -r)/kernel

ie let's say your kernel config contains this: CONFIG_BT_HCIUART=m This option will cause the hci_uart module to be compiled outside of the kernel. This module will physically reside on your system at:

/lib/modules/$(uname -r)/kernel/drivers/bluetooth/hci_uart.ko.xz  (could also be called hci_uart.ko)

Since this module is not built into the kernel, we can simply use the kernel source code to build our own version of this module and then overwrite the original hci_uart.ko module. It's really that simple.

However, if a module is built into the kernel ie, inside of:

/boot/vmlinuz-4.20-x86_64

And you wanted to patch the driver, you would have to re-compile the entire kernel. When you run:

lsmod

All of the modules listed in the output are modules that were built outside of the kernel If a module was built into the kernel, it wouldn't show up with lsmod, you wouldn't see it under /lib/modules/$(uname -r)/kernel, and it wouldn't exist in your initramfs image.

leifliddy commented 5 years ago

As to why bluetooth doesn't work on the stock Manjaro kernel, I have no idea. But, the answer is a bit more complex then it initially seems. In any case, there are Fedora users who claim the bluetooth controller doesn't always come online when the system boots. So, it's not working perfectly there either. I'm not a kernel developer, so I can only help in a limited capacity when it comes to diagnosing this issue on a lower level.

marbetschar commented 5 years ago

@leifliddy I'm currently building the 4.20 kernel with the provided patch applied. Thank you so much for the detailed explanation of how builtin and external modules work!!

Wasn't aware of this, that's why I simply kicked of a full kernel build. However, as I didn't changed any kernel configuration we should end up with the same result eventually.

Will report back as soon as everythings ready.

marbetschar commented 5 years ago

@leifliddy mission accomplished :100: :v: :smile:

The default Manjaro kernel configuration works with simply the patch applied. What's next to get this working in 4.19 or 5.x? Best thing would be to get this solved in the main upstream Linux Kernel in a way everyone does profit from this - but don't know how this process works.

Here are the details:

$ uname -r
4.20.17-1-MANJARO

$ cat /lib/modules/$(uname -r)/build/.config | egrep 'CONFIG_SERIAL_8250_LPSS|CONFIG_BT_HCIUART_BCM|CONFIG_BT_HCIUART_SERDEV|CONFIG_SERIAL_DEV_BUS|CONFIG_SERIAL_DEV_CTRL_TTYPORT|CONFIG_SERIAL_8250_DW'
CONFIG_BT_HCIUART_SERDEV=y
CONFIG_BT_HCIUART_BCM=y
CONFIG_SERIAL_8250_DW=m
CONFIG_SERIAL_8250_LPSS=y
CONFIG_SERIAL_DEV_BUS=y
CONFIG_SERIAL_DEV_CTRL_TTYPORT=y
marbetschar commented 5 years ago

@leifliddy out of curiosity:

Which type of patches get "backported" to a Linux kernel LTS version? Bug- and security fixes? I doubt "new features" would make it?