From patchwork Thu Sep 15 20:02:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1678410 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=k24Lmu3K; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MT7Rp1glsz1ynm for ; Fri, 16 Sep 2022 06:03:18 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 983F884B33; Thu, 15 Sep 2022 22:03:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com 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=canonical.com header.i=@canonical.com header.b="k24Lmu3K"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 853B983FB5; Thu, 15 Sep 2022 22:02:57 +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,DKIMWL_WL_HIGH, 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 smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E721D84ACA for ; Thu, 15 Sep 2022 22:02:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from LT2ubnt.fritz.box (ip-084-118-157-002.um23.pools.vodafone-ip.de [84.118.157.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 3BA813FDD6; Thu, 15 Sep 2022 20:02:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1663272173; bh=5x2apQvkJAmls/P4CfrOggHbQyQGjg7/N5B6x64j0bY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=k24Lmu3KWic/JJco8EIAIVO27lbMco2q6CEP6UZNrgoNJC/FX1741hxtt2TdxVejC b/i06q06AUKstr0etucwfBf8F0krr3ufCLvZYd9DIijlOwHQGe/Sjj2E7tEfac13V+ +AMxnRrTYrUqfDmYVTRh34fSouiQhLOVC2ie5leYdgm8hv+IF16HayZU9ZSrKWuE2F M4p9xhmprH5i7eK2HEMwDhLNejFMsaMxgIo6iC4BXC3IbsAs2MapCCYSQn1mRg+C/1 A1fKT9/6iHUxmBRIVsIawkUB4ZoY1YOWYFI+f0bmY/Pcbr0iAK6p6m9SXPmQK967d0 7mkC2vliqcYhw== From: Heinrich Schuchardt To: Simon Glass , Ilias Apalodimas Cc: AKASHI Takahiro , Masahisa Kojima , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 1/2] dm: blk: assign media ID to block devices Date: Thu, 15 Sep 2022 22:02:41 +0200 Message-Id: <20220915200242.18358-2-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220915200242.18358-1-heinrich.schuchardt@canonical.com> References: <20220915200242.18358-1-heinrich.schuchardt@canonical.com> 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.6 at phobos.denx.de X-Virus-Status: Clean Currently block devices are only identified by uclass_id and device number. When dealing with removable media this is not enough to uniquely identify the medium. E.g. after host unbind, host bind we can have the same device number but a different backing file. The EFI specification uses a 32bit number media ID to identify media. Add a matching field to the block device descriptor. Signed-off-by: Heinrich Schuchardt --- drivers/block/blk-uclass.c | 16 +++++++++++++++- include/blk.h | 11 +++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index 21c5209bb6..c6f6be81c3 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -51,6 +51,11 @@ static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = { [IF_TYPE_PVBLOCK] = UCLASS_PVBLOCK, }; +/* + * Global counter for media IDs + */ +static u32 media_id_counter; + static enum if_type if_typename_to_iftype(const char *if_typename) { int i; @@ -741,11 +746,20 @@ int blk_unbind_all(int if_type) return 0; } +void blk_assign_media_id(struct blk_desc *desc) +{ + desc->media_id = ++media_id_counter; +} + static int blk_post_probe(struct udevice *dev) { + struct blk_desc *desc = dev_get_uclass_plat(dev); + + if (!desc->media_id) + blk_assign_media_id(desc); + if (CONFIG_IS_ENABLED(PARTITIONS) && IS_ENABLED(CONFIG_HAVE_BLOCK_DEVICE)) { - struct blk_desc *desc = dev_get_uclass_plat(dev); part_init(desc); diff --git a/include/blk.h b/include/blk.h index 9503369db8..c176f8374e 100644 --- a/include/blk.h +++ b/include/blk.h @@ -77,6 +77,7 @@ struct blk_desc { unsigned char hwpart; /* HW partition, e.g. for eMMC */ unsigned char type; /* device type */ unsigned char removable; /* removable device */ + u32 media_id; /* ID to identify media */ #ifdef CONFIG_LBA48 /* device can use 48bit addr (ATA/ATAPI v7) */ unsigned char lba48; @@ -808,4 +809,14 @@ int blk_find_next(enum blk_flag_t flags, struct udevice **devp); */ int blk_count_devices(enum blk_flag_t flag); +/** + * blk_assign_media_id() - assign a media ID to the block device + * + * The field media_id of the block device descriptor is filled from a global + * counter. + * + * @desc: block device descriptor + */ +void blk_assign_media_id(struct blk_desc *desc); + #endif From patchwork Thu Sep 15 20:02:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1678411 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=q3rT3sSU; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MT7Rz3MZbz1ynm for ; Fri, 16 Sep 2022 06:03:27 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BFFF484B73; Thu, 15 Sep 2022 22:03:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com 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=canonical.com header.i=@canonical.com header.b="q3rT3sSU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A83CA84B33; Thu, 15 Sep 2022 22:02:58 +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,DKIMWL_WL_HIGH, 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 smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A00DB84B33 for ; Thu, 15 Sep 2022 22:02:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from LT2ubnt.fritz.box (ip-084-118-157-002.um23.pools.vodafone-ip.de [84.118.157.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id A014C3FDDB; Thu, 15 Sep 2022 20:02:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1663272173; bh=GyDD7tymP3Nxb+ppHBeLYSHHiTx5Fnx05bo6WJQ446Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q3rT3sSUyWLtW0GnexTyofo7QT1ajIQPr3DdDmUQ9nHx95fzgleHC8Z8tzsxLLSfd gSuHuwcUygLhZQcEDhl89gGHxFz8KRyIMLPDkd+fT2oP5tQctAPW07m+RaBJqhE+uP dwsteN8ENy3vWkWR/ZZcGSRgMSxCBovYntzXciFHkvPnJn1s+D12NmSqGTQsjffUqd 5faXAzShZLENKbavhEJC55AyYtQPY48AoIBarPesmiMCHC4neyFixvNNNqOGzyL6mz bOziPTYOQ4S92cygekGlXHSI3+rK7BV/ZiWS4928ufJXfsMO/A8fiKDnnKC/NPy/wd IhMywIaYILdxw== From: Heinrich Schuchardt To: Simon Glass , Ilias Apalodimas Cc: AKASHI Takahiro , Masahisa Kojima , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 2/2] efi_loader: fill media_id from block device descriptor Date: Thu, 15 Sep 2022 22:02:42 +0200 Message-Id: <20220915200242.18358-3-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220915200242.18358-1-heinrich.schuchardt@canonical.com> References: <20220915200242.18358-1-heinrich.schuchardt@canonical.com> 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.6 at phobos.denx.de X-Virus-Status: Clean Fill the media ID in the block IO protocol from the block device descriptor of the driver model. Signed-off-by: Heinrich Schuchardt Acked-by: Ilias Apalodimas --- lib/efi_loader/efi_disk.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 73745ccaa0..35790aa86d 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -476,11 +476,7 @@ static efi_status_t efi_disk_add_dev( /* Fill in EFI IO Media info (for read/write callbacks) */ diskobj->media.removable_media = desc->removable; diskobj->media.media_present = 1; - /* - * MediaID is just an arbitrary counter. - * We have to change it if the medium is removed or changed. - */ - diskobj->media.media_id = 1; + diskobj->media.media_id = desc->media_id; diskobj->media.block_size = desc->blksz; diskobj->media.io_align = desc->blksz; if (part)