Re: Linux 2.4.20 RTC Timer bug

From: Richard B. Johnson (root@chaos.analogic.com)
Date: Fri Jul 18 2003 - 07:39:29 EST


On Fri, 18 Jul 2003, Willy Tarreau wrote:

> On Thu, Jul 17, 2003 at 04:38:05PM -0400, Richard B. Johnson wrote:
>
[SNIPPED...]

> > Or leaves the index register somewhere that a power-fail sequence will
> > trash a checksummed register..
>
> yes, that's possible too.
>
>
>
> is it in the spec that it has to be set to 0xFF or because you chose this
> value since it's out of the checksummed area ? On older chips, it will be
> equal to 0x3F (0xBF if we include NMI) and on newer ones, 0x7F. If the BIOS
> uses these bytes to write the checksum of the advanced setup, it might be
> dangerous. I would personaly prefer to set it to something not checked, such
> as the alarm, status, or so (except if the chip does a special case of FF).

Well, yes. It probably should be left at status register 'D'. Here's
a patch. Let's see if the Linux folks accept it....

Problem:
Power failure can cause CMOS checksum corruption and failure to boot.
Patch (tested -- running now):

--- linux-2.4.20/include/asm-i386/mc146818rtc.h.orig Thu Jul 17 15:06:33 2003
+++ linux-2.4.20/include/asm-i386/mc146818rtc.h Fri Jul 18 08:01:58 2003
@@ -10,18 +10,28 @@
 #define RTC_PORT(x) (0x70 + (x))
 #define RTC_ALWAYS_BCD 1 /* RTC operates in binary mode */
 #endif
+#define RTC_FAILSAFE 0x0d
+#define NMI_ENABLE 0x80

 /*
  * The yet supported machines all access the RTC index register via
  * an ISA port access but the way to access the date register differs ...
+ * Modified 18-JUL-2003
+ * Willy Tarreau <willy@w.ods.org>, Richard Johnson <rjohnson@analogic.com>
+ * Leave index register at status register D so a power failure doesn't
+ * corrupt checksummed CMOS. Keep NMI bit enabled (in case it really exists).
  */
 #define CMOS_READ(addr) ({ \
-outb_p((addr),RTC_PORT(0)); \
-inb_p(RTC_PORT(1)); \
+int __val; \
+outb_p((addr)|NMI_ENABLE,RTC_PORT(0)); \
+__val = inb_p(RTC_PORT(1)); \
+outb_p(RTC_FAILSAFE|NMI_ENABLE, RTC_PORT(0)); \
+__val; \
 })
 #define CMOS_WRITE(val, addr) ({ \
-outb_p((addr),RTC_PORT(0)); \
+outb_p((addr)|NMI_ENABLE,RTC_PORT(0)); \
 outb_p((val),RTC_PORT(1)); \
+outb_p(RTC_FAILSAFE|NMI_ENABLE, RTC_PORT(0)); \
 })

 #define RTC_IRQ 8

Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips).
            Note 96.31% of all statistics are fiction.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Jul 23 2003 - 22:00:33 EST