Bluetooth開發環境的搭建

一、修改 Linux 內核

1、cd /arm2410s/kernel-2410s

2、make menuconfig(如報錯,先安裝 libncurses5-dev 即可)

3、加載 2410s-1.5-2005-9-4.config 配置文件(可見該內核已經支持bluetooth,所以直接保存退出即可)

4、make dep

5、make zImage

6、編譯完成的內核在 /arm2410s/kernel-2410s/arch/arm/boot 目錄下,將該內核燒進開發板


二、交叉編譯 bluez 及相關庫

1、下載:bluez-libs-3.36 和 bluez-utils-3.36  glib-2.12.12  libsndfile-1.0.17  libusb-0.1.1  dbus-1.0.2  libxml2-2.6.11
   
    相關依賴關係:    bluez-utils-3.36 依賴:glib-2.12.12  libsndfile-1.0.17  libusb-0.1.12  dbus-1.0.2
                       
                glib-2.12.12 依賴:libxml2-2.6.11

2、交叉編譯 bluez-libs-3.36

(1)./configure --prefix=/root/bluez_install/bluez-libs-3.36 --host=arm-linux

    (運行:make、make install,下同)

(2)將 /root/bluez_install/bluez-libs-3.36/lib/pkgconfig/bluez.pc 複製到 /usr/lib/pkgconfig

    在 /root/bluez_install/bluez-libs-3.36/lib 下將生成 libbluetooth.so.2.11.2,將該庫拷貝到開發板 /mnt/yaffs/lib 目錄下並建立連接

    ln -s libbluetooth.so.2.11.2 libbluetooth.so
    ln -s libbluetooth.so.2.11.2 libbluetooth.so.1
    ln -s libbluetooth.so.2.11.2 libbluetooth.so.2

    此時 藍牙已經可以啓動,初始化等過程正常進行

3、交叉編譯 bluez 工具接口庫

(1)交叉編譯 libxml2-2.6.11

./configure --prefix=/root/bluez_install/libxml2-2.6.11 --host=arm-linux CC=arm-linux-gcc

    將 /root/bluez_install/libxml2-2.6.11/lib/pkgconfig/libxml-2.0.pc 複製到 /usr/lib/pkgconfig

(2)交叉編譯 glib-2.12.12

主機安裝 gettext

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

./configure --prefix=/root/bluez_install/glib-2.12.12 --host=arm-linux CC=arm-linux-gcc --cache-file=arm-linux.cache

    若報錯:error: Could not find a glib-genmarshal in your PATH,先在主機安裝 libglib2.0-dev
   
    將 /root/bluez_install/glib-2.12.12/lib/pkgconfig 下的 glib-2.0.pc、gmodule-2.0.pc、gmodule-export-2.0.pc、gmodule-no-export-2.0.pc、gobject-2.0.pc、gthread-2.0.pc 複製到 /usr/lib/pkgconfig

(3)交叉編譯 libsndfile-1.0.17

./configure --prefix=/root/bluez_install/libsndfile-1.0.17 --host=arm-linux CC=arm-linux-gcc

    將 /root/bluez_install/libsndfile-1.0.17/lib/pkgconfig/sndfile.pc 複製到 /usr/lib/pkgconfig

(4)交叉編譯 libusb-0.1.12

./configure --prefix=/root/bluez_install/libusb-0.1.12 --host=arm-linux CC=arm-linux-gcc

    將 /root/bluez_install/libusb-0.1.12/lib/pkgconfig/libusb.pc 複製到 /usr/lib/pkgconfig

(5)交叉編譯 dbus-1.0.2

echo ac_cv_have_abstract_sockets=yes > arm-linux.cache

./configure --prefix=/root/bluez_install/dbus-1.0.2 --host=arm-linux CC=arm-linux-gcc --cache-file=arm-linux.cache --without-x

    將 /root/bluez_install/dbus-1.0.2/lib/pkgconfig/dbus-1.pc 複製到 /usr/lib/pkgconfig

(6)交叉編譯 bluez-utils-3.36

主機安裝 libbluetooth-dev libcwiid1

在 bluez-utils-3.36/network/bridge.h 中添加宏定義:

    #define SIOCBRADDBR     0x89a0          /* create new bridge device     */
    #define SIOCBRDELBR     0x89a1          /* remove bridge device         */
    #define SIOCBRADDIF     0x89a2          /* add interface to bridge      */
    #define SIOCBRDELIF     0x89a3          /* remove interface from bridge */

在 bluez-utils-3.36/input/storage.c 中添加宏定義:

    #define ENOKEY 161

./configure --prefix=/root/bluez_install/bluez-utils-3.36 --host=arm-linux CC="arm-linux-gcc -I/root/bluez_install/bluez-libs-3.36/include -L/root/bluez_install/bluez-libs-3.36/lib" --disable-audio

    注:(1)當編譯 bluez-utils-3.36 時,通常會出現找不到頭文件或庫,例如 bluetooth.h 等,因此需在 configure 時指明頭文件和庫的地址
   
    (2)--disable-audio 選項是爲了避免 make 時出現 audio 模塊的錯誤,此錯誤如下:
   
    test -f lexer.c || /bin/bash ../ylwrap lexer.l .c lexer.c -- /bin/bash /root/armbluetooth/source/blue-install/bluez-utils-3.36/missing --run flex
    make[2]: *** [lexer.c] 錯誤 1
   
make 時出現錯誤:

make[2]: Entering directory `/home/blueZ/bluez-utils-3.36/sbc'
/bin/sh ../libtool --tag=CC   --mode=link arm-linux-gcc -I/usr/local/arm/3.4.1/arm-linux/include   -Wall -O2 -D_FORTIFY_SOURCE=2 -fPIE  -pie -o sbcinfo sbcinfo.o
arm-linux-gcc -I/usr/local/arm/3.4.1/arm-linux/include -Wall -O2 -D_FORTIFY_SOURCE=2 -fPIE -pie -o sbcinfo sbcinfo.o
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/lib/libc_nonshared.a(elf-init.oS)(.text+0x44): In function `__libc_csu_init':
: undefined reference to `__init_array_end'
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/lib/libc_nonshared.a(elf-init.oS)(.text+0x48): In function `__libc_csu_init':
: undefined reference to `__init_array_start'
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/lib/libc_nonshared.a(elf-init.oS)(.text+0x8c): In function `__libc_csu_fini':
: undefined reference to `__fini_array_end'
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/lib/libc_nonshared.a(elf-init.oS)(.text+0x90): In function `__libc_csu_fini':
: undefined reference to `__fini_array_start'
collect2: ld returned 1 exit status
make[2]: *** [sbcinfo] 錯誤 1
make[2]: Leaving directory `/home/blueZ/bluez-utils-3.36/sbc'
make[1]: *** [all-recursive] 錯誤 1
make[1]: Leaving directory `/home/blueZ/bluez-utils-3.36'
make: *** [all] 錯誤 2

原因:auto 工具生成的 makefile 文件,在鏈接 libc_nonshared.a 時使用 gcc -Wall,正確的用法是 gcc -shared
方法:將 sbc 目錄中 makefile 文件裏的 wall 改爲 shared

爲避免類似錯誤,對所有目錄下 Makefile 文件均做如上修改


三、交叉編譯 openobex 庫

(1)./configure --prefix=/root/bluez_install/openobex-1.3 --host=arm-linux CC="arm-linux-gcc -I/root/bluez_install/bluez-libs-3.36/include -L/root/bluez_install/bluez-libs-3.36/lib" --enable-bluetooth --disable-usb --enable-apps

(2)運行:make

(3)運行:make install
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章