新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 2410開發(fā)板上實(shí)現(xiàn)DHCP自動(dòng)獲取IP地址

2410開發(fā)板上實(shí)現(xiàn)DHCP自動(dòng)獲取IP地址

作者: 時(shí)間:2016-11-10 來源:網(wǎng)絡(luò) 收藏
前提:系統(tǒng)已經(jīng)實(shí)現(xiàn)DNS(即使用ping 通)。

1.在內(nèi)核中添加以下選項(xiàng):
Networking--->

本文引用地址:http://m.butianyuan.cn/article/201611/317265.htm
  • Networking support
    Networking options--->
    Packet socket //添加.配置CONFIG_PACKET
    [ * ] IP: DHCP support //添加
    [ * ] Network packet filtering (replaces ipchains)---> //添加,后面子選項(xiàng)可不選,配置CONFIG_NETFILTER
    說明:若沒選 Packet socket, [ * ] Network packet filtering (replaces ipchains)--->選項(xiàng),在執(zhí)行udhcpc命令時(shí)出現(xiàn)如下錯(cuò)誤:
    ~ # udhcpc
    udhcpc (v0.9.9-pre) started
    udhcpc[208]: udhcpc (v0.9.9-pre) started

    FATAL: couldnt listen on socket, Address family not supported by protocol
    udhcpc[208]: FATAL: couldnt listen on socket, Address family not supported by protocol
    2.Busybox中添加以下選項(xiàng):
    Networking Utilities--->
    udhcp Server/Client--->
    [] udhcp Server (udhcpd) //在此不作服務(wù)端,故不選。生成udhcpd命令
  • udhcp Client (udhcpc) //生成udhcpc命令
    [ ] Lease display utility (dumpleases)
    [ ] Log udhcp messages to syslog (instead of stdout)
    [ ] Compile udhcp with noisy debugging messages
    busybox沒編譯相應(yīng)選項(xiàng),也可從網(wǎng)上下載相應(yīng)文件,用arm-linux交叉編譯得到udhcpd,udhcpc命令copy到usr/sbin下就可以了。
    我從 網(wǎng)上下的udhcp_0.9.8cvs20050303.orig.tar.gz文件
    解壓后修改Makefile文件
    在19行添加CROSS_COMPILE=arm-linux-
    注釋12行的COMBINED_BINARY=1,否則不生成udhcpc命令。
    3.建相關(guān)配置文件
    從busybox的examples/udhcp/下copysimple.script文件到開發(fā)板/usr/share/udhcpc/下,并重命名為default.script,udhcp_0.9.8cvs20050303.orig.tar.gz中也有這樣的文件。
    [root@localhost root]# vi usr/share/udhcpc/default.script
    #!/bin/sh

    # udhcpc script edited by Tim Riker

    [ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1

    RESOLV_CONF="/etc/resolv.conf"
    [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
    [ -n "$subnet" ] && NETMASK="netmask $subnet"

    case "$1" in
    deconfig)
    /sbin/ifconfig $interface 0.0.0.0
    ;;

    renew|bound)
    /sbin/ifconfig $interface $ip $BROADCAST $NETMASK

    if [ -n "$router" ] ; then
    echo "deleting routers"
    while route del default gw 0.0.0.0 dev $interface ; do
    :
    done
    for i in $router ; do
    route add default gw $i dev $interface
    done
    fi

    echo -n > $RESOLV_CONF
    [ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
    for i in $dns ; do
    echo adding dns $i
    echo nameserver $i >> $RESOLV_CONF
    done
    ;;
    esac

    exit 0

    4.重啟開發(fā)板,執(zhí)行udhcpc就可自動(dòng)獲取IP地址了,以下是執(zhí)行udhcpc的輸出信息:

    ~ # udhcpc
    udhcpc (v0.9.9-pre) started
    udhcpc[228]: udhcpc (v0.9.9-pre) started

    Sending discover...
    udhcpc[228]: Sending discover...

    Sending select for 192.168.1.109...
    udhcpc[228]: Sending select for 192.168.1.109...

    Lease of 192.168.1.109 obtained, lease time 86400
    udhcpc[228]: Lease of 192.168.1.109 obtained, lease time 86400

    deleting routers
    route: SIOC[ADD|DEL]RT: No such process
    adding dns 192.168.0.1
    ~ # ping www.baidu.com
    PING www.a.shifen.com (220.181.38.4): 56 data bytes
    64 bytes from 220.181.38.4: icmp_seq=0 ttl=52 time=1219.0 ms
    [1] + Stopped ping www.baidu.com

    5.如果是雙網(wǎng)卡必須用參數(shù)指明
    例:udhcpc-ieth1
===============================================
今天在我的2410上搞定攝像頭。交叉編譯gspca驅(qū)動(dòng),配置linux2.6.20.3使其支持V4L,不用選擇linux2.6自帶的ZC0301驅(qū)動(dòng)。發(fā)現(xiàn)可以搞定,但是2410性能交叉,640*480的VGA輸出,攝像頭分辨率大小不能設(shè)太大,否則很慢。我設(shè)定為176*144.

今天順便上busybox.net看了看,發(fā)現(xiàn)穩(wěn)定版已經(jīng)到1.5.1,于是重新把我現(xiàn)在用的1.4.2換成1.5.1。
發(fā)現(xiàn)原來ls -l /dev出現(xiàn)segment fault的BUG消除了!
順便加上了dhcp client的支持??戳藢戀Y料,方法:

在KERNEL中需要將 Packet socket和IP: DHCP support編譯進(jìn)內(nèi)核或編譯成模塊。在編譯Busybox時(shí)把 Networking Utilities下udhcp Server/Client中的 udhcp Client (udhcpc)選上。
關(guān)鍵點(diǎn)要把examples/udhcp/simple.script 腳本文件做為default.script拷貝到/usr/share/udhcpc/default.script

運(yùn)行udhcpc
~ # udhcpc
udhcpc (v1.5.1) started
Sending discover...
Sending select for 59.64.134.99...
Sending select for 59.64.134.99...
Sending select for 59.64.134.99...
Lease of 59.64.134.99 obtained, lease time 10800
deleting routers
route: SIOC[ADD|DEL]RT: No such process
adding dns 211.68.71.4
adding dns 211.68.71.5
adding dns 202.106.196.115
adding dns 202.106.0.20
然后可以使用tftp命令下載和上傳文件,主機(jī)的ip為192.168.1.105,下載自己tftp服務(wù)器下的led.ko文件,先在主機(jī)上建立tftp服務(wù)器,在開發(fā)板上輸入下面的命令,可以將led.ko文件下載到當(dāng)前目錄下。
#tftp -g -r led.ko 192.168.1.105
tftp使用說明如下:

Usage: tftp [OPTION]... HOST [PORT]
Transfers a file from/to a tftp server using "octet" mode.
Options:
-l FILE Local FILE
-r FILE Remote FILE
-g Get file
-p Put file
-b SIZE Transfer blocks of SIZE octets


評(píng)論


技術(shù)專區(qū)

關(guān)閉