build.c 33 KB

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