mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Add NFS Bootloader Spec support
@ 2014-02-27 21:00 Sascha Hauer
  2014-02-27 21:00 ` [PATCH 1/5] run_command: remove unused flag parameter Sascha Hauer
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Sascha Hauer @ 2014-02-27 21:00 UTC (permalink / raw)
  To: barebox

This series adds support for booting bootloader Spec entries
via NFS. NFS URLs are specified according to rfc2224:

nfs://<host>[:<port>]<url-path>

The port argument is optional.

So 'boot nfs://192.168.2.2//home/sha/nfsroot/generic-v5'

Would look for a bootloader spec entry in the given directory
on the host and start it.

Sascha

----------------------------------------------------------------
Sascha Hauer (5):
      run_command: remove unused flag parameter
      net: constify eth_get_byname argument
      net: remove old nfs support
      net: Add ifup support
      blspec: Add NFS support

 commands/boot.c                       |   2 +-
 commands/exec.c                       |   2 +-
 commands/login.c                      |   2 +-
 commands/time.c                       |   2 +-
 common/Kconfig                        |   1 +
 common/blspec.c                       | 114 +++++-
 common/hush.c                         |   2 +-
 common/menu.c                         |   2 +-
 common/parser.c                       |   2 +-
 common/startup.c                      |   4 +-
 defaultenv/defaultenv-2-base/bin/ifup |  67 ----
 fs/fs.c                               |   2 +-
 include/common.h                      |   3 +-
 include/net.h                         |   7 +-
 net/Kconfig                           |  15 +-
 net/Makefile                          |   2 +-
 net/eth.c                             |   2 +-
 net/ifup.c                            | 179 +++++++++
 net/nfs.c                             | 737 ----------------------------------
 19 files changed, 322 insertions(+), 825 deletions(-)
 delete mode 100644 defaultenv/defaultenv-2-base/bin/ifup
 create mode 100644 net/ifup.c
 delete mode 100644 net/nfs.c

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/5] run_command: remove unused flag parameter
  2014-02-27 21:00 Add NFS Bootloader Spec support Sascha Hauer
@ 2014-02-27 21:00 ` Sascha Hauer
  2014-02-27 21:00 ` [PATCH 2/5] net: constify eth_get_byname argument Sascha Hauer
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2014-02-27 21:00 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/boot.c  | 2 +-
 commands/exec.c  | 2 +-
 commands/login.c | 2 +-
 commands/time.c  | 2 +-
 common/hush.c    | 2 +-
 common/menu.c    | 2 +-
 common/parser.c  | 2 +-
 common/startup.c | 4 ++--
 fs/fs.c          | 2 +-
 include/common.h | 3 +--
 10 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/commands/boot.c b/commands/boot.c
index ccf5827..bb8d07f 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -47,7 +47,7 @@ static int boot_script(char *path)
 	globalvar_set_match("linux.bootargs.dyn.", "");
 	globalvar_set_match("bootm.", "");
 
-	ret = run_command(path, 0);
+	ret = run_command(path);
 	if (ret) {
 		printf("Running %s failed\n", path);
 		goto out;
diff --git a/commands/exec.c b/commands/exec.c
index bd7d54a..8d12b30 100644
--- a/commands/exec.c
+++ b/commands/exec.c
@@ -39,7 +39,7 @@ static int do_exec(int argc, char *argv[])
 		if (!script)
 			return 1;
 
-		if (run_command (script, 0) == -1)
+		if (run_command(script) == -1)
 			goto out;
 		free(script);
 	}
diff --git a/commands/login.c b/commands/login.c
index b616bf1..d9297fa 100644
--- a/commands/login.c
+++ b/commands/login.c
@@ -68,7 +68,7 @@ static int do_login(int argc, char *argv[])
 
 		if (passwd_len < 0) {
 			console_allow_input(false);
-			run_command(timeout_cmd, 0);
+			run_command(timeout_cmd);
 		}
 
 		if (check_passwd(passwd, passwd_len))
diff --git a/commands/time.c b/commands/time.c
index 987c25e..2cc3292 100644
--- a/commands/time.c
+++ b/commands/time.c
@@ -27,7 +27,7 @@ static int do_time(int argc, char *argv[])
 
 	start = get_time_ns();
 
-	run_command(buf, 0);
+	run_command(buf);
 
 	end = get_time_ns();
 
diff --git a/common/hush.c b/common/hush.c
index abe2ced..bd534c1 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -1824,7 +1824,7 @@ static char * make_string(char ** inp)
 	return str;
 }
 
-int run_command (const char *cmd, int flag)
+int run_command(const char *cmd)
 {
 	struct p_context ctx;
 	int ret;
diff --git a/common/menu.c b/common/menu.c
index 4cefadb..54f2c71 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -468,7 +468,7 @@ static void menu_action_command(struct menu *m, struct menu_entry *me)
 	if (!s)
 		s = e->command;
 
-	ret = run_command (s, 0);
+	ret = run_command(s);
 
 	if (ret < 0)
 		udelay(1000000);
diff --git a/common/parser.c b/common/parser.c
index d390fb6..fcd885b 100644
--- a/common/parser.c
+++ b/common/parser.c
@@ -176,7 +176,7 @@ static void process_macros (const char *input, char *output)
  * creates or modifies environment variables (like "bootp" does).
  */
 
-int run_command (const char *cmd, int flag)
+int run_command(const char *cmd)
 {
 	char cmdbuf[CONFIG_CBSIZE];	/* working copy of cmd		*/
 	char *token;			/* start of token in cmdbuf	*/
diff --git a/common/startup.c b/common/startup.c
index d7f97a5..ceb597b 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -95,11 +95,11 @@ void __noreturn start_barebox(void)
 		pr_info("running /env/bin/init...\n");
 
 		if (!stat("/env/bin/init", &s)) {
-			run_command("source /env/bin/init", 0);
+			run_command("source /env/bin/init");
 		} else {
 			pr_err("/env/bin/init not found\n");
 			if (IS_ENABLED(CONFIG_CMD_LOGIN))
-				while(run_command("login -t 0", 0));
+				while(run_command("login -t 0"));
 		}
 	}
 
diff --git a/fs/fs.c b/fs/fs.c
index eed0fce..b0ac918 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -435,7 +435,7 @@ static void automount_mount(const char *path, int instat)
 
 		setenv("automount_path", am->path);
 		export("automount_path");
-		ret = run_command(am->cmd, 0);
+		ret = run_command(am->cmd);
 		setenv("automount_path", NULL);
 
 		if (ret)
diff --git a/include/common.h b/include/common.h
index 293f504..6987b4f 100644
--- a/include/common.h
+++ b/include/common.h
@@ -92,8 +92,7 @@ void __noreturn panic(const char *fmt, ...);
 
 char *size_human_readable(unsigned long long size);
 
-/* common/main.c */
-int	run_command	(const char *cmd, int flag);
+int run_command(const char *cmd);
 int	readline	(const char *prompt, char *buf, int len);
 
 /* common/memsize.c */
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/5] net: constify eth_get_byname argument
  2014-02-27 21:00 Add NFS Bootloader Spec support Sascha Hauer
  2014-02-27 21:00 ` [PATCH 1/5] run_command: remove unused flag parameter Sascha Hauer
@ 2014-02-27 21:00 ` Sascha Hauer
  2014-02-27 21:00 ` [PATCH 3/5] net: remove old nfs support Sascha Hauer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2014-02-27 21:00 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/net.h | 2 +-
 net/eth.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/net.h b/include/net.h
index 6c86947..a680f97 100644
--- a/include/net.h
+++ b/include/net.h
@@ -404,7 +404,7 @@ typedef void rx_handler_f(void *ctx, char *packet, unsigned int len);
 
 void eth_set_current(struct eth_device *eth);
 struct eth_device *eth_get_current(void);
