summaryrefslogtreecommitdiffstats
path: root/mtdutils
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--mtdutils/Android.mk12
-rw-r--r--mtdutils/mtdutils.c16
2 files changed, 25 insertions, 3 deletions
diff --git a/mtdutils/Android.mk b/mtdutils/Android.mk
index 7e5fadc71..87ac08129 100644
--- a/mtdutils/Android.mk
+++ b/mtdutils/Android.mk
@@ -5,13 +5,17 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
mtdutils.c \
- mounts.c
+ mounts.c
ifneq ($(filter rk30xx rk3188,$(TARGET_BOARD_PLATFORM)),)
LOCAL_SRC_FILES += rk3xhack.c
LOCAL_CFLAGS += -DRK3X
endif
+ifeq ($(TARGET_MTD_BY_NAME),true)
+LOCAL_CFLAGS += -DBYNAME
+endif
+
LOCAL_MODULE := libmtdutils
LOCAL_STATIC_LIBRARIES := libcutils libc
LOCAL_CLANG := true
@@ -22,13 +26,17 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
mtdutils.c \
- mounts.c
+ mounts.c
ifneq ($(filter rk30xx rk3188,$(TARGET_BOARD_PLATFORM)),)
LOCAL_SRC_FILES += rk3xhack.c
LOCAL_CFLAGS += -DRK3X
endif
+ifeq ($(TARGET_MTD_BY_NAME),true)
+LOCAL_CFLAGS += -DBYNAME
+endif
+
LOCAL_MODULE := libmtdutils
LOCAL_SHARED_LIBRARIES := libcutils libc
LOCAL_CLANG := true
diff --git a/mtdutils/mtdutils.c b/mtdutils/mtdutils.c
index 6779d6e9a..7a22efe2e 100644
--- a/mtdutils/mtdutils.c
+++ b/mtdutils/mtdutils.c
@@ -32,6 +32,11 @@
#include "rk3xhack.h"
#endif
+#ifdef BYNAME
+static const char mtdprefix[] = "/dev/block/mtd/by-name/";
+#define MTD_BASENAME_OFFSET (sizeof(mtdprefix)-1)
+#endif
+
struct MtdReadContext {
const MtdPartition *partition;
char *buffer;
@@ -141,7 +146,11 @@ mtd_scan_partitions()
p->device_index = mtdnum;
p->size = mtdsize;
p->erase_size = mtderasesize;
+#ifdef BYNAME
+ asprintf(&p->name, "%s%s", mtdprefix, mtdname);
+#else
p->name = strdup(mtdname);
+#endif
if (p->name == NULL) {
errno = ENOMEM;
goto bail;
@@ -180,6 +189,11 @@ mtd_find_partition_by_name(const char *name)
if (strcmp(p->name, name) == 0) {
return p;
}
+#ifdef BYNAME
+ if (strcmp(p->name+MTD_BASENAME_OFFSET, name) == 0) {
+ return p;
+ }
+#endif
}
}
}
@@ -795,4 +809,4 @@ int cmd_mtd_get_partition_device(const char *partition, char *device)
return -1;
sprintf(device, "/dev/block/mtdblock%d", p->device_index);
return 0;
-}
+} \ No newline at end of file