aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/build.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi/build.c')
-rw-r--r--drivers/mtd/ubi/build.c52
1 files changed, 42 insertions, 10 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index b3efb2fa3c10..3f37b16f8774 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -21,11 +21,16 @@
21 */ 21 */
22 22
23/* 23/*
24 * This file includes UBI initialization and building of UBI devices. At the 24 * This file includes UBI initialization and building of UBI devices.
25 * moment UBI devices may only be added while UBI is initialized, but dynamic 25 *
26 * device add/remove functionality is planned. Also, at the moment we only 26 * When UBI is initialized, it attaches all the MTD devices specified as the
27 * attach UBI devices by scanning, which will become a bottleneck when flashes 27 * module load parameters or the kernel boot parameters. If MTD devices were
28 * reach certain large size. Then one may improve UBI and add other methods. 28 * specified, UBI does not attach any MTD device, but it is possible to do
29 * later using the "UBI control device".
30 *
31 * At the moment we only attach UBI devices by scanning, which will become a
32 * bottleneck when flashes reach certain large size. Then one may improve UBI
33 * and add other methods, although it does not seem to be easy to do.
29 */ 34 */
30 35
31#include <linux/err.h> 36#include <linux/err.h>
@@ -33,6 +38,7 @@
33#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
34#include <linux/stringify.h> 39#include <linux/stringify.h>
35#include <linux/stat.h> 40#include <linux/stat.h>
41#include <linux/miscdevice.h>
36#include <linux/log2.h> 42#include <linux/log2.h>
37#include "ubi.h" 43#include "ubi.h"
38 44
@@ -70,6 +76,12 @@ struct kmem_cache *ubi_ltree_slab;
70/* Slab cache for wear-leveling entries */ 76/* Slab cache for wear-leveling entries */
71struct kmem_cache *ubi_wl_entry_slab; 77struct kmem_cache *ubi_wl_entry_slab;
72 78
79/* UBI control character device */
80static struct miscdevice ubi_ctrl_cdev = {
81 .minor = MISC_DYNAMIC_MINOR,
82 .name = "ubi_ctrl",
83 .fops = &ubi_ctrl_cdev_operations,
84};
73 85
74/* "Show" method for files in '/<sysfs>/class/ubi/' */ 86/* "Show" method for files in '/<sysfs>/class/ubi/' */
75static ssize_t ubi_version_show(struct class *class, char *buf) 87static ssize_t ubi_version_show(struct class *class, char *buf)
@@ -701,19 +713,31 @@ static int __init ubi_init(void)
701 return -EINVAL; 713 return -EINVAL;
702 } 714 }
703 715
716 /* Create base sysfs directory and sysfs files */
704 ubi_class = class_create(THIS_MODULE, UBI_NAME_STR); 717 ubi_class = class_create(THIS_MODULE, UBI_NAME_STR);
705 if (IS_ERR(ubi_class)) 718 if (IS_ERR(ubi_class)) {
706 return PTR_ERR(ubi_class); 719 err = PTR_ERR(ubi_class);
720 printk(KERN_ERR "UBI error: cannot create UBI class\n");
721 goto out;
722 }
707 723
708 err = class_create_file(ubi_class, &ubi_version); 724 err = class_create_file(ubi_class, &ubi_version);
709 if (err) 725 if (err) {
726 printk(KERN_ERR "UBI error: cannot create sysfs file\n");
710 goto out_class; 727 goto out_class;
728 }
729
730 err = misc_register(&ubi_ctrl_cdev);
731 if (err) {
732 printk(KERN_ERR "UBI error: cannot register device\n");
733 goto out_version;
734 }
711 735
712 ubi_ltree_slab = kmem_cache_create("ubi_ltree_slab", 736 ubi_ltree_slab = kmem_cache_create("ubi_ltree_slab",
713 sizeof(struct ubi_ltree_entry), 0, 737 sizeof(struct ubi_ltree_entry), 0,
714 0, &ltree_entry_ctor); 738 0, &ltree_entry_ctor);
715 if (!ubi_ltree_slab) 739 if (!ubi_ltree_slab)
716 goto out_version; 740 goto out_dev_unreg;
717 741
718 ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab", 742 ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab",
719 sizeof(struct ubi_wl_entry), 743 sizeof(struct ubi_wl_entry),
@@ -727,8 +751,11 @@ static int __init ubi_init(void)
727 751
728 cond_resched(); 752 cond_resched();
729 err = attach_mtd_dev(p->name, p->vid_hdr_offs, p->data_offs); 753 err = attach_mtd_dev(p->name, p->vid_hdr_offs, p->data_offs);
730 if (err) 754 if (err) {
755 printk(KERN_ERR "UBI error: cannot attach %s\n",
756 p->name);
731 goto out_detach; 757 goto out_detach;
758 }
732 } 759 }
733 760
734 return 0; 761 return 0;
@@ -739,10 +766,14 @@ out_detach:
739 kmem_cache_destroy(ubi_wl_entry_slab); 766 kmem_cache_destroy(ubi_wl_entry_slab);
740out_ltree: 767out_ltree:
741 kmem_cache_destroy(ubi_ltree_slab); 768 kmem_cache_destroy(ubi_ltree_slab);
769out_dev_unreg:
770 misc_deregister(&ubi_ctrl_cdev);
742out_version: 771out_version:
743 class_remove_file(ubi_class, &ubi_version); 772 class_remove_file(ubi_class, &ubi_version);
744out_class: 773out_class:
745 class_destroy(ubi_class); 774 class_destroy(ubi_class);
775out:
776 printk(KERN_ERR "UBI error: cannot initialize UBI, error %d\n", err);
746 return err; 777 return err;
747} 778}
748module_init(ubi_init); 779module_init(ubi_init);
@@ -756,6 +787,7 @@ static void __exit ubi_exit(void)
756 detach_mtd_dev(ubi_devices[i]); 787 detach_mtd_dev(ubi_devices[i]);
757 kmem_cache_destroy(ubi_wl_entry_slab); 788 kmem_cache_destroy(ubi_wl_entry_slab);
758 kmem_cache_destroy(ubi_ltree_slab); 789 kmem_cache_destroy(ubi_ltree_slab);
790 misc_deregister(&ubi_ctrl_cdev);
759 class_remove_file(ubi_class, &ubi_version); 791 class_remove_file(ubi_class, &ubi_version);
760 class_destroy(ubi_class); 792 class_destroy(ubi_class);
761} 793}