-struct eth_device *eth_get_byname(char *name);
+struct eth_device *eth_get_byname(const char *name);
 
 /**
  * net_receive - Pass a received packet from an ethernet driver to the protocol stack
diff --git a/net/eth.c b/net/eth.c
index 524fb89..1f48f2d 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -144,7 +144,7 @@ struct eth_device * eth_get_current(void)
 	return eth_current;
 }
 
-struct eth_device *eth_get_byname(char *ethname)
+struct eth_device *eth_get_byname(const char *ethname)
 {
 	struct eth_device *edev;
 
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/5] net: remove old nfs support
  2014-02-27 21:00 Add NFS Bootloader Spec support Sascha Hauer
  2014-02-27 21:00 ` [PATCH 1/5] run_command: remove unused flag parameter Sascha Hauer
  2014-02-27 21:00 ` [PATCH 2/5] net: constify eth_get_byname argument Sascha Hauer
@ 2014-02-27 21:00 ` Sascha Hauer
  2014-03-04  4:03   ` Jean-Christophe PLAGNIOL-VILLARD
  2014-02-27 21:00 ` [PATCH 4/5] net: Add ifup support Sascha Hauer
  2014-02-27 21:00 ` [PATCH 5/5] blspec: Add NFS support Sascha Hauer
  4 siblings, 1 reply; 9+ messages in thread
From: Sascha Hauer @ 2014-02-27 21:00 UTC (permalink / raw)
  To: barebox

Now that we have the NFS as filesystem support for several releases
remove the old command based NFS support.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/Kconfig  |   4 -
 net/Makefile |   1 -
 net/nfs.c    | 737 -----------------------------------------------------------
 3 files changed, 742 deletions(-)
 delete mode 100644 net/nfs.c

diff --git a/net/Kconfig b/net/Kconfig
index c12193d..adafa9b 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -7,10 +7,6 @@ config NET_DHCP
 	bool
 	prompt "dhcp support"
 
-config NET_NFS
-	bool
-	prompt "nfs support"
-
 config NET_PING
 	bool
 	prompt "ping support"
diff --git a/net/Makefile b/net/Makefile
index 416e30a..98e0f09 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -1,7 +1,6 @@
 obj-$(CONFIG_NET_DHCP)	+= dhcp.o
 obj-$(CONFIG_NET)	+= eth.o
 obj-$(CONFIG_NET)	+= net.o
-obj-$(CONFIG_NET_NFS)	+= nfs.o
 obj-$(CONFIG_NET_PING)	+= ping.o
 obj-$(CONFIG_NET_RESOLV)+= dns.o
 obj-$(CONFIG_NET_NETCONSOLE) += netconsole.o
diff --git a/net/nfs.c b/net/nfs.c
deleted file mode 100644
index 9cb7dc9..0000000
--- a/net/nfs.c
+++ /dev/null
@@ -1,737 +0,0 @@
-/*
- * NFS support driver - based on etherboot and barebox'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 <clock.h>
-#include <net.h>
-#include <malloc.h>
-#include <libgen.h>
-#include <fs.h>
-#include <libgen.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <progress.h>
-#include <linux/err.h>
-
-#define SUNRPC_PORT     111
-
-#define PROG_PORTMAP    100000
-#define PROG_NFS        100003
-#define PROG_MOUNT      100005
-
-#define MSG_CALL        0
-#define MSG_REPLY       1
-
-#define PORTMAP_GETPORT 3
-
-#define MOUNT_ADDENTRY  1
-#define MOUNT_UMOUNTALL 4
-
-#define NFS_LOOKUP      4
-#define NFS_READLINK    5
-#define NFS_READ        6
-
-#define NFS_FHSIZE      32
-
-enum nfs_stat {
-	NFS_OK		= 0,
-	NFSERR_PERM	= 1,
-	NFSERR_NOENT	= 2,
-	NFSERR_IO	= 5,
-	NFSERR_NXIO	= 6,
-	NFSERR_ACCES	= 13,
-	NFSERR_EXIST	= 17,
-	NFSERR_NODEV	= 19,
-	NFSERR_NOTDIR	= 20,
-	NFSERR_ISDIR	= 21,
-	NFSERR_FBIG	= 27,
-	NFSERR_NOSPC	= 28,
-	NFSERR_ROFS	= 30,
-	NFSERR_NAMETOOLONG=63,
-	NFSERR_NOTEMPTY	= 66,
-	NFSERR_DQUOT	= 69,
-	NFSERR_STALE	= 70,
-	NFSERR_WFLUSH	= 99,
-};
-
-/* Block size used for NFS read accesses.  A RPC reply packet (including  all
- * headers) must fit within a single Ethernet frame to avoid fragmentation.
- * Chosen to be a power of two, as most NFS servers are optimized for this.  */
-#define NFS_READ_SIZE   1024
-
-struct rpc_call {
-	uint32_t id;
-	uint32_t type;
-	uint32_t rpcvers;
-	uint32_t prog;
-	uint32_t vers;
-	uint32_t proc;
-	uint32_t data[0];
-};
-
-struct rpc_reply {
-	uint32_t id;
-	uint32_t type;
-	uint32_t rstatus;
-	uint32_t verifier;
-	uint32_t v2;
-	uint32_t astatus;
-	uint32_t data[0];
-};
-
-struct rpc_t {
-	union {
-		struct {
-			uint32_t id;
-			uint32_t type;
-			uint32_t rpcvers;
-			uint32_t prog;
-			uint32_t vers;
-			uint32_t proc;
-			uint32_t data[1];
-		} call;
-		struct {
-			uint32_t id;
-			uint32_t type;
-			uint32_t rstatus;
-			uint32_t verifier;
-			uint32_t v2;
-			uint32_t astatus;
-			uint32_t data[19];
-		} reply;
-	} u;
-};
-
-#define NFS_TIMEOUT 15
-
-static unsigned long rpc_id = 0;
-static int nfs_offset = -1;
-static uint64_t nfs_timer_start;
-static int nfs_err;
-
-static char dirfh[NFS_FHSIZE];	/* file handle of directory */
-static char filefh[NFS_FHSIZE]; /* file handle of kernel image */
-
-static int	nfs_server_mount_port;
-static int	nfs_server_nfs_port;
-static int	nfs_state;
-#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
-#define STATE_DONE			8
-
-static char *nfs_filename;
-static char *nfs_path;
-static char nfs_path_buff[2048];
-
-static int net_store_fd;
-static struct net_connection *nfs_con;
-
-/**************************************************************************
-RPC_ADD_CREDENTIALS - Add RPC authentication/verifier entries
-**************************************************************************/
-static uint32_t *rpc_add_credentials(uint32_t *p)
-{
-	int hl;
-	int hostnamelen = 0;
-
-	/* 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 */
-
-	if (hostnamelen & 3)
-		*(p + hostnamelen / 4) = 0; /* add zero padding */
-
-	/* memcpy(p, hostname, hostnamelen); */ /* empty hostname */
-
-	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 int rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
-{
-	struct rpc_call pkt;
-	unsigned long id;
-	int sport;
-	int ret;
-	unsigned char *payload = net_udp_get_payload(nfs_con);
-
-	id = ++rpc_id;
-	pkt.id = htonl(id);
-	pkt.type = htonl(MSG_CALL);
-	pkt.rpcvers = htonl(2);	/* use RPC version 2 */
-	pkt.prog = htonl(rpc_prog);
-	pkt.vers = htonl(2);	/* portmapper is version 2 */
-	pkt.proc = htonl(rpc_proc);
-
-	memcpy(payload, &pkt, sizeof(pkt));
-	memcpy(payload + sizeof(pkt), data, datalen * sizeof(uint32_t));
-
-	if (rpc_prog == PROG_PORTMAP)
-		sport = SUNRPC_PORT;
-	else if (rpc_prog == PROG_MOUNT)
-		sport = nfs_server_mount_port;
-	else
-		sport = nfs_server_nfs_port;
-
-	nfs_con->udp->uh_dport = htons(sport);
-	ret = net_udp_send(nfs_con, sizeof(pkt) + datalen * sizeof(uint32_t));
-
-	return ret;
-}
-
-/**************************************************************************
-RPC_LOOKUP - Lookup RPC Port numbers
-**************************************************************************/
-static void rpc_lookup_req(int prog, int ver)
-{
-	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;
-
-	rpc_req(PROG_PORTMAP, PORTMAP_GETPORT, data, 8);
-}
-
-/**************************************************************************
-NFS_MOUNT - Mount an NFS Filesystem
-**************************************************************************/
-static void nfs_mount_req(char *path)
-{
-	uint32_t data[1024];
-	uint32_t *p;
-	int len;
-	int pathlen;
-
-	pathlen = strlen (path);
-
-	p = &(data[0]);
-	p = rpc_add_credentials(p);
-
-	*p++ = htonl(pathlen);
-	if (pathlen & 3)
-		*(p + pathlen / 4) = 0;
-	memcpy (p, path, pathlen);
-	p += (pathlen + 3) / 4;
-
-	len = p - &(data[0]);
-
-	rpc_req(PROG_MOUNT, MOUNT_ADDENTRY, data, len);
-}
-
-/**************************************************************************
-NFS_UMOUNTALL - Unmount all our NFS Filesystems on the Server
-**************************************************************************/
-static void nfs_umountall_req(void)
-{
-	uint32_t data[1024];
-	uint32_t *p;
-	int len;
-
-	if (nfs_server_mount_port < 0)
-		/* Nothing mounted, nothing to umount */
-		return;
-
-	p = &(data[0]);
-	p = rpc_add_credentials(p);
-
-	len = p - &(data[0]);
-
-	rpc_req(PROG_MOUNT, MOUNT_UMOUNTALL, data, len);
-}
-
-/***************************************************************************
- * 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 nfs_readlink_req(void)
-{
-	uint32_t data[1024];
-	uint32_t *p;
-	int len;
-
-	p = &(data[0]);
-	p = rpc_add_credentials(p);
-
-	memcpy (p, filefh, NFS_FHSIZE);
-	p += (NFS_FHSIZE / 4);
-
-	len = p - &(data[0]);
-
-	rpc_req(PROG_NFS, NFS_READLINK, data, len);
-}
-
-/**************************************************************************
-NFS_LOOKUP - Lookup Pathname
-**************************************************************************/
-static void nfs_lookup_req(char *fname)
-{
-	uint32_t data[1024];
-	uint32_t *p;
-	int len;
-	int fnamelen;
-
-	fnamelen = strlen (fname);
-
-	p = &(data[0]);
-	p = rpc_add_credentials(p);
-
-	memcpy (p, dirfh, NFS_FHSIZE);
-	p += (NFS_FHSIZE / 4);
-	*p++ = htonl(fnamelen);
-	if (fnamelen & 3)
-		*(p + fnamelen / 4) = 0;
-	memcpy (p, fname, fnamelen);
-	p += (fnamelen + 3) / 4;
-
-	len = p - &(data[0]);
-
-	rpc_req(PROG_NFS, NFS_LOOKUP, data, len);
-}
-
-/**************************************************************************
-NFS_READ - Read File on NFS Server
-**************************************************************************/
-static void nfs_read_req(int offset, int readlen)
-{
-	uint32_t data[1024];
-	uint32_t *p;
-	int len;
-
-	p = &(data[0]);
-	p = rpc_add_credentials(p);
-
-	memcpy (p, filefh, NFS_FHSIZE);
-	p += (NFS_FHSIZE / 4);
-	*p++ = htonl(offset);
-	*p++ = htonl(readlen);
-	*p++ = 0;
-
-	len = p - &(data[0]);
-
-	rpc_req(PROG_NFS, NFS_READ, data, len);
-}
-
-/**************************************************************************
-RPC request dispatcher
-**************************************************************************/
-static void nfs_send(void)
-{
-	debug("%s\n", __func__);
-
-	switch (nfs_state) {
-	case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
-		rpc_lookup_req(PROG_MOUNT, 1);
-		break;
-	case STATE_PRCLOOKUP_PROG_NFS_REQ:
-		rpc_lookup_req(PROG_NFS, 2);
-		break;
-	case STATE_MOUNT_REQ:
-		nfs_mount_req(nfs_path);
-		break;
-	case STATE_UMOUNT_REQ:
-		nfs_umountall_req();
-		break;
-	case STATE_LOOKUP_REQ:
-		nfs_lookup_req(nfs_filename);
-		break;
-	case STATE_READ_REQ:
-		nfs_read_req(nfs_offset, NFS_READ_SIZE);
-		break;
-	case STATE_READLINK_REQ:
-		nfs_readlink_req();
-		break;
-	}
-
-	nfs_timer_start = get_time_ns();
-}
-
-static int rpc_check_reply(unsigned char *pkt, int isnfs)
-{
-	uint32_t *data;
-	int nfserr;
-	struct rpc_reply rpc;
-
-	memcpy(&rpc, pkt, sizeof(rpc));
-
-	if (ntohl(rpc.id) != rpc_id)
-		return -EINVAL;
-
-	if (rpc.rstatus  ||
-	    rpc.verifier ||
-	    rpc.astatus ) {
-		return -EINVAL;
-	}
-
-	if (!isnfs)
-		return 0;
-
-	data = (uint32_t *)(pkt + sizeof(struct rpc_reply));
-	nfserr = ntohl(net_read_uint32(data));
-
-	debug("%s: state: %d, err %d\n", __func__, nfs_state, -nfserr);
-
-	if (nfserr <= 30)
-		/* These nfs codes correspond with those in errno.h */
-		return -nfserr;
-	if (nfserr == NFSERR_STALE)
-		return -ESTALE;
-
-	return -EINVAL;
-}
-
-static int rpc_lookup_reply(int prog, unsigned char *pkt, unsigned len)
-{
-	uint32_t port;
-	int ret;
-
-	ret = rpc_check_reply(pkt, 0);
-	if (ret)
-		return ret;
-
-	port = net_read_uint32((uint32_t *)(pkt + sizeof(struct rpc_reply)));
-	switch (prog) {
-	case PROG_MOUNT:
-		nfs_server_mount_port = ntohl(port);
-		break;
-	case PROG_NFS:
-		nfs_server_nfs_port = ntohl(port);
-		break;
-	}
-
-	return 0;
-}
-
-static int nfs_mount_reply(unsigned char *pkt, unsigned len)
-{
-	int ret;
-
-	ret = rpc_check_reply(pkt, 1);
-	if (ret)
-		return ret;
-
-	memcpy(dirfh, pkt + sizeof(struct rpc_reply) + 4, NFS_FHSIZE);
-
-	return 0;
-}
-
-static int nfs_umountall_reply(unsigned char *pkt, unsigned len)
-{
-	int ret;
-
-	ret = rpc_check_reply(pkt, 0);
-	if (ret)
-		return ret;
-
-	memset(dirfh, 0, sizeof(dirfh));
-
-	return 0;
-}
-
-static int nfs_lookup_reply(unsigned char *pkt, unsigned len)
-{
-	int ret;
-
-	ret = rpc_check_reply(pkt, 1);
-	if (ret)
-		return ret;
-
-	memcpy(filefh, pkt + sizeof(struct rpc_reply) + 4, NFS_FHSIZE);
-
-	return 0;
-}
-
-static int nfs_readlink_reply(unsigned char *pkt, unsigned len)
-{
-	uint32_t *data;
-	char *path;
-	int rlen;
-	int ret;
-
-	ret = rpc_check_reply(pkt, 1);
-	if (ret)
-		return ret;
-
-	data = (uint32_t *)(pkt + sizeof(struct rpc_reply));
-
-	data++;
-
-	rlen = ntohl(net_read_uint32(data)); /* new path length */
-
-	data++;
-	path = (char *)data;
-
-	if (*path != '/') {
-		strcat(nfs_path, "/");
-		strncat(nfs_path, path, rlen);
-	} else {
-		memcpy(nfs_path, path, rlen);
-		nfs_path[rlen] = 0;
-	}
-	return 0;
-}
-
-static int nfs_read_reply(unsigned char *pkt, unsigned len)
-{
-	int rlen;
-	uint32_t *data;
-	int ret;
-
-	debug("%s\n", __func__);
-
-	ret = rpc_check_reply(pkt, 1);
-	if (ret)
-		return ret;
-
-	data = (uint32_t *)(pkt + sizeof(struct rpc_reply));
-
-	if (!nfs_offset) {
-		uint32_t filesize = ntohl(net_read_uint32(data + 6));
-		init_progression_bar(filesize);
-	}
-
-	rlen = ntohl(net_read_uint32(data + 18));
-
-	ret = write(net_store_fd, (char *)(data + 19), rlen);
-	if (ret < 0) {
-		perror("write");
-		return ret;
-	}
-
-	return rlen;
-}
-
-/**************************************************************************
-Interfaces of barebox
-**************************************************************************/
-
-static void nfs_handler(void *ctx, char *packet, unsigned len)
-{
-	char *pkt = net_eth_to_udp_payload(packet);
-	int ret;
-
-	debug("%s\n", __func__);
-
-	switch (nfs_state) {
-	case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
-		ret = rpc_lookup_reply(PROG_MOUNT, pkt, len);
-		if (ret)
-			goto err_out;
-		nfs_state = STATE_PRCLOOKUP_PROG_NFS_REQ;
-		break;
-
-	case STATE_PRCLOOKUP_PROG_NFS_REQ:
-		ret = rpc_lookup_reply(PROG_NFS, pkt, len);
-		if (ret)
-			goto err_out;
-		nfs_state = STATE_MOUNT_REQ;
-		break;
-
-	case STATE_MOUNT_REQ:
-		ret = nfs_mount_reply(pkt, len);
-		if (ret)
-			goto err_out;
-
-		nfs_state = STATE_LOOKUP_REQ;
-		break;
-
-	case STATE_UMOUNT_REQ:
-		ret = nfs_umountall_reply(pkt, len);
-		if (ret)
-			nfs_err = ret;
-		nfs_state = STATE_DONE;
-		return;
-
-	case STATE_LOOKUP_REQ:
-		ret = nfs_lookup_reply(pkt, len);
-		if (ret)
-			goto err_umount;
-
-		nfs_state = STATE_READ_REQ;
-		nfs_offset = 0;
-		break;
-
-	case STATE_READLINK_REQ:
-		ret = nfs_readlink_reply(pkt, len);
-		if (ret)
-			goto err_umount;
-
-		debug("Symlink --> %s\n", nfs_path);
-
-		nfs_filename = basename(nfs_path);
-		nfs_path     = dirname(nfs_path);
-
-		nfs_state = STATE_MOUNT_REQ;
-		break;
-
-	case STATE_READ_REQ:
-		ret = nfs_read_reply(pkt, len);
-		nfs_timer_start = get_time_ns();
-		if (ret > 0)
-			nfs_offset += ret;
-		else if (ret == -EISDIR || ret == -EINVAL)
-			/* symbolic link */
-			nfs_state = STATE_READLINK_REQ;
-		else
-			goto err_umount;
-		show_progress(nfs_offset);
-		break;
-	}
-
-	nfs_send();
-
-	return;
-
-err_umount:
-	nfs_state = STATE_UMOUNT_REQ;
-	nfs_err = ret;
-	nfs_send();
-	return;
-
-err_out:
-	nfs_state = STATE_DONE;
-	nfs_err = ret;
-}
-
-static void nfs_start(char *p)
-{
-	debug("%s\n", __func__);
-
-	nfs_path = (char *)nfs_path_buff;
-
-	strcpy(nfs_path, p);
-
-	nfs_filename = basename (nfs_path);
-	nfs_path     = dirname (nfs_path);
-
-	printf("\nFilename '%s/%s'.\n", nfs_path, nfs_filename);
-
-	nfs_state = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
-
-	nfs_send();
-}
-
-static int do_nfs(int argc, char *argv[])
-{
-	char  *localfile;
-	char  *remotefile;
-
-	if (argc < 2)
-		return COMMAND_ERROR_USAGE;
-
-	remotefile = argv[1];
-
-	if (argc == 2)
-		localfile = basename(remotefile);
-	else
-		localfile = argv[2];
-
-	net_store_fd = open(localfile, O_WRONLY | O_CREAT);
-	if (net_store_fd < 0) {
-		perror("open");
-		return 1;
-	}
-
-	nfs_con = net_udp_new(net_get_serverip(), 0, nfs_handler, NULL);
-	if (IS_ERR(nfs_con)) {
-		nfs_err = PTR_ERR(nfs_con);
-		goto err_udp;
-	}
-	net_udp_bind(nfs_con, 1000);
-
-	nfs_err = 0;
-
-	nfs_start(remotefile);
-
-	while (nfs_state != STATE_DONE) {
-		if (ctrlc()) {
-			nfs_err = -EINTR;
-			break;
-		}
-		net_poll();
-		if (is_timeout(nfs_timer_start, NFS_TIMEOUT * SECOND)) {
-			show_progress(-1);
-			nfs_send();
-		}
-	}
-
-	net_unregister(nfs_con);
-err_udp:
-	close(net_store_fd);
-	if (nfs_err) {
-		printf("NFS failed: %s\n", strerror(-nfs_err));
-		unlink(localfile);
-	}
-
-	printf("\n");
-
-	return nfs_err == 0 ? 0 : 1;
-}
-
-static const __maybe_unused char cmd_nfs_help[] =
-"Usage: nfs <file> [localfile]\n"
-"Load a file via network using nfs protocol.\n";
-
-BAREBOX_CMD_START(nfs)
-	.cmd		= do_nfs,
-	.usage		= "boot image via network using nfs protocol",
-	BAREBOX_CMD_HELP(cmd_nfs_help)
-BAREBOX_CMD_END
-
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/5] net: Add ifup support
  2014-02-27 21:00 Add NFS Bootloader Spec support Sascha Hauer
                   ` (2 preceding siblings ...)
  2014-02-27 21:00 ` [PATCH 3/5] net: remove old nfs support Sascha Hauer
