Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JQkum-0001tS-UF for mharc-grub-devel@gnu.org; Sun, 17 Feb 2008 09:54:48 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JQkum-0001t5-2D for grub-devel@gnu.org; Sun, 17 Feb 2008 09:54:48 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JQkul-0001sW-1I for grub-devel@gnu.org; Sun, 17 Feb 2008 09:54:47 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JQkuk-0001sT-O0 for grub-devel@gnu.org; Sun, 17 Feb 2008 09:54:46 -0500 Received: from bigbox.boeglin.org ([88.191.20.48]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JQkuk-0005o3-Az for grub-devel@gnu.org; Sun, 17 Feb 2008 09:54:46 -0500 Received: by bigbox.boeglin.org (Postfix, from userid 1000) id D63B39408A; Sun, 17 Feb 2008 15:55:14 +0100 (CET) Date: Sun, 17 Feb 2008 15:55:14 +0100 From: Alexandre Boeglin To: grub-devel@gnu.org Message-ID: <20080217145514.GA10562@boeglin.org> References: <20080217115240.GB8497@boeglin.org> <20080217121554.GD8497@boeglin.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="XsQoSWH+UP9D9v3l" Content-Disposition: inline In-Reply-To: <20080217121554.GD8497@boeglin.org> User-Agent: Mutt/1.5.17+20080114 (2008-01-14) Content-Transfer-Encoding: 7bit X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) Subject: Re: [PATCH] fix GRUB_TICKS_PER_SECOND in include/grub/efi/time.h X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Feb 2008 14:54:48 -0000 --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Le dim 17 f=E9v 2008 =E0 13:15:54 +0100, Alexandre Boeglin a =E9crit : > Ah, actually, it seems it's not good enough, as it still hangs on minut= e > leaps... This one seems to work (returning unix time), but I don't know if it's acceptable. Alex --XsQoSWH+UP9D9v3l Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="grub2_efitime.patch" Index: include/grub/efi/time.h =================================================================== RCS file: /sources/grub/grub2/include/grub/efi/time.h,v retrieving revision 1.2 diff -u -r1.2 time.h --- include/grub/efi/time.h 21 Jul 2007 23:32:23 -0000 1.2 +++ include/grub/efi/time.h 17 Feb 2008 14:52:00 -0000 @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +21,7 @@ #include -/* This is destined to overflow when one minute passes by. */ -#define GRUB_TICKS_PER_SECOND ((1UL << 31) / 60 / 60 * 2) +#define GRUB_TICKS_PER_SECOND 1 /* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void); Index: kern/efi/efi.c =================================================================== RCS file: /sources/grub/grub2/kern/efi/efi.c,v retrieving revision 1.10 diff -u -r1.10 efi.c --- kern/efi/efi.c 12 Feb 2008 23:47:07 -0000 1.10 +++ kern/efi/efi.c 17 Feb 2008 14:52:00 -0000 @@ -194,15 +194,46 @@ { grub_efi_time_t time; grub_efi_runtime_services_t *r; + grub_uint32_t rtc_time; + grub_uint16_t cur_year; r = grub_efi_system_table->runtime_services; if (r->get_time (&time, 0) != GRUB_EFI_SUCCESS) /* What is possible in this case? */ return 0; - return (((time.minute * 60 + time.second) * 1000 - + time.nanosecond / 1000000) - * GRUB_TICKS_PER_SECOND / 1000); + rtc_time = 0; + for (cur_year = time.year -1; cur_year >= 1970; cur_year--) + { + if (!(cur_year % 400) || ((cur_year % 100) && !(cur_year % 4))) + rtc_time += 366; + else + rtc_time += 365; + } + /* Months have 30 days by default. */ + rtc_time += (time.month - 1) * 30; + /* February has fewer days. */ + if (time.month > 2) + { + if (!(time.year % 400) || ((time.year % 100) && !(time.year % 4))) + rtc_time -= 1; + else + rtc_time -= 2; + } + /* Odd months have 31 days. */ + rtc_time += time.month / 2; + /* August also has 31 days. */ + if (time.month == 9 || time.month == 11) + rtc_time += 1; + rtc_time += (time.day - 1); + rtc_time *= 24; + rtc_time += time.hour; + rtc_time *= 60; + rtc_time += time.minute; + rtc_time *= 60; + rtc_time += time.second; + + return rtc_time; } /* Search the mods section from the PE32/PE32+ image. This code uses --XsQoSWH+UP9D9v3l--