From c0fc1501d9b808d957265d60a5afaf47a190375d Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Sun, 24 Oct 2010 14:02:04 -0700 Subject: delay recovery startup until emmc block devices exist recovery can get started before the kernel has created the EMMC devices, which will make the wipe_data operation fail (trying to open a device that doesn't exist). Hold up the start of recovery for up to 5 seconds waiting for the userdata partition block device to exist. Bug: 3126195 Change-Id: I2b3d74cc3ffdc69372cdba00d3ffdc5251d8c6b3 --- recovery/recovery_ui.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'recovery') diff --git a/recovery/recovery_ui.c b/recovery/recovery_ui.c index 3474832..d26bff8 100644 --- a/recovery/recovery_ui.c +++ b/recovery/recovery_ui.c @@ -15,6 +15,9 @@ */ #include +#include +#include +#include #include "recovery_ui.h" #include "common.h" @@ -31,6 +34,34 @@ char* MENU_ITEMS[] = { "reboot system now", NULL }; int device_recovery_start() { + // recovery can get started before the kernel has created the EMMC + // devices, which will make the wipe_data operation fail (trying + // to open a device that doesn't exist). Hold up the start of + // recovery for up to 5 seconds waiting for the userdata partition + // block device to exist. + + const char* fn = "/dev/block/platform/s3c-sdhci.0/by-name/userdata"; + + int tries = 0; + int ret; + struct stat buf; + do { + ++tries; + ret = stat(fn, &buf); + if (ret) { + printf("try %d: %s\n", tries, strerror(errno)); + sleep(1); + } + } while (ret && tries < 5); + if (!ret) { + printf("stat() of %s succeeded on try %d\n", fn, tries); + } else { + printf("failed to stat %s\n", fn); + } + + // We let recovery attempt to carry on even if the stat never + // succeeded. + return 0; } -- cgit v1.1