mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/7] defaultenv-2: add bootp support
@ 2012-08-24  5:03 Jean-Christophe PLAGNIOL-VILLARD
  2012-08-24  5:06 ` [PATCH 1/7] dhcp: add global var support Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-24  5:03 UTC (permalink / raw)
  To: barebox

HI,

	this patch serie depends on the 2 previous fs-symlink and
	defaultenv-2-boot-sequence

please pull

wing changes since commit ae5c90abd8625d1f091a0a089ac29f886fb6c6f5:

  defaultenv-2: add boot sequence (2012-08-24 12:02:36 +0800)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git tags/defaultenv-2-bootp

for you to fetch changes up to bc19b321f0cc42539eb573ae54edf8d93914e1ef:

  defaultenv-2: add symbolic link support to boot/nfs (2012-08-24 12:56:40 +0800)

----------------------------------------------------------------
defaultenv-2: add bootp support

dhcp: add global var support

This way you can specify as previously set the dhcp parameter via global.dhcp.xxx
and get the result via global.dhcp.xxx

dhcp: add retries limit support

boot: add bootp support to net (tftp)

boot: add nfs bootp support

Where the kernel and oftree as retrieved via nfs
support also the symlink file so we will mount the correct path to get the
file as nfs does not follow the link as it's done on tftp

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (7):
      dhcp: add global var support
      dhcp: add alternative var support
      dhcp: add retries limit support
      defaultenv-2: eth0 add default global.dhcp.vendor_id
      defaultenv-2: boot/net add bootp support
      defaultenv-2: add net boot support with kernel and oftree via nfs
      defaultenv-2: add symbolic link support to boot/nfs

 defaultenv-2/base/boot/net     |   34 +++++++++++++++++++++++++++++++++-
 defaultenv-2/base/boot/nfs     |  123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 defaultenv-2/base/network/eth0 |    1 +
 net/dhcp.c                     |  152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 4 files changed, 305 insertions(+), 5 deletions(-)
 create mode 100644 defaultenv-2/base/boot/nfs

Best Regards,
J.

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

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

* [PATCH 1/7] dhcp: add global var support
  2012-08-24  5:03 [PATCH 0/7] defaultenv-2: add bootp support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-24  5:06 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-24  5:06   ` [PATCH 2/7] dhcp: add alternative " Jean-Christophe PLAGNIOL-VILLARD
                     ` (7 more replies)
  0 siblings, 8 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-24  5:06 UTC (permalink / raw)
  To: barebox

This way you can specify as previously set the dhcp parameter via global.dhcp.xxx
and get the result via global.dhcp.xxx

This is need for the defaultenv-2 to add the bootp suppport.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 net/dhcp.c |  100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 99 insertions(+), 1 deletion(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index 79efa3e..51c4283 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -19,6 +19,8 @@
 #include <magicvar.h>
 #include <linux/err.h>
 #include <getopt.h>
+#include <globalvar.h>
+#include <init.h>
 
 #define OPT_SIZE 312	/* Minimum DHCP Options size per RFC2131 - results in 576 byte pkt */
 
@@ -78,11 +80,39 @@ static IPaddr_t net_dhcp_server_ip;
 static uint64_t dhcp_start;
 static char dhcp_tftpname[256];
 
+static const char* dhcp_get_barebox_global(const char * var)
+{
+	char * var_global = asprintf("global.dhcp.%s", var);
+	const char *val;
+
+	if (!var_global)
+		return NULL;
+
+	val = getenv(var_global);
+	free(var_global);
+	return val;
+}
+
+static int dhcp_set_barebox_global(const char * var, char *val)
+{
+	char * var_global = asprintf("global.dhcp.%s", var);
+	int ret;
+
+	if (!var_global)
+		return -ENOMEM;
+
+	ret = setenv(var_global, val);
+	free(var_global);
+	return ret;
+}
+
 struct dhcp_opt {
 	unsigned char option;
 	/* request automatically the option when creating the DHCP request */
 	bool optional;
 	const char *barebox_var_name;
+	const char *barebox_var_alt_name;
+	const char *barebox_dhcp_global;
 	void (*handle)(struct dhcp_opt *opt, unsigned char *data, int tlen);
 	void *data;
 
@@ -124,6 +154,9 @@ static void env_str_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen
 	memcpy(tmp, popt, optlen);
 	tmp[optlen] = 0;
 	setenv(opt->barebox_var_name, tmp);
+	if (opt->barebox_dhcp_global)
+		dhcp_set_barebox_global(opt->barebox_dhcp_global, tmp);
+
 }
 
 static void copy_uint32_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
@@ -184,6 +217,7 @@ struct dhcp_opt dhcp_options[] = {
 		.option = 17,
 		.handle = env_str_handle,
 		.barebox_var_name = "rootpath",
+		.barebox_dhcp_global = "rootpath",
 	}, {
 		.option = 51,
 		.handle = copy_uint32_handle,
@@ -197,21 +231,26 @@ struct dhcp_opt dhcp_options[] = {
 		.option = 66,
 		.handle = env_str_handle,
 		.barebox_var_name = "dhcp_tftp_server_name",
+		.barebox_dhcp_global = "tftp_server_name",
 		.data = dhcp_tftpname,
 	}, {
 		.option = 67,
 		.handle = bootfile_vendorex_handle,
 		.barebox_var_name = "bootfile",
+		.barebox_dhcp_global = "bootfile",
 	}, {
 		.option = 224,
 		.handle = env_str_handle,
 		.barebox_var_name = "dhcp_oftree_file",
+		.barebox_dhcp_global = "oftree_file",
 	},
 };
 
 struct dhcp_param {
 	unsigned char option;
 	const char *barebox_var_name;
+	const char *barebox_var_alt_name;
+	const char *barebox_dhcp_global;
 	int (*handle)(struct dhcp_param *param, u8 *e);
 	void *data;
 };
@@ -224,6 +263,9 @@ static int dhcp_set_string_options(struct dhcp_param *param, u8 *e)
 	if (!str && param->barebox_var_name)
 		str = (char*)getenv(param->barebox_var_name);
 
+	if (!str && param->barebox_dhcp_global)
+		str = (char*)dhcp_get_barebox_global(param->barebox_dhcp_global);
+
 	if (!str)
 		return 0;
 
@@ -253,18 +295,22 @@ struct dhcp_param dhcp_params[] = {
 		.option = DHCP_VENDOR_ID,
 		.handle = dhcp_set_string_options,
 		.barebox_var_name = "dhcp_vendor_id",
+		.barebox_dhcp_global = "vendor_id",
 	}, {
 		.option = DHCP_CLIENT_ID,
 		.handle = dhcp_set_string_options,
 		.barebox_var_name = "dhcp_client_id",
+		.barebox_dhcp_global = "client_id",
 	}, {
 		.option = DHCP_USER_CLASS,
 		.handle = dhcp_set_string_options,
 		.barebox_var_name = "dhcp_user_class",
+		.barebox_dhcp_global = "user_class",
 	}, {
 		.option = DHCP_CLIENT_UUID,
 		.handle = dhcp_set_string_options,
 		.barebox_var_name = "dhcp_client_uuid",
+		.barebox_dhcp_global = "client_uuid",
 	}
 };
 
@@ -345,8 +391,10 @@ static void bootp_copy_net_params(struct bootp *bp)
 	if (tmp_ip != 0)
 		net_set_serverip(tmp_ip);
 
-	if (strlen(bp->bp_file) > 0)
+	if (strlen(bp->bp_file) > 0) {
 		setenv("bootfile", bp->bp_file);
+		dhcp_set_barebox_global("bootfile", bp->bp_file);
+	}
 
 	debug("bootfile: %s\n", bp->bp_file);
 }
@@ -611,9 +659,50 @@ static void dhcp_reset_env(void)
 			continue;
 
 		setenv(opt->barebox_var_name,"");
+		if (opt->barebox_dhcp_global)
+			dhcp_set_barebox_global(opt->barebox_dhcp_global,"");
 	}
 }
 
+static void dhcp_global_add(const char *var)
+{
+	char * var_global = asprintf("dhcp.%s", var);
+
+	if (!var_global)
+		return;
+
+	globalvar_add_simple(var_global);
+	free(var_global);
+}
+
+static int dhcp_global_init(void)
+{
+	struct dhcp_opt *opt;
+	struct dhcp_param *param;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(dhcp_options); i++) {
+		opt = &dhcp_options[i];
+
+		if (!opt->barebox_dhcp_global)
+			continue;
+
+		dhcp_global_add(opt->barebox_dhcp_global);
+	}
+
+	for (i = 0; i < ARRAY_SIZE(dhcp_params); i++) {
+		param = &dhcp_params[i];
+
+		if (!param->barebox_dhcp_global)
+			continue;
+
+		dhcp_global_add(param->barebox_dhcp_global);
+	}
+
+	return 0;
+}
+late_initcall(dhcp_global_init);
+
 static int do_dhcp(int argc, char *argv[])
 {
 	int ret, opt;
@@ -718,3 +807,12 @@ BAREBOX_MAGICVAR(dhcp_client_id, "cliend id to send to the DHCP server");
 BAREBOX_MAGICVAR(dhcp_user_class, "user class to send to the DHCP server");
 BAREBOX_MAGICVAR(dhcp_tftp_server_name, "TFTP server Name returned from DHCP request");
 BAREBOX_MAGICVAR(dhcp_oftree_file, "OF tree returned from DHCP request (option 224)");
+
+BAREBOX_MAGICVAR_NAMED(global_dhcp_bootfile, global.dhcp.bootfile, "bootfile returned from DHCP request");
+BAREBOX_MAGICVAR_NAMED(global_dhcp_rootpath, global.dhcp.rootpath, "rootpath returned from DHCP request");
+BAREBOX_MAGICVAR_NAMED(global_dhcp_vendor_id, global.dhcp.vendor_id, "vendor id to send to the DHCP server");
+BAREBOX_MAGICVAR_NAMED(global_dhcp_client_uuid, global.dhcp.client_uuid, "cliend uuid to send to the DHCP server");
+BAREBOX_MAGICVAR_NAMED(global_dhcp_client_id, global.dhcp.client_id, "cliend id to send to the DHCP server");
+BAREBOX_MAGICVAR_NAMED(global_dhcp_user_class, global.dhcp.user_class, "user class to send to the DHCP server");
+BAREBOX_MAGICVAR_NAMED(global_dhcp_tftp_server_name, global.dhcp.tftp_server_name, "TFTP server Name returned from DHCP request");
+BAREBOX_MAGICVAR_NAMED(global_dhcp_oftree_file, global.dhcp.oftree_file, "OF tree returned from DHCP request (option 224)");
-- 
1.7.10.4


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

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

* [PATCH 2/7] dhcp: add alternative var support
  2012-08-24  5:06 ` [PATCH 1/7] dhcp: add global var support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-24  5:06   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-24  5:06   ` [PATCH 3/7] dhcp: add retries limit support Jean-Christophe PLAGNIOL-VILLARD
                     ` (6 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-24  5:06 UTC (permalink / raw)
  To: barebox

This is need for the defaultenv-2 to add the bootp suppport.
As now the hostname is store in global.hostname not hostname.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 net/dhcp.c |   17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index 51c4283..b32af6a 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -110,6 +110,7 @@ struct dhcp_opt {
 	unsigned char option;
 	/* request automatically the option when creating the DHCP request */
 	bool optional;
+	bool copy_only_if_valid;
 	const char *barebox_var_name;
 	const char *barebox_var_alt_name;
 	const char *barebox_dhcp_global;
@@ -153,7 +154,13 @@ static void env_str_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen
 
 	memcpy(tmp, popt, optlen);
 	tmp[optlen] = 0;
+
+	if (opt->copy_only_if_valid && !strlen(tmp))
+		return;
+
 	setenv(opt->barebox_var_name, tmp);
+	if (opt->barebox_var_alt_name)
+		setenv(opt->barebox_var_alt_name, tmp);
 	if (opt->barebox_dhcp_global)
 		dhcp_set_barebox_global(opt->barebox_dhcp_global, tmp);
 
@@ -207,8 +214,10 @@ struct dhcp_opt dhcp_options[] = {
 		.barebox_var_name = "net.nameserver",
 	}, {
 		.option = 12,
+		.copy_only_if_valid = 1,
 		.handle = env_str_handle,
 		.barebox_var_name = "hostname",
+		.barebox_var_alt_name = "global.hostname",
 	}, {
 		.option = 15,
 		.handle = env_str_handle,
@@ -263,6 +272,9 @@ static int dhcp_set_string_options(struct dhcp_param *param, u8 *e)
 	if (!str && param->barebox_var_name)
 		str = (char*)getenv(param->barebox_var_name);
 
+	if (!str && param->barebox_var_alt_name)
+		str = (char*)getenv(param->barebox_var_alt_name);
+
 	if (!str && param->barebox_dhcp_global)
 		str = (char*)dhcp_get_barebox_global(param->barebox_dhcp_global);
 
@@ -291,6 +303,7 @@ struct dhcp_param dhcp_params[] = {
 		.option = DHCP_HOSTNAME,
 		.handle = dhcp_set_string_options,
 		.barebox_var_name = "hostname",
+		.barebox_var_alt_name = "global.hostname",
 	}, {
 		.option = DHCP_VENDOR_ID,
 		.handle = dhcp_set_string_options,
@@ -655,10 +668,12 @@ static void dhcp_reset_env(void)
 
 	for (i = 0; i < ARRAY_SIZE(dhcp_options); i++) {
 		opt = &dhcp_options[i];
-		if (!opt->barebox_var_name)
+		if (!opt->barebox_var_name || opt->copy_only_if_valid)
 			continue;
 
 		setenv(opt->barebox_var_name,"");
+		if (opt->barebox_var_alt_name)
+			setenv(opt->barebox_var_alt_name,"");
 		if (opt->barebox_dhcp_global)
 			dhcp_set_barebox_global(opt->barebox_dhcp_global,"");
 	}
-- 
1.7.10.4


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

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

* [PATCH 3/7] dhcp: add retries limit support
  2012-08-24  5:06 ` [PATCH 1/7] dhcp: add global var support Jean-Christophe PLAGNIOL-VILLARD
  2012-08-24  5:06   ` [PATCH 2/7] dhcp: add alternative " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-24  5:06   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-24  7:14     ` Roberto Nibali
  2012-08-24  5:06   ` [PATCH 4/7] defaultenv-2: eth0 add default global.dhcp.vendor_id Jean-Christophe PLAGNIOL-VILLARD
                     ` (5 subsequent siblings)
  7 siblings, 1 reply; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-24  5:06 UTC (permalink / raw)
  To: barebox

via -r opt, global.dhcp.retries or dhcp_retries

set the priority order;

This will allow to do not stay infinite loop if no dhcp availlable
for boot sequence as example

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 net/dhcp.c |   35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index b32af6a..40709e5 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -718,13 +718,27 @@ static int dhcp_global_init(void)
 }
 late_initcall(dhcp_global_init);
 
+static void dhcp_getenv_int(const char *name, int *i)
+{
+	const char* str = getenv(name);
+
+	if (!str)
+		return;
+
+	*i = simple_strtoul(str, NULL, 10);
+}
+
 static int do_dhcp(int argc, char *argv[])
 {
 	int ret, opt;
+	int retries = -1;
 
 	dhcp_reset_env();
 
-	while((opt = getopt(argc, argv, "H:v:c:u:U:")) > 0) {
+	dhcp_getenv_int("dhcp_retries", &retries);
+	dhcp_getenv_int("global.dhcp.retries", &retries);
+
+	while((opt = getopt(argc, argv, "H:v:c:u:U:r:")) > 0) {
 		switch(opt) {
 		case 'H':
 			dhcp_set_param_data(DHCP_HOSTNAME, optarg);
@@ -741,9 +755,17 @@ static int do_dhcp(int argc, char *argv[])
 		case 'U':
 			dhcp_set_param_data(DHCP_USER_CLASS, optarg);
 			break;
+		case 'r':
+			retries = simple_strtoul(optarg, NULL, 10);
+			break;
 		}
 	}
 
+	if (!retries) {
+		printf("retries is set to zero, set it to -1\n");
+		retries = -1;
+	}
+
 	dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler, NULL);
 	if (IS_ERR(dhcp_con)) {
 		ret = PTR_ERR(dhcp_con);
@@ -764,11 +786,17 @@ static int do_dhcp(int argc, char *argv[])
 	while (dhcp_state != BOUND) {
 		if (ctrlc())
 			break;
+		if (!retries) {
+			ret = ETIMEDOUT;
+			goto out1;
+		}
 		net_poll();
 		if (is_timeout(dhcp_start, 3 * SECOND)) {
 			dhcp_start = get_time_ns();
 			printf("T ");
 			ret = bootp_request();
+			/* no need to check if retries > 0 as we check if != 0 */
+			retries--;
 			if (ret)
 				goto out1;
 		}
@@ -803,7 +831,8 @@ BAREBOX_CMD_HELP_OPT  ("-u <client_uuid>",
 BAREBOX_CMD_HELP_OPT  ("-U <user_class>",
 "DHCP User class (code 77) submitted in DHCP requests. It can\n"
 "be used in the DHCP server's configuration to select options\n"
-"(e.g. bootfile or server) which are valid for barebox clients only.\n");
+"(e.g. bootfile or server) which are valid for barebox clients only.\n")
+BAREBOX_CMD_HELP_OPT  ("-r <retry>", "retry limi\n");
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(dhcp)
@@ -822,6 +851,7 @@ BAREBOX_MAGICVAR(dhcp_client_id, "cliend id to send to the DHCP server");
 BAREBOX_MAGICVAR(dhcp_user_class, "user class to send to the DHCP server");
 BAREBOX_MAGICVAR(dhcp_tftp_server_name, "TFTP server Name returned from DHCP request");
 BAREBOX_MAGICVAR(dhcp_oftree_file, "OF tree returned from DHCP request (option 224)");
+BAREBOX_MAGICVAR(dhcp_retries, "retry limit");
 
 BAREBOX_MAGICVAR_NAMED(global_dhcp_bootfile, global.dhcp.bootfile, "bootfile returned from DHCP request");
 BAREBOX_MAGICVAR_NAMED(global_dhcp_rootpath, global.dhcp.rootpath, "rootpath returned from DHCP request");
@@ -831,3 +861,4 @@ BAREBOX_MAGICVAR_NAMED(global_dhcp_client_id, global.dhcp.client_id, "cliend id
 BAREBOX_MAGICVAR_NAMED(global_dhcp_user_class, global.dhcp.user_class, "user class to send to the DHCP server");
 BAREBOX_MAGICVAR_NAMED(global_dhcp_tftp_server_name, global.dhcp.tftp_server_name, "TFTP server Name returned from DHCP request");
 BAREBOX_MAGICVAR_NAMED(global_dhcp_oftree_file, global.dhcp.oftree_file, "OF tree returned from DHCP request (option 224)");
+BAREBOX_MAGICVAR_NAMED(global_dhcp_retries, global.dhcp.retries, "retry limit");
-- 
1.7.10.4


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

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

* [PATCH 4/7] defaultenv-2: eth0 add default global.dhcp.vendor_id
  2012-08-24  5:06 ` [PATCH 1/7] dhcp: add global var support Jean-Christophe PLAGNIOL-VILLARD
  2012-08-24  5:06   ` [PATCH 2/7] dhcp: add alternative " Jean-Christophe PLAGNIOL-VILLARD
  2012-08-24  5:06   ` [PATCH 3/7] dhcp: add retries limit support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-24  5:06   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-24  5:06   ` [PATCH 5/7] defaultenv-2: boot/net add bootp support Jean-Christophe PLAGNIOL-VILLARD
                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-24  5:06 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 defaultenv-2/base/network/eth0 |    1 +
 1 file changed, 1 insertion(+)

diff --git a/defaultenv-2/base/network/eth0 b/defaultenv-2/base/network/eth0
index 048a288..7e731ca 100644
--- a/defaultenv-2/base/network/eth0
+++ b/defaultenv-2/base/network/eth0
@@ -2,6 +2,7 @@
 
 # ip setting (static/dhcp)
 ip=dhcp
+global.dhcp.vendor_id=barebox-${global.hostname}
 
 # static setup used if ip=static
 ipaddr=
-- 
1.7.10.4


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

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

* [PATCH 5/7] defaultenv-2: boot/net add bootp support
  2012-08-24  5:06 ` [PATCH 1/7] dhcp: add global var support Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 preceding siblings ...)
  2012-08-24  5:06   ` [PATCH 4/7] defaultenv-2: eth0 add default global.dhcp.vendor_id Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-24  5:06   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-24  5:06   ` [PATCH 6/7] defaultenv-2: add net boot support with kernel and oftree via nfs Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-24  5:06 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 defaultenv-2/base/boot/net |   34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/defaultenv-2/base/boot/net b/defaultenv-2/base/boot/net
index 922bef1..a232e8c 100644
--- a/defaultenv-2/base/boot/net
+++ b/defaultenv-2/base/boot/net
@@ -7,8 +7,40 @@ fi
 
 path="/mnt/tftp"
 
+# to get the dhcp info (global.dhcp.rootpath, global.dhcp.bootfile, global.dhcp.oftree_file)
+ifup eth0
+
 global.bootm.image="${path}/${global.user}-linux-${global.hostname}"
 #global.bootm.oftree="${path}/${global.user}-oftree-${global.hostname}"
-nfsroot="/home/${global.user}/nfsroot/${global.hostname}"
+
+if [ -n "${global.dhcp.rootpath}" ]; then
+	bootp=1
+	nfsroot="${global.dhcp.rootpath}"
+else
+	nfsroot="/home/${global.user}/nfsroot/${global.hostname}"
+fi
+
+if [ -n "${global.dhcp.bootfile}" -o -n "${global.dhcp.oftree_file}" ]; then
+	bootp=1
+	path="/mnt/dhcp"
+
+	if [ -d "${path}" ]; then
+		umount "${path}"
+	else
+		mkdir "${path}"
+	fi
+	mount -t tftp $eth0.serverip "${path}"
+
+	[ -n "${global.dhcp.bootfile}" ] && global.bootm.image="${path}/${global.dhcp.bootfile}"
+	[ -n "${global.dhcp.oftree_file}" ] && global.bootm.oftree="${path}/${global.dhcp.oftree_file}"
+fi
+
+if [ x${bootp} = x1 ]; then
+	echo "Boot via bootp/dhcp on server ${eth0.serverip}"
+	[ -n "${global.dhcp.bootfile}" ] && echo "bootm.image => ${global.dhcp.bootfile}"
+	[ -n "${global.dhcp.oftree_file}" ] && echo "bootm.oftree => ${global.dhcp.oftree_file}"
+	[ -n "${global.dhcp.rootpath}" ] && echo "nfsroot => ${global.dhcp.rootpath}"
+fi
+
 bootargs-ip
 bootargs-root-nfs -n "$nfsroot"
-- 
1.7.10.4


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

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

* [PATCH 6/7] defaultenv-2: add net boot support with kernel and oftree via nfs
  2012-08-24  5:06 ` [PATCH 1/7] dhcp: add global var support Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 preceding siblings ...)
  2012-08-24  5:06   ` [PATCH 5/7] defaultenv-2: boot/net add bootp support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-24  5:06   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-24  5:06   ` [PATCH 7/7] defaultenv-2: add symbolic link support to boot/nfs Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-24  5:06 UTC (permalink / raw)
  To: barebox

This also support the bootp.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 defaultenv-2/base/boot/nfs |   74 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 defaultenv-2/base/boot/nfs

diff --git a/defaultenv-2/base/boot/nfs b/defaultenv-2/base/boot/nfs
new file mode 100644
index 0000000..248f975
--- /dev/null
+++ b/defaultenv-2/base/boot/nfs
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+if [ "$1" = menu ]; then
+	boot-menu-add-entry "$0" "network (nfs, nfs)"
+	exit
+fi
+
+path="/mnt/tftp"
+
+# to get the dhcp info (global.dhcp.rootpath, global.dhcp.bootfile, global.dhcp.oftree_file)
+ifup eth0
+
+global.bootm.image="${path}/${global.user}-linux-${global.hostname}"
+#global.bootm.oftree="${path}/${global.user}-oftree-${global.hostname}"
+
+if [ -n "${global.dhcp.rootpath}" ]; then
+	bootp=1
+	nfsroot="${global.dhcp.rootpath}"
+else
+	nfsroot="/home/${global.user}/nfsroot/${global.hostname}"
+fi
+
+dhcp_patch_base="/mnt/dhcp"
+if [ -d "${dhcp_patch_base}" ]; then
+	umount "${dhcp_patch_base}"
+else
+	mkdir "${dhcp_patch_base}"
+fi
+
+if [ -n "${global.dhcp.bootfile}" ]; then
+	bootp=1
+	path="${dhcp_patch_base}/bootfile"
+
+	if [ -d "${path}" ]; then
+		umount "${path}"
+	else
+		mkdir "${path}"
+	fi
+
+	dirname "${global.dhcp.bootfile}" mnt
+	basename "${global.dhcp.bootfile}" bootfile
+
+	mount -t nfs "${eth0.serverip}:${mnt}" "${path}"
+
+	global.bootm.image="${path}/${bootfile}"
+fi
+
+if [ -n "${global.dhcp.oftree_file}" ]; then
+	bootp=1
+	path="${dhcp_patch_base}/oftree_file"
+
+	if [ -d "${path}" ]; then
+		umount "${path}"
+	else
+		mkdir "${path}"
+	fi
+
+	dirname "${global.dhcp.oftree_file}" mnt
+	basename "${global.dhcp.oftree_file}" bootfile
+
+	mount -t nfs "${eth0.serverip}:${mnt}" "${path}"
+
+	global.bootm.oftree="${path}/${bootfile}"
+fi
+
+if [ x${bootp} = x1 ]; then
+	echo "Boot via bootp/dhcp on server ${eth0.serverip}"
+	[ -n "${global.dhcp.bootfile}" ] && echo "bootm.image => ${global.dhcp.bootfile}"
+	[ -n "${global.dhcp.oftree_file}" ] && echo "bootm.oftree => ${global.dhcp.oftree_file}"
+	[ -n "${global.dhcp.rootpath}" ] && echo "nfsroot => ${global.dhcp.rootpath}"
+fi
+
+bootargs-ip
+bootargs-root-nfs -n "$nfsroot"
-- 
1.7.10.4


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

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

* [PATCH 7/7] defaultenv-2: add symbolic link support to boot/nfs
  2012-08-24  5:06 ` [PATCH 1/7] dhcp: add global var support Jean-Christophe PLAGNIOL-VILLARD
                     ` (4 preceding siblings ...)
  2012-08-24  5:06   ` [PATCH 6/7] defaultenv-2: add net boot support with kernel and oftree via nfs Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-24  5:06   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-28  8:47     ` Sascha Hauer
  2012-08-24  7:26   ` [PATCH 1/7] dhcp: add global var support Roberto Nibali
  2012-08-28  8:40   ` Sascha Hauer
  7 siblings, 1 reply; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-24  5:06 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 defaultenv-2/base/boot/nfs |   55 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 52 insertions(+), 3 deletions(-)

diff --git a/defaultenv-2/base/boot/nfs b/defaultenv-2/base/boot/nfs
index 248f975..a33a21c 100644
--- a/defaultenv-2/base/boot/nfs
+++ b/defaultenv-2/base/boot/nfs
@@ -43,6 +43,18 @@ if [ -n "${global.dhcp.bootfile}" ]; then
 	mount -t nfs "${eth0.serverip}:${mnt}" "${path}"
 
 	global.bootm.image="${path}/${bootfile}"
+
+	if [ -L "${global.bootm.image}" ]; then
+		readlink -f "${global.bootm.image}" bootfile_symlink
+
+		dirname -V "${bootfile_symlink}" mnt
+		basename "${bootfile_symlink}" bootfile
+
+		umount "${path}"
+		mount -t nfs "${eth0.serverip}:${mnt}" "${path}"
+
+		global.bootm.image="${path}/${bootfile}"
+	fi
 fi
 
 if [ -n "${global.dhcp.oftree_file}" ]; then
@@ -61,13 +73,50 @@ if [ -n "${global.dhcp.oftree_file}" ]; then
 	mount -t nfs "${eth0.serverip}:${mnt}" "${path}"
 
 	global.bootm.oftree="${path}/${bootfile}"
+
+	if [ -L "${global.bootm.oftree}" ]; then
+		readlink -f "${global.bootm.oftree}" oftree_symlink
+
+		dirname -V "${oftree_symlink}" mnt
+		basename "${oftree_symlink}" bootfile
+
+		umount "${path}"
+		mount -t nfs "${eth0.serverip}:${mnt}" "${path}"
+
+		global.bootm.oftree="${path}/${bootfile}"
+	fi
+fi
+
+if [ ${global.allow_color} = "true" ]; then
+	blue="\e[1;36m"
+	normal="\e[0m"
 fi
 
 if [ x${bootp} = x1 ]; then
 	echo "Boot via bootp/dhcp on server ${eth0.serverip}"
-	[ -n "${global.dhcp.bootfile}" ] && echo "bootm.image => ${global.dhcp.bootfile}"
-	[ -n "${global.dhcp.oftree_file}" ] && echo "bootm.oftree => ${global.dhcp.oftree_file}"
-	[ -n "${global.dhcp.rootpath}" ] && echo "nfsroot => ${global.dhcp.rootpath}"
+	if [ -n "${global.dhcp.bootfile}" ]; then
+		echo -n "bootm.image => "
+		if [ "x${bootfile_symlink}" != x ]; then
+			echo -e -n "${blue}${global.dhcp.bootfile}${normal}"
+			echo -n " -> ${bootfile_symlink}"
+		else
+			echo -n "${global.dhcp.bootfile}"
+		fi
+		echo ""
+	fi
+
+	if [ -n "${global.dhcp.oftree_file}" ]; then
+		echo "bootm.oftree => "
+		if [ "x${oftree_symlink}" != x ]; then
+			echo -e -n "${blue}${global.dhcp.oftree_file}${normal}"
+			echo -n " -> ${oftree_symlink}"
+		else
+			echo -n "${global.dhcp.oftree_file}"
+		fi
+		echo ""
+	fi
+
+	[ -n "${global.dhcp.rootpath}" ] && echo "nfsroot -> ${global.dhcp.rootpath}"
 fi
 
 bootargs-ip
-- 
1.7.10.4


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

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

* Re: [PATCH 3/7] dhcp: add retries limit support
  2012-08-24  5:06   ` [PATCH 3/7] dhcp: add retries limit support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-24  7:14     ` Roberto Nibali
  0 siblings, 0 replies; 14+ messages in thread
From: Roberto Nibali @ 2012-08-24  7:14 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

Hi

On Fri, Aug 24, 2012 at 7:06 AM, Jean-Christophe PLAGNIOL-VILLARD
<plagnioj@jcrosoft.com> wrote:
> via -r opt, global.dhcp.retries or dhcp_retries
>
> set the priority order;
>
> This will allow to do not stay infinite loop if no dhcp availlable
> for boot sequence as example
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  net/dhcp.c |   35 +++++++++++++++++++++++++++++++++--
>  1 file changed, 33 insertions(+), 2 deletions(-)
>
> diff --git a/net/dhcp.c b/net/dhcp.c
> index b32af6a..40709e5 100644
> --- a/net/dhcp.c
> +++ b/net/dhcp.c
> @@ -718,13 +718,27 @@ static int dhcp_global_init(void)
>  }
>  late_initcall(dhcp_global_init);
>
> +static void dhcp_getenv_int(const char *name, int *i)
> +{
> +       const char* str = getenv(name);
> +
> +       if (!str)
> +               return;
> +
> +       *i = simple_strtoul(str, NULL, 10);
> +}
> +
>  static int do_dhcp(int argc, char *argv[])
>  {
>         int ret, opt;
> +       int retries = -1;
>
>         dhcp_reset_env();
>
> -       while((opt = getopt(argc, argv, "H:v:c:u:U:")) > 0) {
> +       dhcp_getenv_int("dhcp_retries", &retries);
> +       dhcp_getenv_int("global.dhcp.retries", &retries);
> +
> +       while((opt = getopt(argc, argv, "H:v:c:u:U:r:")) > 0) {
>                 switch(opt) {
>                 case 'H':
>                         dhcp_set_param_data(DHCP_HOSTNAME, optarg);
> @@ -741,9 +755,17 @@ static int do_dhcp(int argc, char *argv[])
>                 case 'U':
>                         dhcp_set_param_data(DHCP_USER_CLASS, optarg);
>                         break;
> +               case 'r':
> +                       retries = simple_strtoul(optarg, NULL, 10);
> +                       break;
>                 }
>         }
>
> +       if (!retries) {
> +               printf("retries is set to zero, set it to -1\n");

I don't think the user needs to know that in the background you're
using -1 to express zero retries. I suppose a comment would suffice.

> +               retries = -1;
> +       }
> +
>         dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler, NULL);
>         if (IS_ERR(dhcp_con)) {
>                 ret = PTR_ERR(dhcp_con);
> @@ -764,11 +786,17 @@ static int do_dhcp(int argc, char *argv[])
>         while (dhcp_state != BOUND) {
>                 if (ctrlc())
>                         break;
> +               if (!retries) {
> +                       ret = ETIMEDOUT;
> +                       goto out1;
> +               }
>                 net_poll();
>                 if (is_timeout(dhcp_start, 3 * SECOND)) {
>                         dhcp_start = get_time_ns();
>                         printf("T ");
>                         ret = bootp_request();
> +                       /* no need to check if retries > 0 as we check if != 0 */
> +                       retries--;
>                         if (ret)
>                                 goto out1;
>                 }
> @@ -803,7 +831,8 @@ BAREBOX_CMD_HELP_OPT  ("-u <client_uuid>",
>  BAREBOX_CMD_HELP_OPT  ("-U <user_class>",
>  "DHCP User class (code 77) submitted in DHCP requests. It can\n"
>  "be used in the DHCP server's configuration to select options\n"
> -"(e.g. bootfile or server) which are valid for barebox clients only.\n");
> +"(e.g. bootfile or server) which are valid for barebox clients only.\n")
> +BAREBOX_CMD_HELP_OPT  ("-r <retry>", "retry limi\n");

s/limi/limit/

Regards
Roberto Nibali

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

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

* Re: [PATCH 1/7] dhcp: add global var support
  2012-08-24  5:06 ` [PATCH 1/7] dhcp: add global var support Jean-Christophe PLAGNIOL-VILLARD
                     ` (5 preceding siblings ...)
  2012-08-24  5:06   ` [PATCH 7/7] defaultenv-2: add symbolic link support to boot/nfs Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-24  7:26   ` Roberto Nibali
  2012-08-28  8:40   ` Sascha Hauer
  7 siblings, 0 replies; 14+ messages in thread
From: Roberto Nibali @ 2012-08-24  7:26 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

Hi

Minor nitpick below:

On Fri, Aug 24, 2012 at 7:06 AM, Jean-Christophe PLAGNIOL-VILLARD
<plagnioj@jcrosoft.com> wrote:
> This way you can specify as previously set the dhcp parameter via global.dhcp.xxx
> and get the result via global.dhcp.xxx
>
> This is need for the defaultenv-2 to add the bootp suppport.
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  net/dhcp.c |  100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 99 insertions(+), 1 deletion(-)
>
> diff --git a/net/dhcp.c b/net/dhcp.c
> index 79efa3e..51c4283 100644
> --- a/net/dhcp.c
> +++ b/net/dhcp.

[...]

> @@ -718,3 +807,12 @@ BAREBOX_MAGICVAR(dhcp_client_id, "cliend id to send to the DHCP server");
>  BAREBOX_MAGICVAR(dhcp_user_class, "user class to send to the DHCP server");
>  BAREBOX_MAGICVAR(dhcp_tftp_server_name, "TFTP server Name returned from DHCP request");
>  BAREBOX_MAGICVAR(dhcp_oftree_file, "OF tree returned from DHCP request (option 224)");
> +
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_bootfile, global.dhcp.bootfile, "bootfile returned from DHCP request");
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_rootpath, global.dhcp.rootpath, "rootpath returned from DHCP request");
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_vendor_id, global.dhcp.vendor_id, "vendor id to send to the DHCP server");
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_client_uuid, global.dhcp.client_uuid, "cliend uuid to send to the DHCP server");

s/cliend/client/

> +BAREBOX_MAGICVAR_NAMED(global_dhcp_client_id, global.dhcp.client_id, "cliend id to send to the DHCP server");

s/cliend/client/

> +BAREBOX_MAGICVAR_NAMED(global_dhcp_user_class, global.dhcp.user_class, "user class to send to the DHCP server");
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_tftp_server_name, global.dhcp.tftp_server_name, "TFTP server Name returned from DHCP request");

s/Name/name/

> +BAREBOX_MAGICVAR_NAMED(global_dhcp_oftree_file, global.dhcp.oftree_file, "OF tree returned from DHCP request (option 224)");

Cheers
Roberto

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

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

* Re: [PATCH 1/7] dhcp: add global var support
  2012-08-24  5:06 ` [PATCH 1/7] dhcp: add global var support Jean-Christophe PLAGNIOL-VILLARD
                     ` (6 preceding siblings ...)
  2012-08-24  7:26   ` [PATCH 1/7] dhcp: add global var support Roberto Nibali
@ 2012-08-28  8:40   ` Sascha Hauer
  2012-09-01 12:49     ` Jean-Christophe PLAGNIOL-VILLARD
  7 siblings, 1 reply; 14+ messages in thread
From: Sascha Hauer @ 2012-08-28  8:40 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Fri, Aug 24, 2012 at 07:06:50AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> This way you can specify as previously set the dhcp parameter via global.dhcp.xxx
> and get the result via global.dhcp.xxx
> 
> This is need for the defaultenv-2 to add the bootp suppport.
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  net/dhcp.c |  100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 99 insertions(+), 1 deletion(-)
> 
> diff --git a/net/dhcp.c b/net/dhcp.c
> index 79efa3e..51c4283 100644
> --- a/net/dhcp.c
> +++ b/net/dhcp.c
> @@ -19,6 +19,8 @@
>  #include <magicvar.h>
>  #include <linux/err.h>
>  #include <getopt.h>
> +#include <globalvar.h>
> +#include <init.h>
>  
>  #define OPT_SIZE 312	/* Minimum DHCP Options size per RFC2131 - results in 576 byte pkt */
>  
> @@ -78,11 +80,39 @@ static IPaddr_t net_dhcp_server_ip;
>  static uint64_t dhcp_start;
>  static char dhcp_tftpname[256];
>  
> +static const char* dhcp_get_barebox_global(const char * var)

static const char *dhcp_get_barebox_global

> +{
> +	char * var_global = asprintf("global.dhcp.%s", var);

char *var_global =

Generally I don't think we should introduce a second set of variables.
Drop The other ones instead.

Sascha

> +	const char *val;
> +
> +	if (!var_global)
> +		return NULL;
> +
> +	val = getenv(var_global);
> +	free(var_global);
> +	return val;
> +}
> +
> +static int dhcp_set_barebox_global(const char * var, char *val)
> +{
> +	char * var_global = asprintf("global.dhcp.%s", var);
> +	int ret;
> +
> +	if (!var_global)
> +		return -ENOMEM;
> +
> +	ret = setenv(var_global, val);
> +	free(var_global);
> +	return ret;
> +}
> +
>  struct dhcp_opt {
>  	unsigned char option;
>  	/* request automatically the option when creating the DHCP request */
>  	bool optional;
>  	const char *barebox_var_name;
> +	const char *barebox_var_alt_name;
> +	const char *barebox_dhcp_global;
>  	void (*handle)(struct dhcp_opt *opt, unsigned char *data, int tlen);
>  	void *data;
>  
> @@ -124,6 +154,9 @@ static void env_str_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen
>  	memcpy(tmp, popt, optlen);
>  	tmp[optlen] = 0;
>  	setenv(opt->barebox_var_name, tmp);
> +	if (opt->barebox_dhcp_global)
> +		dhcp_set_barebox_global(opt->barebox_dhcp_global, tmp);
> +
>  }
>  
>  static void copy_uint32_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
> @@ -184,6 +217,7 @@ struct dhcp_opt dhcp_options[] = {
>  		.option = 17,
>  		.handle = env_str_handle,
>  		.barebox_var_name = "rootpath",
> +		.barebox_dhcp_global = "rootpath",
>  	}, {
>  		.option = 51,
>  		.handle = copy_uint32_handle,
> @@ -197,21 +231,26 @@ struct dhcp_opt dhcp_options[] = {
>  		.option = 66,
>  		.handle = env_str_handle,
>  		.barebox_var_name = "dhcp_tftp_server_name",
> +		.barebox_dhcp_global = "tftp_server_name",
>  		.data = dhcp_tftpname,
>  	}, {
>  		.option = 67,
>  		.handle = bootfile_vendorex_handle,
>  		.barebox_var_name = "bootfile",
> +		.barebox_dhcp_global = "bootfile",
>  	}, {
>  		.option = 224,
>  		.handle = env_str_handle,
>  		.barebox_var_name = "dhcp_oftree_file",
> +		.barebox_dhcp_global = "oftree_file",
>  	},
>  };
>  
>  struct dhcp_param {
>  	unsigned char option;
>  	const char *barebox_var_name;
> +	const char *barebox_var_alt_name;
> +	const char *barebox_dhcp_global;
>  	int (*handle)(struct dhcp_param *param, u8 *e);
>  	void *data;
>  };
> @@ -224,6 +263,9 @@ static int dhcp_set_string_options(struct dhcp_param *param, u8 *e)
>  	if (!str && param->barebox_var_name)
>  		str = (char*)getenv(param->barebox_var_name);
>  
> +	if (!str && param->barebox_dhcp_global)
> +		str = (char*)dhcp_get_barebox_global(param->barebox_dhcp_global);
> +
>  	if (!str)
>  		return 0;
>  
> @@ -253,18 +295,22 @@ struct dhcp_param dhcp_params[] = {
>  		.option = DHCP_VENDOR_ID,
>  		.handle = dhcp_set_string_options,
>  		.barebox_var_name = "dhcp_vendor_id",
> +		.barebox_dhcp_global = "vendor_id",
>  	}, {
>  		.option = DHCP_CLIENT_ID,
>  		.handle = dhcp_set_string_options,
>  		.barebox_var_name = "dhcp_client_id",
> +		.barebox_dhcp_global = "client_id",
>  	}, {
>  		.option = DHCP_USER_CLASS,
>  		.handle = dhcp_set_string_options,
>  		.barebox_var_name = "dhcp_user_class",
> +		.barebox_dhcp_global = "user_class",
>  	}, {
>  		.option = DHCP_CLIENT_UUID,
>  		.handle = dhcp_set_string_options,
>  		.barebox_var_name = "dhcp_client_uuid",
> +		.barebox_dhcp_global = "client_uuid",
>  	}
>  };
>  
> @@ -345,8 +391,10 @@ static void bootp_copy_net_params(struct bootp *bp)
>  	if (tmp_ip != 0)
>  		net_set_serverip(tmp_ip);
>  
> -	if (strlen(bp->bp_file) > 0)
> +	if (strlen(bp->bp_file) > 0) {
>  		setenv("bootfile", bp->bp_file);
> +		dhcp_set_barebox_global("bootfile", bp->bp_file);
> +	}
>  
>  	debug("bootfile: %s\n", bp->bp_file);
>  }
> @@ -611,9 +659,50 @@ static void dhcp_reset_env(void)
>  			continue;
>  
>  		setenv(opt->barebox_var_name,"");
> +		if (opt->barebox_dhcp_global)
> +			dhcp_set_barebox_global(opt->barebox_dhcp_global,"");
>  	}
>  }
>  
> +static void dhcp_global_add(const char *var)
> +{
> +	char * var_global = asprintf("dhcp.%s", var);
> +
> +	if (!var_global)
> +		return;
> +
> +	globalvar_add_simple(var_global);
> +	free(var_global);
> +}
> +
> +static int dhcp_global_init(void)
> +{
> +	struct dhcp_opt *opt;
> +	struct dhcp_param *param;
> +	int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(dhcp_options); i++) {
> +		opt = &dhcp_options[i];
> +
> +		if (!opt->barebox_dhcp_global)
> +			continue;
> +
> +		dhcp_global_add(opt->barebox_dhcp_global);
> +	}
> +
> +	for (i = 0; i < ARRAY_SIZE(dhcp_params); i++) {
> +		param = &dhcp_params[i];
> +
> +		if (!param->barebox_dhcp_global)
> +			continue;
> +
> +		dhcp_global_add(param->barebox_dhcp_global);
> +	}
> +
> +	return 0;
> +}
> +late_initcall(dhcp_global_init);
> +
>  static int do_dhcp(int argc, char *argv[])
>  {
>  	int ret, opt;
> @@ -718,3 +807,12 @@ BAREBOX_MAGICVAR(dhcp_client_id, "cliend id to send to the DHCP server");
>  BAREBOX_MAGICVAR(dhcp_user_class, "user class to send to the DHCP server");
>  BAREBOX_MAGICVAR(dhcp_tftp_server_name, "TFTP server Name returned from DHCP request");
>  BAREBOX_MAGICVAR(dhcp_oftree_file, "OF tree returned from DHCP request (option 224)");
> +
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_bootfile, global.dhcp.bootfile, "bootfile returned from DHCP request");
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_rootpath, global.dhcp.rootpath, "rootpath returned from DHCP request");
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_vendor_id, global.dhcp.vendor_id, "vendor id to send to the DHCP server");
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_client_uuid, global.dhcp.client_uuid, "cliend uuid to send to the DHCP server");
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_client_id, global.dhcp.client_id, "cliend id to send to the DHCP server");
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_user_class, global.dhcp.user_class, "user class to send to the DHCP server");
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_tftp_server_name, global.dhcp.tftp_server_name, "TFTP server Name returned from DHCP request");
> +BAREBOX_MAGICVAR_NAMED(global_dhcp_oftree_file, global.dhcp.oftree_file, "OF tree returned from DHCP request (option 224)");
> -- 
> 1.7.10.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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] 14+ messages in thread

