[U-Boot] [PATCH v6 28/31] mtd: mtdpart: implement proper partition handling

Boris Brezillon boris.brezillon at bootlin.com
Thu Aug 16 16:19:48 UTC 2018


+Rafal

On Thu, 16 Aug 2018 17:30:26 +0200
Miquel Raynal <miquel.raynal at bootlin.com> wrote:

> 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.

That's also something I'd like to have in Linux ;-). But you'll
probably have to sync with Rafal before porting that to Linux.

> 
> Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
> ---

[...]

> diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
> index 755c785416..3902c9ec08 100644
> --- a/include/linux/mtd/mtd.h
> +++ b/include/linux/mtd/mtd.h
> @@ -307,6 +307,15 @@ struct mtd_info {
>  	struct udevice *dev;
>  #endif
>  	int usecount;
> +
> +	/* MTD devices do not have any parent. MTD partitions do. */
> +	struct mtd_info *parent;

Add a blank line after each declaration.

> +	/* Offset of the partition relatively to the parent offset */

	Say that it must be 0 for real MTD devices (those that are not
	partitions).

> +	u64 offset;
> +	/* List node for this MTD device */

	/*
	 * List node used to add an MTD partition to the parent
	 * partition list.
	 */

> +	struct list_head node;
> +	/* List of this MTD devices partitions (if any) */

	/*
	 * 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 +343,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 struct mtd_info *mtd_part_node_to_info(struct list_head *n)
> +{
> +	return container_of(n, struct mtd_info, node);
> +}

Do you really need that one? Don't we have a list_for_each_entry() in
uboot?


More information about the U-Boot mailing list