1 驱动源码下载

  驱动源码的下载链接为 https://https://github.com/lwfinger,根据自己实际使用的芯片型号选择合适的驱动代码进行下载克隆。笔者本次使用的芯片型号为 RTL8723BU,因此执行下面的命令进行克隆

git clone https://github.com/lwfinger/rtl8723bu.git

  下载后进入到顶层目录,查看所有文件显示如下:
在这里插入图片描述

2 驱动移植

2.1 源码的拷贝

  将下载好的驱动源码复制到内核的源码中,然后解压缩,并把文件夹名字改短。

// 拷贝源码
cp rtl8723BU_WiFi_linux_v4.3.6.11_12942.20141204_BTCOEX20140507-4E40.tar.gz ~/100ask_imx6ull-sdk/crystal/linux-imx/drivers/net/wireless/realtek/
// 解压缩
tar -xvf rtl8723BU_WiFi_linux_v4.3.6.11_12942.20141204_BTCOEX20140507-4E40.tar.gz
// 修改名字
mv rtl8723BU_WiFi_linux_v4.3.6.11_12942.20141204_BTCOEX20140507-4E40 rtl8723BU_WiFi_linux_v4.3.6.11

2.2 源代码的修改

  移植时参考 Quick Start Guide for Driver Compilation and Installation.pdf 文档,文档下载链接为 https://download.csdn.net/download/qq_36310253/56378817
  进入到源码的顶层目录中

$ cd rtl8723BU_WiFi_linux_v4.3.6.11
$ ls
$ core  hal  include  Kconfig  Makefile  os_dep  platform

  修改目标设备平台打开该目录下的 Makefile 文件,首先修改平台部分代码,如下图所示,本次移植的目标设备为 imx6ull 的开发板,所以讲 I386_PC 的平台修改为n,添加自己的设备平台,名字可以任意取。
在这里插入图片描述
  修改目标平台后,增加编译选项,具体操作如下图所示
在这里插入图片描述

2.3 将wifi 驱动添加到内核中

  进入到内核源码目录的上一层目录,即 realtek 目录

book@100ask:~/100ask_imx6ull-sdk/crystal/linux-imx/drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11$ cd ..
book@100ask:~/100ask_imx6ull-sdk/crystal/linux-imx/drivers/net/wireless/realtek$ ls
built-in.o  Makefile         modules.order  rtl8723BU_WiFi_linux_v4.3.6.11                                            rtl8xxxu
Kconfig     modules.builtin  rtl818x        rtl8723BU_WiFi_linux_v4.3.6.11_12942.20141204_BTCOEX20140507-4E40.tar.gz  rtlwifi
book@100ask:~/100ask_imx6ull-sdk/crystal/linux-imx/drivers/net/wireless/realtek$ 

2.3.1 修改 Kconfig 文件

  修改后如下所示
在这里插入图片描述

2.3.2 修改Makefile

  修改后如下所示
在这里插入图片描述

2.3.3 配置Linux内核

  在内核源码的顶层目录执行 make menuconfig,进入图形配置界面

book@100ask:~/100ask_imx6ull-sdk/crystal/linux-imx/drivers/net/wireless/realtek$ cd ../../../../
book@100ask:~/100ask_imx6ull-sdk/crystal/linux-imx$ make menuconfig

  1 、配置 USB 支持设备,配置路径如下:

-> Device Drivers
  -> <*> USB support
    -> <*> Support for Host-side USB
      -> <*> EHCI HCD (USB 2.0) support
      -> <*> OHCI HCD (USB 1.1) support
      -> <*> ChipIdea Highspeed Dual Role Controller
        -> [*] ChipIdea device controller
        -> [*] ChipIdea host controller

  2 、配置支持 WIFI 设备,配置路径如下:

-> Device Drivers
  -> [*] Network device support
    -> [*] Wireless LAN
      -> <*> IEEE 802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP)
        -> [*] Support downloading firmware images with Host AP driver
        -> [*] Support for non-volatile firmware download

  3 、配置支持 IEEE 802.11,配置路径如下:

-> Networking support
  -> -*- Wireless
    -> [*] cfg80211 wireless extensions compatibility
    -> <*> Generic IEEE 802.11 Networking Stack (mac80211)

  4 、将RTL8723BU编译位模块,配置路径如下:

-> Device Drivers
  -> Network device support (NETDEVICES [=y])
    -> Wireless LAN (WLAN [=y])
      -> Realtek devices [=y]
        -> Realtek 8723B USB WiFi [=M]

2.3.4 编译 RTL8723BU 驱动模块

  在内核顶层目录下执行 make modules 进行驱动模块的的编译

book@100ask:~/100ask_imx6ull-sdk/crystal/linux-imx$ make menuconfig
scripts/kconfig/mconf  Kconfig


*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.

book@100ask:~/100ask_imx6ull-sdk/crystal/linux-imx$ make modules

  没有错误的情况下会在目录下生成 .ko 文件,证明自己编译的没有问题。有错误的情况请继续往下看,笔者列举出了我在编译的过程中产生几个的错误以及解决办法。

3 编译出错解决

  编译报错解决部分笔者参考了 rtl8188驱动移植 wifi工具移植 的文章,在此表示感谢。在编译时出现了该文章中未出现的其他错误,笔者将其进行补充如下。

3.1 _seqdump 错误

  该错误提示的信息如下所示

drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_cmd.c: 在函数‘btinfo_evt_dump’中:
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/include/rtw_debug.h:186:19: 错误: void 值未如预期地被忽略
  #define _seqdump seq_printf
                   ^
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/include/rtw_debug.h:240:7: 附注: in expansion of macro ‘_seqdump’
    if(_seqdump(sel, fmt, ##arg)) /*rtw_warn_on(1)*/; \
       ^~~~~~~~
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_cmd.c:3166:2: 附注: in expansion of macro ‘DBG_871X_SEL_NL’
  DBG_871X_SEL_NL(sel, "cid:0x%02x, len:%u\n", info->cid, info->len);
  ^~~~~~~~~~~~~~~
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/include/rtw_debug.h:186:19: 错误: void 值未如预期地被忽略
  #define _seqdump seq_printf
                   ^
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/include/rtw_debug.h:240:7: 附注: in expansion of macro ‘_seqdump’
    if(_seqdump(sel, fmt, ##arg)) /*rtw_warn_on(1)*/; \
       ^~~~~~~~
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_cmd.c:3169:2: 附注: in expansion of macro ‘DBG_871X_SEL_NL’
  DBG_871X_SEL_NL(sel, "byte2:%s%s%s%s%s%s%s%s\n"
  ^~~~~~~~~~~~~~~
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/include/rtw_debug.h:186:19: 错误: void 值未如预期地被忽略
  #define _seqdump seq_printf
                   ^
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/include/rtw_debug.h:240:7: 附注: in expansion of macro ‘_seqdump’
    if(_seqdump(sel, fmt, ##arg)) /*rtw_warn_on(1)*/; \
       ^~~~~~~~
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_cmd.c:3181:2: 附注: in expansion of macro ‘DBG_871X_SEL_NL’
  DBG_871X_SEL_NL(sel, "retry_cnt:%u\n", info->retry_cnt);
  ^~~~~~~~~~~~~~~

  解决办法:打开WIFI驱动目录下的 include/rtw_debug.h 文件,将_seqdump重新定义为用printk的,参考PLATFORM_FREEBSD的,修改后如下图所示。
在这里插入图片描述
  为了减少打印的信息,可以将宏定义设置为空
在这里插入图片描述

  修改后再次编译 make modules,可能会出现下面的错误。

3.2 DATETIME 错误

  错误提示信息如下所示

drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_debug.c: 在函数‘dump_drv_version’中:
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_debug.c:66:64: 错误: macro "__DATE__" might prevent reproducible builds [-Werror=date-time]
  DBG_871X_SEL_NL(sel, "build time: %s %s\n", __DATE__, __TIME__);
                                                                ^
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_debug.c:66:64: 错误: macro "__TIME__" might prevent reproducible builds [-Werror=date-time]
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_debug.c:66:64: 错误: macro "__DATE__" might prevent reproducible builds [-Werror=date-time]
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_debug.c:66:64: 错误: macro "__TIME__" might prevent reproducible builds [-Werror=date-time]
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_debug.c:66:64: 错误: macro "__DATE__" might prevent reproducible builds [-Werror=date-time]
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_debug.c:66:64: 错误: macro "__TIME__" might prevent reproducible builds [-Werror=date-time]
cc1:有些警告被当作是错误
scripts/Makefile.build:293: recipe for target 'drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_debug.o' failed
make[5]: *** [drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/core/rtw_debug.o] Error 1
scripts/Makefile.build:544: recipe for target 'drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11' failed

  解决办法是打开WIFI驱动源码顶层目录下的Makefile,增加 EXTRA_CFLAGS += -Wno-error=date-time 选项,修改后如下图所示。
在这里插入图片描述
  修改后再次编译 make modules,可能会出现下面的错误。

3.3 strnicmp错误

  错误信息提示如下,错误原因是:在最近的Linux版本中,系统调用 strnicmp 已被弃用并由包装器替换,以便以后删除,以支持 strncasecmp。所以将 strnicmp 修改为 strncasecmp。

drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/os_dep/linux/rtw_android.c: In function ‘rtw_android_cmdstr_to_num’:
drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/os_dep/linux/rtw_android.c:345:11: error: implicit declaration of function ‘strnicmp’; did you mean ‘strncmp’? [-Werror=implicit-function-declaration]
   if(0 == strnicmp(cmdstr , android_wifi_cmd_str[cmd_num], strlen(android_wifi_cmd_str[cmd_num])) )
           ^~~~~~~~
           strncmp
cc1: some warnings being treated as errors
scripts/Makefile.build:293: recipe for target 'drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/os_dep/linux/rtw_android.o' failed

  修改如下:
在这里插入图片描述
  修改后再次编译 make modules,可能会出现下面的错误。

3.4 file_path相关错误

  错误信息提示如下

drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/hal/hal_com_phycfg.c:2583:6: 错误: ‘file_path’被重新声明为不同意义的符号
 char file_path[PATH_LENGTH_MAX];
      ^~~~~~~~~
In file included from ./include/linux/seq_file.h:10:0,
                 from ./include/linux/pinctrl/consumer.h:17,
                 from ./include/linux/pinctrl/devinfo.h:21,
                 from ./include/linux/device.h:24,
                 from ./include/linux/dmaengine.h:20,
                 from ./include/linux/netdevice.h:38,
                 from drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/include/osdep_service_linux.h:35,
                 from drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/include/osdep_service.h:41,
                 from drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/include/drv_types.h:32,
                 from drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/hal/hal_com_phycfg.c:22:
./include/linux/fs.h:2715:14: 附注: ‘file_path’的上一个声明在此
 extern char *file_path(struct file *, char *, int);
              ^~~~~~~~~
scripts/Makefile.build:293: recipe for target 'drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/hal/hal_com_phycfg.o' failed

  根据提示是 在rtl8723BU_WiFi_linux_v4.3.6.11/hal/hal_com_phycfg.c 文件中重新定了 file_path 变量,与 ./include/linux/fs.h 文件进行重复定义了,笔者修改的方法是将 rtl8723BU_WiFi_linux_v4.3.6.11/hal/hal_com_phycfg.c 文件中的 file_path 变量重新命名,将文件中所有出现 file_path 的位置修改为 _file_path。
在这里插入图片描述
  修改后再次编译 make modules,到此为止笔者的代码没有出现其他的错误,如果有其他错误欢迎一起讨论。编译后提示的信息如下:

  Building modules, stage 2.
  MODPOST 57 modules
  CC      drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/8723bu.mod.o
  LD [M]  drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11/8723bu.ko
book@100ask:~/100ask_imx6ull-sdk/crystal/linux-imx$ 

  根据上面的消息可以看出成功编译生成了 8723bu.ko 文件,如下所示:

book@100ask:~/100ask_imx6ull-sdk/crystal/linux-imx/drivers/net/wireless/realtek/rtl8723BU_WiFi_linux_v4.3.6.11$ ls
8723bu.ko  8723bu.mod.c  8723bu.mod.o  8723bu.o  core  hal  include  Kconfig  Makefile  modules.order  os_dep  platform
Logo

更多推荐