hsy75的个人空间 https://blog.eetop.cn/vivilife [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

[o]详析ubuntu/debian下建立和cotext_arm目标板的tftp连接

已有 1717 次阅读| 2012-10-26 14:23 |个人分类:practic_linux

tftp服务经常被嵌入式开发用来从主机和目标板之间传输,和烧录文件,此文介绍了基本的建立tftp服务的方法和实践:

文章使用了两种不同的linux host,debain(5)和ubuntu (10.10),分别成功实现和目标板的tftp的连接


1 tftp服务的安装

ubuntu 下方法
apt-get install tftpd-hpa tftp-hpa

tftp-hpa是客户端,tftpd-hpa是服务器端

因为tftp是要inetd来控制的,而ubuntu或debian类的系统,默认是没有安装inetd的,所以一般要再安装一下:

debian下方法

 apt-get install tftpd tftp xinetd

有关于xinetd,如果你希望在ubuntu下也用的话,安装的时候,因为xinetd有两个版本,所以会提示你须选择:

我们这里选择了下面这个:

apt-get install inetutils-inetd

还有一个是apt-get install netkit-inetd

有些方法是用rpm包安装没有实践过:

redhat下方法

  在redhat9的CD3里可以找到tftp-server-0.32-4.i386.rpm文件
  [root@gliethttp root]# rpm -ivh tftp-server-0.32-4.i386.rpm


2 在linux host机器上建立tftp的服务器根目录,一般可以命名为:tftpboot,

为了以后调试方便,tftp,nfs,samba等工作目录一般都放在自己的工作目录下,我的是 /home/wine/

root@ubuntu:/home/wine# mkdir tftpboot
root@ubuntu:/home/wine# chmod 777 tftpboot/

 


3 tftp 配置:

ubuntu 下方法 修改文件

vim /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
#TFTP_DIRECTORY="/var/lib/tftpboot" 改为 -->
TFTP_DIRECTORY="/home/wine/tftpboot"


TFTP_ADDRESS="0.0.0.0:69"


#TFTP_OPTIONS="--secure" 改为-->
TFTP_OPTIONS="-l -c -s"

OPTIONS
-l Run the server in standalone (listen) mode, rather than run from
inetd. In listen mode, the -t option is ignored, and the -a
option can be used to specify a specific local address or port
to listen to.

-a [address][:port]
Specify a specific address and port to listen to when called
with the -l option. The default is to listen to the tftp port
specified in /etc/services on all local addresses.
listen 的 ip address 和 Port
-c Allow new files to be created. By default, tftpd will only
allow upload of files that already exist. Files are created
with default permissions allowing anyone to read or write them,
unless the -p or -U options are specified.

-s (决定tftp根目录)Change root directory on startup. This means the remote host
does not need to pass along the directory as part of the trans-
fer, and may add security. When -s is specified, exactly one
directory should be specified on the command line. The use of
this option is recommended for security as well as compatibility
with some boot ROMs which cannot be easily made to include a
directory name in its request.

debian下方法

31 检查一下配置文件的权限:

