Skip to contentSkip to conversation

Auto-append ip= option for NFS boot with appendrot

PATCH In review Enrico Jorns 3 participants 5 messages Sep 19, 2016 – Sep 21, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Auto-append ip= option for NFS boot with appendrot

This patches allow booting from nfs without the need to additionally provide an extra ip= option, such as ip=dhcp to the kernel commandline.

This is solved by adding a bootargs property to the network device of the connection used for the NFS boot and appending this to the nfs bootarg string.

Note that these patches are based on the 'vsprintf: Add support for printing ipv4 addresses with %pI4' series posted by Sascha.

Enrico Jorns (2):
net: add linux.bootarg parameter from ifup call
fs: nfs: pick up network interface bootargs parameter

 fs/nfs.c      |  8 ++++++++
 include/net.h |  1 +
 net/eth.c     |  1 +
 net/ifup.c    | 10 ++++++++++
 4 files changed, 20 insertions(+)
Signature · 7 lines
2.8.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 1/2 net: add linux.bootarg parameter from ifup call

This sets a ip=dhcp or ip=<clientip>:<serverip>:<gatewayip>:<netmaskip>::<iface>: bootarg for the network device upon execution of 'ifup'. This is the only point where we can distinguish between a static ip and a dhcp-based network setup and thus set a valid bootarg options as it will be required for nfs boot, for example.

---
 include/net.h |  1 +
 net/eth.c     |  1 +
 net/ifup.c    | 10 ++++++++++
 3 files changed, 12 insertions(+)
include/net.h +1 -0
index fd1c412..632b6d5 100644
@@ -62,6 +62,7 @@ struct eth_device {
 	IPaddr_t netmask;
 	IPaddr_t gateway;
 	char ethaddr[6];
+	char *bootarg;
 };
 
 #define dev_to_edev(d) container_of(d, struct eth_device, dev)
net/eth.c +1 -0
index 6f8e78d..e056826 100644
@@ -384,6 +384,7 @@ 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);
+	dev_add_param_string(dev, "linux.bootargs", NULL, NULL, &edev->bootarg, NULL);
 
 	if (edev->init)
 		edev->init(edev);
net/ifup.c +10 -0
index 30ac3f5..618eb8a 100644
@@ -106,12 +106,22 @@ int ifup(const char *name, unsigned flags)
 		ret = eth_set_param(dev, "serverip");
 		if (ret)
 			goto out;
+		dev_set_param(dev, "linux.bootargs", "ip=dhcp");
 	} else if (!strcmp(ip, "static")) {
+		char *bootarg;
 		for (i = 0; i < ARRAY_SIZE(vars); i++) {
 			ret = eth_set_param(dev, vars[i]);
 			if (ret)
 				goto out;
 		}
+		bootarg = basprintf("ip=%pI4:%pI4:%pI4:%pI4::%s:",
+				&edev->ipaddr,
+				&edev->serverip,
+				&edev->gateway,
+				&edev->netmask,
+				edev->devname);
+		dev_set_param(dev, "linux.bootargs", bootarg);
+		free(bootarg);
 	} else {
 		pr_err("unknown ip type: %s\n", ip);
 		ret = -EINVAL;
Signature · 7 lines
2.8.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

Re: [PATCH 1/2] net: add linux.bootarg parameter from ifup call

Quoted 8 lines · Enrico Jorns

This sets a ip=dhcp or ip=<clientip>:<serverip>:<gatewayip>:<netmaskip>::<iface>: bootarg for the network device upon execution of 'ifup'. This is the only point where we can distinguish between a static ip and a dhcp-based network setup and thus set a valid bootarg options as it will be required for nfs boot, for example.

Applied both with two little adjustments

net/eth.c int eth_register(struct eth_device *edev) · line 387

Quoted 7 lines
net/eth.c +1 -0
@@ -384,6 +384,7 @@ 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);
+	dev_add_param_string(dev, "linux.bootargs", NULL, NULL, &edev->bootarg, NULL);

Added a edev->bootarg = xstrdup(""); here to not have a <NULL> string in the variable when not initialized.

Quoted 15 lines
net/eth.c +0 -0
 	if (edev->init)
 		edev->init(edev);
net/ifup.c +2 -0
index 30ac3f5..618eb8a 100644
@@ -106,12 +106,22 @@ int ifup(const char *name, unsigned flags)
 		ret = eth_set_param(dev, "serverip");
 		if (ret)
 			goto out;
+		dev_set_param(dev, "linux.bootargs", "ip=dhcp");
 	} else if (!strcmp(ip, "static")) {
+		char *bootarg;
 		for (i = 0; i < ARRAY_SIZE(vars); i++) {

net/ifup.c int ifup(const char *name, unsigned flags) · line 122

Quoted 10 lines
net/ifup.c +6 -0
 			ret = eth_set_param(dev, vars[i]);
 			if (ret)
 				goto out;
 		}
+		bootarg = basprintf("ip=%pI4:%pI4:%pI4:%pI4::%s:",
+				&edev->ipaddr,
+				&edev->serverip,
+				&edev->gateway,
+				&edev->netmask,
+				edev->devname);

I dropped setting the devname here since we do not know if it's the same under Linux. If there are multiple interfaces in Linux we can only hope that the right one is used anyway.

Sascha

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 2/2 fs: nfs: pick up network interface bootargs parameter

In reply to Enrico Jorns

This adds the linux.bootarg device parameter from the network device of the current nfs connection and adds it to the nfs bootargs line.

This allows booting from nfs without manually setting a ip=dhcp or ip=<ipaddr> option.

---
 fs/nfs.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/nfs.c +8 -0
index a0a9dfc..97f01cf 100644
@@ -1314,6 +1314,7 @@ static char *rootnfsopts;
 static void nfs_set_rootarg(struct nfs_priv *npriv, struct fs_device_d *fsdev)
 {
 	char *str, *tmp;
+	const char *bootargs;
 
 	str = basprintf("root=/dev/nfs nfsroot=%pI4:%s%s%s", &npriv->server, npriv->path,
 			  rootnfsopts[0] ? "," : "", rootnfsopts);
@@ -1331,6 +1332,13 @@ static void nfs_set_rootarg(struct nfs_priv *npriv, struct fs_device_d *fsdev)
 		str = tmp;
 	}
 
+	bootargs = dev_get_param(&npriv->con->edev->dev, "linux.bootargs");
+	if (bootargs) {
+		tmp = basprintf("%s %s", str, bootargs);
+		free(str);
+		str = tmp;
+	}
+
 	fsdev_set_linux_rootarg(fsdev, str);
 
 	free(str);
Signature · 7 lines
2.8.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Re: [PATCH 2/2] fs: nfs: pick up network interface bootargs parameter

Quoted 1 line · Enrico Jorns

This adds the linux.bootarg device parameter from the network device of

s/bootarg/bootargs/

Quoted 1 line

the current nfs connection and adds it to the nfs bootargs line.

s/and adds it//

Quoted 2 lines

This allows booting from nfs without manually setting a ip=dhcp or ip=<ipaddr> option.

Otherwise: \o/
(i.e.: Acked-by: Uwe Kleine-König <[email protected]> for both patches)

Best regards
Uwe

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

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox