实验环境
- 主板:JZ2440
- 编译器:arm-linux-gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72)
- Linux Kernel:3.4.2
- DHCP版本:dhcp-4.2.5-P1.tar.gz
- 无线网卡:Ralink Technology, Corp. RT2870/RT3070 Wireless Adapter
交叉编译
解压
tar xzf dhcp-4.2.5-P1.tar.gz
cd dhcp-4.2.5-P1
配置
./configure --host=arm-linux ac_cv_file__dev_random=yes
修改 bind 文件夹中文件
cd bind
vim Makefile
把第 55 行:
./configure --disable-kqueue
改为
./configure BUILD_CC=gcc ac_cv_file__dev_random=yes --host=arm-linux --disable-kqueue
解压 bind 文件夹下 bind.tar.gz
tar xzf bind.tar.gz
cd bind-9.8.4-P2
修改 lib/export/dns/Makefile.in
vim lib/export/dns/Makefile.in
将第 168 和 169 行:
168 gen: ${srcdir}/gen.c
169 ${CC} ${ALL_CFLAGS} ${LDFLAGS} -o $@ ${srcdir}/gen.c ${LIBS}
改为:
gen: ${srcdir}/gen.c
${BUILD_CC} ${ALL_CFLAGS} ${LDFLAGS} -o $@ ${srcdir}/gen.c ${LIBS}
编译
cd ../..
make
mkdir tmp
make DESTDIR=$PWD/tmp install
使用 DHCP
将编译出来的程序和文件拷贝到根文件系统
cd tmp/usr/local/
# XHR ROOTFS 为我的 NFS 根文件系统路径
export XHRROOTFS=/nfsroot/rootfs-1.20.0
cp bin/* $XHRROOTFS/bin/
cp sbin/* $XHRROOTFS/sbin/
cp etc/dhclient.conf.example $XHRROOTFS/etc/dhclient.conf
cp etc/dhcpd.conf.example $XHRROOTFS/etc/dhcpd.conf
拷贝并修改执行脚本
cd ../../..
cp client/scripts/linux $XHRROOTFS/etc/dhclient-script
vim $XHRROOTFS/etc/dhclient-script
{
将第一行
#!/bin/bash
改为
#!/bin/sh
}
使用
在开发板上:
mkdir -p /var/db
#wpa_supplicant -B -d -Dnl80211 -iwlan0 -c/etc/wpa-wpa2.conf
#wpa_supplicant -B -d -iwlan0 -c/etc/wpa-wpa2.conf
wpa_supplicant -B -iwlan0 -c/etc/wpa-wpa2.conf
wpa_cli -iwlan0 status
使用 wpa_cli -iwlan0 status 查看状态,显示 COMPLETED:
/ # wpa_cli -iwlan0 status
bssid=94:0e:6b:f5:0f:81
ssid=Honor V9 # 热点名称
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK # 加密方式
wpa_state=COMPLETED # 链接热点成功
address=70:f1:1c:27:dd:3a
使用 dhcp 自动分配 ip
/sbin/dhclient wlan0
再使用 ifconfig 查看 wlan0 的 IP,192.168.43.1 是手机IP。
eth0 Link encap:Ethernet HWaddr 00:60:6E:33:44:55
inet addr:192.168.0.231 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7777 errors:0 dropped:0 overruns:0 frame:0
TX packets:3326 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9705696 (9.2 MiB) TX bytes:537300 (524.7 KiB)
Interrupt:51 Base address:0x4000
wlan0 Link encap:Ethernet HWaddr 70:F1:1C:27:DD:3A
inet addr:192.168.43.234 Bcast:192.168.43.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16 errors:0 dropped:1 overruns:0 frame:0
TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2294 (2.2 KiB) TX bytes:1960 (1.9 KiB)
ping 测试
ping 192.168.43.1
PING 192.168.43.1 (192.168.43.1): 56 data bytes
64 bytes from 192.168.43.1: seq=0 ttl=64 time=51.363 ms
64 bytes from 192.168.43.1: seq=1 ttl=64 time=49.740 ms
64 bytes from 192.168.43.1: seq=2 ttl=64 time=58.300 ms
64 bytes from 192.168.43.1: seq=3 ttl=64 time=51.565 ms
参考链接
cross-compile dhcp-4.2.5 and bind-9.8.4-P1
wifi 热点的 ip 是固定的 192.168.43.1
来源:CSDN
作者:xhr_embedded
链接:https://blog.csdn.net/u012849539/article/details/104511739