RT3070L_USB_WIFI网卡在GT2440开发板上的移植和使用(四)--dhcp移植
6、dhcp的移植和应用
6.1、源码准备
(1)源码下载:ftp://ftp.isc.org/isc/
(2)源码文件确认:dhcp-4.2.5-P1.tar.gz
6.2、编译dhcp(如果不想看一步步的解决过程,可以跳过1,直接看2)
(1)尝试编译
tar zxf dhcp-4.2.5-P1.tar.gz //解压源码
cd dhcp-4.2.5-P1 && ls //到目录里面看有没有什么配置文件,只有一个configure
./configure --host=arm-linux //用万能配置试一下
/@#################出错,无法确定/dev/random
checking for /dev/random... configure: error: cannot check for file existence when cross compiling
#################@/
vi config.log //查看一下配置的日志,在最后会找到出错的地方。
/@#################
config.log:1132:configure:7689: checking for /dev/random
configure:7688:# check for /dev/random (declares HAVE_DEV_RANDOM) 在7688行的问题,那就看一下
configure:7689:{ echo "$as_me:$LINENO: checking for /dev/random" >&5
configure:7690:echo $ECHO_N "checking for /dev/random... $ECHO_C" >&6; }
configure:7698:if test -r "/dev/random"; then
configure.ac:535:# check for /dev/random (declares HAVE_DEV_RANDOM)
#################@/
vi configure +7688 //打开看一下:
/@#################
# check for /dev/random (declares HAVE_DEV_RANDOM)
{ echo "$as_me:$LINENO: checking for /dev/random" >&5
echo $ECHO_N "checking for /dev/random... $ECHO_C" >&6; }
if test "${ac_cv_file__dev_random+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
test "$cross_compiling" = yes && #我们指定了编译工具直接执行这条出错。我们怎么解决呢?直接将ac_cv_file__dev_random这个变量指定为yes
{ { echo "$as_me:$LINENO: error: cannot check for file existence when cross compiling" >&5
echo "$as_me: error: cannot check for file existence when cross compiling" >&2;}
{ (exit 1); exit 1; }; }
if test -r "/dev/random"; then
ac_cv_file__dev_random=yes
else
ac_cv_file__dev_random=no
fi
fi
#################@/
./configure --host=arm-linux ac_cv_file__dev_random=yes //重新用这条命令配置试试
/@#################
ISC DHCP source configure results:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Package:
Name: DHCP
Version: 4.2.5-P1
C Compiler: arm-linux-gcc
Flags:
DEFS: -DHAVE_CONFIG_H
CFLAGS: -g -O2 -Wall -Werror -fno-strict-aliasing -I${top_srcdir}/bind/include
Features:
debug: no
failover:
execute:
Developer:
ATF unittests : no
Now you can type make to build ISC DHCP
#################@/
make //编译一下看看有没有错误
/@#################显然不是一帆风顺的
.......
ar cru libomapi.a protocol.o buffer.o alloc.o result.o connection.o errwarn.o listener.o dispatch.o generic.o support.o handle.o message.o convert.o hash.o auth.o inet_addr.o array.o trace.o toisc.o iscprint.o isclib.o
arm-linux-ranlib libomapi.a
arm-linux-gcc -DHAVE_CONFIG_H -I. -I../includes -g -O2 -Wall -Werror -fno-strict-aliasing -I../bind/include -MT test.o -MD -MP -MF .deps/test.Tpo -c -o test.o test.c
mv -f .deps/test.Tpo .deps/test.Po
arm-linux-gcc -g -O2 -Wall -Werror -fno-strict-aliasing -I../bind/include -o svtest test.o libomapi.a ../bind/lib/libdns.a ../bind/lib/libisc.a #最后一条编译语句是这个,也就是这里出的错
/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: ../bind/lib/libdns.a(client.o): Relocations in generic ELF (EM: 3)
/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: ../bind/lib/libdns.a(client.o): Relocations in generic ELF (EM: 3)
/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: ../bind/lib/libdns.a(client.o): Relocations in generic ELF (EM: 3)
/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: ../bind/lib/libdns.a(client.o): Relocations in generic ELF (EM: 3)
/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: ../bind/lib/libdns.a(client.o): Relocations in generic ELF (EM: 3)
/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: ../bind/lib/libdns.a(client.o): Relocations in generic ELF (EM: 3)
../bind/lib/libdns.a: could not read symbols: File in wrong format #这里说这些库的格式是错误的,怎么会格式错误呢。
找到这个库的编译路径去看看吧。
collect2: ld returned 1 exit status
make[1]: *** [svtest] Error 1
make[1]: Leaving directory `/work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1/omapip'
make: *** [all-recursive] Error 1
#################@/
find -name "libdns.a"
/@#################
./bind/bind-9.8.4-P2/lib/export/dns/libdns.a
./bind/lib/libdns.a
#################@/
cd bind/bind-9.8.4-P2/lib/export/dns/ && ls //进里面看一下,有很多*.o文件。随便看一个
file acl.o //看一下这个文件的信息
/@################# 发现是386的。我是给arm开发板用的。这就不正常了。下面来解决这个问题
acl.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
#################@/
cd - && vi Makefile //进入源码根目录查看Makefile,源码中肯定有进入bind目录执行的命令。我们搜索bind
/@#################
#
# We have a lot of files that we want shipped with the distribution.
#
......
SUBDIRS = bind includes tests common dst omapip client dhcpctl relay server //搜索 SUBDIRS
nobase_include_HEADERS = dhcpctl/dhcpctl.h
all: all-recursive
搜索得到:对于SUBDIRS这些子目录,一个一个的进到里面执行make。
list='$(SUBDIRS)'; for subdir in target in $$subdir"; \
#################@/
cd bind && vi Makefile //进到bind目录看看Makefile做什么,找到all
/@#################
all:
# Extract the source from the tarball, if it hasn't been already.
#先解压源文件
@if test -d ${bindsrcdir} ; then \
echo ${bindsrcdir} already unpacked... ; \
else \
gunzip -c bind.tar.gz | tar xf - ; \
fi
@if test -z "${GMAKE}"; then \
echo "unable to find gmake" 1>&2 ; \
exit 1; \
fi
# Configure the export libraries 然后配置文件
# Currently disable the epoll and devpoll options as they don't interact
# well with the DHCP code.
# If the top-level Bind Makefile exists we skip the configuration step
# as we assume it's done and won't change. Doing a make clean will
# reset things if necessary.
#我们的配置没有配置为交叉编译所以不正确,我们试试修改加上交叉编译工具
@if test -f ${bindsrcdir}/Makefile ; then \
echo Bind export libraries already configured ; \
else \
echo Configuring BIND Export libraries for DHCP. ; \
rm -rf ./lib ./include ./configure.log ./build.log ./install.log ; \
--(cd ${bindsrcdir} && ./configure --disable-kqueue --disable-epoll --disable-devpoll --without-openssl --without-libxml2 --enable-exportlib --enable-threads=no --with-export-includedir=${binddir}/include --with-export-libdir=${binddir}/lib --with-gssapi=no > ${binddir}/configure.log); \
++ (cd ${bindsrcdir} && ./configure --host=arm-linux --disable-kqueue --disable-epoll --disable-devpoll --without-openssl --without-libxml2 --enable-exportlib --enable-threads=no --with-export-includedir=${binddir}/include --with-export-libdir=${binddir}/lib --with-gssapi=no > ${binddir}/configure.log); \
fi
# Build and install the export libraries 配置和安装
# No need to do anything if we already have something installed.
@if test -d ${binddir}/lib ; then \
echo Bind export libraries already installed ; \
else \
echo Building BIND Export libraries - this takes some time. ;\
(cd ${bindsrcdir}/lib/export ; \
echo building in `pwd` ; \
MAKE=${GMAKE} ${GMAKE} > ${binddir}/build.log) ; \
\
echo Installing BIND Export libraries to ${binddir}. ; \
(cd ${bindsrcdir}/lib/export ; \
MAKE=${GMAKE} ${GMAKE} install > ${binddir}/install.log) ; \
fi
#################@/修改后吧加压出的目录删掉,重新make看看还有什么错误
rm bind-9.8.4-P2/ -rf && make
/@#################还有错误啊。
Configuring BIND Export libraries for DHCP.
configure: error: cannot check for file existence when cross compiling
make: *** [all] Error 1 #configure的时候无法确认某些文件是否错误。
#################@/那就看看bind目录里的config.log吧
vi bind-9.8.4-P2/config.log
/@#################跳到最后,往前翻找到那个错误。
configure:22147: result: /dev/random
configure:22150: checking for /dev/random //configure的22150行,还是这个文件找不到啊
configure:22156: error: cannot check for file existence when cross compiling
#################@/
vi bind-9.8.4-P2/configure +22150 //看看这行怎么说
/@#################
22137 case "$use_randomdev" in
22138 unspec)
22139 case "$host" in
22140 *-openbsd*)
22141 devrandom=/dev/arandom
22142 ;;
22143 *)
22144 devrandom=/dev/random
22145 ;;
22146 esac
22147 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $devrandom" >&5
22148 $as_echo "$devrandom" >&6; }
22149 as_ac_File=`$as_echo "ac_cv_file_$devrandom" | $as_tr_sh`
22150 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $devrandom" >&5
22151 $as_echo_n "checking for $devrandom... " >&6; }
22152 if eval \${$as_ac_File+:} false; then :
22153 $as_echo_n "(cached) " >&6
22154 else
22155 test "$cross_compiling" = yes && #还是指定了交叉编译就抛出错误。直接用根目录的配置试一试。
22156 as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5
22157 if test -r "$devrandom"; then
22158 eval "$as_ac_File=yes"
22159 else
22160 eval "$as_ac_File=no"
22161 fi
22162 fi
#################@/在bind目录的configure项再加个选项:
vi Makefile
/@#################
-- (cd ${bindsrcdir} && ./configure --host=arm-linux --disable-kqueue --disable-epoll --disable-devpoll --without-openssl --without-libxml2 --enable-exportlib --enable-threads=no --with-export-includedir=${binddir}/include --with-export-libdir=${binddir}/lib --with-gssapi=no > ${binddir}/configure.log); \
++ (cd ${bindsrcdir} && ./configure ac_cv_file__dev_random=yes --host=arm-linux --disable-kqueue --disable-epoll --disable-devpoll --without-openssl --without-libxml2 --enable-exportlib --enable-threads=no --with-export-includedir=${binddir}/include --with-export-libdir=${binddir}/lib --with-gssapi=no > ${binddir}/configure.log); \
#################@/
rm -rf bind-9.8.4-P2/ && make //删除这个目录,重新make再看。
/@#################
Configuring BIND Export libraries for DHCP.
configure: error: BUILD_CC not set
make: *** [all] Error 1
#################@/BUILD_CC没有设置。我的思路:可以设置,或者退到上层目录make。也许是上层导入的。我们退到上层make
cd .. && make
/@#################还是没有设置啊。看来只能在里面指定试试了
root@book-desktop:/work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1# make
Making all in bind
make[1]: Entering directory `/work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1/bind'
bind-9.8.4-P2 already unpacked...
Configuring BIND Export libraries for DHCP.
configure: error: BUILD_CC not set
make[1]: *** [all] Error 1
make[1]: Leaving directory `/work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1/bind'
make: *** [all-recursive] Error 1
#################@/
vi bind/Makefile
/@#################改为这个。BUILD_CC是我们本机的编译器。
(cd ${bindsrcdir} && ./configure ac_cv_file__dev_random=yes BUILD_CC=gcc --host=arm-linux --disable-kqueue --disable-epoll --disable-devpoll --without-openssl --without-libxml2 --enable-exportlib --enable-threads=no --with-export-includedir=${binddir}/include --with-export-libdir=${binddir}/lib --with-gssapi=no > ${binddir}/configure.log);
#################@/
cd bind && make
/@#################又出错了
/bin/bash: ./gen: cannot execute binary file
make[2]: *** [include/dns/enumtype.h] Error 126
make[1]: *** [subdirs] Error 1
Installing BIND Export libraries to /work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1/bind.
/bin/bash: ./gen: cannot execute binary file //gen 无法执行的二进制文件
make[2]: *** [include/dns/enumclass.h] Error 126
make[1]: *** [subdirs] Error 1
make: *** [all] Error 2
#################@/搜索一下这个程序吧。
find -name "gen" //搜索一下这个程序在哪里
cd bind-9.8.4-P2/lib/export/dns //进入搜索的目录
file gen //查看一下这个程序的内容
/@#################
gen: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped //这是一个arm平台的程序,当然不能在我的主机上执行了
#################@/那我们得修改他的Makefile了。里面有Makefile.in,Makefile是根据Makefile.in编译来的
bind/bind-9.8.4-P2/lib/export/dns# vi Makefile.in
/@#################改为PC机的工具链
168 gen: ${srcdir}/gen.c
--169 ${CC} ${ALL_CFLAGS} ${LDFLAGS} -o $@ ${srcdir}/gen.c ${LIBS}
++169 ${BUILD_CC} ${ALL_CFLAGS} ${LDFLAGS} -o $@ ${srcdir}/gen.c ${LIBS}
#################@/到这里基本上所有的问题就处理完了。
(2)编译总结:正确的步骤:把所有的都删除掉,重新开始:
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 //配置源码
cd bind //进入bind目录,修改里面的Makefile,加上这些:
./configure BUILD_CC=gcc ac_cv_file__dev_random=yes --host=arm-linux --disable-kqueue
tar xzf bind.tar.gz //解压里面的bind
cd bind-9.8.4-P2 //进入解压的目录
修改 lib/export/dns/Makefile.in //修改里面的Makefile.in
gen: ${srcdir}/gen.c
${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 //编译吧,编译好了,如何安装呢?,打开Makefile,搜索一下install
/@#################
arm-linux-gcc -g -O2 -Wall -Werror -fno-strict-aliasing -I../bind/include -o dhcpd dhcpd-dhcpd.o dhcpd-dhcp.o dhcpd-bootp.o dhcpd-confpars.o dhcpd-db.o dhcpd-class.o dhcpd-failover.o dhcpd-omapi.o dhcpd-mdb.o dhcpd-stables.o dhcpd-salloc.o dhcpd-ddns.o dhcpd-dhcpleasequery.o dhcpd-dhcpv6.o dhcpd-mdb6.o dhcpd-ldap.o dhcpd-ldap_casa.o ../common/libdhcp.a ../omapip/libomapi.a ../dhcpctl/libdhcpctl.a ../bind/lib/libdns.a ../bind/lib/libisc.a
make[2]: Leaving directory `/work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1/server'
Making all in tests
make[2]: Entering directory `/work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1/server/tests'
Making all in .
make[3]: Entering directory `/work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1/server/tests'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1/server/tests'
make[2]: Leaving directory `/work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1/server/tests'
make[1]: Leaving directory `/work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1/server'
make[1]: Entering directory `/work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/work/gt2440_prj/zyp_RT3070/04_dhcp/dhcp-4.2.5-P1'
#################@/
vi Makefile //搜索install
/@#################可以看出DESTDIR是目的目录。
install-nobase_includeHEADERS: $(nobase_include_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)"
@$(am__vpath_adj_setup) \
list='$(nobase_include_HEADERS)'; for p in p"; then d=; else d="$(srcdir)/"; fi; \
$(am__vpath_adj) \
echo " $(nobase_includeHEADERS_INSTALL) 'p' '$(DESTDIR)$(includedir)/df"; \
done
#################@/
make DESTDIR=$PWD/tmp install //安装到$PWD/tmp
6.3、部署源码
cd tmp/usr/local/ && ls //进入目录看一下
/@#################
bin etc include lib sbin share
#################@/bin和sbin是应用程序。etc里面是配置文件。我们就需要这些就可以了。
把文件复制到你的开发板目录。
我将这些文件都复制到了网络文件系统/work/nfs_root/first_fs/gt2440_dev/dhcp
开发板端部署:
mount -t nfs -o nolock 192.168.15.15:/work/nfs_root/first_fs /mnt //挂接网络文件系统
cd /usr/bin/
cp /mnt/gt2440_dev/dhcp/bin/* ./
cd ../sbin/
cp /mnt/gt2440_dev/dhcp/sbin/* ./
cd /etc/
cp /mnt/gt2440_dev/dhcp/etc/* ./
mv dhclient.conf.example dhclient.conf
mv dhcpd.conf.example dhcpd.conf
这里部署完成了。
6.4、dhcp应用程序的使用
cd /myprj/rt3070l_usbwifi_driver/
insmod rt3070sta.ko //在rt3070l_usbwifi_driver目录下加载驱动
ifconfig ra0 up //打开无线设备
wpa_supplicant -B -c/etc/wpaconf/aes_tkip.conf -ira0 //开启wpa_supplicant这个服务
wpa_cli -ira0 status //wpa_cli这个命令连接到wpa服务器查看网卡状态
dhclient ra0 //启动一下,
ifconfig //查看一下:
/@#################没有成功啊。
ra0 Link encap:Ethernet HWaddr 48:5D:60:90:5D:1A
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:997141 (973.7 KiB) TX bytes:5310 (5.1 KiB)
#################@/
dhclient -d ra0 //执行程序并打印调试信息
/@#################
Internet Systems Consortium DHCP Client 4.2.5-P1
Copyright 2004-2013 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
can't create /var/db/dhclient.leases: No such file or directory //没有这个文件
execve (/etc/dhclient-script, ...): No such file or directory //没有这个脚本,我们查看dhclient.conf这个配置文件\
发现需要运行这个脚本
Listening on LPF/ra0/48:5d:60:90:5d:1a
Sending on LPF/ra0/48:5d:60:90:5d:1a
Sending on Socket/fallback
Trying medium "-link0 -link1 -link2" 1
execve (/etc/dhclient-script, ...): No such file or directory
DHCPDISCOVER on ra0 to 255.255.255.255 port 67 interval 2
parse_option_buffer: malformed option vendor.<unknown> (code 33966151): option length exceeds option buffer length.
DHCPOFFER from 192.168.1.1
DHCPREQUEST on ra0 to 255.255.255.255 port 67
parse_option_buffer: malformed option vendor.<unknown> (code 33966151): option length exceeds option buffer length.
DHCPACK from 192.168.1.1
#################@/看看源码目录有没有这个脚本吧。发现是有的哦
cp client/scripts/linux /work/nfs_root/first_fs/gt2440_dev/dhcp/dhclient-script //复制大网络文件系统
cp /mnt/gt2440_dev/dhcp/dhclient-script /etc/ //开发板端执行。复制到/etc下
chmod a+x dhclient-script //加上执行权限,发现还是不会成功。需要修改脚本的内容
vi dhclient-script
/@#################
--#!/bin/bash
++#!/bin/sh
#################@/
dhclient -d ra0 //执行程序并打印调试信息
/@#################
.......
can't create /var/db/dhclient.leases: No such file or directory //还会提示这个,一会儿创建一个空的好了。
....
bound to 192.168.1.2 -- renewal in 1508 seconds.
^C
#################@/
[root@GTStudio /etc]# ifconfig
/@#################
ra0 Link encap:Ethernet HWaddr 48:5D:60:90:5D:1A
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0 ^_^已经帮我们配置ip了
...
RX bytes:4066020 (3.8 MiB) TX bytes:11458 (11.1 KiB)
#################@/
[root@GTStudio /etc]# route
/@#################路由也设置好了^_^
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 ra0
default 192.168.1.1 0.0.0.0 UG 0 0 0 ra0
#################@/
[root@GTStudio /etc]# cat /etc/resolv.conf
/@################# DNS也设置了啊
search fugue.com. home.vix.com.
nameserver 127.0.0.1
nameserver 192.168.1.1
#################@/
[root@GTStudio /etc]# ping news.qq.com
/@#################也可以ping通外网了。^_^^_^
PING news.qq.com (111.30.144.71): 56 data bytes
64 bytes from 111.30.144.71: seq=0 ttl=53 time=16.059 ms
64 bytes from 111.30.144.71: seq=1 ttl=53 time=266.647 ms
^C
--- news.qq.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 16.059/141.353/266.647 ms
#################@/
mkdir -p /var/db/ //创建那个报错的目录
dhclient -d ra0 //执行程序并打印调试信息就不会有错了。
Water Droplet
598323431@qq.com
2020.4.6