@ 2014-02-27 21:00 ` Sascha Hauer
  2014-02-27 21:00 ` [PATCH 5/5] blspec: Add NFS support Sascha Hauer
  4 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2014-02-27 21:00 UTC (permalink / raw)
  To: barebox

The defaultenv-2 has ifup support as a shell script. This patch
replaces it with a command which is more robust, can be called
from C and now can also bring up all configured interfaces.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/Kconfig                        |   1 +
 defaultenv/defaultenv-2-base/bin/ifup |  67 -------------
 include/net.h                         |   5 +
 net/Kconfig                           |  11 +++
 net/Makefile                          |   1 +
 net/ifup.c                            | 179 ++++++++++++++++++++++++++++++++++
 6 files changed, 197 insertions(+), 67 deletions(-)
 delete mode 100644 defaultenv/defaultenv-2-base/bin/ifup
 create mode 100644 net/ifup.c

diff --git a/common/Kconfig b/common/Kconfig
index 5224838..5989502 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -596,6 +596,7 @@ config DEFAULT_ENVIRONMENT_GENERIC_NEW
 	select CMD_DIRNAME
 	select FLEXIBLE_BOOTARGS
 	select CMD_BOOT
+	select NET_CMD_IFUP if NET
 	prompt "Generic environment template"
 
 config DEFAULT_ENVIRONMENT_GENERIC_NEW_MENU
