public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2 0/7] UBI: add max_beb_per1024 parameter / ioctl
@ 2012-08-20 12:09 Richard Genoud
  2012-08-20 12:09 ` [PATCH v2 1/7] UBI: prepare for max_beb_per1024 module parameter addition Richard Genoud
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Richard Genoud @ 2012-08-20 12:09 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: Richard Genoud, linux-mtd, Shmulik Ladkani


Artem,
This patch serie introduce, step by step the kernel module parameter
max_beb_per1024, then the ioctl and finally drop the kernel config option
CONFIG_MTD_UBI_BEB_LIMIT.

It's based on top of linux-ubi/master (4ebb4b5)

The differences from previous version are:
* The upper bound of max_beb_per1024 is checked and set to 768
* The vid_hdr_offs parameter can now be an empty string in order to have a
kernel parameter like that: mtd.ubi=2,,25
* The max_beb_per1024 parameter can also be empty (just for consistency with
vid_hdr_offs)
* The comment in ubi-user.h has been adjusted with the new range 0-768 and
the term "default kernel value" is used in place of MTD_UBI_DEFAULT_BEB_LIMIT
or CONFIG_MTD_UBI_BEB_LIMIT
* As max_beb_per1024 can be safely null, the config range of MTD_UBI_BEB_LIMIT
has been updates to 0..768
* For the ioctl, max_beb_per1024 is now an __u16, so that we are not limited
to 255 anymore.
* The comment on the default value of max_beb_per1024 has been adjusted before
and after the ioctl patch.

I compiled and tested each patch, so every thing should go smoothly.
I tested also with a 0 value for CONFIG_MTD_UBI_BEB_LIMIT, it seemed to go
well.


Best Regards

Richard.

Richard Genoud (7):
  UBI: prepare for max_beb_per1024 module parameter addition
  UBI: change CONFIG_MTD_UBI_BEB_LIMIT range
  UBI: accept empty string for vid_hdr_offs parameter
  UBI: check max_beb_per1024 value in ubi_attach_mtd_dev
  UBI: replace MTD_UBI_BEB_LIMIT with module parameter
  UBI: add ioctl for max_beb_per1024
  UBI: drop CONFIG_MTD_UBI_BEB_LIMIT

 arch/arm/configs/sam9_l9260_defconfig |    1 -
 drivers/mtd/ubi/Kconfig               |   26 ------------
 drivers/mtd/ubi/build.c               |   69 ++++++++++++++++++++++++---------
 drivers/mtd/ubi/cdev.c                |    3 +-
 drivers/mtd/ubi/ubi.h                 |    6 ++-
 include/mtd/ubi-user.h                |   19 +++++++++-
 6 files changed, 75 insertions(+), 49 deletions(-)

-- 
1.7.2.5

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 1/7] UBI: prepare for max_beb_per1024 module parameter addition
  2012-08-20 12:09 [PATCH v2 0/7] UBI: add max_beb_per1024 parameter / ioctl Richard Genoud
@ 2012-08-20 12:09 ` Richard Genoud
  2012-08-20 12:26   ` Shmulik Ladkani
  2012-08-20 12:09 ` [PATCH v2 2/7] UBI: change CONFIG_MTD_UBI_BEB_LIMIT range Richard Genoud
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Richard Genoud @ 2012-08-20 12:09 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: Richard Genoud, linux-mtd, Shmulik Ladkani

This patch prepare the way for the addition of max_beb_per1024 module
parameter.
There's no functional change.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
 drivers/mtd/ubi/build.c |   14 ++++++++------
 drivers/mtd/ubi/cdev.c  |    3 ++-
 drivers/mtd/ubi/ubi.h   |    3 ++-
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 4385aaa..3c0b91f 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -602,6 +602,7 @@ static int get_bad_peb_limit(const struct ubi_device *ubi, int max_beb_per1024)
 /**
  * io_init - initialize I/O sub-system for a given UBI device.
  * @ubi: UBI device description object
+ * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEB
  *
  * If @ubi->vid_hdr_offset or @ubi->leb_start is zero, default offsets are
  * assumed:
@@ -614,10 +615,8 @@ static int get_bad_peb_limit(const struct ubi_device *ubi, int max_beb_per1024)
  * This function returns zero in case of success and a negative error code in
  * case of failure.
  */
