Merge branch '2021.01-rc' of https://github.com/lftan/u-boot
[platform/kernel/u-boot.git] / net / net.c
index 11683dd..ad7e3b3 100644 (file)
--- a/net/net.c
+++ b/net/net.c
  *     We want:        - load the boot file
  *     Next step:      none
  *
- * SNTP:
- *
- *     Prerequisites:  - own ethernet address
- *                     - own IP address
- *     We want:        - network time
- *     Next step:      none
  *
  * WOL:
  *
 #if defined(CONFIG_CMD_PCAP)
 #include <net/pcap.h>
 #endif
+#include <net/udp.h>
 #if defined(CONFIG_LED_STATUS)
 #include <miiphy.h>
 #include <status_led.h>
 #include "nfs.h"
 #include "ping.h"
 #include "rarp.h"
-#if defined(CONFIG_CMD_SNTP)
-#include "sntp.h"
-#endif
 #if defined(CONFIG_CMD_WOL)
 #include "wol.h"
 #endif
@@ -184,13 +176,6 @@ u32 net_boot_file_size;
 /* Boot file size in blocks as reported by the DHCP server */
 u32 net_boot_file_expected_size_in_blocks;
 
-#if defined(CONFIG_CMD_SNTP)
-/* NTP server IP address */
-struct in_addr net_ntp_server;
-/* offset time from UTC */
-int            net_ntp_time_offset;
-#endif
-
 static uchar net_pkt_buf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
 /* Receive packets */
 uchar *net_rx_packets[PKTBUFSRX];
@@ -353,12 +338,19 @@ void net_auto_load(void)
        tftp_start(TFTPGET);
 }
 
-static void net_init_loop(void)
+static int net_init_loop(void)
 {
        if (eth_get_dev())
                memcpy(net_ethaddr, eth_get_ethaddr(), 6);
+       else
+               /*
+                * Not ideal, but there's no way to get the actual error, and I
+                * don't feel like fixing all the users of eth_get_dev to deal
+                * with errors.
+                */
+               return -ENONET;
 
-       return;
+       return 0;
 }
 
 static void net_clear_handlers(void)
@@ -373,7 +365,7 @@ static void net_cleanup_loop(void)
        net_clear_handlers();
 }
 
-void net_init(void)
+int net_init(void)
 {
        static int first_call = 1;
 
@@ -396,7 +388,7 @@ void net_init(void)
                first_call = 0;
        }
 
-       net_init_loop();
+       return net_init_loop();
 }
 
 /**********************************************************************/
@@ -409,6 +401,10 @@ int net_loop(enum proto_t protocol)
        int ret = -EINVAL;
        enum net_loop_state prev_net_state = net_state;
 
+#if defined(CONFIG_CMD_PING)
+       if (protocol != PING)
+               net_ping_ip.s_addr = 0;
+#endif
        net_restarted = 0;
        net_dev_exists = 0;
        net_try_count = 1;
@@ -516,11 +512,6 @@ restart:
                        nc_start();
                        break;
 #endif
-#if defined(CONFIG_CMD_SNTP)
-               case SNTP:
-                       sntp_start();
-                       break;
-#endif
 #if defined(CONFIG_CMD_DNS)
                case DNS:
                        dns_start();
@@ -540,6 +531,9 @@ restart:
                        break;
                }
 
+               if (IS_ENABLED(CONFIG_PROT_UDP) && protocol == UDP)
+                       udp_start();
+
                break;
        }
 
@@ -1344,14 +1338,6 @@ static int net_check_prereq(enum proto_t protocol)
                }
                goto common;
 #endif
-#if defined(CONFIG_CMD_SNTP)
-       case SNTP:
-               if (net_ntp_server.s_addr == 0) {
-                       puts("*** ERROR: NTP server address not given\n");
-                       return 1;
-               }
-               goto common;
-#endif
 #if defined(CONFIG_CMD_DNS)
        case DNS:
                if (net_dns_server.s_addr == 0) {
@@ -1360,6 +1346,13 @@ static int net_check_prereq(enum proto_t protocol)
                }
                goto common;
 #endif
+#if defined(CONFIG_PROT_UDP)
+       case UDP:
+               if (udp_prereq())
+                       return 1;
+               goto common;
+#endif
+
 #if defined(CONFIG_CMD_NFS)
        case NFS:
 #endif
@@ -1370,8 +1363,8 @@ static int net_check_prereq(enum proto_t protocol)
                        puts("*** ERROR: `serverip' not set\n");
                        return 1;
                }
-#if    defined(CONFIG_CMD_PING) || defined(CONFIG_CMD_SNTP) || \
-       defined(CONFIG_CMD_DNS)
+#if    defined(CONFIG_CMD_PING) || \
+       defined(CONFIG_CMD_DNS) || defined(CONFIG_PROT_UDP)
 common:
 #endif
                /* Fall through */
@@ -1564,20 +1557,6 @@ int net_parse_bootfile(struct in_addr *ipaddr, char *filename, int max_len)
        return 1;
 }
 
-#if    defined(CONFIG_CMD_NFS)         || \
-       defined(CONFIG_CMD_SNTP)        || \
-       defined(CONFIG_CMD_DNS)
-/*
- * make port a little random (1024-17407)
- * This keeps the math somewhat trivial to compute, and seems to work with
- * all supported protocols/clients/servers
- */
-unsigned int random_port(void)
-{
-       return 1024 + (get_timer(0) % 0x4000);
-}
-#endif
-
 void ip_to_string(struct in_addr x, char *s)
 {
        x.s_addr = ntohl(x.s_addr);