From 19447c05506e4dfd19f621081770fe03e29d0457 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Wed, 10 Nov 2010 10:40:44 -0800 Subject: Refactor recovery's block device handling to work across variant hardware in a cleaner fashion. Re add firmware update Change-Id: I699ad22390ed14e597d17a7bcb32ad1b1af00b4b support mmc misc Change-Id: Iff02f8d03db6835f501d052140cebeefee521305 fix compile errors Change-Id: I032edbd157a8a15f561bb83330c715ebaa008d18 fix compile errors Change-Id: Idff3449be3376f22fceefc2c35637527f8df8f3f Initial work to clean up the block devices. Change-Id: I4be20ac124864a281be9cd116e211a2618404a27 all done Change-Id: I0338f62f6a045556ebe90b0200685be113178319 fix up nandroid Change-Id: I886f00271183e6d2921c080b0939341f2cf12a4d --- flashutils/erase_image.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 flashutils/erase_image.c (limited to 'flashutils/erase_image.c') diff --git a/flashutils/erase_image.c b/flashutils/erase_image.c new file mode 100644 index 0000000..c495255 --- /dev/null +++ b/flashutils/erase_image.c @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * Portions Copyright (C) 2010 Magnus Eriksson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "cutils/log.h" +#include "flashutils.h" + +#if 0 + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + + +#define LOG_TAG "erase_image" + +static int die(const char *msg, ...) { + int err = errno; + va_list args; + va_start(args, msg); + char buf[1024]; + vsnprintf(buf, sizeof(buf), msg, args); + va_end(args); + + if (err != 0) { + strlcat(buf, ": ", sizeof(buf)); + strlcat(buf, strerror(err), sizeof(buf)); + } + + fprintf(stderr, "%s\n", buf); + LOGE("%s\n", buf); + return 3; +} + + +int erase_image(char* partition_name) { + MtdWriteContext *out; + size_t erased; + size_t total_size; + size_t erase_size; + + if (mtd_scan_partitions() <= 0) die("error scanning partitions"); + const MtdPartition *partition = mtd_find_partition_by_name(partition_name); + if (partition == NULL) return die("can't find %s partition", partition_name); + + out = mtd_write_partition(partition); + if (out == NULL) return die("could not estabilish write context for %s", partition_name); + + // do the actual erase, -1 = full partition erase + erased = mtd_erase_blocks(out, -1); + + // erased = bytes erased, if zero, something borked + if (!erased) return die("error erasing %s", partition_name); + + return 0; +} + + +/* Erase a mtd partition */ + +int main(int argc, char **argv) { + if (argc != 2) { + fprintf(stderr, "usage: %s \n", argv[0]); + return 2; + } + + return erase_image(argv[1]); +} + +#endif + + +int main(int argc, char **argv) +{ + if (argc != 2) { + fprintf(stderr, "usage: %s partition\n", argv[0]); + return 2; + } + + return erase_raw_partition(argv[1]); +} -- cgit v1.1