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. |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 23 | * size: the partition size; if defined as MTDPART_SIZ_FULL, the partition |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | * will extend to the end of the master MTD device. |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 25 | * offset: absolute starting position within the master MTD device; if |
| 26 | * defined as MTDPART_OFS_APPEND, the partition will start where the |
Dmitry Eremin-Solenikov | 1a31368 | 2011-06-06 18:04:14 +0400 | [diff] [blame] | 27 | * previous one ended; if MTDPART_OFS_NXTBLK, at the next erase block; |
| 28 | * if MTDPART_OFS_RETAIN, consume as much as possible, leaving size |
| 29 | * after the end of partition. |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 30 | * mask_flags: contains flags that have to be masked (removed) from the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | * master MTD flag set for the corresponding MTD partition. |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 32 | * For example, to force a read-only partition, simply adding |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | * MTD_WRITEABLE to the mask_flags will do the trick. |
| 34 | * |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 35 | * Note: writeable partitions require their size and offset be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | * erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK). |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 37 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | struct mtd_partition { |
Geert Uytterhoeven | 26a6d24 | 2013-11-12 20:11:26 +0100 | [diff] [blame] | 40 | const char *name; /* identifier string */ |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 41 | uint64_t size; /* partition size */ |
| 42 | uint64_t offset; /* offset within the master MTD space */ |
David Woodhouse | 26cdb67 | 2008-12-10 14:08:12 +0000 | [diff] [blame] | 43 | uint32_t mask_flags; /* master MTD flags to mask out for this partition */ |
Brian Norris | cc26c3c | 2010-08-24 18:12:00 -0700 | [diff] [blame] | 44 | struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
Dmitry Eremin-Solenikov | 1a31368 | 2011-06-06 18:04:14 +0400 | [diff] [blame] | 47 | #define MTDPART_OFS_RETAIN (-3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define MTDPART_OFS_NXTBLK (-2) |
| 49 | #define MTDPART_OFS_APPEND (-1) |
| 50 | #define MTDPART_SIZ_FULL (0) |
| 51 | |
| 52 | |
Nicolas Pitre | 7699ad3 | 2009-06-15 01:10:18 -0400 | [diff] [blame] | 53 | struct mtd_info; |
Dmitry Eremin-Solenikov | d26c87d | 2011-05-29 21:32:33 +0400 | [diff] [blame] | 54 | struct device_node; |
Nicolas Pitre | 7699ad3 | 2009-06-15 01:10:18 -0400 | [diff] [blame] | 55 | |
Dmitry Eremin-Solenikov | c797533 | 2011-06-10 18:18:28 +0400 | [diff] [blame] | 56 | /** |
| 57 | * struct mtd_part_parser_data - used to pass data to MTD partition parsers. |
| 58 | * @origin: for RedBoot, start address of MTD device |
Dmitry Eremin-Solenikov | d26c87d | 2011-05-29 21:32:33 +0400 | [diff] [blame] | 59 | * @of_node: for OF parsers, device node containing partitioning information |
Dmitry Eremin-Solenikov | c797533 | 2011-06-10 18:18:28 +0400 | [diff] [blame] | 60 | */ |
| 61 | struct mtd_part_parser_data { |
| 62 | unsigned long origin; |
Dmitry Eremin-Solenikov | d26c87d | 2011-05-29 21:32:33 +0400 | [diff] [blame] | 63 | struct device_node *of_node; |
Dmitry Eremin-Solenikov | c797533 | 2011-06-10 18:18:28 +0400 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | /* |
| 68 | * Functions dealing with the various ways of partitioning the space |
| 69 | */ |
| 70 | |
| 71 | struct mtd_part_parser { |
| 72 | struct list_head list; |
| 73 | struct module *owner; |
| 74 | const char *name; |
Dmitry Eremin-Solenikov | c797533 | 2011-06-10 18:18:28 +0400 | [diff] [blame] | 75 | int (*parse_fn)(struct mtd_info *, struct mtd_partition **, |
| 76 | struct mtd_part_parser_data *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Axel Lin | 6e14a61 | 2013-12-01 19:01:06 +0800 | [diff] [blame] | 79 | extern void register_mtd_parser(struct mtd_part_parser *parser); |
Axel Lin | cf3b2b1 | 2013-12-01 18:59:15 +0800 | [diff] [blame] | 80 | extern void deregister_mtd_parser(struct mtd_part_parser *parser); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Richard Genoud | 5dee467 | 2012-07-10 18:23:39 +0200 | [diff] [blame] | 82 | int mtd_is_partition(const struct mtd_info *mtd); |
Geert Uytterhoeven | 26a6d24 | 2013-11-12 20:11:26 +0100 | [diff] [blame] | 83 | int mtd_add_partition(struct mtd_info *master, const char *name, |
Roman Tereshonkov | 5daa7b2 | 2010-09-17 13:31:41 +0300 | [diff] [blame] | 84 | long long offset, long long length); |
| 85 | int mtd_del_partition(struct mtd_info *master, int partno); |
Richard Genoud | 62082e5 | 2012-07-10 18:23:40 +0200 | [diff] [blame] | 86 | uint64_t mtd_get_device_size(const struct mtd_info *mtd); |
Roman Tereshonkov | 5daa7b2 | 2010-09-17 13:31:41 +0300 | [diff] [blame] | 87 | |
Scott Wood | 9a310d2 | 2008-01-15 17:54:43 -0600 | [diff] [blame] | 88 | #endif |