summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTom Wai-Hong Tam <waihong@chromium.org>2011-07-21 14:54:04 +0800
committerSimon Glass <sjg@chromium.org>2011-08-29 10:59:06 -0700
commitdc6e35ef762466861ed50b3caf6138150bd9a4f3 (patch)
tree3cd110b6496e8b5d2974ef0f1af58521b61c3027 /lib
parentc64570aa9d553db32666f9caa7b065211e663ae9 (diff)
CHROMIUM: Add memory wipe library and its test.
The old code is copied from the old recovery firmware implementation: http://gerrit.chromium.org/gerrit/gitweb?p=chromiumos/third_party/u-boot.git;a=blob;f=common/cmd_cros_rec.c;h=4188ec98d136129e45d9d6c7664f861b279185f8;hb=refs/heads/chromeos-v2010.09 BUG=chromium-os:17950 TEST=run "vboot_test memwipe" success. Tegra2 # vboot_test memwipe memory_wipe: clear memory regions: memory_wipe: [0x3f760c5c, 0x3f760c5d) memory_wipe: [0x3f760c64, 0x3f760c65) Memory wipe test SUCCESS! Change-Id: Ieb587dbe001f91a58add6bcd3a1bc505e4227bda Reviewed-on: http://gerrit.chromium.org/gerrit/4478 Tested-by: Tom Wai-Hong Tam <waihong@chromium.org> Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/chromeos/Makefile3
-rw-r--r--lib/chromeos/memory_wipe.c68
2 files changed, 70 insertions, 1 deletions
diff --git a/lib/chromeos/Makefile b/lib/chromeos/Makefile
index 0056259c2f..a004bfba6d 100644
--- a/lib/chromeos/Makefile
+++ b/lib/chromeos/Makefile
@@ -16,8 +16,9 @@ COBJS-$(CONFIG_CHROMEOS) += cmdline_updater.o
COBJS-$(CONFIG_CHROMEOS) += crossystem_data.o
COBJS-$(CONFIG_CHROMEOS) += fdt_decode.o
COBJS-$(CONFIG_CHROMEOS) += firmware_storage_spi.o
-COBJS-$(CONFIG_CHROMEOS) += preboot_fdt_update.o
COBJS-$(CONFIG_CHROMEOS) += gbb_bmpblk.o
+COBJS-$(CONFIG_CHROMEOS) += memory_wipe.o
+COBJS-$(CONFIG_CHROMEOS) += preboot_fdt_update.o
# TODO(sjg): This MMC code is not needed as yet, and needs slight changes
# to build now
diff --git a/lib/chromeos/memory_wipe.c b/lib/chromeos/memory_wipe.c
new file mode 100644
index 0000000000..59ea0ef145
--- /dev/null
+++ b/lib/chromeos/memory_wipe.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ */
+
+#include <common.h>
+#include <chromeos/common.h>
+#include <chromeos/memory_wipe.h>
+
+#include <vboot_api.h>
+
+#define PREFIX "memory_wipe: "
+
+void memory_wipe_init(memory_wipe_t *wipe, uintptr_t start, uintptr_t end)
+{
+ wipe->whole.start = start;
+ wipe->whole.end = end;
+ wipe->excluded_count = 0;
+}
+
+int memory_wipe_exclude(memory_wipe_t *wipe, uintptr_t start, uintptr_t end)
+{
+ int i = wipe->excluded_count;
+
+ if (i >= MAX_EXCLUDED_REGIONS) {
+ VBDEBUG(PREFIX "the number of excluded regions reaches"
+ "the maximum: %d\n", MAX_EXCLUDED_REGIONS);
+ return -1;
+ }
+
+ while (i > 0 && wipe->excluded[i - 1].start > start) {
+ wipe->excluded[i].start = wipe->excluded[i - 1].start;
+ wipe->excluded[i].end = wipe->excluded[i - 1].end;
+ i--;
+ }
+ wipe->excluded[i].start = start;
+ wipe->excluded[i].end = end;
+ wipe->excluded_count++;
+
+ return 0;
+}
+
+static void zero_mem(uintptr_t start, uintptr_t end)
+{
+ if (end > start) {
+ VBDEBUG(PREFIX "\t[0x%08x, 0x%08x)\n", start, end);
+ memset((void *)start, '\0', (size_t)(end - start));
+ }
+}
+
+void memory_wipe_execute(memory_wipe_t *wipe)
+{
+ uintptr_t addr = wipe->whole.start;
+ int i;
+
+ VBDEBUG(PREFIX "Wipe memory regions:\n");
+ for (i = 0; i < wipe->excluded_count; i++) {
+ zero_mem(addr, wipe->excluded[i].start);
+ if (wipe->excluded[i].end > addr)
+ addr = wipe->excluded[i].end;
+ }
+ zero_mem(addr, wipe->whole.end);
+}