]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - net/nfs.c
Merge branch 'master' of git://git.denx.de/u-boot-microblaze
[karo-tx-uboot.git] / net / nfs.c
index aa8d612e5847a8f204f6ab7ef04c6b423fdea4e0..7f2393f6064c62976ea3bf0c5f10a2ac22e7d443 100644 (file)
--- a/net/nfs.c
+++ b/net/nfs.c
 #include "nfs.h"
 #include "bootp.h"
 
-/*#define NFS_DEBUG*/
-
-#if defined(CONFIG_CMD_NET) && defined(CONFIG_CMD_NFS)
-
 #define HASHES_PER_LINE 65     /* Number of "loading" hashes per line  */
-#define NFS_TIMEOUT 60UL
+#define NFS_RETRY_COUNT 30
+#ifndef CONFIG_NFS_TIMEOUT
+# define NFS_TIMEOUT 2000UL
+#else
+# define NFS_TIMEOUT CONFIG_NFS_TIMEOUT
+#endif
 
-static int fs_mounted = 0;
-static unsigned long rpc_id = 0;
+static int fs_mounted;
+static unsigned long rpc_id;
 static int nfs_offset = -1;
 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 enum net_loop_state nfs_download_state;
 static IPaddr_t NfsServerIP;
 static int     NfsSrvMountPort;
 static int     NfsSrvNfsPort;
@@ -64,14 +65,14 @@ static char *nfs_filename;
 static char *nfs_path;
 static char nfs_path_buff[2048];
 