* Re: [PATCH 7/7] defaultenv-2: add symbolic link support to boot/nfs
  2012-08-24  5:06   ` [PATCH 7/7] defaultenv-2: add symbolic link support to boot/nfs Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-28  8:47     ` Sascha Hauer
  2012-09-01 12:47       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 14+ messages in thread
From: Sascha Hauer @ 2012-08-28  8:47 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Fri, Aug 24, 2012 at 07:06:56AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  defaultenv-2/base/boot/nfs |   55 +++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 52 insertions(+), 3 deletions(-)
> 
> diff --git a/defaultenv-2/base/boot/nfs b/defaultenv-2/base/boot/nfs
> index 248f975..a33a21c 100644
> --- a/defaultenv-2/base/boot/nfs
> +++ b/defaultenv-2/base/boot/nfs
> @@ -43,6 +43,18 @@ if [ -n "${global.dhcp.bootfile}" ]; then
>  	mount -t nfs "${eth0.serverip}:${mnt}" "${path}"
>  
>  	global.bootm.image="${path}/${bootfile}"
> +
> +	if [ -L "${global.bootm.image}" ]; then
> +		readlink -f "${global.bootm.image}" bootfile_symlink
> +
> +		dirname -V "${bootfile_symlink}" mnt
> +		basename "${bootfile_symlink}" bootfile
> +
> +		umount "${path}"
> +		mount -t nfs "${eth0.serverip}:${mnt}" "${path}"
> +
> +		global.bootm.image="${path}/${bootfile}"
> +	fi

