xref: /OK3568_Linux_fs/kernel/include/linux/mtd/partitions.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * MTD partitioning layer definitions
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * (C) 2000 Nicolas Pitre <nico@fluxnic.net>
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * This code is GPL
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef MTD_PARTITIONS_H
10*4882a593Smuzhiyun #define MTD_PARTITIONS_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/types.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun /*
16*4882a593Smuzhiyun  * Partition definition structure:
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * An array of struct partition is passed along with a MTD object to
19*4882a593Smuzhiyun  * mtd_device_register() to create them.
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  * For each partition, these fields are available:
22*4882a593Smuzhiyun  * name: string that will be used to label the partition's MTD device.
23*4882a593Smuzhiyun  * types: some partitions can be containers using specific format to describe
24*4882a593Smuzhiyun  *	embedded subpartitions / volumes. E.g. many home routers use "firmware"
25*4882a593Smuzhiyun  *	partition that contains at least kernel and rootfs. In such case an
26*4882a593Smuzhiyun  *	extra parser is needed that will detect these dynamic partitions and
27*4882a593Smuzhiyun  *	report them to the MTD subsystem. If set this property stores an array
28*4882a593Smuzhiyun  *	of parser names to use when looking for subpartitions.
29*4882a593Smuzhiyun  * size: the partition size; if defined as MTDPART_SIZ_FULL, the partition
30*4882a593Smuzhiyun  * 	will extend to the end of the master MTD device.
31*4882a593Smuzhiyun  * offset: absolute starting position within the master MTD device; if
32*4882a593Smuzhiyun  * 	defined as MTDPART_OFS_APPEND, the partition will start where the
33*4882a593Smuzhiyun  *	previous one ended; if MTDPART_OFS_NXTBLK, at the next erase block;
34*4882a593Smuzhiyun  *	if MTDPART_OFS_RETAIN, consume as much as possible, leaving size
35*4882a593Smuzhiyun  *	after the end of partition.
36*4882a593Smuzhiyun  * mask_flags: contains flags that have to be masked (removed) from the
37*4882a593Smuzhiyun  * 	master MTD flag set for the corresponding MTD partition.
38*4882a593Smuzhiyun  * 	For example, to force a read-only partition, simply adding
39*4882a593Smuzhiyun  * 	MTD_WRITEABLE to the mask_flags will do the trick.
40*4882a593Smuzhiyun  * add_flags: contains flags to add to the parent flags
41*4882a593Smuzhiyun  *
42*4882a593Smuzhiyun  * Note: writeable partitions require their size and offset be
43*4882a593Smuzhiyun  * erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK).
44*4882a593Smuzhiyun  */
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun struct mtd_partition {
47*4882a593Smuzhiyun 	const char *name;		/* identifier string */
48*4882a593Smuzhiyun 	const char *const *types;	/* names of parsers to use if any */
49*4882a593Smuzhiyun 	uint64_t size;			/* partition size */
50*4882a593Smuzhiyun 	uint64_t offset;		/* offset within the master MTD space */
51*4882a593Smuzhiyun 	uint32_t mask_flags;		/* master MTD flags to mask out for this partition */
52*4882a593Smuzhiyun 	uint32_t add_flags;		/* flags to add to the partition */
53*4882a593Smuzhiyun 	struct device_node *of_node;
54*4882a593Smuzhiyun };
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun #define MTDPART_OFS_RETAIN	(-3)
57*4882a593Smuzhiyun #define MTDPART_OFS_NXTBLK	(-2)
58*4882a593Smuzhiyun #define MTDPART_OFS_APPEND	(-1)
59*4882a593Smuzhiyun #define MTDPART_SIZ_FULL	(0)
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun struct mtd_info;
63*4882a593Smuzhiyun struct device_node;
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun /**
66*4882a593Smuzhiyun  * struct mtd_part_parser_data - used to pass data to MTD partition parsers.
67*4882a593Smuzhiyun  * @origin: for RedBoot, start address of MTD device
68*4882a593Smuzhiyun  */
69*4882a593Smuzhiyun struct mtd_part_parser_data {
70*4882a593Smuzhiyun 	unsigned long origin;
71*4882a593Smuzhiyun };
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun /*
75*4882a593Smuzhiyun  * Functions dealing with the various ways of partitioning the space
76*4882a593Smuzhiyun  */
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun struct mtd_part_parser {
79*4882a593Smuzhiyun 	struct list_head list;
80*4882a593Smuzhiyun 	struct module *owner;
81*4882a593Smuzhiyun 	const char *name;
82*4882a593Smuzhiyun 	const struct of_device_id *of_match_table;
83*4882a593Smuzhiyun 	int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
84*4882a593Smuzhiyun 			struct mtd_part_parser_data *);
85*4882a593Smuzhiyun 	void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);
86*4882a593Smuzhiyun };
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun /* Container for passing around a set of parsed partitions */
89*4882a593Smuzhiyun struct mtd_partitions {
90*4882a593Smuzhiyun 	const struct mtd_partition *parts;
91*4882a593Smuzhiyun 	int nr_parts;
92*4882a593Smuzhiyun 	const struct mtd_part_parser *parser;
93*4882a593Smuzhiyun };
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun extern int __register_mtd_parser(struct mtd_part_parser *parser,
96*4882a593Smuzhiyun 				 struct module *owner);
97*4882a593Smuzhiyun #define register_mtd_parser(parser) __register_mtd_parser(parser, THIS_MODULE)
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun extern void deregister_mtd_parser(struct mtd_part_parser *parser);
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun /*
102*4882a593Smuzhiyun  * module_mtd_part_parser() - Helper macro for MTD partition parsers that don't
103*4882a593Smuzhiyun  * do anything special in module init/exit. Each driver may only use this macro
104*4882a593Smuzhiyun  * once, and calling it replaces module_init() and module_exit().
105*4882a593Smuzhiyun  */
106*4882a593Smuzhiyun #define module_mtd_part_parser(__mtd_part_parser) \
107*4882a593Smuzhiyun 	module_driver(__mtd_part_parser, register_mtd_parser, \
108*4882a593Smuzhiyun 		      deregister_mtd_parser)
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun int mtd_add_partition(struct mtd_info *master, const char *name,
111*4882a593Smuzhiyun 		      long long offset, long long length);
112*4882a593Smuzhiyun int mtd_del_partition(struct mtd_info *master, int partno);
113*4882a593Smuzhiyun uint64_t mtd_get_device_size(const struct mtd_info *mtd);
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun #endif
116