]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_date.c
Some code cleanup for GCC 4.x
[karo-tx-uboot.git] / common / cmd_date.c
index 1472e3f1aa6a10c373eec6dd73b76f0b04f813a6..a569d78cadc3f911e9ebd4cf5714f3565d8b0736 100644 (file)
@@ -34,24 +34,27 @@ const char *weekdays[] = {
        "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur",
 };
 
+#define RELOC(a)       ((typeof(a))((unsigned long)(a) + gd->reloc_off))
+
 int mk_date (char *, struct rtc_time *);
 
 int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
+       DECLARE_GLOBAL_DATA_PTR;
        struct rtc_time tm;
        int rcode = 0;
 
        switch (argc) {
        case 2:                 /* set date & time */
                if (strcmp(argv[1],"reset") == 0) {
-                       printf ("Reset RTC...\n");
+                       puts ("Reset RTC...\n");
                        rtc_reset ();
                } else {
                        /* initialize tm with current time */
                        rtc_get (&tm);
                        /* insert new date & time */
                        if (mk_date (argv[1], &tm) != 0) {
-                               printf ("## Bad date format\n");
+                               puts ("## Bad date format\n");
                                return 1;
                        }
                        /* and write to RTC */
@@ -64,7 +67,7 @@ int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                printf ("Date: %4d-%02d-%02d (%sday)    Time: %2d:%02d:%02d\n",
                        tm.tm_year, tm.tm_mon, tm.tm_mday,
                        (tm.tm_wday<0 || tm.tm_wday>6) ?
-                               "unknown " : weekdays[tm.tm_wday],
+                               "unknown " : RELOC(weekdays[tm.tm_wday]),
                        tm.tm_hour, tm.tm_min, tm.tm_sec);
 
                return 0;
@@ -186,4 +189,15 @@ int mk_date (char *datestr, struct rtc_time *tmp)
        return (-1);
 }
 
+/***************************************************/
+
+U_BOOT_CMD(
+       date,   2,      1,      do_date,
+       "date    - get/set/reset date & time\n",
+       "[MMDDhhmm[[CC]YY][.ss]]\ndate reset\n"
+       "  - without arguments: print date & time\n"
+       "  - with numeric argument: set the system date & time\n"
+       "  - with 'reset' argument: reset the RTC\n"
+);
+
 #endif /* CFG_CMD_DATE */