【RV1103/RV1106】使用Buildroot构建文件系统支持Bluetooth--交叉编译Bluez5

文章目录

  • 添加bluez
  • 添加DBUS
    • 保存设置、编译
  • 编译过程中报错
    • 1、ERROR: Automatic wrap-based subproject downloading is disabled
    • bluez5编译时
      • 编译错误1:
    • 编译错误2:
    • 查看一下各个软件的依赖关系
    • 最终的配置
  • 测试
    • hciconfig测试
      • RTL873BS测试
      • AIC8800DW测试
  • 软件工具
    • rfkill 系统射频开关
    • hciconfig
    • hcitool
    • bluetoothctl

Bluez的依赖:

Bluez
glib
dbus
readline
Bluez
libffi
zlib
gettext
libiconv
expat
ncurses

Buildroot源码地址:https://buildroot.org/downloads/buildroot-2023.02.6.tar.gz
Buildroot仓库下载地址:http://sources.buildroot.net

wget https://buildroot.org/downloads/buildroot-2023.02.6.tar.gz
tar xvfz buildroot-2023.02.6.tar.gz
cd buildroot-2023.02.6
make ARCH=arm menuconfig

参考:https://whycan.com/t_10152.html

【RV1103/RV1106】使用Buildroot构建文件系统支持Bluetooth--交叉编译Bluez5_第1张图片【RV1103/RV1106】使用Buildroot构建文件系统支持Bluetooth--交叉编译Bluez5_第2张图片

/home/liefyuan/rv1103/luckfox-pico-main-origin/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf

arm-rockchip830-linux-uclibcgnueabihf

添加bluez

【RV1103/RV1106】使用Buildroot构建文件系统支持Bluetooth--交叉编译Bluez5_第3张图片

添加DBUS

【RV1103/RV1106】使用Buildroot构建文件系统支持Bluetooth--交叉编译Bluez5_第4张图片【RV1103/RV1106】使用Buildroot构建文件系统支持Bluetooth--交叉编译Bluez5_第5张图片【RV1103/RV1106】使用Buildroot构建文件系统支持Bluetooth--交叉编译Bluez5_第6张图片

保存设置、编译

make ARCH=arm menuconfig
make ARCH=arm savedefconfig
make

编译过程中报错

1、ERROR: Automatic wrap-based subproject downloading is disabled

Library iconv found: YES
Found pkg-config: /home/liefyuan/rv1103/luckfox-pico-main-origin/sysdrv/tools/board/buildroot/buildroot-2023.02.6/output/host/bin/pkgconf (1.6.3)
Run-time dependency libpcre found: YES 8.45
Library m found: YES
Run-time dependency libffi found: YES 3.4.4
Run-time dependency zlib found: YES 1.2.13
Checking for function "ngettext" : NO 
Library intl found: NO

output/build/libglib2-2.72.3/meson.build:2102:4: ERROR: Automatic wrap-based subproject downloading is disabled

A full log can be found at /home/liefyuan/rv1103/luckfox-pico-main-origin/sysdrv/tools/board/buildroot/buildroot-2023.02.6/output/build/libglib2-2.72.3/build/meson-logs/meson-log.txt
package/pkg-generic.mk:273: recipe for target '/home/liefyuan/rv1103/luckfox-pico-main-origin/sysdrv/tools/board/buildroot/buildroot-2023.02.6/output/build/libglib2-2.72.3/.stamp_configured' failed
make[1]: *** [/home/liefyuan/rv1103/luckfox-pico-main-origin/sysdrv/tools/board/buildroot/buildroot-2023.02.6/output/build/libglib2-2.72.3/.stamp_configured] Error 1
Makefile:82: recipe for target '_all' failed
make: *** [_all] Error 2

更详细的log

