aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorRichard Genoud <richard.genoud@gmail.com>2012-08-20 12:00:14 -0400
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-09-04 02:39:01 -0400
commitedac493dfb48fe46d43fe6afabb8cfb2d1d4c048 (patch)
tree6652e8b2f92504fbe69566e59df982099507de4c /drivers/mtd
parentd2f588f9340ed23dfb6cda08b8a1917ef3e8527c (diff)
UBI: allow specifying bad PEBs limit using module parameter
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> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/ubi/Kconfig2
-rw-r--r--drivers/mtd/ubi/build.c40
2 files changed, 27 insertions, 15 deletions
diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig
index dcbaae3ead63..3e185e46cf6c 100644
--- a/drivers/mtd/ubi/Kconfig
+++ b/drivers/mtd/ubi/Kconfig
@@ -51,6 +51,8 @@ config MTD_UBI_BEB_LIMIT
51 MTD partitions of the same size, UBI will reserve 40 eraseblocks when 51 MTD partitions of the same size, UBI will reserve 40 eraseblocks when
52 attaching a partition. 52 attaching a partition.
53 53
54 This option can be overridden by the "mtd=" UBI module parameter.
55
54 Leave the default value if unsure. 56 Leave the default value if unsure.
55 57
56config MTD_UBI_GLUEBI 58config MTD_UBI_GLUEBI
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 3700bf77b0b8..355756bd37ab 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -47,7 +47,7 @@
47#define MTD_PARAM_LEN_MAX 64 47#define MTD_PARAM_LEN_MAX 64
48 48
49/* Maximum number of comma-separated items in the 'mtd=' parameter */ 49/* Maximum number of comma-separated items in the 'mtd=' parameter */
50#define MTD_PARAM_MAX_COUNT 2 50#define MTD_PARAM_MAX_COUNT 3
51 51
52/* Maximum value for the number of bad PEBs per 1024 PEBs */ 52/* Maximum value for the number of bad PEBs per 1024 PEBs */
53#define MAX_MTD_UBI_BEB_LIMIT 768 53#define MAX_MTD_UBI_BEB_LIMIT 768
@@ -63,10 +63,12 @@
63 * @name: MTD character device node path, MTD device name, or MTD device number 63 * @name: MTD character device node path, MTD device name, or MTD device number
64 * string 64 * string
65 * @vid_hdr_offs: VID header offset 65 * @vid_hdr_offs: VID header offset
66 * @max_beb_per1024: maximum expected number of bad PEBs per 1024 PEBs
66 */ 67 */
67struct mtd_dev_param { 68struct mtd_dev_param {
68 char name[MTD_PARAM_LEN_MAX]; 69 char name[MTD_PARAM_LEN_MAX];
69 int vid_hdr_offs; 70 int vid_hdr_offs;
71 int max_beb_per1024;
70}; 72};
71 73
72/* Numbers of elements set in the @mtd_dev_param array */ 74/* Numbers of elements set in the @mtd_dev_param array */
@@ -838,7 +840,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
838 * @mtd: MTD device description object 840 * @mtd: MTD device description object
839 * @ubi_num: number to assign to the new UBI device 841 * @ubi_num: number to assign to the new UBI device
840 * @vid_hdr_offset: VID header offset 842 * @vid_hdr_offset: VID header offset
841 * @max_beb_per1024: maximum number of expected bad blocks per 1024 PEBs 843 * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs
842 * 844 *
843 * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number 845 * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number
844 * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in 846 * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in
@@ -1218,8 +1220,7 @@ static int __init ubi_init(void)
1218 1220
1219 mutex_lock(&ubi_devices_mutex); 1221 mutex_lock(&ubi_devices_mutex);
1220 err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 1222 err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO,
1221 p->vid_hdr_offs, 1223 p->vid_hdr_offs, p->max_beb_per1024);
1222 CONFIG_MTD_UBI_BEB_LIMIT);
1223 mutex_unlock(&ubi_devices_mutex); 1224 mutex_unlock(&ubi_devices_mutex);
1224 if (err < 0) { 1225 if (err < 0) {
1225 ubi_err("cannot attach mtd%d", mtd->index); 1226 ubi_err("cannot attach mtd%d", mtd->index);
@@ -1386,23 +1387,32 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
1386 if (p->vid_hdr_offs < 0) 1387 if (p->vid_hdr_offs < 0)
1387 return p->vid_hdr_offs; 1388 return p->vid_hdr_offs;
1388 1389
1390 if (tokens[2]) {
1391 int err = kstrtoint(tokens[2], 10, &p->max_beb_per1024);
1392
1393 if (err) {
1394 printk(KERN_ERR "UBI error: bad value for "
1395 "max_beb_per1024 parameter: %s", tokens[2]);
1396 return -EINVAL;
1397 }
1398 }
1399
1389 mtd_devs += 1; 1400 mtd_devs += 1;
1390 return 0; 1401 return 0;
1391} 1402}
1392 1403
1393module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); 1404module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000);
1394MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: " 1405MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024]].\n"
1395 "mtd=<name|num|path>[,<vid_hdr_offs>].\n"
1396 "Multiple \"mtd\" parameters may be specified.\n" 1406 "Multiple \"mtd\" parameters may be specified.\n"
1397 "MTD devices may be specified by their number, name, or " 1407 "MTD devices may be specified by their number, name, or path to the MTD character device node.\n"
1398 "path to the MTD character device node.\n" 1408 "Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0)\n"
1399 "Optional \"vid_hdr_offs\" parameter specifies UBI VID " 1409 "Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value ("
1400 "header position to be used by UBI.\n" 1410 __stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0)\n"
1401 "Example 1: mtd=/dev/mtd0 - attach MTD device " 1411 "\n"
1402 "/dev/mtd0.\n" 1412 "Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n"
1403 "Example 2: mtd=content,1984 mtd=4 - attach MTD device " 1413 "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"
1404 "with name \"content\" using VID header offset 1984, and " 1414 "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"
1405 "MTD device number 4 with default VID header offset."); 1415 "\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device).");
1406 1416
1407MODULE_VERSION(__stringify(UBI_VERSION)); 1417MODULE_VERSION(__stringify(UBI_VERSION));
1408MODULE_DESCRIPTION("UBI - Unsorted Block Images"); 1418MODULE_DESCRIPTION("UBI - Unsorted Block Images");