tftpnaive.c
来自「2410 boot loader,usb ftp」· C语言 代码 · 共 126 行
C
126 行
/* Copyright 2001-2004 Georges Menie (www.menie.org) This file is part of Tftpnaive. Tftpnaive is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Tftpnaive is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Tftpnaive; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include "tftpnaive.h"#include "baselib.h"#include "timer.h"#define RETRYCOUNT 5extern unsigned int downloadFileSize;#if TFTPNAIVE_TIMEREQUESTstatic void getTime (){ int ts, h, m, s; /* send a timestamp request to the TFTP server, * to get it's GMT time of the day */ if (tftp_req) { if ((ts = netTimestampRequest (tftp_req->server)) != 0) { ts = (ts + 500) / 1000; /* round to secs */ h = (ts / 3600) % 24; m = (ts / 60) % 60; s = ts % 60; setTime (h, m, s); Uart_Printf ("GMT time is %d:%d:%d\n", h, m, s); } }}#endifint tftpnaive (TFTPDownload *tftp){ int error; int retry=RETRYCOUNT, crcretry=RETRYCOUNT; downloadFileSize = 0;crcretry_again: Uart_Printf("\n"); timerInit (); /* initialize the network chip, loop until it's ready */ while (((error = netUp (tftp->mac)) != 0) && retry) { if (error != ERR_LINK) Uart_Printf ("Network interface init failed: code %d\n", error); else Uart_Printf ("No network, cable problem ?\n"); usleep (1000000); retry--; } if(!retry) goto fail; else retry=RETRYCOUNT; while (retry) { /* request an IP address through BOOTP */ if(tftp->mode==1) // BOOTP + TFTP netRequestIP (); else // TFTP directBOOTP(tftp->local_ip, tftp->remote_ip, tftp->file);#if TFTPNAIVE_TIMEREQUEST getTime ();#endif /* bootstrap using TFTP */ if (netBoot (tftp->downaddr) == 0) break; usleep (1000000); retry--; } /* shutdown the network chip */ netDown (); /* if the download is successfull and * a start address has been given, jump to it */ Led_Display(15);fail: if(downloadFileSize==0xffffffff) { if(crcretry) { Uart_Printf("CRC Error, Retry...\n"); crcretry--; goto crcretry_again; } else downloadFileSize = 0; } else if (downloadFileSize==0) { Uart_Printf("Download Failed!!!\n"); return -1; } return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?