@@ -763,6 +763,7 @@ int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd)
if (ret < 0)
return -1;
((char *)mtd->type_str)[ret - 1] = '\0';
+ mtd->type = type_str2int(mtd->type_str);
if (dev_read_pos_int(lib->mtd_eb_size, mtd_num, &mtd->eb_size))
return -1;
@@ -774,14 +775,20 @@ int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd)
return -1;
if (dev_read_pos_int(lib->mtd_oob_size, mtd_num, &mtd->oob_size))
return -1;
- if (dev_read_pos_int(lib->mtd_oobavail, mtd_num, &mtd->oobavail)) {
- /*
- * Fail to access oobavail sysfs file,
- * try ioctl ECCGETLAYOUT. */
- mtd->oobavail = legacy_get_mtd_oobavail1(mtd_num);
- /* Set 0 as default if can not get valid ecc layout */
- if (mtd->oobavail < 0)
- mtd->oobavail = 0;
+ if (mtd->type != MTD_NORFLASH) {
+ if (dev_read_pos_int(lib->mtd_oobavail, mtd_num, &mtd->oobavail)) {
+ /*
+ * Fail to access oobavail sysfs file,
+ * try ioctl ECCGETLAYOUT. */
+ mtd->oobavail = legacy_get_mtd_oobavail1(mtd_num);
+ /* Set 0 as default if can not get valid ecc layout */
+ if (mtd->oobavail < 0) {
+ mtd->oobavail = 0;
+ errmsg("not possible to get oob for mtd_num %d (type: %d %s)", mtd_num, mtd->type, mtd->type_str);
+ }
+ }
+ } else {
+ mtd->oobavail = 0;
}
if (dev_read_pos_int(lib->mtd_region_cnt, mtd_num, &mtd->region_cnt))
return -1;
@@ -790,7 +797,6 @@ int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd)
mtd->writable = !!(ret & MTD_WRITEABLE);
mtd->eb_cnt = mtd->size / mtd->eb_size;
- mtd->type = type_str2int(mtd->type_str);
mtd->bb_allowed = !!(mtd->type == MTD_NANDFLASH ||
mtd->type == MTD_MLCNANDFLASH);
@@ -235,7 +235,7 @@ int legacy_get_mtd_oobavail(const char *node)
ret = ioctl(fd, ECCGETLAYOUT, &usrlay);
if (ret < 0) {
- sys_errmsg("ECCGETLAYOUT ioctl request failed");
+ sys_errmsg("ECCGETLAYOUT ioctl request failed on \"%s\"", node);
goto out_close;
}
@@ -375,8 +375,17 @@ int legacy_get_dev_info(const char *node, struct mtd_dev_info *mtd)
close(fd);
- ret = legacy_get_mtd_oobavail(node);
- mtd->oobavail = ret > 0 ? ret : 0;
+ if (mtd->type != MTD_NORFLASH) {
+ ret = legacy_get_mtd_oobavail(node);
+ if (ret < 0) {
+ mtd->oobavail = 0;
+ errmsg("not possible to get oob for mtd_num %d (type: %d %s)", mtd->mtd_num, mtd->type, mtd->type_str);
+ } else {
+ mtd->oobavail = ret;
+ }
+ } else {
+ mtd->oobavail = 0;
+ }
/*
* Unfortunately, the device name is not available via ioctl, and