aboutsummaryrefslogtreecommitdiffstats
path: root/mtdutils/mtdutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'mtdutils/mtdutils.c')
-rw-r--r--mtdutils/mtdutils.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/mtdutils/mtdutils.c b/mtdutils/mtdutils.c
index d04b26ef..98e7aaf3 100644
--- a/mtdutils/mtdutils.c
+++ b/mtdutils/mtdutils.c
@@ -28,6 +28,9 @@
#include "mtdutils.h"
+static const char mtdprefix[] = "/dev/block/mtd/by-name/";
+#define MTD_BASENAME_OFFSET (sizeof(mtdprefix)-1+1)
+
struct MtdPartition {
int device_index;
unsigned int size;
@@ -144,7 +147,7 @@ mtd_scan_partitions()
p->device_index = mtdnum;
p->size = mtdsize;
p->erase_size = mtderasesize;
- p->name = strdup(mtdname);
+ asprintf(&p->name, "%s%s", mtdprefix, mtdname);
if (p->name == NULL) {
errno = ENOMEM;
goto bail;
@@ -183,6 +186,9 @@ mtd_find_partition_by_name(const char *name)
if (strcmp(p->name, name) == 0) {
return p;
}
+ if (strcmp(p->name+MTD_BASENAME_OFFSET, name) == 0) {
+ return p;
+ }
}
}
}
@@ -313,8 +319,8 @@ static int read_block(const MtdPartition *partition, int fd, char *data)
memcpy(&before, &after, sizeof(struct mtd_ecc_stats));
} else if ((mgbb = ioctl(fd, MEMGETBADBLOCK, &pos))) {
fprintf(stderr,
- "mtd: MEMGETBADBLOCK returned %d at 0x%08llx (errno=%d)\n",
- mgbb, pos, errno);
+ "mtd: MEMGETBADBLOCK returned %d at 0x%08llx: %s\n",
+ mgbb, pos, strerror(errno));
} else {
return 0; // Success!
}
@@ -419,8 +425,8 @@ static int write_block(MtdWriteContext *ctx, const char *data)
if (ret != 0 && !(ret == -1 && errno == EOPNOTSUPP)) {
add_bad_block_offset(ctx, pos);
fprintf(stderr,
- "mtd: not writing bad block at 0x%08lx (ret %d errno %d)\n",
- pos, ret, errno);
+ "mtd: not writing bad block at 0x%08lx (ret %d): %s\n",
+ pos, ret, strerror(errno));
pos += partition->erase_size;
continue; // Don't try to erase known factory-bad blocks.
}