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

Search This thread

Phil3759

Inactive Recognized Developer
May 30, 2012
9,579
33,063

<<< 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:
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 :good:


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:

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.

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://xdaforums.com/showthread.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)

  • 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");
 

Attachments

  • Samsung_Factory_Reset-signed.zip
    154 KB · Views: 2,312
  • Samsung_Wipe_Cache-signed.zip
    153.9 KB · Views: 1,643
  • Samsung_Wipe_Dalvik-signed.zip
    153.9 KB · Views: 2,659
  • Samsung_Wipe_Data_System_Cache-signed.zip
    154.2 KB · Views: 1,609
  • Samsung_Factory_Reset_2.0-signed.zip
    154.5 KB · Views: 1,984
  • Samsung_Wipe_Cache_2.0-signed.zip
    154.5 KB · Views: 1,368
  • Samsung_Wipe_Data_System_Cache_2.0-signed.zip
    154.6 KB · Views: 4,301
Last edited:

Smoky

Senior Member
Sep 15, 2007
157
10
Rennes
Great job :thumbup:
So it will replace the wipe options in CWM. ;)

Envoyé depuis mon GT-I9100 avec Tapatalk
 

GoJo ^^

Senior Member
Dec 2, 2011
3,474
175
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
 

Phil3759

Inactive Recognized Developer
May 30, 2012
9,579
33,063
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
 
  • Like
Reactions: cammi123

Phil3759

Inactive Recognized Developer
May 30, 2012
9,579
33,063

Phil3759

Inactive Recognized Developer
May 30, 2012
9,579
33,063
Yes, it will be safe on the note, no format commands issued

Sent from my GT-I9100 using Tapatalk 2
 
  • Like
Reactions: cammi123

Entropy512

Senior Recognized Developer
Aug 31, 2007
14,088
25,086
Owego, NY
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");
delete_recursive can leave the filesystem in an unclean state. Using this workaround is not advisable.

It is better to use an update-binary that has been rendered safe by building with BOARD_SUPPRESS_EMMC_WIPE.

Run this to check an update-binary for safety:
Code:
strings update-binary |grep MMC
It should return:
Code:
warning: %s: Wipe via secure discard suppressed due to bug in EMMC firmware
Any update-binary versions that have that string are safe to use.
 
  • Like
Reactions: Rila and Phil3759

Phil3759

Inactive Recognized Developer
May 30, 2012
9,579
33,063
delete_recursive can leave the filesystem in an unclean state. Using this workaround is not advisable.

It is better to use an update-binary that has been rendered safe by building with BOARD_SUPPRESS_EMMC_WIPE.

Run this to check an update-binary for safety:
Code:
strings update-binary |grep MMC
It should return:
Code:
warning: %s: Wipe via secure discard suppressed due to bug in EMMC firmware
Any update-binary versions that have that string are safe to use.

Thank you a lot for the input.

However, Chainfire just answered me in his CF-Root for the n7000 that using format commands in update.zip could still brick an unsafe kernel whatever recovery (patched or non patched) it uses. Now, you say that a patched binary in update.zip will make it safe what ever kernel/recovery combo it is

If you confirm it, I will update my post. CF disagree the use of format commands in update.zip (yes, I know, if there are FS errors, they will not be fixed without format)
 
  • Like
Reactions: cammi123

shoey63

Recognized Contributor
Good news Phil! Ran Entropys command on Temp CWM Touch 6.0.12 update-binary and got this "ubuntu@ubuntu:~/Desktop/binary$ strings update-binary |grep MMC
warning: %s: Wipe via secure discard suppressed due to bug in EMMC firmware
EMMC
EMMC:" Unfortunately doesn't produce same result in update-binary for ur wiping script. So simply swap update binary, change "delete-recursive" to "format", re-sign file and job done right? (That's assuming u trust Entropy, and who doesn't?)
 
Last edited:

Phil3759

Inactive Recognized Developer
May 30, 2012
9,579
33,063
Update 08.10.2012:
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 :good:
 

shoey63

Recognized Contributor
Well it's one thing to contribute theoretical information, but it's another to actually go ahead and do it! I hope Entropy is right, I'm about to use script to do factory reset based on his assertion that "format" commands in zips with update binarys that contain "secure discard supressed" are safe.:fingers-crossed:

---------- Post added at 07:54 PM ---------- Previous post was at 07:10 PM ----------

Entropy's right! No problems whatsoever :victory: Flashed factory reset, format commands and all. and the patched update-binary prevented my Note from bricking! It only took seconds:good: (Man.... that was a wild ride):cyclops:
 
  • Like
Reactions: immortalneo

Top Liked Posts

  • There are no posts matching your filters.
  • 50

    <<< 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:
    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 :good:


    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:

    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.

    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://xdaforums.com/showthread.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)

    • 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");
    3
    There's no updated binaries zip file for wiping dalvik right?

    Sent from my GT-I9100 using xda premium

    Wiping dalvik should be safe as there is no dalvik partition, so no format commands issued
    Factory reset is wipe data (so dalvik too)
    Sent from my GT-I9100 using Tapatalk 2
    3
    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
    3
    Every now and then someone on stock ICS wants to do a wipe
    But doesn't want to use custom kernel or even temp CWM. And unless they are prepared to do factory reset from stock recovery, this is they only way.
    Sent from my GT-N7000 using xda app-developers app
    2
    Very nice idea and good work!
    Tested on I9100. No problem.
    Thank you!