没志青年
发布于 2025-09-08 / 20 阅读
0

Linux WIFI驱动移植

以移植 RTL8188EUS 为例

下载官方驱动:

删除内核自带驱动

在 drivers/net/wireless/rtlwifi/Kconfig 中删除以下内容

config RTL8192CU
	tristate "Realtek RTL8192CU/RTL8188CU USB Wireless Network Adapter"
	depends on USB
	select RTLWIFI
	select RTLWIFI_USB
	select RTL8192C_COMMON
	---help---
	This is the driver for Realtek RTL8192CU/RTL8188CU 802.11n USB
	wireless network adapters.

	If you choose to build it as a module, it will be called rtl8192cu

删除 drivers/net/wireless/rtlwifi/Makefile 中的

obj-$(CONFIG_RTL8192CU)		+= rtl8192cu/

Linux 内核配置

编译网卡驱动

将解压后的 realtek 目录拷贝到 drivers/net/wireless 目录下

编辑 drivers/net/wireless/Kconfig,在第 286 行后添加

source "drivers/net/wireless/realtek/Kconfig"

在 drivers/net/wireless/Makefile 第65行添加

obj-y += realtek/

对于linux4可以

对于5版本以上就不行

quickreflex/rtl8188eus: Wifi driver support for rtl8188eu, rtl8188eus and rtl8188etv chips and working under the new linux kernel (5.1.x). (github.com)

Linux无线网卡芯片RTL8188EUS驱动安装_安装 rtl8188 deb驱动-CSDN博客

wireless tools 测试工具

1、修改 Makefile

CC = arm-linux-gnueabihf-gcc
AR = arm-linux-gnueabihf-ar
RANLIB = arm-linux-gnueabihf-ranlib

2、编译和安装

make clean
make -j4
make DESTDIR=$PWD/build install

将 iwlist、iwconfig、iwspy、iwpriv、ifrename 这5个可执行文件拷贝到根文件系统的 /usr/bin

将 libiw.so.29 拷贝到/usr/lib

3、测试

modprobe 8188eu.ko
ifconfig wlan0 up
iwlist wlan0 scan

wpa_supplicant

1、编译 openssl,然后复制到根文件系统的 /usr/lib 目录下

sudo cp libcrypto.so* /.../usr/lib/ -af
sudo cp libssl.so* /.../usr/lib/ -af

2、编译 libnl,然后复制到根文件系统的 /usr/lib 目录下

sudo cp lib/* /.../usr/lib/ -rf

3、解压后进入 wpa_supplicant 目录,然后复制 defconfig 重命名为 .config

在 .config 文件中指定交叉编译器、openssl、libnl 库和头文件路径

CC = arm-linux-gnueabihf-gcc
CFLAGS += -I/.../openssl/include
LIBS += -L/.../openssl/lib -lssl -lcrypto
CFLAGS += -I/.../libnl/include/libnl3
LIBS += -L/.../libnl/lib

4、编译与安装

# 指定 libnl 库 pkgconfig 包位置,否则编译 wpa_supplicant 会报错
export PKG_CONFIG_PATH=/.../libnl/lib/pkgconfig:$PKG_CONFIG_PATH

make -j4
make DESTDIR=$PWD/build install

5、编译完成后,复制到根文件系统的 /usr/bin 目录下

sudo cp wpa_cli wpa_supplicant /.../usr/bin/ -f

6、测试是否移植成功

wpa_supplicant  -v

网络连接测试

创建目录

mkdir -p /var/run/wpa_supplicant

添加 /etc/wpa_supplicant.conf 配置文件

ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
network={
  ssid="WIFI名称"
  psk="WIFI密码"
}

然后依次执行

ifconfig wlan0 up
wpa_supplicant -D wext -c /etc/wpa_supplicant.conf -i wlan0 &
udhcpc -i wlan0

出现类似 wlan0: CTRL-EVENT-CONNECTED - Connection to 5c:e8:d3:0b:f4:a4 completed [id=0 id_str=] 就说明连接成功了

或者

wpa_supplicant -Dnl80211 -c /etc/wpa_supplicant.conf -i wlan0 &

ping www.baidu.com

注意,如果开发板的以太网和无线网在同一个网段下且网关相同,那么会导致网络连接冲突,无法上网,解决办法就是换个wifi。

使用 buildroot 简化移植

→ Target packages 
    → Networking applications
        → [*] wireless tools //选中
                →[*] Install shared library //选中
        → [*] wpa_supplicant //选中
              →[*] Enable nl80211 support //选中
              →[*] Enable AP mode //选中
                    → [*] Enable Wi-Fi Display //选中
                    → [*] Enable mesh networking //选中  
              → [*] Enable autoscan //选中
              → [*] Enable EAP //选中
              → [*] Enable HS20 //选中
              → [*] Enable syslog support //选中
              → [*] Enable WPS //选中
              → [*] Enable WPA3 support //选中
              → [*] Install wpa_cli binary //选中
              → [*] Install wpa_client shared library //选中
              → [*] Install wpa_passphrase binary //选中
              → [*] Enable support for the DBus control interface //选中
              → [*] Introspection support //选中

就是

HT/VHT/HE 不选