build.c 33 KB

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