diff --git a/defaultenv/defaultenv-2-base/bin/ifup b/defaultenv/defaultenv-2-base/bin/ifup
deleted file mode 100644
index 37b986c..0000000
--- a/defaultenv/defaultenv-2-base/bin/ifup
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/bin/sh
-
-mkdir -p /tmp/network
-
-if [ $# != 1 ]; then
-	echo "usage: ifup <interface>"
-	exit 1
-fi
-
-interface="$1"
-
-if [ -f /tmp/network/$interface ]; then
-	exit 0
-fi
-
-cmd=/env/network/$interface
-
-if [ ! -e $cmd ]; then
-	echo "$f: no such file"
-	exit 1
-fi
-
-ip=
-ipaddr=
-netmask=
-gateway=
-serverip=
-ethaddr=
-
-. $cmd
-
-if [ $? != 0 ]; then
-	echo "failed to bring up $interface"
-	exit 1
-fi
-
-if [ -f /env/network/${interface}-discover ]; then
-	/env/network/${interface}-discover
-	if [ $? != 0 ]; then
-		echo "failed to discover eth0"
-		exit 1
-	fi
-fi
-
-if [ -n "$ethaddr" ]; then
-	${interface}.ethaddr=$ethaddr
-fi
-
-if [ "$ip" = static ]; then
-	${interface}.ipaddr=$ipaddr
-	${interface}.netmask=$netmask
-	${interface}.serverip=$serverip
-	${interface}.gateway=$gateway
-	ret=0
-elif [ "$ip" = dhcp ]; then
-	dhcp
-	ret=$?
-	if [ $ret = 0 -a -n "$serverip" ]; then
-		${interface}.serverip=$serverip
-	fi
-fi
-
-if [ $ret = 0 ]; then
-	echo -o /tmp/network/$interface up
-fi
-
-exit $ret
diff --git a/include/net.h b/include/net.h
index a680f97..3b800b7 100644
--- a/include/net.h
+++ b/include/net.h
@@ -457,4 +457,9 @@ int net_icmp_send(struct net_connection *con, int len);
 
 void led_trigger_network(enum led_trigger trigger);
 
+#define IFUP_FLAG_FORCE		(1 << 0)
+
+int ifup(const char *name, unsigned flags);
+int ifup_all(unsigned flags);
+
 #endif /* __NET_H__ */
diff --git a/net/Kconfig b/net/Kconfig
index adafa9b..d59a88d 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -22,4 +22,15 @@ config NET_RESOLV
 	bool
 	prompt "dns support"
 
+config NET_IFUP
+	default y
+	bool
+
+config NET_CMD_IFUP
+	bool
+	prompt "ifup support"
+	help
+	  This enables the 'ifup' command which is used to bring up network
+	  interfaces based on config files under /env/network/<ethname>
+
 endif
diff --git a/net/Makefile b/net/Makefile
index 98e0f09..30f6e5a 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_NET)	+= net.o
 obj-$(CONFIG_NET_PING)	+= ping.o
 obj-$(CONFIG_NET_RESOLV)+= dns.o
 obj-$(CONFIG_NET_NETCONSOLE) += netconsole.o
