PPP撥號在ARM2410平臺上的移植
本次PPP移植是在三星arm2410的平臺上進(jìn)行的,所用的工作環(huán)境為:
Kernel: 2.4.18
Sysvinit:2.86
Tinylogin:1.4
Glibc: 2.2.5 +GCC:3.3
PPP: 2.4.1
U-boot:1.1.3
Busybox :1.00
Sysvinit:2.86
一、具體操作步驟
首先編譯內(nèi)核支持 PPP:
$make menuconfig
$make ARCH=arm CROSS_COMPILE=/../arm-linux- zImage
$./mkimage2410 uImage
其中mkimage2410、mkimage等文件來自u-boot1.1.3 需要根據(jù)你的路徑修改mkimage2410的內(nèi)容,指定mkimage文件的位置。
第二步,制作文件系統(tǒng):
1. 編譯Busybox
$make menuconfig
Build options ---->
[*] Build BusyBox as a static binary (no shared libs)
[*] Do you want to build BusyBox with a Cross Compiler?
(/usr/local/arm/3.3/bin/arm-linux-) Cross Compiler prefix
$make
$make PREFIX=/../rootfs/ install
注意:Busybox的README中說用make busybox 命令來編譯busybox,但是這樣做好像有點(diǎn)問題,有時(shí)不能成功,其實(shí)直接敲入make就行了。
2. 編譯System V init
$cd src
$make CROSS=/../arm-linux- PREFIX=/../rootfs/ all
$make PREFIX=/../rootfs install
3. 編譯 Tinylogin
$make CROSS=/../arm-linux- PREFIX=/../rootfs/ all
$make PREFIX=/../rootfs install
4.交叉編譯 PPP:
$export CROSS_COMPILE=/../arm-linux-
$export CC=/../arm-linux-gcc
$make
這樣就在目錄: /../ppp-2.4.1/pppd,/../ppp-2.4.1/pppdump,/../ppp-2.4.1/pppstats and /../ppp-2.4.1/chat下得到了可執(zhí)行程序pppd,pppdump,pppstats 和 chat.
將它們復(fù)制到 /../rootfs/usr/sbin 目錄下
移到文件系統(tǒng)根目錄
#mkdir etc dev
#cd dev
#mknod 600 console 5 1
#mknod ppp c 108 0
#cd ..
配制/etc目錄下的文件和文件夾,如: inittab fstab host.conf rc.d以便內(nèi)核能夠正確啟動文件系統(tǒng)。
最后,從/../3.3/lib目錄下選出所需要的庫文件放到文件系統(tǒng)根目錄rootfs/lib下面.
$su
#mkdir tmp/initrd
#dd if=/dev/zero of=images/initrd.img bs=1k count=8192
#/sbin/mke2fs –F –v –m0 images/initrd.img
#mount –o loop images/initrd.img tmp/initrd
#cp –av rootfs/* tmp/initrd
#umount tmp/initrd
#exit
$gzip –9 < images/initrd.img > images/initrd.bin
這樣,就得到了我們所需要的uImage 和initrd.bin.將U-boot燒到板子上并設(shè)置好環(huán)境變量后就能通過tftp下載kernel 和ramdisk到目標(biāo)板上運(yùn)行了。
二、撥號腳本配置:
當(dāng)然,要正確連上GPRS網(wǎng)還需要配置PPP撥號的腳本和配置PPP設(shè)備。
1.GPRS撥號腳本如下:
# File:
# /etc/ppp/gprs
#
# Description:
# This file holds the serial cable and IrDA pppd options for GPRS phones
# Tell the ppp-daemon to accept mangled data
receive-all
# Give some debug info
debug
kdebug 7
# Print out all the option values which have been set.
dump
# Serial device to which terminal is connected;
# with serial port (COM1 in Windows) use /dev/ttyS0
# and with IrDA use /dev/ircomm0.
#/dev/ircomm0 # IrDA
/dev/ttyS1
# Serial port line speed
115200
# Turn off waiting of carrier detect or flow control signal
# With IrDA it should be disabled with nocrtscts option.
-crtscts # serial cable
#nocrtscts # IrDA
# Ignore carrier detect signal from the modem
local
# To keep pppd on the terminal
nodetach
# Accept the peer's idea of our local IP address
ipcp-accept-local
# Accept the peer's idea of its (remote) IP address
ipcp-accept-remote
# IP addresses:
# - accept peers idea of our local address and set address peer as 10.0.0.1
# (any address would do, since IPCP gives 0.0.0.0 to it)
# - if you use the 10. network at home or something and pppd rejects it,
# change the address to something else
0.0.0.0:0.0.0.0
-chap
#-pap
# pppd must not propose any IP address to the peer!
#noipdefault
# No ppp compression
novj
novjccomp
papcrypt
nodeflate
#No ppp magic number
nomagic
# no asyn cmap
asyncmap 0
# Add default route
defaultroute
# Connect script
connect /etc/ppp/gprs-connect-chat
# Disconnect script
disconnect /etc/ppp/gprs-disconnect-chat
2.下面是options文件:
# File:
# /etc/ppp/options
#
receive-all
nopcomp
noaccomp
nomagic
debug
# Mobile is connected to the first serial port
/dev/ttyS1
115200
connect '/usr/sbin/chat -e -f /etc/ppp/gprs-connect-chat -v'
disconnect '/usr/sbin/chat -e -f /etc/ppp/chat-disconnect -v'
modem
noauth
noccp
novj
novjccomp
defaultroute
noipdefault
user foo
lock
3.GPRS連接腳本:(注意移動夢網(wǎng)接入點(diǎn)是CMNET,號碼是*99***1#,帶有引號的AT命令一定要用單引號包含整個(gè)命令。)
#!/bin/sh
#
# File:
# /etc/ppp/chat-gprs-connect
#
# Description:
# chat script to open Sonera GPRS service with GPRS phones. If ppp
# negotiation stalls, try restarting the phone. To try with other GPRS
# operator setting, change the PDP contex setting. The settings work with
# all Ericsson models, but Nokia 8310 does not suppor QoS parameters with
# AT commands, so just delete those lines and it'll work.
#
# Set PDP context CID=1, protocol=IP, APN=internet:
# AT+CGDCONT=1,"IP","internet","",0,0
#
# Set CID=1 QoS requirements from the network, not supported by 8310:
# AT+CGQREQ=1,0,0,0,0,0
#
# Set CID=1 minimum acceptable QoS parameters, not supported by 8310:
# AT+CGQMIN=1,0,0,0,0,0
#
# 'Call' CID=1 (activate PDP context one, perform GPRS attach):
# ATD*99***1#
#
# ogin:-BREAK-ogin: \
# TIMEOUT 5 \
# assword: \
# SAY "\nLogged in OK...\n" \
# The actual chat script:
exec chat \
TIMEOUT 5 \
ECHO ON \
ABORT '\nBUSY\r' \
ABORT '\nERROR\r' \
ABORT '\nNO ANSWER\r' \
ABORT '\nNO CARRIER\r' \
ABORT '\nNO DIALTONE\r' \
ABORT '\nRINGING\r\n\r\nRINGING\r' \
'' AT \
TIMEOUT 5 \
SAY "Press CTRL-C to close the connection at any stage!" \
SAY "\ndefining PDP context...\n" \
OK AT+IPR=115200 \
OK 'AT+CGDCONT=1,"IP","CMNET"' \
OK 'AT+CGCLASS="B"' \
OK AT+CGACT=1,1 \
OK ATD*99***1# \
TIMEOUT 60 \
SAY "\nwaiting up to 2 mintues for connect...\n"\
CONNECT "" \
SAY "\nConnected. now logging in...\n" \
SAY "\nIf the following ppp negotiations fail,\n" \
SAY "try restarting the phone.\n"
4.pap-secrets文件:
# File:
#/etc/ppp/pap-secrets
# Secrets for authentication using PAP
# client server secret IP addresses
####### redhat-config-network will overwrite this part!!! (begin) ##########
####### redhat-config-network will overwrite this part!!! (end) ############
foo * "" *
5.chap-secrets文件(這個(gè)文件好像可以不要):
# File:
# /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client server secret IP addresses
####### redhat-config-network will overwrite this part!!! (begin) ##########
####### redhat-config-network will overwrite this part!!! (end) ############
其它什么ip-up,ip-down文件都不是必需的。gprs, pap-secrets, gprs-connect-chat, options 這四個(gè)文件都不能少。
GPRS斷開腳本gprs-disconnect-chat我正在調(diào)試,現(xiàn)在還沒有通過。目前只能用kill來斷開。
三、GPRS的開機(jī)自動登錄和斷線自動重連
在有些應(yīng)用中需要PPP在開機(jī)的時(shí)候能自動撥上GPRS網(wǎng),并且在斷線之后能自動進(jìn)行重?fù)。此功能可以用一個(gè)簡單的shell腳本來實(shí)現(xiàn)。
編輯一名為ppp的shell腳本如下:
#!/bin/sh
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
export LD_LIBRARY_PATH="/usr/local/lib:/usr/lib:/lib"
trap "echo 'PPPD:Do not interrupt me!'" INT
trap "echo 'PPPD:Help! Do not kill me!'" TERM
while(ps -ax | grep 'pppd' )
do sleep 10
pppd file /etc/ppp/gprs
sleep 8
trap "echo 'PPPD:Do not interrupt me!'" INT
trap "echo 'PPPD:Help! Do not kill me!'" TERM
done
然后在inittab文件中加入項(xiàng)目:
::once:/etc/ppp/ppp 1>>/etc/ppp/info
這樣,就實(shí)現(xiàn)了開機(jī)自動登錄和斷線自動重連的功能。此時(shí)撥號信息不會在終端輸出而是記錄在/etc/ppp/info文件中,要了解撥號信息可以要此文件中查看。要終止PPP連接可輸入:kill –9 27
總結(jié):嵌入式linux下應(yīng)用程序的移植,實(shí)際上是一個(gè)系統(tǒng)平臺轉(zhuǎn)換的過程。最好能先在宿主機(jī)(X86)上對程序源文件進(jìn)行從頭到尾的編譯、連接,讓它首先在宿主機(jī)上跑起來。弄清每一個(gè)步驟及其工作的具體內(nèi)容,在向目標(biāo)板移植的過程中一定要保證交叉編譯,其它文件配置和操作步驟跟宿主機(jī)上幾乎完全一樣。
|