stat /etc/inetd.conf
  File: `/etc/inetd.conf'
  Size: 1139       Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d Inode: 167025      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-10-25 22:03:34.803054929 -0700
Modify: 2012-10-25 22:02:58.983057568 -0700
Change: 2012-10-25 22:02:59.035057567 -0700

32 权限ok话,做如下修改:

加入:tftp  dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /home/wine/tftpboot 到文件/etc/inetd.conf里面

注意我的是 /home/wine/下工作目录

redhat下方法

修改如下文件,当然如果没有你可能需要重新建一个

[root@gliethttp root]# vim /etc/xinetd.d/tftp                  
  将server_args配置项为你自己的tftpboot根目录
  将disable 配置为no
  service tftp
  {
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /tftpboot
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
  }

 

 

 


 4 重启tftp服务:

ubuntu 下方法

service tftpd-hpa restart

 

debian下方法

sudo /etc/init.d/inetd reload

sudo /etc/init.d/xinetd restart

 

其他可能需要的服务:

1 cd /etc/init.d/

./inetutils-inetd restart

2 sudo in.tftpd -l /tftpboot


5 测试tftp在本机是否工作

51 我的主机本机host地址:192.168.0.1

$ cd /home/wine/tftpboot/

$ echo "hello tftp service">>a.txt  #生成一个测试文件,在tftp root 文件夹下

$cd /home/wine

$echo "hello tftp service,put to tftp serive">>send.text  #在tftp root文件夹外做一个文件准备传进去

root@ubuntu:/home/wine# tftp 192.168.0.1
tftp 192.168.0.1
tftp> get a.txt
tftp> q
root@ubuntu:/home/wine# ls
ls
a.txt   send.text  tftpboot  

可以看到a.txt已经传输过来了,然后我们要检查一下他的内容,因为错误传输,也会生出一个同名空文件

root@ubuntu:/home/wine# vim a.txt
vim a.txt

没问题的话,再往里面传一个

root@ubuntu:/home/wine# tftp 192.168.0.1
tftp 192.168.0.1
tftp> put send.txt
tftp: send.txt: No such file or directory
tftp> put send.text
tftp> q
root@ubuntu:/home/wine# cd tftpboot/
cd tftpboot/
root@ubuntu:/home/wine/tftpboot# ls
ls
a.txt  send.text  test  vmlinux.in

 

52 tftp tftpserver.test.net


6 uboot中对应的设置选项:

6.1 serverip 

set serverip 192.168.0.1

6.2 bootcmd

bootcmd=tftp vmlinux.bin; go [系统启动RAM地址] #这里假设要烧kernel

 


使用tftp下载linux kernel到目标板:

1 生成kernel编译

2 cp 生成的kernel文件vmlinux,到tftp的root文件夹:/home/wine/tftpboot

3 上电启动打印:

and the test passed in uboot log:
TFTP from server 192.168.0.1; our IP address is 你的板子的ip地址
Filename 'vmlinux.bin'.
Load address: 【你的地址启动】
Loading: #################################################################
         #################################################################
         #################################################################

 


ref:

http://lesca.me/archives/set-up-tftp-server-on-ubuntu.html

http://www.cnblogs.com/shenhaocn/archive/2011/03/13/1983042.html

http://hi.baidu.com/yjicllignqbkovq/item/b257179368e6c1d97b7f0123

http://my.opera.com/volans/blog/show.dml/680197

http://doc.chinaunix.net/linux/201208/2311353.shtml


附录:
inetd (Internet 超级服务器 )
     inetd是监视一些网络请求的守护进程,其根据网络请求来调用相应的服务进程来处理连接请求。它可以为多种服务管理连接,当 inetd 接到连接时,它能够确定连接所需的程序,启动相应的进程,并把 socket 交给它 (服务 socket 会作为程序的标准输入、 输出和错误输出描述符)。 使用 inetd 来运行那些负载不重的服务有助于降低系统负载,因为它不需要为每个服务都启动独立的服务程序。
      一般说来, inetd 主要用于启动其它服务程序,但它也有能力直接处理某些简单的服务, 例如 chargen、 auth, 以及 daytime。
     inetd 是通过rc系统启动的。 inetd_enable 选项默认设为 NO,但可以在安装系统时, 由用户根据需要通过 sysinstall 来打开。
     inetd.conf则是inetd的配置文件。 inetd.conf文件告诉inetd监听哪些网络端口,为每个端口启动哪个服务。在任何的网络环境中使用Linux系统,第一件要做的事就是了解一下 服务器到底要提供哪些服务。不需要的那些服务应该被禁止掉,最好卸载掉,这样黑客就少了一些攻击系统的机会。查看 “/etc/inetd.conf”文件,了解一下inetd提供哪些服务。用加上注释的方法(在一行的开头加上#号),禁止任何不需要的服务,再给 inetd进程发一个SIGHUP信号。

the settings for ineted.conf file

http://www.faqs.org/docs/securing/chap5sec36.html


注意事项:

1 iptables

如果关不掉,直接卸载:sudo apt-get remove iptables

2 服务器地址错误,或者连接硬件问题

3

 

 


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 2

    粉丝
  • 1

    好友
  • 2

    获赞
  • 14

    评论
  • 3241

    访问数
关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-23 14:02 , Processed in 0.030435 second(s), 15 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部