现在的位置: 首页 > 综合 > 正文

uboot中使用tftp命令下载

2013年02月27日 ⁄ 综合 ⁄ 共 6271字 ⁄ 字号 评论关闭

uboot 提供了tftp命令,可以连接到tftp服务器以下载文件
虚拟机fedora9下,安装tftp服务
yum install xinetd
yum install tftp tftp-server
下面是我的tftp配置

[root@localhost /]# cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
#    protocol.  The tftp protocol is often used to boot diskless \
#    workstations, download configuration files to network-aware printers, \
#    and to start the installation process for some operating systems.
service tftp
{
    socket_type        = dgram
    protocol        = udp
    wait            = yes
    user            = root
    server            = /usr/sbin/in.tftpd
    server_args        = -s /tftpboot -c
    disable            = no
    per_source        = 11
    cps            = 100 2
    flags            = IPv4
}

server_args指定tftp的目录,我这里是一个链接,指向源码的boot目录
ln -s  /opt/FriendlyARM/mini2440/linux-2.6.32.2/arch/arm/boot/  /tftpboot

然后将目录权限增大一点,以防万一
chmod 777 /opt/FriendlyARM/mini2440/linux-2.6.32.2/arch/arm/boot/
还需将selinux关闭。在桌面菜单,系统--》管理--》selinux management ,在status页,将 system defalut Enforcing Mode 设置为 Disabled ,将current enforcing mode 改为permissive
用命令serviceconf确认一下tftp服务有没开启,需将其打开
关闭防火墙 /etc/init.d/iptables stop

现在本机测试一下

[root@localhost /]touch testfile //在当前目录下创建一个文件
[root@localhost /]# tftp 192.168.1.116
tftp> put testfile//将当前目录的文件上传到tftp服务器的服务目录即/tftpboot
tftp> 
tftp> ^\Quit
[root@localhost /]# ls /tftpboot/
bootp  compressed  Image  install.sh  Makefile  testfile  zImage

在开发板uboot下如果serverip不是主机ip需要
setenv  serverip 192.168.1.116(我的fedora ip)

saveenv
另外,板子的一些环境变量如下

EmbedSky> printenv
bootcmd=nboot 0x32000000 kernel; bootm 0x32000000
bootdelay=0
baudrate=115200
ethaddr=0a:1b:2c:3d:4e:5f
ipaddr=192.168.1.6
netmask=255.255.255.0
mtdids=nand0=nandflash0
mtdparts=mtdparts=nandflash0:256k@0(bios),128k(params),128k(toc),512k(eboot),1024k(logo),2m(kernel),-(root)
filesize=0
filesize+1=0
fileaddr=30000000
bootargs=noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0
serverip=192.168.1.116
stdin=serial
stdout=serial
stderr=serial
partition=nand0,0
mtddevnum=0
mtddevname=bios

Environment size: 497/131068 bytes

此时使用tftp便可从虚拟机上下载文件了
比如
tftp 32000000 zImage.img

refer to
http://bbs.chinaunix.net/thread-2025289-1-1.html


2012-5-1 17
关于xinetd服务,仔细看下面的几行
refer to begging linux programming


比如

[root@localhost chapter15]# ll /etc/xinetd.d/
total 60
-rw-r--r-- 1 root root 1157 2008-01-31 23:13 chargen-dgram
-rw-r--r-- 1 root root 1159 2008-01-31 23:13 chargen-stream
-rw-r--r-- 1 root root  523 2008-02-20 09:47 cvs
-rw-r--r-- 1 root root 1144 2012-05-01 17:45 daytime-dgram
-rw-r--r-- 1 root root 1146 2012-05-01 17:45 daytime-stream
-rw-r--r-- 1 root root 1157 2008-01-31 23:13 discard-dgram
-rw-r--r-- 1 root root 1159 2008-01-31 23:13 discard-stream
-rw-r--r-- 1 root root 1148 2008-01-31 23:13 echo-dgram
-rw-r--r-- 1 root root 1150 2008-01-31 23:13 echo-stream
-rw-r--r-- 1 root root  332 2008-04-09 04:59 rsync
-rw-r--r-- 1 root root 1212 2008-01-31 23:13 tcpmux-server
-rw-r--r-- 1 root root  510 2012-04-17 09:11 tftp
-rw-r--r-- 1 root root  515 2012-04-17 09:12 tftp~
-rw-r--r-- 1 root root 1149 2008-01-31 23:13 time-dgram
-rw-r--r-- 1 root root 1150 2008-01-31 23:13 time-stream


****************************
ubunt 11.04下安装tftp

安装tftpd-hpa版本的tftp服务器

1. sudo apt-get install tftp-hpa tftpd-hpa

   sudo apt-get install xinetd

   sudo apt-get install netkit-inetd

