Commit 7e0af5d09729c13900e3e7933ec2071a3646017a
1 parent
2331d91e
added -startdate option
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3540 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
4 changed files
with
54 additions
and
4 deletions
hw/mc146818rtc.c
... | ... | @@ -393,11 +393,16 @@ void rtc_set_date_from_host(RTCState *s) |
393 | 393 | int val; |
394 | 394 | |
395 | 395 | /* set the CMOS date */ |
396 | - time(&ti); | |
397 | - if (rtc_utc) | |
396 | + if (rtc_start_date == -1) { | |
397 | + time(&ti); | |
398 | + if (rtc_utc) | |
399 | + tm = gmtime(&ti); | |
400 | + else | |
401 | + tm = localtime(&ti); | |
402 | + } else { | |
403 | + ti = rtc_start_date; | |
398 | 404 | tm = gmtime(&ti); |
399 | - else | |
400 | - tm = localtime(&ti); | |
405 | + } | |
401 | 406 | rtc_set_date(s, tm); |
402 | 407 | |
403 | 408 | val = to_bcd(s, (tm->tm_year / 100) + 19); | ... | ... |
qemu-doc.texi
... | ... | @@ -268,6 +268,11 @@ Set the real time clock to local time (the default is to UTC |
268 | 268 | time). This option is needed to have correct date in MS-DOS or |
269 | 269 | Windows. |
270 | 270 | |
271 | +@item -startdate date | |
272 | +Set the initial date of the real time clock. Valid format for | |
273 | +@var{date} are: @code{now} or @code{2006-06-17T16:01:21} or | |
274 | +@code{2006-06-17}. The default value is @code{now}. | |
275 | + | |
271 | 276 | @item -pidfile file |
272 | 277 | Store the QEMU process PID in @var{file}. It is useful if you launch QEMU |
273 | 278 | from a script. | ... | ... |
vl.c
... | ... | @@ -174,6 +174,7 @@ int nb_nics; |
174 | 174 | NICInfo nd_table[MAX_NICS]; |
175 | 175 | int vm_running; |
176 | 176 | int rtc_utc = 1; |
177 | +int rtc_start_date = -1; /* -1 means now */ | |
177 | 178 | int cirrus_vga_enabled = 1; |
178 | 179 | int vmsvga_enabled = 0; |
179 | 180 | #ifdef TARGET_SPARC |
... | ... | @@ -7212,6 +7213,7 @@ enum { |
7212 | 7213 | QEMU_OPTION_prom_env, |
7213 | 7214 | QEMU_OPTION_old_param, |
7214 | 7215 | QEMU_OPTION_clock, |
7216 | + QEMU_OPTION_startdate, | |
7215 | 7217 | }; |
7216 | 7218 | |
7217 | 7219 | typedef struct QEMUOption { |
... | ... | @@ -7318,6 +7320,7 @@ const QEMUOption qemu_options[] = { |
7318 | 7320 | { "old-param", 0, QEMU_OPTION_old_param }, |
7319 | 7321 | #endif |
7320 | 7322 | { "clock", HAS_ARG, QEMU_OPTION_clock }, |
7323 | + { "startdate", HAS_ARG, QEMU_OPTION_startdate }, | |
7321 | 7324 | { NULL }, |
7322 | 7325 | }; |
7323 | 7326 | |
... | ... | @@ -8107,6 +8110,42 @@ int main(int argc, char **argv) |
8107 | 8110 | case QEMU_OPTION_clock: |
8108 | 8111 | configure_alarms(optarg); |
8109 | 8112 | break; |
8113 | + case QEMU_OPTION_startdate: | |
8114 | + { | |
8115 | + struct tm tm; | |
8116 | + if (!strcmp(optarg, "now")) { | |
8117 | + rtc_start_date = -1; | |
8118 | + } else { | |
8119 | + if (sscanf(optarg, "%d-%d-%dT%d:%d:%d", | |
8120 | + &tm.tm_year, | |
8121 | + &tm.tm_mon, | |
8122 | + &tm.tm_mday, | |
8123 | + &tm.tm_hour, | |
8124 | + &tm.tm_min, | |
8125 | + &tm.tm_sec) == 6) { | |
8126 | + /* OK */ | |
8127 | + } else if (sscanf(optarg, "%d-%d-%d", | |
8128 | + &tm.tm_year, | |
8129 | + &tm.tm_mon, | |
8130 | + &tm.tm_mday) == 3) { | |
8131 | + tm.tm_hour = 0; | |
8132 | + tm.tm_min = 0; | |
8133 | + tm.tm_sec = 0; | |
8134 | + } else { | |
8135 | + goto date_fail; | |
8136 | + } | |
8137 | + tm.tm_year -= 1900; | |
8138 | + tm.tm_mon--; | |
8139 | + rtc_start_date = timegm(&tm); | |
8140 | + if (rtc_start_date == -1) { | |
8141 | + date_fail: | |
8142 | + fprintf(stderr, "Invalid date format. Valid format are:\n" | |
8143 | + "'now' or '2006-06-17T16:01:21' or '2006-06-17'\n"); | |
8144 | + exit(1); | |
8145 | + } | |
8146 | + } | |
8147 | + } | |
8148 | + break; | |
8110 | 8149 | } |
8111 | 8150 | } |
8112 | 8151 | } | ... | ... |
vl.h