diff options
| -rw-r--r-- | drivers/mtd/ubi/build.c | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 34977039850c..c9b99be8f6d5 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c | |||
| @@ -76,7 +76,10 @@ static int __initdata mtd_devs; | |||
| 76 | 76 | ||
| 77 | /* MTD devices specification parameters */ | 77 | /* MTD devices specification parameters */ |
| 78 | static struct mtd_dev_param __initdata mtd_dev_param[UBI_MAX_DEVICES]; | 78 | static struct mtd_dev_param __initdata mtd_dev_param[UBI_MAX_DEVICES]; |
| 79 | 79 | #ifdef CONFIG_MTD_UBI_FASTMAP | |
| 80 | /* UBI module parameter to enable fastmap automatically on non-fastmap images */ | ||
| 81 | static bool fm_autoconvert; | ||
| 82 | #endif | ||
| 80 | /* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */ | 83 | /* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */ |
| 81 | struct class *ubi_class; | 84 | struct class *ubi_class; |
| 82 | 85 | ||
| @@ -153,6 +156,19 @@ int ubi_volume_notify(struct ubi_device *ubi, struct ubi_volume *vol, int ntype) | |||
| 153 | 156 | ||
| 154 | ubi_do_get_device_info(ubi, &nt.di); | 157 | ubi_do_get_device_info(ubi, &nt.di); |
| 155 | ubi_do_get_volume_info(ubi, vol, &nt.vi); | 158 | ubi_do_get_volume_info(ubi, vol, &nt.vi); |
| 159 | |||
| 160 | #ifdef CONFIG_MTD_UBI_FASTMAP | ||
| 161 | switch (ntype) { | ||
| 162 | case UBI_VOLUME_ADDED: | ||
| 163 | case UBI_VOLUME_REMOVED: | ||
| 164 | case UBI_VOLUME_RESIZED: | ||
| 165 | case UBI_VOLUME_RENAMED: | ||
| 166 | if (ubi_update_fastmap(ubi)) { | ||
| 167 | ubi_err("Unable to update fastmap!"); | ||
| 168 | ubi_ro_mode(ubi); | ||
| 169 | } | ||
| 170 | } | ||
| 171 | #endif | ||
| 156 | return blocking_notifier_call_chain(&ubi_notifiers, ntype, &nt); | 172 | return blocking_notifier_call_chain(&ubi_notifiers, ntype, &nt); |
| 157 | } | 173 | } |
| 158 | 174 | ||
| @@ -918,10 +934,40 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, | |||
| 918 | ubi->vid_hdr_offset = vid_hdr_offset; | 934 | ubi->vid_hdr_offset = vid_hdr_offset; |
| 919 | ubi->autoresize_vol_id = -1; | 935 | ubi->autoresize_vol_id = -1; |
| 920 | 936 | ||
| 937 | #ifdef CONFIG_MTD_UBI_FASTMAP | ||
| 938 | ubi->fm_pool.used = ubi->fm_pool.size = 0; | ||
| 939 | ubi->fm_wl_pool.used = ubi->fm_wl_pool.size = 0; | ||
| 940 | |||
| 941 | /* | ||
| 942 | * fm_pool.max_size is 5% of the total number of PEBs but it's also | ||
| 943 | * between UBI_FM_MAX_POOL_SIZE and UBI_FM_MIN_POOL_SIZE. | ||
| 944 | */ | ||
| 945 | ubi->fm_pool.max_size = min(((int)mtd_div_by_eb(ubi->mtd->size, | ||
| 946 | ubi->mtd) / 100) * 5, UBI_FM_MAX_POOL_SIZE); | ||
| 947 | if (ubi->fm_pool.max_size < UBI_FM_MIN_POOL_SIZE) | ||
| 948 | ubi->fm_pool.max_size = UBI_FM_MIN_POOL_SIZE; | ||
| 949 | |||
| 950 | ubi->fm_wl_pool.max_size = UBI_FM_WL_POOL_SIZE; | ||
| 951 | ubi->fm_disabled = !fm_autoconvert; | ||
| 952 | |||
| 953 | if (!ubi->fm_disabled && (int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd) | ||
| 954 | <= UBI_FM_MAX_START) { | ||
| 955 | ubi_err("More than %i PEBs are needed for fastmap, sorry.", | ||
| 956 | UBI_FM_MAX_START); | ||
| 957 | ubi->fm_disabled = 1; | ||
| 958 | } | ||
| 959 | |||
| 960 | ubi_msg("default fastmap pool size: %d", ubi->fm_pool.max_size); | ||
| 961 | ubi_msg("default fastmap WL pool size: %d", ubi->fm_wl_pool.max_size); | ||
| 962 | #else | ||
| 963 | ubi->fm_disabled = 1; | ||
| 964 | #endif | ||
| 921 | mutex_init(&ubi->buf_mutex); | 965 | mutex_init(&ubi->buf_mutex); |
| 922 | mutex_init(&ubi->ckvol_mutex); | 966 | mutex_init(&ubi->ckvol_mutex); |
| 923 | mutex_init(&ubi->device_mutex); | 967 | mutex_init(&ubi->device_mutex); |
| 924 | spin_lock_init(&ubi->volumes_lock); | 968 | spin_lock_init(&ubi->volumes_lock); |
| 969 | mutex_init(&ubi->fm_mutex); | ||
| 970 | init_rwsem(&ubi->fm_sem); | ||
| 925 | 971 | ||
| 926 | ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num); | 972 | ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num); |
| 927 | 973 | ||
| @@ -934,6 +980,12 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, | |||
| 934 | if (!ubi->peb_buf) | 980 | if (!ubi->peb_buf) |
| 935 | goto out_free; | 981 | goto out_free; |
| 936 | 982 | ||
| 983 | #ifdef CONFIG_MTD_UBI_FASTMAP | ||
| 984 | ubi->fm_size = ubi_calc_fm_size(ubi); | ||
| 985 | ubi->fm_buf = vzalloc(ubi->fm_size); | ||
| 986 | if (!ubi->fm_buf) | ||
| 987 | goto out_free; | ||
| 988 | #endif | ||
| 937 | err = ubi_debugging_init_dev(ubi); | 989 | err = ubi_debugging_init_dev(ubi); |
| 938 | if (err) | 990 | if (err) |
| 939 | goto out_free; | 991 | goto out_free; |
| @@ -1012,6 +1064,7 @@ out_debugging: | |||
| 1012 | ubi_debugging_exit_dev(ubi); | 1064 | ubi_debugging_exit_dev(ubi); |
| 1013 | out_free: | 1065 | out_free: |
| 1014 | vfree(ubi->peb_buf); | 1066 | vfree(ubi->peb_buf); |
| 1067 | vfree(ubi->fm_buf); | ||
| 1015 | if (ref) | 1068 | if (ref) |
| 1016 | put_device(&ubi->dev); | 1069 | put_device(&ubi->dev); |
| 1017 | else | 1070 | else |
| @@ -1061,7 +1114,11 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway) | |||
| 1061 | ubi_assert(ubi_num == ubi->ubi_num); | 1114 | ubi_assert(ubi_num == ubi->ubi_num); |
| 1062 | ubi_notify_all(ubi, UBI_VOLUME_REMOVED, NULL); | 1115 | ubi_notify_all(ubi, UBI_VOLUME_REMOVED, NULL); |
| 1063 | ubi_msg("detaching mtd%d from ubi%d", ubi->mtd->index, ubi_num); | 1116 | ubi_msg("detaching mtd%d from ubi%d", ubi->mtd->index, ubi_num); |
| 1064 | 1117 | #ifdef CONFIG_MTD_UBI_FASTMAP | |
| 1118 | /* If we don't write a new fastmap at detach time we lose all | ||
| 1119 | * EC updates that have been made since the last written fastmap. */ | ||
| 1120 | ubi_update_fastmap(ubi); | ||
| 1121 | #endif | ||
| 1065 | /* | 1122 | /* |
| 1066 | * Before freeing anything, we have to stop the background thread to | 1123 | * Before freeing anything, we have to stop the background thread to |
| 1067 | * prevent it from doing anything on this device while we are freeing. | 1124 | * prevent it from doing anything on this device while we are freeing. |
| @@ -1077,12 +1134,14 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway) | |||
| 1077 | 1134 | ||
| 1078 | ubi_debugfs_exit_dev(ubi); | 1135 | ubi_debugfs_exit_dev(ubi); |
| 1079 | uif_close(ubi); | 1136 | uif_close(ubi); |
| 1137 | |||
| 1080 | ubi_wl_close(ubi); | 1138 | ubi_wl_close(ubi); |
| 1081 | ubi_free_internal_volumes(ubi); | 1139 | ubi_free_internal_volumes(ubi); |
| 1082 | vfree(ubi->vtbl); | 1140 | vfree(ubi->vtbl); |
| 1083 | put_mtd_device(ubi->mtd); | 1141 | put_mtd_device(ubi->mtd); |
| 1084 | ubi_debugging_exit_dev(ubi); | 1142 | ubi_debugging_exit_dev(ubi); |
| 1085 | vfree(ubi->peb_buf); | 1143 | vfree(ubi->peb_buf); |
| 1144 | vfree(ubi->fm_buf); | ||
| 1086 | ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num); | 1145 | ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num); |
| 1087 | put_device(&ubi->dev); | 1146 | put_device(&ubi->dev); |
| 1088 | return 0; | 1147 | return 0; |
| @@ -1404,7 +1463,10 @@ MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|pa | |||
| 1404 | "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" | 1463 | "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" |
| 1405 | "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" | 1464 | "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" |
| 1406 | "\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device)."); | 1465 | "\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device)."); |
| 1407 | 1466 | #ifdef CONFIG_MTD_UBI_FASTMAP | |
| 1467 | module_param(fm_autoconvert, bool, 0644); | ||
| 1468 | MODULE_PARM_DESC(fm_autoconvert, "Set this parameter to enable fastmap automatically on images without a fastmap."); | ||
| 1469 | #endif | ||
| 1408 | MODULE_VERSION(__stringify(UBI_VERSION)); | 1470 | MODULE_VERSION(__stringify(UBI_VERSION)); |
| 1409 | MODULE_DESCRIPTION("UBI - Unsorted Block Images"); | 1471 | MODULE_DESCRIPTION("UBI - Unsorted Block Images"); |
| 1410 | MODULE_AUTHOR("Artem Bityutskiy"); | 1472 | MODULE_AUTHOR("Artem Bityutskiy"); |
