From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CD49C433EF for ; Fri, 8 Oct 2021 00:52:14 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7A10261053 for ; Fri, 8 Oct 2021 00:52:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7A10261053 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 329988332B; Fri, 8 Oct 2021 02:52:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Lg7jSeRz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5671A8332B; Fri, 8 Oct 2021 02:52:08 +0200 (CEST) Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 12BA8831E9 for ; Fri, 8 Oct 2021 02:52:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pl1-x62b.google.com with SMTP id j15so5074327plh.7 for ; Thu, 07 Oct 2021 17:52:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=sSJ3wKAY6s4EIsS6POKrjEuynsHACS4OahE7Kvw3Zmk=; b=Lg7jSeRzBJvlB04Iqsjxpjd/eeobHYBHkqD8ZbzYfDUV7UowZMyLnowfCxropM7wq1 rMdlivSWWwk6kX/V2UDSqO8JpK+1s+hw+0tb+Ecjdf4wsnpQZpT3+/LLXSqQJaKlpCIb WUnk179uqzFfewj/6dqEcz98RiRSpa6RUcuRbtcUeLUU7W+WnLFTcQVoMdvgUDaKXm7t ZUhZbUQfQks5yopsWH4ekXf2QS1olI2wj3xD8ogLf7yQ9Fx6d/GuJSIkekLbui5bjn+u cJA0iyO8ozuDug4ahQbSDPkjACOpPKbMJX6td49bXkOxeQyDQNRmNNSA07WbxalFKS0C Wg6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to; bh=sSJ3wKAY6s4EIsS6POKrjEuynsHACS4OahE7Kvw3Zmk=; b=7m0zS/ntEqhRrHfp/LxaMtGIQco1Tx3/Qei19+w+0MfBUcNggYQBMrEBeRqkErqDd6 rvZaKfPXLP/VJtPhFmGBxgwr+2jIPCmNqRic2tLAC6EsHDQ1MJftUExwT/xbbwHTZy+5 8XgEa056F+dGbia0AACIKoYcShbFFYiv5DKDb7UtznGhVlyuMsstN1jV9DySck4hy2yC 0XQt0CGSgpG5Qz8cG3U3aJdu2PyZpX6cM6NZHQfIwQZMXu5Rbek3+oTF5D0/bj6HrhgM Lz+n3Z1RHTFwcv8juKOiq0CktWXgVOvn1x6r3a510jB1Osj6hzwKQCdzIzKiWgZ/WiDa X8NA== X-Gm-Message-State: AOAM530vD2EtHs0Wm1MhCfWF3qlTOWIZTgUc71uI7umRNxvwoUr27ZhU 1F/bbzj1M1WcbzZx8iRHr5d4sQ== X-Google-Smtp-Source: ABdhPJzI21wl35PZ8xVd+hm5QJh4ZU2xaso9k9lhwkgBssAg8+eFfAwwt2JQa5HT4ZqcR4vP05eUDw== X-Received: by 2002:a17:90a:638b:: with SMTP id f11mr8953117pjj.52.1633654322167; Thu, 07 Oct 2021 17:52:02 -0700 (PDT) Received: from laputa (122-100-26-39m5.mineo.jp. [122.100.26.39]) by smtp.gmail.com with ESMTPSA id om5sm27594pjb.36.2021.10.07.17.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 17:52:01 -0700 (PDT) Date: Fri, 8 Oct 2021 09:51:56 +0900 From: AKASHI Takahiro To: Heinrich Schuchardt , u-boot@lists.denx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org Subject: Re: [RFC 07/22] dm: blk: add UCLASS_PARTITION Message-ID: <20211008005156.GA34717@laputa> Mail-Followup-To: AKASHI Takahiro , Heinrich Schuchardt , u-boot@lists.denx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org References: <20211001050228.55183-1-takahiro.akashi@linaro.org> <20211001050228.55183-15-takahiro.akashi@linaro.org> <20211004032759.GC39720@laputa> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211004032759.GC39720@laputa> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On Mon, Oct 04, 2021 at 12:27:59PM +0900, AKASHI Takahiro wrote: > On Fri, Oct 01, 2021 at 11:30:37AM +0200, Heinrich Schuchardt wrote: > > > > > > On 10/1/21 07:01, AKASHI Takahiro wrote: > > > UCLASS_PARTITION device will be created as a child node of > > > UCLASS_BLK device. > > > > > > Signed-off-by: AKASHI Takahiro > > > --- > > > drivers/block/blk-uclass.c | 111 +++++++++++++++++++++++++++++++++++++ > > > include/blk.h | 9 +++ > > > include/dm/uclass-id.h | 1 + > > > 3 files changed, 121 insertions(+) > > > > > > diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c > > > index 83682dcc181a..dd7f3c0fe31e 100644 > > > --- a/drivers/block/blk-uclass.c > > > +++ b/drivers/block/blk-uclass.c > > > @@ -12,6 +12,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > #include > > > #include > > > #include > > > @@ -695,6 +696,44 @@ int blk_unbind_all(int if_type) > > > return 0; > > > } > > > > > > +int blk_create_partitions(struct udevice *parent) > > > +{ > > > + int part, count; > > > + struct blk_desc *desc = dev_get_uclass_plat(parent); > > > + 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; > > > + > > > + /* 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", parent->name, > > > + part); > > > + > > > + ret = device_bind_driver(parent, "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++; > > > + > > > + device_probe(dev); > > > + } > > > + debug("%s: %d partitions found in %s\n", __func__, count, parent->name); > > > + > > > + return 0; > > > +} > > > + > > > static int blk_post_probe(struct udevice *dev) > > > { > > > if (IS_ENABLED(CONFIG_PARTITIONS) && > > > @@ -713,3 +752,75 @@ UCLASS_DRIVER(blk) = { > > > .post_probe = blk_post_probe, > > > .per_device_plat_auto = sizeof(struct blk_desc), > > > }; > > > + > > > +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); > > > > What device type will the parent have if it is a eMMC hardware partition? > > > > > + ops = blk_get_ops(parent); > > > + if (!ops->read) > > > + return -ENOSYS; > > > + > > > + part = dev_get_uclass_plat(dev); > > > > You should check that we do not access the block device past the > > partition end: > > Yes, I will fix all of checks. > > > struct blk_desc *desc = dev_get_uclass_plat(parent); > > if ((start + blkcnt) * desc->blksz < part->gpt_part_info.blksz) > > return -EFAULT. > > > > > + start += part->gpt_part_info.start; A better solution is: 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; instead of returning -EFAULT. (note that start and blkcnt are in "block".) -Takahiro Akashi > > > + > > > + 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); > > > + start += part->gpt_part_info.start; > > > > here too > > > > > + > > > + 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); > > > + start += part->gpt_part_info.start; > > > > here too > > > > Best regards > > > > Heinrich > > > > > + > > > + 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/blk.h b/include/blk.h > > > index 19bab081c2cd..3d883eb1db64 100644 > > > --- a/include/blk.h > > > +++ b/include/blk.h > > > @@ -366,6 +366,15 @@ int blk_create_devicef(struct udevice *parent, const char *drv_name, > > > const char *name, int if_type, int devnum, int blksz, > > > lbaint_t lba, struct udevice **devp); > > > > > > +/** > > > + * blk_create_partitions - Create block devices for disk partitions > > > + * > > > + * Create UCLASS_PARTITION udevices for each of disk partitions in @parent > > > + * > > > + * @parent: Whole disk device > > > + */ > > > +int blk_create_partitions(struct udevice *parent); > > > + > > > /** > > > * blk_unbind_all() - Unbind all device of the given interface type > > > * > > > diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h > > > index e7edd409f307..30892d01ce13 100644 > > > --- a/include/dm/uclass-id.h > > > +++ b/include/dm/uclass-id.h > > > @@ -80,6 +80,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 */ > > >