-static __inline__ int
-store_block (uchar * src, unsigned offset, unsigned len)
+static inline int
+store_block(uchar *src, unsigned offset, unsigned len)
 {
        ulong newsize = offset + len;
-#ifdef CFG_DIRECT_FLASH_NFS
+#ifdef CONFIG_SYS_DIRECT_FLASH_NFS
        int i, rc = 0;
 
-       for (i=0; i<CFG_MAX_FLASH_BANKS; i++) {
+       for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) {
                /* start address in flash? */
                if (load_addr + offset >= flash_info[i].start[0]) {
                        rc = 1;
@@ -80,15 +81,15 @@ store_block (uchar * src, unsigned offset, unsigned len)
        }
 
        if (rc) { /* Flash is destination for this packet */
-               rc = flash_write ((uchar *)src, (ulong)(load_addr+offset), len);
+               rc = flash_write((uchar *)src, (ulong)(load_addr+offset), len);
                if (rc) {
-                       flash_perror (rc);
+                       flash_perror(rc);
                        return -1;
                }
        } else
-#endif /* CFG_DIRECT_FLASH_NFS */
+#endif /* CONFIG_SYS_DIRECT_FLASH_NFS */
        {
-               (void)memcpy ((void *)(load_addr + offset), src, len);
+               (void)memcpy((void *)(load_addr + offset), src, len);
        }
 
        if (NetBootFileXferSize < (offset+len))
@@ -97,7 +98,7 @@ store_block (uchar * src, unsigned offset, unsigned len)
 }
 
 static char*
-basename (char *path)
+basename(char *path)
 {
        char *fname;
 
@@ -113,11 +114,11 @@ basename (char *path)
 }
 
 static char*
-dirname (char *path)
+dirname(char *path)
 {
        char *fname;
 
-       fname = basename (path);
+       fname = basename(path);
        --fname;
        *fname = '\0';
        return path;
@@ -126,14 +127,14 @@ dirname (char *path)
 /**************************************************************************
 RPC_ADD_CREDENTIALS - Add RPC authentication/verifier entries
 **************************************************************************/
-static long *rpc_add_credentials (long *p)
+static long *rpc_add_credentials(long *p)
 {
        int hl;
        int hostnamelen;
        char hostname[256];
 
-       strcpy (hostname, "");
-       hostnamelen=strlen (hostname);
+       strcpy(hostname, "");
+       hostnamelen = strlen(hostname);
 
        /* Here's the executive summary on authentication requirements of the
         * various NFS server implementations:  Linux accepts both AUTH_NONE
@@ -151,10 +152,9 @@ static long *rpc_add_credentials (long *p)
        *p++ = htonl(hl+20);            /* auth length */
        *p++ = htonl(0);                /* stamp */
        *p++ = htonl(hostnamelen);      /* hostname string */
-       if (hostnamelen & 3) {
+       if (hostnamelen & 3)
                *(p + hostnamelen / 4) = 0; /* add zero padding */
-       }
-       memcpy (p, hostname, hostnamelen);
+       memcpy(p, hostname, hostnamelen);
        p += hl / 4;
        *p++ = 0;                       /* uid */
        *p++ = 0;                       /* gid */
@@ -171,7 +171,7 @@ static long *rpc_add_credentials (long *p)
 RPC_LOOKUP - Lookup RPC Port numbers
 **************************************************************************/
 static void
-rpc_req (int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
+rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
 {
        struct rpc_t pkt;
        unsigned long id;
@@ -189,11 +189,12 @@ rpc_req (int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
        p = (uint32_t *)&(pkt.u.call.data);
 
        if (datalen)
-               memcpy ((char *)p, (char *)data, datalen*sizeof(uint32_t));
+               memcpy((char *)p, (char *)data, datalen*sizeof(uint32_t));
 
        pktlen = (char *)p + datalen*sizeof(uint32_t) - (char *)&pkt;
 
-       memcpy ((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE, (char *)&pkt, pktlen);
+       memcpy((char *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE,
+               (char *)&pkt, pktlen);
 
        if (rpc_prog == PROG_PORTMAP)
                sport = SUNRPC_PORT;
@@ -202,14 +203,15 @@ rpc_req (int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
        else
                sport = NfsSrvNfsPort;
 
-       NetSendUDPPacket (NetServerEther, NfsServerIP, sport, NfsOurPort, pktlen);
+       NetSendUDPPacket(NetServerEther, NfsServerIP, sport, NfsOurPort,
+               pktlen);
 }
 
 /**************************************************************************
 RPC_LOOKUP - Lookup RPC Port numbers
 **************************************************************************/
 static void
-rpc_lookup_req (int prog, int ver)
+rpc_lookup_req(int prog, int ver)
 {
        uint32_t data[16];
 
@@ -220,56 +222,56 @@ rpc_lookup_req (int prog, int ver)
        data[6] = htonl(17);    /* IP_UDP */
        data[7] = 0;
 
-       rpc_req (PROG_PORTMAP, PORTMAP_GETPORT, data, 8);
+       rpc_req(PROG_PORTMAP, PORTMAP_GETPORT, data, 8);
 }
 
 /**************************************************************************
 NFS_MOUNT - Mount an NFS Filesystem
 **************************************************************************/
 static void
-nfs_mount_req (char *path)
+nfs_mount_req(char *path)
 {
        uint32_t data[1024];
        uint32_t *p;
        int len;
        int pathlen;
 
-       pathlen = strlen (path);
+       pathlen = strlen(path);
 
        p = &(data[0]);
        p = (uint32_t *)rpc_add_credentials((long *)p);
 
        *p++ = htonl(pathlen);
-       if (pathlen & 3) *(p + pathlen / 4) = 0;
-       memcpy (p, path, pathlen);
+       if (pathlen & 3)
+               *(p + pathlen / 4) = 0;
+       memcpy(p, path, pathlen);
        p += (pathlen + 3) / 4;
 
        len = (uint32_t *)p - (uint32_t *)&(data[0]);
 
-       rpc_req (PROG_MOUNT, MOUNT_ADDENTRY, data, len);
+       rpc_req(PROG_MOUNT, MOUNT_ADDENTRY, data, len);
 }
 
 /**************************************************************************
 NFS_UMOUNTALL - Unmount all our NFS Filesystems on the Server
 **************************************************************************/
 static void
-nfs_umountall_req (void)
+nfs_umountall_req(void)
 {
        uint32_t data[1024];
        uint32_t *p;
        int len;
 
-       if ((NfsSrvMountPort == -1) || (!fs_mounted)) {
+       if ((NfsSrvMountPort == -1) || (!fs_mounted))
                /* Nothing mounted, nothing to umount */
                return;
-       }
 
        p = &(data[0]);
-       p = (uint32_t *)rpc_add_credentials ((long *)p);
+       p = (uint32_t *)rpc_add_credentials((long *)p);
 
        len = (uint32_t *)p - (uint32_t *)&(data[0]);
 
-       rpc_req (PROG_MOUNT, MOUNT_UMOUNTALL, data, len);
+       rpc_req(PROG_MOUNT, MOUNT_UMOUNTALL, data, len);
 }
 
 /***************************************************************************
@@ -280,65 +282,66 @@ nfs_umountall_req (void)
  * so that inside the nfs() function a recursion can be done.
  **************************************************************************/
 static void
-nfs_readlink_req (void)
+nfs_readlink_req(void)
 {
        uint32_t data[1024];
        uint32_t *p;
        int len;
 
        p = &(data[0]);
-       p = (uint32_t *)rpc_add_credentials ((long *)p);
+       p = (uint32_t *)rpc_add_credentials((long *)p);
 
-       memcpy (p, filefh, NFS_FHSIZE);
+       memcpy(p, filefh, NFS_FHSIZE);
        p += (NFS_FHSIZE / 4);
 
        len = (uint32_t *)p - (uint32_t *)&(data[0]);
 
-       rpc_req (PROG_NFS, NFS_READLINK, data, len);
+       rpc_req(PROG_NFS, NFS_READLINK, data, len);
 }
 
 /**************************************************************************
 NFS_LOOKUP - Lookup Pathname
 **************************************************************************/
 static void
-nfs_lookup_req (char *fname)
+nfs_lookup_req(char *fname)
 {
        uint32_t data[1024];
        uint32_t *p;
        int len;
        int fnamelen;
 
-       fnamelen = strlen (fname);
+       fnamelen = strlen(fname);
 
        p = &(data[0]);
-       p = (uint32_t *)rpc_add_credentials ((long *)p);
+       p = (uint32_t *)rpc_add_credentials((long *)p);
 
-       memcpy (p, dirfh, NFS_FHSIZE);
+       memcpy(p, dirfh, NFS_FHSIZE);
        p += (NFS_FHSIZE / 4);
        *p++ = htonl(fnamelen);
-       if (fnamelen & 3) *(p + fnamelen / 4) = 0;
-       memcpy (p, fname, fnamelen);
+       if (fnamelen & 3)
+               *(p + fnamelen / 4) = 0;
+       memcpy(p, fname, fnamelen);
        p += (fnamelen + 3) / 4;
 
        len = (uint32_t *)p - (uint32_t *)&(data[0]);
 
-       rpc_req (PROG_NFS, NFS_LOOKUP, data, len);
+       rpc_req(PROG_NFS, NFS_LOOKUP, data, len);
 }
 
 /**************************************************************************
 NFS_READ - Read File on NFS Server
 **************************************************************************/
 static void
-nfs_read_req (int offset, int readlen)
+nfs_read_req(int offset, int readlen)
 {
        uint32_t data[1024];
        uint32_t *p;
        int len;
 
        p = &(data[0]);
-       p = (uint32_t *)rpc_add_credentials ((long *)p);
+       p = (uint32_t *)rpc_add_credentials((long *)p);
 
-       memcpy (p, filefh, NFS_FHSIZE);
+       memcpy(p, filefh, NFS_FHSIZE);
        p += (NFS_FHSIZE / 4);
        *p++ = htonl(offset);
        *p++ = htonl(readlen);
@@ -346,7 +349,7 @@ nfs_read_req (int offset, int readlen)
 
        len = (uint32_t *)p - (uint32_t *)&(data[0]);
 
-       rpc_req (PROG_NFS, NFS_READ, data, len);
+       rpc_req(PROG_NFS, NFS_READ, data, len);
 }
 
 /**************************************************************************
@@ -354,33 +357,31 @@ RPC request dispatcher
 **************************************************************************/
 
 static void
-NfsSend (void)
+NfsSend(void)
 {
-#ifdef NFS_DEBUG
-       printf ("%s\n", __FUNCTION__);
-#endif
+       debug("%s\n", __func__);
 
        switch (NfsState) {
        case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
-               rpc_lookup_req (PROG_MOUNT, 1);
+               rpc_lookup_req(PROG_MOUNT, 1);
                break;
        case STATE_PRCLOOKUP_PROG_NFS_REQ:
-               rpc_lookup_req (PROG_NFS, 2);
+               rpc_lookup_req(PROG_NFS, 2);
                break;
        case STATE_MOUNT_REQ:
-               nfs_mount_req (nfs_path);
+               nfs_mount_req(nfs_path);
                break;
        case STATE_UMOUNT_REQ:
-               nfs_umountall_req ();
+               nfs_umountall_req();
                break;
        case STATE_LOOKUP_REQ:
-               nfs_lookup_req (nfs_filename);
+               nfs_lookup_req(nfs_filename);
                break;
        case STATE_READ_REQ:
-               nfs_read_req (nfs_offset, nfs_len);
+               nfs_read_req(nfs_offset, nfs_len);
                break;
        case STATE_READLINK_REQ:
-               nfs_readlink_req ();
+               nfs_readlink_req();
                break;
        }
 }
@@ -390,24 +391,21 @@ Handlers for the reply from server
 **************************************************************************/
 
 static int
-rpc_lookup_reply (int prog, uchar *pkt, unsigned len)
+rpc_lookup_reply(int prog, uchar *pkt, unsigned len)
 {
        struct rpc_t rpc_pkt;
 
-       memcpy ((unsigned char *)&rpc_pkt, pkt, len);
+       memcpy((unsigned char *)&rpc_pkt, pkt, len);
 
-#ifdef NFS_DEBUG
-       printf ("%s\n", __FUNCTION__);
-#endif
+       debug("%s\n", __func__);
 
        if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
                return -1;
 
        if (rpc_pkt.u.reply.rstatus  ||
            rpc_pkt.u.reply.verifier ||
-           rpc_pkt.u.reply.astatus) {
+           rpc_pkt.u.reply.astatus)
                return -1;
-       }
 
        switch (prog) {
        case PROG_MOUNT:
@@ -422,15 +420,13 @@ rpc_lookup_reply (int prog, uchar *pkt, unsigned len)
 }
 
 static int
-nfs_mount_reply (uchar *pkt, unsigned len)
+nfs_mount_reply(uchar *pkt, unsigned len)
 {
        struct rpc_t rpc_pkt;
 
-#ifdef NFS_DEBUG
-       printf ("%s\n", __FUNCTION__);
-#endif
+       debug("%s\n", __func__);
 
-       memcpy ((unsigned char *)&rpc_pkt, pkt, len);
+       memcpy((unsigned char *)&rpc_pkt, pkt, len);
 
        if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
                return -1;
@@ -438,52 +434,46 @@ nfs_mount_reply (uchar *pkt, unsigned len)
        if (rpc_pkt.u.reply.rstatus  ||
            rpc_pkt.u.reply.verifier ||
            rpc_pkt.u.reply.astatus  ||
-           rpc_pkt.u.reply.data[0]) {
+           rpc_pkt.u.reply.data[0])
                return -1;
-       }
 
        fs_mounted = 1;
-       memcpy (dirfh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
+       memcpy(dirfh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
 
        return 0;
 }
 
 static int
-nfs_umountall_reply (uchar *pkt, unsigned len)
+nfs_umountall_reply(uchar *pkt, unsigned len)
 {
        struct rpc_t rpc_pkt;
 
-#ifdef NFS_DEBUG
-       printf ("%s\n", __FUNCTION__);
-#endif
+       debug("%s\n", __func__);
 
-       memcpy ((unsigned char *)&rpc_pkt, pkt, len);
+       memcpy((unsigned char *)&rpc_pkt, pkt, len);
 
        if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
                return -1;
 
        if (rpc_pkt.u.reply.rstatus  ||
            rpc_pkt.u.reply.verifier ||
-           rpc_pkt.u.reply.astatus) {
+           rpc_pkt.u.reply.astatus)
                return -1;
-       }
 
        fs_mounted = 0;
-       memset (dirfh, 0, sizeof(dirfh));
+       memset(dirfh, 0, sizeof(dirfh));
 
        return 0;
 }
 
 static int
-nfs_lookup_reply (uchar *pkt, unsigned len)
+nfs_lookup_reply(uchar *pkt, unsigned len)
 {
        struct rpc_t rpc_pkt;
 
-#ifdef NFS_DEBUG
-       printf ("%s\n", __FUNCTION__);
-#endif
+       debug("%s\n", __func__);
 
-       memcpy ((unsigned char *)&rpc_pkt, pkt, len);
+       memcpy((unsigned char *)&rpc_pkt, pkt, len);
 
        if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
                return -1;
@@ -491,26 +481,23 @@ nfs_lookup_reply (uchar *pkt, unsigned len)
        if (rpc_pkt.u.reply.rstatus  ||
            rpc_pkt.u.reply.verifier ||
            rpc_pkt.u.reply.astatus  ||
-           rpc_pkt.u.reply.data[0]) {
+           rpc_pkt.u.reply.data[0])
                return -1;
-       }
 
-       memcpy (filefh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
+       memcpy(filefh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
 
        return 0;
 }
 
 static int
-nfs_readlink_reply (uchar *pkt, unsigned len)
+nfs_readlink_reply(uchar *pkt, unsigned len)
 {
        struct rpc_t rpc_pkt;
        int rlen;
 
-#ifdef NFS_DEBUG
-       printf ("%s\n", __FUNCTION__);
-#endif
+       debug("%s\n", __func__);
 
-       memcpy ((unsigned char *)&rpc_pkt, pkt, len);
+       memcpy((unsigned char *)&rpc_pkt, pkt, len);
 
        if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
                return -1;
@@ -518,36 +505,34 @@ nfs_readlink_reply (uchar *pkt, unsigned len)
        if (rpc_pkt.u.reply.rstatus  ||
            rpc_pkt.u.reply.verifier ||
            rpc_pkt.u.reply.astatus  ||
-           rpc_pkt.u.reply.data[0]) {
+           rpc_pkt.u.reply.data[0])
                return -1;
-       }
 
-       rlen = ntohl (rpc_pkt.u.reply.data[1]); /* new path length */
+       rlen = ntohl(rpc_pkt.u.reply.data[1]); /* new path length */
 
        if (*((char *)&(rpc_pkt.u.reply.data[2])) != '/') {
                int pathlen;
-               strcat (nfs_path, "/");
+               strcat(nfs_path, "/");
                pathlen = strlen(nfs_path);
-               memcpy (nfs_path+pathlen, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen);
-               nfs_path[pathlen+rlen+1] = 0;
+               memcpy(nfs_path + pathlen, (uchar *)&(rpc_pkt.u.reply.data[2]),
+                       rlen);
+               nfs_path[pathlen + rlen] = 0;
        } else {
-               memcpy (nfs_path, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen);
+               memcpy(nfs_path, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen);
                nfs_path[rlen] = 0;
        }
        return 0;
 }
 
 static int
-nfs_read_reply (uchar *pkt, unsigned len)
+nfs_read_reply(uchar *pkt, unsigned len)
 {
        struct rpc_t rpc_pkt;
        int rlen;
 
-#ifdef NFS_DEBUG_nop
-       printf ("%s\n", __FUNCTION__);
-#endif
+       debug("%s\n", __func__);
 
-       memcpy ((uchar *)&rpc_pkt, pkt, sizeof(rpc_pkt.u.reply));
+       memcpy((uchar *)&rpc_pkt, pkt, sizeof(rpc_pkt.u.reply));
 
        if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
                return -1;
@@ -556,24 +541,22 @@ nfs_read_reply (uchar *pkt, unsigned len)
            rpc_pkt.u.reply.verifier ||
            rpc_pkt.u.reply.astatus  ||
            rpc_pkt.u.reply.data[0]) {
-               if (rpc_pkt.u.reply.rstatus) {
+               if (rpc_pkt.u.reply.rstatus)
                        return -9999;
-               }
-               if (rpc_pkt.u.reply.astatus) {
+               if (rpc_pkt.u.reply.astatus)
                        return -9999;
-               }
-               return -ntohl(rpc_pkt.u.reply.data[0]);;
+               return -ntohl(rpc_pkt.u.reply.data[0]);
        }
 
-       if ((nfs_offset!=0) && !((nfs_offset) % (NFS_READ_SIZE/2*10*HASHES_PER_LINE))) {
-               puts ("\n\t ");
-       }
-       if (!(nfs_offset % ((NFS_READ_SIZE/2)*10))) {
-               putc ('#');
-       }
+       if ((nfs_offset != 0) && !((nfs_offset) %
+                       (NFS_READ_SIZE / 2 * 10 * HASHES_PER_LINE)))
+               puts("\n\t ");
+       if (!(nfs_offset % ((NFS_READ_SIZE / 2) * 10)))
+               putc('#');
 
        rlen = ntohl(rpc_pkt.u.reply.data[18]);
-       if ( 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;
@@ -584,104 +567,106 @@ Interfaces of U-BOOT
 **************************************************************************/
 
 static void
-NfsTimeout (void)
+NfsTimeout(void)
 {
-       puts ("Timeout\n");
-       NetState = NETLOOP_FAIL;
-       return;
+       if (++NfsTimeoutCount > NFS_RETRY_COUNT) {
+               puts("\nRetry count exceeded; starting again\n");
+               NetStartAgain();
+       } else {
+               puts("T ");
+               NetSetTimeout(NFS_TIMEOUT, NfsTimeout);
+               NfsSend();
+       }
 }
 
 static void
-NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
+NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
 {
        int rlen;
 
-#ifdef NFS_DEBUG
-       printf ("%s\n", __FUNCTION__);
-#endif
+       debug("%s\n", __func__);
 
-       if (dest != NfsOurPort) return;
+       if (dest != NfsOurPort)
+               return;
 
        switch (NfsState) {
        case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
-               rpc_lookup_reply (PROG_MOUNT, pkt, len);
+               rpc_lookup_reply(PROG_MOUNT, pkt, len);
                NfsState = STATE_PRCLOOKUP_PROG_NFS_REQ;
-               NfsSend ();
+               NfsSend();
                break;
 
        case STATE_PRCLOOKUP_PROG_NFS_REQ:
-               rpc_lookup_reply (PROG_NFS, pkt, len);
+               rpc_lookup_reply(PROG_NFS, pkt, len);
                NfsState = STATE_MOUNT_REQ;
-               NfsSend ();
+               NfsSend();
                break;
 
        case STATE_MOUNT_REQ:
                if (nfs_mount_reply(pkt, len)) {
-                       puts ("*** ERROR: Cannot mount\n");
+                       puts("*** ERROR: Cannot mount\n");
                        /* just to be sure... */
                        NfsState = STATE_UMOUNT_REQ;
-                       NfsSend ();
+                       NfsSend();
                } else {
                        NfsState = STATE_LOOKUP_REQ;
-                       NfsSend ();
+                       NfsSend();
                }
                break;
 
        case STATE_UMOUNT_REQ:
                if (nfs_umountall_reply(pkt, len)) {
-                       puts ("*** ERROR: Cannot umount\n");
-                       NetState = NETLOOP_FAIL;
+                       puts("*** ERROR: Cannot umount\n");
+                       net_set_state(NETLOOP_FAIL);
                } else {
-                       puts ("\ndone\n");
-                       NetState = NfsDownloadState;
+                       puts("\ndone\n");
+                       net_set_state(nfs_download_state);
                }
                break;
 
        case STATE_LOOKUP_REQ:
                if (nfs_lookup_reply(pkt, len)) {
-                       puts ("*** ERROR: File lookup fail\n");
+                       puts("*** ERROR: File lookup fail\n");
                        NfsState = STATE_UMOUNT_REQ;
-                       NfsSend ();
+                       NfsSend();
                } else {
                        NfsState = STATE_READ_REQ;
                        nfs_offset = 0;
                        nfs_len = NFS_READ_SIZE;
-                       NfsSend ();
+                       NfsSend();
                }
                break;
 
        case STATE_READLINK_REQ:
                if (nfs_readlink_reply(pkt, len)) {
-                       puts ("*** ERROR: Symlink fail\n");
+                       puts("*** ERROR: Symlink fail\n");
                        NfsState = STATE_UMOUNT_REQ;
-                       NfsSend ();
+                       NfsSend();
                } else {
-#ifdef NFS_DEBUG
-                       printf ("Symlink --> %s\n", nfs_path);
-#endif
-                       nfs_filename = basename (nfs_path);
-                       nfs_path     = dirname (nfs_path);
+                       debug("Symlink --> %s\n", nfs_path);
+                       nfs_filename = basename(nfs_path);
+                       nfs_path     = dirname(nfs_path);
 
                        NfsState = STATE_MOUNT_REQ;
-                       NfsSend ();
+                       NfsSend();
                }
                break;
 
        case STATE_READ_REQ:
-               rlen = nfs_read_reply (pkt, len);
-               NetSetTimeout (NFS_TIMEOUT * CFG_HZ, NfsTimeout);
+               rlen = nfs_read_reply(pkt, len);
+               NetSetTimeout(NFS_TIMEOUT, NfsTimeout);
                if (rlen > 0) {
                        nfs_offset += rlen;
-                       NfsSend ();
-               }
-               else if ((rlen == -NFSERR_ISDIR)||(rlen == -NFSERR_INVAL)) {
+                       NfsSend();
+               } else if ((rlen == -NFSERR_ISDIR) || (rlen == -NFSERR_INVAL)) {
                        /* symbolic link */
                        NfsState = STATE_READLINK_REQ;
-                       NfsSend ();
+                       NfsSend();
                } else {
-                       if ( ! rlen ) NfsDownloadState = NETLOOP_SUCCESS;
+                       if (!rlen)
+                               nfs_download_state = NETLOOP_SUCCESS;
                        NfsState = STATE_UMOUNT_REQ;
-                       NfsSend ();
+                       NfsSend();
                }
                break;
        }
@@ -689,77 +674,72 @@ NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
 
 
 void
-NfsStart (void)
+NfsStart(void)
 {
-#ifdef NFS_DEBUG
-       printf ("%s\n", __FUNCTION__);
-#endif
-       NfsDownloadState = NETLOOP_FAIL;
+       debug("%s\n", __func__);
+       nfs_download_state = NETLOOP_FAIL;
 
        NfsServerIP = NetServerIP;
        nfs_path = (char *)nfs_path_buff;
 
        if (nfs_path == NULL) {
-               NetState = NETLOOP_FAIL;
-               puts ("*** ERROR: Fail allocate memory\n");
+               net_set_state(NETLOOP_FAIL);
+               puts("*** ERROR: Fail allocate memory\n");
                return;
        }
 
        if (BootFile[0] == '\0') {
-               sprintf (default_filename, "/nfsroot/%02lX%02lX%02lX%02lX.img",
+               sprintf(default_filename, "/nfsroot/%02X%02X%02X%02X.img",
                        NetOurIP & 0xFF,
                        (NetOurIP >>  8) & 0xFF,
                        (NetOurIP >> 16) & 0xFF,
-                       (NetOurIP >> 24) & 0xFF );
-               strcpy (nfs_path, default_filename);
+                       (NetOurIP >> 24) & 0xFF);
+               strcpy(nfs_path, default_filename);
 
-               printf ("*** Warning: no boot file name; using '%s'\n",
+               printf("*** Warning: no boot file name; using '%s'\n",
                        nfs_path);
        } else {
-               char *p=BootFile;
+               char *p = BootFile;
 
-               p = strchr (p, ':');
+               p = strchr(p, ':');
 
                if (p != NULL) {
-                       NfsServerIP = string_to_ip (BootFile);
+                       NfsServerIP = string_to_ip(BootFile);
                        ++p;
-                       strcpy (nfs_path, p);
+                       strcpy(nfs_path, p);
                } else {
-                       strcpy (nfs_path, BootFile);
+                       strcpy(nfs_path, BootFile);
                }
        }
 
-       nfs_filename = basename (nfs_path);
-       nfs_path     = dirname (nfs_path);
+       nfs_filename = basename(nfs_path);
+       nfs_path     = dirname(nfs_path);
 
-#if defined(CONFIG_NET_MULTI)
-       printf ("Using %s device\n", eth_get_name());
-#endif
+       printf("Using %s device\n", eth_get_name());
 
-       puts ("File transfer via NFS from server "); print_IPaddr (NfsServerIP);
-       puts ("; our IP address is ");              print_IPaddr (NetOurIP);
+       printf("File transfer via NFS from server %pI4"
+               "; our IP address is %pI4", &NfsServerIP, &NetOurIP);
 
        /* Check if we need to send across this subnet */
        if (NetOurGatewayIP && NetOurSubnetMask) {
                IPaddr_t OurNet     = NetOurIP    & NetOurSubnetMask;
                IPaddr_t ServerNet  = NetServerIP & NetOurSubnetMask;
 
-               if (OurNet != ServerNet) {
-                       puts ("; sending through gateway ");
-                       print_IPaddr (NetOurGatewayIP) ;
-               }
+               if (OurNet != ServerNet)
+                       printf("; sending through gateway %pI4",
+                               &NetOurGatewayIP);
        }
-       printf ("\nFilename '%s/%s'.", nfs_path, nfs_filename);
+       printf("\nFilename '%s/%s'.", nfs_path, nfs_filename);
 
        if (NetBootFileSize) {
-               printf (" Size is 0x%x Bytes = ", NetBootFileSize<<9);
-               print_size (NetBootFileSize<<9, "");
+               printf(" Size is 0x%x Bytes = ", NetBootFileSize<<9);
+               print_size(NetBootFileSize<<9, "");
        }
-       printf ("\nLoad address: 0x%lx\n"
+       printf("\nLoad address: 0x%lx\n"
                "Loading: *\b", load_addr);
 
-       NetSetTimeout (NFS_TIMEOUT * CFG_HZ, NfsTimeout);
-       NetSetHandler (NfsHandler);
+       NetSetTimeout(NFS_TIMEOUT, NfsTimeout);
+       net_set_udp_handler(NfsHandler);
 
        NfsTimeoutCount = 0;
        NfsState = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
@@ -769,9 +749,7 @@ NfsStart (void)
        NfsOurPort = 1000;
 
        /* zero out server ether in case the server ip has changed */
-       memset (NetServerEther, 0, 6);
+       memset(NetServerEther, 0, 6);
 
-       NfsSend ();
+       NfsSend();
 }
-
-#endif