From 4ece916d9e48bfcd74043eba8fefe5b361c02130 Mon Sep 17 00:00:00 2001 From: hanwckf Date: Thu, 21 Aug 2025 12:53:45 +0800 Subject: [PATCH] uboot-2025: add force ipaddr support --- uboot-mtk-20250711/board/mediatek/common/load_data.c | 8 ++++++-- uboot-mtk-20250711/net/Kconfig | 4 ++++ uboot-mtk-20250711/net/net.c | 9 +++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/uboot-mtk-20250711/board/mediatek/common/load_data.c b/uboot-mtk-20250711/board/mediatek/common/load_data.c index cbb53673e..66bcd198f 100644 --- a/uboot-mtk-20250711/board/mediatek/common/load_data.c +++ b/uboot-mtk-20250711/board/mediatek/common/load_data.c @@ -123,19 +123,23 @@ static int load_tftp(ulong addr, size_t *data_size, const char *env_name) { char file_name[CONFIG_SYS_CBSIZE + 1]; u32 size; - +#ifdef CONFIG_NET_FORCE_IPADDR + printf("U-Boot's IP address: %s, IP netmask: %s\n", CONFIG_IPADDR, CONFIG_NETMASK); +#else if (env_update("ipaddr", CONFIG_IPADDR, "Input U-Boot's IP address:", NULL, 0)) return CMD_RET_FAILURE; - +#endif if (env_update("serverip", CONFIG_SERVERIP, "Input TFTP server's IP address:", NULL, 0)) return CMD_RET_FAILURE; +#ifndef CONFIG_NET_FORCE_IPADDR #ifdef CONFIG_NETMASK if (env_update("netmask", CONFIG_NETMASK, "Input IP netmask:", NULL, 0)) return CMD_RET_FAILURE; +#endif #endif if (env_update(env_name, "", "Input file name:", diff --git a/uboot-mtk-20250711/net/Kconfig b/uboot-mtk-20250711/net/Kconfig index 67aba76e0..fa82f9ce0 100644 --- a/uboot-mtk-20250711/net/Kconfig +++ b/uboot-mtk-20250711/net/Kconfig @@ -233,6 +233,10 @@ config MTK_HTTPD help Enable mediatek httpd framework that allows some customized features. +config NET_FORCE_IPADDR + bool "Use ipaddr and netmask with CONFIG_IPADDR and CONFIG_NETMASK" + default n + endif # if NET source "net/lwip/Kconfig" diff --git a/uboot-mtk-20250711/net/net.c b/uboot-mtk-20250711/net/net.c index abf297435..2bf69f36f 100644 --- a/uboot-mtk-20250711/net/net.c +++ b/uboot-mtk-20250711/net/net.c @@ -220,6 +220,7 @@ int __maybe_unused net_busy_flag; /**********************************************************************/ +#ifndef CONFIG_NET_FORCE_IPADDR static int on_ipaddr(const char *name, const char *value, enum env_op op, int flags) { @@ -231,6 +232,7 @@ static int on_ipaddr(const char *name, const char *value, enum env_op op, return 0; } U_BOOT_ENV_CALLBACK(ipaddr, on_ipaddr); +#endif static int on_gatewayip(const char *name, const char *value, enum env_op op, int flags) @@ -244,6 +246,7 @@ static int on_gatewayip(const char *name, const char *value, enum env_op op, } U_BOOT_ENV_CALLBACK(gatewayip, on_gatewayip); +#ifndef CONFIG_NET_FORCE_IPADDR static int on_netmask(const char *name, const char *value, enum env_op op, int flags) { @@ -255,6 +258,7 @@ static int on_netmask(const char *name, const char *value, enum env_op op, return 0; } U_BOOT_ENV_CALLBACK(netmask, on_netmask); +#endif static int on_serverip(const char *name, const char *value, enum env_op op, int flags) @@ -451,6 +455,11 @@ int net_loop(enum proto_t protocol) net_try_count = 1; debug_cond(DEBUG_INT_STATE, "--- net_loop Entry\n"); +#ifdef CONFIG_NET_FORCE_IPADDR + net_ip = string_to_ip(CONFIG_IPADDR); + net_netmask = string_to_ip(CONFIG_NETMASK); +#endif + #ifdef CONFIG_PHY_NCSI if (phy_interface_is_ncsi() && protocol != NCSI && !ncsi_active()) { printf("%s: configuring NCSI first\n", __func__);