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.c85
1 files changed, 14 insertions, 71 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 0fde9fc7d2e5..2c5ed5ca9c33 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -27,10 +27,6 @@
27 * module load parameters or the kernel boot parameters. If MTD devices were 27 * module load parameters or the kernel boot parameters. If MTD devices were
28 * specified, UBI does not attach any MTD device, but it is possible to do 28 * specified, UBI does not attach any MTD device, but it is possible to do
29 * later using the "UBI control device". 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.
34 */ 30 */
35 31
36#include <linux/err.h> 32#include <linux/err.h>
@@ -554,10 +550,10 @@ static void uif_close(struct ubi_device *ubi)
554} 550}
555 551
556/** 552/**
557 * free_internal_volumes - free internal volumes. 553 * ubi_free_internal_volumes - free internal volumes.
558 * @ubi: UBI device description object 554 * @ubi: UBI device description object
559 */ 555 */
560static void free_internal_volumes(struct ubi_device *ubi) 556void ubi_free_internal_volumes(struct ubi_device *ubi)
561{ 557{
562 int i; 558 int i;
563 559
@@ -569,59 +565,6 @@ static void free_internal_volumes(struct ubi_device *ubi)
569} 565}
570 566
571/** 567/**
572 * attach_by_scanning - attach an MTD device using scanning method.
573 * @ubi: UBI device descriptor
574 *
575 * This function returns zero in case of success and a negative error code in
576 * case of failure.
577 *
578 * Note, currently this is the only method to attach UBI devices. Hopefully in
579 * the future we'll have more scalable attaching methods and avoid full media
580 * scanning. But even in this case scanning will be needed as a fall-back
581 * attaching method if there are some on-flash table corruptions.
582 */
583static int attach_by_scanning(struct ubi_device *ubi)
584{
585 int err;
586 struct ubi_scan_info *si;
587
588 si = ubi_scan(ubi);
589 if (IS_ERR(si))
590 return PTR_ERR(si);
591
592 ubi->bad_peb_count = si->bad_peb_count;
593 ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count;
594 ubi->corr_peb_count = si->corr_peb_count;
595 ubi->max_ec = si->max_ec;
596 ubi->mean_ec = si->mean_ec;
597 ubi_msg("max. sequence number: %llu", si->max_sqnum);
598
599 err = ubi_read_volume_table(ubi, si);
600 if (err)
601 goto out_si;
602
603 err = ubi_wl_init_scan(ubi, si);
604 if (err)
605 goto out_vtbl;
606
607 err = ubi_eba_init_scan(ubi, si);
608 if (err)
609 goto out_wl;
610
611 ubi_scan_destroy_si(si);
612 return 0;
613
614out_wl:
615 ubi_wl_close(ubi);
616out_vtbl:
617 free_internal_volumes(ubi);
618 vfree(ubi->vtbl);
619out_si:
620 ubi_scan_destroy_si(si);
621 return err;
622}
623
624/**
625 * io_init - initialize I/O sub-system for a given UBI device. 568 * io_init - initialize I/O sub-system for a given UBI device.
626 * @ubi: UBI device description object 569 * @ubi: UBI device description object
627 * 570 *
@@ -790,11 +733,11 @@ static int io_init(struct ubi_device *ubi)
790 ubi_msg("data offset: %d", ubi->leb_start); 733 ubi_msg("data offset: %d", ubi->leb_start);
791 734
792 /* 735 /*
793 * Note, ideally, we have to initialize ubi->bad_peb_count here. But 736 * Note, ideally, we have to initialize @ubi->bad_peb_count here. But
794 * unfortunately, MTD does not provide this information. We should loop 737 * unfortunately, MTD does not provide this information. We should loop
795 * over all physical eraseblocks and invoke mtd->block_is_bad() for 738 * over all physical eraseblocks and invoke mtd->block_is_bad() for
796 * each physical eraseblock. So, we skip ubi->bad_peb_count 739 * each physical eraseblock. So, we leave @ubi->bad_peb_count
797 * uninitialized and initialize it after scanning. 740 * uninitialized so far.
798 */ 741 */
799 742
800 return 0; 743 return 0;
@@ -805,7 +748,7 @@ static int io_init(struct ubi_device *ubi)
805 * @ubi: UBI device description object 748 * @ubi: UBI device description object
806 * @vol_id: ID of the volume to re-size 749 * @vol_id: ID of the volume to re-size
807 * 750 *
808 * This function re-sizes the volume marked by the @UBI_VTBL_AUTORESIZE_FLG in 751 * This function re-sizes the volume marked by the %UBI_VTBL_AUTORESIZE_FLG in
809 * the volume table to the largest possible size. See comments in ubi-header.h 752 * the volume table to the largest possible size. See comments in ubi-header.h
810 * for more description of the flag. Returns zero in case of success and a 753 * for more description of the flag. Returns zero in case of success and a
811 * negative error code in case of failure. 754 * negative error code in case of failure.
@@ -881,7 +824,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
881 for (i = 0; i < UBI_MAX_DEVICES; i++) { 824 for (i = 0; i < UBI_MAX_DEVICES; i++) {
882 ubi = ubi_devices[i]; 825 ubi = ubi_devices[i];
883 if (ubi && mtd->index == ubi->mtd->index) { 826 if (ubi && mtd->index == ubi->mtd->index) {
884 dbg_err("mtd%d is already attached to ubi%d", 827 ubi_err("mtd%d is already attached to ubi%d",
885 mtd->index, i); 828 mtd->index, i);
886 return -EEXIST; 829 return -EEXIST;
887 } 830 }
@@ -907,7 +850,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
907 if (!ubi_devices[ubi_num]) 850 if (!ubi_devices[ubi_num])
908 break; 851 break;
909 if (ubi_num == UBI_MAX_DEVICES) { 852 if (ubi_num == UBI_MAX_DEVICES) {
910 dbg_err("only %d UBI devices may be created", 853 ubi_err("only %d UBI devices may be created",
911 UBI_MAX_DEVICES); 854 UBI_MAX_DEVICES);
912 return -ENFILE; 855 return -ENFILE;
913 } 856 }
@@ -917,7 +860,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
917 860
918 /* Make sure ubi_num is not busy */ 861 /* Make sure ubi_num is not busy */
919 if (ubi_devices[ubi_num]) { 862 if (ubi_devices[ubi_num]) {
920 dbg_err("ubi%d already exists", ubi_num); 863 ubi_err("ubi%d already exists", ubi_num);
921 return -EEXIST; 864 return -EEXIST;
922 } 865 }
923 } 866 }
@@ -937,7 +880,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
937 spin_lock_init(&ubi->volumes_lock); 880 spin_lock_init(&ubi->volumes_lock);
938 881
939 ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num); 882 ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num);
940 dbg_msg("sizeof(struct ubi_scan_leb) %zu", sizeof(struct ubi_scan_leb)); 883 dbg_msg("sizeof(struct ubi_ainf_peb) %zu", sizeof(struct ubi_ainf_peb));
941 dbg_msg("sizeof(struct ubi_wl_entry) %zu", sizeof(struct ubi_wl_entry)); 884 dbg_msg("sizeof(struct ubi_wl_entry) %zu", sizeof(struct ubi_wl_entry));
942 885
943 err = io_init(ubi); 886 err = io_init(ubi);
@@ -953,9 +896,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
953 if (err) 896 if (err)
954 goto out_free; 897 goto out_free;
955 898
956 err = attach_by_scanning(ubi); 899 err = ubi_attach(ubi);
957 if (err) { 900 if (err) {
958 dbg_err("failed to attach by scanning, error %d", err); 901 ubi_err("failed to attach mtd%d, error %d", mtd->index, err);
959 goto out_debugging; 902 goto out_debugging;
960 } 903 }
961 904
@@ -1020,7 +963,7 @@ out_uif:
1020 uif_close(ubi); 963 uif_close(ubi);
1021out_detach: 964out_detach:
1022 ubi_wl_close(ubi); 965 ubi_wl_close(ubi);
1023 free_internal_volumes(ubi); 966 ubi_free_internal_volumes(ubi);
1024 vfree(ubi->vtbl); 967 vfree(ubi->vtbl);
1025out_debugging: 968out_debugging:
1026 ubi_debugging_exit_dev(ubi); 969 ubi_debugging_exit_dev(ubi);
@@ -1092,7 +1035,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1092 ubi_debugfs_exit_dev(ubi); 1035 ubi_debugfs_exit_dev(ubi);
1093 uif_close(ubi); 1036 uif_close(ubi);
1094 ubi_wl_close(ubi); 1037 ubi_wl_close(ubi);
1095 free_internal_volumes(ubi); 1038 ubi_free_internal_volumes(ubi);
1096 vfree(ubi->vtbl); 1039 vfree(ubi->vtbl);
1097 put_mtd_device(ubi->mtd); 1040 put_mtd_device(ubi->mtd);
1098 ubi_debugging_exit_dev(ubi); 1041 ubi_debugging_exit_dev(ubi);