mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] Add linux.devname property to eth device
@ 2017-11-21 15:40 Gavin Schenk
  2017-11-23  7:51 ` Uwe Kleine-König
  2017-11-24  8:15 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Gavin Schenk @ 2017-11-21 15:40 UTC (permalink / raw)
  To: barebox; +Cc: Gavin Schenk

When you have a static network environment but more than one network
device on your machine it is necessary to provide the <device> parameter
to the ip parameter at kernel cmd line.

The device name assigned by Linux cannot in general be predicted as it
depends on driver bind order.

This patch introduces a new property linux.devname to eth devices.
The value is added to bootargs per interface and can be changed in
env/network/INTF

Note that the device name is also used when dhcp is in use.

Signed-off-by: Gavin Schenk <g.schenk@eckelmann.de>
---

This is V2 of "[PATCH] Configure network device for nfsboot via nv var"

 include/net.h |  1 +
 net/eth.c     |  2 ++
 net/ifup.c    | 19 +++++++++++++++----
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/include/net.h b/include/net.h
index 632b6d541..0aa5569e0 100644
--- a/include/net.h
+++ b/include/net.h
@@ -62,6 +62,7 @@ struct eth_device {
 	IPaddr_t netmask;
 	IPaddr_t gateway;
 	char ethaddr[6];
+	char *linuxdevname;
 	char *bootarg;
 };
 
diff --git a/net/eth.c b/net/eth.c
index dac2400b8..fe661c832 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -384,6 +384,8 @@ int eth_register(struct eth_device *edev)
 	dev_add_param_ip(dev, "netmask", NULL, NULL, &edev->netmask, edev);
 	dev_add_param_mac(dev, "ethaddr", eth_param_set_ethaddr, NULL,
 			edev->ethaddr, edev);
+	edev->linuxdevname = xstrdup("");
+	dev_add_param_string(dev, "linux.devname", NULL, NULL, &edev->linuxdevname, NULL);
 	edev->bootarg = xstrdup("");
 	dev_add_param_string(dev, "linux.bootargs", NULL, NULL, &edev->bootarg, NULL);
 
diff --git a/net/ifup.c b/net/ifup.c
index 5113d1383..106700e2e 100644
--- a/net/ifup.c
+++ b/net/ifup.c
@@ -50,6 +50,7 @@ int ifup(const char *name, unsigned flags)
 	int ret;
 	char *cmd, *cmd_discover;
 	const char *ip;
+	const char *linuxdevname;
 	struct stat s;
 	int i;
 	struct device_d *dev;
@@ -63,6 +64,7 @@ int ifup(const char *name, unsigned flags)
 	env_push_context();
 
 	setenv("ip", "");
+	setenv("linuxdevname", "");
 
 	for (i = 0; i < ARRAY_SIZE(vars); i++)
 		setenv(vars[i], "");
@@ -95,6 +97,13 @@ int ifup(const char *name, unsigned flags)
 	if (ret)
 		goto out;
 
+	linuxdevname = getenv("linuxdevname");
+	if (!linuxdevname)
+		linuxdevname = "";
+	ret = dev_set_param(dev, "linux.devname", linuxdevname);
+	if (ret)
+		goto out;
+
 	ip = getenv("ip");
 	if (!ip)
 		ip = "";
@@ -114,11 +123,12 @@ int ifup(const char *name, unsigned flags)
 			if (ret)
 				goto out;
 		}
-		bootarg = basprintf("ip=%pI4:%pI4:%pI4:%pI4:::",
+		bootarg = basprintf("ip=%pI4:%pI4:%pI4:%pI4::%s:",
 				&edev->ipaddr,
 				&edev->serverip,
 				&edev->gateway,
-				&edev->netmask);
+				&edev->netmask,
+				edev->linuxdevname);
 		dev_set_param(dev, "linux.bootargs", bootarg);
 		free(bootarg);
 	} else {
@@ -194,8 +204,9 @@ static int do_ifup(int argc, char *argv[])
 BAREBOX_CMD_HELP_START(ifup)
 BAREBOX_CMD_HELP_TEXT("Each INTF must have a script /env/network/INTF that set the variables")
 BAREBOX_CMD_HELP_TEXT("ip (to 'static' or 'dynamic'), ipaddr, netmask, gateway, serverip and/or")
-BAREBOX_CMD_HELP_TEXT("ethaddr. A script /env/network/INTF-discover can contains for discovering")
-BAREBOX_CMD_HELP_TEXT("the ethernet device, e.g. 'usb'.")
+BAREBOX_CMD_HELP_TEXT("ethaddr, linuxdevname. A script /env/network/INTF-discover can contains")
+BAREBOX_CMD_HELP_TEXT("for discovering the ethernet device, e.g. 'usb'. If set, linuxdevname is")
+BAREBOX_CMD_HELP_TEXT("added to bootargs as device parameter.")
 BAREBOX_CMD_HELP_TEXT("")
 BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT ("-a",  "bring up all interfaces")
-- 
2.15.0


Eckelmann AG
Vorstand: Dipl.-Ing. Peter Frankenbach (Sprecher) Dipl.-Wi.-Ing. Philipp Eckelmann
Dr.-Ing. Marco Münchhof Dr.-Ing. Frank Uhlemann
Vorsitzender des Aufsichtsrats: Hubertus G. Krossa
Stv. Vorsitzender des Aufsichtsrats: Dr.-Ing. Gerd Eckelmann
Sitz der Gesellschaft: Berliner Str. 161, 65205 Wiesbaden, Amtsgericht Wiesbaden HRB 12636
http://www.eckelmann.de 


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

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

* Re: [PATCH] Add linux.devname property to eth device
  2017-11-21 15:40 [PATCH] Add linux.devname property to eth device Gavin Schenk
@ 2017-11-23  7:51 ` Uwe Kleine-König
  2017-11-24  8:15 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2017-11-23  7:51 UTC (permalink / raw)
  To: Gavin Schenk; +Cc: barebox

On Tue, Nov 21, 2017 at 04:40:47PM +0100, Gavin Schenk wrote:
> When you have a static network environment but more than one network
> device on your machine it is necessary to provide the <device> parameter
> to the ip parameter at kernel cmd line.
> 
> The device name assigned by Linux cannot in general be predicted as it
> depends on driver bind order.
> 
> This patch introduces a new property linux.devname to eth devices.
> The value is added to bootargs per interface and can be changed in
> env/network/INTF
> 
> Note that the device name is also used when dhcp is in use.
> 
> Signed-off-by: Gavin Schenk <g.schenk@eckelmann.de>
> ---
> 
> This is V2 of "[PATCH] Configure network device for nfsboot via nv var"

After first thinking that the former patch was a good idea, seeing this
now I agree with Sascha this new approach is better.

Maybe add the following (in a separate commit?):

diff --git a/defaultenv/defaultenv-2-base/network/eth0 b/defaultenv/defaultenv-2-base/network/eth0
index 33fe7c1b2b48..992e37a35deb 100644
--- a/defaultenv/defaultenv-2-base/network/eth0
+++ b/defaultenv/defaultenv-2-base/network/eth0
@@ -13,6 +13,10 @@ serverip=
 # MAC address if needed
 #ethaddr=xx:xx:xx:xx:xx:xx
 
+# device name under Linux (needed for static setups with more than
+# one network adapter)
+#linuxdevname=eth0
+
 # put code to discover eth0 (i.e. 'usb') to /env/network/eth0-discover
 
 exit 0

Other than that:

Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

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

* Re: [PATCH] Add linux.devname property to eth device
  2017-11-21 15:40 [PATCH] Add linux.devname property to eth device Gavin Schenk
  2017-11-23  7:51 ` Uwe Kleine-König
@ 2017-11-24  8:15 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2017-11-24  8:15 UTC (permalink / raw)
  To: Gavin Schenk; +Cc: barebox

Hi Gavin,

On Tue, Nov 21, 2017 at 04:40:47PM +0100, Gavin Schenk wrote:
> When you have a static network environment but more than one network
> device on your machine it is necessary to provide the <device> parameter
> to the ip parameter at kernel cmd line.
> 
> The device name assigned by Linux cannot in general be predicted as it
> depends on driver bind order.
> 
> This patch introduces a new property linux.devname to eth devices.
> The value is added to bootargs per interface and can be changed in
> env/network/INTF
> 
> Note that the device name is also used when dhcp is in use.
> 
> Signed-off-by: Gavin Schenk <g.schenk@eckelmann.de>

Looks much better now. This needs some updates to fit into the
networking update series I just sent, but I'll handle that soon
when I see if this series can be taken or not.

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

end of thread, other threads:[~2017-11-24  8:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-21 15:40 [PATCH] Add linux.devname property to eth device Gavin Schenk
2017-11-23  7:51 ` Uwe Kleine-König
2017-11-24  8:15 ` Sascha Hauer

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