int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
ip_addr_t addr;
+ int ret;
if (argc < 2)
return CMD_RET_USAGE;
return CMD_RET_USAGE;
net_try_count = 1;
-restart:
- if (net_lwip_eth_start() < 0 || ping_loop(eth_get_dev(), &addr) < 0) {
- if (net_start_again() == 0)
- goto restart;
- else
- return CMD_RET_FAILURE;
- }
- return CMD_RET_SUCCESS;
+ do {
+ if (net_lwip_eth_start() == 0) {
+ ret = ping_loop(eth_get_dev(), &addr);
+ net_lwip_eth_stop();
+ if (ret == 0)
+ return CMD_RET_SUCCESS;
+ }
+ } while (net_start_again() == 0);
+
+ return CMD_RET_FAILURE;
}
ip_addr_t *srvip;
char *server;
ip_addr_t ipaddr;
+ int ret = CMD_RET_FAILURE;
switch (argc) {
case 1:
return CMD_RET_FAILURE;
if (sntp_loop(eth_get_dev(), srvip) < 0)
- return CMD_RET_FAILURE;
+ goto out;
+
+ ret = CMD_RET_SUCCESS;
+
+out:
+ net_lwip_eth_stop();
- return CMD_RET_SUCCESS;
+ return ret;
}
int net_lwip_dns_init(void);
int net_lwip_eth_start(void);
+void net_lwip_eth_stop(void);
struct netif *net_lwip_new_netif(struct udevice *udev);
struct netif *net_lwip_new_netif_noip(struct udevice *udev);
void net_lwip_remove_netif(struct netif *netif);
dev = eth_get_dev();
if (!dev) {
log_err("No network device\n");
- return CMD_RET_FAILURE;
+ ret = CMD_RET_FAILURE;
+ goto out;
}
ret = dhcp_loop(dev);
if (ret)
- return ret;
+ goto out;
if (argc > 1) {
struct cmd_tbl cmdtp = {};
- return do_tftpb(&cmdtp, 0, argc, argv);
+ ret = do_tftpb(&cmdtp, 0, argc, argv);
+ goto out;
}
- return CMD_RET_SUCCESS;
+ ret = CMD_RET_SUCCESS;
+
+out:
+ net_lwip_eth_stop();
+
+ return ret;
}
{
char *name;
char *var = NULL;
+ int ret;
if (argc == 1 || argc > 3)
return CMD_RET_USAGE;
if (net_lwip_eth_start() < 0)
return CMD_RET_FAILURE;
- return dns_loop(eth_get_dev(), name, var);
+ ret = dns_loop(eth_get_dev(), name, var);
+
+ net_lwip_eth_stop();
+
+ return ret;
}
int net_try_count;
static int net_restarted;
int net_restart_wrap;
+static int net_lwip_eth_started;
static uchar net_pkt_buf[(PKTBUFSRX) * PKTSIZE_ALIGN + PKTALIGN]
__aligned(PKTALIGN);
const u8 net_bcast_ethaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
{
int ret;
+ if (net_lwip_eth_started++ > 0)
+ return 0;
+
net_init();
eth_halt();
eth_set_current();
ret = eth_init();
if (ret < 0) {
+ net_lwip_eth_started--;
eth_halt();
return ret;
}
return 0;
}
+void net_lwip_eth_stop(void)
+{
+ if (!net_lwip_eth_started)
+ return;
+
+ if (--net_lwip_eth_started)
+ return;
+
+ eth_halt();
+}
+
static struct netif *new_netif(struct udevice *udev, bool with_ip)
{
unsigned char enetaddr[ARP_HLEN];
int do_nfs(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
int ret = CMD_RET_SUCCESS;
+ bool started = false;
char *arg = NULL;
char *words[2] = { };
char *fname = NULL;
ret = CMD_RET_FAILURE;
goto out;
}
+ started = true;
if (nfs_loop(eth_get_dev(), laddr, fname, srvip) < 0)
ret = CMD_RET_FAILURE;
out:
+ if (started)
+ net_lwip_eth_stop();
if (arg != net_boot_file_name)
free(arg);
return ret;
int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
int ret = CMD_RET_SUCCESS;
+ bool started = false;
char *arg = NULL;
char *words[3] = { };
char *fname = NULL;
ret = CMD_RET_FAILURE;
goto out;
}
+ started = true;
if (tftp_loop(eth_get_dev(), laddr, fname, srvip, port) < 0)
ret = CMD_RET_FAILURE;
else
image_load_addr = laddr;
out:
+ if (started)
+ net_lwip_eth_stop();
if (arg != net_boot_file_name)
free(arg);
return ret;
udev = eth_get_dev();
netif = net_lwip_new_netif(udev);
- if (!netif)
+ if (!netif) {
+ net_lwip_eth_stop();
return -ENODEV;
+ }
ret = wget_handle_request(&ctx, is_https, udev, netif);
net_lwip_remove_netif(netif);
+ net_lwip_eth_stop();
return ret;
}