基于MX6ULL的蓝牙协议栈bluez移植


前言

开发板集成了 wifi&bt 模块(AP6275S),测试该模块的 bluetooth 蓝牙功能。


原理图wifi&bt模块
在这里插入图片描述
软件平台:Ubuntu 20.04.4 LTS
硬件平台: NXP 公司的 i.MX6ULL

一、bluez5.47编译

编译之前需要交叉编译工具链,及环境配置,路径根据自己环境配置

#!/bin/sh
 export PKG_CONFIG_PATH=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/pkgconfig:$PKG_CONFIG_PATH
 export PATH=/home/cyzhangep/workspace/6ull_41/toolchain/gcc-linaro-4.9.4-2017.01-i686_arm-linux-gnueabihf/bin:$PATH

1.相关库编译

1.编译zlib

cd zlib-1.2.8
mkdir install_us
host=arm-linux prefix=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/zlib-1.2.8/install_us CC=arm-linux-gnueabihf-gcc ./configure --shared
make
make install

2.编译libffi

cd libffi-3.2.1
mkdir install_us
./configure --host=arm-linux  --prefix=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/libffi-3.2.1/install_us CC=arm-linux-gnueabihf-gcc
make
make install
cd ..

3.编译glib

cd glib-2.45.3
mkdir install_us
echo ac_cv_type_long_long=yes>arm-linux.cache
echo glib_cv_stack_grows=no>>arm-linux.cache
echo glib_cv_uscore=no>>arm-linux.cache
echo ac_cv_func_posix_getpwuid_r=yes>>arm-linux.cache
echo ac_cv_func_posix_getgrgid_r=yes>>arm-linux.cache

./configure  --host=arm-linux  --prefix=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/glib-2.45.3/install_us CC=arm-linux-gnueabihf-gcc LIBFFI_CFLAGS="-I/home/cyzhangep/workspace/6ull_41/dbus_zzy1/libffi-3.2.1/install_us/lib/libffi-3.2.1/include" LIBFFI_LIBS="-lffi -L/home/cyzhangep/workspace/6ull_41/dbus_zzy1/libffi-3.2.1/install_us/lib" ZLIB_CFLAGS="-I/home/cyzhangep/workspace/6ull_41/dbus_zzy1/zlib-1.2.8/install_us/include" ZLIB_LIBS="-lz -L/home/cyzhangep/workspace/6ull_41/dbus_zzy1/zlib-1.2.8/install_us/lib" --cache-file=arm-linux.cache --disable-selinux --disable-xattr --disable-libelf --disable-fam

make
make install
cd ..

4.编译expat

cd expat-2.2.7
mkdir install_us
make clean
./configure  --prefix=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/expat-2.2.7/install_us --host=arm-linux CC=arm-linux-gnueabihf-gcc --enable-shared
make
make install
cd ..

5.编译dbus

cd dbus-1.6.16
mkdir install_us
# echo ac_cv_have_abstract_sockets=yes>arm-linux.cache
./configure --prefix= --host=arm-linux CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++   --with-xml=expat --without-x LDFLAGS="-L/home/cyzhangep/workspace/6ull_41/dbus_zzy1/expat-2.2.7/install_us/lib"   CFLAGS="-fPIE -I/home/cyzhangep/workspace/6ull_41/dbus_zzy1/expat-2.2.7/install_us/include/" enable_selinux="no" --disable-tests #--cache-file=arm-linux.cache
 
make
make install DESTDIR=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/dbus-1.6.16/install_us
cd ..

6.编译ncurses

cd ncurses-5.9
mkdir install_us
export CPPFLAGS="-P"
./configure --prefix=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/ncurses-5.9/install_us --host=arm-linux CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ CFLAGS="-fPIC"

make
make install
unset CPPFLAGS
cd ..

7.编译readline

cd readline-6.0
mkdir install_us
make clean
./configure  --host=arm-linux  CC=arm-linux-gnueabihf-gcc --prefix=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/readline-6.0/install_us bash_cv_wcwidth_broken=yes CFLAGS="-fPIC"  LDFLAGS="-L/home/cyzhangep/workspace/6ull_41/dbus_zzy1/ncurses-5.9/install_us/lib"
make SHLIB_LIBS=-lncurses
# make 
make install
cd ..
ldconfig

8.编译libical

cd libical-0.43
mkdir install_us
./configure --prefix=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/libical-0.43/install_us --host=arm-linux  CC=arm-linux-gnueabihf-gcc

make
make install
cd ..

9.编译bluez

