build.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. /*
  2. * Copyright (c) International Business Machines Corp., 2006
  3. * Copyright (c) Nokia Corporation, 2007
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * Author: Artem Bityutskiy (Битюцкий Артём),
  20. * Frank Haverkamp
  21. */
  22. /*
  23. * This file includes UBI initialization and building of UBI devices.
  24. *
  25. * When UBI is initialized, it attaches all the MTD devices specified as the
  26. * module load parameters or the kernel boot parameters. If MTD devices were
  27. * specified, UBI does not attach any MTD device, but it is possible to do
  28. * later using the "UBI control device".
  29. *
  30. * At the moment we only attach UBI devices by scanning, which will become a
  31. * bottleneck when flashes reach certain large size. Then one may improve UBI
  32. * and add other methods, although it does not seem to be easy to do.
  33. */
  34. #include <linux/err.h>
  35. #include <linux/module.h>
  36. #include <linux/moduleparam.h>
  37. #include <linux/stringify.h>
  38. #include <linux/stat.h>
  39. #include <linux/miscdevice.h>
  40. #include <linux/log2.h>
  41. #include <linux/kthread.h>
  42. #include "ubi.h"
  43. /* Maximum length of the 'mtd=' parameter */
  44. #define MTD_PARAM_LEN_MAX 64
  45. /**
  46. * struct mtd_dev_param - MTD device parameter description data structure.
  47. * @name: MTD device name or number string
  48. * @vid_hdr_offs: VID header offset
  49. */
  50. struct mtd_dev_param
  51. {
  52. char name[MTD_PARAM_LEN_MAX];
  53. int vid_hdr_offs;
  54. };
  55. /* Numbers of elements set in the @mtd_dev_param array */
  56. static int mtd_devs = 0;
  57. /* MTD devices specification parameters */
  58. static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES];
  59. /* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */
  60. struct class *ubi_class;
  61. /* Slab cache for wear-leveling entries */
  62. struct kmem_cache *ubi_wl_entry_slab;
  63. /* UBI control character device */
  64. static struct miscdevice ubi_ctrl_cdev = {
  65. .minor = MISC_DYNAMIC_MINOR,
  66. .name = "ubi_ctrl",
  67. .fops = &ubi_ctrl_cdev_operations,
  68. };
  69. /* All UBI devices in system */
  70. static struct ubi_device *ubi_devices[UBI_MAX_DEVICES];
  71. /* Serializes UBI devices creations and removals */
  72. DEFINE_MUTEX(ubi_devices_mutex);
  73. /* Protects @ubi_devices and @ubi->ref_count */
  74. static DEFINE_SPINLOCK(ubi_devices_lock);
  75. /* "Show" method for files in '/<sysfs>/class/ubi/' */
  76. static ssize_t ubi_version_show(struct class *class, char *buf)
  77. {
  78. return sprintf(buf, "%d\n", UBI_VERSION);
  79. }
  80. /* UBI version attribute ('/<sysfs>/class/ubi/version') */
  81. static struct class_attribute ubi_version =
  82. __ATTR(version, S_IRUGO, ubi_version_show, NULL);
  83. static ssize_t dev_attribute_show(struct device *dev,
  84. struct device_attribute *attr, char *buf);
  85. /* UBI device attributes (correspond to files in '/<sysfs>/class/ubi/ubiX') */
  86. static struct device_attribute dev_eraseblock_size =
  87. __ATTR(eraseblock_size, S_IRUGO, dev_attribute_show, NULL);
  88. static struct device_attribute dev_avail_eraseblocks =
  89. __ATTR(avail_eraseblocks, S_IRUGO, dev_attribute_show, NULL);
  90. static struct device_attribute dev_total_eraseblocks =
  91. __ATTR(total_eraseblocks, S_IRUGO, dev_attribute_show, NULL);
  92. static struct device_attribute dev_volumes_count =
  93. __ATTR(volumes_count, S_IRUGO, dev_attribute_show, NULL);
  94. static struct device_attribute dev_max_ec =
  95. __ATTR(max_ec, S_IRUGO, dev_attribute_show, NULL);
  96. static struct device_attribute dev_reserved_for_bad =
  97. __ATTR(reserved_for_bad, S_IRUGO, dev_attribute_show, NULL);
  98. static struct device_attribute dev_bad_peb_count =
  99. __ATTR(bad_peb_count, S_IRUGO, dev_attribute_show, NULL);
  100. static struct device_attribute dev_max_vol_count =
  101. __ATTR(max_vol_count, S_IRUGO, dev_attribute_show, NULL);
  102. static struct device_attribute dev_min_io_size =
  103. __ATTR(min_io_size, S_IRUGO, dev_attribute_show, NULL);
  104. static struct device_attribute dev_bgt_enabled =
  105. __ATTR(bgt_enabled, S_IRUGO, dev_attribute_show, NULL);
  106. static struct device_attribute dev_mtd_num =
  107. __ATTR(mtd_num, S_IRUGO, dev_attribute_show, NULL);
  108. /**
  109. * ubi_get_device - get UBI device.
  110. * @ubi_num: UBI device number
  111. *
  112. * This function returns UBI device description object for UBI device number
  113. * @ubi_num, or %NULL if the device does not exist. This function increases the
  114. * device reference count to prevent removal of the device. In other words, the
  115. * device cannot be removed if its reference count is not zero.
  116. */
  117. struct ubi_device *ubi_get_device(int ubi_num)
  118. {
  119. struct ubi_device *ubi;
  120. spin_lock(&ubi_devices_lock);
  121. ubi = ubi_devices[ubi_num];
  122. if (ubi) {
  123. ubi_assert(ubi->ref_count >= 0);
  124. ubi->ref_count += 1;
  125. get_device(&ubi->dev);
  126. }
  127. spin_unlock(&ubi_devices_lock);
  128. return ubi;
  129. }
  130. /**
  131. * ubi_put_device - drop an UBI device reference.
  132. * @ubi: UBI device description object
  133. */
  134. void ubi_put_device(struct ubi_device *ubi)
  135. {
  136. spin_lock(&ubi_devices_lock);
  137. ubi->ref_count -= 1;
  138. put_device(&ubi->dev);
  139. spin_unlock(&ubi_devices_lock);
  140. }
  141. /**
  142. * ubi_get_by_major - get UBI device description object by character device
  143. * major number.
  144. * @major: major number
  145. *
  146. * This function is similar to 'ubi_get_device()', but it searches the device
  147. * by its major number.
  148. */
  149. struct ubi_device *ubi_get_by_major(int major)
  150. {
  151. int i;
  152. struct ubi_device *ubi;
  153. spin_lock(&ubi_devices_lock);
  154. for (i = 0; i < UBI_MAX_DEVICES; i++) {
  155. ubi = ubi_devices[i];
  156. if (ubi && MAJOR(ubi->cdev.dev) == major) {
  157. ubi_assert(ubi->ref_count >= 0);
  158. ubi->ref_count += 1;
  159. get_device(&ubi->dev);
  160. spin_unlock(&ubi_devices_lock);
  161. return ubi;
  162. }
  163. }
  164. spin_unlock(&ubi_devices_lock);
  165. return NULL;
  166. }
  167. /**
  168. * ubi_major2num - get UBI device number by character device major number.
  169. * @major: major number
  170. *
  171. * This function searches UBI device number object by its major number. If UBI
  172. * device was not found, this function returns -ENODEV, otherwise the UBI device
  173. * number is returned.
  174. */
  175. int ubi_major2num(int major)
  176. {
  177. int i, ubi_num = -ENODEV;
  178. spin_lock(&ubi_devices_lock);
  179. for (i = 0; i < UBI_MAX_DEVICES; i++) {
  180. struct ubi_device *ubi = ubi_devices[i];
  181. if (ubi && MAJOR(ubi->cdev.dev) == major) {
  182. ubi_num = ubi->ubi_num;
  183. break;
  184. }
  185. }
  186. spin_unlock(&ubi_devices_lock);
  187. return ubi_num;
  188. }
  189. /* "Show" method for files in '/<sysfs>/class/ubi/ubiX/' */
  190. static ssize_t dev_attribute_show(struct device *dev,
  191. struct device_attribute *attr, char *buf)
  192. {
  193. ssize_t ret;
  194. struct ubi_device *ubi;
  195. /*
  196. * The below code looks weird, but it actually makes sense. We get the
  197. * UBI device reference from the contained 'struct ubi_device'. But it
  198. * is unclear if the device was removed or not yet. Indeed, if the
  199. * device was removed before we increased its reference count,
  200. * 'ubi_get_device()' will return -ENODEV and we fail.
  201. *
  202. * Remember, 'struct ubi_device' is freed in the release function, so
  203. * we still can use 'ubi->ubi_num'.
  204. */
  205. ubi = container_of(dev, struct ubi_device, dev);
  206. ubi = ubi_get_device(ubi->ubi_num);
  207. if (!ubi)
  208. return -ENODEV;
  209. if (attr == &dev_eraseblock_size)
  210. ret = sprintf(buf, "%d\n", ubi->leb_size);
  211. else if (attr == &dev_avail_eraseblocks)
  212. ret = sprintf(buf, "%d\n", ubi->avail_pebs);
  213. else if (attr == &dev_total_eraseblocks)
  214. ret = sprintf(buf, "%d\n", ubi->good_peb_count);
  215. else if (attr == &dev_volumes_count)
  216. ret = sprintf(buf, "%d\n", ubi->vol_count - UBI_INT_VOL_COUNT);
  217. else if (attr == &dev_max_ec)
  218. ret = sprintf(buf, "%d\n", ubi->max_ec);
  219. else if (attr == &dev_reserved_for_bad)
  220. ret = sprintf(buf, "%d\n", ubi->beb_rsvd_pebs);
  221. else if (attr == &dev_bad_peb_count)
  222. ret = sprintf(buf, "%d\n", ubi->bad_peb_count);
  223. else if (attr == &dev_max_vol_count)
  224. ret = sprintf(buf, "%d\n", ubi->vtbl_slots);
  225. else if (attr == &dev_min_io_size)
  226. ret = sprintf(buf, "%d\n", ubi->min_io_size);
  227. else if (attr == &dev_bgt_enabled)
  228. ret = sprintf(buf, "%d\n", ubi->thread_enabled);
  229. else if (attr == &dev_mtd_num)
  230. ret = sprintf(buf, "%d\n", ubi->mtd->index);
  231. else
  232. ret = -EINVAL;
  233. ubi_put_device(ubi);
  234. return ret;
  235. }
  236. /* Fake "release" method for UBI devices */
  237. static void dev_release(struct device *dev) { }
  238. /**
  239. * ubi_sysfs_init - initialize sysfs for an UBI device.
  240. * @ubi: UBI device description object
  241. *
  242. * This function returns zero in case of success and a negative error code in
  243. * case of failure.
  244. */
  245. static int ubi_sysfs_init(struct ubi_device *ubi)
  246. {
  247. int err;
  248. ubi->dev.release = dev_release;
  249. ubi->dev.devt = ubi->cdev.dev;
  250. ubi->dev.class = ubi_class;
  251. sprintf(&ubi->dev.bus_id[0], UBI_NAME_STR"%d", ubi->ubi_num);
  252. err = device_register(&ubi->dev);
  253. if (err)
  254. return err;
  255. err = device_create_file(&ubi->dev, &dev_eraseblock_size);
  256. if (err)
  257. return err;
  258. err = device_create_file(&ubi->dev, &dev_avail_eraseblocks);
  259. if (err)
  260. return err;
  261. err = device_create_file(&ubi->dev, &dev_total_eraseblocks);
  262. if (err)
  263. return err;
  264. err = device_create_file(&ubi->dev, &dev_volumes_count);
  265. if (err)
  266. return err;
  267. err = device_create_file(&ubi->dev, &dev_max_ec);
  268. if (err)
  269. return err;
  270. err = device_create_file(&ubi->dev, &dev_reserved_for_bad);
  271. if (err)
  272. return err;
  273. err = device_create_file(&ubi->dev, &dev_bad_peb_count);
  274. if (err)
  275. return err;
  276. err = device_create_file(&ubi->dev, &dev_max_vol_count);
  277. if (err)
  278. return err;
  279. err = device_create_file(&ubi->dev, &dev_min_io_size);
  280. if (err)
  281. return err;
  282. err = device_create_file(&ubi->dev, &dev_bgt_enabled);
  283. if (err)
  284. return err;
  285. err = device_create_file(&ubi->dev, &dev_mtd_num);
  286. return err;
  287. }
  288. /**
  289. * ubi_sysfs_close - close sysfs for an UBI device.
  290. * @ubi: UBI device description object
  291. */
  292. static void ubi_sysfs_close(struct ubi_device *ubi)
  293. {
  294. device_remove_file(&ubi->dev, &dev_mtd_num);
  295. device_remove_file(&ubi->dev, &dev_bgt_enabled);
  296. device_remove_file(&ubi->dev, &dev_min_io_size);
  297. device_remove_file(&ubi->dev, &dev_max_vol_count);
  298. device_remove_file(&ubi->dev, &dev_bad_peb_count);
  299. device_remove_file(&ubi->dev, &dev_reserved_for_bad);
  300. device_remove_file(&ubi->dev, &dev_max_ec);
  301. device_remove_file(&ubi->dev, &dev_volumes_count);
  302. device_remove_file(&ubi->dev, &dev_total_eraseblocks);
  303. device_remove_file(&ubi->dev, &dev_avail_eraseblocks);
  304. device_remove_file(&ubi->dev, &dev_eraseblock_size);
  305. device_unregister(&ubi->dev);
  306. }
  307. /**
  308. * kill_volumes - destroy all volumes.
  309. * @ubi: UBI device description object
  310. */
  311. static void kill_volumes(struct ubi_device *ubi)
  312. {
  313. int i;
  314. for (i = 0; i < ubi->vtbl_slots; i++)
  315. if (ubi->volumes[i])
  316. ubi_free_volume(ubi, ubi->volumes[i]);
  317. }
  318. /**
  319. * uif_init - initialize user interfaces for an UBI device.
  320. * @ubi: UBI device description object
  321. *
  322. * This function returns zero in case of success and a negative error code in
  323. * case of failure.
  324. */
  325. static int uif_init(struct ubi_device *ubi)
  326. {
  327. int i, err;
  328. dev_t dev;
  329. sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num);
  330. /*
  331. * Major numbers for the UBI character devices are allocated
  332. * dynamically. Major numbers of volume character devices are
  333. * equivalent to ones of the corresponding UBI character device. Minor
  334. * numbers of UBI character devices are 0, while minor numbers of
  335. * volume character devices start from 1. Thus, we allocate one major
  336. * number and ubi->vtbl_slots + 1 minor numbers.
  337. */
  338. err = alloc_chrdev_region(&dev, 0, ubi->vtbl_slots + 1, ubi->ubi_name);
  339. if (err) {
  340. ubi_err("cannot register UBI character devices");
  341. return err;
  342. }
  343. ubi_assert(MINOR(dev) == 0);
  344. cdev_init(&ubi->cdev, &ubi_cdev_operations);
  345. dbg_msg("%s major is %u", ubi->ubi_name, MAJOR(dev));
  346. ubi->cdev.owner = THIS_MODULE;
  347. err = cdev_add(&ubi->cdev, dev, 1);
  348. if (err) {
  349. ubi_err("cannot add character device");
  350. goto out_unreg;
  351. }
  352. err = ubi_sysfs_init(ubi);
  353. if (err)
  354. goto out_sysfs;
  355. for (i = 0; i < ubi->vtbl_slots; i++)
  356. if (ubi->volumes[i]) {
  357. err = ubi_add_volume(ubi, ubi->volumes[i]);
  358. if (err) {
  359. ubi_err("cannot add volume %d", i);
  360. goto out_volumes;
  361. }
  362. }
  363. return 0;
  364. out_volumes:
  365. kill_volumes(ubi);
  366. out_sysfs:
  367. ubi_sysfs_close(ubi);
  368. cdev_del(&ubi->cdev);
  369. out_unreg:
  370. unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1);
  371. ubi_err("cannot initialize UBI %s, error %d", ubi->ubi_name, err);
  372. return err;
  373. }
  374. /**
  375. * uif_close - close user interfaces for an UBI device.
  376. * @ubi: UBI device description object
  377. *
  378. * Note, since this function un-registers UBI volume device objects (@vol->dev),
  379. * the memory allocated voe the volumes is freed as well (in the release
  380. * function).
  381. */
  382. static void uif_close(struct ubi_device *ubi)
  383. {
  384. kill_volumes(ubi);
  385. ubi_sysfs_close(ubi);
  386. cdev_del(&ubi->cdev);
  387. unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1);
  388. }
  389. /**
  390. * free_internal_volumes - free internal volumes.
  391. * @ubi: UBI device description object
  392. */
  393. static void free_internal_volumes(struct ubi_device *ubi)
  394. {
  395. int i;
  396. for (i = ubi->vtbl_slots;
  397. i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
  398. kfree(ubi->volumes[i]->eba_tbl);
  399. kfree(ubi->volumes[i]);
  400. }
  401. }
  402. /**
  403. * attach_by_scanning - attach an MTD device using scanning method.
  404. * @ubi: UBI device descriptor
  405. *
  406. * This function returns zero in case of success and a negative error code in
  407. * case of failure.
  408. *
  409. * Note, currently this is the only method to attach UBI devices. Hopefully in
  410. * the future we'll have more scalable attaching methods and avoid full media
  411. * scanning. But even in this case scanning will be needed as a fall-back
  412. * attaching method if there are some on-flash table corruptions.
  413. */
  414. static int attach_by_scanning(struct ubi_device *ubi)
  415. {
  416. int err;
  417. struct ubi_scan_info *si;
  418. si = ubi_scan(ubi);
  419. if (IS_ERR(si))
  420. return PTR_ERR(si);
  421. ubi->bad_peb_count = si->bad_peb_count;
  422. ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count;
  423. ubi->max_ec = si->max_ec;
  424. ubi->mean_ec = si->mean_ec;
  425. err = ubi_read_volume_table(ubi, si);
  426. if (err)
  427. goto out_si;
  428. err = ubi_wl_init_scan(ubi, si);
  429. if (err)
  430. goto out_vtbl;
  431. err = ubi_eba_init_scan(ubi, si);
  432. if (err)
  433. goto out_wl;
  434. ubi_scan_destroy_si(si);
  435. return 0;
  436. out_wl:
  437. ubi_wl_close(ubi);
  438. out_vtbl:
  439. free_internal_volumes(ubi);
  440. vfree(ubi->vtbl);
  441. out_si:
  442. ubi_scan_destroy_si(si);
  443. return err;
  444. }
  445. /**
  446. * io_init - initialize I/O unit for a given UBI device.
  447. * @ubi: UBI device description object
  448. *
  449. * If @ubi->vid_hdr_offset or @ubi->leb_start is zero, default offsets are
  450. * assumed:
  451. * o EC header is always at offset zero - this cannot be changed;
  452. * o VID header starts just after the EC header at the closest address
  453. * aligned to @io->hdrs_min_io_size;
  454. * o data starts just after the VID header at the closest address aligned to
  455. * @io->min_io_size
  456. *
  457. * This function returns zero in case of success and a negative error code in
  458. * case of failure.
  459. */
  460. static int io_init(struct ubi_device *ubi)
  461. {
  462. if (ubi->mtd->numeraseregions != 0) {
  463. /*
  464. * Some flashes have several erase regions. Different regions
  465. * may have different eraseblock size and other
  466. * characteristics. It looks like mostly multi-region flashes
  467. * have one "main" region and one or more small regions to
  468. * store boot loader code or boot parameters or whatever. I
  469. * guess we should just pick the largest region. But this is
  470. * not implemented.
  471. */
  472. ubi_err("multiple regions, not implemented");
  473. return -EINVAL;
  474. }
  475. if (ubi->vid_hdr_offset < 0)
  476. return -EINVAL;
  477. /*
  478. * Note, in this implementation we support MTD devices with 0x7FFFFFFF
  479. * physical eraseblocks maximum.
  480. */
  481. ubi->peb_size = ubi->mtd->erasesize;
  482. ubi->peb_count = ubi->mtd->size / ubi->mtd->erasesize;
  483. ubi->flash_size = ubi->mtd->size;
  484. if (ubi->mtd->block_isbad && ubi->mtd->block_markbad)
  485. ubi->bad_allowed = 1;
  486. ubi->min_io_size = ubi->mtd->writesize;
  487. ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft;
  488. /*
  489. * Make sure minimal I/O unit is power of 2. Note, there is no
  490. * fundamental reason for this assumption. It is just an optimization
  491. * which allows us to avoid costly division operations.
  492. */
  493. if (!is_power_of_2(ubi->min_io_size)) {
  494. ubi_err("min. I/O unit (%d) is not power of 2",
  495. ubi->min_io_size);
  496. return -EINVAL;
  497. }
  498. ubi_assert(ubi->hdrs_min_io_size > 0);
  499. ubi_assert(ubi->hdrs_min_io_size <= ubi->min_io_size);
  500. ubi_assert(ubi->min_io_size % ubi->hdrs_min_io_size == 0);
  501. /* Calculate default aligned sizes of EC and VID headers */
  502. ubi->ec_hdr_alsize = ALIGN(UBI_EC_HDR_SIZE, ubi->hdrs_min_io_size);
  503. ubi->vid_hdr_alsize = ALIGN(UBI_VID_HDR_SIZE, ubi->hdrs_min_io_size);
  504. dbg_msg("min_io_size %d", ubi->min_io_size);
  505. dbg_msg("hdrs_min_io_size %d", ubi->hdrs_min_io_size);
  506. dbg_msg("ec_hdr_alsize %d", ubi->ec_hdr_alsize);
  507. dbg_msg("vid_hdr_alsize %d", ubi->vid_hdr_alsize);
  508. if (ubi->vid_hdr_offset == 0)
  509. /* Default offset */
  510. ubi->vid_hdr_offset = ubi->vid_hdr_aloffset =
  511. ubi->ec_hdr_alsize;
  512. else {
  513. ubi->vid_hdr_aloffset = ubi->vid_hdr_offset &
  514. ~(ubi->hdrs_min_io_size - 1);
  515. ubi->vid_hdr_shift = ubi->vid_hdr_offset -
  516. ubi->vid_hdr_aloffset;
  517. }
  518. /* Similar for the data offset */
  519. ubi->leb_start = ubi->vid_hdr_offset + UBI_EC_HDR_SIZE;
  520. ubi->leb_start = ALIGN(ubi->leb_start, ubi->min_io_size);
  521. dbg_msg("vid_hdr_offset %d", ubi->vid_hdr_offset);
  522. dbg_msg("vid_hdr_aloffset %d", ubi->vid_hdr_aloffset);
  523. dbg_msg("vid_hdr_shift %d", ubi->vid_hdr_shift);
  524. dbg_msg("leb_start %d", ubi->leb_start);
  525. /* The shift must be aligned to 32-bit boundary */
  526. if (ubi->vid_hdr_shift % 4) {
  527. ubi_err("unaligned VID header shift %d",
  528. ubi->vid_hdr_shift);
  529. return -EINVAL;
  530. }
  531. /* Check sanity */
  532. if (ubi->vid_hdr_offset < UBI_EC_HDR_SIZE ||
  533. ubi->leb_start < ubi->vid_hdr_offset + UBI_VID_HDR_SIZE ||
  534. ubi->leb_start > ubi->peb_size - UBI_VID_HDR_SIZE ||
  535. ubi->leb_start & (ubi->min_io_size - 1)) {
  536. ubi_err("bad VID header (%d) or data offsets (%d)",
  537. ubi->vid_hdr_offset, ubi->leb_start);
  538. return -EINVAL;
  539. }
  540. /*
  541. * It may happen that EC and VID headers are situated in one minimal
  542. * I/O unit. In this case we can only accept this UBI image in
  543. * read-only mode.
  544. */
  545. if (ubi->vid_hdr_offset + UBI_VID_HDR_SIZE <= ubi->hdrs_min_io_size) {
  546. ubi_warn("EC and VID headers are in the same minimal I/O unit, "
  547. "switch to read-only mode");
  548. ubi->ro_mode = 1;
  549. }
  550. ubi->leb_size = ubi->peb_size - ubi->leb_start;
  551. if (!(ubi->mtd->flags & MTD_WRITEABLE)) {
  552. ubi_msg("MTD device %d is write-protected, attach in "
  553. "read-only mode", ubi->mtd->index);
  554. ubi->ro_mode = 1;
  555. }
  556. ubi_msg("physical eraseblock size: %d bytes (%d KiB)",
  557. ubi->peb_size, ubi->peb_size >> 10);
  558. ubi_msg("logical eraseblock size: %d bytes", ubi->leb_size);
  559. ubi_msg("smallest flash I/O unit: %d", ubi->min_io_size);
  560. if (ubi->hdrs_min_io_size != ubi->min_io_size)
  561. ubi_msg("sub-page size: %d",
  562. ubi->hdrs_min_io_size);
  563. ubi_msg("VID header offset: %d (aligned %d)",
  564. ubi->vid_hdr_offset, ubi->vid_hdr_aloffset);
  565. ubi_msg("data offset: %d", ubi->leb_start);
  566. /*
  567. * Note, ideally, we have to initialize ubi->bad_peb_count here. But
  568. * unfortunately, MTD does not provide this information. We should loop
  569. * over all physical eraseblocks and invoke mtd->block_is_bad() for
  570. * each physical eraseblock. So, we skip ubi->bad_peb_count
  571. * uninitialized and initialize it after scanning.
  572. */
  573. return 0;
  574. }
  575. /**
  576. * autoresize - re-size the volume which has the "auto-resize" flag set.
  577. * @ubi: UBI device description object
  578. * @vol_id: ID of the volume to re-size
  579. *
  580. * This function re-sizes the volume marked by the @UBI_VTBL_AUTORESIZE_FLG in
  581. * the volume table to the largest possible size. See comments in ubi-header.h
  582. * for more description of the flag. Returns zero in case of success and a
  583. * negative error code in case of failure.
  584. */
  585. static int autoresize(struct ubi_device *ubi, int vol_id)
  586. {
  587. struct ubi_volume_desc desc;
  588. struct ubi_volume *vol = ubi->volumes[vol_id];
  589. int err, old_reserved_pebs = vol->reserved_pebs;
  590. /*
  591. * Clear the auto-resize flag in the volume in-memory copy of the
  592. * volume table, and 'ubi_resize_volume()' will propagate this change
  593. * to the flash.
  594. */
  595. ubi->vtbl[vol_id].flags &= ~UBI_VTBL_AUTORESIZE_FLG;
  596. if (ubi->avail_pebs == 0) {
  597. struct ubi_vtbl_record vtbl_rec;
  598. /*
  599. * No available PEBs to re-size the volume, clear the flag on
  600. * flash and exit.
  601. */
  602. memcpy(&vtbl_rec, &ubi->vtbl[vol_id],
  603. sizeof(struct ubi_vtbl_record));
  604. err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
  605. if (err)
  606. ubi_err("cannot clean auto-resize flag for volume %d",
  607. vol_id);
  608. } else {
  609. desc.vol = vol;
  610. err = ubi_resize_volume(&desc,
  611. old_reserved_pebs + ubi->avail_pebs);
  612. if (err)
  613. ubi_err("cannot auto-resize volume %d", vol_id);
  614. }
  615. if (err)
  616. return err;
  617. ubi_msg("volume %d (\"%s\") re-sized from %d to %d LEBs", vol_id,
  618. vol->name, old_reserved_pebs, vol->reserved_pebs);
  619. return 0;
  620. }
  621. /**
  622. * ubi_attach_mtd_dev - attach an MTD device.
  623. * @mtd_dev: MTD device description object
  624. * @ubi_num: number to assign to the new UBI device
  625. * @vid_hdr_offset: VID header offset
  626. *
  627. * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number
  628. * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in
  629. * which case this function finds a vacant device number and assigns it
  630. * automatically. Returns the new UBI device number in case of success and a
  631. * negative error code in case of failure.
  632. *
  633. * Note, the invocations of this function has to be serialized by the
  634. * @ubi_devices_mutex.
  635. */
  636. int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
  637. {
  638. struct ubi_device *ubi;
  639. int i, err;
  640. /*
  641. * Check if we already have the same MTD device attached.
  642. *
  643. * Note, this function assumes that UBI devices creations and deletions
  644. * are serialized, so it does not take the &ubi_devices_lock.
  645. */
  646. for (i = 0; i < UBI_MAX_DEVICES; i++) {
  647. ubi = ubi_devices[i];
  648. if (ubi && mtd->index == ubi->mtd->index) {
  649. dbg_err("mtd%d is already attached to ubi%d",
  650. mtd->index, i);
  651. return -EEXIST;
  652. }
  653. }
  654. /*
  655. * Make sure this MTD device is not emulated on top of an UBI volume
  656. * already. Well, generally this recursion works fine, but there are
  657. * different problems like the UBI module takes a reference to itself
  658. * by attaching (and thus, opening) the emulated MTD device. This
  659. * results in inability to unload the module. And in general it makes
  660. * no sense to attach emulated MTD devices, so we prohibit this.
  661. */
  662. if (mtd->type == MTD_UBIVOLUME) {
  663. ubi_err("refuse attaching mtd%d - it is already emulated on "
  664. "top of UBI", mtd->index);
  665. return -EINVAL;
  666. }
  667. if (ubi_num == UBI_DEV_NUM_AUTO) {
  668. /* Search for an empty slot in the @ubi_devices array */
  669. for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++)
  670. if (!ubi_devices[ubi_num])
  671. break;
  672. if (ubi_num == UBI_MAX_DEVICES) {
  673. dbg_err("only %d UBI devices may be created", UBI_MAX_DEVICES);
  674. return -ENFILE;
  675. }
  676. } else {
  677. if (ubi_num >= UBI_MAX_DEVICES)
  678. return -EINVAL;
  679. /* Make sure ubi_num is not busy */
  680. if (ubi_devices[ubi_num]) {
  681. dbg_err("ubi%d already exists", ubi_num);
  682. return -EEXIST;
  683. }
  684. }
  685. ubi = kzalloc(sizeof(struct ubi_device), GFP_KERNEL);
  686. if (!ubi)
  687. return -ENOMEM;
  688. ubi->mtd = mtd;
  689. ubi->ubi_num = ubi_num;
  690. ubi->vid_hdr_offset = vid_hdr_offset;
  691. ubi->autoresize_vol_id = -1;
  692. mutex_init(&ubi->buf_mutex);
  693. mutex_init(&ubi->ckvol_mutex);
  694. mutex_init(&ubi->volumes_mutex);
  695. spin_lock_init(&ubi->volumes_lock);
  696. ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num);
  697. err = io_init(ubi);
  698. if (err)
  699. goto out_free;
  700. ubi->peb_buf1 = vmalloc(ubi->peb_size);
  701. if (!ubi->peb_buf1)
  702. goto out_free;
  703. ubi->peb_buf2 = vmalloc(ubi->peb_size);
  704. if (!ubi->peb_buf2)
  705. goto out_free;
  706. #ifdef CONFIG_MTD_UBI_DEBUG
  707. mutex_init(&ubi->dbg_buf_mutex);
  708. ubi->dbg_peb_buf = vmalloc(ubi->peb_size);
  709. if (!ubi->dbg_peb_buf)
  710. goto out_free;
  711. #endif
  712. err = attach_by_scanning(ubi);
  713. if (err) {
  714. dbg_err("failed to attach by scanning, error %d", err);
  715. goto out_free;
  716. }
  717. if (ubi->autoresize_vol_id != -1) {
  718. err = autoresize(ubi, ubi->autoresize_vol_id);
  719. if (err)
  720. goto out_detach;
  721. }
  722. err = uif_init(ubi);
  723. if (err)
  724. goto out_detach;
  725. ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name);
  726. if (IS_ERR(ubi->bgt_thread)) {
  727. err = PTR_ERR(ubi->bgt_thread);
  728. ubi_err("cannot spawn \"%s\", error %d", ubi->bgt_name,
  729. err);
  730. goto out_uif;
  731. }
  732. ubi_msg("attached mtd%d to ubi%d", mtd->index, ubi_num);
  733. ubi_msg("MTD device name: \"%s\"", mtd->name);
  734. ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20);
  735. ubi_msg("number of good PEBs: %d", ubi->good_peb_count);
  736. ubi_msg("number of bad PEBs: %d", ubi->bad_peb_count);
  737. ubi_msg("max. allowed volumes: %d", ubi->vtbl_slots);
  738. ubi_msg("wear-leveling threshold: %d", CONFIG_MTD_UBI_WL_THRESHOLD);
  739. ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT);
  740. ubi_msg("number of user volumes: %d",
  741. ubi->vol_count - UBI_INT_VOL_COUNT);
  742. ubi_msg("available PEBs: %d", ubi->avail_pebs);
  743. ubi_msg("total number of reserved PEBs: %d", ubi->rsvd_pebs);
  744. ubi_msg("number of PEBs reserved for bad PEB handling: %d",
  745. ubi->beb_rsvd_pebs);
  746. ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec);
  747. /* Enable the background thread */
  748. if (!DBG_DISABLE_BGT) {
  749. ubi->thread_enabled = 1;
  750. wake_up_process(ubi->bgt_thread);
  751. }
  752. ubi_devices[ubi_num] = ubi;
  753. return ubi_num;
  754. out_uif:
  755. uif_close(ubi);
  756. out_detach:
  757. ubi_wl_close(ubi);
  758. free_internal_volumes(ubi);
  759. vfree(ubi->vtbl);
  760. out_free:
  761. vfree(ubi->peb_buf1);
  762. vfree(ubi->peb_buf2);
  763. #ifdef CONFIG_MTD_UBI_DEBUG
  764. vfree(ubi->dbg_peb_buf);
  765. #endif
  766. kfree(ubi);
  767. return err;
  768. }
  769. /**
  770. * ubi_detach_mtd_dev - detach an MTD device.
  771. * @ubi_num: UBI device number to detach from
  772. * @anyway: detach MTD even if device reference count is not zero
  773. *
  774. * This function destroys an UBI device number @ubi_num and detaches the
  775. * underlying MTD device. Returns zero in case of success and %-EBUSY if the
  776. * UBI device is busy and cannot be destroyed, and %-EINVAL if it does not
  777. * exist.
  778. *
  779. * Note, the invocations of this function has to be serialized by the
  780. * @ubi_devices_mutex.
  781. */
  782. int ubi_detach_mtd_dev(int ubi_num, int anyway)
  783. {
  784. struct ubi_device *ubi;
  785. if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES)
  786. return -EINVAL;
  787. spin_lock(&ubi_devices_lock);
  788. ubi = ubi_devices[ubi_num];
  789. if (!ubi) {
  790. spin_unlock(&ubi_devices_lock);
  791. return -EINVAL;
  792. }
  793. if (ubi->ref_count) {
  794. if (!anyway) {
  795. spin_unlock(&ubi_devices_lock);
  796. return -EBUSY;
  797. }
  798. /* This may only happen if there is a bug */
  799. ubi_err("%s reference count %d, destroy anyway",
  800. ubi->ubi_name, ubi->ref_count);
  801. }
  802. ubi_devices[ubi_num] = NULL;
  803. spin_unlock(&ubi_devices_lock);
  804. ubi_assert(ubi_num == ubi->ubi_num);
  805. dbg_msg("detaching mtd%d from ubi%d", ubi->mtd->index, ubi_num);
  806. /*
  807. * Before freeing anything, we have to stop the background thread to
  808. * prevent it from doing anything on this device while we are freeing.
  809. */
  810. if (ubi->bgt_thread)
  811. kthread_stop(ubi->bgt_thread);
  812. uif_close(ubi);
  813. ubi_wl_close(ubi);
  814. free_internal_volumes(ubi);
  815. vfree(ubi->vtbl);
  816. put_mtd_device(ubi->mtd);
  817. vfree(ubi->peb_buf1);
  818. vfree(ubi->peb_buf2);
  819. #ifdef CONFIG_MTD_UBI_DEBUG
  820. vfree(ubi->dbg_peb_buf);
  821. #endif
  822. ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num);
  823. kfree(ubi);
  824. return 0;
  825. }
  826. /**
  827. * find_mtd_device - open an MTD device by its name or number.
  828. * @mtd_dev: name or number of the device
  829. *
  830. * This function tries to open and MTD device described by @mtd_dev string,
  831. * which is first treated as an ASCII number, and if it is not true, it is
  832. * treated as MTD device name. Returns MTD device description object in case of
  833. * success and a negative error code in case of failure.
  834. */
  835. static struct mtd_info * __init open_mtd_device(const char *mtd_dev)
  836. {
  837. struct mtd_info *mtd;
  838. int mtd_num;
  839. char *endp;
  840. mtd_num = simple_strtoul(mtd_dev, &endp, 0);
  841. if (*endp != '\0' || mtd_dev == endp) {
  842. /*
  843. * This does not look like an ASCII integer, probably this is
  844. * MTD device name.
  845. */
  846. mtd = get_mtd_device_nm(mtd_dev);
  847. } else
  848. mtd = get_mtd_device(NULL, mtd_num);
  849. return mtd;
  850. }
  851. static int __init ubi_init(void)
  852. {
  853. int err, i, k;
  854. /* Ensure that EC and VID headers have correct size */
  855. BUILD_BUG_ON(sizeof(struct ubi_ec_hdr) != 64);
  856. BUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64);
  857. if (mtd_devs > UBI_MAX_DEVICES) {
  858. ubi_err("too many MTD devices, maximum is %d", UBI_MAX_DEVICES);
  859. return -EINVAL;
  860. }
  861. /* Create base sysfs directory and sysfs files */
  862. ubi_class = class_create(THIS_MODULE, UBI_NAME_STR);
  863. if (IS_ERR(ubi_class)) {
  864. err = PTR_ERR(ubi_class);
  865. ubi_err("cannot create UBI class");
  866. goto out;
  867. }
  868. err = class_create_file(ubi_class, &ubi_version);
  869. if (err) {
  870. ubi_err("cannot create sysfs file");
  871. goto out_class;
  872. }
  873. err = misc_register(&ubi_ctrl_cdev);
  874. if (err) {
  875. ubi_err("cannot register device");
  876. goto out_version;
  877. }
  878. ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab",
  879. sizeof(struct ubi_wl_entry),
  880. 0, 0, NULL);
  881. if (!ubi_wl_entry_slab)
  882. goto out_dev_unreg;
  883. /* Attach MTD devices */
  884. for (i = 0; i < mtd_devs; i++) {
  885. struct mtd_dev_param *p = &mtd_dev_param[i];
  886. struct mtd_info *mtd;
  887. cond_resched();
  888. mtd = open_mtd_device(p->name);
  889. if (IS_ERR(mtd)) {
  890. err = PTR_ERR(mtd);
  891. goto out_detach;
  892. }
  893. mutex_lock(&ubi_devices_mutex);
  894. err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO,
  895. p->vid_hdr_offs);
  896. mutex_unlock(&ubi_devices_mutex);
  897. if (err < 0) {
  898. put_mtd_device(mtd);
  899. ubi_err("cannot attach mtd%d", mtd->index);
  900. goto out_detach;
  901. }
  902. }
  903. return 0;
  904. out_detach:
  905. for (k = 0; k < i; k++)
  906. if (ubi_devices[k]) {
  907. mutex_lock(&ubi_devices_mutex);
  908. ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1);
  909. mutex_unlock(&ubi_devices_mutex);
  910. }
  911. kmem_cache_destroy(ubi_wl_entry_slab);
  912. out_dev_unreg:
  913. misc_deregister(&ubi_ctrl_cdev);
  914. out_version:
  915. class_remove_file(ubi_class, &ubi_version);
  916. out_class:
  917. class_destroy(ubi_class);
  918. out:
  919. ubi_err("UBI error: cannot initialize UBI, error %d", err);
  920. return err;
  921. }
  922. module_init(ubi_init);
  923. static void __exit ubi_exit(void)
  924. {
  925. int i;
  926. for (i = 0; i < UBI_MAX_DEVICES; i++)
  927. if (ubi_devices[i]) {
  928. mutex_lock(&ubi_devices_mutex);
  929. ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1);
  930. mutex_unlock(&ubi_devices_mutex);
  931. }
  932. kmem_cache_destroy(ubi_wl_entry_slab);
  933. misc_deregister(&ubi_ctrl_cdev);
  934. class_remove_file(ubi_class, &ubi_version);
  935. class_destroy(ubi_class);
  936. }
  937. module_exit(ubi_exit);
  938. /**
  939. * bytes_str_to_int - convert a string representing number of bytes to an
  940. * integer.
  941. * @str: the string to convert
  942. *
  943. * This function returns positive resulting integer in case of success and a
  944. * negative error code in case of failure.
  945. */
  946. static int __init bytes_str_to_int(const char *str)
  947. {
  948. char *endp;
  949. unsigned long result;
  950. result = simple_strtoul(str, &endp, 0);
  951. if (str == endp || result < 0) {
  952. printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
  953. str);
  954. return -EINVAL;
  955. }
  956. switch (*endp) {
  957. case 'G':
  958. result *= 1024;
  959. case 'M':
  960. result *= 1024;
  961. case 'K':
  962. result *= 1024;
  963. if (endp[1] == 'i' && endp[2] == 'B')
  964. endp += 2;
  965. case '\0':
  966. break;
  967. default:
  968. printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
  969. str);
  970. return -EINVAL;
  971. }
  972. return result;
  973. }
  974. /**
  975. * ubi_mtd_param_parse - parse the 'mtd=' UBI parameter.
  976. * @val: the parameter value to parse
  977. * @kp: not used
  978. *
  979. * This function returns zero in case of success and a negative error code in
  980. * case of error.
  981. */
  982. static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
  983. {
  984. int i, len;
  985. struct mtd_dev_param *p;
  986. char buf[MTD_PARAM_LEN_MAX];
  987. char *pbuf = &buf[0];
  988. char *tokens[2] = {NULL, NULL};
  989. if (!val)
  990. return -EINVAL;
  991. if (mtd_devs == UBI_MAX_DEVICES) {
  992. printk(KERN_ERR "UBI error: too many parameters, max. is %d\n",
  993. UBI_MAX_DEVICES);
  994. return -EINVAL;
  995. }
  996. len = strnlen(val, MTD_PARAM_LEN_MAX);
  997. if (len == MTD_PARAM_LEN_MAX) {
  998. printk(KERN_ERR "UBI error: parameter \"%s\" is too long, "
  999. "max. is %d\n", val, MTD_PARAM_LEN_MAX);
  1000. return -EINVAL;
  1001. }
  1002. if (len == 0) {
  1003. printk(KERN_WARNING "UBI warning: empty 'mtd=' parameter - "
  1004. "ignored\n");
  1005. return 0;
  1006. }
  1007. strcpy(buf, val);
  1008. /* Get rid of the final newline */
  1009. if (buf[len - 1] == '\n')
  1010. buf[len - 1] = '\0';
  1011. for (i = 0; i < 2; i++)
  1012. tokens[i] = strsep(&pbuf, ",");
  1013. if (pbuf) {
  1014. printk(KERN_ERR "UBI error: too many arguments at \"%s\"\n",
  1015. val);
  1016. return -EINVAL;
  1017. }
  1018. p = &mtd_dev_param[mtd_devs];
  1019. strcpy(&p->name[0], tokens[0]);
  1020. if (tokens[1])
  1021. p->vid_hdr_offs = bytes_str_to_int(tokens[1]);
  1022. if (p->vid_hdr_offs < 0)
  1023. return p->vid_hdr_offs;
  1024. mtd_devs += 1;
  1025. return 0;
  1026. }
  1027. module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000);
  1028. MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: "
  1029. "mtd=<name|num>[,<vid_hdr_offs>].\n"
  1030. "Multiple \"mtd\" parameters may be specified.\n"
  1031. "MTD devices may be specified by their number or name.\n"
  1032. "Optional \"vid_hdr_offs\" parameter specifies UBI VID "
  1033. "header position and data starting position to be used "
  1034. "by UBI.\n"
  1035. "Example: mtd=content,1984 mtd=4 - attach MTD device"
  1036. "with name \"content\" using VID header offset 1984, and "
  1037. "MTD device number 4 with default VID header offset.");
  1038. MODULE_VERSION(__stringify(UBI_VERSION));
  1039. MODULE_DESCRIPTION("UBI - Unsorted Block Images");
  1040. MODULE_AUTHOR("Artem Bityutskiy");
  1041. MODULE_LICENSE("GPL");