On 13.09.2023 08:07, Ilias Apalodimas wrote:
On Fri, Sep 08, 2023 at 07:53:09PM +0600, Maxim Uvarov wrote:
+
+#include <common.h>
+#include <command.h>
+#include <console.h>
+
+#include <lwip/dhcp.h>
+#include <lwip/prot/dhcp.h>
+#include "lwip/timeouts.h"
+
+#include <net/eth.h>
+#include <net/ulwip.h>
+
+#define DHCP_WAIT_MS 2000
Is this the time we wait for a dhcp reply? If so we should bump it to
something higher
+
+static void dhcp_tmo(void *arg)
+{
+ struct netif *netif = (struct netif *)arg;
+ struct dhcp *dhcp;
+ int err = 0;
+
+ dhcp = netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP);
+ if (!dhcp)
+ return;
+
+ switch (dhcp->state) {
+ case DHCP_STATE_BOUND:
+ err += env_set("bootfile", dhcp->boot_file_name);
+ err += env_set("ipaddr", ip4addr_ntoa(&dhcp->offered_ip_addr));
+ err += env_set("netmask", ip4addr_ntoa(&dhcp->offered_sn_mask));
+ err += env_set("serverip", ip4addr_ntoa(&dhcp->server_ip_addr));
+ if (err)
+ log_err("error update envs\n");
+ log_info("DHCP client bound to address %s\n",
ip4addr_ntoa(&dhcp->offered_ip_addr));
+ break;
+ default:
+ return;
+ }
+}
+
+int ulwip_dhcp(void)
+{
+ struct netif *netif;
+ int eth_idx;
+
+ eth_idx = eth_get_dev_index();
+ if (eth_idx < 0)
+ return -EPERM;
+
+ netif = netif_get_by_index(eth_idx + 1);
Why is the +1 needed here?
Netif index is driven by posix design and is 1-based in contrast to
U-Boot's 0-based dev index. A comment noting that would probably help
the ones not knowing lwIP.
Regards,
Simon
+ if (!netif)
+ return -ENOENT;
+
+ sys_timeout(DHCP_WAIT_MS, dhcp_tmo, netif);
+
+ return dhcp_start(netif) ? 0 : -EPERM;
+}
--
2.30.2