xref: /linux/include/linux/mtd/partitions.h (revision 1a31368bf92ef2a7da3ba379672c405bd2751df9)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * MTD partitioning layer definitions
31da177e4SLinus Torvalds  *
42f82af08SNicolas Pitre  * (C) 2000 Nicolas Pitre <nico@fluxnic.net>
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * This code is GPL
71da177e4SLinus Torvalds  */
81da177e4SLinus Torvalds 
91da177e4SLinus Torvalds #ifndef MTD_PARTITIONS_H
101da177e4SLinus Torvalds #define MTD_PARTITIONS_H
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds #include <linux/types.h>
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds 
151da177e4SLinus Torvalds /*
161da177e4SLinus Torvalds  * Partition definition structure:
171da177e4SLinus Torvalds  *
181da177e4SLinus Torvalds  * An array of struct partition is passed along with a MTD object to
19f5671ab3SJamie Iles  * mtd_device_register() to create them.
201da177e4SLinus Torvalds  *
211da177e4SLinus Torvalds  * For each partition, these fields are available:
221da177e4SLinus Torvalds  * name: string that will be used to label the partition's MTD device.
231da177e4SLinus Torvalds  * size: the partition size; if defined as MTDPART_SIZ_FULL, the partition
241da177e4SLinus Torvalds  * 	will extend to the end of the master MTD device.
251da177e4SLinus Torvalds  * offset: absolute starting position within the master MTD device; if
261da177e4SLinus Torvalds  * 	defined as MTDPART_OFS_APPEND, the partition will start where the
27*1a31368bSDmitry Eremin-Solenikov  *	previous one ended; if MTDPART_OFS_NXTBLK, at the next erase block;
28*1a31368bSDmitry Eremin-Solenikov  *	if MTDPART_OFS_RETAIN, consume as much as possible, leaving size
29*1a31368bSDmitry Eremin-Solenikov  *	after the end of partition.
301da177e4SLinus Torvalds  * mask_flags: contains flags that have to be masked (removed) from the
311da177e4SLinus Torvalds  * 	master MTD flag set for the corresponding MTD partition.
321da177e4SLinus Torvalds  * 	For example, to force a read-only partition, simply adding
331da177e4SLinus Torvalds  * 	MTD_WRITEABLE to the mask_flags will do the trick.
341da177e4SLinus Torvalds  *
351da177e4SLinus Torvalds  * Note: writeable partitions require their size and offset be
361da177e4SLinus Torvalds  * erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK).
371da177e4SLinus Torvalds  */
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds struct mtd_partition {
401da177e4SLinus Torvalds 	char *name;			/* identifier string */
4169423d99SAdrian Hunter 	uint64_t size;			/* partition size */
4269423d99SAdrian Hunter 	uint64_t offset;		/* offset within the master MTD space */
4326cdb67cSDavid Woodhouse 	uint32_t mask_flags;		/* master MTD flags to mask out for this partition */
445bd34c09SThomas Gleixner 	struct nand_ecclayout *ecclayout;	/* out of band layout for this partition (NAND only) */
451da177e4SLinus Torvalds };
461da177e4SLinus Torvalds 
47*1a31368bSDmitry Eremin-Solenikov #define MTDPART_OFS_RETAIN	(-3)
481da177e4SLinus Torvalds #define MTDPART_OFS_NXTBLK	(-2)
491da177e4SLinus Torvalds #define MTDPART_OFS_APPEND	(-1)
501da177e4SLinus Torvalds #define MTDPART_SIZ_FULL	(0)
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds 
537699ad35SNicolas Pitre struct mtd_info;
547699ad35SNicolas Pitre 
551da177e4SLinus Torvalds /*
561da177e4SLinus Torvalds  * Functions dealing with the various ways of partitioning the space
571da177e4SLinus Torvalds  */
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds struct mtd_part_parser {
601da177e4SLinus Torvalds 	struct list_head list;
611da177e4SLinus Torvalds 	struct module *owner;
621da177e4SLinus Torvalds 	const char *name;
631da177e4SLinus Torvalds 	int (*parse_fn)(struct mtd_info *, struct mtd_partition **, unsigned long);
641da177e4SLinus Torvalds };
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds extern int register_mtd_parser(struct mtd_part_parser *parser);
671da177e4SLinus Torvalds extern int deregister_mtd_parser(struct mtd_part_parser *parser);
681da177e4SLinus Torvalds extern int parse_mtd_partitions(struct mtd_info *master, const char **types,
691da177e4SLinus Torvalds 				struct mtd_partition **pparts, unsigned long origin);
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds #define put_partition_parser(p) do { module_put((p)->owner); } while(0)
721da177e4SLinus Torvalds 
739a310d21SScott Wood struct device;
749a310d21SScott Wood struct device_node;
751da177e4SLinus Torvalds 
7611b73c8bSJamie Iles #ifdef CONFIG_MTD_OF_PARTS
779a310d21SScott Wood int __devinit of_mtd_parse_partitions(struct device *dev,
789a310d21SScott Wood                                       struct device_node *node,
799a310d21SScott Wood                                       struct mtd_partition **pparts);
8011b73c8bSJamie Iles #else
8111b73c8bSJamie Iles static inline int of_mtd_parse_partitions(struct device *dev,
8211b73c8bSJamie Iles 					  struct device_node *node,
8311b73c8bSJamie Iles 					  struct mtd_partition **pparts)
8411b73c8bSJamie Iles {
8511b73c8bSJamie Iles 	return 0;
8611b73c8bSJamie Iles }
8711b73c8bSJamie Iles #endif
889a310d21SScott Wood 
89a7e93dcdSRoman Tereshonkov int mtd_is_partition(struct mtd_info *mtd);
905daa7b21SRoman Tereshonkov int mtd_add_partition(struct mtd_info *master, char *name,
915daa7b21SRoman Tereshonkov 		      long long offset, long long length);
925daa7b21SRoman Tereshonkov int mtd_del_partition(struct mtd_info *master, int partno);
935daa7b21SRoman Tereshonkov 
949a310d21SScott Wood #endif
95