From patchwork Fri Apr 15 07:15:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 561940 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp115249map; Fri, 15 Apr 2022 00:16:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEkrBODEh1sn1l/6xve7ZzZhWh4Wf/nAqtAOSquK9+T3gfbhVynVPAtr0TFioCa/TjPR4T X-Received: by 2002:a05:6402:134e:b0:41d:774f:4c40 with SMTP id y14-20020a056402134e00b0041d774f4c40mr7000531edw.202.1650007019570; Fri, 15 Apr 2022 00:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650007019; cv=none; d=google.com; s=arc-20160816; b=g8jH29A0aGvv0gkeF/trAMJdp/riGeQ6J5bFjFqoG6g/D2qsnl1WSo+LADUvQG+lxs qX3s5ZxQsUCT9IN7oCJQ86HGbeTEd0EfvOdKc+cXnv6ikTLBfKXP80QXQ1UGHLadjgRE MjY3jRe1kkUcBjmbjpS1qU0yvBLDJaUKyIoWjYKTg1TqW5D93jeTQgI1gOa2a595GafP +yVzhrAgu0YZJBi/hY76LZJIzE6mnQUQ4XQKFLOAKEA6e/Y3t4b0jHQlyJjl1ctdCJh4 gmlMDSQR1A2Nu/GoFUb7mM9Z4Iwy2LnInUdjvgTtgGJNT9iolx/l53rgNluL1SykAVWC rd6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ao/Y3BMYKq5BtgP/1yBdnx1BqNPG07Ibdvm5nE+ob5w=; b=wQeUkoWLjOLA5/pXWIWAdfva+tP5FCHczbobjtTlTOfQc5yKw83jNXw50DseVVumF7 24Lv4aNMarf7caOgynRHmgnMeh/fmcZKNLkmt6kxr44m7ks2va8AdEbz6DbohoZsmeJP vUxQJZH0bx5wO/aPoWFO1ML9LIG4HGZCnOk8+FN4rAW6kTUtmTVrzoH4GpxrFtcSN/ED c1df2YDa/zqi58ifYN0C0qT1Yqw20R4ThN1BQxkApHzyhOMSGEgHUQG1uCd34J8zTXYk 3kdzz3ZFTBYF4I457jnEtmAAYbNYjXK+02IQ6slbS59GIPfVz2w7iSQ0xWejNsPD6pWF NRxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ffskeXGt; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id k16-20020a17090632d000b006df76385e97si519819ejk.823.2022.04.15.00.16.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 00:16:59 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ffskeXGt; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9299A83A95; Fri, 15 Apr 2022 09:16:33 +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="ffskeXGt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BCCBD83AD0; Fri, 15 Apr 2022 09:16:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (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 6E16B831CA for ; Fri, 15 Apr 2022 09:16:25 +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-x631.google.com with SMTP id n8so6548492plh.1 for ; Fri, 15 Apr 2022 00:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ao/Y3BMYKq5BtgP/1yBdnx1BqNPG07Ibdvm5nE+ob5w=; b=ffskeXGt3CF1MrDt89Fj6HfkQ0eTkTwHr/SnayEA9W+c+xSH4FN73krH2X3qc1id5S ysUW12lvvRecUwRG3YSxS4apJOAhKNITkvjRv6TTPUOerWn0vJy7kaXGC2iQmpP7W7LP KLX9Ox3ijfUKMhLjXHy7m8q+npAYgo3scn/H3k+FS8C7zznWe5azE3cxzVx5tOXZ3yhY 1twJwUJiE55/rAaGg7AisySaQ4x+QMu4ffKMaz9VZ76CLi6fxm/Ow0j0x+BG3MUlV8lI OJTkF4rrPpviN9dKaFNyHEhnktzGcg9LOdC5sQLbYbxPTbN0mB75LCDTifRdfV5VIguF sKhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ao/Y3BMYKq5BtgP/1yBdnx1BqNPG07Ibdvm5nE+ob5w=; b=pcd8v7lgDD5B5YksIt4DjWv+JoYZv2Lqch8ippiarbtGwZXDULGZ64G36Gt+trulLz 7/sZxyPccvrg2F3XEeanonOVuqq5cxG1o8srs5gOGFHMxLD0oOkUt78sLP49BekeRGo0 snoLEQ/BPVU3klgDFjQaRWa2nllCMmNt6Dq8tl5IjAAG2UfT4d+2CtImAI095DjrTwWj T2LuPIIAZJ7bPz83Q90lwwbFopGvgTHPhR7wSg3esUBolnALeuEpbWt8FVSbM4mQCnUn 3bEC+txDT8wNtvt1RfS3yrGLTcIhvkKoA+EwHutR3vzGs/v556R+L80aKRgbcSwy/i6w wbuQ== X-Gm-Message-State: AOAM532U6EJAxGrGGKqemNYIXFMHlZEJPUxiFPpGrbjM5EYKcfgywGHS SZcM/3TKyh0wAEBlAQrJYn53rg== X-Received: by 2002:a17:90b:38d2:b0:1c6:fa94:96bb with SMTP id nn18-20020a17090b38d200b001c6fa9496bbmr2736863pjb.206.1650006983776; Fri, 15 Apr 2022 00:16:23 -0700 (PDT) Received: from localhost.localdomain ([2400:4050:c3e1:100:18f3:1e4:6c4:6ea3]) by smtp.gmail.com with ESMTPSA id p1-20020a17090a0e4100b001ce188720e5sm3566921pja.53.2022.04.15.00.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 00:16:23 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, sjg@chromium.org, ilias.apalodimas@linaro.org Cc: masami.hiramatsu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v4 04/12] dm: disk: add UCLASS_PARTITION Date: Fri, 15 Apr 2022 16:15:38 +0900 Message-Id: <20220415071546.122475-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220415071546.122475-1-takahiro.akashi@linaro.org> References: <20220415071546.122475-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean NOTE: probably we have to update config dependencies, in particular, SPL/TPL_PRINTF? With this new function, UCLASS_PARTITION devices will be created as child nodes of UCLASS_BLK device. Signed-off-by: AKASHI Takahiro --- disk/Makefile | 3 + disk/disk-uclass.c | 153 +++++++++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/part.h | 10 +++ 4 files changed, 167 insertions(+) create mode 100644 disk/disk-uclass.c diff --git a/disk/Makefile b/disk/Makefile index 5ca10c55762b..ec148832b330 100644 --- a/disk/Makefile +++ b/disk/Makefile @@ -6,6 +6,9 @@ #ccflags-y += -DET_DEBUG -DDEBUG obj-$(CONFIG_$(SPL_TPL_)PARTITIONS) += part.o +ifdef CONFIG_$(SPL_TPL_)BLK +obj-$(CONFIG_$(SPL_TPL_)PARTITIONS) += disk-uclass.o +endif obj-$(CONFIG_$(SPL_TPL_)MAC_PARTITION) += part_mac.o obj-$(CONFIG_$(SPL_TPL_)DOS_PARTITION) += part_dos.o obj-$(CONFIG_$(SPL_TPL_)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 +#include +#include +#include +#include +#include +#include + +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..907c227aa20d 100644 --- a/include/part.h +++ b/include/part.h @@ -287,6 +287,16 @@ part_get_info_by_dev_and_name_or_num(const char *dev_iface, } #endif +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); + /* * We don't support printing partition information in SPL and only support * getting partition information in a few cases.