fix erroneous detection of device flash type when device is explicitly provided. fix bugs in mount generation.

Change-Id: I54a35390550b1384f12c4b12267029d77bef8fa3
diff --git a/flashutils/flashutils.c b/flashutils/flashutils.c
index b71d4fa..0b1467e 100644
--- a/flashutils/flashutils.c
+++ b/flashutils/flashutils.c
@@ -69,9 +69,21 @@
     return (pid == -1 ? -1 : pstat);
 }
 
-int restore_raw_partition(const char *partition, const char *filename)
+static int detect_partition(const char *partition)
 {
     int type = device_flash_type();
+    if (strstr(partition, "/dev/block/mtd") != NULL)
+        type = MTD;
+    else if (strstr(partition, "/dev/block/mmc") != NULL)
+        type = MMC;
+    else if (strstr(partition, "/dev/block/bml") != NULL)
+        type = BML;
+        
+    return type;
+}
+int restore_raw_partition(const char *partition, const char *filename)
+{
+    int type = detect_partition(partition);
     switch (type) {
         case MTD:
             return cmd_mtd_restore_raw_partition(partition, filename);
@@ -86,7 +98,7 @@
 
 int backup_raw_partition(const char *partition, const char *filename)
 {
-    int type = device_flash_type();
+    int type = detect_partition(partition);
     switch (type) {
         case MTD:
             return cmd_mtd_backup_raw_partition(partition, filename);
@@ -101,7 +113,7 @@
 
 int erase_raw_partition(const char *partition)
 {
-    int type = device_flash_type();
+    int type = detect_partition(partition);
     switch (type) {
         case MTD:
             return cmd_mtd_erase_raw_partition(partition);
@@ -116,7 +128,7 @@
 
 int erase_partition(const char *partition, const char *filesystem)
 {
-    int type = device_flash_type();
+    int type = detect_partition(partition);
     switch (type) {
         case MTD:
             return cmd_mtd_erase_partition(partition, filesystem);
@@ -131,7 +143,7 @@
 
 int mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only)
 {
-    int type = device_flash_type();
+    int type = detect_partition(partition);
     switch (type) {
         case MTD:
             return cmd_mtd_mount_partition(partition, mount_point, filesystem, read_only);