From 0d2550a1692abe294e50de728d6faa7e84a9eae7 Mon Sep 17 00:00:00 2001 From: Ian Lepore Date: Mon, 22 Feb 2016 18:53:55 +0000 Subject: [PATCH] If the user has set a u-boot env var named rootpath, automatically import it into the loader(8) env as dhcp.root-path, so that it overrides any dhcp/bootp server-provided path. Now if you have a dhcp server available you can easily net-boot a u-boot system even if you don't control the dhcp server config, by setting just two variables in the u-boot env: loaderdev=net rootpath=: Previously you had to either accept all the dhcp parameters from the server without the ability to locally provide the rootpath, or you had to forego dhcp and set more vars (ipaddr, netmask, serverip, rootpath). --- sys/boot/uboot/lib/net.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sys/boot/uboot/lib/net.c b/sys/boot/uboot/lib/net.c index 20a26b741468..9bc0c0754370 100644 --- a/sys/boot/uboot/lib/net.c +++ b/sys/boot/uboot/lib/net.c @@ -108,9 +108,19 @@ get_env_net_params() char *envstr; in_addr_t rootaddr, serveraddr; - /* Silently get out right away if we don't have rootpath. */ - if (ub_env_get("rootpath") == NULL) + /* + * Silently get out right away if we don't have rootpath, because none + * of the other info we obtain below is sufficient to boot without it. + * + * If we do have rootpath, copy it into the global var and also set + * dhcp.root-path in the env. If we don't get all the other info from + * the u-boot env below, we will still try dhcp/bootp, but the server- + * provided path will not replace the user-provided value we set here. + */ + if ((envstr = ub_env_get("rootpath")) == NULL) return; + strlcpy(rootpath, envstr, sizeof(rootpath)); + setenv("dhcp.root-path", rootpath, 0); /* * Our own IP address must be valid. Silently get out if it's not set, @@ -154,9 +164,6 @@ get_env_net_params() * There must be a rootpath. It may be ip:/path or it may be just the * path in which case the ip needs to be in serverip. */ - if ((envstr = ub_env_get("rootpath")) == NULL) - return; - strncpy(rootpath, envstr, sizeof(rootpath) - 1); rootaddr = net_parse_rootpath(); if (rootaddr == INADDR_NONE) rootaddr = serveraddr;