libpayload: Add get_option_from()
[coreboot.git] / payloads / libpayload / drivers / options.c
index 8eed78ef17d37572b11432d1ecbd7427ea42b5e5..fdb4be34bbc6d48b70e7a1da42a2bcc91b81e777 100644 (file)
@@ -48,6 +48,23 @@ static int options_checksum_valid(void)
        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;
@@ -55,8 +72,6 @@ static int get_cmos_value(u32 bitnum, u32 len, void *valptr)
        u32 addr, bit;
        u8 reg8;
 
-       value = valptr;
-
        /* Convert to byte borders */
        addr=(bitnum / 8);
        bit=(bitnum % 8);
@@ -78,14 +93,12 @@ static int get_cmos_value(u32 bitnum, u32 len, void *valptr)
        return 0;
 }
 
-int get_option(void *dest, char *name)
+int get_option_from(struct cb_cmos_option_table *option_table, void *dest, char *name)
 {
-       struct cb_cmos_option_table *option_table = phys_to_virt(lib_sysinfo.option_table);
        struct cb_cmos_entries *cmos_entry;
        int len = strnlen(name, CMOS_MAX_NAME_LENGTH);
-       
+
        /* cmos entries are located right after the option table */
-       cmos_entry=(struct cb_cmos_entries*)((unsigned char *)option_table + option_table->header_length);
 
        for (   cmos_entry = (struct cb_cmos_entries*)((unsigned char *)option_table + option_table->header_length);
                cmos_entry->tag == CB_TAG_OPTION;
@@ -104,3 +117,9 @@ int get_option(void *dest, char *name)
        printf("ERROR: No such CMOS option (%s)\n", name);
        return 1;
 }
+
+int get_option(void *dest, char *name)
+{
+       struct cb_cmos_option_table *option_table = phys_to_virt(lib_sysinfo.option_table);
+       return get_option_from(option_table, dest, name);
+}