2 * Copyright (c) International Business Machines Corp., 2006
3 * Copyright (c) Nokia Corporation, 2007
5 * SPDX-License-Identifier: GPL-2.0+
7 * Author: Artem Bityutskiy (Битюцкий Артём),
12 * This file includes UBI initialization and building of UBI devices.
14 * When UBI is initialized, it attaches all the MTD devices specified as the
15 * module load parameters or the kernel boot parameters. If MTD devices were
16 * specified, UBI does not attach any MTD device, but it is possible to do
17 * later using the "UBI control device".
21 #include <linux/module.h>
22 #include <linux/moduleparam.h>
23 #include <linux/stringify.h>
24 #include <linux/namei.h>
25 #include <linux/stat.h>
26 #include <linux/miscdevice.h>
27 #include <linux/log2.h>
28 #include <linux/kthread.h>
29 #include <linux/kernel.h>
30 #include <linux/slab.h>
31 #include <linux/major.h>
33 #include <linux/compat.h>
35 #include <linux/err.h>
36 #include <ubi_uboot.h>
37 #include <linux/mtd/partitions.h>
41 /* Maximum length of the 'mtd=' parameter */
42 #define MTD_PARAM_LEN_MAX 64
44 /* Maximum number of comma-separated items in the 'mtd=' parameter */
45 #define MTD_PARAM_MAX_COUNT 4
47 /* Maximum value for the number of bad PEBs per 1024 PEBs */
48 #define MAX_MTD_UBI_BEB_LIMIT 768
50 #ifdef CONFIG_MTD_UBI_MODULE
51 #define ubi_is_module() 1
53 #define ubi_is_module() 0
56 #if (CONFIG_SYS_MALLOC_LEN < (512 << 10))
57 #error Malloc area too small for UBI, increase CONFIG_SYS_MALLOC_LEN to >= 512k
61 * struct mtd_dev_param - MTD device parameter description data structure.
62 * @name: MTD character device node path, MTD device name, or MTD device number
64 * @vid_hdr_offs: VID header offset
65 * @max_beb_per1024: maximum expected number of bad PEBs per 1024 PEBs
67 struct mtd_dev_param {
68 char name[MTD_PARAM_LEN_MAX];
74 /* Numbers of elements set in the @mtd_dev_param array */
75 static int __initdata mtd_devs;
77 /* MTD devices specification parameters */
78 static struct mtd_dev_param __initdata mtd_dev_param[UBI_MAX_DEVICES];
80 #ifdef CONFIG_MTD_UBI_FASTMAP
81 /* UBI module parameter to enable fastmap automatically on non-fastmap images */
82 static bool fm_autoconvert;
85 #ifdef CONFIG_MTD_UBI_FASTMAP
86 #if !defined(CONFIG_MTD_UBI_FASTMAP_AUTOCONVERT)
87 #define CONFIG_MTD_UBI_FASTMAP_AUTOCONVERT 0
89 static bool fm_autoconvert = CONFIG_MTD_UBI_FASTMAP_AUTOCONVERT;
92 /* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */
93 struct class *ubi_class;
95 /* Slab cache for wear-leveling entries */
96 struct kmem_cache *ubi_wl_entry_slab;
99 /* UBI control character device */
100 static struct miscdevice ubi_ctrl_cdev = {
101 .minor = MISC_DYNAMIC_MINOR,
103 .fops = &ubi_ctrl_cdev_operations,
107 /* All UBI devices in system */
109 static struct ubi_device *ubi_devices[UBI_MAX_DEVICES];
111 struct ubi_device *ubi_devices[UBI_MAX_DEVICES];
115 /* Serializes UBI devices creations and removals */
116 DEFINE_MUTEX(ubi_devices_mutex);
118 /* Protects @ubi_devices and @ubi->ref_count */
119 static DEFINE_SPINLOCK(ubi_devices_lock);
121 /* "Show" method for files in '/<sysfs>/class/ubi/' */
122 static ssize_t ubi_version_show(struct class *class,
123 struct class_attribute *attr, char *buf)
125 return sprintf(buf, "%d\n", UBI_VERSION);
128 /* UBI version attribute ('/<sysfs>/class/ubi/version') */
129 static struct class_attribute ubi_version =
130 __ATTR(version, S_IRUGO, ubi_version_show, NULL);
132 static ssize_t dev_attribute_show(struct device *dev,
133 struct device_attribute *attr, char *buf);
135 /* UBI device attributes (correspond to files in '/<sysfs>/class/ubi/ubiX') */
136 static struct device_attribute dev_eraseblock_size =
137 __ATTR(eraseblock_size, S_IRUGO, dev_attribute_show, NULL);
138 static struct device_attribute dev_avail_eraseblocks =
139 __ATTR(avail_eraseblocks, S_IRUGO, dev_attribute_show, NULL);
140 static struct device_attribute dev_total_eraseblocks =
141 __ATTR(total_eraseblocks, S_IRUGO, dev_attribute_show, NULL);
142 static struct device_attribute dev_volumes_count =
143 __ATTR(volumes_count, S_IRUGO, dev_attribute_show, NULL);
144 static struct device_attribute dev_max_ec =
145 __ATTR(max_ec, S_IRUGO, dev_attribute_show, NULL);
146 static struct device_attribute dev_reserved_for_bad =
147 __ATTR(reserved_for_bad, S_IRUGO, dev_attribute_show, NULL);
148 static struct device_attribute dev_bad_peb_count =
149 __ATTR(bad_peb_count, S_IRUGO, dev_attribute_show, NULL);
150 static struct device_attribute dev_max_vol_count =
151 __ATTR(max_vol_count, S_IRUGO, dev_attribute_show, NULL);
152 static struct device_attribute dev_min_io_size =
153 __ATTR(min_io_size, S_IRUGO, dev_attribute_show, NULL);
154 static struct device_attribute dev_bgt_enabled =
155 __ATTR(bgt_enabled, S_IRUGO, dev_attribute_show, NULL);
156 static struct device_attribute dev_mtd_num =
157 __ATTR(mtd_num, S_IRUGO, dev_attribute_show, NULL);
161 * ubi_volume_notify - send a volume change notification.
162 * @ubi: UBI device description object
163 * @vol: volume description object of the changed volume
164 * @ntype: notification type to send (%UBI_VOLUME_ADDED, etc)
166 * This is a helper function which notifies all subscribers about a volume
167 * change event (creation, removal, re-sizing, re-naming, updating). Returns
168 * zero in case of success and a negative error code in case of failure.
170 int ubi_volume_notify(struct ubi_device *ubi, struct ubi_volume *vol, int ntype)
172 struct ubi_notification nt;
174 ubi_do_get_device_info(ubi, &nt.di);
175 ubi_do_get_volume_info(ubi, vol, &nt.vi);
177 #ifdef CONFIG_MTD_UBI_FASTMAP
179 case UBI_VOLUME_ADDED:
180 case UBI_VOLUME_REMOVED:
181 case UBI_VOLUME_RESIZED:
182 case UBI_VOLUME_RENAMED:
183 if (ubi_update_fastmap(ubi)) {
184 ubi_err("Unable to update fastmap!");
189 return blocking_notifier_call_chain(&ubi_notifiers, ntype, &nt);
193 * ubi_notify_all - send a notification to all volumes.
194 * @ubi: UBI device description object
195 * @ntype: notification type to send (%UBI_VOLUME_ADDED, etc)
196 * @nb: the notifier to call
198 * This function walks all volumes of UBI device @ubi and sends the @ntype
199 * notification for each volume. If @nb is %NULL, then all registered notifiers
200 * are called, otherwise only the @nb notifier is called. Returns the number of
201 * sent notifications.
203 int ubi_notify_all(struct ubi_device *ubi, int ntype, struct notifier_block *nb)
205 struct ubi_notification nt;
211 ubi_do_get_device_info(ubi, &nt.di);
213 mutex_lock(&ubi->device_mutex);
214 for (i = 0; i < ubi->vtbl_slots; i++) {
216 * Since the @ubi->device is locked, and we are not going to
217 * change @ubi->volumes, we do not have to lock
218 * @ubi->volumes_lock.
220 if (!ubi->volumes[i])
223 ubi_do_get_volume_info(ubi, ubi->volumes[i], &nt.vi);
226 nb->notifier_call(nb, ntype, &nt);
228 ret = blocking_notifier_call_chain(&ubi_notifiers, ntype,
233 mutex_unlock(&ubi->device_mutex);
239 * ubi_enumerate_volumes - send "add" notification for all existing volumes.
240 * @nb: the notifier to call
242 * This function walks all UBI devices and volumes and sends the
243 * %UBI_VOLUME_ADDED notification for each volume. If @nb is %NULL, then all
244 * registered notifiers are called, otherwise only the @nb notifier is called.
245 * Returns the number of sent notifications.
247 int ubi_enumerate_volumes(struct notifier_block *nb)
252 * Since the @ubi_devices_mutex is locked, and we are not going to
253 * change @ubi_devices, we do not have to lock @ubi_devices_lock.
255 for (i = 0; i < UBI_MAX_DEVICES; i++) {
256 struct ubi_device *ubi = ubi_devices[i];
260 count += ubi_notify_all(ubi, UBI_VOLUME_ADDED, nb);
267 * ubi_get_device - get UBI device.
268 * @ubi_num: UBI device number
270 * This function returns UBI device description object for UBI device number
271 * @ubi_num, or %NULL if the device does not exist. This function increases the
272 * device reference count to prevent removal of the device. In other words, the
273 * device cannot be removed if its reference count is not zero.
275 struct ubi_device *ubi_get_device(int ubi_num)
277 struct ubi_device *ubi;
279 spin_lock(&ubi_devices_lock);
280 ubi = ubi_devices[ubi_num];
282 ubi_assert(ubi->ref_count >= 0);
284 get_device(&ubi->dev);
286 spin_unlock(&ubi_devices_lock);
292 * ubi_put_device - drop an UBI device reference.
293 * @ubi: UBI device description object
295 void ubi_put_device(struct ubi_device *ubi)
297 spin_lock(&ubi_devices_lock);
299 put_device(&ubi->dev);
300 spin_unlock(&ubi_devices_lock);
304 * ubi_get_by_major - get UBI device by character device major number.
305 * @major: major number
307 * This function is similar to 'ubi_get_device()', but it searches the device
308 * by its major number.
310 struct ubi_device *ubi_get_by_major(int major)
313 struct ubi_device *ubi;
315 spin_lock(&ubi_devices_lock);
316 for (i = 0; i < UBI_MAX_DEVICES; i++) {
317 ubi = ubi_devices[i];
318 if (ubi && MAJOR(ubi->cdev.dev) == major) {
319 ubi_assert(ubi->ref_count >= 0);
321 get_device(&ubi->dev);
322 spin_unlock(&ubi_devices_lock);
326 spin_unlock(&ubi_devices_lock);
332 * ubi_major2num - get UBI device number by character device major number.
333 * @major: major number
335 * This function searches UBI device number object by its major number. If UBI
336 * device was not found, this function returns -ENODEV, otherwise the UBI device
337 * number is returned.
339 int ubi_major2num(int major)
341 int i, ubi_num = -ENODEV;
343 spin_lock(&ubi_devices_lock);
344 for (i = 0; i < UBI_MAX_DEVICES; i++) {
345 struct ubi_device *ubi = ubi_devices[i];
347 if (ubi && MAJOR(ubi->cdev.dev) == major) {
348 ubi_num = ubi->ubi_num;
352 spin_unlock(&ubi_devices_lock);
358 /* "Show" method for files in '/<sysfs>/class/ubi/ubiX/' */
359 static ssize_t dev_attribute_show(struct device *dev,
360 struct device_attribute *attr, char *buf)
363 struct ubi_device *ubi;
366 * The below code looks weird, but it actually makes sense. We get the
367 * UBI device reference from the contained 'struct ubi_device'. But it
368 * is unclear if the device was removed or not yet. Indeed, if the
369 * device was removed before we increased its reference count,
370 * 'ubi_get_device()' will return -ENODEV and we fail.
372 * Remember, 'struct ubi_device' is freed in the release function, so
373 * we still can use 'ubi->ubi_num'.
375 ubi = container_of(dev, struct ubi_device, dev);
376 ubi = ubi_get_device(ubi->ubi_num);
380 if (attr == &dev_eraseblock_size)
381 ret = sprintf(buf, "%d\n", ubi->leb_size);
382 else if (attr == &dev_avail_eraseblocks)
383 ret = sprintf(buf, "%d\n", ubi->avail_pebs);
384 else if (attr == &dev_total_eraseblocks)
385 ret = sprintf(buf, "%d\n", ubi->good_peb_count);
386 else if (attr == &dev_volumes_count)
387 ret = sprintf(buf, "%d\n", ubi->vol_count - UBI_INT_VOL_COUNT);
388 else if (attr == &dev_max_ec)
389 ret = sprintf(buf, "%d\n", ubi->max_ec);
390 else if (attr == &dev_reserved_for_bad)
391 ret = sprintf(buf, "%d\n", ubi->beb_rsvd_pebs);
392 else if (attr == &dev_bad_peb_count)
393 ret = sprintf(buf, "%d\n", ubi->bad_peb_count);
394 else if (attr == &dev_max_vol_count)
395 ret = sprintf(buf, "%d\n", ubi->vtbl_slots);
396 else if (attr == &dev_min_io_size)
397 ret = sprintf(buf, "%d\n", ubi->min_io_size);
398 else if (attr == &dev_bgt_enabled)
399 ret = sprintf(buf, "%d\n", ubi->thread_enabled);
400 else if (attr == &dev_mtd_num)
401 ret = sprintf(buf, "%d\n", ubi->mtd->index);
409 static void dev_release(struct device *dev)
411 struct ubi_device *ubi = container_of(dev, struct ubi_device, dev);
417 * ubi_sysfs_init - initialize sysfs for an UBI device.
418 * @ubi: UBI device description object
419 * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was
422 * This function returns zero in case of success and a negative error code in
425 static int ubi_sysfs_init(struct ubi_device *ubi, int *ref)
429 ubi->dev.release = dev_release;
430 ubi->dev.devt = ubi->cdev.dev;
431 ubi->dev.class = ubi_class;
432 dev_set_name(&ubi->dev, UBI_NAME_STR"%d", ubi->ubi_num);
433 err = device_register(&ubi->dev);
438 err = device_create_file(&ubi->dev, &dev_eraseblock_size);
441 err = device_create_file(&ubi->dev, &dev_avail_eraseblocks);
444 err = device_create_file(&ubi->dev, &dev_total_eraseblocks);
447 err = device_create_file(&ubi->dev, &dev_volumes_count);
450 err = device_create_file(&ubi->dev, &dev_max_ec);
453 err = device_create_file(&ubi->dev, &dev_reserved_for_bad);
456 err = device_create_file(&ubi->dev, &dev_bad_peb_count);
459 err = device_create_file(&ubi->dev, &dev_max_vol_count);
462 err = device_create_file(&ubi->dev, &dev_min_io_size);
465 err = device_create_file(&ubi->dev, &dev_bgt_enabled);
468 err = device_create_file(&ubi->dev, &dev_mtd_num);
473 * ubi_sysfs_close - close sysfs for an UBI device.
474 * @ubi: UBI device description object
476 static void ubi_sysfs_close(struct ubi_device *ubi)
478 device_remove_file(&ubi->dev, &dev_mtd_num);
479 device_remove_file(&ubi->dev, &dev_bgt_enabled);
480 device_remove_file(&ubi->dev, &dev_min_io_size);
481 device_remove_file(&ubi->dev, &dev_max_vol_count);
482 device_remove_file(&ubi->dev, &dev_bad_peb_count);
483 device_remove_file(&ubi->dev, &dev_reserved_for_bad);
484 device_remove_file(&ubi->dev, &dev_max_ec);
485 device_remove_file(&ubi->dev, &dev_volumes_count);
486 device_remove_file(&ubi->dev, &dev_total_eraseblocks);
487 device_remove_file(&ubi->dev, &dev_avail_eraseblocks);
488 device_remove_file(&ubi->dev, &dev_eraseblock_size);
489 device_unregister(&ubi->dev);
494 * kill_volumes - destroy all user volumes.
495 * @ubi: UBI device description object
497 static void kill_volumes(struct ubi_device *ubi)
501 for (i = 0; i < ubi->vtbl_slots; i++)
503 ubi_free_volume(ubi, ubi->volumes[i]);
507 * uif_init - initialize user interfaces for an UBI device.
508 * @ubi: UBI device description object
509 * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was
510 * taken, otherwise set to %0
512 * This function initializes various user interfaces for an UBI device. If the
513 * initialization fails at an early stage, this function frees all the
514 * resources it allocated, returns an error, and @ref is set to %0. However,
515 * if the initialization fails after the UBI device was registered in the
516 * driver core subsystem, this function takes a reference to @ubi->dev, because
517 * otherwise the release function ('dev_release()') would free whole @ubi
518 * object. The @ref argument is set to %1 in this case. The caller has to put
521 * This function returns zero in case of success and a negative error code in
524 static int uif_init(struct ubi_device *ubi, int *ref)
532 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num);
535 * Major numbers for the UBI character devices are allocated
536 * dynamically. Major numbers of volume character devices are
537 * equivalent to ones of the corresponding UBI character device. Minor
538 * numbers of UBI character devices are 0, while minor numbers of
539 * volume character devices start from 1. Thus, we allocate one major
540 * number and ubi->vtbl_slots + 1 minor numbers.
542 err = alloc_chrdev_region(&dev, 0, ubi->vtbl_slots + 1, ubi->ubi_name);
544 ubi_err("cannot register UBI character devices");
548 ubi_assert(MINOR(dev) == 0);
549 cdev_init(&ubi->cdev, &ubi_cdev_operations);
550 dbg_gen("%s major is %u", ubi->ubi_name, MAJOR(dev));
551 ubi->cdev.owner = THIS_MODULE;
553 err = cdev_add(&ubi->cdev, dev, 1);
555 ubi_err("cannot add character device");
559 err = ubi_sysfs_init(ubi, ref);
563 for (i = 0; i < ubi->vtbl_slots; i++)
564 if (ubi->volumes[i]) {
565 err = ubi_add_volume(ubi, ubi->volumes[i]);
567 ubi_err("cannot add volume %d", i);
578 get_device(&ubi->dev);
579 ubi_sysfs_close(ubi);
580 cdev_del(&ubi->cdev);
582 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1);
583 ubi_err("cannot initialize UBI %s, error %d", ubi->ubi_name, err);
588 * uif_close - close user interfaces for an UBI device.
589 * @ubi: UBI device description object
591 * Note, since this function un-registers UBI volume device objects (@vol->dev),
592 * the memory allocated voe the volumes is freed as well (in the release
595 static void uif_close(struct ubi_device *ubi)
598 ubi_sysfs_close(ubi);
599 cdev_del(&ubi->cdev);
600 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1);
604 * ubi_free_internal_volumes - free internal volumes.
605 * @ubi: UBI device description object
607 void ubi_free_internal_volumes(struct ubi_device *ubi)
611 for (i = ubi->vtbl_slots;
612 i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
613 kfree(ubi->volumes[i]->eba_tbl);
614 kfree(ubi->volumes[i]);
618 static int get_bad_peb_limit(const struct ubi_device *ubi, int max_beb_per1024)
620 int limit, device_pebs;
621 uint64_t device_size;
623 if (!max_beb_per1024)
627 * Here we are using size of the entire flash chip and
628 * not just the MTD partition size because the maximum
629 * number of bad eraseblocks is a percentage of the
630 * whole device and bad eraseblocks are not fairly
631 * distributed over the flash chip. So the worst case
632 * is that all the bad eraseblocks of the chip are in
633 * the MTD partition we are attaching (ubi->mtd).
635 device_size = mtd_get_device_size(ubi->mtd);
636 device_pebs = mtd_div_by_eb(device_size, ubi->mtd);
637 limit = mult_frac(device_pebs, max_beb_per1024, 1024);
640 if (mult_frac(limit, 1024, max_beb_per1024) < device_pebs)
647 * io_init - initialize I/O sub-system for a given UBI device.
648 * @ubi: UBI device description object
649 * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs
651 * If @ubi->vid_hdr_offset or @ubi->leb_start is zero, default offsets are
653 * o EC header is always at offset zero - this cannot be changed;
654 * o VID header starts just after the EC header at the closest address
655 * aligned to @io->hdrs_min_io_size;
656 * o data starts just after the VID header at the closest address aligned to
659 * This function returns zero in case of success and a negative error code in
662 static int io_init(struct ubi_device *ubi, int max_beb_per1024)
664 dbg_gen("sizeof(struct ubi_ainf_peb) %zu", sizeof(struct ubi_ainf_peb));
665 dbg_gen("sizeof(struct ubi_wl_entry) %zu", sizeof(struct ubi_wl_entry));
667 if (ubi->mtd->numeraseregions != 0) {
669 * Some flashes have several erase regions. Different regions
670 * may have different eraseblock size and other
671 * characteristics. It looks like mostly multi-region flashes
672 * have one "main" region and one or more small regions to
673 * store boot loader code or boot parameters or whatever. I
674 * guess we should just pick the largest region. But this is
677 ubi_err("multiple regions, not implemented");
681 if (ubi->vid_hdr_offset < 0)
685 * Note, in this implementation we support MTD devices with 0x7FFFFFFF
686 * physical eraseblocks maximum.
689 ubi->peb_size = ubi->mtd->erasesize;
690 ubi->peb_count = mtd_div_by_eb(ubi->mtd->size, ubi->mtd);
691 ubi->flash_size = ubi->mtd->size;
693 if (mtd_can_have_bb(ubi->mtd)) {
694 ubi->bad_allowed = 1;
695 ubi->bad_peb_limit = get_bad_peb_limit(ubi, max_beb_per1024);
698 if (ubi->mtd->type == MTD_NORFLASH) {
699 ubi_assert(ubi->mtd->writesize == 1);
703 ubi->min_io_size = ubi->mtd->writesize;
704 ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft;
707 * Make sure minimal I/O unit is power of 2. Note, there is no
708 * fundamental reason for this assumption. It is just an optimization
709 * which allows us to avoid costly division operations.
711 if (!is_power_of_2(ubi->min_io_size)) {
712 ubi_err("min. I/O unit (%d) is not power of 2",
717 ubi_assert(ubi->hdrs_min_io_size > 0);
718 ubi_assert(ubi->hdrs_min_io_size <= ubi->min_io_size);
719 ubi_assert(ubi->min_io_size % ubi->hdrs_min_io_size == 0);
721 ubi->max_write_size = ubi->mtd->writebufsize;
723 * Maximum write size has to be greater or equivalent to min. I/O
724 * size, and be multiple of min. I/O size.
726 if (ubi->max_write_size < ubi->min_io_size ||
727 ubi->max_write_size % ubi->min_io_size ||
728 !is_power_of_2(ubi->max_write_size)) {
729 ubi_err("bad write buffer size %d for %d min. I/O unit",
730 ubi->max_write_size, ubi->min_io_size);
734 /* Calculate default aligned sizes of EC and VID headers */
735 ubi->ec_hdr_alsize = ALIGN(UBI_EC_HDR_SIZE, ubi->hdrs_min_io_size);
736 ubi->vid_hdr_alsize = ALIGN(UBI_VID_HDR_SIZE, ubi->hdrs_min_io_size);
738 dbg_gen("min_io_size %d", ubi->min_io_size);
739 dbg_gen("max_write_size %d", ubi->max_write_size);
740 dbg_gen("hdrs_min_io_size %d", ubi->hdrs_min_io_size);
741 dbg_gen("ec_hdr_alsize %d", ubi->ec_hdr_alsize);
742 dbg_gen("vid_hdr_alsize %d", ubi->vid_hdr_alsize);
744 if (ubi->vid_hdr_offset == 0)
746 ubi->vid_hdr_offset = ubi->vid_hdr_aloffset =
749 ubi->vid_hdr_aloffset = ubi->vid_hdr_offset &
750 ~(ubi->hdrs_min_io_size - 1);
751 ubi->vid_hdr_shift = ubi->vid_hdr_offset -
752 ubi->vid_hdr_aloffset;
755 /* Similar for the data offset */
756 ubi->leb_start = ubi->vid_hdr_offset + UBI_VID_HDR_SIZE;
757 ubi->leb_start = ALIGN(ubi->leb_start, ubi->min_io_size);
759 dbg_gen("vid_hdr_offset %d", ubi->vid_hdr_offset);
760 dbg_gen("vid_hdr_aloffset %d", ubi->vid_hdr_aloffset);
761 dbg_gen("vid_hdr_shift %d", ubi->vid_hdr_shift);
762 dbg_gen("leb_start %d", ubi->leb_start);
764 /* The shift must be aligned to 32-bit boundary */
765 if (ubi->vid_hdr_shift % 4) {
766 ubi_err("unaligned VID header shift %d",
772 if (ubi->vid_hdr_offset < UBI_EC_HDR_SIZE ||
773 ubi->leb_start < ubi->vid_hdr_offset + UBI_VID_HDR_SIZE ||
774 ubi->leb_start > ubi->peb_size - UBI_VID_HDR_SIZE ||
775 ubi->leb_start & (ubi->min_io_size - 1)) {
776 ubi_err("bad VID header (%d) or data offsets (%d)",
777 ubi->vid_hdr_offset, ubi->leb_start);
782 * Set maximum amount of physical erroneous eraseblocks to be 10%.
783 * Erroneous PEB are those which have read errors.
785 ubi->max_erroneous = ubi->peb_count / 10;
786 if (ubi->max_erroneous < 16)
787 ubi->max_erroneous = 16;
788 dbg_gen("max_erroneous %d", ubi->max_erroneous);
791 * It may happen that EC and VID headers are situated in one minimal
792 * I/O unit. In this case we can only accept this UBI image in
795 if (ubi->vid_hdr_offset + UBI_VID_HDR_SIZE <= ubi->hdrs_min_io_size) {
796 ubi_warn("EC and VID headers are in the same minimal I/O unit, switch to read-only mode");
800 ubi->leb_size = ubi->peb_size - ubi->leb_start;
802 if (!(ubi->mtd->flags & MTD_WRITEABLE)) {
803 ubi_msg("MTD device %d is write-protected, attach in read-only mode",
809 * Note, ideally, we have to initialize @ubi->bad_peb_count here. But
810 * unfortunately, MTD does not provide this information. We should loop
811 * over all physical eraseblocks and invoke mtd->block_is_bad() for
812 * each physical eraseblock. So, we leave @ubi->bad_peb_count
813 * uninitialized so far.
820 * autoresize - re-size the volume which has the "auto-resize" flag set.
821 * @ubi: UBI device description object
822 * @vol_id: ID of the volume to re-size
824 * This function re-sizes the volume marked by the %UBI_VTBL_AUTORESIZE_FLG in
825 * the volume table to the largest possible size. See comments in ubi-header.h
826 * for more description of the flag. Returns zero in case of success and a
827 * negative error code in case of failure.
829 static int autoresize(struct ubi_device *ubi, int vol_id)
831 struct ubi_volume_desc desc;
832 struct ubi_volume *vol = ubi->volumes[vol_id];
833 int err, old_reserved_pebs = vol->reserved_pebs;
836 ubi_warn("skip auto-resize because of R/O mode");
841 * Clear the auto-resize flag in the volume in-memory copy of the
842 * volume table, and 'ubi_resize_volume()' will propagate this change
845 ubi->vtbl[vol_id].flags &= ~UBI_VTBL_AUTORESIZE_FLG;
847 if (ubi->avail_pebs == 0) {
848 struct ubi_vtbl_record vtbl_rec;
851 * No available PEBs to re-size the volume, clear the flag on
854 vtbl_rec = ubi->vtbl[vol_id];
855 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
857 ubi_err("cannot clean auto-resize flag for volume %d",
861 err = ubi_resize_volume(&desc,
862 old_reserved_pebs + ubi->avail_pebs);
864 ubi_err("cannot auto-resize volume %d", vol_id);
870 ubi_msg("volume %d (\"%s\") re-sized from %d to %d LEBs", vol_id,
871 vol->name, old_reserved_pebs, vol->reserved_pebs);
876 * ubi_attach_mtd_dev - attach an MTD device.
877 * @mtd: MTD device description object
878 * @ubi_num: number to assign to the new UBI device
879 * @vid_hdr_offset: VID header offset
880 * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs
882 * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number
883 * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in
884 * which case this function finds a vacant device number and assigns it
885 * automatically. Returns the new UBI device number in case of success and a
886 * negative error code in case of failure.
888 * Note, the invocations of this function has to be serialized by the
889 * @ubi_devices_mutex.
891 int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
892 int vid_hdr_offset, int max_beb_per1024)
894 struct ubi_device *ubi;
897 if (max_beb_per1024 < 0 || max_beb_per1024 > MAX_MTD_UBI_BEB_LIMIT)
900 if (!max_beb_per1024)
901 max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT;
904 * Check if we already have the same MTD device attached.
906 * Note, this function assumes that UBI devices creations and deletions
907 * are serialized, so it does not take the &ubi_devices_lock.
909 for (i = 0; i < UBI_MAX_DEVICES; i++) {
910 ubi = ubi_devices[i];
911 if (ubi && mtd->index == ubi->mtd->index) {
912 ubi_err("mtd%d is already attached to ubi%d",
919 * Make sure this MTD device is not emulated on top of an UBI volume
920 * already. Well, generally this recursion works fine, but there are
921 * different problems like the UBI module takes a reference to itself
922 * by attaching (and thus, opening) the emulated MTD device. This
923 * results in inability to unload the module. And in general it makes
924 * no sense to attach emulated MTD devices, so we prohibit this.
926 if (mtd->type == MTD_UBIVOLUME) {
927 ubi_err("refuse attaching mtd%d - it is already emulated on top of UBI",
932 if (ubi_num == UBI_DEV_NUM_AUTO) {
933 /* Search for an empty slot in the @ubi_devices array */
934 for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++)
935 if (!ubi_devices[ubi_num])
937 if (ubi_num == UBI_MAX_DEVICES) {
938 ubi_err("only %d UBI devices may be created",
943 if (ubi_num >= UBI_MAX_DEVICES)
946 /* Make sure ubi_num is not busy */
947 if (ubi_devices[ubi_num]) {
948 ubi_err("ubi%d already exists", ubi_num);
953 ubi = kzalloc(sizeof(struct ubi_device), GFP_KERNEL);
958 ubi->ubi_num = ubi_num;
959 ubi->vid_hdr_offset = vid_hdr_offset;
960 ubi->autoresize_vol_id = -1;
962 #ifdef CONFIG_MTD_UBI_FASTMAP
963 ubi->fm_pool.used = ubi->fm_pool.size = 0;
964 ubi->fm_wl_pool.used = ubi->fm_wl_pool.size = 0;
967 * fm_pool.max_size is 5% of the total number of PEBs but it's also
968 * between UBI_FM_MAX_POOL_SIZE and UBI_FM_MIN_POOL_SIZE.
970 ubi->fm_pool.max_size = min(((int)mtd_div_by_eb(ubi->mtd->size,
971 ubi->mtd) / 100) * 5, UBI_FM_MAX_POOL_SIZE);
972 if (ubi->fm_pool.max_size < UBI_FM_MIN_POOL_SIZE)
973 ubi->fm_pool.max_size = UBI_FM_MIN_POOL_SIZE;
975 ubi->fm_wl_pool.max_size = UBI_FM_WL_POOL_SIZE;
976 ubi->fm_disabled = !fm_autoconvert;
978 if (!ubi->fm_disabled && (int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd)
979 <= UBI_FM_MAX_START) {
980 ubi_err("More than %i PEBs are needed for fastmap, sorry.",
982 ubi->fm_disabled = 1;
985 ubi_msg("default fastmap pool size: %d", ubi->fm_pool.max_size);
986 ubi_msg("default fastmap WL pool size: %d", ubi->fm_wl_pool.max_size);
988 ubi->fm_disabled = 1;
990 mutex_init(&ubi->buf_mutex);
991 mutex_init(&ubi->ckvol_mutex);
992 mutex_init(&ubi->device_mutex);
993 spin_lock_init(&ubi->volumes_lock);
994 mutex_init(&ubi->fm_mutex);
995 init_rwsem(&ubi->fm_sem);
997 ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num);
999 err = io_init(ubi, max_beb_per1024);
1004 ubi->peb_buf = vmalloc(ubi->peb_size);
1008 #ifdef CONFIG_MTD_UBI_FASTMAP
1009 ubi->fm_size = ubi_calc_fm_size(ubi);
1010 ubi->fm_buf = vzalloc(ubi->fm_size);
1014 err = ubi_attach(ubi, 0);
1016 ubi_err("failed to attach mtd%d, error %d", mtd->index, err);
1020 if (ubi->autoresize_vol_id != -1) {
1021 err = autoresize(ubi, ubi->autoresize_vol_id);
1026 err = uif_init(ubi, &ref);
1030 err = ubi_debugfs_init_dev(ubi);
1034 ubi->bgt_thread = kthread_create(ubi_thread, ubi, "%s", ubi->bgt_name);
1035 if (IS_ERR(ubi->bgt_thread)) {
1036 err = PTR_ERR(ubi->bgt_thread);
1037 ubi_err("cannot spawn \"%s\", error %d", ubi->bgt_name,
1042 ubi_msg("attached mtd%d (name \"%s\", size %llu MiB) to ubi%d",
1043 mtd->index, mtd->name, ubi->flash_size >> 20, ubi_num);
1044 ubi_msg("PEB size: %d bytes (%d KiB), LEB size: %d bytes",
1045 ubi->peb_size, ubi->peb_size >> 10, ubi->leb_size);
1046 ubi_msg("min./max. I/O unit sizes: %d/%d, sub-page size %d",
1047 ubi->min_io_size, ubi->max_write_size, ubi->hdrs_min_io_size);
1048 ubi_msg("VID header offset: %d (aligned %d), data offset: %d",
1049 ubi->vid_hdr_offset, ubi->vid_hdr_aloffset, ubi->leb_start);
1050 ubi_msg("good PEBs: %d, bad PEBs: %d, corrupted PEBs: %d",
1051 ubi->good_peb_count, ubi->bad_peb_count, ubi->corr_peb_count);
1052 ubi_msg("user volume: %d, internal volumes: %d, max. volumes count: %d",
1053 ubi->vol_count - UBI_INT_VOL_COUNT, UBI_INT_VOL_COUNT,
1055 ubi_msg("max/mean erase counter: %d/%d, WL threshold: %d, image sequence number: %u",
1056 ubi->max_ec, ubi->mean_ec, CONFIG_MTD_UBI_WL_THRESHOLD,
1058 ubi_msg("available PEBs: %d, total reserved PEBs: %d, PEBs reserved for bad PEB handling: %d",
1059 ubi->avail_pebs, ubi->rsvd_pebs, ubi->beb_rsvd_pebs);
1062 * The below lock makes sure we do not race with 'ubi_thread()' which
1063 * checks @ubi->thread_enabled. Otherwise we may fail to wake it up.
1065 spin_lock(&ubi->wl_lock);
1066 ubi->thread_enabled = 1;
1067 wake_up_process(ubi->bgt_thread);
1068 spin_unlock(&ubi->wl_lock);
1070 ubi_devices[ubi_num] = ubi;
1071 ubi_notify_all(ubi, UBI_VOLUME_ADDED, NULL);
1075 ubi_debugfs_exit_dev(ubi);
1077 get_device(&ubi->dev);
1082 ubi_free_internal_volumes(ubi);
1085 vfree(ubi->peb_buf);
1088 put_device(&ubi->dev);
1095 * ubi_detach_mtd_dev - detach an MTD device.
1096 * @ubi_num: UBI device number to detach from
1097 * @anyway: detach MTD even if device reference count is not zero
1099 * This function destroys an UBI device number @ubi_num and detaches the
1100 * underlying MTD device. Returns zero in case of success and %-EBUSY if the
1101 * UBI device is busy and cannot be destroyed, and %-EINVAL if it does not
1104 * Note, the invocations of this function has to be serialized by the
1105 * @ubi_devices_mutex.
1107 int ubi_detach_mtd_dev(int ubi_num, int anyway)
1109 struct ubi_device *ubi;
1111 if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES)
1114 ubi = ubi_get_device(ubi_num);
1118 spin_lock(&ubi_devices_lock);
1119 put_device(&ubi->dev);
1120 ubi->ref_count -= 1;
1121 if (ubi->ref_count) {
1123 spin_unlock(&ubi_devices_lock);
1126 /* This may only happen if there is a bug */
1127 ubi_err("%s reference count %d, destroy anyway",
1128 ubi->ubi_name, ubi->ref_count);
1130 ubi_devices[ubi_num] = NULL;
1131 spin_unlock(&ubi_devices_lock);
1133 ubi_assert(ubi_num == ubi->ubi_num);
1134 ubi_notify_all(ubi, UBI_VOLUME_REMOVED, NULL);
1135 ubi_msg("detaching mtd%d from ubi%d", ubi->mtd->index, ubi_num);
1136 #ifdef CONFIG_MTD_UBI_FASTMAP
1137 /* If we don't write a new fastmap at detach time we lose all
1138 * EC updates that have been made since the last written fastmap. */
1139 ubi_update_fastmap(ubi);
1142 * Before freeing anything, we have to stop the background thread to
1143 * prevent it from doing anything on this device while we are freeing.
1145 if (ubi->bgt_thread)
1146 kthread_stop(ubi->bgt_thread);
1149 * Get a reference to the device in order to prevent 'dev_release()'
1150 * from freeing the @ubi object.
1152 get_device(&ubi->dev);
1154 ubi_debugfs_exit_dev(ubi);
1158 ubi_free_internal_volumes(ubi);
1160 put_mtd_device(ubi->mtd);
1161 vfree(ubi->peb_buf);
1163 ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num);
1164 put_device(&ubi->dev);
1170 * open_mtd_by_chdev - open an MTD device by its character device node path.
1171 * @mtd_dev: MTD character device node path
1173 * This helper function opens an MTD device by its character node device path.
1174 * Returns MTD device description object in case of success and a negative
1175 * error code in case of failure.
1177 static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev)
1179 int err, major, minor, mode;
1182 /* Probably this is an MTD character device node path */
1183 err = kern_path(mtd_dev, LOOKUP_FOLLOW, &path);
1185 return ERR_PTR(err);
1187 /* MTD device number is defined by the major / minor numbers */
1188 major = imajor(path.dentry->d_inode);
1189 minor = iminor(path.dentry->d_inode);
1190 mode = path.dentry->d_inode->i_mode;
1192 if (major != MTD_CHAR_MAJOR || !S_ISCHR(mode))
1193 return ERR_PTR(-EINVAL);
1197 * Just do not think the "/dev/mtdrX" devices support is need,
1198 * so do not support them to avoid doing extra work.
1200 return ERR_PTR(-EINVAL);
1202 return get_mtd_device(NULL, minor / 2);
1207 * open_mtd_device - open MTD device by name, character device path, or number.
1208 * @mtd_dev: name, character device node path, or MTD device device number
1210 * This function tries to open and MTD device described by @mtd_dev string,
1211 * which is first treated as ASCII MTD device number, and if it is not true, it
1212 * is treated as MTD device name, and if that is also not true, it is treated
1213 * as MTD character device node path. Returns MTD device description object in
1214 * case of success and a negative error code in case of failure.
1216 static struct mtd_info * __init open_mtd_device(const char *mtd_dev)
1218 struct mtd_info *mtd;
1222 mtd_num = simple_strtoul(mtd_dev, &endp, 0);
1223 if (*endp != '\0' || mtd_dev == endp) {
1225 * This does not look like an ASCII integer, probably this is
1228 mtd = get_mtd_device_nm(mtd_dev);
1230 if (IS_ERR(mtd) && PTR_ERR(mtd) == -ENODEV)
1231 /* Probably this is an MTD character device node path */
1232 mtd = open_mtd_by_chdev(mtd_dev);
1235 mtd = get_mtd_device(NULL, mtd_num);
1241 static int __init ubi_init(void)
1248 /* Ensure that EC and VID headers have correct size */
1249 BUILD_BUG_ON(sizeof(struct ubi_ec_hdr) != 64);
1250 BUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64);
1252 if (mtd_devs > UBI_MAX_DEVICES) {
1253 ubi_err("too many MTD devices, maximum is %d", UBI_MAX_DEVICES);
1257 /* Create base sysfs directory and sysfs files */
1258 ubi_class = class_create(THIS_MODULE, UBI_NAME_STR);
1259 if (IS_ERR(ubi_class)) {
1260 err = PTR_ERR(ubi_class);
1261 ubi_err("cannot create UBI class");
1265 err = class_create_file(ubi_class, &ubi_version);
1267 ubi_err("cannot create sysfs file");
1271 err = misc_register(&ubi_ctrl_cdev);
1273 ubi_err("cannot register device");
1277 ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab",
1278 sizeof(struct ubi_wl_entry),
1280 if (!ubi_wl_entry_slab) {
1285 err = ubi_debugfs_init();
1290 /* Attach MTD devices */
1291 for (i = 0; i < mtd_devs; i++) {
1292 struct mtd_dev_param *p = &mtd_dev_param[i];
1293 struct mtd_info *mtd;
1297 mtd = open_mtd_device(p->name);
1300 ubi_err("cannot open mtd %s, error %d", p->name, err);
1301 /* See comment below re-ubi_is_module(). */
1302 if (ubi_is_module())
1307 mutex_lock(&ubi_devices_mutex);
1308 err = ubi_attach_mtd_dev(mtd, p->ubi_num,
1309 p->vid_hdr_offs, p->max_beb_per1024);
1310 mutex_unlock(&ubi_devices_mutex);
1312 ubi_err("cannot attach mtd%d", mtd->index);
1313 put_mtd_device(mtd);
1316 * Originally UBI stopped initializing on any error.
1317 * However, later on it was found out that this
1318 * behavior is not very good when UBI is compiled into
1319 * the kernel and the MTD devices to attach are passed
1320 * through the command line. Indeed, UBI failure
1321 * stopped whole boot sequence.
1323 * To fix this, we changed the behavior for the
1324 * non-module case, but preserved the old behavior for
1325 * the module case, just for compatibility. This is a
1326 * little inconsistent, though.
1328 if (ubi_is_module())
1333 err = ubiblock_init();
1335 ubi_err("block: cannot initialize, error %d", err);
1337 /* See comment above re-ubi_is_module(). */
1338 if (ubi_is_module())
1345 for (k = 0; k < i; k++)
1346 if (ubi_devices[k]) {
1347 mutex_lock(&ubi_devices_mutex);
1348 ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1);
1349 mutex_unlock(&ubi_devices_mutex);
1353 kmem_cache_destroy(ubi_wl_entry_slab);
1355 misc_deregister(&ubi_ctrl_cdev);
1357 class_remove_file(ubi_class, &ubi_version);
1359 class_destroy(ubi_class);
1362 /* Reset any globals that the driver depends on being zeroed */
1365 ubi_err("cannot initialize UBI, error %d", err);
1368 late_initcall(ubi_init);
1371 static void __exit ubi_exit(void)
1380 for (i = 0; i < UBI_MAX_DEVICES; i++)
1381 if (ubi_devices[i]) {
1382 mutex_lock(&ubi_devices_mutex);
1383 ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1);
1384 mutex_unlock(&ubi_devices_mutex);
1387 kmem_cache_destroy(ubi_wl_entry_slab);
1388 misc_deregister(&ubi_ctrl_cdev);
1389 class_remove_file(ubi_class, &ubi_version);
1390 class_destroy(ubi_class);
1392 /* Reset any globals that the driver depends on being zeroed */
1396 module_exit(ubi_exit);
1399 * bytes_str_to_int - convert a number of bytes string into an integer.
1400 * @str: the string to convert
1402 * This function returns positive resulting integer in case of success and a
1403 * negative error code in case of failure.
1405 static int __init bytes_str_to_int(const char *str)
1408 unsigned long result;
1410 result = simple_strtoul(str, &endp, 0);
1411 if (str == endp || result >= INT_MAX) {
1412 ubi_err("incorrect bytes count: \"%s\"\n", str);
1423 if (endp[1] == 'i' && endp[2] == 'B')
1428 ubi_err("incorrect bytes count: \"%s\"\n", str);
1435 int kstrtoint(const char *s, unsigned int base, int *res)
1437 unsigned long long tmp;
1439 tmp = simple_strtoull(s, NULL, base);
1440 if (tmp != (unsigned long long)(int)tmp)
1447 * ubi_mtd_param_parse - parse the 'mtd=' UBI parameter.
1448 * @val: the parameter value to parse
1451 * This function returns zero in case of success and a negative error code in
1455 static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
1457 int ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
1461 struct mtd_dev_param *p;
1462 char buf[MTD_PARAM_LEN_MAX];
1463 char *pbuf = &buf[0];
1464 char *tokens[MTD_PARAM_MAX_COUNT], *token;
1469 if (mtd_devs == UBI_MAX_DEVICES) {
1470 ubi_err("too many parameters, max. is %d\n",
1475 len = strnlen(val, MTD_PARAM_LEN_MAX);
1476 if (len == MTD_PARAM_LEN_MAX) {
1477 ubi_err("parameter \"%s\" is too long, max. is %d\n",
1478 val, MTD_PARAM_LEN_MAX);
1483 pr_warn("UBI warning: empty 'mtd=' parameter - ignored\n");
1489 /* Get rid of the final newline */
1490 if (buf[len - 1] == '\n')
1491 buf[len - 1] = '\0';
1493 for (i = 0; i < MTD_PARAM_MAX_COUNT; i++)
1494 tokens[i] = strsep(&pbuf, ",");
1497 ubi_err("too many arguments at \"%s\"\n", val);
1501 p = &mtd_dev_param[mtd_devs];
1502 strcpy(&p->name[0], tokens[0]);
1506 p->vid_hdr_offs = bytes_str_to_int(token);
1508 if (p->vid_hdr_offs < 0)
1509 return p->vid_hdr_offs;
1514 int err = kstrtoint(token, 10, &p->max_beb_per1024);
1517 ubi_err("bad value for max_beb_per1024 parameter: %s",
1525 int err = kstrtoint(token, 10, &p->ubi_num);
1528 ubi_err("bad value for ubi_num parameter: %s", token);
1532 p->ubi_num = UBI_DEV_NUM_AUTO;
1538 module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000);
1539 MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024[,ubi_num]]].\n"
1540 "Multiple \"mtd\" parameters may be specified.\n"
1541 "MTD devices may be specified by their number, name, or path to the MTD character device node.\n"
1542 "Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0)\n"
1543 "Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value ("
1544 __stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0)\n"
1545 "Optional \"ubi_num\" parameter specifies UBI device number which have to be assigned to the newly created UBI device (assigned automatically by default)\n"
1547 "Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n"
1548 "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"
1549 "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"
1550 "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"
1551 "\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device).");
1552 #ifdef CONFIG_MTD_UBI_FASTMAP
1553 module_param(fm_autoconvert, bool, 0644);
1554 MODULE_PARM_DESC(fm_autoconvert, "Set this parameter to enable fastmap automatically on images without a fastmap.");
1556 MODULE_VERSION(__stringify(UBI_VERSION));
1557 MODULE_DESCRIPTION("UBI - Unsorted Block Images");
1558 MODULE_AUTHOR("Artem Bityutskiy");
1559 MODULE_LICENSE("GPL");