60

Basically this is my problem/

I have 200+ phones running stock Android that need to be wiped (in the Wipe Data/Factory Reset way) and then a new ROM installed with some additional apks.

Currently I've got everything automated except the Wipe Data part. Everything else can be done through a .bat with a set of commands quite happily but I cannot for the life of me work out how to either imitate or force the recovery mode to wipe the data.

Things I've currently tried:

  • Wiping the data myself using rm -r * on the folders it's supposed to do (data,cache,sd-ext etc.). This does wipe but then the ROM doesn't work properly and gets stuck in a bootloop.
  • Trying to use "adb input keyevent" to mimic the key presses. I have no idea what they are mapped to because they are in a UNIX shell basically and even then there is no "input" because the OS hasn't been loaded anyway.
  • Trying to find the file/script on the system that actually runs the wipe/reset and then running that manually. This might be the simplest way as it's already been written for me somewhere but I just cannot see where it is hidden, even in something like CWM.

If anyone has got any method whereby I could do this factory reset through a .bat or through the adb shell I would greatly appreciate it. Been trying to solve this for about 2 days now with little progress.

deadwards
  • 2,109
  • 1
  • 16
  • 27

1 Answers1

63

After a lot of digging around I finally ended up downloading the source code of the recovery section of Android. Turns out you can actually send commands to the recovery.

 * The arguments which may be supplied in the recovery.command file:
 *   --send_intent=anystring - write the text out to recovery.intent
 *   --update_package=path - verify install an OTA package file
 *   --wipe_data - erase user data (and cache), then reboot
 *   --wipe_cache - wipe cache (but not user data), then reboot
 *   --set_encrypted_filesystem=on|off - enables / diasables encrypted fs

Those are the commands you can use according to the one I found but that might be different for modded files. So using adb you can do this:

adb shell
recovery --wipe_data

Using --wipe_data seemed to do what I was looking for which was handy although I have not fully tested this as of yet.

EDIT:

For anyone still using this topic, these commands may change based on which recovery you are using. If you are using Clockword recovery, these commands should still work. You can find other commands in /cache/recovery/command

For more information please see here: https://github.com/CyanogenMod/android_bootable_recovery/blob/cm-10.2/recovery.c

deadwards
  • 2,109
  • 1
  • 16
  • 27
  • 6
    Just FYI - My personal phone , Samsung Galaxy S2 I9100 (I'm a developer, but not on android) has stopped responding after trying to use ROM Manager to make a backup. I could not even boot to recovery nor download mode. After searching the internet, I tried to use Odin, but it didn't recognize the phone. ADB did, and then I found this post. After using this command, my phone finally responds! Thanks a lot, even if you didn't mean it. I hope that others will be able to find your post via my commend. – H.Wolper Sep 10 '12 at 18:35
  • 7
    *recovery: not found* Android Debug Bridge version 1.0.31 | Droid 2 Global | CyanogenMod 7.2 – earthmeLon Mar 09 '13 at 16:38
  • 5
    Try the `wipe` command instead. You have to be root to wipe data though (`adb shell, su` or `adb root`) but if you can't get root, this won't work. – Artem Russakovskii Aug 18 '13 at 06:24
  • 2
    @daniel u may have experienced that "recovery --wipe_data" end up in "segmentation fault" – kmonsoor Nov 27 '13 at 05:20
  • 11
    I found out that we have to use another command on Android 4.3: `adb shell wipe data`. If mobile screen is broken and phone is functional you can login to the phone via "adb shell". – kirsche40 Jan 31 '14 at 12:48
  • Unfortunately this requires ADB debugging be enabled before the screen gets cracked or dies. – cde Jun 20 '15 at 20:29
  • this didn't reset the Internal Storage for me – netimen Mar 30 '16 at 08:50
  • The file mentioned in the CyanogenMod repository is ultimately from the Google Android sources. Here is a more recent version from Google: https://android.googlesource.com/platform/bootable/recovery/+/lollipop-release/recovery.cpp – ThomasW Sep 23 '16 at 02:49
  • For my ROM, nothing here worked. But I found this: `wipedata`. – phrogg Jul 05 '19 at 16:18