aboutsummaryrefslogtreecommitdiffstats
path: root/flashutils/erase_image.c
diff options
context:
space:
mode:
authorKoushik Dutta <koushd@gmail.com>2010-11-10 10:40:44 -0800
committerKoushik Dutta <koushd@gmail.com>2010-11-10 23:31:34 -0800
commit19447c05506e4dfd19f621081770fe03e29d0457 (patch)
tree301e637311e817165d030878adb102f32b28ab14 /flashutils/erase_image.c
parentfef77c02533ee2e62c6827af5ba3cfcc2bd0e749 (diff)
downloadbootable_recovery-19447c05506e4dfd19f621081770fe03e29d0457.zip
bootable_recovery-19447c05506e4dfd19f621081770fe03e29d0457.tar.gz
bootable_recovery-19447c05506e4dfd19f621081770fe03e29d0457.tar.bz2
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
Diffstat (limited to 'flashutils/erase_image.c')
-rw-r--r--flashutils/erase_image.c103
1 files changed, 103 insertions, 0 deletions
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 <packetlss@gmail.com>
+ *
+ * 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 <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <fcntl.h>
+
+#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 <partition>\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]);
+}