2004-02-24 02:00:03 +00:00
|
|
|
/*
|
|
|
|
* NFS support driver - based on etherboot and U-BOOT's tftp.c
|
|
|
|
*
|
|
|
|
* Masami Komiya <mkomiya@sonare.it> 2004
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* NOTE: the NFS code is heavily inspired by the NetBSD netboot code (read:
|
|
|
|
* large portions are copied verbatim) as distributed in OSKit 0.97. A few
|
|
|
|
* changes were necessary to adapt the code to Etherboot and to fix several
|
|
|
|
* inconsistencies. Also the RPC message preparation is done "by hand" to
|
|
|
|
* avoid adding netsprintf() which I find hard to understand and use. */
|
|
|
|
|
|
|
|
/* NOTE 2: Etherboot does not care about things beyond the kernel image, so
|
|
|
|
* it loads the kernel image off the boot server (ARP_SERVER) and does not
|
|
|
|
* access the client root disk (root-path in dhcpd.conf), which would use
|
|
|
|
* ARP_ROOTSERVER. The root disk is something the operating system we are
|
|
|
|
* about to load needs to use. This is different from the OSKit 0.97 logic. */
|
|
|
|
|
|
|
|
/* NOTE 3: Symlink handling introduced by Anselm M Hoffmeister, 2003-July-14
|
|
|
|
* If a symlink is encountered, it is followed as far as possible (recursion
|
|
|
|
* possible, maximum 16 steps). There is no clearing of ".."'s inside the
|
|
|
|
* path, so please DON'T DO THAT. thx. */
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <net.h>
|
|
|
|
#include <malloc.h>
|
2015-03-22 22:09:08 +00:00
|
|
|
#include <mapmem.h>
|
2004-02-24 02:00:03 +00:00
|
|
|
#include "nfs.h"
|
|
|
|
#include "bootp.h"
|
|
|
|
|
|
|
|
#define HASHES_PER_LINE 65 /* Number of "loading" hashes per line */
|
2008-01-31 09:35:04 +00:00
|
|
|
#define NFS_RETRY_COUNT 30
|
2012-07-03 22:25:21 +00:00
|
|
|
#ifndef CONFIG_NFS_TIMEOUT
|
|
|
|
# define NFS_TIMEOUT 2000UL
|
|
|
|
#else
|
|
|
|
# define NFS_TIMEOUT CONFIG_NFS_TIMEOUT
|
|
|
|
#endif
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-12-11 18:14:16 +00:00
|
|
|
#define NFS_RPC_ERR 1
|
|
|
|
#define NFS_RPC_DROP 124
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
static int fs_mounted;
|
|
|
|
static unsigned long rpc_id;
|
2004-02-24 02:00:03 +00:00
|
|
|
static int nfs_offset = -1;
|
|
|
|
static int nfs_len;
|
2012-12-11 18:14:16 +00:00
|
|
|
static ulong nfs_timeout = NFS_TIMEOUT;
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
static char dirfh[NFS_FHSIZE]; /* file handle of directory */
|
|
|
|
static char filefh[NFS_FHSIZE]; /* file handle of kernel image */
|
|
|
|
|
2012-05-23 07:59:14 +00:00
|
|
|
static enum net_loop_state nfs_download_state;
|
2015-04-08 06:41:01 +00:00
|
|
|
static struct in_addr nfs_server_ip;
|
2004-02-24 02:00:03 +00:00
|
|
|
static int NfsSrvMountPort;
|
|
|
|
static int NfsSrvNfsPort;
|
|
|
|
static int NfsOurPort;
|
|
|
|
static int NfsTimeoutCount;
|
|
|
|
static int NfsState;
|
|
|
|
#define STATE_PRCLOOKUP_PROG_MOUNT_REQ 1
|
|
|
|
#define STATE_PRCLOOKUP_PROG_NFS_REQ 2
|
|
|
|
#define STATE_MOUNT_REQ 3
|
|
|
|
#define STATE_UMOUNT_REQ 4
|
|
|
|
#define STATE_LOOKUP_REQ 5
|
|
|
|
#define STATE_READ_REQ 6
|
|
|
|
#define STATE_READLINK_REQ 7
|
|
|
|
|
|
|
|
static char default_filename[64];
|
|
|
|
static char *nfs_filename;
|
|
|
|
static char *nfs_path;
|
|
|
|
static char nfs_path_buff[2048];
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
static inline int
|
|
|
|
store_block(uchar *src, unsigned offset, unsigned len)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
2004-02-24 22:33:21 +00:00
|
|
|
ulong newsize = offset + len;
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifdef CONFIG_SYS_DIRECT_FLASH_NFS
|
2004-02-24 02:00:03 +00:00
|
|
|
int i, rc = 0;
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) {
|
2004-02-24 02:00:03 +00:00
|
|
|
/* start address in flash? */
|
|
|
|
if (load_addr + offset >= flash_info[i].start[0]) {
|
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc) { /* Flash is destination for this packet */
|
2012-05-15 08:59:09 +00:00
|
|
|
rc = flash_write((uchar *)src, (ulong)(load_addr+offset), len);
|
2004-02-24 02:00:03 +00:00
|
|
|
if (rc) {
|
2012-05-15 08:59:09 +00:00
|
|
|
flash_perror(rc);
|
2005-08-05 23:11:12 +00:00
|
|
|
return -1;
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
} else
|
2008-10-16 13:01:15 +00:00
|
|
|
#endif /* CONFIG_SYS_DIRECT_FLASH_NFS */
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
2015-03-22 22:09:08 +00:00
|
|
|
void *ptr = map_sysmem(load_addr + offset, len);
|
|
|
|
|
|
|
|
memcpy(ptr, src, len);
|
|
|
|
unmap_sysmem(ptr);
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
2004-02-24 22:33:21 +00:00
|
|
|
|
2015-04-08 06:41:02 +00:00
|
|
|
if (net_boot_file_size < (offset + len))
|
|
|
|
net_boot_file_size = newsize;
|
2005-08-05 23:11:12 +00:00
|
|
|
return 0;
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
2012-05-15 08:59:09 +00:00
|
|
|
basename(char *path)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
char *fname;
|
|
|
|
|
|
|
|
fname = path + strlen(path) - 1;
|
|
|
|
while (fname >= path) {
|
|
|
|
if (*fname == '/') {
|
|
|
|
fname++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fname--;
|
|
|
|
}
|
|
|
|
return fname;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
2012-05-15 08:59:09 +00:00
|
|
|
dirname(char *path)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
char *fname;
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
fname = basename(path);
|
2004-02-24 02:00:03 +00:00
|
|
|
--fname;
|
|
|
|
*fname = '\0';
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
RPC_ADD_CREDENTIALS - Add RPC authentication/verifier entries
|
|
|
|
**************************************************************************/
|
2012-05-15 08:59:09 +00:00
|
|
|
static long *rpc_add_credentials(long *p)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
int hl;
|
|
|
|
int hostnamelen;
|
|
|
|
char hostname[256];
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
strcpy(hostname, "");
|
|
|
|
hostnamelen = strlen(hostname);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
/* Here's the executive summary on authentication requirements of the
|
|
|
|
* various NFS server implementations: Linux accepts both AUTH_NONE
|
|
|
|
* and AUTH_UNIX authentication (also accepts an empty hostname field
|
|
|
|
* in the AUTH_UNIX scheme). *BSD refuses AUTH_NONE, but accepts
|
|
|
|
* AUTH_UNIX (also accepts an empty hostname field in the AUTH_UNIX
|
|
|
|
* scheme). To be safe, use AUTH_UNIX and pass the hostname if we have
|
|
|
|
* it (if the BOOTP/DHCP reply didn't give one, just use an empty
|
|
|
|
* hostname). */
|
|
|
|
|
|
|
|
hl = (hostnamelen + 3) & ~3;
|
|
|
|
|
|
|
|
/* Provide an AUTH_UNIX credential. */
|
|
|
|
*p++ = htonl(1); /* AUTH_UNIX */
|
|
|
|
*p++ = htonl(hl+20); /* auth length */
|
|
|
|
*p++ = htonl(0); /* stamp */
|
|
|
|
*p++ = htonl(hostnamelen); /* hostname string */
|
2012-05-15 08:59:09 +00:00
|
|
|
if (hostnamelen & 3)
|
2004-02-24 02:00:03 +00:00
|
|
|
*(p + hostnamelen / 4) = 0; /* add zero padding */
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy(p, hostname, hostnamelen);
|
2004-02-24 02:00:03 +00:00
|
|
|
p += hl / 4;
|
|
|
|
*p++ = 0; /* uid */
|
|
|
|
*p++ = 0; /* gid */
|
|
|
|
*p++ = 0; /* auxiliary gid list */
|
|
|
|
|
|
|
|
/* Provide an AUTH_NONE verifier. */
|
|
|
|
*p++ = 0; /* AUTH_NONE */
|
|
|
|
*p++ = 0; /* auth length */
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
RPC_LOOKUP - Lookup RPC Port numbers
|
|
|
|
**************************************************************************/
|
|
|
|
static void
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
struct rpc_t pkt;
|
|
|
|
unsigned long id;
|
|
|
|
uint32_t *p;
|
|
|
|
int pktlen;
|
|
|
|
int sport;
|
|
|
|
|
2004-03-14 00:59:59 +00:00
|
|
|
id = ++rpc_id;
|
2004-02-24 02:00:03 +00:00
|
|
|
pkt.u.call.id = htonl(id);
|
|
|
|
pkt.u.call.type = htonl(MSG_CALL);
|
|
|
|
pkt.u.call.rpcvers = htonl(2); /* use RPC version 2 */
|
|
|
|
pkt.u.call.prog = htonl(rpc_prog);
|
|
|
|
pkt.u.call.vers = htonl(2); /* portmapper is version 2 */
|
|
|
|
pkt.u.call.proc = htonl(rpc_proc);
|
|
|
|
p = (uint32_t *)&(pkt.u.call.data);
|
|
|
|
|
|
|
|
if (datalen)
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy((char *)p, (char *)data, datalen*sizeof(uint32_t));
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
pktlen = (char *)p + datalen*sizeof(uint32_t) - (char *)&pkt;
|
|
|
|
|
2012-05-23 07:58:04 +00:00
|
|
|
memcpy((char *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE,
|
2012-05-15 08:59:09 +00:00
|
|
|
(char *)&pkt, pktlen);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
if (rpc_prog == PROG_PORTMAP)
|
|
|
|
sport = SUNRPC_PORT;
|
|
|
|
else if (rpc_prog == PROG_MOUNT)
|
|
|
|
sport = NfsSrvMountPort;
|
|
|
|
else
|
|
|
|
sport = NfsSrvNfsPort;
|
|
|
|
|
2015-04-08 06:41:04 +00:00
|
|
|
NetSendUDPPacket(net_server_ethaddr, nfs_server_ip, sport, NfsOurPort,
|
2015-04-08 06:41:01 +00:00
|
|
|
pktlen);
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
RPC_LOOKUP - Lookup RPC Port numbers
|
|
|
|
**************************************************************************/
|
|
|
|
static void
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_lookup_req(int prog, int ver)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
uint32_t data[16];
|
|
|
|
|
|
|
|
data[0] = 0; data[1] = 0; /* auth credential */
|
|
|
|
data[2] = 0; data[3] = 0; /* auth verifier */
|
|
|
|
data[4] = htonl(prog);
|
|
|
|
data[5] = htonl(ver);
|
|
|
|
data[6] = htonl(17); /* IP_UDP */
|
|
|
|
data[7] = 0;
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_req(PROG_PORTMAP, PORTMAP_GETPORT, data, 8);
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
NFS_MOUNT - Mount an NFS Filesystem
|
|
|
|
**************************************************************************/
|
|
|
|
static void
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_mount_req(char *path)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
uint32_t data[1024];
|
|
|
|
uint32_t *p;
|
|
|
|
int len;
|
|
|
|
int pathlen;
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
pathlen = strlen(path);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
p = &(data[0]);
|
|
|
|
p = (uint32_t *)rpc_add_credentials((long *)p);
|
|
|
|
|
|
|
|
*p++ = htonl(pathlen);
|
2012-05-15 08:59:09 +00:00
|
|
|
if (pathlen & 3)
|
|
|
|
*(p + pathlen / 4) = 0;
|
|
|
|
memcpy(p, path, pathlen);
|
2004-02-24 02:00:03 +00:00
|
|
|
p += (pathlen + 3) / 4;
|
|
|
|
|
|
|
|
len = (uint32_t *)p - (uint32_t *)&(data[0]);
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_req(PROG_MOUNT, MOUNT_ADDENTRY, data, len);
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
NFS_UMOUNTALL - Unmount all our NFS Filesystems on the Server
|
|
|
|
**************************************************************************/
|
|
|
|
static void
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_umountall_req(void)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
uint32_t data[1024];
|
|
|
|
uint32_t *p;
|
|
|
|
int len;
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
if ((NfsSrvMountPort == -1) || (!fs_mounted))
|
2004-02-24 02:00:03 +00:00
|
|
|
/* Nothing mounted, nothing to umount */
|
|
|
|
return;
|
|
|
|
|
|
|
|
p = &(data[0]);
|
2012-05-15 08:59:09 +00:00
|
|
|
p = (uint32_t *)rpc_add_credentials((long *)p);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
len = (uint32_t *)p - (uint32_t *)&(data[0]);
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_req(PROG_MOUNT, MOUNT_UMOUNTALL, data, len);
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* NFS_READLINK (AH 2003-07-14)
|
|
|
|
* This procedure is called when read of the first block fails -
|
|
|
|
* this probably happens when it's a directory or a symlink
|
|
|
|
* In case of successful readlink(), the dirname is manipulated,
|
|
|
|
* so that inside the nfs() function a recursion can be done.
|
|
|
|
**************************************************************************/
|
|
|
|
static void
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_readlink_req(void)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
uint32_t data[1024];
|
|
|
|
uint32_t *p;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
p = &(data[0]);
|
2012-05-15 08:59:09 +00:00
|
|
|
p = (uint32_t *)rpc_add_credentials((long *)p);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy(p, filefh, NFS_FHSIZE);
|
2004-02-24 02:00:03 +00:00
|
|
|
p += (NFS_FHSIZE / 4);
|
|
|
|
|
|
|
|
len = (uint32_t *)p - (uint32_t *)&(data[0]);
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_req(PROG_NFS, NFS_READLINK, data, len);
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
NFS_LOOKUP - Lookup Pathname
|
|
|
|
**************************************************************************/
|
|
|
|
static void
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_lookup_req(char *fname)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
uint32_t data[1024];
|
|
|
|
uint32_t *p;
|
|
|
|
int len;
|
|
|
|
int fnamelen;
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
fnamelen = strlen(fname);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
p = &(data[0]);
|
2012-05-15 08:59:09 +00:00
|
|
|
p = (uint32_t *)rpc_add_credentials((long *)p);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy(p, dirfh, NFS_FHSIZE);
|
2004-02-24 02:00:03 +00:00
|
|
|
p += (NFS_FHSIZE / 4);
|
|
|
|
*p++ = htonl(fnamelen);
|
2012-05-15 08:59:09 +00:00
|
|
|
if (fnamelen & 3)
|
|
|
|
*(p + fnamelen / 4) = 0;
|
|
|
|
memcpy(p, fname, fnamelen);
|
2004-02-24 02:00:03 +00:00
|
|
|
p += (fnamelen + 3) / 4;
|
|
|
|
|
|
|
|
len = (uint32_t *)p - (uint32_t *)&(data[0]);
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_req(PROG_NFS, NFS_LOOKUP, data, len);
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
NFS_READ - Read File on NFS Server
|
|
|
|
**************************************************************************/
|
|
|
|
static void
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_read_req(int offset, int readlen)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
uint32_t data[1024];
|
|
|
|
uint32_t *p;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
p = &(data[0]);
|
2012-05-15 08:59:09 +00:00
|
|
|
p = (uint32_t *)rpc_add_credentials((long *)p);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy(p, filefh, NFS_FHSIZE);
|
2004-02-24 02:00:03 +00:00
|
|
|
p += (NFS_FHSIZE / 4);
|
|
|
|
*p++ = htonl(offset);
|
|
|
|
*p++ = htonl(readlen);
|
|
|
|
*p++ = 0;
|
|
|
|
|
|
|
|
len = (uint32_t *)p - (uint32_t *)&(data[0]);
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_req(PROG_NFS, NFS_READ, data, len);
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
RPC request dispatcher
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
static void
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend(void)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
2009-07-23 07:01:03 +00:00
|
|
|
debug("%s\n", __func__);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
switch (NfsState) {
|
|
|
|
case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_lookup_req(PROG_MOUNT, 1);
|
2004-02-24 02:00:03 +00:00
|
|
|
break;
|
|
|
|
case STATE_PRCLOOKUP_PROG_NFS_REQ:
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_lookup_req(PROG_NFS, 2);
|
2004-02-24 02:00:03 +00:00
|
|
|
break;
|
|
|
|
case STATE_MOUNT_REQ:
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_mount_req(nfs_path);
|
2004-02-24 02:00:03 +00:00
|
|
|
break;
|
|
|
|
case STATE_UMOUNT_REQ:
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_umountall_req();
|
2004-02-24 02:00:03 +00:00
|
|
|
break;
|
|
|
|
case STATE_LOOKUP_REQ:
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_lookup_req(nfs_filename);
|
2004-02-24 02:00:03 +00:00
|
|
|
break;
|
|
|
|
case STATE_READ_REQ:
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_read_req(nfs_offset, nfs_len);
|
2004-02-24 02:00:03 +00:00
|
|
|
break;
|
|
|
|
case STATE_READLINK_REQ:
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_readlink_req();
|
2004-02-24 02:00:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
Handlers for the reply from server
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
static int
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_lookup_reply(int prog, uchar *pkt, unsigned len)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
struct rpc_t rpc_pkt;
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy((unsigned char *)&rpc_pkt, pkt, len);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2009-07-23 07:01:03 +00:00
|
|
|
debug("%s\n", __func__);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-12-11 18:14:16 +00:00
|
|
|
if (ntohl(rpc_pkt.u.reply.id) > rpc_id)
|
|
|
|
return -NFS_RPC_ERR;
|
|
|
|
else if (ntohl(rpc_pkt.u.reply.id) < rpc_id)
|
|
|
|
return -NFS_RPC_DROP;
|
2004-03-14 00:59:59 +00:00
|
|
|
|
2004-02-24 02:00:03 +00:00
|
|
|
if (rpc_pkt.u.reply.rstatus ||
|
|
|
|
rpc_pkt.u.reply.verifier ||
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_pkt.u.reply.astatus)
|
2004-03-14 00:59:59 +00:00
|
|
|
return -1;
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
switch (prog) {
|
|
|
|
case PROG_MOUNT:
|
|
|
|
NfsSrvMountPort = ntohl(rpc_pkt.u.reply.data[0]);
|
|
|
|
break;
|
|
|
|
case PROG_NFS:
|
|
|
|
NfsSrvNfsPort = ntohl(rpc_pkt.u.reply.data[0]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_mount_reply(uchar *pkt, unsigned len)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
struct rpc_t rpc_pkt;
|
|
|
|
|
2009-07-23 07:01:03 +00:00
|
|
|
debug("%s\n", __func__);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy((unsigned char *)&rpc_pkt, pkt, len);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-12-11 18:14:16 +00:00
|
|
|
if (ntohl(rpc_pkt.u.reply.id) > rpc_id)
|
|
|
|
return -NFS_RPC_ERR;
|
|
|
|
else if (ntohl(rpc_pkt.u.reply.id) < rpc_id)
|
|
|
|
return -NFS_RPC_DROP;
|
2004-03-14 00:59:59 +00:00
|
|
|
|
2004-02-24 02:00:03 +00:00
|
|
|
if (rpc_pkt.u.reply.rstatus ||
|
|
|
|
rpc_pkt.u.reply.verifier ||
|
|
|
|
rpc_pkt.u.reply.astatus ||
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_pkt.u.reply.data[0])
|
2004-02-24 02:00:03 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
fs_mounted = 1;
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy(dirfh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_umountall_reply(uchar *pkt, unsigned len)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
struct rpc_t rpc_pkt;
|
|
|
|
|
2009-07-23 07:01:03 +00:00
|
|
|
debug("%s\n", __func__);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy((unsigned char *)&rpc_pkt, pkt, len);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-12-11 18:14:16 +00:00
|
|
|
if (ntohl(rpc_pkt.u.reply.id) > rpc_id)
|
|
|
|
return -NFS_RPC_ERR;
|
|
|
|
else if (ntohl(rpc_pkt.u.reply.id) < rpc_id)
|
|
|
|
return -NFS_RPC_DROP;
|
2004-03-14 00:59:59 +00:00
|
|
|
|
2004-02-24 02:00:03 +00:00
|
|
|
if (rpc_pkt.u.reply.rstatus ||
|
|
|
|
rpc_pkt.u.reply.verifier ||
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_pkt.u.reply.astatus)
|
2004-02-24 02:00:03 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
fs_mounted = 0;
|
2012-05-15 08:59:09 +00:00
|
|
|
memset(dirfh, 0, sizeof(dirfh));
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_lookup_reply(uchar *pkt, unsigned len)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
struct rpc_t rpc_pkt;
|
|
|
|
|
2009-07-23 07:01:03 +00:00
|
|
|
debug("%s\n", __func__);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy((unsigned char *)&rpc_pkt, pkt, len);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-12-11 18:14:16 +00:00
|
|
|
if (ntohl(rpc_pkt.u.reply.id) > rpc_id)
|
|
|
|
return -NFS_RPC_ERR;
|
|
|
|
else if (ntohl(rpc_pkt.u.reply.id) < rpc_id)
|
|
|
|
return -NFS_RPC_DROP;
|
2004-03-14 00:59:59 +00:00
|
|
|
|
2004-02-24 02:00:03 +00:00
|
|
|
if (rpc_pkt.u.reply.rstatus ||
|
|
|
|
rpc_pkt.u.reply.verifier ||
|
|
|
|
rpc_pkt.u.reply.astatus ||
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_pkt.u.reply.data[0])
|
2004-02-24 02:00:03 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy(filefh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_readlink_reply(uchar *pkt, unsigned len)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
struct rpc_t rpc_pkt;
|
|
|
|
int rlen;
|
|
|
|
|
2009-07-23 07:01:03 +00:00
|
|
|
debug("%s\n", __func__);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy((unsigned char *)&rpc_pkt, pkt, len);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-12-11 18:14:16 +00:00
|
|
|
if (ntohl(rpc_pkt.u.reply.id) > rpc_id)
|
|
|
|
return -NFS_RPC_ERR;
|
|
|
|
else if (ntohl(rpc_pkt.u.reply.id) < rpc_id)
|
|
|
|
return -NFS_RPC_DROP;
|
2004-03-14 00:59:59 +00:00
|
|
|
|
2004-02-24 02:00:03 +00:00
|
|
|
if (rpc_pkt.u.reply.rstatus ||
|
|
|
|
rpc_pkt.u.reply.verifier ||
|
|
|
|
rpc_pkt.u.reply.astatus ||
|
2012-05-15 08:59:09 +00:00
|
|
|
rpc_pkt.u.reply.data[0])
|
2004-02-24 02:00:03 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
rlen = ntohl(rpc_pkt.u.reply.data[1]); /* new path length */
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
if (*((char *)&(rpc_pkt.u.reply.data[2])) != '/') {
|
|
|
|
int pathlen;
|
2012-05-15 08:59:09 +00:00
|
|
|
strcat(nfs_path, "/");
|
2004-02-24 02:00:03 +00:00
|
|
|
pathlen = strlen(nfs_path);
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy(nfs_path + pathlen, (uchar *)&(rpc_pkt.u.reply.data[2]),
|
|
|
|
rlen);
|
2009-11-19 08:47:28 +00:00
|
|
|
nfs_path[pathlen + rlen] = 0;
|
2004-02-24 02:00:03 +00:00
|
|
|
} else {
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy(nfs_path, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen);
|
2004-02-24 02:00:03 +00:00
|
|
|
nfs_path[rlen] = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_read_reply(uchar *pkt, unsigned len)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
struct rpc_t rpc_pkt;
|
|
|
|
int rlen;
|
|
|
|
|
2009-07-23 07:01:03 +00:00
|
|
|
debug("%s\n", __func__);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
memcpy((uchar *)&rpc_pkt, pkt, sizeof(rpc_pkt.u.reply));
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-12-11 18:14:16 +00:00
|
|
|
if (ntohl(rpc_pkt.u.reply.id) > rpc_id)
|
|
|
|
return -NFS_RPC_ERR;
|
|
|
|
else if (ntohl(rpc_pkt.u.reply.id) < rpc_id)
|
|
|
|
return -NFS_RPC_DROP;
|
2004-03-14 00:59:59 +00:00
|
|
|
|
2004-02-24 02:00:03 +00:00
|
|
|
if (rpc_pkt.u.reply.rstatus ||
|
|
|
|
rpc_pkt.u.reply.verifier ||
|
|
|
|
rpc_pkt.u.reply.astatus ||
|
|
|
|
rpc_pkt.u.reply.data[0]) {
|
2012-05-15 08:59:09 +00:00
|
|
|
if (rpc_pkt.u.reply.rstatus)
|
2004-02-24 02:00:03 +00:00
|
|
|
return -9999;
|
2012-05-15 08:59:09 +00:00
|
|
|
if (rpc_pkt.u.reply.astatus)
|
2004-02-24 02:00:03 +00:00
|
|
|
return -9999;
|
2012-05-15 08:59:09 +00:00
|
|
|
return -ntohl(rpc_pkt.u.reply.data[0]);
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
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('#');
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
rlen = ntohl(rpc_pkt.u.reply.data[18]);
|
2012-05-15 08:59:09 +00:00
|
|
|
if (store_block((uchar *)pkt + sizeof(rpc_pkt.u.reply),
|
|
|
|
nfs_offset, rlen))
|
2005-08-05 23:11:12 +00:00
|
|
|
return -9999;
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
return rlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
Interfaces of U-BOOT
|
|
|
|
**************************************************************************/
|
|
|
|
|
2004-09-28 21:51:42 +00:00
|
|
|
static void
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsTimeout(void)
|
2004-09-28 21:51:42 +00:00
|
|
|
{
|
2012-05-15 08:59:09 +00:00
|
|
|
if (++NfsTimeoutCount > NFS_RETRY_COUNT) {
|
|
|
|
puts("\nRetry count exceeded; starting again\n");
|
|
|
|
NetStartAgain();
|
2009-11-10 02:08:36 +00:00
|
|
|
} else {
|
|
|
|
puts("T ");
|
2012-12-11 18:14:16 +00:00
|
|
|
NetSetTimeout(nfs_timeout + NFS_TIMEOUT * NfsTimeoutCount,
|
|
|
|
NfsTimeout);
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
2008-01-31 09:35:04 +00:00
|
|
|
}
|
2004-09-28 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 06:41:01 +00:00
|
|
|
static void nfs_handler(uchar *pkt, unsigned dest, struct in_addr sip,
|
|
|
|
unsigned src, unsigned len)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
int rlen;
|
2012-12-11 18:14:16 +00:00
|
|
|
int reply;
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2009-07-23 07:01:03 +00:00
|
|
|
debug("%s\n", __func__);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
if (dest != NfsOurPort)
|
|
|
|
return;
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
switch (NfsState) {
|
|
|
|
case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
|
2012-12-11 18:14:16 +00:00
|
|
|
if (rpc_lookup_reply(PROG_MOUNT, pkt, len) == -NFS_RPC_DROP)
|
|
|
|
break;
|
2004-02-24 02:00:03 +00:00
|
|
|
NfsState = STATE_PRCLOOKUP_PROG_NFS_REQ;
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
2004-02-24 02:00:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_PRCLOOKUP_PROG_NFS_REQ:
|
2012-12-11 18:14:16 +00:00
|
|
|
if (rpc_lookup_reply(PROG_NFS, pkt, len) == -NFS_RPC_DROP)
|
|
|
|
break;
|
2004-02-24 02:00:03 +00:00
|
|
|
NfsState = STATE_MOUNT_REQ;
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
2004-02-24 02:00:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_MOUNT_REQ:
|
2012-12-11 18:14:16 +00:00
|
|
|
reply = nfs_mount_reply(pkt, len);
|
|
|
|
if (reply == -NFS_RPC_DROP)
|
|
|
|
break;
|
|
|
|
else if (reply == -NFS_RPC_ERR) {
|
2012-05-15 08:59:09 +00:00
|
|
|
puts("*** ERROR: Cannot mount\n");
|
2004-02-24 02:00:03 +00:00
|
|
|
/* just to be sure... */
|
|
|
|
NfsState = STATE_UMOUNT_REQ;
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
2004-02-24 02:00:03 +00:00
|
|
|
} else {
|
|
|
|
NfsState = STATE_LOOKUP_REQ;
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_UMOUNT_REQ:
|
2012-12-11 18:14:16 +00:00
|
|
|
reply = nfs_umountall_reply(pkt, len);
|
|
|
|
if (reply == -NFS_RPC_DROP)
|
|
|
|
break;
|
|
|
|
else if (reply == -NFS_RPC_ERR) {
|
2012-05-15 08:59:09 +00:00
|
|
|
puts("*** ERROR: Cannot umount\n");
|
2012-05-23 07:59:14 +00:00
|
|
|
net_set_state(NETLOOP_FAIL);
|
2004-02-24 02:00:03 +00:00
|
|
|
} else {
|
2012-05-15 08:59:09 +00:00
|
|
|
puts("\ndone\n");
|
2012-05-23 07:59:14 +00:00
|
|
|
net_set_state(nfs_download_state);
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_LOOKUP_REQ:
|
2012-12-11 18:14:16 +00:00
|
|
|
reply = nfs_lookup_reply(pkt, len);
|
|
|
|
if (reply == -NFS_RPC_DROP)
|
|
|
|
break;
|
|
|
|
else if (reply == -NFS_RPC_ERR) {
|
2012-05-15 08:59:09 +00:00
|
|
|
puts("*** ERROR: File lookup fail\n");
|
2004-02-24 02:00:03 +00:00
|
|
|
NfsState = STATE_UMOUNT_REQ;
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
2004-02-24 02:00:03 +00:00
|
|
|
} else {
|
|
|
|
NfsState = STATE_READ_REQ;
|
|
|
|
nfs_offset = 0;
|
|
|
|
nfs_len = NFS_READ_SIZE;
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_READLINK_REQ:
|
2012-12-11 18:14:16 +00:00
|
|
|
reply = nfs_readlink_reply(pkt, len);
|
|
|
|
if (reply == -NFS_RPC_DROP)
|
|
|
|
break;
|
|
|
|
else if (reply == -NFS_RPC_ERR) {
|
2012-05-15 08:59:09 +00:00
|
|
|
puts("*** ERROR: Symlink fail\n");
|
2004-02-24 02:00:03 +00:00
|
|
|
NfsState = STATE_UMOUNT_REQ;
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
2004-02-24 02:00:03 +00:00
|
|
|
} else {
|
2009-07-23 07:01:03 +00:00
|
|
|
debug("Symlink --> %s\n", nfs_path);
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_filename = basename(nfs_path);
|
|
|
|
nfs_path = dirname(nfs_path);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
NfsState = STATE_MOUNT_REQ;
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_READ_REQ:
|
2012-05-15 08:59:09 +00:00
|
|
|
rlen = nfs_read_reply(pkt, len);
|
2012-12-11 18:14:16 +00:00
|
|
|
NetSetTimeout(nfs_timeout, NfsTimeout);
|
2004-02-24 02:00:03 +00:00
|
|
|
if (rlen > 0) {
|
|
|
|
nfs_offset += rlen;
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
|
|
|
} else if ((rlen == -NFSERR_ISDIR) || (rlen == -NFSERR_INVAL)) {
|
2004-02-24 02:00:03 +00:00
|
|
|
/* symbolic link */
|
|
|
|
NfsState = STATE_READLINK_REQ;
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
2004-02-24 02:00:03 +00:00
|
|
|
} else {
|
2012-05-15 08:59:09 +00:00
|
|
|
if (!rlen)
|
2012-05-23 07:59:14 +00:00
|
|
|
nfs_download_state = NETLOOP_SUCCESS;
|
2004-02-24 02:00:03 +00:00
|
|
|
NfsState = STATE_UMOUNT_REQ;
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsStart(void)
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
2009-07-23 07:01:03 +00:00
|
|
|
debug("%s\n", __func__);
|
2012-05-23 07:59:14 +00:00
|
|
|
nfs_download_state = NETLOOP_FAIL;
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2015-04-08 06:41:01 +00:00
|
|
|
nfs_server_ip = net_server_ip;
|
2004-02-24 02:00:03 +00:00
|
|
|
nfs_path = (char *)nfs_path_buff;
|
|
|
|
|
|
|
|
if (nfs_path == NULL) {
|
2012-05-23 07:59:14 +00:00
|
|
|
net_set_state(NETLOOP_FAIL);
|
2012-05-15 08:59:09 +00:00
|
|
|
puts("*** ERROR: Fail allocate memory\n");
|
2004-02-24 02:00:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-08 06:41:02 +00:00
|
|
|
if (net_boot_file_name[0] == '\0') {
|
2011-12-03 03:29:44 +00:00
|
|
|
sprintf(default_filename, "/nfsroot/%02X%02X%02X%02X.img",
|
2015-04-08 06:41:01 +00:00
|
|
|
net_ip.s_addr & 0xFF,
|
|
|
|
(net_ip.s_addr >> 8) & 0xFF,
|
|
|
|
(net_ip.s_addr >> 16) & 0xFF,
|
|
|
|
(net_ip.s_addr >> 24) & 0xFF);
|
2012-05-15 08:59:09 +00:00
|
|
|
strcpy(nfs_path, default_filename);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
printf("*** Warning: no boot file name; using '%s'\n",
|
2004-02-24 02:00:03 +00:00
|
|
|
nfs_path);
|
|
|
|
} else {
|
2015-04-08 06:41:02 +00:00
|
|
|
char *p = net_boot_file_name;
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
p = strchr(p, ':');
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
if (p != NULL) {
|
2015-04-08 06:41:02 +00:00
|
|
|
nfs_server_ip = string_to_ip(net_boot_file_name);
|
2004-02-24 02:00:03 +00:00
|
|
|
++p;
|
2012-05-15 08:59:09 +00:00
|
|
|
strcpy(nfs_path, p);
|
2004-02-24 02:00:03 +00:00
|
|
|
} else {
|
2015-04-08 06:41:02 +00:00
|
|
|
strcpy(nfs_path, net_boot_file_name);
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
nfs_filename = basename(nfs_path);
|
|
|
|
nfs_path = dirname(nfs_path);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
printf("Using %s device\n", eth_get_name());
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2015-04-08 06:41:01 +00:00
|
|
|
printf("File transfer via NFS from server %pI4; our IP address is %pI4",
|
|
|
|
&nfs_server_ip, &net_ip);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
/* Check if we need to send across this subnet */
|
2015-04-08 06:41:01 +00:00
|
|
|
if (net_gateway.s_addr && net_netmask.s_addr) {
|
|
|
|
struct in_addr our_net;
|
|
|
|
struct in_addr server_net;
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2015-04-08 06:41:01 +00:00
|
|
|
our_net.s_addr = net_ip.s_addr & net_netmask.s_addr;
|
|
|
|
server_net.s_addr = net_server_ip.s_addr & net_netmask.s_addr;
|
|
|
|
if (our_net.s_addr != server_net.s_addr)
|
2012-05-15 08:59:09 +00:00
|
|
|
printf("; sending through gateway %pI4",
|
2015-04-08 06:41:01 +00:00
|
|
|
&net_gateway);
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
2012-05-15 08:59:09 +00:00
|
|
|
printf("\nFilename '%s/%s'.", nfs_path, nfs_filename);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2015-04-08 06:41:02 +00:00
|
|
|
if (net_boot_file_expected_size_in_blocks) {
|
|
|
|
printf(" Size is 0x%x Bytes = ",
|
|
|
|
net_boot_file_expected_size_in_blocks << 9);
|
|
|
|
print_size(net_boot_file_expected_size_in_blocks << 9, "");
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|
2012-05-15 08:59:09 +00:00
|
|
|
printf("\nLoad address: 0x%lx\n"
|
2004-03-23 22:14:11 +00:00
|
|
|
"Loading: *\b", load_addr);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-12-11 18:14:16 +00:00
|
|
|
NetSetTimeout(nfs_timeout, NfsTimeout);
|
2015-04-08 06:41:01 +00:00
|
|
|
net_set_udp_handler(nfs_handler);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
|
|
|
NfsTimeoutCount = 0;
|
|
|
|
NfsState = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
|
|
|
|
|
|
|
|
/*NfsOurPort = 4096 + (get_ticks() % 3072);*/
|
|
|
|
/*FIX ME !!!*/
|
|
|
|
NfsOurPort = 1000;
|
|
|
|
|
|
|
|
/* zero out server ether in case the server ip has changed */
|
2015-04-08 06:41:04 +00:00
|
|
|
memset(net_server_ethaddr, 0, 6);
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2012-05-15 08:59:09 +00:00
|
|
|
NfsSend();
|
2004-02-24 02:00:03 +00:00
|
|
|
}
|