fix up bmlutils some more
Change-Id: Ia11e917a6c0dc8164d599e02154f9f7b2934ed65
diff --git a/bmlutils/bmlutils.c b/bmlutils/bmlutils.c
index 6062ac9..1cc28b2 100644
--- a/bmlutils/bmlutils.c
+++ b/bmlutils/bmlutils.c
@@ -23,14 +23,8 @@
extern int __system(const char *command);
#define BML_UNLOCK_ALL 0x8A29 ///< unlock all partition RO -> RW
-int cmd_bml_restore_raw_partition(const char *partition, const char *filename)
+static int restore_internal(const char* bml, const char* filename)
{
- char *bml;
- if (strcmp(partition, "boot") == 0 || strcmp(partition, "recovery") == 0)
- bml = "/dev/block/bml7";
- else
- return 6;
-
char buf[4096];
int dstfd, srcfd, bytes_read, bytes_written, total_read = 0;
if (filename == NULL)
@@ -54,14 +48,33 @@
if (write(dstfd, buf, 4096) < 4096)
return 5;
} while(bytes_read == 4096);
-
+
+ close(dstfd);
+ close(srcfd);
+
return 0;
}
+int cmd_bml_restore_raw_partition(const char *partition, const char *filename)
+{
+ char *bml;
+ if (strcmp(partition, "boot") == 0 || strcmp(partition, "recovery") == 0)
+ bml = "/dev/block/bml7";
+ else
+ return 6;
+
+ int ret = restore_internal("/dev/block/bml7", filename);
+ if (ret != 0)
+ return ret;
+
+ ret = restore_internal("/dev/block/bml8", filename);
+ return ret;
+}
+
int cmd_bml_backup_raw_partition(const char *partition, const char *filename)
{
char tmp[PATH_MAX];
- sprintf("dd of=%s if=/dev/block/bml7 bs=4096", filename);
+ sprintf(tmp, "dd of=%s if=/dev/block/bml7 bs=4096", filename);
return __system(tmp);
}