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>
29
auto int hook (struct grub_ieee1275_devalias *alias);
30
int hook (struct grub_ieee1275_devalias *alias)
32
if (grub_strcmp (alias->type, "rtc") == 0)
34
grub_dprintf ("datetime", "Found RTC %s\n", alias->path);
35
rtc = grub_strdup (alias->path);
41
grub_ieee1275_devices_iterate (hook);
45
grub_get_datetime (struct grub_datetime *datetime)
49
struct grub_ieee1275_common_hdr common;
50
grub_ieee1275_cell_t method;
51
grub_ieee1275_cell_t device;
52
grub_ieee1275_cell_t catch_result;
53
grub_ieee1275_cell_t year;
54
grub_ieee1275_cell_t month;
55
grub_ieee1275_cell_t day;
56
grub_ieee1275_cell_t hour;
57
grub_ieee1275_cell_t minute;
58
grub_ieee1275_cell_t second;
62
grub_ieee1275_ihandle_t ihandle;
67
return grub_error (GRUB_ERR_IO, "no RTC found");
69
status = grub_ieee1275_open (rtc, &ihandle);
71
return grub_error (GRUB_ERR_IO, "couldn't open RTC");
73
INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 7);
74
args.device = (grub_ieee1275_cell_t) ihandle;
75
args.method = (grub_ieee1275_cell_t) "get-time";
77
status = IEEE1275_CALL_ENTRY_FN (&args);
79
grub_ieee1275_close (ihandle);
82
return grub_error (GRUB_ERR_IO, "get-time failed");
84
datetime->year = args.year;
85
datetime->month = args.month;
86
datetime->day = args.day;
87
datetime->hour = args.hour;
88
datetime->minute = args.minute;
89
datetime->second = args.second;
95
grub_set_datetime (struct grub_datetime *datetime)
99
struct grub_ieee1275_common_hdr common;
100
grub_ieee1275_cell_t method;
101
grub_ieee1275_cell_t device;
102
grub_ieee1275_cell_t year;
103
grub_ieee1275_cell_t month;
104
grub_ieee1275_cell_t day;
105
grub_ieee1275_cell_t hour;
106
grub_ieee1275_cell_t minute;
107
grub_ieee1275_cell_t second;
108
grub_ieee1275_cell_t catch_result;
112
grub_ieee1275_ihandle_t ihandle;
117
return grub_error (GRUB_ERR_IO, "no RTC found");
119
status = grub_ieee1275_open (rtc, &ihandle);
121
return grub_error (GRUB_ERR_IO, "couldn't open RTC");
123
INIT_IEEE1275_COMMON (&args.common, "call-method", 8, 1);
124
args.device = (grub_ieee1275_cell_t) ihandle;
125
args.method = (grub_ieee1275_cell_t) "set-time";
127
args.year = datetime->year;
128
args.month = datetime->month;
129
args.day = datetime->day;
130
args.hour = datetime->hour;
131
args.minute = datetime->minute;
132
args.second = datetime->second;
134
status = IEEE1275_CALL_ENTRY_FN (&args);
136
grub_ieee1275_close (ihandle);
139
return grub_error (GRUB_ERR_IO, "set-time failed");
141
return GRUB_ERR_NONE;