+obj-$(CONFIG_NET_IFUP)	+= ifup.o
diff --git a/net/ifup.c b/net/ifup.c
new file mode 100644
index 0000000..3b89ce1
--- /dev/null
+++ b/net/ifup.c
@@ -0,0 +1,179 @@
+/*
+ * ifup.c - bring up network interfaces
+ *
+ * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more detaiifup.
+ *
+ */
+#define pr_fmt(fmt)  "ifup: " fmt
+
+#include <environment.h>
+#include <command.h>
+#include <common.h>
+#include <getopt.h>
+#include <net.h>
+#include <fs.h>
+#include <linux/stat.h>
+
+static char *vars[] = {
+	"ipaddr",
+	"netmask",
+	"gateway",
+	"serverip",
+	"ethaddr",
+};
+
+static int eth_set_param(struct device_d *dev, const char *param)
+{
+	const char *value = getenv(param);
+
+	if (!value)
+		return 0;
+	if (!*value)
+		return 0;
+
+	return dev_set_param(dev, param, value);
+}
+
+int ifup(const char *name, unsigned flags)
+{
+	int ret;
+	char *cmd, *cmd_discover;
+	const char *ip;
+	struct stat s;
+	int i;
+	struct device_d *dev;
+	struct eth_device *edev = eth_get_byname(name);
+
+	if (edev && edev->ipaddr && !(flags & IFUP_FLAG_FORCE))
+		return 0;
+
+	env_push_context();
+
+	setenv("ip", "");
+
+	for (i = 0; i < ARRAY_SIZE(vars); i++)
+		setenv(vars[i], "");
+
+	cmd = asprintf("source /env/network/%s", name);
+	cmd_discover = asprintf("/env/network/%s-discover", name);
+
+	ret = run_command(cmd);
+	if (ret)
+		goto out;
+
+	ret = stat(cmd_discover, &s);
+	if (!ret) {
+		ret = run_command(cmd_discover);
+		if (ret)
+			goto out;
+	}
+
+	dev = get_device_by_name(name);
+	if (!dev) {
+		pr_err("Cannot find device %s\n", name);
+		goto out;
+	}
+
+	ret = eth_set_param(dev, "ethaddr");
+	if (ret)
+		goto out;
+
+	ip = getenv("ip");
+	if (!strcmp(ip, "dhcp")) {
+		ret = run_command("dhcp");
+		if (ret)
+			goto out;
+	} else if (!strcmp(ip, "static")) {
+		for (i = 0; i < ARRAY_SIZE(vars); i++) {
+			ret = eth_set_param(dev, vars[i]);
+			if (ret)
+				goto out;
+		}
+	} else {
+		pr_err("unknown ip type: %s\n", ip);
+		ret = -EINVAL;
+		goto out;
+	}
+
+	ret = 0;
+out:
+	env_pop_context();
+	free(cmd);
+	free(cmd_discover);
+
+	return ret;
+}
+
+int ifup_all(unsigned flags)
+{
+	DIR *dir;
+	struct dirent *d;
+
+	dir = opendir("/env/network");
+	if (!dir)
+		return -ENOENT;
+
+	while ((d = readdir(dir))) {
+		if (*d->d_name == '.')
+			continue;
+		ifup(d->d_name, flags);
+	}
+
+	closedir(dir);
+
+	return 0;
+}
+
+#if IS_ENABLED(CONFIG_NET_CMD_IFUP)
+
+static int do_ifup(int argc, char *argv[])
+{
+	int opt;
+	unsigned flags = 0;
+	int all = 0;
+
+	while ((opt = getopt(argc, argv, "af")) > 0) {
+		switch (opt) {
+		case 'f':
+			flags |= IFUP_FLAG_FORCE;
+			break;
+		case 'a':
+			all = 1;
+			break;
+		}
+	}
+
+	if (all)
+		return ifup_all(flags);
+
+	if (argc == optind)
+		return COMMAND_ERROR_USAGE;
+
+	return ifup(argv[optind], flags);
+}
+
+BAREBOX_CMD_HELP_START(ifup)
+BAREBOX_CMD_HELP_USAGE("ifup [OPTIONS] <interface>\n")
+BAREBOX_CMD_HELP_OPT  ("-a",  "bring up all interfaces\n")
+BAREBOX_CMD_HELP_OPT  ("-f",  "Force. Configure even if ip already set\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(ifup)
+	.cmd		= do_ifup,
+	.usage		= "Bring up network interfaces",
+	BAREBOX_CMD_HELP(cmd_ifup_help)
+BAREBOX_CMD_END
+
+#endif
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/5] blspec: Add NFS support
  2014-02-27 21:00 Add NFS Bootloader Spec support Sascha Hauer
                   ` (3 preceding siblings ...)
  2014-02-27 21:00 ` [PATCH 4/5] net: Add ifup support Sascha Hauer
@ 2014-02-27 21:00 ` Sascha Hauer
  4 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2014-02-27 21:00 UTC (permalink / raw)
  To: barebox

With this barebox can start root filesystems containing bootloader
spec entries via NFS. It is used as:

boot nfs://<ipaddr>[:<port]//path/to/nfsroot

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/blspec.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 112 insertions(+), 2 deletions(-)

diff --git a/common/blspec.c b/common/blspec.c
index df3c9c3..fcdcc77 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -10,6 +10,8 @@
  * GNU General Public License for more details.
  *
  */
+#define pr_fmt(fmt)  "blspec: " fmt
+
 #include <environment.h>
 #include <globalvar.h>
 #include <readkey.h>
@@ -22,6 +24,7 @@
 #include <libbb.h>
 #include <init.h>
 #include <boot.h>
+#include <net.h>
 #include <fs.h>
 #include <of.h>
 #include <linux/stat.h>
@@ -131,6 +134,107 @@ static int blspec_have_entry(struct blspec *blspec, const char *path)
 }
 
 /*
+ * nfs_find_mountpath - Check if a given url is already mounted
+ */
+static const char *nfs_find_mountpath(const char *nfshostpath)
+{
+	struct fs_device_d *fsdev;
+
+	for_each_fs_device(fsdev) {
+		if (fsdev->backingstore && !strcmp(fsdev->backingstore, nfshostpath))
+			return fsdev->path;
+	}
+
+	return NULL;
+}
+
+/*
+ * parse_nfs_url - check for nfs:// style url
+ *
+ * Check if the passed string is a NFS url and if yes, mount the
+ * NFS and return the path we have mounted to.
+ */
+static char *parse_nfs_url(const char *url)
+{
+	char *sep, *str, *host, *port, *path;
+	char *mountpath = NULL, *hostpath = NULL, *options = NULL;
+	const char *prevpath;
+	IPaddr_t ip;
+	int ret;
+
+	if (!IS_ENABLED(CONFIG_FS_NFS))
+		return NULL;
+
+	if (strncmp(url, "nfs://", 6))
+		return ERR_PTR(-EINVAL);
+
+	url += 6;
+
+	str = xstrdup(url);
+
+	host = str;
+
+	sep = strchr(str, '/');
+	if (!sep) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	*sep++ = 0;
+
+	path = sep;
+
+	port = strchr(host, ':');
+	if (port)
+		*port++ = 0;
+
+	ret = ifup_all(0);
+	if (ret) {
+		pr_err("Failed to bring up networking\n");
+		goto out;
+	}
+
+	ip = resolv(host);
+	if (ip == 0)
+		goto out;
+
+	hostpath = asprintf("%s:%s", ip_to_string(ip), path);
+
+	prevpath = nfs_find_mountpath(hostpath);
+
+	if (prevpath) {
+		mountpath = xstrdup(prevpath);
+	} else {
+		mountpath = asprintf("/mnt/nfs-%s-blspec-%08x", host, rand());
+		if (port)
+			options = asprintf("mountport=%s,port=%s", port, port);
+
+		ret = make_directory(mountpath);
+		if (ret)
+			goto out;
+
+		pr_debug("host: %s port: %s path: %s\n", host, port, path);
+		pr_debug("hostpath: %s mountpath: %s options: %s\n", hostpath, mountpath, options);
+
+		ret = mount(hostpath, "nfs", mountpath, options);
+		if (ret)
+			goto out;
+	}
+
+	ret = 0;
+
+out:
+	free(str);
+	free(hostpath);
+	free(options);
+
+	if (ret)
+		free(mountpath);
+
+	return ret ? ERR_PTR(ret) : mountpath;
+}
+
+/*
  * blspec_scan_directory - scan over a directory
  *
  * Given a root path collects all blspec entries found under /blspec/entries/.
@@ -145,9 +249,13 @@ int blspec_scan_directory(struct blspec *blspec, const char *root)
 	char *abspath;
 	int ret, found = 0;
 	const char *dirname = "loader/entries";
-	char *entry_default = NULL, *entry_once = NULL, *name;
+	char *entry_default = NULL, *entry_once = NULL, *name, *nfspath = NULL;
+
+	nfspath = parse_nfs_url(root);
+	if (!IS_ERR(nfspath))
+		root = nfspath;
 
-	pr_debug("%s: %s %s\n", __func__, root, dirname);
+	pr_info("%s: %s %s\n", __func__, root, dirname);
 
 	entry_default = read_file_line("%s/default", root);
 	entry_once = read_file_line("%s/once", root);
@@ -239,6 +347,8 @@ int blspec_scan_directory(struct blspec *blspec, const char *root)
 
 	closedir(dir);
 err_out:
+	if (!IS_ERR(nfspath))
+		free(nfspath);
 	free(abspath);
 	free(entry_default);
 	free(entry_once);
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/5] net: remove old nfs support
  2014-02-27 21:00 ` [PATCH 3/5] net: remove old nfs support Sascha Hauer
