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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 50D60C19F2A for ; Sun, 7 Aug 2022 15:49:13 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B56AB848A4; Sun, 7 Aug 2022 17:48:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ljWycy0/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 55B5F8486C; Sun, 7 Aug 2022 17:47:56 +0200 (CEST) Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) (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 B2C198486B for ; Sun, 7 Aug 2022 17:47:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x22a.google.com with SMTP id q184so7886773oif.1 for ; Sun, 07 Aug 2022 08:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=8JdWWSyZ0DydDvRiSx5yaFNYUrEXFxsmpWKAbl1AFkw=; b=ljWycy0/BwCHuiAnlnAaxZrBJMivYoyGfcuxNXmkRfdc8OKg2Ch3Ot/b1zDEUHyZiz opIzF6FT8OAzCr3Pl+slZMjoAK2/lRGSYoKWpKf0aF24ZPXQaZLbOKoNLGQgnL8DAbQO /h1d0dVRw8lV38V5HlZ2QBBGucYWECH6GON+0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=8JdWWSyZ0DydDvRiSx5yaFNYUrEXFxsmpWKAbl1AFkw=; b=jEsh1zM4xNPgKh5YlQGnmXQOg9DMEQVx2vQvIC58jp8Mn4GdoIdsVSN1B6Aj24cWDK yJlnsunzxF028wl05KyxmEOLwBLuF/grEcF3KSQI+/6G9K0Hj3bp2vjz1bDsjfttoVdS cQRmlkaBglplZvnyovikMOZvLanZNuLbLwepQ4iEXKwXtHbU/a4S5KrYLNxSm/t0yKfW xa57hR+DDZUY7em6aJf6xn0/vOeph4uifc0fpX6l6sKNtyUQJiQsZFa5rvleXeAPspb0 HWWtelbcRrCnfhKLcgJtKW4GOHwCyFXfL50DgvoWE10jyYX7NTo0hFGTZHAIjypbt8PN zUVQ== X-Gm-Message-State: ACgBeo33m1Ed4dsg5hVEGYXJdYMf2of6/JBMcCHh0eccQBbDmxxTNgev 9FLh1NVHEneCMnHr6NrIyE9ENLIyErke1Q== X-Google-Smtp-Source: AA6agR6AwtrPBFQmpHUDddE3MpkMAI5Jn9NScZRj8Hz9xFlnJlWVentT67vyleZA4Rxba/wqYkF/Pg== X-Received: by 2002:a05:6808:f86:b0:33a:a748:b462 with SMTP id o6-20020a0568080f8600b0033aa748b462mr9084030oiw.66.1659887272147; Sun, 07 Aug 2022 08:47:52 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id y18-20020a056808131200b0034290c4ed01sm1553412oiv.41.2022.08.07.08.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Aug 2022 08:47:51 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , AKASHI Takahiro , Marcel Ziswiler , Masahisa Kojima , Oleksandr Suvorov , Oleksii Bidnichenko , Ricardo Salveti , schspa Subject: [PATCH 07/23] blk: Use a function for whether block devices are available Date: Sun, 7 Aug 2022 09:46:52 -0600 Message-Id: <20220807154708.1418967-8-sjg@chromium.org> X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog In-Reply-To: <20220807154708.1418967-1-sjg@chromium.org> References: <20220807154708.1418967-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 At present we use HAVE_BLOCK_DEVICE to indicate when block devices are available. This is a very strange option, since it partially duplicates the BLK option used by driver model. It also covers both U-Boot proper and SPL, even though one might have block devices and another not. As a first step towards correcting this, create a new inline function called blk_enabled() which indicates if block devices are available. This cannot be used in Makefiles, or #if clauses, but can be used in C code. A function is useful because we cannot use CONFIG_IS_ENABLED(BLK) to decide if block devices are needed, since we must consider the legacy block interface, enabled by HAVE_BLOCK_DEVICE Update a few places where it can be used and drop some unnecessary #if checks around some functions in disk/part.c - rely on the compiler's dead-code elimination instead. Signed-off-by: Simon Glass --- disk/part.c | 80 ++++++++++++++++---------------------- drivers/block/blk-uclass.c | 3 +- fs/fat/fat.c | 2 +- include/blk.h | 5 +++ 4 files changed, 40 insertions(+), 50 deletions(-) diff --git a/disk/part.c b/disk/part.c index 79955c7fb00..9594bb432c4 100644 --- a/disk/part.c +++ b/disk/part.c @@ -54,12 +54,13 @@ static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc) return NULL; } -#ifdef CONFIG_HAVE_BLOCK_DEVICE static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart) { struct blk_desc *dev_desc; int ret; + if (!blk_enabled()) + return NULL; dev_desc = blk_get_devnum_by_typename(ifname, dev); if (!dev_desc) { debug("%s: No device for iface '%s', dev %d\n", __func__, @@ -78,21 +79,11 @@ static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart) struct blk_desc *blk_get_dev(const char *ifname, int dev) { - return get_dev_hwpart(ifname, dev, 0); -} -#else -struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart) -{ - return NULL; -} + if (!blk_enabled()) + return NULL; -struct blk_desc *blk_get_dev(const char *ifname, int dev) -{ - return NULL; + return get_dev_hwpart(ifname, dev, 0); } -#endif - -#ifdef CONFIG_HAVE_BLOCK_DEVICE /* ------------------------------------------------------------------------- */ /* @@ -228,9 +219,6 @@ void dev_print (struct blk_desc *dev_desc) puts (" Capacity: not available\n"); } } -#endif - -#ifdef CONFIG_HAVE_BLOCK_DEVICE void part_init(struct blk_desc *dev_desc) { @@ -325,38 +313,36 @@ void part_print(struct blk_desc *dev_desc) drv->print(dev_desc); } -#endif /* CONFIG_HAVE_BLOCK_DEVICE */ - int part_get_info(struct blk_desc *dev_desc, int part, struct disk_partition *info) { -#ifdef CONFIG_HAVE_BLOCK_DEVICE struct part_driver *drv; + if (blk_enabled()) { #if CONFIG_IS_ENABLED(PARTITION_UUIDS) - /* The common case is no UUID support */ - info->uuid[0] = 0; + /* The common case is no UUID support */ + info->uuid[0] = 0; #endif #ifdef CONFIG_PARTITION_TYPE_GUID - info->type_guid[0] = 0; + info->type_guid[0] = 0; #endif - drv = part_driver_lookup_type(dev_desc); - if (!drv) { - debug("## Unknown partition table type %x\n", - dev_desc->part_type); - return -EPROTONOSUPPORT; - } - if (!drv->get_info) { - PRINTF("## Driver %s does not have the get_info() method\n", - drv->name); - return -ENOSYS; - } - if (drv->get_info(dev_desc, part, info) == 0) { - PRINTF("## Valid %s partition found ##\n", drv->name); - return 0; + drv = part_driver_lookup_type(dev_desc); + if (!drv) { + debug("## Unknown partition table type %x\n", + dev_desc->part_type); + return -EPROTONOSUPPORT; + } + if (!drv->get_info) { + PRINTF("## Driver %s does not have the get_info() method\n", + drv->name); + return -ENOSYS; + } + if (drv->get_info(dev_desc, part, info) == 0) { + PRINTF("## Valid %s partition found ##\n", drv->name); + return 0; + } } -#endif /* CONFIG_HAVE_BLOCK_DEVICE */ return -ENOENT; } @@ -424,15 +410,15 @@ int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str, goto cleanup; } -#ifdef CONFIG_HAVE_BLOCK_DEVICE - /* - * Updates the partition table for the specified hw partition. - * Always should be done, otherwise hw partition 0 will return stale - * data after displaying a non-zero hw partition. - */ - if ((*dev_desc)->if_type == IF_TYPE_MMC) - part_init(*dev_desc); -#endif + if (blk_enabled()) { + /* + * Updates the partition table for the specified hw partition. + * Always should be done, otherwise hw partition 0 will return + * stale data after displaying a non-zero hw partition. + */ + if ((*dev_desc)->if_type == IF_TYPE_MMC) + part_init(*dev_desc); + } cleanup: free(dup_str); diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index 21c5209bb63..1a6e8f8c29d 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -743,8 +743,7 @@ int blk_unbind_all(int if_type) static int blk_post_probe(struct udevice *dev) { - if (CONFIG_IS_ENABLED(PARTITIONS) && - IS_ENABLED(CONFIG_HAVE_BLOCK_DEVICE)) { + if (CONFIG_IS_ENABLED(PARTITIONS) && blk_enabled()) { struct blk_desc *desc = dev_get_uclass_plat(dev); part_init(desc); diff --git a/fs/fat/fat.c b/fs/fat/fat.c index df9ea2c028f..c64e253abd4 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -1144,7 +1144,7 @@ int file_fat_detectfs(void) return 1; } - if (IS_ENABLED(CONFIG_HAVE_BLOCK_DEVICE)) { + if (blk_enabled()) { printf("Interface: %s\n", blk_get_if_type_name(cur_dev->if_type)); printf(" Device %d: ", cur_dev->devnum); dev_print(cur_dev); diff --git a/include/blk.h b/include/blk.h index 9503369db83..332481a90b8 100644 --- a/include/blk.h +++ b/include/blk.h @@ -21,6 +21,11 @@ typedef ulong lbaint_t; struct udevice; +static inline bool blk_enabled(void) +{ + return CONFIG_IS_ENABLED(BLK) || IS_ENABLED(CONFIG_HAVE_BLOCK_DEVICE); +} + /* Interface types: */ enum if_type { IF_TYPE_UNKNOWN = 0, -- 2.37.1.559.g78731f0fdb-goog