Re: [PATCH v4 3/3] sntp: use udp framework

2020-10-01 Thread Tom Rini
On Fri, Sep 18, 2020 at 02:13:02PM +0200, Philippe Reynes wrote:

> This commits update the support of sntp to use
> the framework udp. This change allows to remove
> all the reference to sntp in the main network
> file net/net.c.
> 
> Signed-off-by: Philippe Reynes 
> Reviewed-by: Simon Glass 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v4 3/3] sntp: use udp framework

2020-09-18 Thread Simon Glass
Hi Philippe,

On Fri, 18 Sep 2020 at 06:13, Philippe Reynes
 wrote:
>
> This commits update the support of sntp to use
> the framework udp. This change allows to remove
> all the reference to sntp in the main network
> file net/net.c.
>
> Signed-off-by: Philippe Reynes 
> ---
>
> Changelog:
> v4:
> - new patch in the serie
>
>  cmd/Kconfig|  1 +
>  cmd/net.c  | 10 +-
>  include/net/sntp.h | 58 
> ++
>  net/net.c  | 31 +
>  net/sntp.c | 29 +--
>  net/sntp.h | 57 -
>  6 files changed, 96 insertions(+), 90 deletions(-)
>  create mode 100644 include/net/sntp.h
>  delete mode 100644 net/sntp.h
>

Reviewed-by: Simon Glass 

I wonder if we should use driver model to have a network-protocol uclass?

Regards,
Simon


[PATCH v4 3/3] sntp: use udp framework

2020-09-18 Thread Philippe Reynes
This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes 
---

Changelog:
v4:
- new patch in the serie

 cmd/Kconfig|  1 +
 cmd/net.c  | 10 +-
 include/net/sntp.h | 58 ++
 net/net.c  | 31 +
 net/sntp.c | 29 +--
 net/sntp.h | 57 -
 6 files changed, 96 insertions(+), 90 deletions(-)
 create mode 100644 include/net/sntp.h
 delete mode 100644 net/sntp.h

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 0761dbb..169c16a 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1633,6 +1633,7 @@ config CMD_CDP
 
 config CMD_SNTP
bool "sntp"
+   select PROT_UDP
help
  Synchronize RTC via network
 
diff --git a/cmd/net.c b/cmd/net.c
index 9bbcdbc..beb2877 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -13,6 +13,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 static int netboot_common(enum proto_t, struct cmd_tbl *, int, char * const 
[]);
 
@@ -356,6 +358,12 @@ U_BOOT_CMD(
 #endif
 
 #if defined(CONFIG_CMD_SNTP)
+static struct udp_ops sntp_ops = {
+   .prereq = sntp_prereq,
+   .start = sntp_start,
+   .data = NULL,
+};
+
 int do_sntp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
char *toff;
@@ -380,7 +388,7 @@ int do_sntp(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[])
else
net_ntp_time_offset = simple_strtol(toff, NULL, 10);
 
-   if (net_loop(SNTP) < 0) {
+   if (udp_loop(_ops) < 0) {
printf("SNTP failed: host %pI4 not responding\n",
   _ntp_server);
return CMD_RET_FAILURE;
diff --git a/include/net/sntp.h b/include/net/sntp.h
new file mode 100644
index 000..30b44d1
--- /dev/null
+++ b/include/net/sntp.h
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Masami Komiya  2005
+ */
+
+#ifndef __SNTP_H__
+#define __SNTP_H__
+
+#define NTP_SERVICE_PORT   123
+#define SNTP_PACKET_LEN48
+
+
+/* Leap Indicator */
+#define NTP_LI_NOLEAP  0x0
+#define NTP_LI_61SECS  0x1
+#define NTP_LI_59SECS  0x2
+#define NTP_LI_ALARM   0x3
+
+/* Version */
+
+#define NTP_VERSION4
+
+/* Mode */
+#define NTP_MODE_RESERVED  0
+#define NTP_MODE_SYMACTIVE 1   /* Symmetric Active */
+#define NTP_MODE_SYMPASSIVE2   /* Symmetric Passive */
+#define NTP_MODE_CLIENT3
+#define NTP_MODE_SERVER4
+#define NTP_MODE_BROADCAST 5
+#define NTP_MODE_NTPCTRL   6   /* Reserved for NTP control message */
+#define NTP_MODE_PRIVATE   7   /* Reserved for private use */
+
+struct sntp_pkt_t {
+#if __LITTLE_ENDIAN
+   uchar mode:3;
+   uchar vn:3;
+   uchar li:2;
+#else
+   uchar li:2;
+   uchar vn:3;
+   uchar mode:3;
+#endif
+   uchar stratum;
+   uchar poll;
+   uchar precision;
+   uint root_delay;
+   uint root_dispersion;
+   uint reference_id;
+   unsigned long long reference_timestamp;
+   unsigned long long originate_timestamp;
+   unsigned long long receive_timestamp;
+   unsigned long long transmit_timestamp;
+} __attribute__((packed));
+
+int sntp_prereq(void *data);
+int sntp_start(void *data);/* Begin SNTP */
+
+#endif /* __SNTP_H__ */
diff --git a/net/net.c b/net/net.c
index 1ce0eb5..197fde3 100644
--- a/net/net.c
+++ b/net/net.c
@@ -72,12 +72,6 @@
  * 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:
  *
@@ -119,9 +113,6 @@
 #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
@@ -185,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 */
-intnet_ntp_time_offset;
-#endif
-
 static uchar net_pkt_buf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
 /* Receive packets */
 uchar *net_rx_packets[PKTBUFSRX];
@@ -521,11 +505,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();
@@ -1352,14 +1331,6 @@ static int net_check_prereq(enum proto_t protocol)