Checking for function "ngettext" : NO
Running compile:
Working directory:  /home/liefyuan/rv1103/luckfox-pico-main-origin/sysdrv/tools/board/buildroot/buildroot-2023.02.6/output/build/libglib2-2.72.3/build/meson-private/tmpq5wyfo6i
Command line:  /home/liefyuan/rv1103/luckfox-pico-main-origin/sysdrv/tools/board/buildroot/buildroot-2023.02.6/output/host/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc /home/liefyuan/rv1103/luckfox-pico-main-origin/sysdrv/tools/board/buildroot/buildroot-2023.02.6/output/build/libglib2-2.72.3/build/meson-private/tmpq5wyfo6i/testfile.c -o /home/liefyuan/rv1103/luckfox-pico-main-origin/sysdrv/tools/board/buildroot/buildroot-2023.02.6/output/build/libglib2-2.72.3/build/meson-private/tmpq5wyfo6i/output.exe -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -Os -g0 -D_FILE_OFFSET_BITS=64 -O0 -Wl,--start-group -lintl -Wl,--end-group -Wl,--allow-shlib-undefined

Code:
 int main(void) { return 0; }

Compiler stdout:

Compiler stderr:
 /home/liefyuan/rv1103/luckfox-pico-main-origin/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/../lib/gcc/arm-rockchip830-linux-uclibcgnueabihf/8.3.0/../../../../arm-rockchip830-linux-uclibcgnueabihf/bin/ld.bfd: cannot find -lintl
collect2: error: ld returned 1 exit status

Library intl found: NO

output/build/libglib2-2.72.3/meson.build:2102:4: ERROR: Automatic wrap-based subproject downloading is disabled

很难找到为什么

https://github.com/mesonbuild/meson/blob/master/mesonbuild/wrap/wrap.py

...
def check_can_download(self) -> None:
        # Don't download subproject data based on wrap file if requested.
        # Git submodules are ok (see above)!
        if self.wrap_mode is WrapMode.nodownload:
            m = 'Automatic wrap-based subproject downloading is disabled'
            raise WrapException(m)
...

解决办法:这几个给他选上。

【RV1103/RV1106】使用Buildroot构建文件系统支持Bluetooth--交叉编译Bluez5_第7张图片

bluez5编译时

编译错误1:

 CC       tools/mpris-proxy.o
src/shared/shell.c:25:10: fatal error: wordexp.h: No such file or directory
 #include 
          ^~~~~~~~~~~
compilation terminated.
Makefile:8020: recipe for target 'src/shared/libshared_mainloop_la-shell.lo' failed
make[3]: *** [src/shared/libshared_mainloop_la-shell.lo] Error 1
make[3]: *** Waiting for unfinished jobs....
Makefile:4358: recipe for target 'all' failed
make[2]: *** [all] Error 2
package/pkg-generic.mk:290: recipe for target '/home/liefyuan/rv1103/luckfox-pico-main/sysdrv/source/buildroot-2023.02.6/output/build/bluez5_utils-5.65/.stamp_built' failed
make[1]: *** [/home/liefyuan/rv1103/luckfox-pico-main/sysdrv/source/buildroot-2023.02.6/output/build/bluez5_utils-5.65/.stamp_built] Error 2
Makefile:82: recipe for target '_all' failed
make: *** [_all] Error 2

buildroot-2023.02.6/output/build/bluez5_utils-5.65$
vim ./src/shared/shell.c

#include
改为:
#include

buildroot-2023.02.6/output/build/bluez5_utils-5.65$ grep -r ""
client/player.c:#include 
client/main.c:#include 
tools/meshctl.c:#include 
tools/mesh-gatt/node.c:#include 
tools/mesh-gatt/gatt.c:#include 
tools/mesh-gatt/onoff-model.c:#include 
tools/mesh-gatt/config-client.c:#include 
tools/mesh-gatt/config-server.c:#include 
tools/mesh-gatt/prov.c:#include 
tools/btmgmt.c:#include 
tools/obexctl.c:#include 

把下面五个改一下就OK了!

