From cfd256a3328aac1199a35825b5daf04f5f4fc112 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Fri, 22 Apr 2011 09:26:44 -0700 Subject: [PATCH] delay accessing misc partition until its device exists When the misc partition is on an emmc device, recovery can get started and try to access it before the kernel has actually created the device. Try statting the device before reading or writing it; delay up to 10 seconds waiting for the device to exist. Change-Id: Ib9bf6c35fa2c28fc43aa7550aaaffb76c9f6e120 --- bootloader.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bootloader.c b/bootloader.c index b690c55..7096566 100644 --- a/bootloader.c +++ b/bootloader.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include static int get_bootloader_message_mtd(struct bootloader_message *out, const Volume* v); static int set_bootloader_message_mtd(const struct bootloader_message *in, const Volume* v); @@ -132,8 +134,26 @@ static int set_bootloader_message_mtd(const struct bootloader_message *in, // for misc partitions on block devices // ------------------------------------ +static void wait_for_device(const char* fn) { + int tries = 0; + int ret; + struct stat buf; + do { + ++tries; + ret = stat(fn, &buf); + if (ret) { + printf("stat %s try %d: %s\n", fn, tries, strerror(errno)); + sleep(1); + } + } while (ret && tries < 10); + if (ret) { + printf("failed to stat %s\n", fn); + } +} + static int get_bootloader_message_block(struct bootloader_message *out, const Volume* v) { + wait_for_device(v->device); FILE* f = fopen(v->device, "rb"); if (f == NULL) { LOGE("Can't open %s\n(%s)\n", v->device, strerror(errno)); @@ -155,6 +175,7 @@ static int get_bootloader_message_block(struct bootloader_message *out, static int set_bootloader_message_block(const struct bootloader_message *in, const Volume* v) { + wait_for_device(v->device); FILE* f = fopen(v->device, "wb"); if (f == NULL) { LOGE("Can't open %s\n(%s)\n", v->device, strerror(errno));