]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - net/nfs.c
Merge branch '080131_artila' of git://linux-arm.org/u-boot-armdev
[karo-tx-uboot.git] / net / nfs.c
index 300c08fa9678e7424ecce80054acc4cdb67059d9..6573c1716bb07fd731f5a03426cf1fd4cedb84ba 100644 (file)
--- a/net/nfs.c
+++ b/net/nfs.c
 
 /*#define NFS_DEBUG*/
 
-#if ((CONFIG_COMMANDS & CFG_CMD_NET) && (CONFIG_COMMANDS & CFG_CMD_NFS))
+#if defined(CONFIG_CMD_NET) && defined(CONFIG_CMD_NFS)
 
 #define HASHES_PER_LINE 65     /* Number of "loading" hashes per line  */
-#define NFS_TIMEOUT 10
+#define NFS_RETRY_COUNT 30
+#define NFS_TIMEOUT 2UL
 
 static int fs_mounted = 0;
 static unsigned long rpc_id = 0;
@@ -44,6 +45,7 @@ static int nfs_len;
 static char dirfh[NFS_FHSIZE]; /* file handle of directory */
 static char filefh[NFS_FHSIZE]; /* file handle of kernel image */
 
+static int     NfsDownloadState;
 static IPaddr_t NfsServerIP;
 static int     NfsSrvMountPort;
 static int     NfsSrvNfsPort;
@@ -63,7 +65,7 @@ static char *nfs_filename;
 static char *nfs_path;
 static char nfs_path_buff[2048];
 
-static __inline__ void
+static __inline__ int
 store_block (uchar * src, unsigned offset, unsigned len)
 {
        ulong newsize = offset + len;
@@ -82,8 +84,7 @@ store_block (uchar * src, unsigned offset, unsigned len)
                rc = flash_write ((uchar *)src, (ulong)(load_addr+offset), len);
                if (rc) {
                        flash_perror (rc);
-                       NetState = NETLOOP_FAIL;
-                       return;
+                       return -1;
                }
        } else
 #endif /* CFG_DIRECT_FLASH_NFS */
@@ -93,6 +94,7 @@ store_block (uchar * src, unsigned offset, unsigned len)
 
        if (NetBootFileXferSize < (offset+len))
                NetBootFileXferSize = newsize;
+       return 0;
 }
 
 static char*
@@ -404,7 +406,6 @@ rpc_lookup_reply (int prog, uchar *pkt, unsigned len)
 
        if (rpc_pkt.u.reply.rstatus  ||
            rpc_pkt.u.reply.verifier ||
-           rpc_pkt.u.reply.astatus  ||
            rpc_pkt.u.reply.astatus) {
                return -1;
        }
@@ -573,7 +574,8 @@ nfs_read_reply (uchar *pkt, unsigned len)
        }
 
        rlen = ntohl(rpc_pkt.u.reply.data[18]);
-       store_block ((uchar *)pkt+sizeof(rpc_pkt.u.reply), nfs_offset, rlen);
+       if ( store_block ((uchar *)pkt+sizeof(rpc_pkt.u.reply), nfs_offset, rlen) )
+               return -9999;
 
        return rlen;
 }
@@ -582,6 +584,18 @@ nfs_read_reply (uchar *pkt, unsigned len)
 Interfaces of U-BOOT
 **************************************************************************/
 
+static void
+NfsTimeout (void)
+{
+       if ( NfsTimeoutCount++ < NFS_RETRY_COUNT ) {
+               NfsSend ();
+               return;
+       }
+       puts ("Timeout\n");
+       NetState = NETLOOP_FAIL;
+       return;
+}
+
 static void
 NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
 {
@@ -624,7 +638,7 @@ NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
                        NetState = NETLOOP_FAIL;
                } else {
                        puts ("\ndone\n");
-                       NetState = NETLOOP_SUCCESS;
+                       NetState = NfsDownloadState;
                }
                break;
 
@@ -660,6 +674,7 @@ NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
 
        case STATE_READ_REQ:
                rlen = nfs_read_reply (pkt, len);
+               NetSetTimeout (NFS_TIMEOUT * CFG_HZ, NfsTimeout);
                if (rlen > 0) {
                        nfs_offset += rlen;
                        NfsSend ();
@@ -669,6 +684,7 @@ NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
                        NfsState = STATE_READLINK_REQ;
                        NfsSend ();
                } else {
+                       if ( ! rlen ) NfsDownloadState = NETLOOP_SUCCESS;
                        NfsState = STATE_UMOUNT_REQ;
                        NfsSend ();
                }
@@ -676,13 +692,6 @@ NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
        }
 }
 
-static void
-NfsTimeout (void)
-{
-       puts ("Timeout\n");
-       NetState = NETLOOP_FAIL;
-       return;
-}
 
 void
 NfsStart (void)
@@ -690,6 +699,7 @@ NfsStart (void)
 #ifdef NFS_DEBUG
        printf ("%s\n", __FUNCTION__);
 #endif
+       NfsDownloadState = NETLOOP_FAIL;
 
        NfsServerIP = NetServerIP;
        nfs_path = (char *)nfs_path_buff;
@@ -701,13 +711,11 @@ NfsStart (void)
        }
 
        if (BootFile[0] == '\0') {
-               IPaddr_t OurIP = ntohl (NetOurIP);
-
                sprintf (default_filename, "/nfsroot/%02lX%02lX%02lX%02lX.img",
-                       OurIP & 0xFF,
-                       (OurIP >>  8) & 0xFF,
-                       (OurIP >> 16) & 0xFF,
-                       (OurIP >> 24) & 0xFF    );
+                       NetOurIP & 0xFF,
+                       (NetOurIP >>  8) & 0xFF,
+                       (NetOurIP >> 16) & 0xFF,
+                       (NetOurIP >> 24) & 0xFF );
                strcpy (nfs_path, default_filename);
 
                printf ("*** Warning: no boot file name; using '%s'\n",
@@ -771,4 +779,4 @@ NfsStart (void)
        NfsSend ();
 }
 
-#endif /* CONFIG_COMMANDS & CFG_CMD_NFS */
+#endif