From patchwork Tue May 17 10:03:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 95898 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 304081007D1 for ; Tue, 17 May 2011 20:04:58 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B912D28114; Tue, 17 May 2011 12:04:48 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5bCxsoJxCaB0; Tue, 17 May 2011 12:04:48 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7F28D280FA; Tue, 17 May 2011 12:04:33 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 72BEF280C5 for ; Tue, 17 May 2011 12:04:30 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yqANe3FcdJXD for ; Tue, 17 May 2011 12:04:29 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from relayer.comelit.it (mail.comelit.it [217.56.59.218]) by theia.denx.de (Postfix) with ESMTP id AC684280E4 for ; Tue, 17 May 2011 12:04:22 +0200 (CEST) Received: from com-exc-01.comelit.it ([172.24.0.31]) by relayer.comelit.it with Microsoft SMTPSVC(6.0.3790.1830); Tue, 17 May 2011 12:02:20 +0200 Received: from wallace.comelit.it ([172.20.0.35]) by com-exc-01.comelit.it with Microsoft SMTPSVC(6.0.3790.4675); Tue, 17 May 2011 12:04:21 +0200 From: Luca Ceresoli To: u-boot@lists.denx.de Date: Tue, 17 May 2011 12:03:40 +0200 Message-Id: <1305626621-15008-5-git-send-email-luca.ceresoli@comelit.it> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1303143594-5345-1-git-send-email-luca.ceresoli@comelit.it> References: <1303143594-5345-1-git-send-email-luca.ceresoli@comelit.it> X-OriginalArrivalTime: 17 May 2011 10:04:21.0480 (UTC) FILETIME=[CAE97E80:01CC1479] X-TM-AS-Product-Ver: SMEX-8.6.0.1168-6.500.1024-18140.005 X-TM-AS-Result: No--13.779600-8.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No Cc: Luca Ceresoli Subject: [U-Boot] [PATCH v3 4/5] TFTP: add tftpsrv command X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Signed-off-by: Luca Ceresoli Cc: Wolfgang Denk Acked-by: Detlev Zundel --- Changes in v2: none. Changes in v3: - rebased on top of the net/tftp.c cleanup; - made do_tftpsrv() static; - improved tftpsrv command help; - removed all #ifdefs that used to remove negligible amounts of compiled code, at the cost of a much less readable source file; after measurements, it turned out this change does not increase code size. README | 1 + common/cmd_net.c | 17 +++++++++++++++++ include/net.h | 3 ++- net/net.c | 7 ++++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README b/README index 6f3748d..ed73981 100644 --- a/README +++ b/README @@ -709,6 +709,7 @@ The following options need to be configured: (requires CONFIG_CMD_MEMORY) CONFIG_CMD_SOURCE "source" command Support CONFIG_CMD_SPI * SPI serial bus support + CONFIG_CMD_TFTPSRV * TFTP transfer in server mode CONFIG_CMD_USB * USB support CONFIG_CMD_VFD * VFD support (TRAB) CONFIG_CMD_CDP * Cisco Discover Protocol support diff --git a/common/cmd_net.c b/common/cmd_net.c index 8c6f5c8..b2c9355 100644 --- a/common/cmd_net.c +++ b/common/cmd_net.c @@ -52,6 +52,23 @@ U_BOOT_CMD( "[loadAddress] [[hostIPaddr:]bootfilename]" ); +#ifdef CONFIG_CMD_TFTPSRV +static int do_tftpsrv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + return netboot_common(TFTPSRV, cmdtp, argc, argv); +} + +U_BOOT_CMD( + tftpsrv, 2, 1, do_tftpsrv, + "act as a TFTP server and boot the first received file", + "[loadAddress]\n" + "Listen for an incoming TFTP transfer, receive a file and boot it.\n" + "The transfer is aborted if a transfer has not been started after\n" + "about 50 seconds or if Ctrl-C is pressed." +); +#endif + + #ifdef CONFIG_CMD_RARP int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { diff --git a/include/net.h b/include/net.h index 01f7159..018a744 100644 --- a/include/net.h +++ b/include/net.h @@ -364,7 +364,8 @@ extern int NetState; /* Network loop state */ extern int NetRestartWrap; /* Tried all network devices */ #endif -typedef enum { BOOTP, RARP, ARP, TFTP, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP } proto_t; +typedef enum { BOOTP, RARP, ARP, TFTP, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP, + TFTPSRV } proto_t; /* from net/net.c */ extern char BootFile[128]; /* Boot File name */ diff --git a/net/net.c b/net/net.c index 2abf879..7a93542 100644 --- a/net/net.c +++ b/net/net.c @@ -423,7 +423,11 @@ restart: /* always use ARP to get server ethernet address */ TftpStart(); break; - +#ifdef CONFIG_CMD_TFTPSRV + case TFTPSRV: + TftpStartServer(); + break; +#endif #if defined(CONFIG_CMD_DHCP) case DHCP: BootpTry = 0; @@ -1791,6 +1795,7 @@ common: /* Fall through */ case NETCONS: + case TFTPSRV: if (NetOurIP == 0) { puts("*** ERROR: `ipaddr' not set\n"); return 1;