mtd.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org> et al.
  4. *
  5. */
  6. #ifndef __MTD_MTD_H__
  7. #define __MTD_MTD_H__
  8. #ifndef __UBOOT__
  9. #include <linux/types.h>
  10. #include <linux/uio.h>
  11. #include <linux/notifier.h>
  12. #include <linux/device.h>
  13. #include <mtd/mtd-abi.h>
  14. #include <asm/div64.h>
  15. #else
  16. #include <linux/compat.h>
  17. #include <mtd/mtd-abi.h>
  18. #include <linux/errno.h>
  19. #include <linux/list.h>
  20. #include <div64.h>
  21. #if IS_ENABLED(CONFIG_DM)
  22. #include <dm/device.h>
  23. #endif
  24. #define MAX_MTD_DEVICES 32
  25. #endif
  26. #define MTD_ERASE_PENDING 0x01
  27. #define MTD_ERASING 0x02
  28. #define MTD_ERASE_SUSPEND 0x04
  29. #define MTD_ERASE_DONE 0x08
  30. #define MTD_ERASE_FAILED 0x10
  31. #define MTD_FAIL_ADDR_UNKNOWN -1LL
  32. /*
  33. * If the erase fails, fail_addr might indicate exactly which block failed. If
  34. * fail_addr = MTD_FAIL_ADDR_UNKNOWN, the failure was not at the device level
  35. * or was not specific to any particular block.
  36. */
  37. struct erase_info {
  38. struct mtd_info *mtd;
  39. uint64_t addr;
  40. uint64_t len;
  41. uint64_t fail_addr;
  42. u_long time;
  43. u_long retries;
  44. unsigned dev;
  45. unsigned cell;
  46. void (*callback) (struct erase_info *self);
  47. u_long priv;
  48. u_char state;
  49. struct erase_info *next;
  50. int scrub;
  51. };
  52. struct mtd_erase_region_info {
  53. uint64_t offset; /* At which this region starts, from the beginning of the MTD */
  54. uint32_t erasesize; /* For this region */
  55. uint32_t numblocks; /* Number of blocks of erasesize in this region */
  56. unsigned long *lockmap; /* If keeping bitmap of locks */
  57. };
  58. /**
  59. * struct mtd_oob_ops - oob operation operands
  60. * @mode: operation mode
  61. *
  62. * @len: number of data bytes to write/read
  63. *
  64. * @retlen: number of data bytes written/read
  65. *
  66. * @ooblen: number of oob bytes to write/read
  67. * @oobretlen: number of oob bytes written/read
  68. * @ooboffs: offset of oob data in the oob area (only relevant when
  69. * mode = MTD_OPS_PLACE_OOB or MTD_OPS_RAW)
  70. * @datbuf: data buffer - if NULL only oob data are read/written
  71. * @oobbuf: oob data buffer
  72. */
  73. struct mtd_oob_ops {
  74. unsigned int mode;
  75. size_t len;
  76. size_t retlen;
  77. size_t ooblen;
  78. size_t oobretlen;
  79. uint32_t ooboffs;
  80. uint8_t *datbuf;
  81. uint8_t *oobbuf;
  82. };
  83. #ifdef CONFIG_SYS_NAND_MAX_OOBFREE
  84. #define MTD_MAX_OOBFREE_ENTRIES_LARGE CONFIG_SYS_NAND_MAX_OOBFREE
  85. #else
  86. #define MTD_MAX_OOBFREE_ENTRIES_LARGE 32
  87. #endif
  88. #ifdef CONFIG_SYS_NAND_MAX_ECCPOS
  89. #define MTD_MAX_ECCPOS_ENTRIES_LARGE CONFIG_SYS_NAND_MAX_ECCPOS
  90. #else
  91. #define MTD_MAX_ECCPOS_ENTRIES_LARGE 680
  92. #endif
  93. /**
  94. * struct mtd_oob_region - oob region definition
  95. * @offset: region offset
  96. * @length: region length
  97. *
  98. * This structure describes a region of the OOB area, and is used
  99. * to retrieve ECC or free bytes sections.
  100. * Each section is defined by an offset within the OOB area and a
  101. * length.
  102. */
  103. struct mtd_oob_region {
  104. u32 offset;
  105. u32 length;
  106. };
  107. /*
  108. * struct mtd_ooblayout_ops - NAND OOB layout operations
  109. * @ecc: function returning an ECC region in the OOB area.
  110. * Should return -ERANGE if %section exceeds the total number of
  111. * ECC sections.
  112. * @free: function returning a free region in the OOB area.
  113. * Should return -ERANGE if %section exceeds the total number of
  114. * free sections.
  115. */
  116. struct mtd_ooblayout_ops {
  117. int (*ecc)(struct mtd_info *mtd, int section,
  118. struct mtd_oob_region *oobecc);
  119. int (*free)(struct mtd_info *mtd, int section,
  120. struct mtd_oob_region *oobfree);
  121. };
  122. /*
  123. * Internal ECC layout control structure. For historical reasons, there is a
  124. * similar, smaller struct nand_ecclayout_user (in mtd-abi.h) that is retained
  125. * for export to user-space via the ECCGETLAYOUT ioctl.
  126. * nand_ecclayout should be expandable in the future simply by the above macros.
  127. */
  128. struct nand_ecclayout {
  129. __u32 eccbytes;
  130. __u32 eccpos[MTD_MAX_ECCPOS_ENTRIES_LARGE];
  131. __u32 oobavail;
  132. struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES_LARGE];
  133. };
  134. struct module; /* only needed for owner field in mtd_info */
  135. struct mtd_info {
  136. u_char type;
  137. uint32_t flags;
  138. uint64_t size; // Total size of the MTD
  139. /* "Major" erase size for the device. Naïve users may take this
  140. * to be the only erase size available, or may use the more detailed
  141. * information below if they desire
  142. */
  143. uint32_t erasesize;
  144. /* Minimal writable flash unit size. In case of NOR flash it is 1 (even
  145. * though individual bits can be cleared), in case of NAND flash it is
  146. * one NAND page (or half, or one-fourths of it), in case of ECC-ed NOR
  147. * it is of ECC block size, etc. It is illegal to have writesize = 0.
  148. * Any driver registering a struct mtd_info must ensure a writesize of
  149. * 1 or larger.
  150. */
  151. uint32_t writesize;
  152. /*
  153. * Size of the write buffer used by the MTD. MTD devices having a write
  154. * buffer can write multiple writesize chunks at a time. E.g. while
  155. * writing 4 * writesize bytes to a device with 2 * writesize bytes
  156. * buffer the MTD driver can (but doesn't have to) do 2 writesize
  157. * operations, but not 4. Currently, all NANDs have writebufsize
  158. * equivalent to writesize (NAND page size). Some NOR flashes do have
  159. * writebufsize greater than writesize.
  160. */
  161. uint32_t writebufsize;
  162. uint32_t oobsize; // Amount of OOB data per block (e.g. 16)
  163. uint32_t oobavail; // Available OOB bytes per block
  164. /*
  165. * If erasesize is a power of 2 then the shift is stored in
  166. * erasesize_shift otherwise erasesize_shift is zero. Ditto writesize.
  167. */
  168. unsigned int erasesize_shift;
  169. unsigned int writesize_shift;
  170. /* Masks based on erasesize_shift and writesize_shift */
  171. unsigned int erasesize_mask;
  172. unsigned int writesize_mask;
  173. /*
  174. * read ops return -EUCLEAN if max number of bitflips corrected on any
  175. * one region comprising an ecc step equals or exceeds this value.
  176. * Settable by driver, else defaults to ecc_strength. User can override
  177. * in sysfs. N.B. The meaning of the -EUCLEAN return code has changed;
  178. * see Documentation/ABI/testing/sysfs-class-mtd for more detail.
  179. */
  180. unsigned int bitflip_threshold;
  181. // Kernel-only stuff starts here.
  182. #ifndef __UBOOT__
  183. const char *name;
  184. #else
  185. char *name;
  186. #endif
  187. int index;
  188. /* OOB layout description */
  189. const struct mtd_ooblayout_ops *ooblayout;
  190. /* ECC layout structure pointer - read only! */
  191. struct nand_ecclayout *ecclayout;
  192. /* the ecc step size. */
  193. unsigned int ecc_step_size;
  194. /* max number of correctible bit errors per ecc step */
  195. unsigned int ecc_strength;
  196. /* Data for variable erase regions. If numeraseregions is zero,
  197. * it means that the whole device has erasesize as given above.
  198. */
  199. int numeraseregions;
  200. struct mtd_erase_region_info *eraseregions;
  201. /*
  202. * Do not call via these pointers, use corresponding mtd_*()
  203. * wrappers instead.
  204. */
  205. int (*_erase) (struct mtd_info *mtd, struct erase_info *instr);
  206. #ifndef __UBOOT__
  207. int (*_point) (struct mtd_info *mtd, loff_t from, size_t len,
  208. size_t *retlen, void **virt, resource_size_t *phys);
  209. int (*_unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
  210. #endif
  211. unsigned long (*_get_unmapped_area) (struct mtd_info *mtd,
  212. unsigned long len,
  213. unsigned long offset,
  214. unsigned long flags);
  215. int (*_read) (struct mtd_info *mtd, loff_t from, size_t len,
  216. size_t *retlen, u_char *buf);
  217. int (*_write) (struct mtd_info *mtd, loff_t to, size_t len,
  218. size_t *retlen, const u_char *buf);
  219. int (*_panic_write) (struct mtd_info *mtd, loff_t to, size_t len,
  220. size_t *retlen, const u_char *buf);
  221. int (*_read_oob) (struct mtd_info *mtd, loff_t from,
  222. struct mtd_oob_ops *ops);
  223. int (*_write_oob) (struct mtd_info *mtd, loff_t to,
  224. struct mtd_oob_ops *ops);
  225. int (*_get_fact_prot_info) (struct mtd_info *mtd, size_t len,
  226. size_t *retlen, struct otp_info *buf);
  227. int (*_read_fact_prot_reg) (struct mtd_info *mtd, loff_t from,
  228. size_t len, size_t *retlen, u_char *buf);
  229. int (*_get_user_prot_info) (struct mtd_info *mtd, size_t len,
  230. size_t *retlen, struct otp_info *buf);
  231. int (*_read_user_prot_reg) (struct mtd_info *mtd, loff_t from,
  232. size_t len, size_t *retlen, u_char *buf);
  233. int (*_write_user_prot_reg) (struct mtd_info *mtd, loff_t to,
  234. size_t len, size_t *retlen, u_char *buf);
  235. int (*_lock_user_prot_reg) (struct mtd_info *mtd, loff_t from,
  236. size_t len);
  237. #ifndef __UBOOT__
  238. int (*_writev) (struct mtd_info *mtd, const struct kvec *vecs,
  239. unsigned long count, loff_t to, size_t *retlen);
  240. #endif
  241. void (*_sync) (struct mtd_info *mtd);
  242. int (*_lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
  243. int (*_unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
  244. int (*_is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
  245. int (*_block_isreserved) (struct mtd_info *mtd, loff_t ofs);
  246. int (*_block_isbad) (struct mtd_info *mtd, loff_t ofs);
  247. int (*_block_markbad) (struct mtd_info *mtd, loff_t ofs);
  248. #ifndef __UBOOT__
  249. int (*_suspend) (struct mtd_info *mtd);
  250. void (*_resume) (struct mtd_info *mtd);
  251. void (*_reboot) (struct mtd_info *mtd);
  252. #endif
  253. /*
  254. * If the driver is something smart, like UBI, it may need to maintain
  255. * its own reference counting. The below functions are only for driver.
  256. */
  257. int (*_get_device) (struct mtd_info *mtd);
  258. void (*_put_device) (struct mtd_info *mtd);
  259. #ifndef __UBOOT__
  260. /* Backing device capabilities for this device
  261. * - provides mmap capabilities
  262. */
  263. struct backing_dev_info *backing_dev_info;
  264. struct notifier_block reboot_notifier; /* default mode before reboot */
  265. #endif
  266. /* ECC status information */
  267. struct mtd_ecc_stats ecc_stats;
  268. /* Subpage shift (NAND) */
  269. int subpage_sft;
  270. void *priv;
  271. struct module *owner;
  272. #ifndef __UBOOT__
  273. struct device dev;
  274. #else
  275. struct udevice *dev;
  276. #endif
  277. int usecount;
  278. /* MTD devices do not have any parent. MTD partitions do. */
  279. struct mtd_info *parent;
  280. /*
  281. * Offset of the partition relatively to the parent offset.
  282. * Is 0 for real MTD devices (ie. not partitions).
  283. */
  284. u64 offset;
  285. /*
  286. * List node used to add an MTD partition to the parent
  287. * partition list.
  288. */
  289. struct list_head node;
  290. /*
  291. * List of partitions attached to this MTD device (the parent
  292. * MTD device can itself be a partition).
  293. */
  294. struct list_head partitions;
  295. };
  296. #if IS_ENABLED(CONFIG_DM)
  297. static inline void mtd_set_of_node(struct mtd_info *mtd,
  298. const struct device_node *np)
  299. {
  300. mtd->dev->node.np = np;
  301. }
  302. static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd)
  303. {
  304. return mtd->dev->node.np;
  305. }
  306. #else
  307. struct device_node;
  308. static inline void mtd_set_of_node(struct mtd_info *mtd,
  309. const struct device_node *np)
  310. {
  311. }
  312. static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd)
  313. {
  314. return NULL;
  315. }
  316. #endif
  317. static inline bool mtd_is_partition(const struct mtd_info *mtd)
  318. {
  319. return mtd->parent;
  320. }
  321. static inline bool mtd_has_partitions(const struct mtd_info *mtd)
  322. {
  323. return !list_empty(&mtd->partitions);
  324. }
  325. int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
  326. struct mtd_oob_region *oobecc);
  327. int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
  328. int *section,
  329. struct mtd_oob_region *oobregion);
  330. int mtd_ooblayout_get_eccbytes(struct mtd_info *mtd, u8 *eccbuf,
  331. const u8 *oobbuf, int start, int nbytes);
  332. int mtd_ooblayout_set_eccbytes(struct mtd_info *mtd, const u8 *eccbuf,
  333. u8 *oobbuf, int start, int nbytes);
  334. int mtd_ooblayout_free(struct mtd_info *mtd, int section,
  335. struct mtd_oob_region *oobfree);
  336. int mtd_ooblayout_get_databytes(struct mtd_info *mtd, u8 *databuf,
  337. const u8 *oobbuf, int start, int nbytes);
  338. int mtd_ooblayout_set_databytes(struct mtd_info *mtd, const u8 *databuf,
  339. u8 *oobbuf, int start, int nbytes);
  340. int mtd_ooblayout_count_freebytes(struct mtd_info *mtd);
  341. int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd);
  342. static inline void mtd_set_ooblayout(struct mtd_info *mtd,
  343. const struct mtd_ooblayout_ops *ooblayout)
  344. {
  345. mtd->ooblayout = ooblayout;
  346. }
  347. static inline int mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops)
  348. {
  349. return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize;
  350. }
  351. int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
  352. #ifndef __UBOOT__
  353. int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
  354. void **virt, resource_size_t *phys);
  355. int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
  356. #endif
  357. unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len,
  358. unsigned long offset, unsigned long flags);
  359. int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
  360. u_char *buf);
  361. int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
  362. const u_char *buf);
  363. int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
  364. const u_char *buf);
  365. int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops);
  366. int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
  367. int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
  368. struct otp_info *buf);
  369. int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
  370. size_t *retlen, u_char *buf);
  371. int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
  372. struct otp_info *buf);
  373. int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
  374. size_t *retlen, u_char *buf);
  375. int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
  376. size_t *retlen, u_char *buf);
  377. int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len);
  378. #ifndef __UBOOT__
  379. int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
  380. unsigned long count, loff_t to, size_t *retlen);
  381. #endif
  382. static inline void mtd_sync(struct mtd_info *mtd)
  383. {
  384. if (mtd->_sync)
  385. mtd->_sync(mtd);
  386. }
  387. int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
  388. int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
  389. int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len);
  390. int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs);
  391. int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs);
  392. int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs);
  393. #ifndef __UBOOT__
  394. static inline int mtd_suspend(struct mtd_info *mtd)
  395. {
  396. return mtd->_suspend ? mtd->_suspend(mtd) : 0;
  397. }
  398. static inline void mtd_resume(struct mtd_info *mtd)
  399. {
  400. if (mtd->_resume)
  401. mtd->_resume(mtd);
  402. }
  403. #endif
  404. static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)
  405. {
  406. if (mtd->erasesize_shift)
  407. return sz >> mtd->erasesize_shift;
  408. do_div(sz, mtd->erasesize);
  409. return sz;
  410. }
  411. static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd)
  412. {
  413. if (mtd->erasesize_shift)
  414. return sz & mtd->erasesize_mask;
  415. return do_div(sz, mtd->erasesize);
  416. }
  417. static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
  418. {
  419. if (mtd->writesize_shift)
  420. return sz >> mtd->writesize_shift;
  421. do_div(sz, mtd->writesize);
  422. return sz;
  423. }
  424. static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd)
  425. {
  426. if (mtd->writesize_shift)
  427. return sz & mtd->writesize_mask;
  428. return do_div(sz, mtd->writesize);
  429. }
  430. static inline int mtd_has_oob(const struct mtd_info *mtd)
  431. {
  432. return mtd->_read_oob && mtd->_write_oob;
  433. }
  434. static inline int mtd_type_is_nand(const struct mtd_info *mtd)
  435. {
  436. return mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH;
  437. }
  438. static inline int mtd_can_have_bb(const struct mtd_info *mtd)
  439. {
  440. return !!mtd->_block_isbad;
  441. }
  442. /* Kernel-side ioctl definitions */
  443. struct mtd_partition;
  444. struct mtd_part_parser_data;
  445. extern int mtd_device_parse_register(struct mtd_info *mtd,
  446. const char * const *part_probe_types,
  447. struct mtd_part_parser_data *parser_data,
  448. const struct mtd_partition *defparts,
  449. int defnr_parts);
  450. #define mtd_device_register(master, parts, nr_parts) \
  451. mtd_device_parse_register(master, NULL, NULL, parts, nr_parts)
  452. extern int mtd_device_unregister(struct mtd_info *master);
  453. extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
  454. extern int __get_mtd_device(struct mtd_info *mtd);
  455. extern void __put_mtd_device(struct mtd_info *mtd);
  456. extern struct mtd_info *get_mtd_device_nm(const char *name);
  457. extern void put_mtd_device(struct mtd_info *mtd);
  458. #ifndef __UBOOT__
  459. struct mtd_notifier {
  460. void (*add)(struct mtd_info *mtd);
  461. void (*remove)(struct mtd_info *mtd);
  462. struct list_head list;
  463. };
  464. extern void register_mtd_user (struct mtd_notifier *new);
  465. extern int unregister_mtd_user (struct mtd_notifier *old);
  466. #endif
  467. void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size);
  468. #ifdef CONFIG_MTD_PARTITIONS
  469. void mtd_erase_callback(struct erase_info *instr);
  470. #else
  471. static inline void mtd_erase_callback(struct erase_info *instr)
  472. {
  473. if (instr->callback)
  474. instr->callback(instr);
  475. }
  476. #endif
  477. static inline int mtd_is_bitflip(int err) {
  478. return err == -EUCLEAN;
  479. }
  480. static inline int mtd_is_eccerr(int err) {
  481. return err == -EBADMSG;
  482. }
  483. static inline int mtd_is_bitflip_or_eccerr(int err) {
  484. return mtd_is_bitflip(err) || mtd_is_eccerr(err);
  485. }
  486. unsigned mtd_mmap_capabilities(struct mtd_info *mtd);
  487. #ifdef __UBOOT__
  488. /* drivers/mtd/mtdcore.h */
  489. int add_mtd_device(struct mtd_info *mtd);
  490. int del_mtd_device(struct mtd_info *mtd);
  491. int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
  492. int del_mtd_partitions(struct mtd_info *);
  493. struct mtd_info *__mtd_next_device(int i);
  494. #define mtd_for_each_device(mtd) \
  495. for ((mtd) = __mtd_next_device(0); \
  496. (mtd) != NULL; \
  497. (mtd) = __mtd_next_device(mtd->index + 1))
  498. int mtd_arg_off(const char *arg, int *idx, loff_t *off, loff_t *size,
  499. loff_t *maxsize, int devtype, uint64_t chipsize);
  500. int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off,
  501. loff_t *size, loff_t *maxsize, int devtype,
  502. uint64_t chipsize);
  503. /* drivers/mtd/mtdcore.c */
  504. void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
  505. const uint64_t length, uint64_t *len_incl_bad,
  506. int *truncated);
  507. /* drivers/mtd/mtd_uboot.c */
  508. int mtd_search_alternate_name(const char *mtdname, char *altname,
  509. unsigned int max_len);
  510. #endif
  511. #endif /* __MTD_MTD_H__ */