From patchwork Mon Jun 13 23:13:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 100188 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 28309B6FA8 for ; Tue, 14 Jun 2011 09:14:48 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B6D6128186; Tue, 14 Jun 2011 01:14:46 +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 Khttq4LQ3mXM; Tue, 14 Jun 2011 01:14:46 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EDA8C2816C; Tue, 14 Jun 2011 01:14:44 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1425D2816C for ; Tue, 14 Jun 2011 01:14:42 +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 uoqlPRtXwLwm for ; Tue, 14 Jun 2011 01:14:41 +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 smtp-out.google.com (smtp-out.google.com [74.125.121.67]) by theia.denx.de (Postfix) with ESMTPS id 0B95928168 for ; Tue, 14 Jun 2011 01:14:39 +0200 (CEST) Received: from hpaq13.eem.corp.google.com (hpaq13.eem.corp.google.com [172.25.149.13]) by smtp-out.google.com with ESMTP id p5DNDd5f024737; Mon, 13 Jun 2011 16:13:39 -0700 Received: from sglass.mtv.corp.google.com (sglass.mtv.corp.google.com [172.22.72.144]) by hpaq13.eem.corp.google.com with ESMTP id p5DNDb1f028786; Mon, 13 Jun 2011 16:13:38 -0700 Received: by sglass.mtv.corp.google.com (Postfix, from userid 121222) id 85362140BC5; Mon, 13 Jun 2011 16:13:37 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 13 Jun 2011 16:13:12 -0700 Message-Id: <1308006792-22544-5-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1308006792-22544-1-git-send-email-sjg@chromium.org> References: <1308006792-22544-1-git-send-email-sjg@chromium.org> MIME-Version: 1.0 X-System-Of-Record: true Cc: Andy Fleming Subject: [U-Boot] [PATCH v8 4/4] Put common autoload code into auto_load() function 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: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This is a small clean-up patch. Changes for v8: - Fix typo in auto_load Signed-off-by: Simon Glass Tested-by: Eric BĂ©nard --- net/bootp.c | 76 +++++++++++++++++++++++++--------------------------------- 1 files changed, 33 insertions(+), 43 deletions(-) diff --git a/net/bootp.c b/net/bootp.c index 4db63cb..cd9e71d 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -138,6 +138,36 @@ static int truncate_sz (const char *name, int maxlen, int curlen) return (curlen); } +/* + * Check if autoload is enabled. If so, use either NFS or TFTP to download + * the boot file. + */ +static void auto_load(void) +{ + const char *s = getenv("autoload"); + + if (s != NULL) { + if (*s == 'n') { + /* + * Just use BOOTP to configure system; + * Do not use TFTP to load the bootfile. + */ + NetState = NETLOOP_SUCCESS; + return; + } +#if defined(CONFIG_CMD_NFS) + if (strcmp(s, "NFS") == 0) { + /* + * Use NFS to load the bootfile. + */ + NfsStart(); + return; + } +#endif + TftpStart(); + } +} + #if !defined(CONFIG_CMD_DHCP) static void BootpVendorFieldProcess (u8 * ext) @@ -279,6 +309,7 @@ static void BootpVendorProcess (u8 * ext, int size) if (NetBootFileSize) debug("NetBootFileSize: %d\n", NetBootFileSize); } + /* * Handle a BOOTP received packet. */ @@ -287,7 +318,6 @@ BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len) { Bootp_t *bp; - char *s; debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n", src, dest, len, sizeof (Bootp_t)); @@ -314,26 +344,7 @@ BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, debug("Got good BOOTP\n"); - if ((s = getenv("autoload")) != NULL) { - if (*s == 'n') { - /* - * Just use BOOTP to configure system; - * Do not use TFTP to load the bootfile. - */ - NetState = NETLOOP_SUCCESS; - return; -#if defined(CONFIG_CMD_NFS) - } else if (strcmp(s, "NFS") == 0) { - /* - * Use NFS to load the bootfile. - */ - NfsStart(); - return; -#endif - } - } - - TftpStart(); + auto_load(); } #endif @@ -907,34 +918,13 @@ DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, debug("DHCP State: REQUESTING\n"); if ( DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK ) { - char *s; - if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC)) DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp); BootpCopyNetParams(bp); /* Store net params from reply */ dhcp_state = BOUND; printf ("DHCP client bound to address %pI4\n", &NetOurIP); - /* Obey the 'autoload' setting */ - if ((s = getenv("autoload")) != NULL) { - if (*s == 'n') { - /* - * Just use BOOTP to configure system; - * Do not use TFTP to load the bootfile. - */ - NetState = NETLOOP_SUCCESS; - return; -#if defined(CONFIG_CMD_NFS) - } else if (strcmp(s, "NFS") == 0) { - /* - * Use NFS to load the bootfile. - */ - NfsStart(); - return; -#endif - } - } - TftpStart(); + auto_load(); return; } break;