Skip to content

Commit 83ff59a

Browse files
vapierdedekind
authored andcommitted
UBI: support ubi_num on mtd.ubi command line
I want to be able to add UBI volumes with specific numbers, but the command line API doesn't have that atm. Add an additional token to support it. Artem: amended the patch a little bit. Signed-off-by: Mike Frysinger <[email protected]> Signed-off-by: Artem Bityutskiy <[email protected]>
1 parent 584d462 commit 83ff59a

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

drivers/mtd/ubi/build.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#define MTD_PARAM_LEN_MAX 64
4848

4949
/* Maximum number of comma-separated items in the 'mtd=' parameter */
50-
#define MTD_PARAM_MAX_COUNT 3
50+
#define MTD_PARAM_MAX_COUNT 4
5151

5252
/* Maximum value for the number of bad PEBs per 1024 PEBs */
5353
#define MAX_MTD_UBI_BEB_LIMIT 768
@@ -67,6 +67,7 @@
6767
*/
6868
struct mtd_dev_param {
6969
char name[MTD_PARAM_LEN_MAX];
70+
int ubi_num;
7071
int vid_hdr_offs;
7172
int max_beb_per1024;
7273
};
@@ -1269,7 +1270,7 @@ static int __init ubi_init(void)
12691270
}
12701271

12711272
mutex_lock(&ubi_devices_mutex);
1272-
err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO,
1273+
err = ubi_attach_mtd_dev(mtd, p->ubi_num,
12731274
p->vid_hdr_offs, p->max_beb_per1024);
12741275
mutex_unlock(&ubi_devices_mutex);
12751276
if (err < 0) {
@@ -1387,7 +1388,7 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
13871388
struct mtd_dev_param *p;
13881389
char buf[MTD_PARAM_LEN_MAX];
13891390
char *pbuf = &buf[0];
1390-
char *tokens[MTD_PARAM_MAX_COUNT];
1391+
char *tokens[MTD_PARAM_MAX_COUNT], *token;
13911392

13921393
if (!val)
13931394
return -EINVAL;
@@ -1427,37 +1428,53 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
14271428
p = &mtd_dev_param[mtd_devs];
14281429
strcpy(&p->name[0], tokens[0]);
14291430

1430-
if (tokens[1])
1431-
p->vid_hdr_offs = bytes_str_to_int(tokens[1]);
1431+
token = tokens[1];
1432+
if (token) {
1433+
p->vid_hdr_offs = bytes_str_to_int(token);
14321434

1433-
if (p->vid_hdr_offs < 0)
1434-
return p->vid_hdr_offs;
1435+
if (p->vid_hdr_offs < 0)
1436+
return p->vid_hdr_offs;
1437+
}
14351438

1436-
if (tokens[2]) {
1437-
int err = kstrtoint(tokens[2], 10, &p->max_beb_per1024);
1439+
token = tokens[2];
1440+
if (token) {
1441+
int err = kstrtoint(token, 10, &p->max_beb_per1024);
14381442

14391443
if (err) {
14401444
ubi_err("bad value for max_beb_per1024 parameter: %s",
1441-
tokens[2]);
1445+
token);
14421446
return -EINVAL;
14431447
}
14441448
}
14451449

1450+
token = tokens[3];
1451+
if (token) {
1452+
int err = kstrtoint(token, 10, &p->ubi_num);
1453+
1454+
if (err) {
1455+
ubi_err("bad value for ubi_num parameter: %s", token);
1456+
return -EINVAL;
1457+
}
1458+
} else
1459+
p->ubi_num = UBI_DEV_NUM_AUTO;
1460+
14461461
mtd_devs += 1;
14471462
return 0;
14481463
}
14491464

14501465
module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000);
1451-
MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024]].\n"
1466+
MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024[,ubi_num]]].\n"
14521467
"Multiple \"mtd\" parameters may be specified.\n"
14531468
"MTD devices may be specified by their number, name, or path to the MTD character device node.\n"
14541469
"Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0)\n"
14551470
"Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value ("
14561471
__stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0)\n"
1472+
"Optional \"ubi_num\" parameter specifies UBI device number which have to be assigned to the newly created UBI device (assigned automatically by default)\n"
14571473
"\n"
14581474
"Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n"
14591475
"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"
14601476
"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"
1477+
"Example 4: mtd=/dev/mtd1,0,0,5 - attach MTD device /dev/mtd1 to UBI 5 and using default values for the other fields.\n"
14611478
"\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device).");
14621479
#ifdef CONFIG_MTD_UBI_FASTMAP
14631480
module_param(fm_autoconvert, bool, 0644);

0 commit comments

Comments
 (0)