2. cd /

      sudo mkdir /tftpboot

       sudo chmod 777 /tftpboot

打开目录 /etc/xinetd.d/

新建文件tftp
service tftp

{
          socket_type               = dgram
          protocol                  = udp
          wait                      = yes
          user                      = root
          server                    = /usr/sbin/in.tftpd
          server_args               = -s /tftpboot -c
          disable                   = no
          per_source                = 11
          cps                       = 100 2
          flags                     = IPv4
}

3.建立tftp服务文件目录
mkdir /tftpboot

4.重启服务
sudo /etc/init.d/xinetd restart
sudo in.tftpd -l /tftpboot

5.测试
tftp服务器启动成功之后,有如下现象

root@song-virtual-machine:/# ps -el |grep tftp
4 S     0  6630  4679  0  80   0 -   591 poll_s ?        00:00:00 in.tftpd

或安装tftp版本的tftp服务器
refer to http://hi.baidu.com/%CF%E3%BF%CD/blog/item/e14723f463afaa6fddc474b3.html
1、安装相关软件包
apt-get install tftpd     (服务端)
apt-get install tftp     (客户端)  
apt-get install xinetd 
2、建立配置文件
cd /etc/xinetd.d/
vi tftp
输入
service tftp
{
          socket_type               = dgram
          protocol                  = udp
          wait                      = yes
          user                      = root
          server                    = /usr/sbin/in.tftpd
          server_args               = -s /tftpboot -c
          disable                   = no
          per_source                = 11
          cps                       = 100 2
          flags                     = IPv4
}
存盘退出
3、建立tftp服务文件目录
     mkdir /tftpboot
chmod +x tftpboot  //仅目录赋予执行权限即可。如果tftpboot是连接,则仅需要源目录有可执行权限即可。
4、重启服务
     /etc/init.d/xinetd restart
安装完成!
测试方法:
在/tftpboot 目录下随便放个文件abc
然后 运行tftp 192.168.123.202 进入tftp命令行
输入get abc 看看是不是能把文件下下来,如果可以就可以了,也可以put 文件上去


以上两种tftp服务器只需启动一个即可。如果一个不行可以切换另一个看看,可以使用新立得软件管理器管理,管理/系统管理/新立得软件包管理器,搜索tftp,如下
当然使用新立得软件包管理器也可以安装tftp服务器,这样就不用手动写前面的代码区安装了。
双击其中某项。

如果总是出错,比如transfer time out。解决方法:切换为使用tftp-hpa服务器。使用新立得软件包管理器可以切换。
比如Error code 1: File not found  执行/etc/init.d/xinetd restart。比如在改变了tftpboot目录时就会出现Error code 1: File not found,此时执行一下即可。

2012-12-7 21:56:12
http://blog.csdn.net/mowwwcom/article/details/8113143
1.下载服务器和客户端
tftp-hpa是客户端,

tftpd-hpa是服务器端 

xinetd是服务器管理工具

#sudo aptitude install tftp-hpa tftpd-hpa xinetd

2.配置TFTP服务器
#sudo gedit /etc/default/tftpd-hpa

# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure"
该为
#/etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot" 
TFTP_ADDRESS="0.0.0.0:69" 
TFTP_OPTIONS="-l –c -s"

3.创建tftp根目录
在根目录下创建tftpboot目录,将权限设置成777 
#mkdir –m 777 /tftpboot

4.重启tftp
#sudo service tftpd-hpa restart


5、配置xinetd
#gedit /etc/xinetd.conf
------------------添加内容-------------------

 # Simple configuration file for xinetd   
 #   
 # Some defaults, and include /etc/xinetd.d/   
 defaults   
 {   
 # Please note that you need a log_type line to be able 

to use log_on_success   
 # and log_on_failure. The default is the following :   
 # log_type = SYSLOG daemon info   
 }   
 includedir /etc/xinetd.d  

#gedit /etc/xinetd.d/tftp
------------------添加内容-------------------
service tftp
{
disable         = no
socket_type     = dgram
protocol        = udp
wait            = yes
user            = root
server          = /usr/sbin/in.tftpd
server_args     = -s /tftpboot -c
source          = 11
cps             = 100 2
flags =IPv4
}

执行
#/etc/init.d/xinetd reload;/etc/init.d/xinetd restart
#/etc/init.d/xinetd restart


6.测试
#cd /tftpboot 
#echo "hello tftp service">>a.txt 

#cd ~ 
#echo "hello tftp service,put to tftp serive">>b.txt 

#tftp localhost
#get a.txt 
#put b.txt 

其中get是取得文件,put是将文件上传到TFTP服务器上。

ubuntu 11.04下安装nfs及配置

抱歉!评论已关闭.