Skip to content

Commit 4517547

Browse files
committed
Merge tag 'upstream-3.11-rc1' of git://git.infradead.org/linux-ubi
Pull ubi fixes from Artem Bityutskiy: "A couple of fixes and clean-ups, allow for assigning user-defined UBI device numbers when attaching MTD devices by using the "mtd=" module parameter" * tag 'upstream-3.11-rc1' of git://git.infradead.org/linux-ubi: UBI: support ubi_num on mtd.ubi command line UBI: fastmap break out of used PEB search UBI: document UBI_IOCVOLUP better in user header UBI: do not abort init when ubi.mtd devices cannot be found UBI: drop redundant "UBI error" string
2 parents 2dd1cb5 + 83ff59a commit 4517547

3 files changed

Lines changed: 47 additions & 21 deletions

File tree

‎drivers/mtd/ubi/build.c‎

Lines changed: 40 additions & 19 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
};
@@ -1261,11 +1262,15 @@ static int __init ubi_init(void)
12611262
mtd = open_mtd_device(p->name);
12621263
if (IS_ERR(mtd)) {
12631264
err = PTR_ERR(mtd);
1264-
goto out_detach;
1265+
ubi_err("cannot open mtd %s, error %d", p->name, err);
1266+
/* See comment below re-ubi_is_module(). */
1267+
if (ubi_is_module())
1268+
goto out_detach;
1269+
continue;
12651270
}
12661271

12671272
mutex_lock(&ubi_devices_mutex);
1268-
err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO,
1273+
err = ubi_attach_mtd_dev(mtd, p->ubi_num,
12691274
p->vid_hdr_offs, p->max_beb_per1024);
12701275
mutex_unlock(&ubi_devices_mutex);
12711276
if (err < 0) {
@@ -1309,7 +1314,7 @@ static int __init ubi_init(void)
13091314
out_class:
13101315
class_destroy(ubi_class);
13111316
out:
1312-
ubi_err("UBI error: cannot initialize UBI, error %d", err);
1317+
ubi_err("cannot initialize UBI, error %d", err);
13131318
return err;
13141319
}
13151320
late_initcall(ubi_init);
@@ -1346,7 +1351,7 @@ static int __init bytes_str_to_int(const char *str)
13461351

13471352
result = simple_strtoul(str, &endp, 0);
13481353
if (str == endp || result >= INT_MAX) {
1349-
ubi_err("UBI error: incorrect bytes count: \"%s\"\n", str);
1354+
ubi_err("incorrect bytes count: \"%s\"\n", str);
13501355
return -EINVAL;
13511356
}
13521357

@@ -1362,7 +1367,7 @@ static int __init bytes_str_to_int(const char *str)
13621367
case '\0':
13631368
break;
13641369
default:
1365-
ubi_err("UBI error: incorrect bytes count: \"%s\"\n", str);
1370+
ubi_err("incorrect bytes count: \"%s\"\n", str);
13661371
return -EINVAL;
13671372
}
13681373

@@ -1383,20 +1388,20 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
13831388
struct mtd_dev_param *p;
13841389
char buf[MTD_PARAM_LEN_MAX];
13851390
char *pbuf = &buf[0];
1386-
char *tokens[MTD_PARAM_MAX_COUNT];
1391+
char *tokens[MTD_PARAM_MAX_COUNT], *token;
13871392

13881393
if (!val)
13891394
return -EINVAL;
13901395

13911396
if (mtd_devs == UBI_MAX_DEVICES) {
1392-
ubi_err("UBI error: too many parameters, max. is %d\n",
1397+
ubi_err("too many parameters, max. is %d\n",
13931398
UBI_MAX_DEVICES);
13941399
return -EINVAL;
13951400
}
13961401

13971402
len = strnlen(val, MTD_PARAM_LEN_MAX);
13981403
if (len == MTD_PARAM_LEN_MAX) {
1399-
ubi_err("UBI error: parameter \"%s\" is too long, max. is %d\n",
1404+
ubi_err("parameter \"%s\" is too long, max. is %d\n",
14001405
val, MTD_PARAM_LEN_MAX);
14011406
return -EINVAL;
14021407
}
@@ -1416,44 +1421,60 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
14161421
tokens[i] = strsep(&pbuf, ",");
14171422

14181423
if (pbuf) {
1419-
ubi_err("UBI error: too many arguments at \"%s\"\n", val);
1424+
ubi_err("too many arguments at \"%s\"\n", val);
14201425
return -EINVAL;
14211426
}
14221427

14231428
p = &mtd_dev_param[mtd_devs];
14241429
strcpy(&p->name[0], tokens[0]);
14251430

1426-
if (tokens[1])
1427-
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);
14281434

1429-
if (p->vid_hdr_offs < 0)
1430-
return p->vid_hdr_offs;
1435+
if (p->vid_hdr_offs < 0)
1436+
return p->vid_hdr_offs;
1437+
}
14311438

1432-
if (tokens[2]) {
1433-
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);
14341442

14351443
if (err) {
1436-
ubi_err("UBI error: bad value for max_beb_per1024 parameter: %s",
1437-
tokens[2]);
1444+
ubi_err("bad value for max_beb_per1024 parameter: %s",
1445+
token);
14381446
return -EINVAL;
14391447
}
14401448
}
14411449

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+
14421461
mtd_devs += 1;
14431462
return 0;
14441463
}
14451464

14461465
module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000);
1447-
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"
14481467
"Multiple \"mtd\" parameters may be specified.\n"
14491468
"MTD devices may be specified by their number, name, or path to the MTD character device node.\n"
14501469
"Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0)\n"
14511470
"Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value ("
14521471
__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"
14531473
"\n"
14541474
"Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n"
14551475
"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"
14561476
"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"
14571478
"\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device).");
14581479
#ifdef CONFIG_MTD_UBI_FASTMAP
14591480
module_param(fm_autoconvert, bool, 0644);

‎drivers/mtd/ubi/fastmap.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
727727

728728
aeb = NULL;
729729
list_for_each_entry(tmp_aeb, &used, u.list) {
730-
if (tmp_aeb->pnum == pnum)
730+
if (tmp_aeb->pnum == pnum) {
731731
aeb = tmp_aeb;
732+
break;
733+
}
732734
}
733735

734736
/* This can happen if a PEB is already in an EBA known

‎include/uapi/mtd/ubi-user.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@
173173

174174
#define UBI_VOL_IOC_MAGIC 'O'
175175

176-
/* Start UBI volume update */
176+
/* Start UBI volume update
177+
* Note: This actually takes a pointer (__s64*), but we can't change
178+
* that without breaking the ABI on 32bit systems
179+
*/
177180
#define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, __s64)
178181
/* LEB erasure command, used for debugging, disabled by default */
179182
#define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, __s32)

0 commit comments

Comments
 (0)