public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: AKASHI Takahiro <takahiro.akashi@linaro.org>, sjg@chromium.org
Cc: masami.hiramatsu@linaro.org, u-boot@lists.denx.de, lukma@denx.de,
	peng.fan@nxp.com, jh80.chung@samsung.com, bmeng.cn@gmail.com,
	sr@denx.de, ilias.apalodimas@linaro.org
Subject: Re: [PATCH v3 11/19] dm: disk: add UCLASS_PARTITION
Date: Sat, 9 Apr 2022 21:05:07 +0200	[thread overview]
Message-ID: <f6b06a8b-e18b-170f-3ef0-dc48ef3dde14@gmx.de> (raw)
In-Reply-To: <20220308113657.221101-12-takahiro.akashi@linaro.org>

On 3/8/22 12:36, AKASHI Takahiro wrote:
> With this new function, UCLASS_PARTITION devices will be created as
> child nodes of UCLASS_BLK device.
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>   disk/Makefile          |   3 +
>   disk/disk-uclass.c     | 153 +++++++++++++++++++++++++++++++++++++++++
>   include/dm/uclass-id.h |   1 +
>   include/part.h         |  11 +++
>   4 files changed, 168 insertions(+)
>   create mode 100644 disk/disk-uclass.c
>
> diff --git a/disk/Makefile b/disk/Makefile
> index 6ce5a687b36c..ec37b74f5f40 100644
> --- a/disk/Makefile
> +++ b/disk/Makefile
> @@ -6,6 +6,9 @@
>   #ccflags-y += -DET_DEBUG -DDEBUG
>
>   obj-$(CONFIG_PARTITIONS)	+= part.o
> +ifdef CONFIG_$(SPL_)BLK
> +obj-$(CONFIG_PARTITIONS) 	+= disk-uclass.o