mkdir pkgconfig
cp -r /home/cyzhangep/workspace/6ull_41/dbus_zzy1/dbus-1.6.16/install_us/lib/pkgconfig/dbus-1.pc ./pkgconfig
cp -r /home/cyzhangep/workspace/6ull_41/dbus_zzy1/expat-2.2.7/install_us/lib/pkgconfig/expat.pc ./pkgconfig
cp -r /home/cyzhangep/workspace/6ull_41/dbus_zzy1/glib-2.45.3/install_us/lib/pkgconfig/*        ./pkgconfig
cp -r /home/cyzhangep/workspace/6ull_41/dbus_zzy1/libffi-3.2.1/install_us/lib/pkgconfig/libffi.pc ./pkgconfig
# cp -r /home/cyzhangep/workspace/6ull_41/dbus_zzy1/readline-8.0/install_us/lib/pkgconfig/readline.pc ./pkgconfig
cp -r /home/cyzhangep/workspace/6ull_41/dbus_zzy1/zlib-1.2.8/install_us/lib/pkgconfig/*          ./pkgconfig
cp -r /home/cyzhangep/workspace/6ull_41/dbus_zzy1/libical-0.43/install_us/lib/pkgconfig/libical.pc ./pkgconfig
cd bluez-5.47
make clean
./configure --prefix= --sysconfdir=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/bluez-5.47/install_us/etc --localstatedir=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/bluez-5.47/install_us/var --enable-experimental --with-systemdsystemunitdir=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/bluez-5.47/install_us/ll_lib/systemd/system --with-systemduserunitdir=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/bluez-5.47/install_us/ll_usr/lib/systemd --enable-tools  --enable-debug --enable-test --disable-udev --host=arm-linux CC=arm-linux-gnueabihf-gcc  CFLAGS="-I/home/cyzhangep/workspace/6ull_41/dbus_zzy1/readline-6.0/install_us/include -I/home/cyzhangep/workspace/6ull_41/dbus_zzy1/dbus-1.6.16/install_us/include/dbus-1.0/  -I/home/cyzhangep/workspace/6ull_41/dbus_zzy1/libical-0.43/install_us/include/"  LDFLAGS="-L/home/cyzhangep/workspace/6ull_41/dbus_zzy1/readline-6.0/install_us/lib -L/home/cyzhangep/workspace/6ull_41/dbus_zzy1/ncurses-5.9/install_us/lib -L/home/cyzhangep/workspace/6ull_41/dbus_zzy1/dbus-1.6.16/install_us/lib" --enable-library  --enable-shared=yes --enable-network --enable-health  --enable-cups  --enable-threads --enable-pie --enable-deprecated --enable-client #--disable-client 

make LIBS=-lncurses
make install DESTDIR=/home/cyzhangep/workspace/6ull_41/dbus_zzy1/bluez-5.47/install_us

编译结束,工具及库在相应的install_us目录下,拷贝到板卡

二、使用步骤

1.测试脚本

如下:

#!/bin/sh
echo "statr config bt......"

export PATH=/sbin/:$PATH
export DBUS_SESSION_BUS_ADDRESS=unix:path=/var/run/dbus/system_bus_socket
brcm_patchram_plus -d --enable_hci --no2bytes --tosleep 115200 --baudrate 115200 --patchram /lib/firmware/BCM4362A2_001.003.006.1100.1189.hcd --bd_addr 11:22:33:44:55:66 /dev/ttymxc2 &

groupadd -g 3065 messagebus -p x
useradd  -d '/var/lib/dbus/' -g messagebus  -s /bin/false messagebus -p x
groupadd lp -p x
useradd  -d '/var/spool/lpd' -g lp  -s /bin/sh lp -p x
dbus-uuidgen --ensure
dbus-daemon --system --print-pid --print-address
mkdir -p  /home/
# eval dbus-launch --sh-syntax
export $(dbus-launch)
/libexec/bluetooth/bluetoothd -n -d &

2.bluetoothctl工具

bluetoothctl  //打开 bluez 蓝牙工具

power on  //启动蓝牙设备

pairable on //设置为配对模式

discoverable on  //设置为可发现模式

agent on  //启动代理

default-agent  //设置当前代理为默认
//打开手机配对

参考:
https://blog.youkuaiyun.com/weixin_43982460/article/details/116014460
https://blog.youkuaiyun.com/gatieme/article/details/48751743
https://blog.youkuaiyun.com/lee_jimmy/article/details/96739656


总结

移植的过程中,遇到很多很多的问题,主要是搜索,请教同事,结束后将我的经验分享出来,互相学习,也当作记录。

移植过程遇到的错误
地址:https://download.youkuaiyun.com/download/joy_dsp/90277540
当时写了个bluez错误问题记录,里面有相关库下载路径,错误情况以及解决方法,没有整理比较乱建议,搜索查看。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值