@ 2014-03-04  4:03   ` Jean-Christophe PLAGNIOL-VILLARD
  2014-03-06 16:21     ` Sascha Hauer
  0 siblings, 1 reply; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2014-03-04  4:03 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 22:00 Thu 27 Feb     , Sascha Hauer wrote:
> Now that we have the NFS as filesystem support for several releases
> remove the old command based NFS support.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

as the bootp is not fully supported on default env2 do not drop it

Best Regards,
J.
> ---
>  net/Kconfig  |   4 -
>  net/Makefile |   1 -
>  net/nfs.c    | 737 -----------------------------------------------------------
>  3 files changed, 742 deletions(-)
>  delete mode 100644 net/nfs.c
> 
> diff --git a/net/Kconfig b/net/Kconfig
> index c12193d..adafa9b 100644
> --- a/net/Kconfig
> +++ b/net/Kconfig
> @@ -7,10 +7,6 @@ config NET_DHCP
>  	bool
>  	prompt "dhcp support"
>  
> -config NET_NFS
> -	bool
> -	prompt "nfs support"
> -
>  config NET_PING
>  	bool
>  	prompt "ping support"
> diff --git a/net/Makefile b/net/Makefile
> index 416e30a..98e0f09 100644
> --- a/net/Makefile
> +++ b/net/Makefile
> @@ -1,7 +1,6 @@
>  obj-$(CONFIG_NET_DHCP)	+= dhcp.o
>  obj-$(CONFIG_NET)	+= eth.o
>  obj-$(CONFIG_NET)	+= net.o
> -obj-$(CONFIG_NET_NFS)	+= nfs.o
>  obj-$(CONFIG_NET_PING)	+= ping.o
>  obj-$(CONFIG_NET_RESOLV)+= dns.o
>  obj-$(CONFIG_NET_NETCONSOLE) += netconsole.o
> diff --git a/net/nfs.c b/net/nfs.c
> deleted file mode 100644
> index 9cb7dc9..0000000
> --- a/net/nfs.c
> +++ /dev/null
> @@ -1,737 +0,0 @@
> -/*
> - * NFS support driver - based on etherboot and barebox'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 <clock.h>
> -#include <net.h>
> -#include <malloc.h>
> -#include <libgen.h>
> -#include <fs.h>
> -#include <libgen.h>
> -#include <fcntl.h>
> -#include <errno.h>
> -#include <progress.h>
> -#include <linux/err.h>
> -
> -#define SUNRPC_PORT     111
> -
> -#define PROG_PORTMAP    100000
> -#define PROG_NFS        100003
> -#define PROG_MOUNT      100005
> -
> -#define MSG_CALL        0
> -#define MSG_REPLY       1
> -
> -#define PORTMAP_GETPORT 3
> -
> -#define MOUNT_ADDENTRY  1
> -#define MOUNT_UMOUNTALL 4
> -
> -#define NFS_LOOKUP      4
> -#define NFS_READLINK    5
> -#define NFS_READ        6
> -
> -#define NFS_FHSIZE      32
> -
> -enum nfs_stat {
> -	NFS_OK		= 0,
> -	NFSERR_PERM	= 1,
> -	NFSERR_NOENT	= 2,
> -	NFSERR_IO	= 5,
> -	NFSERR_NXIO	= 6,
> -	NFSERR_ACCES	= 13,
> -	NFSERR_EXIST	= 17,
> -	NFSERR_NODEV	= 19,
> -	NFSERR_NOTDIR	= 20,
> -	NFSERR_ISDIR	= 21,
> -	NFSERR_FBIG	= 27,
> -	NFSERR_NOSPC	= 28,
> -	NFSERR_ROFS	= 30,
> -	NFSERR_NAMETOOLONG=63,
> -	NFSERR_NOTEMPTY	= 66,
> -	NFSERR_DQUOT	= 69,
> -	NFSERR_STALE	= 70,
> -	NFSERR_WFLUSH	= 99,
> -};
> -
> -/* Block size used for NFS read accesses.  A RPC reply packet (including  all
> - * headers) must fit within a single Ethernet frame to avoid fragmentation.
> - * Chosen to be a power of two, as most NFS servers are optimized for this.  */
> -#define NFS_READ_SIZE   1024
> -
> -struct rpc_call {
> -	uint32_t id;
> -	uint32_t type;
> -	uint32_t rpcvers;
> -	uint32_t prog;
> -	uint32_t vers;
> -	uint32_t proc;
> -	uint32_t data[0];
> -};
> -
> -struct rpc_reply {
> -	uint32_t id;
> -	uint32_t type;
> -	uint32_t rstatus;
> -	uint32_t verifier;
> -	uint32_t v2;
> -	uint32_t astatus;
> -	uint32_t data[0];
> -};
> -
> -struct rpc_t {
> -	union {
> -		struct {
> -			uint32_t id;
> -			uint32_t type;
> -			uint32_t rpcvers;
> -			uint32_t prog;
> -			uint32_t vers;
> -			uint32_t proc;
> -			uint32_t data[1];
> -		} call;
> -		struct {
> -			uint32_t id;
> -			uint32_t type;
> -			uint32_t rstatus;
> -			uint32_t verifier;
> -			uint32_t v2;
> -			uint32_t astatus;
> -			uint32_t data[19];
> -		} reply;
> -	} u;
> -};
> -
> -#define NFS_TIMEOUT 15
> -
> -static unsigned long rpc_id = 0;
> -static int nfs_offset = -1;
> -static uint64_t nfs_timer_start;
> -static int nfs_err;
> -
> -static char dirfh[NFS_FHSIZE];	/* file handle of directory */
> -static char filefh[NFS_FHSIZE]; /* file handle of kernel image */
> -
> -static int	nfs_server_mount_port;
> -static int	nfs_server_nfs_port;
> -static int	nfs_state;
> -#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
> -#define STATE_DONE			8
> -
> -static char *nfs_filename;
> -static char *nfs_path;
> -static char nfs_path_buff[2048];
> -
> -static int net_store_fd;
> -static struct net_connection *nfs_con;
> -
> -/**************************************************************************
> -RPC_ADD_CREDENTIALS - Add RPC authentication/verifier entries
> -**************************************************************************/
> -static uint32_t *rpc_add_credentials(uint32_t *p)
> -{
> -	int hl;
> -	int hostnamelen = 0;
> -
> -	/* 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 */
> -
> -	if (hostnamelen & 3)
> -		*(p + hostnamelen / 4) = 0; /* add zero padding */
> -
> -	/* memcpy(p, hostname, hostnamelen); */ /* empty hostname */
> -
> -	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 int rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
> -{
> -	struct rpc_call pkt;
> -	unsigned long id;
> -	int sport;
> -	int ret;
> -	unsigned char *payload = net_udp_get_payload(nfs_con);
> -
> -	id = ++rpc_id;
> -	pkt.id = htonl(id);
> -	pkt.type = htonl(MSG_CALL);
> -	pkt.rpcvers = htonl(2);	/* use RPC version 2 */
> -	pkt.prog = htonl(rpc_prog);
> -	pkt.vers = htonl(2);	/* portmapper is version 2 */
> -	pkt.proc = htonl(rpc_proc);
> -
> -	memcpy(payload, &pkt, sizeof(pkt));
> -	memcpy(payload + sizeof(pkt), data, datalen * sizeof(uint32_t));
> -
> -	if (rpc_prog == PROG_PORTMAP)
> -		sport = SUNRPC_PORT;
> -	else if (rpc_prog == PROG_MOUNT)
> -		sport = nfs_server_mount_port;
> -	else
> -		sport = nfs_server_nfs_port;
> -
> -	nfs_con->udp->uh_dport = htons(sport);
> -	ret = net_udp_send(nfs_con, sizeof(pkt) + datalen * sizeof(uint32_t));
> -
> -	return ret;
> -}
> -
> -/**************************************************************************
> -RPC_LOOKUP - Lookup RPC Port numbers
> -**************************************************************************/
> -static void rpc_lookup_req(int prog, int ver)
> -{
> -	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;
> -
> -	rpc_req(PROG_PORTMAP, PORTMAP_GETPORT, data, 8);
> -}
> -
> -/**************************************************************************
> -NFS_MOUNT - Mount an NFS Filesystem
> -**************************************************************************/
> -static void nfs_mount_req(char *path)
> -{
> -	uint32_t data[1024];
> -	uint32_t *p;
> -	int len;
> -	int pathlen;
> -
> -	pathlen = strlen (path);
> -
> -	p = &(data[0]);
> -	p = rpc_add_credentials(p);
> -
> -	*p++ = htonl(pathlen);
> -	if (pathlen & 3)
> -		*(p + pathlen / 4) = 0;
> -	memcpy (p, path, pathlen);
> -	p += (pathlen + 3) / 4;
> -
> -	len = p - &(data[0]);
> -
> -	rpc_req(PROG_MOUNT, MOUNT_ADDENTRY, data, len);
> -}
> -
> -/**************************************************************************
> -NFS_UMOUNTALL - Unmount all our NFS Filesystems on the Server
> -**************************************************************************/
> -static void nfs_umountall_req(void)
> -{
> -	uint32_t data[1024];
> -	uint32_t *p;
> -	int len;
> -
> -	if (nfs_server_mount_port < 0)
> -		/* Nothing mounted, nothing to umount */
> -		return;
> -
> -	p = &(data[0]);
> -	p = rpc_add_credentials(p);
> -
> -	len = p - &(data[0]);
> -
> -	rpc_req(PROG_MOUNT, MOUNT_UMOUNTALL, data, len);
> -}
> -
> -/***************************************************************************
> - * 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 nfs_readlink_req(void)
> -{
> -	uint32_t data[1024];
> -	uint32_t *p;
> -	int len;
> -
> -	p = &(data[0]);
> -	p = rpc_add_credentials(p);
> -
> -	memcpy (p, filefh, NFS_FHSIZE);
> -	p += (NFS_FHSIZE / 4);
> -
> -	len = p - &(data[0]);
> -
> -	rpc_req(PROG_NFS, NFS_READLINK, data, len);
> -}
> -
> -/**************************************************************************
> -NFS_LOOKUP - Lookup Pathname
> -**************************************************************************/
> -static void nfs_lookup_req(char *fname)
> -{
> -	uint32_t data[1024];
> -	uint32_t *p;
> -	int len;
> -	int fnamelen;
> -
> -	fnamelen = strlen (fname);
> -
> -	p = &(data[0]);
> -	p = rpc_add_credentials(p);
> -
> -	memcpy (p, dirfh, NFS_FHSIZE);
> -	p += (NFS_FHSIZE / 4);
> -	*p++ = htonl(fnamelen);
> -	if (fnamelen & 3)
> -		*(p + fnamelen / 4) = 0;
> -	memcpy (p, fname, fnamelen);
> -	p += (fnamelen + 3) / 4;
> -
> -	len = p - &(data[0]);
> -
> -	rpc_req(PROG_NFS, NFS_LOOKUP, data, len);
> -}
> -
> -/**************************************************************************
> -NFS_READ - Read File on NFS Server
> -**************************************************************************/
> -static void nfs_read_req(int offset, int readlen)
> -{
> -	uint32_t data[1024];
> -	uint32_t *p;
> -	int len;
> -
> -	p = &(data[0]);
> -	p = rpc_add_credentials(p);
> -
> -	memcpy (p, filefh, NFS_FHSIZE);
> -	p += (NFS_FHSIZE / 4);
> -	*p++ = htonl(offset);
> -	*p++ = htonl(readlen);
> -	*p++ = 0;
> -
> -	len = p - &(data[0]);
> -
> -	rpc_req(PROG_NFS, NFS_READ, data, len);
> -}
> -
> -/**************************************************************************
> -RPC request dispatcher
> -**************************************************************************/
> -static void nfs_send(void)
> -{
> -	debug("%s\n", __func__);
> -
> -	switch (nfs_state) {
> -	case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
> -		rpc_lookup_req(PROG_MOUNT, 1);
> -		break;
> -	case STATE_PRCLOOKUP_PROG_NFS_REQ:
> -		rpc_lookup_req(PROG_NFS, 2);
> -		break;
> -	case STATE_MOUNT_REQ:
> -		nfs_mount_req(nfs_path);
> -		break;
> -	case STATE_UMOUNT_REQ:
> -		nfs_umountall_req();
> -		break;
> -	case STATE_LOOKUP_REQ:
> -		nfs_lookup_req(nfs_filename);
> -		break;
> -	case STATE_READ_REQ:
> -		nfs_read_req(nfs_offset, NFS_READ_SIZE);
> -		break;
> -	case STATE_READLINK_REQ:
> -		nfs_readlink_req();
> -		break;
> -	}
> -
> -	nfs_timer_start = get_time_ns();
> -}
> -
> -static int rpc_check_reply(unsigned char *pkt, int isnfs)
> -{
> -	uint32_t *data;
> -	int nfserr;
> -	struct rpc_reply rpc;
> -
> -	memcpy(&rpc, pkt, sizeof(rpc));
> -
> -	if (ntohl(rpc.id) != rpc_id)
> -		return -EINVAL;
> -
> -	if (rpc.rstatus  ||
> -	    rpc.verifier ||
> -	    rpc.astatus ) {
> -		return -EINVAL;
> -	}
> -
> -	if (!isnfs)
> -		return 0;
> -
> -	data = (uint32_t *)(pkt + sizeof(struct rpc_reply));
> -	nfserr = ntohl(net_read_uint32(data));
> -
> -	debug("%s: state: %d, err %d\n", __func__, nfs_state, -nfserr);
> -
> -	if (nfserr <= 30)
> -		/* These nfs codes correspond with those in errno.h */
> -		return -nfserr;
> -	if (nfserr == NFSERR_STALE)
> -		return -ESTALE;
> -
> -	return -EINVAL;
> -}
> -
> -static int rpc_lookup_reply(int prog, unsigned char *pkt, unsigned len)
> -{
> -	uint32_t port;
> -	int ret;
> -
> -	ret = rpc_check_reply(pkt, 0);
> -	if (ret)
> -		return ret;
> -
> -	port = net_read_uint32((uint32_t *)(pkt + sizeof(struct rpc_reply)));
> -	switch (prog) {
> -	case PROG_MOUNT:
> -		nfs_server_mount_port = ntohl(port);
> -		break;
> -	case PROG_NFS:
> -		nfs_server_nfs_port = ntohl(port);
> -		break;
> -	}
> -
> -	return 0;
> -}
> -
> -static int nfs_mount_reply(unsigned char *pkt, unsigned len)
> -{
> -	int ret;
> -
> -	ret = rpc_check_reply(pkt, 1);
> -	if (ret)
> -		return ret;
> -
> -	memcpy(dirfh, pkt + sizeof(struct rpc_reply) + 4, NFS_FHSIZE);
> -
> -	return 0;
> -}
> -
> -static int nfs_umountall_reply(unsigned char *pkt, unsigned len)
> -{
> -	int ret;
> -
> -	ret = rpc_check_reply(pkt, 0);
> -	if (ret)
> -		return ret;
> -
> -	memset(dirfh, 0, sizeof(dirfh));
> -
> -	return 0;
> -}
> -
> -static int nfs_lookup_reply(unsigned char *pkt, unsigned len)
> -{
> -	int ret;
> -
> -	ret = rpc_check_reply(pkt, 1);
> -	if (ret)
> -		return ret;
> -
> -	memcpy(filefh, pkt + sizeof(struct rpc_reply) + 4, NFS_FHSIZE);
> -
> -	return 0;
> -}
> -
> -static int nfs_readlink_reply(unsigned char *pkt, unsigned len)
> -{
> -	uint32_t *data;
> -	char *path;
> -	int rlen;
> -	int ret;
> -
> -	ret = rpc_check_reply(pkt, 1);
> -	if (ret)
> -		return ret;
> -
> -	data = (uint32_t *)(pkt + sizeof(struct rpc_reply));
> -
> -	data++;
> -
> -	rlen = ntohl(net_read_uint32(data)); /* new path length */
> -
> -	data++;
> -	path = (char *)data;
> -
> -	if (*path != '/') {
> -		strcat(nfs_path, "/");
> -		strncat(nfs_path, path, rlen);
> -	} else {
> -		memcpy(nfs_path, path, rlen);
> -		nfs_path[rlen] = 0;
> -	}
> -	return 0;
> -}
> -
> -static int nfs_read_reply(unsigned char *pkt, unsigned len)
> -{
> -	int rlen;
> -	uint32_t *data;
> -	int ret;
> -
> -	debug("%s\n", __func__);
> -
> -	ret = rpc_check_reply(pkt, 1);
> -	if (ret)
> -		return ret;
> -
> -	data = (uint32_t *)(pkt + sizeof(struct rpc_reply));
> -
> -	if (!nfs_offset) {
> -		uint32_t filesize = ntohl(net_read_uint32(data + 6));
> -		init_progression_bar(filesize);
> -	}
> -
> -	rlen = ntohl(net_read_uint32(data + 18));
> -
> -	ret = write(net_store_fd, (char *)(data + 19), rlen);
> -	if (ret < 0) {
> -		perror("write");
> -		return ret;
> -	}
> -
> -	return rlen;
> -}
> -
> -/**************************************************************************
> -Interfaces of barebox
> -**************************************************************************/
> -
> -static void nfs_handler(void *ctx, char *packet, unsigned len)
> -{
> -	char *pkt = net_eth_to_udp_payload(packet);
> -	int ret;
> -
> -	debug("%s\n", __func__);
> -
> -	switch (nfs_state) {
> -	case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
> -		ret = rpc_lookup_reply(PROG_MOUNT, pkt, len);
> -		if (ret)
> -			goto err_out;
> -		nfs_state = STATE_PRCLOOKUP_PROG_NFS_REQ;
> -		break;
> -
> -	case STATE_PRCLOOKUP_PROG_NFS_REQ:
> -		ret = rpc_lookup_reply(PROG_NFS, pkt, len);
> -		if (ret)
> -			goto err_out;
> -		nfs_state = STATE_MOUNT_REQ;
> -		break;
> -
> -	case STATE_MOUNT_REQ:
> -		ret = nfs_mount_reply(pkt, len);
> -		if (ret)
> -			goto err_out;
> -
> -		nfs_state = STATE_LOOKUP_REQ;
> -		break;
> -
> -	case STATE_UMOUNT_REQ:
> -		ret = nfs_umountall_reply(pkt, len);
> -		if (ret)
> -			nfs_err = ret;
> -		nfs_state = STATE_DONE;
> -		return;
> -
> -	case STATE_LOOKUP_REQ:
> -		ret = nfs_lookup_reply(pkt, len);
> -		if (ret)
> -			goto err_umount;
> -
> -		nfs_state = STATE_READ_REQ;
> -		nfs_offset = 0;
> -		break;
> -
> -	case STATE_READLINK_REQ:
> -		ret = nfs_readlink_reply(pkt, len);
> -		if (ret)
> -			goto err_umount;
> -
> -		debug("Symlink --> %s\n", nfs_path);
> -
> -		nfs_filename = basename(nfs_path);
> -		nfs_path     = dirname(nfs_path);
> -
> -		nfs_state = STATE_MOUNT_REQ;
> -		break;
> -
> -	case STATE_READ_REQ:
> -		ret = nfs_read_reply(pkt, len);
> -		nfs_timer_start = get_time_ns();
> -		if (ret > 0)
> -			nfs_offset += ret;
> -		else if (ret == -EISDIR || ret == -EINVAL)
> -			/* symbolic link */
> -			nfs_state = STATE_READLINK_REQ;
> -		else
> -			goto err_umount;
> -		show_progress(nfs_offset);
> -		break;
> -	}
> -
> -	nfs_send();
> -
> -	return;
> -
> -err_umount:
> -	nfs_state = STATE_UMOUNT_REQ;
> -	nfs_err = ret;
> -	nfs_send();
> -	return;
> -
> -err_out:
> -	nfs_state = STATE_DONE;
> -	nfs_err = ret;
> -}
> -
> -static void nfs_start(char *p)
> -{
> -	debug("%s\n", __func__);
> -
> -	nfs_path = (char *)nfs_path_buff;
> -
> -	strcpy(nfs_path, p);
> -
> -	nfs_filename = basename (nfs_path);
> -	nfs_path     = dirname (nfs_path);
> -
> -	printf("\nFilename '%s/%s'.\n", nfs_path, nfs_filename);
> -
> -	nfs_state = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
> -
> -	nfs_send();
> -}
> -
> -static int do_nfs(int argc, char *argv[])
> -{
> -	char  *localfile;
> -	char  *remotefile;
> -
> -	if (argc < 2)
> -		return COMMAND_ERROR_USAGE;
> -
> -	remotefile = argv[1];
> -
> -	if (argc == 2)
> -		localfile = basename(remotefile);
> -	else
> -		localfile = argv[2];
> -
> -	net_store_fd = open(localfile, O_WRONLY | O_CREAT);
> -	if (net_store_fd < 0) {
> -		perror("open");
> -		return 1;
> -	}
> -
> -	nfs_con = net_udp_new(net_get_serverip(), 0, nfs_handler, NULL);
> -	if (IS_ERR(nfs_con)) {
> -		nfs_err = PTR_ERR(nfs_con);
> -		goto err_udp;
> -	}
> -	net_udp_bind(nfs_con, 1000);
> -
> -	nfs_err = 0;
> -
> -	nfs_start(remotefile);
> -
> -	while (nfs_state != STATE_DONE) {
> -		if (ctrlc()) {
> -			nfs_err = -EINTR;
> -			break;
> -		}
> -		net_poll();
> -		if (is_timeout(nfs_timer_start, NFS_TIMEOUT * SECOND)) {
> -			show_progress(-1);
> -			nfs_send();
> -		}
> -	}
> -
> -	net_unregister(nfs_con);
> -err_udp:
> -	close(net_store_fd);
> -	if (nfs_err) {
> -		printf("NFS failed: %s\n", strerror(-nfs_err));
> -		unlink(localfile);
> -	}
> -
> -	printf("\n");
> -
> -	return nfs_err == 0 ? 0 : 1;
> -}
> -
> -static const __maybe_unused char cmd_nfs_help[] =
> -"Usage: nfs <file> [localfile]\n"
> -"Load a file via network using nfs protocol.\n";
> -
> -BAREBOX_CMD_START(nfs)
> -	.cmd		= do_nfs,
> -	.usage		= "boot image via network using nfs protocol",
> -	BAREBOX_CMD_HELP(cmd_nfs_help)
> -BAREBOX_CMD_END
> -
> -- 
> 1.8.5.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/5] net: remove old nfs support
  2014-03-04  4:03   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2014-03-06 16:21     ` Sascha Hauer
  2014-03-08 16:54       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 9+ messages in thread
From: Sascha Hauer @ 2014-03-06 16:21 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Tue, Mar 04, 2014 at 05:03:45AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 22:00 Thu 27 Feb     , Sascha Hauer wrote:
> > Now that we have the NFS as filesystem support for several releases
> > remove the old command based NFS support.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> 
> as the bootp is not fully supported on default env2 do not drop it

Ok for now, but I really want to get rid of it. Would a nfs wrapper
command be ok?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/5] net: remove old nfs support
  2014-03-06 16:21     ` Sascha Hauer