-static int io_init(struct ubi_device *ubi)
+static int io_init(struct ubi_device *ubi, int max_beb_per1024)
 {
-	const int max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT;
-
 	if (ubi->mtd->numeraseregions != 0) {
 		/*
 		 * Some flashes have several erase regions. Different regions
@@ -839,6 +838,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
  * @mtd: MTD device description object
  * @ubi_num: number to assign to the new UBI device
  * @vid_hdr_offset: VID header offset
+ * @max_beb_per1024: maximum number of expected bad blocks per 1024 eraseblocks
  *
  * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number
  * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in
@@ -849,7 +849,8 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
  * Note, the invocations of this function has to be serialized by the
  * @ubi_devices_mutex.
  */
-int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
+int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
+		       int vid_hdr_offset, int max_beb_per1024)
 {
 	struct ubi_device *ubi;
 	int i, err, ref = 0;
@@ -922,7 +923,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
 	dbg_msg("sizeof(struct ubi_ainf_peb) %zu", sizeof(struct ubi_ainf_peb));
 	dbg_msg("sizeof(struct ubi_wl_entry) %zu", sizeof(struct ubi_wl_entry));
 
-	err = io_init(ubi);
+	err = io_init(ubi, max_beb_per1024);
 	if (err)
 		goto out_free;
 
@@ -1211,7 +1212,8 @@ static int __init ubi_init(void)
 
 		mutex_lock(&ubi_devices_mutex);
 		err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO,
-					 p->vid_hdr_offs);
+					 p->vid_hdr_offs,
+					 CONFIG_MTD_UBI_BEB_LIMIT);
 		mutex_unlock(&ubi_devices_mutex);
 		if (err < 0) {
 			ubi_err("cannot attach mtd%d", mtd->index);
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index fb55678..619f914 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -1010,7 +1010,8 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd,
 		 * 'ubi_attach_mtd_dev()'.
 		 */
 		mutex_lock(&ubi_devices_mutex);
-		err = ubi_attach_mtd_dev(mtd, req.ubi_num, req.vid_hdr_offset);
+		err = ubi_attach_mtd_dev(mtd, req.ubi_num, req.vid_hdr_offset,
+					 CONFIG_MTD_UBI_BEB_LIMIT);
 		mutex_unlock(&ubi_devices_mutex);
 		if (err < 0)
 			put_mtd_device(mtd);
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index c94612e..2a2475b 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -693,7 +693,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
 			 struct ubi_vid_hdr *vid_hdr);
 
 /* build.c */
-int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset);
+int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
+		       int vid_hdr_offset, int max_beb_per1024);
 int ubi_detach_mtd_dev(int ubi_num, int anyway);
 struct ubi_device *ubi_get_device(int ubi_num);
 void ubi_put_device(struct ubi_device *ubi);
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 2/7] UBI: change CONFIG_MTD_UBI_BEB_LIMIT range
  2012-08-20 12:09 [PATCH v2 0/7] UBI: add max_beb_per1024 parameter / ioctl Richard Genoud
  2012-08-20 12:09 ` [PATCH v2 1/7] UBI: prepare for max_beb_per1024 module parameter addition Richard Genoud
@ 2012-08-20 12:09 ` Richard Genoud
  2012-08-20 12:09 ` [PATCH v2 3/7] UBI: accept empty string for vid_hdr_offs parameter Richard Genoud
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Richard Genoud @ 2012-08-20 12:09 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: Richard Genoud, linux-mtd, Shmulik Ladkani

There's no reason to limit MTD_UBI_BEB_LIMIT to 256 (25%), let's set it
to 768 (75%) this should be enough.
And the lower bound can be 0, no reason to forbid it (even if it will be
reserved for test purpose only I guess).

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
 drivers/mtd/ubi/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig
index 9ee92d6..dcbaae3 100644
--- a/drivers/mtd/ubi/Kconfig
+++ b/drivers/mtd/ubi/Kconfig
@@ -30,7 +30,7 @@ config MTD_UBI_WL_THRESHOLD
 config MTD_UBI_BEB_LIMIT
 	int "Maximum expected bad eraseblock count per 1024 eraseblocks"
 	default 20
-	range 1 256
+	range 0 768
 	help
 	  This option specifies the maximum bad physical eraseblocks UBI
 	  expects on the MTD device (per 1024 eraseblocks). If the underlying
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 3/7] UBI: accept empty string for vid_hdr_offs parameter
  2012-08-20 12:09 [PATCH v2 0/7] UBI: add max_beb_per1024 parameter / ioctl Richard Genoud
  2012-08-20 12:09 ` [PATCH v2 1/7] UBI: prepare for max_beb_per1024 module parameter addition Richard Genoud
  2012-08-20 12:09 ` [PATCH v2 2/7] UBI: change CONFIG_MTD_UBI_BEB_LIMIT range Richard Genoud
@ 2012-08-20 12:09 ` Richard Genoud
  2012-08-20 12:52   ` Shmulik Ladkani
  2012-08-20 12:09 ` [PATCH v2 4/7] UBI: check max_beb_per1024 value in ubi_attach_mtd_dev Richard Genoud
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Richard Genoud @ 2012-08-20 12:09 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: Richard Genoud, linux-mtd, Shmulik Ladkani

as a new parameter (max_beb_per1024) will come in next patches, it's
better to accept empty string value so that we can do:
mtd.ubi=2,,25

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
 drivers/mtd/ubi/build.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 3c0b91f..cc0a4fa 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1292,7 +1292,11 @@ static int __init bytes_str_to_int(const char *str)
 	unsigned long result;
 
 	result = simple_strtoul(str, &endp, 0);
-	if (str == endp || result >= INT_MAX) {
+	if (str == endp)
+		/* empty string, assume it's 0 */
+		return 0;
+
+	if (result >= INT_MAX) {
 		printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
 		       str);
 		return -EINVAL;
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 4/7] UBI: check max_beb_per1024 value in ubi_attach_mtd_dev
  2012-08-20 12:09 [PATCH v2 0/7] UBI: add max_beb_per1024 parameter / ioctl Richard Genoud
                   ` (2 preceding siblings ...)
  2012-08-20 12:09 ` [PATCH v2 3/7] UBI: accept empty string for vid_hdr_offs parameter Richard Genoud
@ 2012-08-20 12:09 ` Richard Genoud
  2012-08-20 12:09 ` [PATCH v2 5/7] UBI: replace MTD_UBI_BEB_LIMIT with module parameter Richard Genoud
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Richard Genoud @ 2012-08-20 12:09 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: Richard Genoud, linux-mtd, Shmulik Ladkani

max_beb_per1024 shouldn't be negative, and a 0 value will be treated as
the default value.
For the upper bound, 768/1024 should be enough.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
 drivers/mtd/ubi/build.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index cc0a4fa..1ddced3 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -49,6 +49,9 @@
 /* Maximum number of comma-separated items in the 'mtd=' parameter */
 #define MTD_PARAM_MAX_COUNT 2
 
+/* Maximum value for the number of bad eraseblocks per 1024 limit */
+#define MAX_MTD_UBI_BEB_LIMIT 768
+
 #ifdef CONFIG_MTD_UBI_MODULE
 #define ubi_is_module() 1
 #else
@@ -855,6 +858,15 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
 	struct ubi_device *ubi;
 	int i, err, ref = 0;
 
+	if ((max_beb_per1024 < 0) || (max_beb_per1024 > MAX_MTD_UBI_BEB_LIMIT))
+		return -EINVAL;
+
+	/*
+	 * Use the default value if max_beb_per1024 isn't provided.
+	 */
+	if (!max_beb_per1024)
+		max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT;
+
 	/*
 	 * Check if we already have the same MTD device attached.
 	 *
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 5/7] UBI: replace MTD_UBI_BEB_LIMIT with module parameter
  2012-08-20 12:09 [PATCH v2 0/7] UBI: add max_beb_per1024 parameter / ioctl Richard Genoud
                   ` (3 preceding siblings ...)
  2012-08-20 12:09 ` [PATCH v2 4/7] UBI: check max_beb_per1024 value in ubi_attach_mtd_dev Richard Genoud
@ 2012-08-20 12:09 ` Richard Genoud
  2012-08-20 12:09 ` [PATCH v2 6/7] UBI: add ioctl for max_beb_per1024 Richard Genoud
  2012-08-20 12:09 ` [PATCH v2 7/7] UBI: drop CONFIG_MTD_UBI_BEB_LIMIT Richard Genoud
  6 siblings, 0 replies; 14+ messages in thread
From: Richard Genoud @ 2012-08-20 12:09 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: Richard Genoud, linux-mtd, Shmulik Ladkani

This patch provides the possibility to adjust the "maximum expected number of
bad blocks per 1024 blocks" (max_beb_per1024) for each mtd device.

The majority of NAND devices have their max_beb_per1024 equal to 20, but
sometimes it's more.
Now, we can adjust that via a kernel parameter:
ubi.mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024]]

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
 drivers/mtd/ubi/Kconfig |    2 ++
 drivers/mtd/ubi/build.c |   39 +++++++++++++++++++++++++--------------
 2 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig
index dcbaae3..37e070c 100644
--- a/drivers/mtd/ubi/Kconfig
+++ b/drivers/mtd/ubi/Kconfig
@@ -51,6 +51,8 @@ config MTD_UBI_BEB_LIMIT
 	  MTD partitions of the same size, UBI will reserve 40 eraseblocks when
 	  attaching a partition.
 
+	  This option can be overridden by the kernel parameter ubi.mtd.
+
 	  Leave the default value if unsure.
 
 config MTD_UBI_GLUEBI
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 1ddced3..0c4c840 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -47,7 +47,7 @@
 #define MTD_PARAM_LEN_MAX 64
 
 /* Maximum number of comma-separated items in the 'mtd=' parameter */
-#define MTD_PARAM_MAX_COUNT 2
+#define MTD_PARAM_MAX_COUNT 3
 
 /* Maximum value for the number of bad eraseblocks per 1024 limit */
 #define MAX_MTD_UBI_BEB_LIMIT 768
@@ -63,10 +63,12 @@
  * @name: MTD character device node path, MTD device name, or MTD device number
  *        string
  * @vid_hdr_offs: VID header offset
+ * @max_beb_per1024: maximum expected number of bad blocks per 1024 erase blocks
  */
 struct mtd_dev_param {
 	char name[MTD_PARAM_LEN_MAX];
 	int vid_hdr_offs;
+	int max_beb_per1024;
 };
 
 /* Numbers of elements set in the @mtd_dev_param array */
@@ -1224,8 +1226,7 @@ static int __init ubi_init(void)
 
 		mutex_lock(&ubi_devices_mutex);
 		err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO,
-					 p->vid_hdr_offs,
-					 CONFIG_MTD_UBI_BEB_LIMIT);
+					 p->vid_hdr_offs, p->max_beb_per1024);
 		mutex_unlock(&ubi_devices_mutex);
 		if (err < 0) {
 			ubi_err("cannot attach mtd%d", mtd->index);
@@ -1349,6 +1350,7 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
 	char buf[MTD_PARAM_LEN_MAX];
 	char *pbuf = &buf[0];
 	char *tokens[MTD_PARAM_MAX_COUNT];
+	int err;
 
 	if (!val)
 		return -EINVAL;
@@ -1396,23 +1398,32 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
 	if (p->vid_hdr_offs < 0)
 		return p->vid_hdr_offs;
 
+	/* empty string will be treated as default */
+	if (tokens[2] && (*tokens[2] != '\0')) {
+		err = kstrtoint(tokens[2], 10, &p->max_beb_per1024);
+		if (err) {
+			pr_err("UBI error: bad value for max_beb_per1024 parameter: %s",
+			       tokens[2]);
+			return -EINVAL;
+		}
+	}
+
 	mtd_devs += 1;
 	return 0;
 }
 
 module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000);
-MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: "
-		      "mtd=<name|num|path>[,<vid_hdr_offs>].\n"
+MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024]].\n"
 		      "Multiple \"mtd\" parameters may be specified.\n"
-		      "MTD devices may be specified by their number, name, or "
-		      "path to the MTD character device node.\n"
-		      "Optional \"vid_hdr_offs\" parameter specifies UBI VID "
-		      "header position to be used by UBI.\n"
-		      "Example 1: mtd=/dev/mtd0 - attach MTD device "
-		      "/dev/mtd0.\n"
-		      "Example 2: mtd=content,1984 mtd=4 - attach MTD device "
-		      "with name \"content\" using VID header offset 1984, and "
-		      "MTD device number 4 with default VID header offset.");
+		      "MTD devices may be specified by their number, name, or path to the MTD character device node.\n"
+		      "Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0 or not set)\n"
+		      "Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value ("
+		      __stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0 or not set)\n"
+		      "\n"
+		      "Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n"
+		      "Example 2: mtd=content,1984 mtd=4 - attach MTD device with name \"content\" using VID header offset 1984, and MTD device number 4 with default VID header offset.\n"
+		      "Example 3: mtd=/dev/mtd1,0,25 - attach MTD device /dev/mtd1 using default VID header offset and reserve 25*nand_size_in_blocks/1024 erase blocks for bad block handling.\n"
+		      "\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device).");
 
 MODULE_VERSION(__stringify(UBI_VERSION));
 MODULE_DESCRIPTION("UBI - Unsorted Block Images");
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 6/7] UBI: add ioctl for max_beb_per1024
  2012-08-20 12:09 [PATCH v2 0/7] UBI: add max_beb_per1024 parameter / ioctl Richard Genoud
                   ` (4 preceding siblings ...)
  2012-08-20 12:09 ` [PATCH v2 5/7] UBI: replace MTD_UBI_BEB_LIMIT with module parameter Richard Genoud
@ 2012-08-20 12:09 ` Richard Genoud
  2012-08-20 12:09 ` [PATCH v2 7/7] UBI: drop CONFIG_MTD_UBI_BEB_LIMIT Richard Genoud
  6 siblings, 0 replies; 14+ messages in thread
From: Richard Genoud @ 2012-08-20 12:09 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: Richard Genoud, linux-mtd, Shmulik Ladkani

This patch provides the possibility to adjust the "maximum expected number of
bad blocks per 1024 blocks" (max_beb_per1024) for each mtd device from
UBI_IOCATT ioctl.

The majority of NAND devices have their max_beb_per1024 equal to 20, but
sometimes it's more.
We already could adjust that via a kernel parameter, now we can also use
UBI_IOCATT ioctl:
struct ubi_attach_req {
	__s32 ubi_num;
	__s32 mtd_num;
	__s32 vid_hdr_offset;
	__u16 max_beb_per1024;
	__s8 padding[10];
};

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
 drivers/mtd/ubi/Kconfig |    3 ++-
 drivers/mtd/ubi/build.c |    2 ++
 drivers/mtd/ubi/cdev.c  |    2 +-
 include/mtd/ubi-user.h  |   19 ++++++++++++++++++-
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig
index 37e070c..9406d26 100644
--- a/drivers/mtd/ubi/Kconfig
+++ b/drivers/mtd/ubi/Kconfig
@@ -51,7 +51,8 @@ config MTD_UBI_BEB_LIMIT
 	  MTD partitions of the same size, UBI will reserve 40 eraseblocks when
 	  attaching a partition.
 
-	  This option can be overridden by the kernel parameter ubi.mtd.
+	  This option can be overridden by the kernel parameter ubi.mtd and the
+	  ioctl UBI_IOCATT.
 
 	  Leave the default value if unsure.
 
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 0c4c840..ec1bd5e 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -865,6 +865,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
 
 	/*
 	 * Use the default value if max_beb_per1024 isn't provided.
+	 * This way, we are keeping the same behaviour between the UBI_IOCATT
+	 * ioctl and the module parameter.
 	 */
 	if (!max_beb_per1024)
 		max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT;
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 619f914..7885dc0 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -1011,7 +1011,7 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd,
 		 */
 		mutex_lock(&ubi_devices_mutex);
 		err = ubi_attach_mtd_dev(mtd, req.ubi_num, req.vid_hdr_offset,
-					 CONFIG_MTD_UBI_BEB_LIMIT);
+					 req.max_beb_per1024);
 		mutex_unlock(&ubi_devices_mutex);
 		if (err < 0)
 			put_mtd_device(mtd);
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h
index 8787349..2a763ae 100644
--- a/include/mtd/ubi-user.h
+++ b/include/mtd/ubi-user.h
@@ -222,6 +222,7 @@ enum {
  * @ubi_num: UBI device number to create
  * @mtd_num: MTD device number to attach
  * @vid_hdr_offset: VID header offset (use defaults if %0)
+ * @max_beb_per1024: Maximum expected bad eraseblocks per 1024 eraseblocks
  * @padding: reserved for future, not used, has to be zeroed
  *
  * This data structure is used to specify MTD device UBI has to attach and the
@@ -245,12 +246,28 @@ enum {
  * be 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes
  * aligned, which is OK, as UBI is clever enough to realize this is 4th
  * sub-page of the first page and add needed padding.
+ *
+ * The @max_beb_per1024 is the maximum bad eraseblocks UBI expects on the ubi
+ * device per 1024 eraseblocks.
+ * This value is often given in an other form in the NAND datasheet (min NVB
+ * i.e. minimal number of valid blocks). The maximum expected bad eraseblocks
+ * per 1024 is then:
+ *   1024 * (1 - MinNVB / MaxNVB)
+ * Which gives 20 for most NAND devices.
+ * This limit is used in order to derive amount of eraseblock UBI reserves for
+ * handling new bad blocks.
+ * If the device has more bad eraseblocks than this limit, UBI does not reserve
+ * any physical eraseblocks for new bad eraseblocks, but attempts to use
+ * available eraseblocks (if any).
+ * The accepted range is 0-768. If 0 is given, the default kernel value will be
+ * used for compatibility.
  */
 struct ubi_attach_req {
 	__s32 ubi_num;
 	__s32 mtd_num;
 	__s32 vid_hdr_offset;
-	__s8 padding[12];
+	__u16 max_beb_per1024;
+	__s8 padding[10];
 };
 
 /**
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 7/7] UBI: drop CONFIG_MTD_UBI_BEB_LIMIT
  2012-08-20 12:09 [PATCH v2 0/7] UBI: add max_beb_per1024 parameter / ioctl Richard Genoud
                   ` (5 preceding siblings ...)
  2012-08-20 12:09 ` [PATCH v2 6/7] UBI: add ioctl for max_beb_per1024 Richard Genoud
@ 2012-08-20 12:09 ` Richard Genoud
  6 siblings, 0 replies; 14+ messages in thread
From: Richard Genoud @ 2012-08-20 12:09 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: Richard Genoud, linux-mtd, Shmulik Ladkani

This option can be set by a kernel parameter and an ioctl, so we may not
need the kernel config option any more.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
 arch/arm/configs/sam9_l9260_defconfig |    1 -
 drivers/mtd/ubi/Kconfig               |   29 -----------------------------
 drivers/mtd/ubi/build.c               |    4 ++--
 drivers/mtd/ubi/ubi.h                 |    3 +++
 4 files changed, 5 insertions(+), 32 deletions(-)

diff --git a/arch/arm/configs/sam9_l9260_defconfig b/arch/arm/configs/sam9_l9260_defconfig
index b4384af..47dd71a 100644
--- a/arch/arm/configs/sam9_l9260_defconfig
+++ b/arch/arm/configs/sam9_l9260_defconfig
@@ -39,7 +39,6 @@ CONFIG_MTD_NAND=y
 CONFIG_MTD_NAND_ATMEL=y
 CONFIG_MTD_NAND_PLATFORM=y
 CONFIG_MTD_UBI=y
-CONFIG_MTD_UBI_BEB_LIMIT=25
 CONFIG_MTD_UBI_GLUEBI=y
 CONFIG_BLK_DEV_LOOP=y
 CONFIG_BLK_DEV_RAM=y
diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig
index 9406d26..7a57cc0 100644
--- a/drivers/mtd/ubi/Kconfig
+++ b/drivers/mtd/ubi/Kconfig
@@ -27,35 +27,6 @@ config MTD_UBI_WL_THRESHOLD
 	  life-cycle less than 10000, the threshold should be lessened (e.g.,
 	  to 128 or 256, although it does not have to be power of 2).
 
-config MTD_UBI_BEB_LIMIT
-	int "Maximum expected bad eraseblock count per 1024 eraseblocks"
-	default 20
-	range 0 768
-	help
-	  This option specifies the maximum bad physical eraseblocks UBI
-	  expects on the MTD device (per 1024 eraseblocks). If the underlying
-	  flash does not admit of bad eraseblocks (e.g. NOR flash), this value
-	  is ignored.
-
-	  NAND datasheets often specify the minimum and maximum NVM (Number of
-	  Valid Blocks) for the flashes' endurance lifetime. The maximum
-	  expected bad eraseblocks per 1024 eraseblocks then can be calculated
-	  as "1024 * (1 - MinNVB / MaxNVB)", which gives 20 for most NANDs
-	  (MaxNVB is basically the total count of eraseblocks on the chip).
-
-	  To put it differently, if this value is 20, UBI will try to reserve
-	  about 1.9% of physical eraseblocks for bad blocks handling. And that
-	  will be 1.9% of eraseblocks on the entire NAND chip, not just the MTD
-	  partition UBI attaches. This means that if you have, say, a NAND
-	  flash chip admits maximum 40 bad eraseblocks, and it is split on two
-	  MTD partitions of the same size, UBI will reserve 40 eraseblocks when
-	  attaching a partition.
-
-	  This option can be overridden by the kernel parameter ubi.mtd and the
-	  ioctl UBI_IOCATT.
-
-	  Leave the default value if unsure.
-
 config MTD_UBI_GLUEBI
 	tristate "MTD devices emulation driver (gluebi)"
 	help
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index ec1bd5e..b0c76c8 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -869,7 +869,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
 	 * ioctl and the module parameter.
 	 */
 	if (!max_beb_per1024)
-		max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT;
+		max_beb_per1024 = MTD_UBI_DEFAULT_BEB_LIMIT;
 
 	/*
 	 * Check if we already have the same MTD device attached.
@@ -1420,7 +1420,7 @@ MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|pa
 		      "MTD devices may be specified by their number, name, or path to the MTD character device node.\n"
 		      "Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0 or not set)\n"
 		      "Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value ("
-		      __stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0 or not set)\n"
+		      __stringify(MTD_UBI_DEFAULT_BEB_LIMIT) ") if 0 or not set)\n"
 		      "\n"
 		      "Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n"
 		      "Example 2: mtd=content,1984 mtd=4 - attach MTD device with name \"content\" using VID header offset 1984, and MTD device number 4 with default VID header offset.\n"
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 2a2475b..2148f35 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -50,6 +50,9 @@
 /* UBI name used for character devices, sysfs, etc */
 #define UBI_NAME_STR "ubi"
 
+/* Default number of maximum expected bad blocks per 1024 eraseblocks */
+#define MTD_UBI_DEFAULT_BEB_LIMIT 20
+
 /* Normal UBI messages */
 #define ubi_msg(fmt, ...) printk(KERN_NOTICE "UBI: " fmt "\n", ##__VA_ARGS__)
 /* UBI warning messages */
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 1/7] UBI: prepare for max_beb_per1024 module parameter addition
  2012-08-20 12:09 ` [PATCH v2 1/7] UBI: prepare for max_beb_per1024 module parameter addition Richard Genoud
@ 2012-08-20 12:26   ` Shmulik Ladkani
  0 siblings, 0 replies; 14+ messages in thread
From: Shmulik Ladkani @ 2012-08-20 12:26 UTC (permalink / raw)
  To: Richard Genoud; +Cc: linux-mtd, Artem Bityutskiy

On Mon, 20 Aug 2012 14:09:15 +0200 Richard Genoud <richard.genoud@gmail.com> wrote:
> This patch prepare the way for the addition of max_beb_per1024 module
> parameter.
> There's no functional change.
> 
> Signed-off-by: Richard Genoud <richard.genoud@gmail.com>

Reviewed-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 3/7] UBI: accept empty string for vid_hdr_offs parameter
  2012-08-20 12:09 ` [PATCH v2 3/7] UBI: accept empty string for vid_hdr_offs parameter Richard Genoud
@ 2012-08-20 12:52   ` Shmulik Ladkani
  2012-08-20 13:04     ` Artem Bityutskiy
  0 siblings, 1 reply; 14+ messages in thread
From: Shmulik Ladkani @ 2012-08-20 12:52 UTC (permalink / raw)
  To: Richard Genoud; +Cc: linux-mtd, Artem Bityutskiy

Hi Richard,

On Mon, 20 Aug 2012 14:09:17 +0200 Richard Genoud <richard.genoud@gmail.com> wrote:
> @@ -1292,7 +1292,11 @@ static int __init bytes_str_to_int(const char *str)
>  	unsigned long result;
>  
>  	result = simple_strtoul(str, &endp, 0);
> -	if (str == endp || result >= INT_MAX) {
> +	if (str == endp)
> +		/* empty string, assume it's 0 */
> +		return 0;

This will allow "ubi=2,#" (or any non numeric character after the
comma), setting a zero vid_hdr_offs instead of erroring.

How about adding:

+	if (!*str)
+		/* empty string, assume it's 0 */
+		return 0;

Before the original (keep it):

 	result = simple_strtoul(str, &endp, 0);
	if (str == endp || result >= INT_MAX) {

Can you test this works in all cases?

Regards,
Shmulik

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 3/7] UBI: accept empty string for vid_hdr_offs parameter
  2012-08-20 12:52   ` Shmulik Ladkani
@ 2012-08-20 13:04     ` Artem Bityutskiy
  2012-08-20 13:06       ` Richard Genoud
  2012-08-21 20:19       ` Shmulik Ladkani
  0 siblings, 2 replies; 14+ messages in thread
From: Artem Bityutskiy @ 2012-08-20 13:04 UTC (permalink / raw)
  To: Shmulik Ladkani; +Cc: Richard Genoud, linux-mtd

[-- Attachment #1: Type: text/plain, Size: 627 bytes --]

On Mon, 2012-08-20 at 15:52 +0300, Shmulik Ladkani wrote:
> Hi Richard,
> 
> On Mon, 20 Aug 2012 14:09:17 +0200 Richard Genoud <richard.genoud@gmail.com> wrote:
> > @@ -1292,7 +1292,11 @@ static int __init bytes_str_to_int(const char *str)
> >  	unsigned long result;
> >  
> >  	result = simple_strtoul(str, &endp, 0);
> > -	if (str == endp || result >= INT_MAX) {
> > +	if (str == endp)
> > +		/* empty string, assume it's 0 */
> > +		return 0;

Please, let's not over-engineer this, do not bother with ",,", use ",0,"
instead. Just do amend the documentation properly.

-- 
Best Regards,
Artem Bityutskiy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 3/7] UBI: accept empty string for vid_hdr_offs parameter
  2012-08-20 13:04     ` Artem Bityutskiy
@ 2012-08-20 13:06       ` Richard Genoud
  2012-08-21 20:19       ` Shmulik Ladkani
  1 sibling, 0 replies; 14+ messages in thread
From: Richard Genoud @ 2012-08-20 13:06 UTC (permalink / raw)
  To: dedekind1; +Cc: linux-mtd, Shmulik Ladkani

2012/8/20 Artem Bityutskiy <dedekind1@gmail.com>:
> On Mon, 2012-08-20 at 15:52 +0300, Shmulik Ladkani wrote:
>> Hi Richard,
>>
>> On Mon, 20 Aug 2012 14:09:17 +0200 Richard Genoud <richard.genoud@gmail.com> wrote:
>> > @@ -1292,7 +1292,11 @@ static int __init bytes_str_to_int(const char *str)
>> >     unsigned long result;
>> >
>> >     result = simple_strtoul(str, &endp, 0);
>> > -   if (str == endp || result >= INT_MAX) {
>> > +   if (str == endp)
>> > +           /* empty string, assume it's 0 */
>> > +           return 0;
>
> Please, let's not over-engineer this, do not bother with ",,", use ",0,"
> instead. Just do amend the documentation properly.

ok, I'll drop the patch and change the doc.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 3/7] UBI: accept empty string for vid_hdr_offs parameter
  2012-08-20 13:04     ` Artem Bityutskiy
  2012-08-20 13:06       ` Richard Genoud
@ 2012-08-21 20:19       ` Shmulik Ladkani
  2012-08-22  8:51         ` Artem Bityutskiy
  1 sibling, 1 reply; 14+ messages in thread
From: Shmulik Ladkani @ 2012-08-21 20:19 UTC (permalink / raw)
  To: dedekind1; +Cc: Richard Genoud, linux-mtd

On Mon, 20 Aug 2012 16:04:58 +0300 Artem Bityutskiy <dedekind1@gmail.com> wrote:
> Please, let's not over-engineer this, do not bother with ",,", use ",0,"
> instead. Just do amend the documentation properly.

Artem, you are probably right, but it was really a one-liner:

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 2c5ed5c..1745764 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1333,7 +1333,7 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
 	p = &mtd_dev_param[mtd_devs];
 	strcpy(&p->name[0], tokens[0]);
 
-	if (tokens[1])
+	if (tokens[1] && *tokens[1] != '\0')
 		p->vid_hdr_offs = bytes_str_to_int(tokens[1]);
 
 	if (p->vid_hdr_offs < 0)


But either case, I guess the user will probably still need to take a
look at the description to understand how to "avoid specifying" the
vid_hdr_offs ;-)
So no real benefit supporting ",,"
Bit more intuitive, though.

Anyways, saw you already pushed, thanks.

Shmulik

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 3/7] UBI: accept empty string for vid_hdr_offs parameter
  2012-08-21 20:19       ` Shmulik Ladkani
@ 2012-08-22  8:51         ` Artem Bityutskiy
  0 siblings, 0 replies; 14+ messages in thread
From: Artem Bityutskiy @ 2012-08-22  8:51 UTC (permalink / raw)
  To: Shmulik Ladkani; +Cc: Richard Genoud, linux-mtd

[-- Attachment #1: Type: text/plain, Size: 396 bytes --]

On Tue, 2012-08-21 at 23:19 +0300, Shmulik Ladkani wrote:
> But either case, I guess the user will probably still need to take a
> look at the description to understand how to "avoid specifying" the
> vid_hdr_offs ;-)
> So no real benefit supporting ",,"

We have 0 as the default value already, no need to have the second way
to specify the same.

-- 
Best Regards,
Artem Bityutskiy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2012-08-22  8:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-20 12:09 [PATCH v2 0/7] UBI: add max_beb_per1024 parameter / ioctl Richard Genoud
2012-08-20 12:09 ` [PATCH v2 1/7] UBI: prepare for max_beb_per1024 module parameter addition Richard Genoud
2012-08-20 12:26   ` Shmulik Ladkani
2012-08-20 12:09 ` [PATCH v2 2/7] UBI: change CONFIG_MTD_UBI_BEB_LIMIT range Richard Genoud
2012-08-20 12:09 ` [PATCH v2 3/7] UBI: accept empty string for vid_hdr_offs parameter Richard Genoud
2012-08-20 12:52   ` Shmulik Ladkani
2012-08-20 13:04     ` Artem Bityutskiy
2012-08-20 13:06       ` Richard Genoud
2012-08-21 20:19       ` Shmulik Ladkani
2012-08-22  8:51         ` Artem Bityutskiy
2012-08-20 12:09 ` [PATCH v2 4/7] UBI: check max_beb_per1024 value in ubi_attach_mtd_dev Richard Genoud
2012-08-20 12:09 ` [PATCH v2 5/7] UBI: replace MTD_UBI_BEB_LIMIT with module parameter Richard Genoud
2012-08-20 12:09 ` [PATCH v2 6/7] UBI: add ioctl for max_beb_per1024 Richard Genoud
2012-08-20 12:09 ` [PATCH v2 7/7] UBI: drop CONFIG_MTD_UBI_BEB_LIMIT Richard Genoud

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox