summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndres Morales <anmorales@google.com>2014-08-06 19:41:05 +0200
committerAndroid Git Automerger <android-git-automerger@android.com>2014-08-06 19:41:05 +0200
commitf38d6e5a3610075fdc57d1cc88287aae3dd47d00 (patch)
tree1d60fc74a6983fe4a1ef3f60e2d039857a18c2a1
parentam 2b5f0e0f: remove spurious parens from error message (diff)
parentMerge "Erase PST partition if its marked to be erased." into lmp-dev (diff)
downloadandroid_bootable_recovery-f38d6e5a3610075fdc57d1cc88287aae3dd47d00.tar
android_bootable_recovery-f38d6e5a3610075fdc57d1cc88287aae3dd47d00.tar.gz
android_bootable_recovery-f38d6e5a3610075fdc57d1cc88287aae3dd47d00.tar.bz2
android_bootable_recovery-f38d6e5a3610075fdc57d1cc88287aae3dd47d00.tar.lz
android_bootable_recovery-f38d6e5a3610075fdc57d1cc88287aae3dd47d00.tar.xz
android_bootable_recovery-f38d6e5a3610075fdc57d1cc88287aae3dd47d00.tar.zst
android_bootable_recovery-f38d6e5a3610075fdc57d1cc88287aae3dd47d00.zip
Diffstat (limited to '')
-rw-r--r--recovery.cpp2
-rw-r--r--roots.cpp37
-rw-r--r--roots.h5
3 files changed, 44 insertions, 0 deletions
diff --git a/recovery.cpp b/recovery.cpp
index d2d85e7c7..f78d6e46c 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -659,6 +659,7 @@ wipe_data(int confirm, Device* device) {
device->WipeData();
erase_volume("/data");
erase_volume("/cache");
+ erase_persistent_partition();
ui->Print("Data wipe complete.\n");
}
@@ -959,6 +960,7 @@ main(int argc, char **argv) {
if (device->WipeData()) status = INSTALL_ERROR;
if (erase_volume("/data")) status = INSTALL_ERROR;
if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
+ if (erase_persistent_partition() == -1 ) status = INSTALL_ERROR;
if (status != INSTALL_SUCCESS) ui->Print("Data wipe failed.\n");
} else if (wipe_cache) {
if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
diff --git a/roots.cpp b/roots.cpp
index ee140160c..0d47577b2 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -39,6 +39,8 @@ static struct fstab *fstab = NULL;
extern struct selabel_handle *sehandle;
+static const char* PERSISTENT_PATH = "/persistent";
+
void load_volume_table()
{
int i;
@@ -264,6 +266,41 @@ int format_volume(const char* volume) {
return -1;
}
+int erase_persistent_partition() {
+ Volume *v = volume_for_path(PERSISTENT_PATH);
+ if (v == NULL) {
+ // most devices won't have /persistent, so this is not an error.
+ return 0;
+ }
+
+ int fd = open(v->blk_device, O_RDWR);
+ uint64_t size = get_file_size(fd);
+ if (size == 0) {
+ LOGE("failed to stat size of /persistent\n");
+ close(fd);
+ return -1;
+ }
+
+ char oem_unlock_enabled;
+ lseek(fd, size - 1, SEEK_SET);
+ read(fd, &oem_unlock_enabled, 1);
+
+ if (oem_unlock_enabled) {
+ if (wipe_block_device(fd, size)) {
+ LOGE("error wiping /persistent: %s\n", strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ lseek(fd, size - 1, SEEK_SET);
+ write(fd, &oem_unlock_enabled, 1);
+ }
+
+ close(fd);
+
+ return (int) oem_unlock_enabled;
+}
+
int setup_install_mounts() {
if (fstab == NULL) {
LOGE("can't set up install mounts: no fstab loaded\n");
diff --git a/roots.h b/roots.h
index 230d9ded3..b62a5b13a 100644
--- a/roots.h
+++ b/roots.h
@@ -46,6 +46,11 @@ int format_volume(const char* volume);
// mounted (/tmp and /cache) are mounted. Returns 0 on success.
int setup_install_mounts();
+// Conditionally wipes the /persistent partition if it's marked
+// to wipe. Returns -1 on failure, 1 if the partition was wiped
+// and 0 if the partition was not wiped.
+int erase_persistent_partition();
+
#ifdef __cplusplus
}
#endif