~ubuntu-branches/ubuntu/quantal/linux-lowlatency/quantal-proposed

« back to all changes in this revision

Viewing changes to drivers/mtd/ubi/build.c

  • Committer: Package Import Robot
  • Author(s): Andy Whitcroft, Andy Whitcroft
  • Date: 2012-06-21 09:16:38 UTC
  • Revision ID: package-import@ubuntu.com-20120621091638-gubhv4nox8xez1ct
Tags: 3.5.0-1.1
[ Andy Whitcroft]

* Rebuild lowlatency against Ubuntu-3.5.0-1.1
* All new configuration system to allow configuration deltas to be
  exposed via debian.lowlatency/config-delta

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 * module load parameters or the kernel boot parameters. If MTD devices were
28
28
 * specified, UBI does not attach any MTD device, but it is possible to do
29
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
32
#include <linux/err.h>
554
550
}
555
551
 
556
552
/**
557
 
 * free_internal_volumes - free internal volumes.
 
553
 * ubi_free_internal_volumes - free internal volumes.
558
554
 * @ubi: UBI device description object
559
555
 */
560
 
static void free_internal_volumes(struct ubi_device *ubi)
 
556
void ubi_free_internal_volumes(struct ubi_device *ubi)
561
557
{
562
558
        int i;
563
559
 
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
 
 */
583
 
static 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
 
 
614
 
out_wl:
615
 
        ubi_wl_close(ubi);
616
 
out_vtbl:
617
 
        free_internal_volumes(ubi);
618
 
        vfree(ubi->vtbl);
619
 
out_si:
620
 
        ubi_scan_destroy_si(si);
621
 
        return err;
622
 
}
623
 
 
624
 
/**
625
568
 * io_init - initialize I/O sub-system for a given UBI device.
626
569
 * @ubi: UBI device description object
627
570
 *
664
607
        ubi->peb_count  = mtd_div_by_eb(ubi->mtd->size, ubi->mtd);
665
608
        ubi->flash_size = ubi->mtd->size;
666
609
 
667
 
        if (ubi->mtd->block_isbad && ubi->mtd->block_markbad)
 
610
        if (mtd_can_have_bb(ubi->mtd))
668
611
                ubi->bad_allowed = 1;
669
612
 
670
613
        if (ubi->mtd->type == MTD_NORFLASH) {
790
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
737
         * unfortunately, MTD does not provide this information. We should loop
795
738
         * over all physical eraseblocks and invoke mtd->block_is_bad() for
796
 
         * each physical eraseblock. So, we skip ubi->bad_peb_count
797
 
         * uninitialized and initialize it after scanning.
 
739
         * each physical eraseblock. So, we leave @ubi->bad_peb_count
 
740
         * uninitialized so far.
798
741
         */
799
742
 
800
743
        return 0;
805
748
 * @ubi: UBI device description object
806
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
752
 * the volume table to the largest possible size. See comments in ubi-header.h
810
753
 * for more description of the flag. Returns zero in case of success and a
811
754
 * negative error code in case of failure.
881
824
        for (i = 0; i < UBI_MAX_DEVICES; i++) {
882
825
                ubi = ubi_devices[i];
883
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
828
                                mtd->index, i);
886
829
                        return -EEXIST;
887
830
                }
907
850
                        if (!ubi_devices[ubi_num])
908
851
                                break;
909
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
854
                                UBI_MAX_DEVICES);
912
855
                        return -ENFILE;
913
856
                }
917
860
 
918
861
                /* Make sure ubi_num is not busy */
919
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
864
                        return -EEXIST;
922
865
                }
923
866
        }
937
880
        spin_lock_init(&ubi->volumes_lock);
938
881
 
939
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
884
        dbg_msg("sizeof(struct ubi_wl_entry) %zu", sizeof(struct ubi_wl_entry));
942
885
 
943
886
        err = io_init(ubi);
945
888
                goto out_free;
946
889
 
947
890
        err = -ENOMEM;
948
 
        ubi->peb_buf1 = vmalloc(ubi->peb_size);
949
 
        if (!ubi->peb_buf1)
950
 
                goto out_free;
951
 
 
952
 
        ubi->peb_buf2 = vmalloc(ubi->peb_size);
953
 
        if (!ubi->peb_buf2)
 
891
        ubi->peb_buf = vmalloc(ubi->peb_size);
 
892
        if (!ubi->peb_buf)
954
893
                goto out_free;
955
894
 
956
895
        err = ubi_debugging_init_dev(ubi);
957
896
        if (err)
958
897
                goto out_free;
959
898
 
960
 
        err = attach_by_scanning(ubi);
 
899
        err = ubi_attach(ubi);
961
900
        if (err) {
962
 
                dbg_err("failed to attach by scanning, error %d", err);
 
901
                ubi_err("failed to attach mtd%d, error %d", mtd->index, err);
963
902
                goto out_debugging;
964
903
        }
965
904
 
1024
963
        uif_close(ubi);
1025
964
out_detach:
1026
965
        ubi_wl_close(ubi);
1027
 
        free_internal_volumes(ubi);
 
966
        ubi_free_internal_volumes(ubi);
1028
967
        vfree(ubi->vtbl);
1029
968
out_debugging:
1030
969
        ubi_debugging_exit_dev(ubi);
1031
970
out_free:
1032
 
        vfree(ubi->peb_buf1);
1033
 
        vfree(ubi->peb_buf2);
 
971
        vfree(ubi->peb_buf);
1034
972
        if (ref)
1035
973
                put_device(&ubi->dev);
1036
974
        else
1097
1035
        ubi_debugfs_exit_dev(ubi);
1098
1036
        uif_close(ubi);
1099
1037
        ubi_wl_close(ubi);
1100
 
        free_internal_volumes(ubi);
 
1038
        ubi_free_internal_volumes(ubi);
1101
1039
        vfree(ubi->vtbl);
1102
1040
        put_mtd_device(ubi->mtd);
1103
1041
        ubi_debugging_exit_dev(ubi);
1104
 
        vfree(ubi->peb_buf1);
1105
 
        vfree(ubi->peb_buf2);
 
1042
        vfree(ubi->peb_buf);
1106
1043
        ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num);
1107
1044
        put_device(&ubi->dev);
1108
1045
        return 0;