Vboot: Exclude kcrashmem from vboot's memory wipe

Exclude kcrashmem from vboot unused memory wipe to allow for recovery of
kernel crash dumps. If the kcrashmem size changes, then the corresponding
fdt must be updated.

BUG=chrome-os-partner:5168
TEST=Manually observed kcrash preserved

Signed-off-by: Katie Roberts-Hoffman <katierh@chromium.org>

Change-Id: Iecb2bd7f7df958125ed3cb3bf0b789602e314e7c
Reviewed-on: http://gerrit.chromium.org/gerrit/8942
Reviewed-by: Simon Glass <sjg@chromium.org>
Commit-Ready: Katie Roberts-Hoffman <katierh@chromium.org>
Tested-by: Katie Roberts-Hoffman <katierh@chromium.org>
diff --git a/board/nvidia/seaboard/tegra2-kaen.dts b/board/nvidia/seaboard/tegra2-kaen.dts
index 4d7f64b..b3c7fe7 100644
--- a/board/nvidia/seaboard/tegra2-kaen.dts
+++ b/board/nvidia/seaboard/tegra2-kaen.dts
@@ -47,6 +47,10 @@
 		reg = <0x00000000 0x40000000>;
 	};
 
+	ramoops@2000000 {
+		reg = <0x02000000 0x02100000>;
+	};
+
 	serial@70006040 {
 		status = "ok";
 		clock-frequency = <216000000>;
diff --git a/common/cmd_vboot_twostop.c b/common/cmd_vboot_twostop.c
index 55088d1..c72cac6 100644
--- a/common/cmd_vboot_twostop.c
+++ b/common/cmd_vboot_twostop.c
@@ -162,13 +162,19 @@
 	crossystem_data_t *cdata, VbCommonParams *cparams)
 {
 	int fb_size, lcd_line_length;
-	struct fdt_memory config;
+	struct fdt_memory config, ramoops;
 
-	if (fdt_decode_memory(gd->blob, &config))
+	if (fdt_decode_memory(gd->blob, "/memory", &config))
 		VbExError(PREFIX "FDT decode memory section error\n");
 
 	memory_wipe_add(wipe, config.start, config.end);
 
+	/* Excludes kcrashmem if in FDT */
+	if (fdt_decode_memory(gd->blob, "/ramoops", &ramoops))
+		VBDEBUG(PREFIX "RAMOOPS not contained within FDT\n");
+	else
+		memory_wipe_sub(wipe, ramoops.start, ramoops.end);
+
 	/* Excludes the LP0 vector. */
 	memory_wipe_sub(wipe,
 			(uintptr_t)TEGRA_LP0_ADDR,
diff --git a/common/fdt_decode.c b/common/fdt_decode.c
index e204368..c969033 100644
--- a/common/fdt_decode.c
+++ b/common/fdt_decode.c
@@ -355,12 +355,13 @@
 }
 #endif
 
-int fdt_decode_memory(const void *blob, struct fdt_memory *config)
+int fdt_decode_memory(const void *blob, const char *name,
+		      struct fdt_memory *config)
 {
 	int node, len;
 	const addr_t *cell;
 
-	node = fdt_path_offset(blob, "/memory");
+	node = fdt_path_offset(blob, name);
 	if (node < 0)
 		return node;
 
diff --git a/include/fdt_decode.h b/include/fdt_decode.h
index d044aff..4fb2afe 100644
--- a/include/fdt_decode.h
+++ b/include/fdt_decode.h
@@ -261,12 +261,14 @@
 };
 
 /**
- * Returns information from the FDT about the memory.
+ * Returns information from the FDT about memory for a given root
  *
  * @param blob          FDT blob to use
+ * @param name          Root name of alias to search for
  * @param config        structure to use to return information
  */
-int fdt_decode_memory(const void *blob, struct fdt_memory *config);
+int fdt_decode_memory(const void *blob, const char *name,
+		      struct fdt_memory *config);
 
 /**
  * Return information from the FDT about the console UART. This looks for