There is something wrong here. I do not understand what you do here, but
symlinks are not supposed to bash on them with dirname/basename until
you get something which fits your needs.

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] 14+ messages in thread

* Re: [PATCH 7/7] defaultenv-2: add symbolic link support to boot/nfs
  2012-08-28  8:47     ` Sascha Hauer
@ 2012-09-01 12:47       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-01 12:47 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 10:47 Tue 28 Aug     , Sascha Hauer wrote:
> On Fri, Aug 24, 2012 at 07:06:56AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> >  defaultenv-2/base/boot/nfs |   55 +++++++++++++++++++++++++++++++++++++++++---
> >  1 file changed, 52 insertions(+), 3 deletions(-)
> > 
> > diff --git a/defaultenv-2/base/boot/nfs b/defaultenv-2/base/boot/nfs
> > index 248f975..a33a21c 100644
> > --- a/defaultenv-2/base/boot/nfs
> > +++ b/defaultenv-2/base/boot/nfs
> > @@ -43,6 +43,18 @@ if [ -n "${global.dhcp.bootfile}" ]; then
> >  	mount -t nfs "${eth0.serverip}:${mnt}" "${path}"
> >  
> >  	global.bootm.image="${path}/${bootfile}"
> > +
> > +	if [ -L "${global.bootm.image}" ]; then
> > +		readlink -f "${global.bootm.image}" bootfile_symlink
> > +
> > +		dirname -V "${bootfile_symlink}" mnt
> > +		basename "${bootfile_symlink}" bootfile
> > +
> > +		umount "${path}"
> > +		mount -t nfs "${eth0.serverip}:${mnt}" "${path}"
> > +
> > +		global.bootm.image="${path}/${bootfile}"
> > +	fi
> 
> There is something wrong here. I do not understand what you do here, but
> symlinks are not supposed to bash on them with dirname/basename until
> you get something which fits your needs.
here the issue is that on nfs you need to mount the correct path otherwise you
can not get the real file

so we need to detect it and mount the correct path

Best Regards,
J.

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

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

* Re: [PATCH 1/7] dhcp: add global var support
  2012-08-28  8:40   ` Sascha Hauer
