diff options
-rw-r--r-- | ubi-utils/include/libubi.h | 12 | ||||
-rw-r--r-- | ubi-utils/libubi.c | 29 | ||||
-rw-r--r-- | ubi-utils/ubiattach.c | 8 |
3 files changed, 43 insertions, 6 deletions
diff --git a/ubi-utils/include/libubi.h b/ubi-utils/include/libubi.h index 84ac84c..47f40e2 100644 --- a/ubi-utils/include/libubi.h +++ b/ubi-utils/include/libubi.h @@ -221,12 +221,14 @@ int mtd_num2ubi_dev(libubi_t desc, int mtd_num, int *dev_num); * @req. If @req->mtd_dev_node is given it should contain path to the MTD * device node. Otherwise @req->mtd_num will be used. * - * Returns %0 in case of success and %-1 in case of failure (errno is set). - * The newly created UBI device number is returned in @req->dev_num. - * The MTD device number is returned in @req->mtd_num (-1 if not found) + * Returns %0 in case of success, %-1 in case of failure (errno is set) and %1 + * if parameter @req->max_beb_per1024 was ignored by kernel (because the kernel + * is old and does not support this feature, which was added in 3.7). The newly + * created UBI device number is returned in @req->dev_num. In the MTD device + * was specified by its device node path, the MTD device number is returned in + * @req->mtd_num. */ -int ubi_attach(libubi_t desc, const char *node, - struct ubi_attach_request *req); +int ubi_attach(libubi_t desc, const char *node, struct ubi_attach_request *req); /** * ubi_detach_mtd - detach an MTD device. diff --git a/ubi-utils/libubi.c b/ubi-utils/libubi.c index 8e1d3ee..a7463e8 100644 --- a/ubi-utils/libubi.c +++ b/ubi-utils/libubi.c @@ -769,6 +769,35 @@ int ubi_attach(libubi_t desc, const char *node, struct ubi_attach_request *req) r.ubi_num = req->dev_num; r.mtd_num = req->mtd_num; r.vid_hdr_offset = req->vid_hdr_offset; + + if (req->max_beb_per1024) { + /* + * We first have to check if the running kernel supports the + * 'max_beb_per1024' parameter. To do this, we invoke the + * "attach" ioctl 2 times: first with incorrect value %-1 of + * 'max_beb_per1024'. + * + * If the ioctl succeeds, it means that the kernel doesn't + * support the feature and just ignored our 'max_beb_per1024' + * value. + * + * If the ioctl returns -EINVAL, we assume this is because + * 'max_beb_per1024' was set to -1, and we invoke the ioctl for + * the second time with the 'max_beb_per1024' value. + */ + r.max_beb_per1024 = -1; + ret = do_attach(node, &r); + if (ret == 0) { + req->dev_num = r.ubi_num; + /* + * The call succeeded. It means that the kernel ignored + * 'max_beb_per1024' parameter. + */ + return 1; + } else if (errno != EINVAL) + return ret; + } + r.max_beb_per1024 = req->max_beb_per1024; ret = do_attach(node, &r); diff --git a/ubi-utils/ubiattach.c b/ubi-utils/ubiattach.c index 8dd0bf6..a7c62d0 100644 --- a/ubi-utils/ubiattach.c +++ b/ubi-utils/ubiattach.c @@ -216,12 +216,18 @@ int main(int argc, char * const argv[]) req.max_beb_per1024 = args.max_beb_per1024; err = ubi_attach(libubi, args.node, &req); - if (err) { + if (err < 0) { if (args.dev) sys_errmsg("cannot attach \"%s\"", args.dev); else sys_errmsg("cannot attach mtd%d", args.mtdn); goto out_libubi; + } else if (err == 1) { + /* The kernel did not support the 'max_beb_per1024' parameter */ + warnmsg("the --max-beb-per1024=%d parameter was ignored", args.max_beb_per1024); + normsg("the UBI kernel driver does not support does not allow changing the reserved PEBs count"); + normsg("the support was added in kernel version 3.7, probably you are running older kernel?"); + goto out_libubi; } /* Print some information about the new UBI device */ |