1 /* kern/cmos_datetime.c - CMOS datetime function.
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2008,2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/datetime.h>
21 #include <grub/ieee1275/ieee1275.h>
22 #include <grub/misc.h>
24 #if defined (__powerpc__) || defined (__sparc__)
25 #include <grub/cmos.h>
28 GRUB_MOD_LICENSE ("GPLv3+");
31 static int no_ieee1275_rtc
= 0;
33 /* Helper for find_rtc. */
35 find_rtc_iter (struct grub_ieee1275_devalias
*alias
)
37 if (grub_strcmp (alias
->type
, "rtc") == 0)
39 grub_dprintf ("datetime", "Found RTC %s\n", alias
->path
);
40 rtc
= grub_strdup (alias
->path
);
49 grub_ieee1275_devices_iterate (find_rtc_iter
);
55 grub_get_datetime (struct grub_datetime
*datetime
)
59 struct grub_ieee1275_common_hdr common
;
60 grub_ieee1275_cell_t method
;
61 grub_ieee1275_cell_t device
;
62 grub_ieee1275_cell_t catch_result
;
63 grub_ieee1275_cell_t year
;
64 grub_ieee1275_cell_t month
;
65 grub_ieee1275_cell_t day
;
66 grub_ieee1275_cell_t hour
;
67 grub_ieee1275_cell_t minute
;
68 grub_ieee1275_cell_t second
;
72 grub_ieee1275_ihandle_t ihandle
;
75 return grub_get_datetime_cmos (datetime
);
79 return grub_get_datetime_cmos (datetime
);
81 status
= grub_ieee1275_open (rtc
, &ihandle
);
83 return grub_error (GRUB_ERR_IO
, "couldn't open RTC");
85 INIT_IEEE1275_COMMON (&args
.common
, "call-method", 2, 7);
86 args
.device
= (grub_ieee1275_cell_t
) ihandle
;
87 args
.method
= (grub_ieee1275_cell_t
) "get-time";
89 status
= IEEE1275_CALL_ENTRY_FN (&args
);
91 grub_ieee1275_close (ihandle
);
93 if (status
== -1 || args
.catch_result
)
94 return grub_error (GRUB_ERR_IO
, "get-time failed");
96 datetime
->year
= args
.year
;
97 datetime
->month
= args
.month
;
98 datetime
->day
= args
.day
+ 1;
99 datetime
->hour
= args
.hour
;
100 datetime
->minute
= args
.minute
;
101 datetime
->second
= args
.second
;
103 return GRUB_ERR_NONE
;
107 grub_set_datetime (struct grub_datetime
*datetime
)
111 struct grub_ieee1275_common_hdr common
;
112 grub_ieee1275_cell_t method
;
113 grub_ieee1275_cell_t device
;
114 grub_ieee1275_cell_t year
;
115 grub_ieee1275_cell_t month
;
116 grub_ieee1275_cell_t day
;
117 grub_ieee1275_cell_t hour
;
118 grub_ieee1275_cell_t minute
;
119 grub_ieee1275_cell_t second
;
120 grub_ieee1275_cell_t catch_result
;
124 grub_ieee1275_ihandle_t ihandle
;
127 return grub_set_datetime_cmos (datetime
);
131 return grub_set_datetime_cmos (datetime
);
133 status
= grub_ieee1275_open (rtc
, &ihandle
);
135 return grub_error (GRUB_ERR_IO
, "couldn't open RTC");
137 INIT_IEEE1275_COMMON (&args
.common
, "call-method", 8, 1);
138 args
.device
= (grub_ieee1275_cell_t
) ihandle
;
139 args
.method
= (grub_ieee1275_cell_t
) "set-time";
141 args
.year
= datetime
->year
;
142 args
.month
= datetime
->month
;
143 args
.day
= datetime
->day
- 1;
144 args
.hour
= datetime
->hour
;
145 args
.minute
= datetime
->minute
;
146 args
.second
= datetime
->second
;
148 status
= IEEE1275_CALL_ENTRY_FN (&args
);
150 grub_ieee1275_close (ihandle
);
152 if (status
== -1 || args
.catch_result
)
153 return grub_error (GRUB_ERR_IO
, "set-time failed");
155 return GRUB_ERR_NONE
;