Commit 45175476ae2dbebc860d5cf486f2916044343513
Exists in
smarc-imx_3.14.28_1.0.0_ga
and in
1 other branch
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
Showing 3 changed files Side-by-side Diff
drivers/mtd/ubi/build.c
... | ... | @@ -47,7 +47,7 @@ |
47 | 47 | #define MTD_PARAM_LEN_MAX 64 |
48 | 48 | |
49 | 49 | /* Maximum number of comma-separated items in the 'mtd=' parameter */ |
50 | -#define MTD_PARAM_MAX_COUNT 3 | |
50 | +#define MTD_PARAM_MAX_COUNT 4 | |
51 | 51 | |
52 | 52 | /* Maximum value for the number of bad PEBs per 1024 PEBs */ |
53 | 53 | #define MAX_MTD_UBI_BEB_LIMIT 768 |
... | ... | @@ -67,6 +67,7 @@ |
67 | 67 | */ |
68 | 68 | struct mtd_dev_param { |
69 | 69 | char name[MTD_PARAM_LEN_MAX]; |
70 | + int ubi_num; | |
70 | 71 | int vid_hdr_offs; |
71 | 72 | int max_beb_per1024; |
72 | 73 | }; |
73 | 74 | |
... | ... | @@ -1261,11 +1262,15 @@ |
1261 | 1262 | mtd = open_mtd_device(p->name); |
1262 | 1263 | if (IS_ERR(mtd)) { |
1263 | 1264 | 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; | |
1265 | 1270 | } |
1266 | 1271 | |
1267 | 1272 | 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, | |
1269 | 1274 | p->vid_hdr_offs, p->max_beb_per1024); |
1270 | 1275 | mutex_unlock(&ubi_devices_mutex); |
1271 | 1276 | if (err < 0) { |
... | ... | @@ -1309,7 +1314,7 @@ |
1309 | 1314 | out_class: |
1310 | 1315 | class_destroy(ubi_class); |
1311 | 1316 | out: |
1312 | - ubi_err("UBI error: cannot initialize UBI, error %d", err); | |
1317 | + ubi_err("cannot initialize UBI, error %d", err); | |
1313 | 1318 | return err; |
1314 | 1319 | } |
1315 | 1320 | late_initcall(ubi_init); |
... | ... | @@ -1346,7 +1351,7 @@ |
1346 | 1351 | |
1347 | 1352 | result = simple_strtoul(str, &endp, 0); |
1348 | 1353 | 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); | |
1350 | 1355 | return -EINVAL; |
1351 | 1356 | } |
1352 | 1357 | |
... | ... | @@ -1362,7 +1367,7 @@ |
1362 | 1367 | case '\0': |
1363 | 1368 | break; |
1364 | 1369 | default: |
1365 | - ubi_err("UBI error: incorrect bytes count: \"%s\"\n", str); | |
1370 | + ubi_err("incorrect bytes count: \"%s\"\n", str); | |
1366 | 1371 | return -EINVAL; |
1367 | 1372 | } |
1368 | 1373 | |
1369 | 1374 | |
1370 | 1375 | |
... | ... | @@ -1383,20 +1388,20 @@ |
1383 | 1388 | struct mtd_dev_param *p; |
1384 | 1389 | char buf[MTD_PARAM_LEN_MAX]; |
1385 | 1390 | char *pbuf = &buf[0]; |
1386 | - char *tokens[MTD_PARAM_MAX_COUNT]; | |
1391 | + char *tokens[MTD_PARAM_MAX_COUNT], *token; | |
1387 | 1392 | |
1388 | 1393 | if (!val) |
1389 | 1394 | return -EINVAL; |
1390 | 1395 | |
1391 | 1396 | 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", | |
1393 | 1398 | UBI_MAX_DEVICES); |
1394 | 1399 | return -EINVAL; |
1395 | 1400 | } |
1396 | 1401 | |
1397 | 1402 | len = strnlen(val, MTD_PARAM_LEN_MAX); |
1398 | 1403 | 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", | |
1400 | 1405 | val, MTD_PARAM_LEN_MAX); |
1401 | 1406 | return -EINVAL; |
1402 | 1407 | } |
1403 | 1408 | |
1404 | 1409 | |
1405 | 1410 | |
1406 | 1411 | |
1407 | 1412 | |
1408 | 1413 | |
1409 | 1414 | |
1410 | 1415 | |
... | ... | @@ -1416,44 +1421,60 @@ |
1416 | 1421 | tokens[i] = strsep(&pbuf, ","); |
1417 | 1422 | |
1418 | 1423 | if (pbuf) { |
1419 | - ubi_err("UBI error: too many arguments at \"%s\"\n", val); | |
1424 | + ubi_err("too many arguments at \"%s\"\n", val); | |
1420 | 1425 | return -EINVAL; |
1421 | 1426 | } |
1422 | 1427 | |
1423 | 1428 | p = &mtd_dev_param[mtd_devs]; |
1424 | 1429 | strcpy(&p->name[0], tokens[0]); |
1425 | 1430 | |
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); | |
1428 | 1434 | |
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 | + } | |
1431 | 1438 | |
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); | |
1434 | 1442 | |
1435 | 1443 | 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); | |
1438 | 1446 | return -EINVAL; |
1439 | 1447 | } |
1440 | 1448 | } |
1441 | 1449 | |
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 | + | |
1442 | 1461 | mtd_devs += 1; |
1443 | 1462 | return 0; |
1444 | 1463 | } |
1445 | 1464 | |
1446 | 1465 | 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" | |
1448 | 1467 | "Multiple \"mtd\" parameters may be specified.\n" |
1449 | 1468 | "MTD devices may be specified by their number, name, or path to the MTD character device node.\n" |
1450 | 1469 | "Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0)\n" |
1451 | 1470 | "Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value (" |
1452 | 1471 | __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" | |
1453 | 1473 | "\n" |
1454 | 1474 | "Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n" |
1455 | 1475 | "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" |
1456 | 1476 | "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" | |
1457 | 1478 | "\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device)."); |
1458 | 1479 | #ifdef CONFIG_MTD_UBI_FASTMAP |
1459 | 1480 | module_param(fm_autoconvert, bool, 0644); |
drivers/mtd/ubi/fastmap.c
... | ... | @@ -727,8 +727,10 @@ |
727 | 727 | |
728 | 728 | aeb = NULL; |
729 | 729 | list_for_each_entry(tmp_aeb, &used, u.list) { |
730 | - if (tmp_aeb->pnum == pnum) | |
730 | + if (tmp_aeb->pnum == pnum) { | |
731 | 731 | aeb = tmp_aeb; |
732 | + break; | |
733 | + } | |
732 | 734 | } |
733 | 735 | |
734 | 736 | /* This can happen if a PEB is already in an EBA known |
include/uapi/mtd/ubi-user.h
... | ... | @@ -173,7 +173,10 @@ |
173 | 173 | |
174 | 174 | #define UBI_VOL_IOC_MAGIC 'O' |
175 | 175 | |
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 | + */ | |
177 | 180 | #define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, __s64) |
178 | 181 | /* LEB erasure command, used for debugging, disabled by default */ |
179 | 182 | #define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, __s32) |