Add nvramtool -C option that takes a CBFS file as argument.
When using this option, nvramtool looks for a cmos_layout.bin
and cmos.default in the image and uses these for layout information
and CMOS data.

Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com>
Acked-by: Stefan Reinauer <stepan@coreboot.org>


git-svn-id: svn://svn.coreboot.org/coreboot/trunk@6285 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
diff --git a/util/nvramtool/nvramtool.c b/util/nvramtool/nvramtool.c
index e82d0ac..6ad5d2f 100644
--- a/util/nvramtool/nvramtool.c
+++ b/util/nvramtool/nvramtool.c
@@ -38,6 +38,7 @@
 #include "cmos_lowlevel.h"
 #include "reg_expr.h"
 #include "hexdump.h"
+#include "cbfs.h"
 
 typedef void (*op_fn_t) (void);
 
@@ -92,7 +93,7 @@
  ****************************************************************************/
 int main(int argc, char *argv[])
 {
-	cmos_layout_get_fn_t fn;
+	cmos_layout_get_fn_t fn = get_layout_from_cmos_table;
 
 	parse_nvramtool_args(argc, argv);
 
@@ -100,8 +101,18 @@
 		set_layout_filename(nvramtool_op_modifiers
 				    [NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].param);
 		fn = get_layout_from_file;
-	} else
+	} else if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found) {
 		fn = get_layout_from_cmos_table;
+	} else if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CBFS_FILE].found) {
+		open_cbfs(nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CBFS_FILE].param);
+		void *cmosdefault = cbfs_find_file("cmos.default", CBFS_COMPONENT_CMOS_DEFAULT, NULL);
+		if (cmosdefault == NULL) {
+			printf("Need a cmos.default in the CBFS image for now.\n");
+			exit(1);
+		}
+		select_hal(HAL_MEMORY, cmosdefault);
+		fn = get_layout_from_cbfs_file;
+	}
 
 	register_cmos_layout_get_fn(fn);
 	op_fns[nvramtool_op.op] ();