src/shared/shell.c:#include 
client/player.c:#include 
client/main.c:#include 
tools/btmgmt.c:#include 
tools/obexctl.c:#include 

编译错误2:

src/shared/shell.c: In function 'cmd_exec':
src/shared/shell.c:419:11: error: 'WRDE_APPEND' undeclared (first use in this function); did you mean 'WRDE_NOCMD'?
  flags |= WRDE_APPEND;
           ^~~~~~~~~~~
           WRDE_NOCMD
src/shared/shell.c:419:11: note: each undeclared identifier is reported only once for each function it appears in
  CC       tools/rctest.o
Makefile:7838: recipe for target 'src/shared/libshared_glib_la-shell.lo' failed
make[3]: *** [src/shared/libshared_glib_la-shell.lo] Error 1
make[3]: *** Waiting for unfinished jobs....
Makefile:4358: recipe for target 'all' failed
make[2]: *** [all] Error 2
package/pkg-generic.mk:290: recipe for target '/home/liefyuan/rv1103/luckfox-pico-main/sysdrv/source/buildroot-2023.02.6/output/build/bluez5_utils-5.65/.stamp_built' failed
make[1]: *** [/home/liefyuan/rv1103/luckfox-pico-main/sysdrv/source/buildroot-2023.02.6/output/build/bluez5_utils-5.65/.stamp_built] Error 2
Makefile:82: recipe for target '_all' failed
make: *** [_all] Error 2

WRDE_APPEND改为:WRDE_NOCMD

/* Check if there are enough arguments */
    if ((unsigned) argc - 1 < w.we_wordc) {
        print_text(COLOR_HIGHLIGHT, "Missing %s argument",
                        w.we_wordv[argc - 1]);
        goto fail;
    }

    //flags |= WRDE_APPEND; // liefyuan commit
    flags |= WRDE_NOCMD;
    opt = strdup(entry->arg + len + 1);

OK编译完毕!

查看一下各个软件的依赖关系

命令:make graph-depends
这需要安装graphviz

sudo apt-get install graphviz

生成在:output/graphs/
【RV1103/RV1106】使用Buildroot构建文件系统支持Bluetooth--交叉编译Bluez5_第8张图片

最终的配置

BR2_arm=y
BR2_cortex_a7=y
BR2_ARM_FPU_NEON_VFPV4=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
BR2_TOOLCHAIN_EXTERNAL_PATH="/home/liefyuan/rv1103/luckfox-pico-main/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf"
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="arm-rockchip830-linux-uclibcgnueabihf"
BR2_TOOLCHAIN_EXTERNAL_GCC_8=y
BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_10=y
BR2_TOOLCHAIN_EXTERNAL_WCHAR=y
BR2_TOOLCHAIN_EXTERNAL_HAS_SSP=y
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_SYSTEM_ENABLE_NLS=y
BR2_PACKAGE_DBUS_CPP=y
BR2_PACKAGE_DBUS_TRIGGERD=y
BR2_PACKAGE_BLUEZ_TOOLS=y
BR2_PACKAGE_BLUEZ5_UTILS=y
BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y
BR2_PACKAGE_BLUEZ5_UTILS_TOOLS=y
BR2_PACKAGE_BLUEZ5_UTILS_DEPRECATED=y
BR2_PACKAGE_BLUEZ5_UTILS_EXPERIMENTAL=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y

把上面保存为xxx_defconfig
我的Buildroot版本是:buildroot-2023.02.6
使用方法:

  • 加载旧配置:make ARCH=arm xxx_defconfig 将会生成.config文件
  • 修改配置:make ARCH=arm menuconfig 修改配置后保存
  • 保存配置(.config):make ARCH=arm savedefconfig 生成defconfig文件
  • 永久保存配置(defconfig):cp defconfig /configs/xxx_v0.2_defconfig 保存

最终生成的文件系统才14.5MB。

测试

