From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 6/7] hwclock: Allow to set hwclock from sntp
Date: Mon, 14 Dec 2015 12:43:30 +0100 [thread overview]
Message-ID: <1450093411-13885-6-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1450093411-13885-1-git-send-email-s.hauer@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/hwclock.c | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/commands/hwclock.c b/commands/hwclock.c
index 3f89cce..7633132 100644
--- a/commands/hwclock.c
+++ b/commands/hwclock.c
@@ -4,6 +4,7 @@
#include <linux/err.h>
#include <linux/ctype.h>
#include <rtc.h>
+#include <sntp.h>
#include <linux/rtc.h>
#include <string.h>
#include <environment.h>
@@ -92,8 +93,10 @@ static int do_hwclock(int argc, char *argv[])
char *env_name = NULL;
int opt;
int set = 0;
+ int ntp_to_hw = 0;
+ char *ntpserver = NULL;
- while ((opt = getopt(argc, argv, "f:s:e:")) > 0) {
+ while ((opt = getopt(argc, argv, "f:s:e:n:")) > 0) {
int ret;
switch (opt) {
@@ -116,6 +119,10 @@ static int do_hwclock(int argc, char *argv[])
case 'e':
env_name = optarg;
break;
+ case 'n':
+ ntp_to_hw = 1;
+ ntpserver = optarg;
+ break;
}
}
@@ -127,6 +134,23 @@ static int do_hwclock(int argc, char *argv[])
return rtc_set_time(r, &stm);
}
+ if (ntp_to_hw) {
+ s64 now;
+
+ if (!IS_ENABLED(CONFIG_NET_SNTP)) {
+ printf("SNTP support is disabled\n");
+ return 1;
+ }
+
+ now = sntp(ntpserver);
+ if (now < 0)
+ return now;
+
+ rtc_time_to_tm(now, &stm);
+ printf("%s\n", time_str(&stm));
+ return rtc_set_time(r, &stm);
+ }
+
rtc_read_time(r, &tm);
if (env_name) {
@@ -147,6 +171,7 @@ BAREBOX_CMD_HELP_START(hwclock)
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT ("-f NAME\t\t\t", "RTC device name (default rtc0)")
BAREBOX_CMD_HELP_OPT ("-e VARNAME\t\t", "store RTC readout into variable VARNAME")
+BAREBOX_CMD_HELP_OPT ("-n NTPSERVER\t", "set RTC from NTP server")
BAREBOX_CMD_HELP_OPT ("-s ccyymmddHHMM[.SS]\t", "set time")
BAREBOX_CMD_HELP_END
--
2.6.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-12-14 11:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-14 11:43 [PATCH 1/7] hwclock command: use format like the Linux tool does Sascha Hauer
2015-12-14 11:43 ` [PATCH 2/7] hwclock command: forward return value of rtc_set_time Sascha Hauer
2015-12-14 11:43 ` [PATCH 3/7] rtc: Check time for validity before passing it to the rtc driver Sascha Hauer
2015-12-14 11:43 ` [PATCH 4/7] rtc: Fill in weekdays before setting time Sascha Hauer
2015-12-14 11:43 ` [PATCH 5/7] net: Add SNTP support Sascha Hauer
2015-12-14 11:43 ` Sascha Hauer [this message]
2015-12-14 11:43 ` [PATCH 7/7] rtc: Add Abracon driver Sascha Hauer
2015-12-14 11:54 ` [PATCH 1/7] hwclock command: use format like the Linux tool does Fabio Estevam
2015-12-14 12:02 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1450093411-13885-6-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox