Patchwork [v3,4/6] UBI: replace MTD_UBI_BEB_LIMIT with module parameter

login
register
mail settings
Submitter Richard Genoud
Date Aug. 20, 2012, 4 p.m.
Message ID <1345478416-23900-5-git-send-email-richard.genoud@gmail.com>
Download mbox | patch
Permalink /patch/178868/
State New
Headers show

Comments

Richard Genoud - Aug. 20, 2012, 4 p.m.
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 |   38 ++++++++++++++++++++++++--------------
 2 files changed, 26 insertions(+), 14 deletions(-)
Artem Bityutskiy - Aug. 21, 2012, 1:54 p.m.
Amended the commit subject,

On Mon, 2012-08-20 at 18:00 +0200, Richard Genoud wrote:
> 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>

Did few minor amendments and applied this one. And pushed out. 

> +			pr_err("UBI error: bad value for max_beb_per1024 parameter: %s",
> +			       tokens[2]);

Changed this to 'printk(KERN_ERR' and wrapped the line.

The former is because the entire function uses 'printk(KERN_ERR', and I
am a fan of consistency. We can change them all to 'pr_err()' and
'pr_warn()' in a separate patch.

Similar for wrapping - UBI wraps all messages. If we want, we can unwrap
them all in a separate patch.

Feel free to submit such a patch, I won't have objections.

> -MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: "
> -		      "mtd=<name|num|path>[,<vid_hdr_offs>].\n"

You unwrapped this one and I pushed that as is, because it is just much
more readable, and it is the only place where we describe a module, so
no inconsistencies. :-)

Thank you!
Richard Genoud - Aug. 22, 2012, 8:32 a.m.
2012/8/21 Artem Bityutskiy <dedekind1@gmail.com>:
> Changed this to 'printk(KERN_ERR' and wrapped the line.
>
> The former is because the entire function uses 'printk(KERN_ERR', and I
> am a fan of consistency. We can change them all to 'pr_err()' and
> 'pr_warn()' in a separate patch.
>
> Similar for wrapping - UBI wraps all messages. If we want, we can unwrap
> them all in a separate patch.
>
> Feel free to submit such a patch, I won't have objections.
>
>> -MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: "
>> -                   "mtd=<name|num|path>[,<vid_hdr_offs>].\n"
>
> You unwrapped this one and I pushed that as is, because it is just much
> more readable, and it is the only place where we describe a module, so
> no inconsistencies. :-)
>
> Thank you!
>
> --
> Best Regards,
> Artem Bityutskiy

Looking for consistency, I made a quick git grep "\<printk( *KERN_" | wc -l
the answer is  > 32000
Looks like I found something to do if I'm getting bored with openstreetmap :)


I double checked linux-ubi/master tree with mine, it's all right.

I'll resend the mtd-utils part updated with the new kernel header ubi-user.h

Best regards

Richard.
Artem Bityutskiy - Aug. 22, 2012, 8:49 a.m.
On Wed, 2012-08-22 at 10:32 +0200, Richard Genoud wrote:
> Looking for consistency, I made a quick git grep "\<printk( *KERN_" |
> wc -l
> the answer is  > 32000
> Looks like I found something to do if I'm getting bored with
> openstreetmap :)

Well, now I am talking about consistency within UBI only, withing the
project. I think that function is the only one which uses plain printk
in UBI. I do not remember the details, but there were some issues using
the UBI wrappers like 'ubi_msg' in this function because it is called
very early during boot time (when UBI is compiled-in). And I just did
not know about pr_err() that time, or pr_err() did not exist. So you can
just amend this single function if you wish.
>
Richard Genoud - Aug. 22, 2012, 12:09 p.m.
2012/8/22 Artem Bityutskiy <dedekind1@gmail.com>:
> Well, now I am talking about consistency within UBI only, withing the
> project. I think that function is the only one which uses plain printk
> in UBI. I do not remember the details, but there were some issues using
> the UBI wrappers like 'ubi_msg' in this function because it is called
> very early during boot time (when UBI is compiled-in). And I just did
> not know about pr_err() that time, or pr_err() did not exist. So you can
> just amend this single function if you wish.

(for the record, pr_err didn't exists at the time UBI got into the kernel)
I tested this function with pr_err and ubi_err, and both are working.
(by using  ubi.mtd= ubi.mtd=2,0,toto ubi.mtd=1,2,3,4)
It should be better to use ubi_err don't you think ?
(or I missed a corner case ?)


Richard.
Artem Bityutskiy - Aug. 22, 2012, 12:16 p.m.
On Wed, 2012-08-22 at 14:09 +0200, Richard Genoud wrote:
> 2012/8/22 Artem Bityutskiy <dedekind1@gmail.com>:
> > Well, now I am talking about consistency within UBI only, withing the
> > project. I think that function is the only one which uses plain printk
> > in UBI. I do not remember the details, but there were some issues using
> > the UBI wrappers like 'ubi_msg' in this function because it is called
> > very early during boot time (when UBI is compiled-in). And I just did
> > not know about pr_err() that time, or pr_err() did not exist. So you can
> > just amend this single function if you wish.
> 
> (for the record, pr_err didn't exists at the time UBI got into the kernel)
> I tested this function with pr_err and ubi_err, and both are working.
> (by using  ubi.mtd= ubi.mtd=2,0,toto ubi.mtd=1,2,3,4)
> It should be better to use ubi_err don't you think ?
> (or I missed a corner case ?)

I guess it is safe to change than, thank you!

Patch

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 6a749d6..5b987cb 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);
@@ -1345,6 +1346,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;
@@ -1392,23 +1394,31 @@  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;
 
+	if (tokens[2]) {
+		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)\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)\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");