开发板:荔枝派zero
linux:linux-zero-4.10.y
rootfs:Debian9.9

Debian软件安装:

apt install  wpa_supplicant
apt install  udhcpc 

在linux-zero-4.10.y版本源码的drivers/staging/目录下没有rtl8723bs驱动。
所以后面clone了linux-zero-4.14.y,在drivers/staging/目录下可以发现存在rtl8723bs驱动文件夹,所以下面记录下使用linux-zero-4.14.y编译与开启rtl8723bs

1、我先查看下rtl8723bs文件夹下的Kconfig文件

config RTL8723BS
	tristate "Realtek RTL8723BS SDIO Wireless LAN NIC driver"
	depends on WLAN && MMC && CFG80211
	depends on m
	select WIRELESS_EXT
	select WEXT_PRIV
	---help---
	This option enables support for RTL8723BS SDIO drivers, such as
	the wifi found on the 1st gen Intel Compute Stick, the CHIP
	and many other Intel Atom and ARM based devices.
	If built as a module, it will be called r8723bs.

可以发现RTL8723BS依赖于 WLAN && MMC && CFG80211。

创建zero的配置文件

make ARCH=arm licheepi_zero_defconfig

根目录下看了下.config配置文件,licheepi_zero_defconfig中相关依赖都已经打开了。

2、配置编译r8723bs模块

make ARCH=arm menuconfig

在这里插入图片描述
在这里插入图片描述
这里只能选择编译成模块。

3、安装r8723bs.ko驱动
编译后的驱动在drivers/staging/rtl8723bs目录下。
拷贝到根文件系统里。

#安装命令
insmod  r8723bs.ko

在这里插入图片描述
安装后提示error:
rtl8723bs mmc1:0001:1: Direct firmware load for rtlwifi/rtl8723bs_nic.bin failed with error -2

4、拷贝 rtl8723bs_nic.bin 到根文件系统的 /lib/firmware/rtlwifi/ 目录下。

mkdir -p  /lib/firmware/rtlwifi/
##拷贝 rtl8723bs_nic.bin 到根文件系统的 /lib/firmware/rtlwifi/ 目录下
##重新安装模块
rmmod  r8723bs
insmod  r8723bs.ko

执行结果如下:

root@ubuntu:/# insmod r8723*
[ 4114.732347] r8723bs: module is from the staging directory, the quality is unk
nown, you have been warned.
[ 4114.748990] RTL8723BS: module init start
[ 4114.752932] RTL8723BS: rtl8723bs v4.3.5.5_12290.20140916_BTCOEX20140507-4E40
[ 4114.760105] RTL8723BS: rtl8723bs BT-Coex version = BTCOEX20140507-4E40
[ 4114.777679] pnetdev = c33d6000
[ 4114.804573] RTL8723BS: rtw_ndev_init(wlan0)
[ 4114.841420] RTL8723BS: module init ret =0
[ 4115.015582] rtl8723bs: acquire FW from file:rtlwifi/rtl8723bs_
nic.bin


root@ubuntu:/# ifconfig -a
eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 02:01:c8:0e:b2:12  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 38

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 19924  bytes 1733352 (1.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 19924  bytes 1733352 (1.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.1.255
        ether b6:fb:ab:a7:ea:2a  txqueuelen 1000  (Ethernet)
        RX packets 325  bytes 78686 (76.8 KiB)
        RX errors 0  dropped 118  overruns 0  frame 0
        TX packets 80  bytes 11718 (11.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:e0:4c:87:00:00  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        

这里可以看到wlan0网络就是了。

5、配置连接WiFi
编辑/etc/network/interfaces文件

# Configure Loopback
auto lo
iface lo inet loopback
# 增加wlan0描述
auto wlan0
iface wlan0 inet dhcp

wpa_supplicant连接WIFI的时候会从配置文件中读取账号和密码,以及加密方式等, 所以我们再运行wpa_supplicant工具的时候要提前写好配置文件。
配置文件名称自定,但是要以 .conf 为后缀,并保存在 /etc/ 目录下,这边给出一个配置文件的例子。
编辑 /etc/wpa_supplicant.conf 文件:


ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
ap_scan=1
network={
    ssid="wifi_name"
    scan_ssid=1
    key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
    pairwise=TKIP CCMP
    group=CCMP TKIP WEP104 WEP40
    psk="wifi_password"
    priority=5
}

注意wifi名与密码不要多了空格,自己犯过这个错误。。
导致出现:

[  100.248490] RTL8723BS: nolinked power save leave
[  102.446737] RTL8723BS: nolinked power save enter

#创建一个socket通信的目录

mkdir -p /var/run/wpa_supplicant

#安装r8723bs驱动

root@ubuntu:/# cd / ;insmod r8723bs.ko
[   29.104243] r8723bs: module is from the staging directory, the quality is unk
nown, you have been warned.
[   29.122015] RTL8723BS: module init start
[   29.126115] RTL8723BS: rtl8723bs v4.3.5.5_12290.20140916_BTCOEX20140507-4E40
[   29.133158] RTL8723BS: rtl8723bs BT-Coex version = BTCOEX20140507-4E40
[   29.148730] pnetdev = c3bde000
[   29.346349] RTL8723BS: rtw_ndev_init(wlan0)
[   29.363866] RTL8723BS: module init ret =0

#启动wlan0

root@ubuntu:/# ifconfig wlan0 up
[   28.250324] rtl8723bs: acquire FW from file:rtlwifi/rtl8723bs_nic.bin
[   28.476287] random: crng init done

#连接WiFi

root@ubuntu:/# wpa_supplicant -B -c /etc/wpa_supplicant.conf -i wlan0
Successfully initialized wpa_supplicant
[   54.751545] RTL8723BS: rtw_set_802_11_connect(wlan0)  fw_state
= 0x00000008
[   54.984523] RTL8723BS: start auth
[   54.990049] RTL8723BS: auth success, start assoc
[   55.000233] RTL8723BS: rtw_cfg80211_indicate_connect(wlan0) BSS not found !!
[   55.007440] RTL8723BS: assoc success
[   55.026198] RTL8723BS: send eapol packet
[   55.037239] RTL8723BS: send eapol packet
[   55.041820] RTL8723BS: set pairwise key camid:4, addr:cc:08:fb:76:c1:66, kid:
0, type:AES
[   55.053800] RTL8723BS: set group key camid:5, addr:cc:08:fb:76:c1:66, kid:1,
type:AES

#自动获取IP地址

root@ubuntu:/# udhcpc -i wlan0
udhcpc (v1.22.1) started
Sending discover...
Sending select for 192.168.1.103...
Lease of 192.168.1.103 obtained, lease time 7200

#查看网络状态

root@ubuntu:/# wpa_cli -iwlan0 status
bssid=cc:08:fb:76:c1:66
freq=2462
ssid=TP-LINK_C166
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
ip_address=192.168.1.103
address=00:e0:4c:87:00:00
uuid=39d339de-d9f2-54e4-ab0c-fa9487e8849b

#最后尝试下ping网络

root@ubuntu:/# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.95 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=3.34 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=10.3 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=1.66 ms
^C
--- 192.168.1.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 1.669/4.334/10.371/3.543 ms

开机自动连接WiFi

cat /lib/systemd/system/rc.local.service

#  SPDX-License-Identifier: LGPL-2.1+

#

#  This file is part of systemd.

#

#  systemd is free software; you can redistribute it and/or modify it

#  under the terms of the GNU Lesser General Public License as published by

#  the Free Software Foundation; either version 2.1 of the License, or

#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by

# systemd-rc-local-generator if /etc/rc.local is executable.

[Unit]

Description=/etc/rc.local Compatibility

Documentation=man:systemd-rc-local-generator(8)

ConditionFileIsExecutable=/etc/rc.local

After=network.target

[Service]

Type=forking

ExecStart=/etc/rc.local start

TimeoutSec=0

RemainAfterExit=yes

GuessMainPID=no

新建一个rc.local文件

#!/bin/sh

sh /etc/init.d/S100auto_wifi_link.sh
echo "wifi finish!!"

创建脚本S100auto_wifi_link.sh

#!/bin/sh
insmod /r8723bs.ko
ifconfig wlan0 up
wpa_supplicant -B -c /etc/wpa_supplicant.conf -i wlan0
sleep 3s
udhcpc -i wlan0
修改rc.local 权限
# chmod +x /etc/rc.local

启动rc-local了
#systemctl start rc-local

查看rc-local启动过程中是否有错误出现
#systemctl status rc-local

到这里,rc-local就能够正常工作了。

在这里插入图片描述

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