diff options
author | Miquel Raynal <miquel.raynal@bootlin.com> | 2018-09-29 13:58:27 +0300 |
---|---|---|
committer | Jagan Teki <jagan@amarulasolutions.com> | 2018-10-02 19:42:32 +0300 |
commit | 2a74930da57f6fbe3c24509f1d481f435acd2356 (patch) | |
tree | 63905613152ac9d2850b75084c7aa3213d4d6825 /include/linux | |
parent | ff4afa8a981e22eef670c7c857cb87983346cc2c (diff) | |
download | u-boot-2a74930da57f6fbe3c24509f1d481f435acd2356.tar.xz |
mtd: mtdpart: implement proper partition handling
Instead of collecting partitions in a flat list, create a hierarchy
within the mtd_info structure: use a partitions list to keep track of
the partitions of an MTD device (which might be itself a partition of
another MTD device), a pointer to the parent device (NULL when the MTD
device is the root one, not a partition).
By also saving directly in mtd_info the offset of the partition, we
can get rid of the mtd_part structure.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>
Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/mtd/mtd.h | 32 | ||||
-rw-r--r-- | include/linux/mtd/partitions.h | 1 |
2 files changed, 32 insertions, 1 deletions
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index af6f4a61f8..68e5915324 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -20,6 +20,7 @@ #include <linux/compat.h> #include <mtd/mtd-abi.h> #include <linux/errno.h> +#include <linux/list.h> #include <div64.h> #if IS_ENABLED(CONFIG_DM) #include <dm/device.h> @@ -307,6 +308,27 @@ struct mtd_info { struct udevice *dev; #endif int usecount; + + /* MTD devices do not have any parent. MTD partitions do. */ + struct mtd_info *parent; + + /* + * Offset of the partition relatively to the parent offset. + * Is 0 for real MTD devices (ie. not partitions). + */ + u64 offset; + + /* + * List node used to add an MTD partition to the parent + * partition list. + */ + struct list_head node; + + /* + * List of partitions attached to this MTD device (the parent + * MTD device can itself be a partition). + */ + struct list_head partitions; }; #if IS_ENABLED(CONFIG_DM) @@ -334,6 +356,16 @@ static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd) } #endif +static inline bool mtd_is_partition(const struct mtd_info *mtd) +{ + return mtd->parent; +} + +static inline bool mtd_has_partitions(const struct mtd_info *mtd) +{ + return !list_empty(&mtd->partitions); +} + int mtd_ooblayout_ecc(struct mtd_info *mtd, int section, struct mtd_oob_region *oobecc); int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte, diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h index 6eea0a547a..3822237f2a 100644 --- a/include/linux/mtd/partitions.h +++ b/include/linux/mtd/partitions.h @@ -81,7 +81,6 @@ extern void register_mtd_parser(struct mtd_part_parser *parser); extern void deregister_mtd_parser(struct mtd_part_parser *parser); #endif -int mtd_is_partition(const struct mtd_info *mtd); int mtd_add_partition(struct mtd_info *master, const char *name, long long offset, long long length); int mtd_del_partition(struct mtd_info *master, int partno); |