IMX6Q上移植AR3K蓝牙驱动

我的开发板配置:
开发板硬件:IMX6Q
蓝牙模块: 基于MINI PCI-E接口的 ATHEROS AR5B225 300M无线+4.0蓝牙 二合一半高网卡模块(AR3K系列)
linux内核:3.14.52(主要是我的开发板自带内核带了很多工具,如果换底版本的内核的话,会比较麻烦,所以就是用了其自带核)
编译工具:arm-linux-gcc:4.9.2
我把所有的压缩包都放在了/opt/arm/下,我下面讲述的都是针对这个目录下。大家可以针对自己的喜好来选择目录

  1. 安装交叉编译工具arm-linux-gcc
    #tar xzvf arm-linux-gcc /usr/local          
    # export PATH=$PATH:/usr/local/arm/4.3.2/bin  
  1. 解压编译配置内核

由于我使我开发板光盘自带的内核源码,所以不需要修改源码中的Makefile。如果是从网上下载的内核源码,在编译的时候需要修改Makefile,需要把蓝牙的部分配置加上去, 如下。

    #tar xzvf linux-3.14.52   
    #cd linux-14.52   
    #make menuconfig ARCH=arm
    Linux/arm 3.14.52 Kernel Configuration
	[*] Networking support 
		<*>   Bluetooth subsystem support 
			--- Bluetooth subsystem support 
			<*>   RFCOMM protocol support
			[*]     RFCOMM TTY support
			<*>   BNEP protocol support
			[*]     Multicast filter support
			[*]     Protocol filter support
			<*>   HIDP protocol support
			Bluetooth device drivers  ---> 
				<*> HCI USB driver
				<*> HCI SDIO driver
				<*> HCI UART driver
				[*]   UART (H4) protocol support
				[*]   BCSP protocol support
				[*]   Atheros AR300x serial support
				[*]   HCILL protocol support
				[*]   Three-wire UART (H5) protocol support
				< > HCI BCM203x USB driver
				< > HCI BPA10x USB driver
				<*> HCI BlueFRITZ! USB driver
				< > HCI VHCI (Virtual HCI device) driver
				< > Marvell Bluetooth driver support
				<*> Atheros firmware download driver

然后就开始交叉编译内核。

    #make zImage  
  1. 烧写内核,启动开发板,查看内核打印信息
 rtc-isl1208 0-006f: setting system clock to 2020-01-01 13:01:50 UTC (1577883710)
ALSA device list:
  #0: imx-hdmi-soc
Bluetooth: Patch file not found ar3k/AthrBT_0x01020200.dfu
Bluetooth: Loading patch file failed
ath3k: probe of 1-1.5:1.0 failed with error -2
kjournald starting.  Commit interval 5 seconds
EXT3-fs (mmcblk3p2): using internal journal

进入系统命令行:

#lsusb
Bus 001 Device 005: ID 0489:e036 Foxconn / Hon Hai
Bus 001 Device 004: ID 0bda:8179 Realtek Semiconductor Corp. 
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
#lsusb -v
Bus 001 Device 005: ID 0489:e036 Foxconn / Hon Hai 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass          224 Wireless
  bDeviceSubClass         1 Radio Frequency
  bDeviceProtocol         1 Bluetooth
  bMaxPacketSize0        64
  idVendor           0x0489 Foxconn / Hon Hai
  idProduct          0xe036 
  bcdDevice            0.02
  iManufacturer           1 Atheros Communications
  iProduct                2 Bluetooth USB Host Controller
  iSerial                 3 Alaska Day 2006
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          177
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          4 BT HCI
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0000  1x 0 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0000  1x 0 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0009  1x 9 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0009  1x 9 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       2
      bNumEndpoints           2
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0011  1x 17 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0011  1x 17 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       3
      bNumEndpoints           2
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0019  1x 25 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0019  1x 25 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       4
      bNumEndpoints           2
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0021  1x 33 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0021  1x 33 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       5
      bNumEndpoints           2
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0031  1x 49 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0031  1x 49 bytes
        bInterval               1
Device Status:     0x0003
  Self Powered
  Remote Wakeup Enabled

根据上述信息中的
iProduct 2 Bluetooth USB Host Controller
可确定对应固件文件为如下文件:

ath3k-1.fw
ar3k/AthrBT_0x01020200.dfu
ar3k/ramps_0x01020200_40.dfu
  1. 下载并添加固件
    固件下载:git clone [git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git](git://git.kernel.org/pub/scm/linux/kernel/git/firmware

刚开始我是打算将这几个固件文件放在文件系统中,但是重启后发现还是提示通用的错误,后面再网上找了一些资料才明白,我的驱动编译在内核,此时的文件系统还没有挂在,不可能找到我的固件文件,此处可以通过先启动linux内核,然后在将蓝牙模块连接上,通过hciconfig便可检测到hci0设备,这表明蓝牙设备驱动OK,固件正确。但是我的蓝牙设备不可能拆下来等内核启动后在连接,太不方便了,于是我有两种思路:
(1)将固件文件编译进内核
(2)将驱动文件以模块方式编译,然后在文件系统中挂载
我这里只尝试了第一种方法,下面列出详细步骤:

#cp linux-firmware/ath3k-1.fw ./linux-3.14.52/firmware/
#cp linux-firmware/ar3k ./linux-3.14.52/firmware/
Linux/arm 3.14.52 Kernel Configuration
	Device Drivers  --->
		Generic Driver Options  --->   
			(ath3k-1.fw ar3k/AthrBT_0x01020200.dfu ar3k/ramps_0x01020200_40.dfu) External firmware blobs to build into the kernel binary                  
			(firmware) Firmware blobs root directory                

其中fireware为固件根目录,然后ath3k-1.fw ar3k/AthrBT_0x01020200.dfu ar3k/ramps_0x01020200_40.dfu这个必须在firmware目录下对应文件夹中,否则驱动还是会报错误.
4. 重新编译内核
将重新编译的内核烧写进板子,启动后发现没有上述的报错信息,说明固件文件解决了。
通过如下命令可确定蓝牙设备驱动加载OK

#cat /proc/device
Character devices:
  1 mem
  4 /dev/vc/0
  4 tty
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
  7 vcs
 10 misc
 13 input
 29 fb
 81 video4linux
 89 i2c
 90 mtd
108 ppp
116 alsa
128 ptm
136 pts
153 spi
166 ttyACM
180 usb
188 ttyUSB
189 usb_device
199 galcore
207 ttymxc
216 rfcomm//这便是蓝牙设备

关于蓝牙的连接及文件传输后续将补充。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值