OSDN Git Service

ext4_utils: add BoardConfig define to suppress EMMC-corrupting wipe command
authorDavid Ferguson <ferguson.david@gmail.com>
Fri, 8 Jun 2012 01:00:41 +0000 (21:00 -0400)
committerSteve Kondik <steve@cyngn.com>
Thu, 25 Aug 2016 00:31:56 +0000 (17:31 -0700)
If BOARD_SUPPRESS_EMMC_WIPE is true, the EMMC wipe command will not be
issued. This works around a bug in some firmware revisions of Samsung EMMC's
that permanently damages the device when the wipe command is issued.

For affected devices with kernel source, MMC_CAP_ERASE should be removed
from the kernel instead.

This is only part of the solution but it does handle the "flashing CM9
for the first time on an unsafe kernel" situation.

Change-Id: Ie4e31f9268a65218e5d344ae3068b021790fc33c

ext4_utils/Android.mk
ext4_utils/wipe.c

index a8362b2..cead6f4 100644 (file)
@@ -80,6 +80,11 @@ LOCAL_SHARED_LIBRARIES := \
     libsparse \
     libz
 LOCAL_CFLAGS := -DREAL_UUID
+
+ifeq ($(BOARD_SUPPRESS_EMMC_WIPE),true)
+    LOCAL_CFLAGS += -DSUPPRESS_EMMC_WIPE
+endif
+
 include $(BUILD_SHARED_LIBRARY)
 
 
@@ -95,6 +100,11 @@ LOCAL_STATIC_LIBRARIES := \
     libsparse_static \
     libselinux \
     libbase
+
+ifeq ($(BOARD_SUPPRESS_EMMC_WIPE),true)
+    LOCAL_CFLAGS += -DSUPPRESS_EMMC_WIPE
+endif
+
 include $(BUILD_STATIC_LIBRARY)
 
 
index 002e021..f8af756 100644 (file)
@@ -34,6 +34,7 @@
 
 int wipe_block_device(int fd, s64 len)
 {
+#ifndef SUPPRESS_EMMC_WIPE
        u64 range[2];
        int ret;
 
@@ -47,7 +48,7 @@ int wipe_block_device(int fd, s64 len)
        range[1] = len;
        ret = ioctl(fd, BLKSECDISCARD, &range);
        if (ret < 0) {
-#endif
+#endif /* NO_SECURE_DISCARD */
                range[0] = 0;
                range[1] = len;
                ret = ioctl(fd, BLKDISCARD, &range);
@@ -60,8 +61,12 @@ int wipe_block_device(int fd, s64 len)
                }
 #ifndef NO_SECURE_DISCARD
        }
-#endif
+#endif /* NO_SECURE_DISCARD */
        return 0;
+#else
+       warn("Wipe via secure discard suppressed due to bug in EMMC firmware\n");
+       return 1;
+#endif /* SUPPRESS_EMMC_WIPE */
 }
 
 #else  /* __linux__ */