Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[ICS-JB][Samsung] Safe No Brick Wipe Data/System/Cache/Dalvik from recovery

OP Phil3759

23rd August 2012, 09:22 PM   |  #1  
Phil3759's Avatar
OP Recognized Developer
Thanks Meter: 32,033
 
9,397 posts
Join Date:Joined: May 2012
Donate to Me

<<< Built for the i9100 in mind, but fine on any Samsung phone >>>
<<< check your mount points before using this on another phone >>>
<<< Backup, Backaup and Backup your Data >>>
<<< Never use it on a non Samsung Phone >>>
<<< Read before flash, you are warned >>>



Update 08.10.2012:
Quote:

Following Entropy512 recommendations, I updated the binary-update to a safe one.
Now format commands are used in script instead of delete_recursive.
This makes the wipe much clean if some file system errors are present

Special thanks to shoey63 for his contribution


Since the superbrick bug story on 4.0.4 firmwares for the i9100 and the Note, wiping and factory reset became a tragedy for many.
many users in N7000 forum asked me for these scripts. Here are they!

shoey63 took my attention to a discussion by Entropy512, Elite Recognized Developer who contributed to a better knowledge of the superbrick bug.

I quote him here:

Quote:
Originally Posted by Entropy512

For a while, as there was little knowledge about the nature of the bug, it was suspected that deleting large files could be dangerous.

However, after further knowledge and research:
For ERASE commands to be caused by simple file deletion (a variation of "TRIM") - The filesystem must be mounted with the "discard" option. No ICS kernel/initramfs/firmware combo I've seen for our device, I9100, or I777 does this.

In theory, an app with superuser permissions could issue erase commands - but I am unaware of any apps that do this.

Quote:
Originally Posted by Entropy512

Root has zero effect despite her claim. When you are in recovery, the only thing that matters is the kernel initramfs - contents of /system do not matter. When you are in recovery, "root" is just another file in /system, indistinguishable from any other as far as wiping algorithms go. In fact, her claim that root voids your warranty is incorrect in many countries. For example, in the United States, her claim is in direct conflict with the Magnusson-Moss Warranty Act, which states that a manufacturer must prove that modifications were the cause of damage before denying warranty service. (This was passed decades ago due to lobbying efforts by SEMA, an association of vendors of aftermarket modifications for vehicles - but it applies to phones too.)

CWM, if wipe isn't suppressed, can be more dangerous than Samsung stock recovery - Samsung believes that only secure erase (done by default in Google-originated source code) is dangerous. However the experiences of Robotu and others have me convinced that while non-secure erase (done by stock recovery) is less dangerous, it is not 100% safe. Also note that even CWM's secure erase doesn't always cause damage - some I777 developers wiped multiple times using CWM on the UCLD3 leak without issues, and Gokhanmoral tested wiping with SiyahKernel 3.1rc6 on the I9100 multiple times without issue - but plenty of users suffered damage. One example of what appears to be damage due to wiping on stock ICS is at http://forum.xda-developers.com/show....php?t=1752468 - The Tab 7.7 gets to join the party now.



To sum it:

- wipe / factory reset from CWM is extremely risky on broken chipsets and vulnerable kernels
- wipe / factory reset in stock recovery is not without risks, even if probably less
- delete operations, even on big data packets is safe

So, here comes the idea: build some wipe scripts that can run in recovery (be it stock recovery or CWM) to complete the wipe operations using safe delete command to avoid brick risks on these affected phones

I attach these scripts to just run in recovery (will work in stock recovery)

Quote:

  • Samsung_Factory_Reset-signed.zip: will delete data and cache partitions
  • Samsung_Wipe_Cache-signed.zip: will delete cache partition
  • Samsung_Wipe_Dalvik-signed.zip: will delete dalvik-cache
  • Samsung_Wipe_Data_System_Cache-signed.zip: will delete the data, cache and system partition. After this one, phone will not boot, only recovery and download mode are accessible. You need to flash a full ROM in Odin after that

Here's the edify code used, for teach purpose (in v2.0, delete_recursive is now replaced by format commands)

Code:
ui_print("***************************");
ui_print("Wipe data-cache-system");
ui_print("Samsung Phones Only");
ui_print("***************************");
show_progress(1.000000, 0);

ui_print("Checking Samsung Phone...");
assert(getprop("ro.product.manufacturer") == "samsung");
set_progress(0.100000);

ui_print("Mounting partitions");
mount("ext4", "EMMC", "/dev/block/mmcblk0p9", "/system");
mount("ext4", "EMMC", "/dev/block/mmcblk0p7", "/cache");
mount("ext4", "EMMC", "/dev/block/mmcblk0p10", "/data");
set_progress(0.200000);

ui_print("Delete Cache Partition");
delete_recursive("/cache");
set_progress(0.400000);

ui_print("Delete Data Partition");
delete_recursive("/data");
set_progress(0.600000);

ui_print("Delete System Partition");
delete_recursive("/system");
set_progress(0.900000);

###############################################################################
############################ Formatting partitions ############################
#### You need to unmount (ALL?) partitions before formatting one partition ####
# unmount("/cache");
# unmount("/data");
# unmount("/system");
# format("ext4", "EMMC", "/dev/block/mmcblk0p9", "0");