@ 2012-09-01 12:49     ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-01 12:49 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 10:40 Tue 28 Aug     , Sascha Hauer wrote:
> On Fri, Aug 24, 2012 at 07:06:50AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > This way you can specify as previously set the dhcp parameter via global.dhcp.xxx
> > and get the result via global.dhcp.xxx
> > 
> > This is need for the defaultenv-2 to add the bootp suppport.
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> >  net/dhcp.c |  100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 99 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/dhcp.c b/net/dhcp.c
> > index 79efa3e..51c4283 100644
> > --- a/net/dhcp.c
> > +++ b/net/dhcp.c
> > @@ -19,6 +19,8 @@
> >  #include <magicvar.h>
> >  #include <linux/err.h>
> >  #include <getopt.h>
> > +#include <globalvar.h>
> > +#include <init.h>
> >  
> >  #define OPT_SIZE 312	/* Minimum DHCP Options size per RFC2131 - results in 576 byte pkt */
> >  
> > @@ -78,11 +80,39 @@ static IPaddr_t net_dhcp_server_ip;
> >  static uint64_t dhcp_start;
> >  static char dhcp_tftpname[256];
> >  
> > +static const char* dhcp_get_barebox_global(const char * var)
> 
> static const char *dhcp_get_barebox_global
> 
> > +{
> > +	char * var_global = asprintf("global.dhcp.%s", var);
> 
> char *var_global =
> 
> Generally I don't think we should introduce a second set of variables.
> Drop The other ones instead.
I'm ok with it as I 'm going to switch all my board to the defaultenv-2

but other people may not so the only to keep this feature on both env are

1) 2 set of var
2) use glovalbar on defaultenv

