diff options
-rw-r--r-- | drivers/mtd/ubi/build.c | 59 | ||||
-rw-r--r-- | drivers/mtd/ubi/fastmap.c | 4 | ||||
-rw-r--r-- | include/uapi/mtd/ubi-user.h | 5 |
3 files changed, 47 insertions, 21 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 0aaece9107c7..315dcc6ec1f5 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 3 | 50 | #define MTD_PARAM_MAX_COUNT 4 |
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 |
@@ -67,6 +67,7 @@ | |||
67 | */ | 67 | */ |
68 | struct mtd_dev_param { | 68 | struct mtd_dev_param { |
69 | char name[MTD_PARAM_LEN_MAX]; | 69 | char name[MTD_PARAM_LEN_MAX]; |
70 | int ubi_num; | ||
70 | int vid_hdr_offs; | 71 | int vid_hdr_offs; |
71 | int max_beb_per1024; | 72 | int max_beb_per1024; |
72 | }; | 73 | }; |
@@ -1261,11 +1262,15 @@ static int __init ubi_init(void) | |||
1261 | mtd = open_mtd_device(p->name); | 1262 | mtd = open_mtd_device(p->name); |
1262 | if (IS_ERR(mtd)) { | 1263 | if (IS_ERR(mtd)) { |
1263 | err = PTR_ERR(mtd); | 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 | mutex_lock(&ubi_devices_mutex); | 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 | p->vid_hdr_offs, p->max_beb_per1024); | 1274 | p->vid_hdr_offs, p->max_beb_per1024); |
1270 | mutex_unlock(&ubi_devices_mutex); | 1275 | mutex_unlock(&ubi_devices_mutex); |
1271 | if (err < 0) { | 1276 | if (err < 0) { |
@@ -1309,7 +1314,7 @@ out_version: | |||
1309 | out_class: | 1314 | out_class: |
1310 | class_destroy(ubi_class); | 1315 | class_destroy(ubi_class); |
1311 | out: | 1316 | out: |
1312 | ubi_err("UBI error: cannot initialize UBI, error %d", err); | 1317 | ubi_err("cannot initialize UBI, error %d", err); |
1313 | return err; | 1318 | return err; |
1314 | } | 1319 | } |
1315 | late_initcall(ubi_init); | 1320 | late_initcall(ubi_init); |
@@ -1346,7 +1351,7 @@ static int __init bytes_str_to_int(const char *str) | |||
1346 | 1351 | ||
1347 | result = simple_strtoul(str, &endp, 0); | 1352 | result = simple_strtoul(str, &endp, 0); |
1348 | if (str == endp || result >= INT_MAX) { | 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 | return -EINVAL; | 1355 | return -EINVAL; |
1351 | } | 1356 | } |
1352 | 1357 | ||
@@ -1362,7 +1367,7 @@ static int __init bytes_str_to_int(const char *str) | |||
1362 | case '\0': | 1367 | case '\0': |
1363 | break; | 1368 | break; |
1364 | default: | 1369 | default: |
1365 | ubi_err("UBI error: incorrect bytes count: \"%s\"\n", str); | 1370 | ubi_err("incorrect bytes count: \"%s\"\n", str); |
1366 | return -EINVAL; | 1371 | return -EINVAL; |
1367 | } | 1372 | } |
1368 | 1373 | ||
@@ -1383,20 +1388,20 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) | |||
1383 | struct mtd_dev_param *p; | 1388 | struct mtd_dev_param *p; |
1384 | char buf[MTD_PARAM_LEN_MAX]; | 1389 | char buf[MTD_PARAM_LEN_MAX]; |
1385 | char *pbuf = &buf[0]; | 1390 | char *pbuf = &buf[0]; |
1386 | char *tokens[MTD_PARAM_MAX_COUNT]; | 1391 | char *tokens[MTD_PARAM_MAX_COUNT], *token; |
1387 | 1392 | ||
1388 | if (!val) | 1393 | if (!val) |
1389 | return -EINVAL; | 1394 | return -EINVAL; |
1390 | 1395 | ||
1391 | if (mtd_devs == UBI_MAX_DEVICES) { | 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 | UBI_MAX_DEVICES); | 1398 | UBI_MAX_DEVICES); |
1394 | return -EINVAL; | 1399 | return -EINVAL; |
1395 | } | 1400 | } |
1396 | 1401 | ||
1397 | len = strnlen(val, MTD_PARAM_LEN_MAX); | 1402 | len = strnlen(val, MTD_PARAM_LEN_MAX); |
1398 | if (len == MTD_PARAM_LEN_MAX) { | 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 | val, MTD_PARAM_LEN_MAX); | 1405 | val, MTD_PARAM_LEN_MAX); |
1401 | return -EINVAL; | 1406 | return -EINVAL; |
1402 | } | 1407 | } |
@@ -1416,44 +1421,60 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) | |||
1416 | tokens[i] = strsep(&pbuf, ","); | 1421 | tokens[i] = strsep(&pbuf, ","); |
1417 | 1422 | ||
1418 | if (pbuf) { | 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 | return -EINVAL; | 1425 | return -EINVAL; |
1421 | } | 1426 | } |
1422 | 1427 | ||
1423 | p = &mtd_dev_param[mtd_devs]; | 1428 | p = &mtd_dev_param[mtd_devs]; |
1424 | strcpy(&p->name[0], tokens[0]); | 1429 | strcpy(&p->name[0], tokens[0]); |
1425 | 1430 | ||
1426 | if (tokens[1]) | 1431 | token = tokens[1]; |
1427 | p->vid_hdr_offs = bytes_str_to_int(tokens[1]); | 1432 | if (token) { |
1433 | p->vid_hdr_offs = bytes_str_to_int(token); | ||
1428 | 1434 | ||
1429 | if (p->vid_hdr_offs < 0) | 1435 | if (p->vid_hdr_offs < 0) |
1430 | return p->vid_hdr_offs; | 1436 | return p->vid_hdr_offs; |
1437 | } | ||
1431 | 1438 | ||
1432 | if (tokens[2]) { | 1439 | token = tokens[2]; |
1433 | int err = kstrtoint(tokens[2], 10, &p->max_beb_per1024); | 1440 | if (token) { |
1441 | int err = kstrtoint(token, 10, &p->max_beb_per1024); | ||
1434 | 1442 | ||
1435 | if (err) { | 1443 | if (err) { |
1436 | ubi_err("UBI error: bad value for max_beb_per1024 parameter: %s", | 1444 | ubi_err("bad value for max_beb_per1024 parameter: %s", |
1437 | tokens[2]); | 1445 | token); |
1438 | return -EINVAL; | 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 | mtd_devs += 1; | 1461 | mtd_devs += 1; |
1443 | return 0; | 1462 | return 0; |
1444 | } | 1463 | } |
1445 | 1464 | ||
1446 | module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); | 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 | "Multiple \"mtd\" parameters may be specified.\n" | 1467 | "Multiple \"mtd\" parameters may be specified.\n" |
1449 | "MTD devices may be specified by their number, name, or path to the MTD character device node.\n" | 1468 | "MTD devices may be specified by their number, name, or path to the MTD character device node.\n" |
1450 | "Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0)\n" | 1469 | "Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0)\n" |
1451 | "Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value (" | 1470 | "Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value (" |
1452 | __stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0)\n" | 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 | "\n" | 1473 | "\n" |
1454 | "Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n" | 1474 | "Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n" |
1455 | "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" | 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 | "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" | 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 | "\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device)."); | 1478 | "\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device)."); |
1458 | #ifdef CONFIG_MTD_UBI_FASTMAP | 1479 | #ifdef CONFIG_MTD_UBI_FASTMAP |
1459 | module_param(fm_autoconvert, bool, 0644); | 1480 | module_param(fm_autoconvert, bool, 0644); |
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index 0648c6996d43..154275182b4b 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c | |||
@@ -727,8 +727,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, | |||
727 | 727 | ||
728 | aeb = NULL; | 728 | aeb = NULL; |
729 | list_for_each_entry(tmp_aeb, &used, u.list) { | 729 | list_for_each_entry(tmp_aeb, &used, u.list) { |
730 | if (tmp_aeb->pnum == pnum) | 730 | if (tmp_aeb->pnum == pnum) { |
731 | aeb = tmp_aeb; | 731 | aeb = tmp_aeb; |
732 | break; | ||
733 | } | ||
732 | } | 734 | } |
733 | 735 | ||
734 | /* This can happen if a PEB is already in an EBA known | 736 | /* This can happen if a PEB is already in an EBA known |
diff --git a/include/uapi/mtd/ubi-user.h b/include/uapi/mtd/ubi-user.h index 53cae1e11e57..723c324590c1 100644 --- a/include/uapi/mtd/ubi-user.h +++ b/include/uapi/mtd/ubi-user.h | |||
@@ -173,7 +173,10 @@ | |||
173 | 173 | ||
174 | #define UBI_VOL_IOC_MAGIC 'O' | 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 | #define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, __s64) | 180 | #define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, __s64) |
178 | /* LEB erasure command, used for debugging, disabled by default */ | 181 | /* LEB erasure command, used for debugging, disabled by default */ |
179 | #define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, __s32) | 182 | #define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, __s32) |