Lines Matching full:ubi
11 * This file includes UBI initialization and building of UBI devices.
13 * When UBI is initialized, it attaches all the MTD devices specified as the
15 * specified, UBI does not attach any MTD device, but it is possible to do
16 * later using the "UBI control device".
39 #include "ubi.h"
57 #error Malloc area too small for UBI, increase CONFIG_SYS_MALLOC_LEN to >= 512k
81 /* UBI module parameter to enable fastmap automatically on non-fastmap images */
102 /* UBI control character device */
110 /* All UBI devices in system */
118 /* Serializes UBI devices creations and removals */
121 /* Protects @ubi_devices and @ubi->ref_count */
124 /* "Show" method for files in '/<sysfs>/class/ubi/' */
131 /* UBI version attribute ('/<sysfs>/class/ubi/version') */
137 /* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */
147 /* UBI device attributes (correspond to files in '/<sysfs>/class/ubi/ubiX') */
174 * @ubi: UBI device description object
182 int ubi_volume_notify(struct ubi_device *ubi, struct ubi_volume *vol, int ntype) in ubi_volume_notify() argument
187 ubi_do_get_device_info(ubi, &nt.di); in ubi_volume_notify()
188 ubi_do_get_volume_info(ubi, vol, &nt.vi); in ubi_volume_notify()
195 ret = ubi_update_fastmap(ubi); in ubi_volume_notify()
197 ubi_msg(ubi, "Unable to write a new fastmap: %i", ret); in ubi_volume_notify()
205 * @ubi: UBI device description object
209 * This function walks all volumes of UBI device @ubi and sends the @ntype
214 int ubi_notify_all(struct ubi_device *ubi, int ntype, struct notifier_block *nb) in ubi_notify_all() argument
222 ubi_do_get_device_info(ubi, &nt.di); in ubi_notify_all()
224 mutex_lock(&ubi->device_mutex); in ubi_notify_all()
225 for (i = 0; i < ubi->vtbl_slots; i++) { in ubi_notify_all()
227 * Since the @ubi->device is locked, and we are not going to in ubi_notify_all()
228 * change @ubi->volumes, we do not have to lock in ubi_notify_all()
229 * @ubi->volumes_lock. in ubi_notify_all()
231 if (!ubi->volumes[i]) in ubi_notify_all()
234 ubi_do_get_volume_info(ubi, ubi->volumes[i], &nt.vi); in ubi_notify_all()
244 mutex_unlock(&ubi->device_mutex); in ubi_notify_all()
253 * This function walks all UBI devices and volumes and sends the
267 struct ubi_device *ubi = ubi_devices[i]; in ubi_enumerate_volumes() local
269 if (!ubi) in ubi_enumerate_volumes()
271 count += ubi_notify_all(ubi, UBI_VOLUME_ADDED, nb); in ubi_enumerate_volumes()
278 * ubi_get_device - get UBI device.
279 * @ubi_num: UBI device number
281 * This function returns UBI device description object for UBI device number
288 struct ubi_device *ubi; in ubi_get_device() local
291 ubi = ubi_devices[ubi_num]; in ubi_get_device()
292 if (ubi) { in ubi_get_device()
293 ubi_assert(ubi->ref_count >= 0); in ubi_get_device()
294 ubi->ref_count += 1; in ubi_get_device()
295 get_device(&ubi->dev); in ubi_get_device()
299 return ubi; in ubi_get_device()
303 * ubi_put_device - drop an UBI device reference.
304 * @ubi: UBI device description object
306 void ubi_put_device(struct ubi_device *ubi) in ubi_put_device() argument
309 ubi->ref_count -= 1; in ubi_put_device()
310 put_device(&ubi->dev); in ubi_put_device()
315 * ubi_get_by_major - get UBI device by character device major number.
324 struct ubi_device *ubi; in ubi_get_by_major() local
328 ubi = ubi_devices[i]; in ubi_get_by_major()
329 if (ubi && MAJOR(ubi->cdev.dev) == major) { in ubi_get_by_major()
330 ubi_assert(ubi->ref_count >= 0); in ubi_get_by_major()
331 ubi->ref_count += 1; in ubi_get_by_major()
332 get_device(&ubi->dev); in ubi_get_by_major()
334 return ubi; in ubi_get_by_major()
343 * ubi_major2num - get UBI device number by character device major number.
346 * This function searches UBI device number object by its major number. If UBI
347 * device was not found, this function returns -ENODEV, otherwise the UBI device
356 struct ubi_device *ubi = ubi_devices[i]; in ubi_major2num() local
358 if (ubi && MAJOR(ubi->cdev.dev) == major) { in ubi_major2num()
359 ubi_num = ubi->ubi_num; in ubi_major2num()
369 /* "Show" method for files in '/<sysfs>/class/ubi/ubiX/' */
374 struct ubi_device *ubi; in dev_attribute_show() local
378 * UBI device reference from the contained 'struct ubi_device'. But it in dev_attribute_show()
384 * we still can use 'ubi->ubi_num'. in dev_attribute_show()
386 ubi = container_of(dev, struct ubi_device, dev); in dev_attribute_show()
387 ubi = ubi_get_device(ubi->ubi_num); in dev_attribute_show()
388 if (!ubi) in dev_attribute_show()
392 ret = sprintf(buf, "%d\n", ubi->leb_size); in dev_attribute_show()
394 ret = sprintf(buf, "%d\n", ubi->avail_pebs); in dev_attribute_show()
396 ret = sprintf(buf, "%d\n", ubi->good_peb_count); in dev_attribute_show()
398 ret = sprintf(buf, "%d\n", ubi->vol_count - UBI_INT_VOL_COUNT); in dev_attribute_show()
400 ret = sprintf(buf, "%d\n", ubi->max_ec); in dev_attribute_show()
402 ret = sprintf(buf, "%d\n", ubi->beb_rsvd_pebs); in dev_attribute_show()
404 ret = sprintf(buf, "%d\n", ubi->bad_peb_count); in dev_attribute_show()
406 ret = sprintf(buf, "%d\n", ubi->vtbl_slots); in dev_attribute_show()
408 ret = sprintf(buf, "%d\n", ubi->min_io_size); in dev_attribute_show()
410 ret = sprintf(buf, "%d\n", ubi->thread_enabled); in dev_attribute_show()
412 ret = sprintf(buf, "%d\n", ubi->mtd->index); in dev_attribute_show()
416 ubi_put_device(ubi); in dev_attribute_show()
438 struct ubi_device *ubi = container_of(dev, struct ubi_device, dev); in dev_release() local
440 kfree(ubi); in dev_release()
444 * ubi_sysfs_init - initialize sysfs for an UBI device.
445 * @ubi: UBI device description object
446 * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was
452 static int ubi_sysfs_init(struct ubi_device *ubi, int *ref) in ubi_sysfs_init() argument
456 ubi->dev.release = dev_release; in ubi_sysfs_init()
457 ubi->dev.devt = ubi->cdev.dev; in ubi_sysfs_init()
458 ubi->dev.class = &ubi_class; in ubi_sysfs_init()
459 ubi->dev.groups = ubi_dev_groups; in ubi_sysfs_init()
460 dev_set_name(&ubi->dev, UBI_NAME_STR"%d", ubi->ubi_num); in ubi_sysfs_init()
461 err = device_register(&ubi->dev); in ubi_sysfs_init()
470 * ubi_sysfs_close - close sysfs for an UBI device.
471 * @ubi: UBI device description object
473 static void ubi_sysfs_close(struct ubi_device *ubi) in ubi_sysfs_close() argument
475 device_unregister(&ubi->dev); in ubi_sysfs_close()
481 * @ubi: UBI device description object
483 static void kill_volumes(struct ubi_device *ubi) in kill_volumes() argument
487 for (i = 0; i < ubi->vtbl_slots; i++) in kill_volumes()
488 if (ubi->volumes[i]) in kill_volumes()
489 ubi_free_volume(ubi, ubi->volumes[i]); in kill_volumes()
493 * uif_init - initialize user interfaces for an UBI device.
494 * @ubi: UBI device description object
495 * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was
498 * This function initializes various user interfaces for an UBI device. If the
501 * if the initialization fails after the UBI device was registered in the
502 * driver core subsystem, this function takes a reference to @ubi->dev, because
503 * otherwise the release function ('dev_release()') would free whole @ubi
510 static int uif_init(struct ubi_device *ubi, int *ref) in uif_init() argument
518 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num); in uif_init()
521 * Major numbers for the UBI character devices are allocated in uif_init()
523 * equivalent to ones of the corresponding UBI character device. Minor in uif_init()
524 * numbers of UBI character devices are 0, while minor numbers of in uif_init()
526 * number and ubi->vtbl_slots + 1 minor numbers. in uif_init()
528 err = alloc_chrdev_region(&dev, 0, ubi->vtbl_slots + 1, ubi->ubi_name); in uif_init()
530 ubi_err(ubi, "cannot register UBI character devices"); in uif_init()
535 cdev_init(&ubi->cdev, &ubi_cdev_operations); in uif_init()
536 dbg_gen("%s major is %u", ubi->ubi_name, MAJOR(dev)); in uif_init()
537 ubi->cdev.owner = THIS_MODULE; in uif_init()
539 err = cdev_add(&ubi->cdev, dev, 1); in uif_init()
541 ubi_err(ubi, "cannot add character device"); in uif_init()
545 err = ubi_sysfs_init(ubi, ref); in uif_init()
549 for (i = 0; i < ubi->vtbl_slots; i++) in uif_init()
550 if (ubi->volumes[i]) { in uif_init()
551 err = ubi_add_volume(ubi, ubi->volumes[i]); in uif_init()
553 ubi_err(ubi, "cannot add volume %d", i); in uif_init()
561 kill_volumes(ubi); in uif_init()
564 get_device(&ubi->dev); in uif_init()
565 ubi_sysfs_close(ubi); in uif_init()
566 cdev_del(&ubi->cdev); in uif_init()
568 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1); in uif_init()
569 ubi_err(ubi, "cannot initialize UBI %s, error %d", in uif_init()
570 ubi->ubi_name, err); in uif_init()
575 * uif_close - close user interfaces for an UBI device.
576 * @ubi: UBI device description object
578 * Note, since this function un-registers UBI volume device objects (@vol->dev),
582 static void uif_close(struct ubi_device *ubi) in uif_close() argument
584 kill_volumes(ubi); in uif_close()
585 ubi_sysfs_close(ubi); in uif_close()
586 cdev_del(&ubi->cdev); in uif_close()
587 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1); in uif_close()
592 * @ubi: UBI device description object
594 void ubi_free_internal_volumes(struct ubi_device *ubi) in ubi_free_internal_volumes() argument
598 for (i = ubi->vtbl_slots; in ubi_free_internal_volumes()
599 i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { in ubi_free_internal_volumes()
600 kfree(ubi->volumes[i]->eba_tbl); in ubi_free_internal_volumes()
601 kfree(ubi->volumes[i]); in ubi_free_internal_volumes()
605 static int get_bad_peb_limit(const struct ubi_device *ubi, int max_beb_per1024) in get_bad_peb_limit() argument
620 * the MTD partition we are attaching (ubi->mtd). in get_bad_peb_limit()
622 device_size = mtd_get_device_size(ubi->mtd); in get_bad_peb_limit()
623 device_pebs = mtd_div_by_eb(device_size, ubi->mtd); in get_bad_peb_limit()
634 * io_init - initialize I/O sub-system for a given UBI device.
635 * @ubi: UBI device description object
638 * If @ubi->vid_hdr_offset or @ubi->leb_start is zero, default offsets are
649 static int io_init(struct ubi_device *ubi, int max_beb_per1024) in io_init() argument
654 if (ubi->mtd->numeraseregions != 0) { in io_init()
664 ubi_err(ubi, "multiple regions, not implemented"); in io_init()
668 if (ubi->vid_hdr_offset < 0) in io_init()
676 ubi->peb_size = ubi->mtd->erasesize; in io_init()
677 ubi->peb_count = mtd_div_by_eb(ubi->mtd->size, ubi->mtd); in io_init()
678 ubi->flash_size = ubi->mtd->size; in io_init()
680 if (mtd_can_have_bb(ubi->mtd)) { in io_init()
681 ubi->bad_allowed = 1; in io_init()
682 ubi->bad_peb_limit = get_bad_peb_limit(ubi, max_beb_per1024); in io_init()
685 if (ubi->mtd->type == MTD_NORFLASH) { in io_init()
686 ubi_assert(ubi->mtd->writesize == 1); in io_init()
687 ubi->nor_flash = 1; in io_init()
690 ubi->min_io_size = ubi->mtd->writesize; in io_init()
691 ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft; in io_init()
698 if (!is_power_of_2(ubi->min_io_size)) { in io_init()
699 ubi_err(ubi, "min. I/O unit (%d) is not power of 2", in io_init()
700 ubi->min_io_size); in io_init()
704 ubi_assert(ubi->hdrs_min_io_size > 0); in io_init()
705 ubi_assert(ubi->hdrs_min_io_size <= ubi->min_io_size); in io_init()
706 ubi_assert(ubi->min_io_size % ubi->hdrs_min_io_size == 0); in io_init()
708 ubi->max_write_size = ubi->mtd->writebufsize; in io_init()
713 if (ubi->max_write_size < ubi->min_io_size || in io_init()
714 ubi->max_write_size % ubi->min_io_size || in io_init()
715 !is_power_of_2(ubi->max_write_size)) { in io_init()
716 ubi_err(ubi, "bad write buffer size %d for %d min. I/O unit", in io_init()
717 ubi->max_write_size, ubi->min_io_size); in io_init()
722 ubi->ec_hdr_alsize = ALIGN(UBI_EC_HDR_SIZE, ubi->hdrs_min_io_size); in io_init()
723 ubi->vid_hdr_alsize = ALIGN(UBI_VID_HDR_SIZE, ubi->hdrs_min_io_size); in io_init()
725 dbg_gen("min_io_size %d", ubi->min_io_size); in io_init()
726 dbg_gen("max_write_size %d", ubi->max_write_size); in io_init()
727 dbg_gen("hdrs_min_io_size %d", ubi->hdrs_min_io_size); in io_init()
728 dbg_gen("ec_hdr_alsize %d", ubi->ec_hdr_alsize); in io_init()
729 dbg_gen("vid_hdr_alsize %d", ubi->vid_hdr_alsize); in io_init()
731 if (ubi->vid_hdr_offset == 0) in io_init()
733 ubi->vid_hdr_offset = ubi->vid_hdr_aloffset = in io_init()
734 ubi->ec_hdr_alsize; in io_init()
736 ubi->vid_hdr_aloffset = ubi->vid_hdr_offset & in io_init()
737 ~(ubi->hdrs_min_io_size - 1); in io_init()
738 ubi->vid_hdr_shift = ubi->vid_hdr_offset - in io_init()
739 ubi->vid_hdr_aloffset; in io_init()
743 ubi->leb_start = ubi->vid_hdr_offset + UBI_VID_HDR_SIZE; in io_init()
744 ubi->leb_start = ALIGN(ubi->leb_start, ubi->min_io_size); in io_init()
746 dbg_gen("vid_hdr_offset %d", ubi->vid_hdr_offset); in io_init()
747 dbg_gen("vid_hdr_aloffset %d", ubi->vid_hdr_aloffset); in io_init()
748 dbg_gen("vid_hdr_shift %d", ubi->vid_hdr_shift); in io_init()
749 dbg_gen("leb_start %d", ubi->leb_start); in io_init()
752 if (ubi->vid_hdr_shift % 4) { in io_init()
753 ubi_err(ubi, "unaligned VID header shift %d", in io_init()
754 ubi->vid_hdr_shift); in io_init()
759 if (ubi->vid_hdr_offset < UBI_EC_HDR_SIZE || in io_init()
760 ubi->leb_start < ubi->vid_hdr_offset + UBI_VID_HDR_SIZE || in io_init()
761 ubi->leb_start > ubi->peb_size - UBI_VID_HDR_SIZE || in io_init()
762 ubi->leb_start & (ubi->min_io_size - 1)) { in io_init()
763 ubi_err(ubi, "bad VID header (%d) or data offsets (%d)", in io_init()
764 ubi->vid_hdr_offset, ubi->leb_start); in io_init()
772 ubi->max_erroneous = ubi->peb_count / 10; in io_init()
773 if (ubi->max_erroneous < 16) in io_init()
774 ubi->max_erroneous = 16; in io_init()
775 dbg_gen("max_erroneous %d", ubi->max_erroneous); in io_init()
779 * I/O unit. In this case we can only accept this UBI image in in io_init()
782 if (ubi->vid_hdr_offset + UBI_VID_HDR_SIZE <= ubi->hdrs_min_io_size) { in io_init()
783 ubi_warn(ubi, "EC and VID headers are in the same minimal I/O unit, switch to read-only mode"); in io_init()
784 ubi->ro_mode = 1; in io_init()
787 ubi->leb_size = ubi->peb_size - ubi->leb_start; in io_init()
789 if (!(ubi->mtd->flags & MTD_WRITEABLE)) { in io_init()
790 ubi_msg(ubi, "MTD device %d is write-protected, attach in read-only mode", in io_init()
791 ubi->mtd->index); in io_init()
792 ubi->ro_mode = 1; in io_init()
796 * Note, ideally, we have to initialize @ubi->bad_peb_count here. But in io_init()
799 * each physical eraseblock. So, we leave @ubi->bad_peb_count in io_init()
808 * @ubi: UBI device description object
812 * the volume table to the largest possible size. See comments in ubi-header.h
816 static int autoresize(struct ubi_device *ubi, int vol_id) in autoresize() argument
819 struct ubi_volume *vol = ubi->volumes[vol_id]; in autoresize()
822 if (ubi->ro_mode) { in autoresize()
823 ubi_warn(ubi, "skip auto-resize because of R/O mode"); in autoresize()
832 ubi->vtbl[vol_id].flags &= ~UBI_VTBL_AUTORESIZE_FLG; in autoresize()
834 if (ubi->avail_pebs == 0) { in autoresize()
841 vtbl_rec = ubi->vtbl[vol_id]; in autoresize()
842 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); in autoresize()
844 ubi_err(ubi, "cannot clean auto-resize flag for volume %d", in autoresize()
849 old_reserved_pebs + ubi->avail_pebs); in autoresize()
851 ubi_err(ubi, "cannot auto-resize volume %d", in autoresize()
858 ubi_msg(ubi, "volume %d (\"%s\") re-sized from %d to %d LEBs", in autoresize()
866 * @ubi_num: number to assign to the new UBI device
870 * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number
871 * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in
873 * automatically. Returns the new UBI device number in case of success and a
882 struct ubi_device *ubi; in ubi_attach_mtd_dev() local
894 * Note, this function assumes that UBI devices creations and deletions in ubi_attach_mtd_dev()
898 ubi = ubi_devices[i]; in ubi_attach_mtd_dev()
899 if (ubi && mtd->index == ubi->mtd->index) { in ubi_attach_mtd_dev()
900 ubi_err(ubi, "mtd%d is already attached to ubi%d", in ubi_attach_mtd_dev()
907 * Make sure this MTD device is not emulated on top of an UBI volume in ubi_attach_mtd_dev()
909 * different problems like the UBI module takes a reference to itself in ubi_attach_mtd_dev()
915 ubi_err(ubi, "refuse attaching mtd%d - it is already emulated on top of UBI", in ubi_attach_mtd_dev()
926 ubi_err(ubi, "only %d UBI devices may be created", in ubi_attach_mtd_dev()
936 ubi_err(ubi, "already exists"); in ubi_attach_mtd_dev()
941 ubi = kzalloc(sizeof(struct ubi_device), GFP_KERNEL); in ubi_attach_mtd_dev()
942 if (!ubi) in ubi_attach_mtd_dev()
945 ubi->mtd = mtd; in ubi_attach_mtd_dev()
946 ubi->ubi_num = ubi_num; in ubi_attach_mtd_dev()
947 ubi->vid_hdr_offset = vid_hdr_offset; in ubi_attach_mtd_dev()
948 ubi->autoresize_vol_id = -1; in ubi_attach_mtd_dev()
951 ubi->fm_pool.used = ubi->fm_pool.size = 0; in ubi_attach_mtd_dev()
952 ubi->fm_wl_pool.used = ubi->fm_wl_pool.size = 0; in ubi_attach_mtd_dev()
958 ubi->fm_pool.max_size = min(((int)mtd_div_by_eb(ubi->mtd->size, in ubi_attach_mtd_dev()
959 ubi->mtd) / 100) * 5, UBI_FM_MAX_POOL_SIZE); in ubi_attach_mtd_dev()
960 ubi->fm_pool.max_size = max(ubi->fm_pool.max_size, in ubi_attach_mtd_dev()
963 ubi->fm_wl_pool.max_size = ubi->fm_pool.max_size / 2; in ubi_attach_mtd_dev()
964 ubi->fm_disabled = !fm_autoconvert; in ubi_attach_mtd_dev()
966 ubi_enable_dbg_chk_fastmap(ubi); in ubi_attach_mtd_dev()
968 if (!ubi->fm_disabled && (int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd) in ubi_attach_mtd_dev()
970 ubi_err(ubi, "More than %i PEBs are needed for fastmap, sorry.", in ubi_attach_mtd_dev()
972 ubi->fm_disabled = 1; in ubi_attach_mtd_dev()
975 ubi_msg(ubi, "default fastmap pool size: %d", ubi->fm_pool.max_size); in ubi_attach_mtd_dev()
976 ubi_msg(ubi, "default fastmap WL pool size: %d", in ubi_attach_mtd_dev()
977 ubi->fm_wl_pool.max_size); in ubi_attach_mtd_dev()
979 ubi->fm_disabled = 1; in ubi_attach_mtd_dev()
981 mutex_init(&ubi->buf_mutex); in ubi_attach_mtd_dev()
982 mutex_init(&ubi->ckvol_mutex); in ubi_attach_mtd_dev()
983 mutex_init(&ubi->device_mutex); in ubi_attach_mtd_dev()
984 spin_lock_init(&ubi->volumes_lock); in ubi_attach_mtd_dev()
985 init_rwsem(&ubi->fm_protect); in ubi_attach_mtd_dev()
986 init_rwsem(&ubi->fm_eba_sem); in ubi_attach_mtd_dev()
988 ubi_msg(ubi, "attaching mtd%d", mtd->index); in ubi_attach_mtd_dev()
990 err = io_init(ubi, max_beb_per1024); in ubi_attach_mtd_dev()
995 ubi->peb_buf = vmalloc(ubi->peb_size); in ubi_attach_mtd_dev()
996 if (!ubi->peb_buf) in ubi_attach_mtd_dev()
1000 ubi->fm_size = ubi_calc_fm_size(ubi); in ubi_attach_mtd_dev()
1001 ubi->fm_buf = vzalloc(ubi->fm_size); in ubi_attach_mtd_dev()
1002 if (!ubi->fm_buf) in ubi_attach_mtd_dev()
1005 err = ubi_attach(ubi, 0); in ubi_attach_mtd_dev()
1007 ubi_err(ubi, "failed to attach mtd%d, error %d", in ubi_attach_mtd_dev()
1012 if (ubi->autoresize_vol_id != -1) { in ubi_attach_mtd_dev()
1013 err = autoresize(ubi, ubi->autoresize_vol_id); in ubi_attach_mtd_dev()
1018 err = uif_init(ubi, &ref); in ubi_attach_mtd_dev()
1022 err = ubi_debugfs_init_dev(ubi); in ubi_attach_mtd_dev()
1026 ubi->bgt_thread = kthread_create(ubi_thread, ubi, "%s", ubi->bgt_name); in ubi_attach_mtd_dev()
1027 if (IS_ERR(ubi->bgt_thread)) { in ubi_attach_mtd_dev()
1028 err = PTR_ERR(ubi->bgt_thread); in ubi_attach_mtd_dev()
1029 ubi_err(ubi, "cannot spawn \"%s\", error %d", in ubi_attach_mtd_dev()
1030 ubi->bgt_name, err); in ubi_attach_mtd_dev()
1034 ubi_msg(ubi, "attached mtd%d (name \"%s\", size %llu MiB)", in ubi_attach_mtd_dev()
1035 mtd->index, mtd->name, ubi->flash_size >> 20); in ubi_attach_mtd_dev()
1036 ubi_msg(ubi, "PEB size: %d bytes (%d KiB), LEB size: %d bytes", in ubi_attach_mtd_dev()
1037 ubi->peb_size, ubi->peb_size >> 10, ubi->leb_size); in ubi_attach_mtd_dev()
1038 ubi_msg(ubi, "min./max. I/O unit sizes: %d/%d, sub-page size %d", in ubi_attach_mtd_dev()
1039 ubi->min_io_size, ubi->max_write_size, ubi->hdrs_min_io_size); in ubi_attach_mtd_dev()
1040 ubi_msg(ubi, "VID header offset: %d (aligned %d), data offset: %d", in ubi_attach_mtd_dev()
1041 ubi->vid_hdr_offset, ubi->vid_hdr_aloffset, ubi->leb_start); in ubi_attach_mtd_dev()
1042 ubi_msg(ubi, "good PEBs: %d, bad PEBs: %d, corrupted PEBs: %d", in ubi_attach_mtd_dev()
1043 ubi->good_peb_count, ubi->bad_peb_count, ubi->corr_peb_count); in ubi_attach_mtd_dev()
1044 ubi_msg(ubi, "user volume: %d, internal volumes: %d, max. volumes count: %d", in ubi_attach_mtd_dev()
1045 ubi->vol_count - UBI_INT_VOL_COUNT, UBI_INT_VOL_COUNT, in ubi_attach_mtd_dev()
1046 ubi->vtbl_slots); in ubi_attach_mtd_dev()
1047 ubi_msg(ubi, "max/mean erase counter: %d/%d, WL threshold: %d, image sequence number: %u", in ubi_attach_mtd_dev()
1048 ubi->max_ec, ubi->mean_ec, CONFIG_MTD_UBI_WL_THRESHOLD, in ubi_attach_mtd_dev()
1049 ubi->image_seq); in ubi_attach_mtd_dev()
1050 ubi_msg(ubi, "available PEBs: %d, total reserved PEBs: %d, PEBs reserved for bad PEB handling: %d", in ubi_attach_mtd_dev()
1051 ubi->avail_pebs, ubi->rsvd_pebs, ubi->beb_rsvd_pebs); in ubi_attach_mtd_dev()
1055 * checks @ubi->thread_enabled. Otherwise we may fail to wake it up. in ubi_attach_mtd_dev()
1057 spin_lock(&ubi->wl_lock); in ubi_attach_mtd_dev()
1058 ubi->thread_enabled = 1; in ubi_attach_mtd_dev()
1060 wake_up_process(ubi->bgt_thread); in ubi_attach_mtd_dev()
1062 ubi_do_worker(ubi); in ubi_attach_mtd_dev()
1065 spin_unlock(&ubi->wl_lock); in ubi_attach_mtd_dev()
1067 ubi_devices[ubi_num] = ubi; in ubi_attach_mtd_dev()
1068 ubi_notify_all(ubi, UBI_VOLUME_ADDED, NULL); in ubi_attach_mtd_dev()
1072 ubi_debugfs_exit_dev(ubi); in ubi_attach_mtd_dev()
1074 get_device(&ubi->dev); in ubi_attach_mtd_dev()
1076 uif_close(ubi); in ubi_attach_mtd_dev()
1078 ubi_wl_close(ubi); in ubi_attach_mtd_dev()
1079 ubi_free_internal_volumes(ubi); in ubi_attach_mtd_dev()
1080 vfree(ubi->vtbl); in ubi_attach_mtd_dev()
1082 vfree(ubi->peb_buf); in ubi_attach_mtd_dev()
1083 vfree(ubi->fm_buf); in ubi_attach_mtd_dev()
1085 put_device(&ubi->dev); in ubi_attach_mtd_dev()
1087 kfree(ubi); in ubi_attach_mtd_dev()
1093 * @ubi_num: UBI device number to detach from
1096 * This function destroys an UBI device number @ubi_num and detaches the
1098 * UBI device is busy and cannot be destroyed, and %-EINVAL if it does not
1106 struct ubi_device *ubi; in ubi_detach_mtd_dev() local
1111 ubi = ubi_get_device(ubi_num); in ubi_detach_mtd_dev()
1112 if (!ubi) in ubi_detach_mtd_dev()
1116 put_device(&ubi->dev); in ubi_detach_mtd_dev()
1117 ubi->ref_count -= 1; in ubi_detach_mtd_dev()
1118 if (ubi->ref_count) { in ubi_detach_mtd_dev()
1124 ubi_err(ubi, "%s reference count %d, destroy anyway", in ubi_detach_mtd_dev()
1125 ubi->ubi_name, ubi->ref_count); in ubi_detach_mtd_dev()
1130 ubi_assert(ubi_num == ubi->ubi_num); in ubi_detach_mtd_dev()
1131 ubi_notify_all(ubi, UBI_VOLUME_REMOVED, NULL); in ubi_detach_mtd_dev()
1132 ubi_msg(ubi, "detaching mtd%d", ubi->mtd->index); in ubi_detach_mtd_dev()
1138 if (!ubi_dbg_chk_fastmap(ubi)) in ubi_detach_mtd_dev()
1139 ubi_update_fastmap(ubi); in ubi_detach_mtd_dev()
1145 if (ubi->bgt_thread) in ubi_detach_mtd_dev()
1146 kthread_stop(ubi->bgt_thread); in ubi_detach_mtd_dev()
1150 * from freeing the @ubi object. in ubi_detach_mtd_dev()
1152 get_device(&ubi->dev); in ubi_detach_mtd_dev()
1154 ubi_debugfs_exit_dev(ubi); in ubi_detach_mtd_dev()
1155 uif_close(ubi); in ubi_detach_mtd_dev()
1157 ubi_wl_close(ubi); in ubi_detach_mtd_dev()
1158 ubi_free_internal_volumes(ubi); in ubi_detach_mtd_dev()
1159 vfree(ubi->vtbl); in ubi_detach_mtd_dev()
1160 put_mtd_device(ubi->mtd); in ubi_detach_mtd_dev()
1161 vfree(ubi->peb_buf); in ubi_detach_mtd_dev()
1162 vfree(ubi->fm_buf); in ubi_detach_mtd_dev()
1163 ubi_msg(ubi, "mtd%d is detached", ubi->mtd->index); in ubi_detach_mtd_dev()
1164 put_device(&ubi->dev); in ubi_detach_mtd_dev()
1253 pr_err("UBI error: too many MTD devices, maximum is %d\n", in ubi_init()
1265 pr_err("UBI error: cannot register device\n"); in ubi_init()
1292 pr_err("UBI error: cannot open mtd %s, error %d\n", in ubi_init()
1305 pr_err("UBI error: cannot attach mtd%d\n", in ubi_init()
1310 * Originally UBI stopped initializing on any error. in ubi_init()
1312 * behavior is not very good when UBI is compiled into in ubi_init()
1314 * through the command line. Indeed, UBI failure in ubi_init()
1329 pr_err("UBI error: block: cannot initialize, error %d\n", err); in ubi_init()
1356 pr_err("UBI error: cannot initialize UBI, error %d\n", err); in ubi_init()
1402 pr_err("UBI error: incorrect bytes count: \"%s\"\n", str); in bytes_str_to_int()
1418 pr_err("UBI error: incorrect bytes count: \"%s\"\n", str); in bytes_str_to_int()
1437 * ubi_mtd_param_parse - parse the 'mtd=' UBI parameter.
1460 pr_err("UBI error: too many parameters, max. is %d\n", in ubi_mtd_param_parse()
1467 pr_err("UBI error: parameter \"%s\" is too long, max. is %d\n", in ubi_mtd_param_parse()
1473 pr_warn("UBI warning: empty 'mtd=' parameter - ignored\n"); in ubi_mtd_param_parse()
1487 pr_err("UBI error: too many arguments at \"%s\"\n", val); in ubi_mtd_param_parse()
1507 pr_err("UBI error: bad value for max_beb_per1024 parameter: %s", in ubi_mtd_param_parse()
1518 pr_err("UBI error: bad value for ubi_num parameter: %s", in ubi_mtd_param_parse()
1533 …"Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default…
1536 …"Optional \"ubi_num\" parameter specifies UBI device number which have to be assigned to the newly…
1541 …"Example 4: mtd=/dev/mtd1,0,0,5 - attach MTD device /dev/mtd1 to UBI 5 and using default values fo…
1542 "\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device).");
1550 MODULE_DESCRIPTION("UBI - Unsorted Block Images");