xref: /openbmc/u-boot/include/linux/mtd/partitions.h (revision 592cd5defd4f71d34ffcbd8dd3326bc10f662e20)
17e6ee7adSKyungmin Park /*
27e6ee7adSKyungmin Park  * MTD partitioning layer definitions
37e6ee7adSKyungmin Park  *
4ff94bc40SHeiko Schocher  * (C) 2000 Nicolas Pitre <nico@fluxnic.net>
57e6ee7adSKyungmin Park  *
67e6ee7adSKyungmin Park  * This code is GPL
77e6ee7adSKyungmin Park  */
87e6ee7adSKyungmin Park 
97e6ee7adSKyungmin Park #ifndef MTD_PARTITIONS_H
107e6ee7adSKyungmin Park #define MTD_PARTITIONS_H
117e6ee7adSKyungmin Park 
127e6ee7adSKyungmin Park #include <linux/types.h>
137e6ee7adSKyungmin Park 
147e6ee7adSKyungmin Park 
157e6ee7adSKyungmin Park /*
167e6ee7adSKyungmin Park  * Partition definition structure:
177e6ee7adSKyungmin Park  *
187e6ee7adSKyungmin Park  * An array of struct partition is passed along with a MTD object to
19ff94bc40SHeiko Schocher  * mtd_device_register() to create them.
207e6ee7adSKyungmin Park  *
217e6ee7adSKyungmin Park  * For each partition, these fields are available:
227e6ee7adSKyungmin Park  * name: string that will be used to label the partition's MTD device.
237e6ee7adSKyungmin Park  * size: the partition size; if defined as MTDPART_SIZ_FULL, the partition
247e6ee7adSKyungmin Park  * 	will extend to the end of the master MTD device.
257e6ee7adSKyungmin Park  * offset: absolute starting position within the master MTD device; if
267e6ee7adSKyungmin Park  * 	defined as MTDPART_OFS_APPEND, the partition will start where the
27ff94bc40SHeiko Schocher  *	previous one ended; if MTDPART_OFS_NXTBLK, at the next erase block;
28ff94bc40SHeiko Schocher  *	if MTDPART_OFS_RETAIN, consume as much as possible, leaving size
29ff94bc40SHeiko Schocher  *	after the end of partition.
307e6ee7adSKyungmin Park  * mask_flags: contains flags that have to be masked (removed) from the
317e6ee7adSKyungmin Park  * 	master MTD flag set for the corresponding MTD partition.
327e6ee7adSKyungmin Park  * 	For example, to force a read-only partition, simply adding
337e6ee7adSKyungmin Park  * 	MTD_WRITEABLE to the mask_flags will do the trick.
347e6ee7adSKyungmin Park  *
357e6ee7adSKyungmin Park  * Note: writeable partitions require their size and offset be
367e6ee7adSKyungmin Park  * erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK).
377e6ee7adSKyungmin Park  */
387e6ee7adSKyungmin Park 
397e6ee7adSKyungmin Park struct mtd_partition {
40ff94bc40SHeiko Schocher 	const char *name;		/* identifier string */
41aaa8eec5SSandeep Paulraj 	uint64_t size;			/* partition size */
42aaa8eec5SSandeep Paulraj 	uint64_t offset;		/* offset within the master MTD space */
43ff94bc40SHeiko Schocher 	uint32_t mask_flags;		/* master MTD flags to mask out for this partition */
447e6ee7adSKyungmin Park 	struct nand_ecclayout *ecclayout;	/* out of band layout for this partition (NAND only) */
457e6ee7adSKyungmin Park };
467e6ee7adSKyungmin Park 
47ff94bc40SHeiko Schocher #define MTDPART_OFS_RETAIN	(-3)
487e6ee7adSKyungmin Park #define MTDPART_OFS_NXTBLK	(-2)
497e6ee7adSKyungmin Park #define MTDPART_OFS_APPEND	(-1)
507e6ee7adSKyungmin Park #define MTDPART_SIZ_FULL	(0)
517e6ee7adSKyungmin Park 
527e6ee7adSKyungmin Park 
53ff94bc40SHeiko Schocher struct mtd_info;
54ff94bc40SHeiko Schocher struct device_node;
557e6ee7adSKyungmin Park 
56ff94bc40SHeiko Schocher #ifndef __UBOOT__
57ff94bc40SHeiko Schocher /**
58ff94bc40SHeiko Schocher  * struct mtd_part_parser_data - used to pass data to MTD partition parsers.
59ff94bc40SHeiko Schocher  * @origin: for RedBoot, start address of MTD device
60ff94bc40SHeiko Schocher  * @of_node: for OF parsers, device node containing partitioning information
61ff94bc40SHeiko Schocher  */
62ff94bc40SHeiko Schocher struct mtd_part_parser_data {
63ff94bc40SHeiko Schocher 	unsigned long origin;
64ff94bc40SHeiko Schocher 	struct device_node *of_node;
65ff94bc40SHeiko Schocher };
66ff94bc40SHeiko Schocher 
67ff94bc40SHeiko Schocher 
687e6ee7adSKyungmin Park /*
697e6ee7adSKyungmin Park  * Functions dealing with the various ways of partitioning the space
707e6ee7adSKyungmin Park  */
717e6ee7adSKyungmin Park 
727e6ee7adSKyungmin Park struct mtd_part_parser {
737e6ee7adSKyungmin Park 	struct list_head list;
747e6ee7adSKyungmin Park 	struct module *owner;
757e6ee7adSKyungmin Park 	const char *name;
76ff94bc40SHeiko Schocher 	int (*parse_fn)(struct mtd_info *, struct mtd_partition **,
77ff94bc40SHeiko Schocher 			struct mtd_part_parser_data *);
787e6ee7adSKyungmin Park };
797e6ee7adSKyungmin Park 
80ff94bc40SHeiko Schocher extern void register_mtd_parser(struct mtd_part_parser *parser);
81ff94bc40SHeiko Schocher extern void deregister_mtd_parser(struct mtd_part_parser *parser);
827e6ee7adSKyungmin Park #endif
837e6ee7adSKyungmin Park 
84ff94bc40SHeiko Schocher int mtd_add_partition(struct mtd_info *master, const char *name,
85ff94bc40SHeiko Schocher 		      long long offset, long long length);
86ff94bc40SHeiko Schocher int mtd_del_partition(struct mtd_info *master, int partno);
87ff94bc40SHeiko Schocher uint64_t mtd_get_device_size(const struct mtd_info *mtd);
88ff94bc40SHeiko Schocher 
89*21cc1fb5SMiquel Raynal #if defined(CONFIG_MTD_PARTITIONS)
90*21cc1fb5SMiquel Raynal int mtd_parse_partitions(struct mtd_info *parent, const char **_mtdparts,
91*21cc1fb5SMiquel Raynal 			 struct mtd_partition **_parts, int *_nparts);
92*21cc1fb5SMiquel Raynal void mtd_free_parsed_partitions(struct mtd_partition *parts,
93*21cc1fb5SMiquel Raynal 				unsigned int nparts);
94*21cc1fb5SMiquel Raynal #else
95*21cc1fb5SMiquel Raynal static inline int
mtd_parse_partitions(struct mtd_info * parent,const char ** _mtdparts,struct mtd_partition ** _parts,int * _nparts)96*21cc1fb5SMiquel Raynal mtd_parse_partitions(struct mtd_info *parent, const char **_mtdparts,
97*21cc1fb5SMiquel Raynal 		     struct mtd_partition **_parts, int *_nparts)
98*21cc1fb5SMiquel Raynal {
99*21cc1fb5SMiquel Raynal 	*_nparts = 0;
100*21cc1fb5SMiquel Raynal 
101*21cc1fb5SMiquel Raynal 	return 0;
102*21cc1fb5SMiquel Raynal }
103*21cc1fb5SMiquel Raynal static inline void
mtd_free_parsed_partitions(struct mtd_partition * parts,unsigned int nparts)104*21cc1fb5SMiquel Raynal mtd_free_parsed_partitions(struct mtd_partition *parts, unsigned int nparts)
105*21cc1fb5SMiquel Raynal {
106*21cc1fb5SMiquel Raynal 	return;
107*21cc1fb5SMiquel Raynal }
108*21cc1fb5SMiquel Raynal #endif /* defined(MTD_PARTITIONS) */
109*21cc1fb5SMiquel Raynal 
1107e6ee7adSKyungmin Park #endif
111