phycore-rk3288_defconfig has CONFIG_SPL_LIBDISK_SUPPORT=n ("Support disk
partitions").
But spl/disk/disk-uclass is built.
This leads to an unnecessary size increase of the SPL image.
With this size increase building fails.

Best regards

Heinrich

> +endif
>   obj-$(CONFIG_$(SPL_)MAC_PARTITION)   += part_mac.o
>   obj-$(CONFIG_$(SPL_)DOS_PARTITION)   += part_dos.o
>   obj-$(CONFIG_$(SPL_)ISO_PARTITION)   += part_iso.o
> diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
> new file mode 100644
> index 000000000000..4918a2f72d1e
> --- /dev/null
> +++ b/disk/disk-uclass.c
> @@ -0,0 +1,153 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + *  Software partition device (UCLASS_PARTITION)
> + *
> + *  Copyright (c) 2021 Linaro Limited
> + *			Author: AKASHI Takahiro
> + */
> +
> +#define LOG_CATEGORY UCLASS_PARTITION
> +
> +#include <blk.h>
> +#include <dm.h>
> +#include <log.h>
> +#include <part.h>
> +#include <vsprintf.h>
> +#include <dm/device-internal.h>
> +#include <dm/lists.h>
> +
> +int part_create_block_devices(struct udevice *blk_dev)
> +{
> +	int part, count;
> +	struct blk_desc *desc = dev_get_uclass_plat(blk_dev);
> +	struct disk_partition info;
> +	struct disk_part *part_data;
> +	char devname[32];
> +	struct udevice *dev;
> +	int ret;
> +
> +	if (!CONFIG_IS_ENABLED(PARTITIONS) ||
> +	    !CONFIG_IS_ENABLED(HAVE_BLOCK_DEVICE))
> +		return 0;
> +
> +	if (device_get_uclass_id(blk_dev) != UCLASS_BLK)
> +		return 0;
> +
> +	/* Add devices for each partition */
> +	for (count = 0, part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
> +		if (part_get_info(desc, part, &info))
> +			continue;
> +		snprintf(devname, sizeof(devname), "%s:%d", blk_dev->name,
> +			 part);
> +
> +		ret = device_bind_driver(blk_dev, "blk_partition",
> +					 strdup(devname), &dev);
> +		if (ret)
> +			return ret;
> +
> +		part_data = dev_get_uclass_plat(dev);
> +		part_data->partnum = part;
> +		part_data->gpt_part_info = info;
> +		count++;
> +
> +		ret = device_probe(dev);
> +		if (ret) {
> +			debug("Can't probe\n");
> +			count--;
> +			device_unbind(dev);
> +
> +			continue;
> +		}
> +	}
> +	debug("%s: %d partitions found in %s\n", __func__, count,
> +	      blk_dev->name);
> +
> +	return 0;
> +}
> +
> +static ulong blk_part_read(struct udevice *dev, lbaint_t start,
> +			   lbaint_t blkcnt, void *buffer)
> +{
> +	struct udevice *parent;
> +	struct disk_part *part;
> +	const struct blk_ops *ops;
> +
> +	parent = dev_get_parent(dev);
> +	ops = blk_get_ops(parent);
> +	if (!ops->read)
> +		return -ENOSYS;
> +
> +	part = dev_get_uclass_plat(dev);
> +	if (start >= part->gpt_part_info.size)
> +		return 0;
> +
> +	if ((start + blkcnt) > part->gpt_part_info.size)
> +		blkcnt = part->gpt_part_info.size - start;
> +	start += part->gpt_part_info.start;
> +
> +	return ops->read(parent, start, blkcnt, buffer);
> +}
> +
> +static ulong blk_part_write(struct udevice *dev, lbaint_t start,
> +			    lbaint_t blkcnt, const void *buffer)
> +{
> +	struct udevice *parent;
> +	struct disk_part *part;
> +	const struct blk_ops *ops;
> +
> +	parent = dev_get_parent(dev);
> +	ops = blk_get_ops(parent);
> +	if (!ops->write)
> +		return -ENOSYS;
> +
> +	part = dev_get_uclass_plat(dev);
> +	if (start >= part->gpt_part_info.size)
> +		return 0;
> +
> +	if ((start + blkcnt) > part->gpt_part_info.size)
> +		blkcnt = part->gpt_part_info.size - start;
> +	start += part->gpt_part_info.start;
> +
> +	return ops->write(parent, start, blkcnt, buffer);
> +}
> +
> +static ulong blk_part_erase(struct udevice *dev, lbaint_t start,
> +			    lbaint_t blkcnt)
> +{
> +	struct udevice *parent;
> +	struct disk_part *part;
> +	const struct blk_ops *ops;
> +
> +	parent = dev_get_parent(dev);
> +	ops = blk_get_ops(parent);
> +	if (!ops->erase)
> +		return -ENOSYS;
> +
> +	part = dev_get_uclass_plat(dev);
> +	if (start >= part->gpt_part_info.size)
> +		return 0;
> +
> +	if ((start + blkcnt) > part->gpt_part_info.size)
> +		blkcnt = part->gpt_part_info.size - start;
> +	start += part->gpt_part_info.start;
> +
> +	return ops->erase(parent, start, blkcnt);
> +}
> +
> +static const struct blk_ops blk_part_ops = {
> +	.read	= blk_part_read,
> +	.write	= blk_part_write,
> +	.erase	= blk_part_erase,
> +};
> +
> +U_BOOT_DRIVER(blk_partition) = {
> +	.name		= "blk_partition",
> +	.id		= UCLASS_PARTITION,
> +	.ops		= &blk_part_ops,
> +};
> +
> +UCLASS_DRIVER(partition) = {
> +	.id		= UCLASS_PARTITION,
> +	.per_device_plat_auto	= sizeof(struct disk_part),
> +	.name		= "partition",
> +};
> diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
> index 0e26e1d13824..230b1ea528cf 100644
> --- a/include/dm/uclass-id.h
> +++ b/include/dm/uclass-id.h
> @@ -83,6 +83,7 @@ enum uclass_id {
>   	UCLASS_P2SB,		/* (x86) Primary-to-Sideband Bus */
>   	UCLASS_PANEL,		/* Display panel, such as an LCD */
>   	UCLASS_PANEL_BACKLIGHT,	/* Backlight controller for panel */
> +	UCLASS_PARTITION,	/* Logical disk partition device */
>   	UCLASS_PCH,		/* x86 platform controller hub */
>   	UCLASS_PCI,		/* PCI bus */
>   	UCLASS_PCI_EP,		/* PCI endpoint device */
> diff --git a/include/part.h b/include/part.h
> index 53cfbdd87671..95e30e60af10 100644
> --- a/include/part.h
> +++ b/include/part.h
> @@ -253,6 +253,17 @@ void part_set_generic_name(const struct blk_desc *dev_desc,
>   	int part_num, char *name);
>
>   extern const struct block_drvr block_drvr[];
> +
> +struct udevice;
> +/**
> + * part_create_block_devices - Create block devices for disk partitions
> + *
> + * Create UCLASS_PARTITION udevices for each of disk partitions in @parent
> + *
> + * @blk_dev:	Whole disk device
> + */
> +int part_create_block_devices(struct udevice *blk_dev);
> +
>   #else
>   static inline struct blk_desc *blk_get_dev(const char *ifname, int dev)
>   { return NULL; }


  reply	other threads:[~2022-04-09 19:05 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08 11:36 [PATCH v3 00/19] efi_loader: more tightly integrate UEFI disks to driver model AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 01/19] scsi: call device_probe() after scanning AKASHI Takahiro
2022-03-08 13:30   ` Heinrich Schuchardt
2022-03-08 11:36 ` [PATCH v3 02/19] usb: storage: " AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 03/19] mmc: " AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 04/19] nvme: " AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 05/19] sata: " AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 06/19] block: ide: " AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 07/19] virtio: call device_probe() in scanning AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 09/19] dm: tag: add some document AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 10/19] test: dm: add tests for tag support AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 11/19] dm: disk: add UCLASS_PARTITION AKASHI Takahiro
2022-04-09 19:05   ` Heinrich Schuchardt [this message]
2022-04-13  3:16     ` AKASHI Takahiro
2022-04-14  6:17       ` AKASHI Takahiro
2022-04-14  7:13         ` Heinrich Schuchardt
2022-03-08 11:36 ` [PATCH v3 12/19] dm: blk: add a device-probe hook for scanning disk partitions AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 14/19] efi_loader: disk: a helper function to create efi_disk objects from udevice AKASHI Takahiro
2022-04-09 11:16   ` Heinrich Schuchardt
2022-04-11  9:06     ` AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 15/19] efi_loader: disk: a helper function to delete efi_disk objects AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 16/19] dm: disk: add read/write interfaces with udevice AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 17/19] efi_loader: disk: use udevice instead of blk_desc AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 18/19] efi_loader: disk: not create BLK device for BLK(IF_TYPE_EFI_LOADER) devices AKASHI Takahiro
2022-03-08 11:36 ` [PATCH v3 19/19] efi_driver: align with efi_disk-dm integration AKASHI Takahiro
2022-03-08 12:59 ` [PATCH v3 00/19] efi_loader: more tightly integrate UEFI disks to driver model Heinrich Schuchardt
2022-03-08 13:04   ` AKASHI Takahiro
2022-03-08 13:24     ` Heinrich Schuchardt
2022-03-08 16:20       ` Simon Glass
2022-03-08 16:49 ` Heinrich Schuchardt
2022-03-08 16:56   ` Simon Glass
2022-03-08 17:21     ` Heinrich Schuchardt
2022-03-08 17:37       ` Simon Glass
2022-03-08 19:15     ` Soeren Moch
2022-03-08 21:20       ` Simon Glass
2022-03-09  0:13         ` Tom Rini
2022-03-09  2:32           ` Simon Glass
2022-03-09  3:00             ` Tom Rini
2022-03-09  3:10               ` Simon Glass
2022-03-09  3:11                 ` Simon Glass
2022-03-09 14:25                 ` Tom Rini
2022-03-09 15:33                   ` Simon Glass
2022-03-11 18:26                     ` Simon Glass
2022-03-11 22:43                     ` Soeren Moch
2022-03-12  5:02                       ` Simon Glass
2022-03-14  8:27                         ` Soeren Moch
2022-03-14 12:57                           ` Tom Rini
2022-03-14 17:08                           ` Simon Glass
2022-03-14 19:12                             ` Soeren Moch
2022-03-14 19:21                               ` Simon Glass
2022-03-09  7:16               ` Mark Kettenis
2022-03-09  2:10   ` AKASHI Takahiro
2022-03-09  2:34     ` Simon Glass
2022-03-09  2:48       ` AKASHI Takahiro
2022-03-09  3:10         ` Simon Glass
2022-03-09  5:07           ` AKASHI Takahiro
2022-03-09 11:52             ` Heinrich Schuchardt
     [not found] ` <20220308113657.221101-9-takahiro.akashi@linaro.org>
2022-03-09 11:41   ` [PATCH v3 08/19] dm: add tag support Ilias Apalodimas
2022-03-10  0:02     ` AKASHI Takahiro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f6b06a8b-e18b-170f-3ef0-dc48ef3dde14@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=bmeng.cn@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jh80.chung@samsung.com \
    --cc=lukma@denx.de \
    --cc=masami.hiramatsu@linaro.org \
    --cc=peng.fan@nxp.com \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --cc=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox