Chinaunix首页 | 论坛 | 博客
  • 博客访问: 36927
  • 博文数量: 28
  • 博客积分: 351
  • 博客等级: 一等列兵
  • 技术积分: 205
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-24 18:36
文章分类

全部博文(28)

文章存档

2012年(18)

2011年(9)

2010年(1)

我的朋友

分类:

2012-08-08 15:35:55

本次PPP移植是在三星arm2410的平台上进行的,所用的工作环境为:
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
一、具体操作步骤
 
 
首先编译内核支持 PPP:
$make menuconfig                    
$make ARCH=arm CROSS_COMPILE=/../arm-linux- zImage
$./mkimage2410 uImage                
其中mkimage2410、mkimage等文件来自u-boot1.1.3 需要根据你的路径修改mkimage2410的内容,指定mkimage文件的位置。
 
第二步,制作文件系统:
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,但是这样做好像有点问题,有时不能成功,其实直接敲入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下得到了可执行程序pppd,pppdump,pppstats 和 chat.
将它们复制到 /../rootfs/usr/sbin 目录下
 
移到文件系统根目录
#mkdir etc dev
#cd dev
#mknod 600 console 5 1
#mknod ppp c 108 0
#cd ..
 
 
配制/etc目录下的文件和文件夹,如: inittab fstab host.conf rc.d以便内核能够正确启动文件系统。
 
 
最后,从/../3.3/lib目录下选出所需要的库文件放到文件系统根目录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烧到板子上并设置好环境变量后就能通过tftp下载kernel 和ramdisk到目标板上运行了。
 
 
 
 
 
 
 
 
 
 
二、拨号脚本配置:
当然,要正确连上GPRS网还需要配置PPP拨号的脚本和配置PPP设备。
1GPRS拨号脚本如下:
# 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
 
3GPRS连接脚本:(注意移动梦网接入点是CMNET,号码是*99***1#,带有引号的AT命令一定要用单引号包含整个命令。)
#!/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"
 
4pap-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 * "" *
 
5chap-secrets文件(这个文件好像可以不要)
# 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 这四个文件都不能少。
GPRS断开脚本gprs-disconnect-chat我正在调试,现在还没有通过。目前只能用kill来断开。
 
三、GPRS的开机自动登录和断线自动重连
在有些应用中需要PPP在开机的时候能自动拨上GPRS网,并且在断线之后能自动进行重拨。此功能可以用一个简单的shell脚本来实现。
编辑一名为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文件中加入项目:
::once:/etc/ppp/ppp 1>>/etc/ppp/info
 
    这样,就实现了开机自动登录和断线自动重连的功能。此时拨号信息不会在终端输出而是记录在/etc/ppp/info文件中,要了解拨号信息可以要此文件中查看。要终止PPP连接可输入:kill –9 27
 
 
总结:嵌入式linux下应用程序的移植,实际上是一个系统平台转换的过程。最好能先在宿主机(X86)上对程序源 文件进行从头到尾的编译、连接,让它首先在宿主机上跑起来。弄清每一个步骤及其工作的具体内容,在向目标板移植的过程中一定要保证交叉编译,其它文件配置 和操作步骤跟宿主机上几乎完全一样。


摘自
阅读(274) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~