@ 2014-03-08 16:54       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2014-03-08 16:54 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 17:21 Thu 06 Mar     , Sascha Hauer wrote:
> On Tue, Mar 04, 2014 at 05:03:45AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 22:00 Thu 27 Feb     , Sascha Hauer wrote:
> > > Now that we have the NFS as filesystem support for several releases
> > > remove the old command based NFS support.
> > > 
> > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > 
> > as the bootp is not fully supported on default env2 do not drop it
> 
> Ok for now, but I really want to get rid of it. Would a nfs wrapper
> command be ok?

no as the issue is the symlink as you need to change the mount path

so check it

When I've time I'll take a look for defautlenv2 to fix the bootp support

but untill we have defaultenv v1 I think we need to keep this cmd and tftp

Best Regards,
J.
> 
> Sascha
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-03-08 16:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-27 21:00 Add NFS Bootloader Spec support Sascha Hauer
2014-02-27 21:00 ` [PATCH 1/5] run_command: remove unused flag parameter Sascha Hauer
2014-02-27 21:00 ` [PATCH 2/5] net: constify eth_get_byname argument Sascha Hauer
2014-02-27 21:00 ` [PATCH 3/5] net: remove old nfs support Sascha Hauer
2014-03-04  4:03   ` Jean-Christophe PLAGNIOL-VILLARD
2014-03-06 16:21     ` Sascha Hauer
2014-03-08 16:54       ` Jean-Christophe PLAGNIOL-VILLARD
2014-02-27 21:00 ` [PATCH 4/5] net: Add ifup support Sascha Hauer
2014-02-27 21:00 ` [PATCH 5/5] blspec: Add NFS support Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox