9
0
Fork 0

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.

Signed-off-by: Enrico Jorns <ejo@pengutronix.de>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Enrico Jorns 2016-09-19 18:03:48 +02:00 committed by Sascha Hauer
parent d60230bded
commit 841d83ff0a
3 changed files with 12 additions and 0 deletions

View File

@ -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)

View File

@ -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->bootarg = xstrdup("");
dev_add_param_string(dev, "linux.bootargs", NULL, NULL, &edev->bootarg, NULL);
if (edev->init)
edev->init(edev);

View File

@ -106,12 +106,21 @@ 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:::",
&edev->ipaddr,
&edev->serverip,
&edev->gateway,
&edev->netmask);
dev_set_param(dev, "linux.bootargs", bootarg);
free(bootarg);
} else {
pr_err("unknown ip type: %s\n", ip);
ret = -EINVAL;