#### Then remount if you intend to use it later in teh script ####
# mount("ext4", "EMMC", "/dev/block/mmcblk0p9", "/system");
# mount("ext4", "EMMC", "/dev/block/mmcblk0p7", "/cache");
# mount("ext4", "EMMC", "/dev/block/mmcblk0p10", "/data");

#### wipe dalvik-cache ####
# mount("ext4", "EMMC", "/dev/block/mmcblk0p10", "/data");
# delete_recursive("/data/dalvik-cache");
# unmount("/data");
#### wipe dalvik-cache done ####

#### Mount in busybox ####
# run_program("/sbin/mount", "/dev/block/mmcblk0p7", "/cache");
# run_program("/sbin/mount", "/dev/block/mmcblk0p10", "/data");
# run_program("/sbin/mount", "/dev/block/mmcblk0p9", "/system");
#### internal sd ####
# run_program("/sbin/mount", "/dev/block/mmcblk0p11", "/sdcard");
###############################################################################

ui_print("Unmounting Partitions");
unmount("/cache");
unmount("/data");
unmount("/system");
set_progress(1.000000);
show_progress(1.000000, 0);

ui_print("Wipe complete!");
ui_print("Reboot in download mode");
ui_print("Flash a full ROM in Odin");
ui_print("by Phil3759@xda-developers.com");
Last edited by Phil3759; 18th November 2012 at 02:04 PM.
The Following 51 Users Say Thank You to Phil3759 For This Useful Post: [ View ]
23rd August 2012, 10:01 PM   |  #2  
maddoguk's Avatar
Senior Member
Flag Devizes
Thanks Meter: 14
 
219 posts
Join Date:Joined: Sep 2009
More
Nice work.
The Following User Says Thank You to maddoguk For This Useful Post: [ View ]
23rd August 2012, 11:08 PM   |  #3  
Smoky's Avatar
Senior Member
Flag Rennes
Thanks Meter: 10
 
156 posts
Join Date:Joined: Sep 2007
More
Great job :thumbup:
So it will replace the wipe options in CWM.

Envoyé depuis mon GT-I9100 avec Tapatalk
24th August 2012, 03:38 AM   |  #4  
goja's Avatar
Senior Member
Thanks Meter: 91
 
1,915 posts
Join Date:Joined: Dec 2011
If i go back to a 4.0.3 stock firmware, no brick risk then, right?

Sent from my GT-I9100 using xda app-developers app
24th August 2012, 09:35 AM   |  #5  
Phil3759's Avatar
OP Recognized Developer
Thanks Meter: 32,033
 
9,397 posts
Join Date:Joined: May 2012
Donate to Me
Quote:
Originally Posted by kojinmalia

If i go back to a 4.0.3 stock firmware, no brick risk then, right?

Sent from my GT-I9100 using xda app-developers app

No brick risks on the i9100 with official 4.0.3 fw

Sent from my GT-I9100 using Tapatalk 2
The Following 3 Users Say Thank You to Phil3759 For This Useful Post: [ View ]
24th August 2012, 01:07 PM   |  #6  
shoey63's Avatar
Recognized Contributor
Flag Somewhere in Oz...
Thanks Meter: 1,440
 
2,324 posts
Join Date:Joined: Jun 2012
More
These files also work on Note N7000 If using on CWM in preparation for installing new ZIP Rom "unmounted" partitions need to be "remounted" (mounts and storage). As per Phil3759's initial warnings. (For Note users - don't know about GSII users)
The Following User Says Thank You to shoey63 For This Useful Post: [ View ]
10th September 2012, 01:04 PM   |  #7  
shoey63's Avatar
Recognized Contributor
Flag Somewhere in Oz...
Thanks Meter: 1,440
 
2,324 posts
Join Date:Joined: Jun 2012
More
I know u don't own a Note Phil, but any idea what's going on with this guy? http://forum.xda-developers.com/show...24&postcount=1. (BTW, ur wiping scripts are pretty much instantaneous in stock 3e ICS recovery).
10th September 2012, 09:28 PM   |  #8  
Phil3759's Avatar
OP Recognized Developer
Thanks Meter: 32,033
 
9,397 posts
Join Date:Joined: May 2012
Donate to Me
I planned to add a pause so users can change their mind and unplug battery before the wipe. A bit out of time now. Busy on the PhilZ-cwm6 kernel
But, if I remind this thread or someone post again later, I could add it

Will be looking at your link
The Following User Says Thank You to Phil3759 For This Useful Post: [ View ]
10th September 2012, 10:44 PM   |  #9  
Phil3759's Avatar
OP Recognized Developer
Thanks Meter: 32,033
 
9,397 posts
Join Date:Joined: May 2012
Donate to Me
Quote:
Originally Posted by shoey63

I know u don't own a Note Phil, but any idea what's going on with this guy? http://forum.xda-developers.com/show...24&postcount=1. (BTW, ur wiping scripts are pretty much instantaneous in stock 3e ICS recovery).

Sorry, seems software or specific hardware issue
Never experienced this, and many note users too

Nothing to do with superbrick in my opinion
The Following 2 Users Say Thank You to Phil3759 For This Useful Post: [ View ]
18th September 2012, 03:37 PM   |  #10  
Member
Thanks Meter: 8
 
76 posts
Join Date:Joined: Nov 2010
Very nice idea and good work!
Tested on I9100. No problem.
Thank you!

The Following 2 Users Say Thank You to rodirodi For This Useful Post: [ View ]
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes