wrong log on NOR

Message ID CAFwEtmqWOcZ1kSu_N4CmpWMb4Z_cTAQGG6L19AvfBi-K672NWA@mail.gmail.com
State New
Delegated to: David Oberhollenzer
Headers show
Series
  • wrong log on NOR
Related show

Commit Message

Michele Dionisio June 6, 2018, 12:36 p.m.
Hi all,
with version v2.0.2 working on NOR I have not so nice log message that say:

ECCGETLAYOUT ioctl request failed

but on NOR is useless to try to read OBB so I suggest to apply the
attached patch.

regards

Comments

Miquel Raynal June 7, 2018, 8:42 a.m. | #1
Hi Michele,

On Wed, 6 Jun 2018 14:36:42 +0200, Michele Dionisio
<michele.dionisio@gmail.com> wrote:

> Hi all,
> with version v2.0.2 working on NOR I have not so nice log message that say:
> 
> ECCGETLAYOUT ioctl request failed
> 
> but on NOR is useless to try to read OBB so I suggest to apply the
> attached patch.

Thanks a lot for contributing.

As depicted in Documentation/process/submitting-patches.rst, could you
please re-send your patch inline (no attachments) to ease the review
process?

Don't forget to add a proper title and commit message.

Thank you,
Miquèl

Patch

diff --git a/lib/libmtd.c b/lib/libmtd.c
index 7382229..99fcb1b 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -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);
 
diff --git a/lib/libmtd_legacy.c b/lib/libmtd_legacy.c
index 97fef04..a882e52 100644
--- a/lib/libmtd_legacy.c
+++ b/lib/libmtd_legacy.c
@@ -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