Patchwork libpayload: fix cmos checksum.

login
register
about
Submitter Stefan Reinauer
Date 2010-06-03 22:46:25
Message ID <4C0830C1.8060902@coresystems.de>
Download mbox | patch
Permalink /patch/1456/
State Accepted
Headers show

Comments

Stefan Reinauer - 2010-06-03 22:46:25
See patch.
libpayload: Add function to fix CMOS checksum.

Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
Myles Watson - 2010-06-04 14:56:04
On Thu, Jun 3, 2010 at 4:46 PM, Stefan Reinauer <stepan@coresystems.de> wrote:
> See patch.

+	checksum = (~checksum)&0xffff;

A tiny bit of overkill since checksum is u16.

Acked-by: Myles Watson <mylesgw@gmail.com>

Thanks,
Myles

Patch

Index: include/libpayload.h
===================================================================
--- include/libpayload.h	(revision 5606)
+++ include/libpayload.h	(working copy)
@@ -190,6 +190,7 @@ 
 /** @} */
 
 /* drivers/option.c */
+void fix_options_checksum(void);
 int get_option(void *dest, char *name);
 
 /**
Index: drivers/options.c
===================================================================
--- drivers/options.c	(revision 5606)
+++ drivers/options.c	(working copy)
@@ -48,6 +48,23 @@ 
 	return (checksum_old == checksum);
 }
 
+void fix_options_checksum(void)
+{
+	int i;
+	int range_start = lib_sysinfo.cmos_range_start / 8;
+	int range_end = lib_sysinfo.cmos_range_end / 8;
+	int checksum_location = lib_sysinfo.cmos_checksum_location / 8;
+	u16 checksum = 0;
+
+	for(i = range_start; i <= range_end; i++) {
+		checksum += nvram_read(i);
+	}
+	checksum = (~checksum)&0xffff;
+
+	nvram_write((checksum >> 8), checksum_location);
+	nvram_write((checksum & 0xff), checksum_location + 1);
+}
+
 static int get_cmos_value(u32 bitnum, u32 len, void *valptr)
 {
 	u8 *value = (u8 *)valptr;