Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * MTD partitioning layer definitions |
| 3 | * |
Nicolas Pitre | 2f82af0 | 2009-09-14 03:25:28 -0400 | [diff] [blame] | 4 | * (C) 2000 Nicolas Pitre <nico@fluxnic.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * This code is GPL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef MTD_PARTITIONS_H |
| 10 | #define MTD_PARTITIONS_H |
| 11 | |
| 12 | #include <linux/types.h> |
| 13 | |
| 14 | |
| 15 | /* |
| 16 | * Partition definition structure: |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 17 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * An array of struct partition is passed along with a MTD object to |
Jamie Iles | f5671ab | 2011-05-23 17:15:46 +0100 | [diff] [blame] | 19 | * mtd_device_register() to create them. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * |
| 21 | * For each partition, these fields are available: |
| 22 | * name: string that will be used to label the partition's MTD device. |
Rafał Miłecki | 1a0915b | 2017-06-21 08:26:46 +0200 | [diff] [blame] | 23 | * types: some partitions can be containers using specific format to describe |
| 24 | * embedded subpartitions / volumes. E.g. many home routers use "firmware" |
| 25 | * partition that contains at least kernel and rootfs. In such case an |
| 26 | * extra parser is needed that will detect these dynamic partitions and |
| 27 | * report them to the MTD subsystem. If set this property stores an array |
| 28 | * of parser names to use when looking for subpartitions. |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 29 | * size: the partition size; if defined as MTDPART_SIZ_FULL, the partition |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * will extend to the end of the master MTD device. |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 31 | * offset: absolute starting position within the master MTD device; if |
| 32 | * defined as MTDPART_OFS_APPEND, the partition will start where the |
Dmitry Eremin-Solenikov | 1a31368 | 2011-06-06 18:04:14 +0400 | [diff] [blame] | 33 | * previous one ended; if MTDPART_OFS_NXTBLK, at the next erase block; |
| 34 | * if MTDPART_OFS_RETAIN, consume as much as possible, leaving size |
| 35 | * after the end of partition. |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 36 | * mask_flags: contains flags that have to be masked (removed) from the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | * master MTD flag set for the corresponding MTD partition. |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 38 | * For example, to force a read-only partition, simply adding |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | * MTD_WRITEABLE to the mask_flags will do the trick. |
| 40 | * |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 41 | * Note: writeable partitions require their size and offset be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | * erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK). |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 43 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | struct mtd_partition { |
Geert Uytterhoeven | 26a6d24 | 2013-11-12 20:11:26 +0100 | [diff] [blame] | 46 | const char *name; /* identifier string */ |
Rafał Miłecki | 1a0915b | 2017-06-21 08:26:46 +0200 | [diff] [blame] | 47 | const char *const *types; /* names of parsers to use if any */ |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 48 | uint64_t size; /* partition size */ |
| 49 | uint64_t offset; /* offset within the master MTD space */ |
David Woodhouse | 26cdb67 | 2008-12-10 14:08:12 +0000 | [diff] [blame] | 50 | uint32_t mask_flags; /* master MTD flags to mask out for this partition */ |
Sascha Hauer | 42e9401 | 2017-02-09 11:50:24 +0100 | [diff] [blame] | 51 | struct device_node *of_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
Dmitry Eremin-Solenikov | 1a31368 | 2011-06-06 18:04:14 +0400 | [diff] [blame] | 54 | #define MTDPART_OFS_RETAIN (-3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #define MTDPART_OFS_NXTBLK (-2) |
| 56 | #define MTDPART_OFS_APPEND (-1) |
| 57 | #define MTDPART_SIZ_FULL (0) |
| 58 | |
| 59 | |
Nicolas Pitre | 7699ad3 | 2009-06-15 01:10:18 -0400 | [diff] [blame] | 60 | struct mtd_info; |
Dmitry Eremin-Solenikov | d26c87d | 2011-05-29 21:32:33 +0400 | [diff] [blame] | 61 | struct device_node; |
Nicolas Pitre | 7699ad3 | 2009-06-15 01:10:18 -0400 | [diff] [blame] | 62 | |
Dmitry Eremin-Solenikov | c797533 | 2011-06-10 18:18:28 +0400 | [diff] [blame] | 63 | /** |
| 64 | * struct mtd_part_parser_data - used to pass data to MTD partition parsers. |
| 65 | * @origin: for RedBoot, start address of MTD device |
| 66 | */ |
| 67 | struct mtd_part_parser_data { |
| 68 | unsigned long origin; |
| 69 | }; |
| 70 | |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* |
| 73 | * Functions dealing with the various ways of partitioning the space |
| 74 | */ |
| 75 | |
| 76 | struct mtd_part_parser { |
| 77 | struct list_head list; |
| 78 | struct module *owner; |
| 79 | const char *name; |
Brian Norris | b9adf46 | 2015-12-04 15:25:14 -0800 | [diff] [blame] | 80 | int (*parse_fn)(struct mtd_info *, const struct mtd_partition **, |
Dmitry Eremin-Solenikov | c797533 | 2011-06-10 18:18:28 +0400 | [diff] [blame] | 81 | struct mtd_part_parser_data *); |
Brian Norris | adc83bf | 2015-12-09 10:24:03 -0800 | [diff] [blame] | 82 | void (*cleanup)(const struct mtd_partition *pparts, int nr_parts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Brian Norris | 07fd2f8 | 2015-12-04 15:25:17 -0800 | [diff] [blame] | 85 | /* Container for passing around a set of parsed partitions */ |
| 86 | struct mtd_partitions { |
| 87 | const struct mtd_partition *parts; |
| 88 | int nr_parts; |
| 89 | const struct mtd_part_parser *parser; |
| 90 | }; |
| 91 | |
Brian Norris | b9eab01 | 2015-11-11 19:13:29 -0800 | [diff] [blame] | 92 | extern int __register_mtd_parser(struct mtd_part_parser *parser, |
| 93 | struct module *owner); |
| 94 | #define register_mtd_parser(parser) __register_mtd_parser(parser, THIS_MODULE) |
| 95 | |
Axel Lin | cf3b2b1 | 2013-12-01 18:59:15 +0800 | [diff] [blame] | 96 | extern void deregister_mtd_parser(struct mtd_part_parser *parser); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Brian Norris | b9eab01 | 2015-11-11 19:13:29 -0800 | [diff] [blame] | 98 | /* |
| 99 | * module_mtd_part_parser() - Helper macro for MTD partition parsers that don't |
| 100 | * do anything special in module init/exit. Each driver may only use this macro |
| 101 | * once, and calling it replaces module_init() and module_exit(). |
| 102 | */ |
| 103 | #define module_mtd_part_parser(__mtd_part_parser) \ |
| 104 | module_driver(__mtd_part_parser, register_mtd_parser, \ |
| 105 | deregister_mtd_parser) |
| 106 | |
Richard Genoud | 5dee467 | 2012-07-10 18:23:39 +0200 | [diff] [blame] | 107 | int mtd_is_partition(const struct mtd_info *mtd); |
Geert Uytterhoeven | 26a6d24 | 2013-11-12 20:11:26 +0100 | [diff] [blame] | 108 | int mtd_add_partition(struct mtd_info *master, const char *name, |
Roman Tereshonkov | 5daa7b2 | 2010-09-17 13:31:41 +0300 | [diff] [blame] | 109 | long long offset, long long length); |
| 110 | int mtd_del_partition(struct mtd_info *master, int partno); |
Richard Genoud | 62082e5 | 2012-07-10 18:23:40 +0200 | [diff] [blame] | 111 | uint64_t mtd_get_device_size(const struct mtd_info *mtd); |
Roman Tereshonkov | 5daa7b2 | 2010-09-17 13:31:41 +0300 | [diff] [blame] | 112 | |
Scott Wood | 9a310d2 | 2008-01-15 17:54:43 -0600 | [diff] [blame] | 113 | #endif |