Put common autoload code into auto_load() function
authorSimon Glass <sjg@chromium.org>
Mon, 13 Jun 2011 23:13:12 +0000 (16:13 -0700)
committerRemy Bohmer <linux@bohmer.net>
Mon, 8 Aug 2011 19:05:23 +0000 (21:05 +0200)
This is a small clean-up patch.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric BĂ©nard <eric@eukrea.com>
net/bootp.c

index 45eaab1e0582c272a075b2adb57e67b9ea0d5926..3db08ea2f31583443ee11581763bac4d1fccb2a8 100644 (file)
@@ -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)
@@ -289,6 +319,7 @@ static void BootpVendorProcess (u8 * ext, int size)
                debug("NetNtpServerIP : %pI4\n", &NetNtpServerIP);
 #endif
 }
+
 /*
  *     Handle a BOOTP received packet.
  */
@@ -297,7 +328,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));
@@ -324,26 +354,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
 
@@ -922,34 +933,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;