[PATCH v2 17/22] elf: Only use network environment-variables if net enabled

Simon Glass sjg at chromium.org
Thu May 1 03:04:42 CEST 2025


If there is no network support it doesn't make sense to try to read
these variables. Add a condition to handle this.

This is needed so that env_get_ip() is not called when it is no-longer
a static inline, but included in net/ code.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 cmd/elf.c | 41 ++++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/cmd/elf.c b/cmd/elf.c
index 6b49c613703..c94125dc4a9 100644
--- a/cmd/elf.c
+++ b/cmd/elf.c
@@ -242,30 +242,33 @@ int do_bootvx(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		 * The following parameters are only needed if 'bootdev'
 		 * is an ethernet device, otherwise they are optional.
 		 */
-		tmp = env_get("ipaddr");
-		if (tmp) {
-			ptr += sprintf(build_buf + ptr, "e=%s", tmp);
-			tmp = env_get("netmask");
+		if (IS_ENABLED(CONFIG_NET) || IS_ENABLED(CONFIG_NET_LWIP)) {
+			tmp = env_get("ipaddr");
 			if (tmp) {
-				u32 mask = env_get_ip("netmask").s_addr;
-				ptr += sprintf(build_buf + ptr,
-					       ":%08x ", ntohl(mask));
-			} else {
-				ptr += sprintf(build_buf + ptr, " ");
+				ptr += sprintf(build_buf + ptr, "e=%s", tmp);
+				tmp = env_get("netmask");
+				if (tmp) {
+					u32 mask = env_get_ip("netmask").s_addr;
+
+					ptr += sprintf(build_buf + ptr,
+						       ":%08x ", ntohl(mask));
+				} else {
+					ptr += sprintf(build_buf + ptr, " ");
+				}
 			}
-		}
 
-		tmp = env_get("serverip");
-		if (tmp)
-			ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
+			tmp = env_get("serverip");
+			if (tmp)
+				ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
 
-		tmp = env_get("gatewayip");
-		if (tmp)
-			ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
+			tmp = env_get("gatewayip");
+			if (tmp)
+				ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
 
-		tmp = env_get("hostname");
-		if (tmp)
-			ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
+			tmp = env_get("hostname");
+			if (tmp)
+				ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
+		}
 
 		tmp = env_get("othbootargs");
 		if (tmp) {
-- 
2.43.0



More information about the U-Boot mailing list