使用hciconfig -a 可以查看出蓝牙版本号:

  • 蓝牙版本 4.0 (0x6)
  • 蓝牙版本 4.1 (0x7)
  • 蓝牙版本 4.2 (0x8)
  • 蓝牙版本 5.0 (0x9)
  • 蓝牙版本 5.1 (0xa)
  • 蓝牙版本 5.2 (0xb)
  • 蓝牙版本 5.3 (0xc)
  • 蓝牙版本 5.4 (0xd)

hciconfig测试

RTL873BS测试

下面是RTL8723BS的信息:

  • Bluetooth 4.0
  • 数据总线是 UART
# hciconfig hci0 up
[  657.905172] rtk_btcoex: Open BTCOEX
[  658.161233] Bluetooth: hu 52138c09 retransmitting 1 pkts
[  658.163591] rtk_btcoex: BTCOEX hci_rev 0x373e
[  658.163618] rtk_btcoex: BTCOEX lmp_subver 0x6962
# hciconfig -a
hci0:   Type: Primary  Bus: UART
        BD Address: 84:20:96:B1:4D:92  ACL MTU: 820:8  SCO MTU: 255:16
        UP RUNNING
        RX bytes:2681 acl:0 sco:0 events:75 errors:0
        TX bytes:2407 acl:0 sco:0 commands:78 errors:0
        Features: 0xff 0xff 0xff 0xfe 0xdb 0xfd 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy: RSWITCH HOLD SNIFF PARK
        Link mode: PERIPHERAL ACCEPT
        Name: 'BlueZ 5.65'
        Class: 0x000000
        Service Classes: Unspecified
        Device Class: Miscellaneous,
        HCI Version: 4.0 (0x6)  Revision: 0x373e
        LMP Version: 4.0 (0x6)  Subversion: 0x6962
        Manufacturer: Realtek Semiconductor Corporation (93)

AIC8800DW测试

# hciconfig -a
hci0:   Type: Primary  Bus: USB
        BD Address: E8:51:9E:22:DC:64  ACL MTU: 1021:9  SCO MTU: 255:4
        UP RUNNING
        RX bytes:4890 acl:0 sco:0 events:122 errors:0
        TX bytes:1315 acl:0 sco:0 commands:102 errors:0
        Features: 0xbf 0x2e 0x4d 0xfe 0xd8 0x3f 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV3
        Link policy: RSWITCH SNIFF
        Link mode: PERIPHERAL ACCEPT
        Name: 'BlueZ 5.65'
        Class: 0x000000
        Service Classes: Unspecified
        Device Class: Miscellaneous,
        HCI Version:  (0xd)  Revision: 0xb
        LMP Version:  (0xd)  Subversion: 0xb
        Manufacturer: not assigned (2875)

软件工具

rfkill 系统射频开关

不只是蓝牙,包括WiFi,eth都是通过rfkill来控制的。

echo 1 > /sys/class/rfkill/rfkill2/state # 打开对应的射频设备开关
echo 0 > /sys/class/rfkill/rfkill2/state # 关闭对应的射频设备开关

可以查看各个设备节点信息去确认它是个啥?

# cat /sys/class/rfkill/rfkill0/uevent
RFKILL_NAME=bt_default
RFKILL_TYPE=bluetooth
RFKILL_STATE=0
# cat /sys/class/rfkill/rfkill1/uevent
RFKILL_NAME=phy0
RFKILL_TYPE=wlan
RFKILL_STATE=1
# cat /sys/class/rfkill/rfkill2/uevent
RFKILL_NAME=hci0
RFKILL_TYPE=bluetooth
RFKILL_STATE=0

RFKILL_STATE:其实就是表示他是个什么状态,0就是关闭,1就是打开。
通过echo 0 > /sys/class/rfkill/rfkill2/state来设置对应的状态

hciconfig

对应于WiFi里面的ifconfig,所以可以这么操作:

  • hciconfig hci0 up:打开蓝牙0的开关
  • hciconfig -a:查看所有的蓝牙设备信息

其他的命令:

  • 打开/关闭/重置hci设备:hciconfig hci0 up/down/reset
  • 认证打开/关闭:hciconfig hci0 auth/noauth,直接体现在进行蓝牙连接时,是否输入连接PIN密码,用于PIN配对
  • 查看/改变蓝牙主从状态:hciconfig hci0 lmhciconfig hci0 lm slave
  • 查看/设置蓝牙名称:hciconfig hci0 namehciconfig hci0 name Donge
  • 开启/关闭广播:hciconfig hci0 leadv/ noleadv
  • 查看支持的链路层状态:hciconfig hci0 lestates

hcitool

这个很常用,因为bluetoothctl没有用。

# hcitool -help
hcitool - HCI Tool ver 5.65
Usage:
        hcitool [options] <command> [command parameters]
Options:
        --help  Display help
        -i dev  HCI device
Commands:
        dev     Display local devices
        inq     Inquire remote devices
        scan    Scan for remote devices
        name    Get name from remote device
        info    Get information from remote device
        spinq   Start periodic inquiry
        epinq   Exit periodic inquiry
        cmd     Submit arbitrary HCI commands
        con     Display active connections
        cc      Create connection to remote device
        dc      Disconnect from remote device
        sr      Switch central/peripheral role
        cpt     Change connection packet type
        rssi    Display connection RSSI
        lq      Display link quality
        tpl     Display transmit power level
        afh     Display AFH channel map
        lp      Set/display link policy settings
        lst     Set/display link supervision timeout
        auth    Request authentication
        enc     Set connection encryption
        key     Change connection link key
        clkoff  Read clock offset
        clock   Read local or remote clock
        lescan  Start LE scan
        leinfo  Get LE remote information
        lealadd Add device to LE Accept List
        lealrm  Remove device from LE Accept List
        lealsz  Read size of LE Accept List
        lealclr Clear LE Accept List
        lewladd Deprecated. Use lealadd instead.
        lewlrm  Deprecated. Use lealrm instead.
        lewlsz  Deprecated. Use lealsz instead.
        lewlclr Deprecated. Use lealclr instead.
        lerladd Add device to LE Resolving List
        lerlrm  Remove device from LE Resolving List
        lerlclr Clear LE Resolving List
        lerlsz  Read size of LE Resolving List
        lerlon  Enable LE Address Resolution
        lerloff Disable LE Address Resolution
        lecc    Create a LE Connection
        ledc    Disconnect a LE Connection
        lecup   LE Connection Update

For more information on the usage of each command use:
        hcitool <command> --help

使用:

# hcitool lescan
LE Scan ...
65:CB:01:01:36:A9 (unknown)
73:EA:18:45:5B:94 (unknown)
52:A3:99:59:87:56 (unknown)
45:62:42:A1:1E:B4 (unknown)
2D:98:31:2F:12:6C (unknown)
3F:5B:7D:70:B0:4B (unknown)
63:BC:FD:06:D9:D1 (unknown)
55:28:0A:62:B6:88 (unknown)
56:03:BC:EC:4F:23 (unknown)
54:FA:90:91:81:AC (unknown)
1A:58:FD:49:AD:7A (unknown)
D5:19:20:99:CE:D0 (unknown)
4A:96:02:E4:D4:83 (unknown)
6D:CB:2F:84:52:12 (unknown)
# hcitool scan
Scanning ...
[  850.534585] rtk_btcoex: hci (periodic)inq start
[  860.777952] rtk_btcoex: inquiry complete
        A4:55:90:0F:90:E6       Redmi K40 Pro+

bluetoothctl

这是一个交互命令行,运行该软件后会进入另一个交互命令。不过我不知道为什么我在这个交互命令行里面输入命令它都没有反应。

你可能感兴趣的:(buildroot,嵌入式linux,linux,Bluetooth)