summaryrefslogtreecommitdiffstats
path: root/common/cmd_net.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/cmd_net.c')
-rw-r--r--common/cmd_net.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/common/cmd_net.c b/common/cmd_net.c
index 47f9622fad..b6d436e9c9 100644
--- a/common/cmd_net.c
+++ b/common/cmd_net.c
@@ -136,6 +136,19 @@ static void netboot_update_env (void)
#endif
if (NetOurNISDomain[0])
setenv ("domain", NetOurNISDomain);
+
+#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_TIMEOFFSET)
+ if (NetTimeOffset) {
+ sprintf (tmp, "%d", NetTimeOffset);
+ setenv ("timeoffset", tmp);
+ }
+#endif
+#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NTPSERVER)
+ if (NetNtpServerIP) {
+ ip_to_string (NetNtpServerIP, tmp);
+ setenv ("ntpserverip", tmp);
+ }
+#endif
}
static int
@@ -279,4 +292,42 @@ U_BOOT_CMD(
);
#endif /* CFG_CMD_CDP */
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ char *toff;
+
+ if (argc < 2) {
+ NetNtpServerIP = getenv_IPaddr ("ntpserverip");
+ if (NetNtpServerIP == 0) {
+ printf ("ntpserverip not set\n");
+ return (1);
+ }
+ } else {
+ NetNtpServerIP = string_to_ip(argv[1]);
+ if (NetNtpServerIP == 0) {
+ printf ("Bad NTP server IP address\n");
+ return (1);
+ }
+ }
+
+ toff = getenv ("timeoffset");
+ if (toff == NULL) NetTimeOffset = 0;
+ else NetTimeOffset = simple_strtol (toff, NULL, 10);
+
+ if (NetLoop(SNTP) < 0) {
+ printf("SNTP failed: host %s not responding\n", argv[1]);
+ return 1;
+ }
+
+ return 0;
+}
+
+U_BOOT_CMD(
+ sntp, 2, 1, do_sntp,
+ "sntp\t- synchronize RTC via network\n",
+ "[NTP server IP]\n"
+);
+#endif /* CFG_CMD_SNTP */
+
#endif /* CFG_CMD_NET */