目錄
5.1、copy所有依賴庫的pkg文件到一個公共的路徑並設置爲全局變量
背景
最近在移植一款RTL8761ATV的藍牙芯片到我的ARM板子上,用的是Linux 4.9的系統,需要自己編譯一個藍牙協議棧。bluez是Linux的官方藍牙協議棧,所以我也用這個來調試我的藍牙功能。雖然網上很多資料講述bluez的移植,但是每個人在移植過程中都可能遇到不同的問題,所以在這裏做個記錄,方便自己也方便他人。
編譯bluez
在正式編譯bluez之前,我們還需要編譯很多其依賴的東西,下面我們按順序來一個一個的編譯。
1、glib的編譯
1.1、編譯zlib
因爲在編譯前需要設置一下環境變量什麼的,比如交叉編譯工具鏈的路徑。包括後面編譯的庫文件也是這樣,所以我將這些環境變量都寫到一個sh腳本里面了:
#!/bin/sh
export PKG_CONFIG_PATH=/home/jimmy/bluez-compile/pkgconfig:$PKG_CONFIG_PATH
export PATH=/home/jimmy/bluez-compile/arm-2014.05/bin:/home/jimmy/bluez-compile/gettext-0.20/install_us/bin:$PATH
設置完交叉編譯命令的環境,然後分別執行下面的編譯命令:
生成Makefile文件:
host=arm-none-linux-gnueabi prefix=/home/jimmy/bluez-compile/zlib-1.2.8/install_us CC=arm-none-linux-gnueabi-gcc ./configure --shared
編譯:
make
安裝:
make install
注意:編譯完後需要設置下路徑,否則glib編譯時可能找不到依賴包。在install_us/lib/pkg-config/目錄中有zlib.pc
執行:pkg-config --cflags zlib.pc
完成後把libz.so* 拷貝到編譯工具鏈libc.so所在目錄:
e.g. install_us/lib/$cp -a libz.so* /home/jimmy/bluez-compile/arm-2014.05/arm-none-linux-gnueabi/libc/lib
1.2、編譯libffi
和zlib的編譯類似
./configure --host=arm-none-linux-gnueabi --prefix=/home/jimmy/bluez-compile/libffi-3.2.1/install_us CC=arm-none-linux-gnueabi-gcc
make
make install
1.3、編譯glib
1.3.1、創建cache文件
jimmy@ubuntu:~/bluez-compile/glib-2.45.3$ vim arm-linux.cache
加入如下設置:
glib_cv_long_long_format=ll
glib_cv_stack_grows=no
glib_cv_uscore=no
ac_cv_func_posix_getpwuid_r=yes
ac_cv_func_posix_getgrgid_r=yes
glib_cv_working_bcopy=no
ac_cv_type_long_long=yes
glib_cv_has__inline=yes
參數的意義可瀏覽:
https://www.gtk.org/api/2.6/glib/glib-cross-compiling.html
1.3.2、執行configure
./configure --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc --prefix=/home/jimmy/bluez-compile/glib-2.45.3/install_us LIBFFI_CFLAGS="-I/home/jimmy/bluez-compile/libffi-3.2.1/install_us/lib/libffi-3.2.1/include" LIBFFI_LIBS="-lffi -L/home/jimmy/bluez-compile/libffi-3.2.1/install_us/lib" ZLIB_CFLAGS="-I/home/jimmy/bluez-compile/zlib-1.2.8/install_us/include" ZLIB_LIBS="-lz -L/home/jimmy/bluez-compile/zlib-1.2.8/install_us/lib" --cache-file=arm-linux.cache --disable-selinux --disable-xattr --disable-libelf --disable-fam
執行過程中遇到的問題及解答:
Q1:
*** You must have either have gettext support in your C library, or use the
*** GNU gettext library. (http://www.gnu.org/software/gettext/gettext.html
A1:
1)下載和編譯gettext,並把編譯出來的bin目錄加入到環境變量中,比如我上面提到的sh腳本
./configure --prefix=/home/jimmy/bluez-compile/gettext-0.20/install_us --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc
make
make install
2)修改後的configure命令爲
./configure --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc --prefix=/home/jimmy/bluez-compile/glib-2.45.3/install_us LIBFFI_CFLAGS="-I/home/jimmy/bluez-compile/libffi-3.2.1/install_us/lib/libffi-3.2.1/include" LIBFFI_LIBS="-lffi -L/home/jimmy/bluez-compile/libffi-3.2.1/install_us/lib" ZLIB_CFLAGS="-I/home/jimmy/bluez-compile/zlib-1.2.8/install_us/include" ZLIB_LIBS="-lz -L/home/jimmy/bluez-compile/zlib-1.2.8/install_us/lib" LD_LIBRARY_PATH="/home/jimmy/bluez-compile/gettext-0.20/install_us/lib" LDFLAGS="-L/home/jimmy/bluez-compile/gettext-0.20/install_us/lib" --cache-file=arm-linux.cache --disable-selinux --disable-xattr --disable-libelf --disable-fam
Q2:error: Could not find a glib-genmarshal in your PATH
A2:apt-get install libglib2.0-dev
2、DBUS編譯
因爲DBUS的編譯依賴expat,所以我們先編譯expat。
2.1、編譯expat
./configure --prefix=/home/jimmy/bluez-compile/expat-2.2.7/install_us --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc --enable-shared
make
make install
2.2、編譯DBUS
./configure --prefix= --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc CXX=arm-none-linux-gnueabi-g++ --with-xml=expat --without-x LDFLAGS="-L/home/jimmy/bluez-compile/expat-2.2.7/install_us/lib" CFLAGS="-fPIE -I/home/jimmy/bluez-compile/expat-2.2.7/install_us/include/" CPPFLAGS="-I/home/jimmy/bluez-compile/expat-2.2.7/install_us/include/" enable_selinux="no" --disable-tests
make
make install DESTDIR=/home/jimmy/bluez-compile/dbus-1.12.12/install_us
注:
我們可以看到這裏的編譯命令會有所不同,比如執行configure的時候,設置prefix爲空,在make install的時候增加了DESTDIR。這是因爲DBUS編譯出來的bin文件,我需要在ARM板子上執行,如果設置prefix前綴的話,會執行不了,比如二進制想去/lib/路徑找個依賴的so,它會去${prefix}/lib這個路徑去找,而不是/lib/路徑。所以我們應該設置prefix爲空,在make install的時候加上DESTDIR設置臨時目錄,就能解決這個問題了。
3、readline的編譯
3.1、編譯ncurses
export CPPFLAGS="-P"
./configure --prefix=/home/jimmy/bluez-compile/ncurses-5.9/install_us --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc CXX=arm-none-linux-gnueabi-g++
make
make install
3.2、編譯readline
./configure --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc --prefix=/home/jimmy/bluez-compile/readline-8.0/install_us bash_cv_wcwidth_broken=yes
make SHLIB_LIBS=-lncurses
make install
Q1:make SHLIB_LIBS=-lncurses 的時候報錯
/home/jimmy/bluez-compile/arm-2014.05/bin/../lib/gcc/arm-none-linux-gnueabi/4.8.3/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -lncurses
collect2: error: ld returned 1 exit status
make[1]: *** [libreadline.so.8.0] Error 1
make[1]: Leaving directory `/home/jimmy/bluez-compile/readline-8.0/shlib'
make: *** [shared] Error 2
A1:
將編譯出來的libncurses.a放到工具鏈的/home/jimmy/bluez-compile/arm-2014.05/arm-none-linux-gnueabi/libc/usr/lib目錄
4、libical編譯
注意:libical編譯與上述依賴庫的編譯體系不同,它採用的是cmake編譯方式,首先服務器要安裝3.14以上的版本才能編譯。
服務器更新到:
jimmy@ubuntu$ cmake --version
cmake version 3.14.3
編譯過程:
libical-2.0.0$mkdir build && cd build
libical-2.0.0$export CC=arm-none-linux-gnueabi-gcc;export CXX=arm-none-linux-gnueabi-g++
#將工具鏈libstdc++庫文件拷貝到build,否則下面編譯可能會報錯
libical-2.0.0$cmake -DCMAKE_INSTALL_PREFIX=/home/jimmy/bluez-compile/libical-3.0.4/build -DCMAKE_BUILD_TYPE=Release -DSHARED_ONLY=yes
libical-2.0.0$make && make install
5、bluez的編譯
5.1、copy所有依賴庫的pkg文件到一個公共的路徑並設置爲全局變量
export PKG_CONFIG_PATH=/home/jimmy/bluez-compile/pkgconfig:$PKG_CONFIG_PATH
這樣做的好處是不用在configure中填寫一堆-L -I
5.2、配置
./configure --prefix= --sysconfdir=/home/jimmy/bluez-compile/bluez-5.47/install_us/etc --localstatedir=/home/jimmy/bluez-compile/bluez-5.47/install_us/var --enable-experimental --with-systemdsystemunitdir=/home/jimmy/bluez-compile/bluez-5.47/install_us/ll_lib/systemd/system --with-systemduserunitdir=/home/jimmy/bluez-compile/bluez-5.47/install_us/ll_usr/lib/systemd -enable-tools --enable-debug --enable-test --disable-udev --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc --enable-library --enable-shared=yes --enable-network --enable-health --enable-cups --enable-threads --enable-pie --enable-deprecated
其中,--enable-deprecated 這個選項可以編譯出hciconfig和hciattach等工具。參考連接:https://blog.csdn.net/luotong86/article/details/38094425
Q1:error: readline header files are required
A1:
1)sudo apt-get install libreadline-dev
2)如果第一步還不行,就將宿主機的/usr/include/readline整個目錄拷貝到自己的arm-linux的編譯器的usr/include目錄:cp /usr/include/readline/* bluez-compile/arm-2014.05/arm-none-linux-gnueabi/libc/usr/include/readline
5.3、編譯
make
Q1:ld: cannot find -lreadline
A1:把編譯好的readline庫拷貝到編譯工具鏈的usr/lib目錄下
make install DESTDIR=/home/jimmy/bluez-compile/bluez-5.47/install_us
測試
在測試前,先了解一下概念:
dbus-daemon是一個後臺進程,負責消息的轉發。它就像個路由器。最常見的基於dbus的程序也是符合C/S結構的。比如我們自己寫了兩個程序,A和B,其中A是客戶,B是服務。假設A要調用B的一個函數C,那麼實際的消息流動方向是:A告訴dbus-daemon我要調用B的C函數,然後dbus-daemon則去調用B的C函數,如果C有返回值的話,B會把返回值告訴dbus-daemon,然後dbus-daemon再把返回值告訴A。由此可以看出,dbus-daemon是很關鍵的一個後臺進程。
1、創建DBUS服務
#dbus-daemon --system --print-pid --print-address
執行後可能會報的錯:
Q1:
# dbus-daemon --system --print-pid --print-address
dbus-daemon: /mnt/app/lib/libdbus-1.so.3: version `LIBDBUS_PRIVATE_1.12.12' not found (required by dbus-daemon)
A1:
導入DBUS編譯出來的libdbus-1.so.3.19.9,並重新創建軟鏈接:
ln -svf libdbus-1.so.3.19.9 libdbus-1.so.3
還不行的話,重新拷貝文件和重啓幾次。。。(我就是這麼成功運行的)
Q2:
# dbus-daemon --system --print-pid --print-address
dbus[3066]: Failed to start message bus: Failed to open "/share/dbus-1/system.conf": No such file or directory
A2:
手動創建/share/dbus-1/,並導入system.conf
Q3:
# dbus-daemon --system --print-pid --print-address
dbus-daemon[3076]: Failed to start message bus: Failed to bind socket "/var/run/dbus/system_bus_socket": No such file or directory
A3:
手動創建/var/run/dbus目錄,然後再執行會報下面的錯:
# dbus-daemon --system --print-pid --print-address
unix:path=/var/run/dbus/system_bus_socket,guid=56ffdd41a4365304d3346656586868bc
dbus-daemon[2824]: Failed to start message bus: Could not get UID and GID for username "messagebus"
按照網上的說法(http://www.makaidong.com/%E5%8D%9A%E5%AE%A2%E5%9B%AD%E7%83%AD/26458.shtml):
通過添加用戶解決 adduser messagebus 密碼設爲dbus。
注:其實這一步出錯,主要是我的系統在啓動過程中,沒有在啓動腳本rcS裏面執行dbus-daemon命令,如果正確執行,是不會出現這個問題的。
2、查看system bus上面掛載的service
注:這步不是必須的,不過可以看到我們成功掛載我們的服務沒有
dbus-send --system --type=method_call --print-reply --dest=org.freedesktop.DBus / org.freedesktop.DBus.Introspectable.Introspect
3、啓動bluetoothd
# bluetoothd -n -d &
Q1:有以下報錯
# bluetoothd[2856]: Bluetooth daemon 5.47
D-Bus setup failed: Connection ":1.3" is not allowed to own the service "org.bluez" due to security policies in the configuration file
bluetoothd[2856]: Unable to get on D-Bus
A1:
參考鏈接:http://blog.sina.com.cn/s/blog_7cedb56d0102v0r3.html
將dbus編譯出來的dbus-1.12.12/install_us/etc/dbus-1/system.d/bluetooth.conf拷貝到板子的/etc/dbus-1/system.d目錄
4、加載固件
1)將rtl8761a_config和rtl8761a_fw導入到/lib/firmware/rtlbt
2)先手動將藍牙的Reset引腳復位一下,這個是調試時候用的,正式版本會在kernel裏面做復位動作
# echo 0 > /sys/class/rfkill/rfkill0/state
# echo 1 > /sys/class/rfkill/rfkill0/state
3)rtk_hciattach -n -s 115200 ttyS1 rtk_h5
5、連接藍牙設備
5.1、用bluetoothctl工具使能板子上的藍牙
# bluetoothctl
[bluetooth]# power on
[bluetooth]#agent on
[bluetooth]#default-agent
或者使用hciconfig 工具,命令爲 hciconfig hci0 up。建議使用 bluetoothctl 使能藍牙
Q1:
# bluetoothctl
bluetoothctl: error while loading shared libraries: libreadline.so.8: cannot open shared object file: No such file or directory
A1:
將readline-8.0編譯出來的libreadline.so.8.0導入/mnt/app/lib,並創建軟鏈接:ln -svf libreadline.so.8.0 libreadline.so.8
5.2、上電
查看控制器的 Power 是否爲 yes,如果 Power 爲 no,則運行 power on
[bluetooth]# show
Controller 00:E0:4C:23:99:87
Name: BlueZ 5.47
Alias: BlueZ 5.47
Class: 0x00000000
Powered: yes
Discoverable: no
Pairable: yes
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
Modalias: usb:v1D6Bp0246d052F
Discovering: no
[bluetooth]#
5.3、連接藍牙音箱
5.3.1、啓動掃描
[bluetooth]# scan on
Discovery started
[CHG] Controller 00:E0:4C:23:99:87 Discovering: yes
[NEW] Device E0:B6:55:4E:F2:5F MI BT18
...
[bluetooth]# scan off
5.3.2、信任
[bluetooth]# trust E0:B6:55:4E:F2:5F
[CHG] Device E0:B6:55:4E:F2:5F Trusted: yes
Changing E0:B6:55:4E:F2:5F trust succeeded
5.3.3、配對
[bluetooth]# pair E0:B6:55:4E:F2:5F
Attempting to pair with E0:B6:55:4E:F2:5F
[CHG] Device E0:B6:55:4E:F2:5F Connected: yes]#
[CHG] Device E0:B6:55:4E:F2:5F Modalias: bluetooth:v05D6p000Ad0240
[CHG] Device E0:B6:55:4E:F2:5F UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device E0:B6:55:4E:F2:5F UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device E0:B6:55:4E:F2:5F UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device E0:B6:55:4E:F2:5F UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device E0:B6:55:4E:F2:5F UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device E0:B6:55:4E:F2:5F UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device E0:B6:55:4E:F2:5F ServicesResolved: yes
[CHG] Device E0:B6:55:4E:F2:5F Paired: yes
Pairing successful
5.3.4、連接
[bluetooth]# connect E0:B6:55:4E:F2:5F
Attempting to connect to E0:B6:55:4E:F2:5F
Failed to connect: org.bluez.Error.Failed
a2dp-sink profile connect failed for E0:B6:55:4E:F2:5F: Protocol not available
但是連接失敗了,從打印來看,沒有支持的profile。搜了資料我們還需要移植bluez-alsa,下面我們就來交叉編譯我們的bluez-alsa。
編譯bluez-alsa
bluez-alsa的執行需要依賴一些庫文件,我們先編譯這些依賴的文件先。
1、編譯libsndfile-1.0.28
./configure --prefix=/home/jimmy/bluez-compile/bluez-alsa/libsndfile-1.0.28/install_us --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc
make
make install
2、編譯fdk-aac
./configure --prefix=/home/jimmy/bluez-compile/bluez-alsa/fdk-aac-2.0.0/install_us --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc
make
make install
3、編譯sbc
./configure --prefix=/home/jimmy/bluez-compile/bluez-alsa/sbc-1.3/install_us --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc
make
make install
4、編譯alsa-lib
./configure --prefix= --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc
make
make install DESTDIR=/home/jimmy/bluez-compile/bluez-alsa/alsa-lib-1.1.9/install_us
5、編譯bluez-alsa
autoreconf --install
./configure --prefix=/home/jimmy/bluez-compile/bluez-alsa/bluez-alsa/install_us --enable-aac --enable-debug --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc
make
make install
編譯中遇到的問題:
Q1:
../../src/shared/dbus-client.h:15:33: fatal error: bluetooth/bluetooth.h: No such file or directory
A1:
如果PKG_CONFIG_PATH已經設置了,很有可能是工具鏈沒有找到依賴的文件,需要把bluez編譯出來的include/bluetooth整個目錄拷貝到你的工具鏈對應的include目錄下。
Q2:
cannot find -lbluetooth
collect2: error: ld returned 1 exit status
A2:
把bluez編譯出來的lib庫都拷貝到工具鏈的libc/usr/lib目錄下
6、編譯alsa-utils-1.1.9
後續在調試音頻時,會用到aplay工具,所以這裏編譯一下alsa-utils工具。因爲交叉編譯alsa-utils默認會生成alsamixer,此時會用到ncurses,但即使交叉編譯了ncurses庫並加入alsa-utils調用路徑,問題仍然存在,所以暫時不編譯alsamixer。
./configure --prefix= --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc CFLAGS="-I/home/jimmy/bluez-compile/bluez-alsa/alsa-lib-1.1.9/install_us/include" LDFLAGS="-L/home/jimmy/bluez-compile/bluez-alsa/alsa-lib-1.1.9/install_us/lib -lasound" --disable-alsamixer --disable-xmlto
make
make install DESTDIR=/home/jimmy/bluez-compile/bluez-alsa/alsa-utils-1.1.9/install_us
編譯中遇到的問題:
Q1:
make[2]: Entering directory `/home/jimmy/bluez-compile/bluez-alsa/alsa-utils-1.1.9/alsaconf/po'
mv: cannot stat ‘t-ja.gmo’: No such file or directory
make[2]: *** [ja.gmo] Error 1
A1:
touch alsaconf/po/t-ja.gmo
注意:根據自己的錯誤提示來輸入命令
如果提示是t-ru.gmo的話,就用命令:touch alsaconf/po/t-ru.gmo
如果提示是t-ja.gmo的話,就用命令:touch alsaconf/po/t-ja.gmo
值得注意的地方是:如果還是報錯,那就make clean一下
避免之後make報錯
參考鏈接:https://www.cnblogs.com/lifan3a/articles/5563049.html
7、拉起ALSA服務
二進制由bluez-alsa編譯出來
# ./bluealsa
執行中可能遇到的問題:
Q1:
./bluealsa: error while loading shared libraries: libbluetooth.so.3: cannot open shared object file: No such file or directory
A1:將bluez-5.47編譯出來的libbluetooth.so.3.18.16導入板子
# wget http://192.168.1.13/libbluetooth.so.3.18.16
# ln -svf libbluetooth.so.3.18.16 libbluetooth.so.3
'libbluetooth.so.3' -> 'libbluetooth.so.3.18.16'
Q2:
./bluealsa: error while loading shared libraries: libgio-2.0.so.0: cannot open shared object file: No such file or directory
A2:將glib-2.45.3編譯出來的libgio-2.0.so.0.4503.0導入板子
# ln -svf libgio-2.0.so.0.4503.0 libgio-2.0.so.0
Q3:
./bluealsa: error while loading shared libraries: libgobject-2.0.so.0: cannot open shared object file: No such file or directory
A3:將glib-2.45.3編譯出來的libgobject-2.0.so.0.4503.0導入板子
# ln -svf libgobject-2.0.so.0.4503.0 libgobject-2.0.so.0
Q4:
./bluealsa: error while loading shared libraries: libfdk-aac.so.2: cannot open shared object file: No such file or directory
A4:將fdk-aac-2.0.0編譯出來的libfdk-aac.so.2.0.0導入板子
# ln -svf libfdk-aac.so.2.0.0 libfdk-aac.so.2
Q5:
./bluealsa: error while loading shared libraries: libsbc.so.1: cannot open shared object file: No such file or directory
A5:
將sbc-1.3編譯出來的libsbc.so.1.2.1導入板子
# ln -svf libsbc.so.1.2.1 libsbc.so.1
Q6:
./bluealsa: error while loading shared libraries: libgmodule-2.0.so.0: cannot open shared object file: No such file or directory
A6:將glib-2.45.3編譯出來的libgmodule-2.0.so.0.4503.0導入板子
# ln -svf libgmodule-2.0.so.0.4503.0 libgmodule-2.0.so.0
Q7:
./bluealsa: bluez.c:803: Registering endpoint: /org/bluez/hci0/A2DP/MPEG24/Source/1
./bluealsa: bluez.c:803: Registering endpoint: /org/bluez/hci0/A2DP/SBC/Source/1
./bluealsa: ba-adapter.c:134: Freeing adapter: hci0
./bluealsa: bluez.c:1066: Registering profile: /org/bluez/HSP/AudioGateway
./bluealsa: bluez.c:1066: Registering profile: /org/bluez/HFP/AudioGateway
./bluealsa: main.c:328: Acquiring D-Bus service name: org.bluealsa
./bluealsa: main.c:333: Starting main dispatching loop
./bluealsa: Couldn't acquire D-Bus name: org.bluealsa
./bluealsa: main.c:337: Exiting main loop
A7:
參考官方鏈接:https://github.com/Arkq/bluez-alsa/blob/master/README.md
It is not possible to run more than one instance of the BlueALSA server per D-Bus interface. If one tries to run second instance, it will fail with the "Couldn't acquire D-Bus name: org.bluealsa" error message. This message might also appear when D-Bus policy does not allow acquiring "org.bluealsa" name for a particular user - by default only root is allowed to start BlueALSA server.
所以,在/etc/dbus-1/system.d/bluetooth.conf添加org.bluealsa的服務:
<policy user="root">
...
<allow own="org.bluealsa"/>
<allow send_destination="org.bluealsa"/>
</policy>
8、播放音頻
aplay -D bluealsa:HCI=hci0,DEV=E0:B6:55:4E:F2:5F,PROFILE=a2dp becauseoflove.wav
執行過程中可能遇到的問題:
Q1:
ALSA lib conf.c:3956:(snd_config_update_r) Cannot access file /share/alsa/alsa.conf
A1:
將alsa-lib-1.1.9編譯出來的share/alsa/alsa.conf導入板子
Q2:
ALSA lib pcm.c:2564:(snd_pcm_open_noupdate) Unknown PCM bluealsa:HCI=hci0,DEV=E0:B6:55:4E:F2:5F,PROFILE=A2DP
aplay: main:828: audio open error: No such file or directory
A2:
這個問題搜索了很多資料和參考了其他同事的文檔,有的做法如下:
需要加個配置,默認爲F0:13:C3:A7:60:D1地址的音箱播放
alsa配置:
主入口:/usr/share/alsa/alsa.conf
# vi /etc/asound.conf
pcm.!default {
type plug
slave.pcm {
type bluealsa
device "E0:B6:55:4E:F2:5F"
profile "a2dp"
}
hint {
show on
description "BT Speaker"
}
}
但是在我的平臺卻還是不行,所以我直接執行下面的命令:
aplay becauseoflove.wav
有以下的報錯:
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /lib/alsa-lib/libasound_module_pcm_bluealsa.so ((null): /lib/alsa-lib/libasound_module_pcm_bluealsa.so: cannot open shared object file: No such file or directory)
aplay: main:828: audio open error: No such device or address
所以我按照提示,導入/lib/alsa-lib/libasound_module_pcm_bluealsa.so。再執行命令就能正常播放了。
不過上面的asound.conf配置還是要改的,不同的音箱需要修改MAC地址,調試階段暫時這麼做。
結語
移植的過程中,真的會遇到很多很多的問題,幾乎很多是靠搜索的,有的連搜索都找不到,所以我也想將我的經驗分享出來,希望也能幫忙大家,也當作給自己做過筆記吧。