I've no preference

Best Regards,
J.

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

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

end of thread, other threads:[~2012-09-01 12:49 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-24  5:03 [PATCH 0/7] defaultenv-2: add bootp support Jean-Christophe PLAGNIOL-VILLARD
2012-08-24  5:06 ` [PATCH 1/7] dhcp: add global var support Jean-Christophe PLAGNIOL-VILLARD
2012-08-24  5:06   ` [PATCH 2/7] dhcp: add alternative " Jean-Christophe PLAGNIOL-VILLARD
2012-08-24  5:06   ` [PATCH 3/7] dhcp: add retries limit support Jean-Christophe PLAGNIOL-VILLARD
2012-08-24  7:14     ` Roberto Nibali
2012-08-24  5:06   ` [PATCH 4/7] defaultenv-2: eth0 add default global.dhcp.vendor_id Jean-Christophe PLAGNIOL-VILLARD
2012-08-24  5:06   ` [PATCH 5/7] defaultenv-2: boot/net add bootp support Jean-Christophe PLAGNIOL-VILLARD
2012-08-24  5:06   ` [PATCH 6/7] defaultenv-2: add net boot support with kernel and oftree via nfs Jean-Christophe PLAGNIOL-VILLARD
2012-08-24  5:06   ` [PATCH 7/7] defaultenv-2: add symbolic link support to boot/nfs Jean-Christophe PLAGNIOL-VILLARD
2012-08-28  8:47     ` Sascha Hauer
2012-09-01 12:47       ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-24  7:26   ` [PATCH 1/7] dhcp: add global var support Roberto Nibali
2012-08-28  8:40   ` Sascha Hauer
2012-09-01 12:49     ` Jean-Christophe PLAGNIOL-VILLARD

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