+ return cmos_entry;
+ }
+
+ printf("ERROR: No such CMOS option (%s)\n", name);
+ return NULL;
+}
+
+struct cb_cmos_entries *first_cmos_entry(struct cb_cmos_option_table *option_table)
+{
+ return lookup_cmos_entry(option_table, "");
+}
+
+struct cb_cmos_entries *next_cmos_entry(struct cb_cmos_entries *cmos_entry)
+{
+ struct cb_cmos_entries *next = (struct cb_cmos_entries*)((unsigned char *)cmos_entry + cmos_entry->size);
+ if (next->tag == CB_TAG_OPTION)
+ return next;
+ else
+ return NULL;
+}
+
+/* Either value or text must be NULL. Returns the field that matches "the other" for a given config_id */
+static struct cb_cmos_enums *lookup_cmos_enum_core(struct cb_cmos_option_table *option_table, int config_id, u8 *value, char *text)
+{
+ struct cb_cmos_entries *cmos_entry;
+ int len = strnlen(text, CMOS_MAX_TEXT_LENGTH);
+
+ /* cmos entries are located right after the option table. Skip them */
+ cmos_entry = (struct cb_cmos_entries*)((unsigned char *)option_table + option_table->header_length);
+ while (cmos_entry->tag == CB_TAG_OPTION)
+ cmos_entry = (struct cb_cmos_entries*)((unsigned char *)cmos_entry + cmos_entry->size);
+
+ /* cmos enums are located after cmos entries. */
+ struct cb_cmos_enums *cmos_enum;
+ for ( cmos_enum = (struct cb_cmos_enums*)cmos_entry;
+ cmos_enum->tag == CB_TAG_OPTION_ENUM;
+ cmos_enum = (struct cb_cmos_enums*)((unsigned char *)cmos_enum + cmos_enum->size)) {
+ if ((cmos_enum->config_id == config_id)
+ && ((value == NULL) || (cmos_enum->value == *value))
+ && ((text == NULL) || (memcmp((const char*)cmos_enum->text, text, len)))) {
+ return cmos_enum;
+ }
+ }
+
+ return NULL;
+}
+
+static struct cb_cmos_enums *lookup_cmos_enum_by_value(struct cb_cmos_option_table *option_table, int config_id, u8 *value)
+{
+ return lookup_cmos_enum_core(option_table, config_id, value, NULL);
+}
+
+static struct cb_cmos_enums *lookup_cmos_enum_by_label(struct cb_cmos_option_table *option_table, int config_id, char *label)
+{
+ return lookup_cmos_enum_core(option_table, config_id, NULL, label);
+}
+
+int get_option_with(const struct nvram_accessor *nvram, struct cb_cmos_option_table *option_table, void *dest, char *name)
+{
+ struct cb_cmos_entries *cmos_entry = lookup_cmos_entry(option_table, name);
+ if (cmos_entry) {
+ if(get_cmos_value(nvram, cmos_entry->bit, cmos_entry->length, dest))