From dc6e35ef762466861ed50b3caf6138150bd9a4f3 Mon Sep 17 00:00:00 2001 From: Tom Wai-Hong Tam Date: Thu, 21 Jul 2011 14:54:04 +0800 Subject: 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 Reviewed-by: Che-Liang Chiou --- lib/chromeos/Makefile | 3 +- lib/chromeos/memory_wipe.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 lib/chromeos/memory_wipe.c (limited to 'lib') diff --git a/lib/chromeos/Makefile b/lib/chromeos/Makefile index 0056259c2ff..a004bfba6dd 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 00000000000..59ea0ef145f --- /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 +#include +#include + +#include + +#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); +} -- cgit v1.2.3