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 454B4C46467 for ; Sun, 8 Jan 2023 02:55:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 63CAE855EA; Sun, 8 Jan 2023 03:52:25 +0100 (CET) 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="PcZAAOfs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3609985611; Sun, 8 Jan 2023 03:51:54 +0100 (CET) Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) (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 51AC685621 for ; Sun, 8 Jan 2023 03:51:09 +0100 (CET) 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-il1-x12e.google.com with SMTP id g2so3300954ila.4 for ; Sat, 07 Jan 2023 18:51:09 -0800 (PST) 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:subject:date :message-id:reply-to; bh=HQHJYDLUFbbSRnICM1CLsiO2B4dZ/duugg65mBowOXE=; b=PcZAAOfs2hcZYBvb/1zSCpDAAs8QkcCWSfWBSa4wZ5csnTT0HqfzBz1rVp8Zin6V6c ApM+j5cFv51Km9RqyEMLKG7q2Q++8N1+HH3PjPZL7x3PnkBjcDRhq2j6Z0GCQus+bqFM Tbur1FObGZBM3k4NEIY5PDiTf01sJ262ZYBTQ= 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 :subject:date:message-id:reply-to; bh=HQHJYDLUFbbSRnICM1CLsiO2B4dZ/duugg65mBowOXE=; b=ADG66oAL4HUGDmgiiHdvsP3muSoC6AdD8RqZLqoxDqK9FPdz+f+a1QuyDy3AdUwOrl Itg889dx7ED0C9fopY8NjbYc9sPcGUQWQVDvj4E2LJgBjZ63naf4sV+lgM56ByVXHMLs k0VY7gYFf5P72rDpL59HNb4amG6GFHYruTPWj3NTlCOezU0yURQa9mrwzIWaLDTVFSyg Umqo//JAKvFGWNu6lv8jatJFE/93SFirccn8cFipm0XdUkYzbBtZPtWT7EzrXlEtJxTE AF2csX54kR7wqGndNxigc/7x6/P3k/uk6gK1rFUaQ3oS+z4sa3DQBj5nLlth7NfzvWzL fqdw== X-Gm-Message-State: AFqh2krxqqVeHdWdVCz3i9i4CO8wQorBHM9QikbtEv80agtBZrOyZxKY xlq+rzshdBE2VlCAcPYc9Biq0eG0BhlfN+8G X-Google-Smtp-Source: AMrXdXtasmjaSLKgoi0chrimcJ8njkLx/oWX5jgWwg45OIs7WG1k7zGzOPAlcF6984lUTJ6V3cjirA== X-Received: by 2002:a05:6e02:2219:b0:30d:771c:db3e with SMTP id j25-20020a056e02221900b0030d771cdb3emr14600347ilf.9.1673146268799; Sat, 07 Jan 2023 18:51:08 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-71-56-217-229.hsd1.co.comcast.net. [71.56.217.229]) by smtp.gmail.com with ESMTPSA id c17-20020a92bd11000000b00302a00aaefasm1622174ile.26.2023.01.07.18.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 18:51:08 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass , Jaehoon Chung , Marek Vasut , Pavel Herrmann , Peng Fan Subject: [PATCH v2 15/71] dm: mmc: Use bootdev_setup_sibling_blk() Date: Sat, 7 Jan 2023 19:49:51 -0700 Message-Id: <20230108025047.522240-16-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230108025047.522240-1-sjg@chromium.org> References: <20230108025047.522240-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 MMC uses the bootdev_setup_for_dev() function to set up the bootdev. This is because MMC only has one block-device child, so does not need to worry about naming of the bootdev. However this inconsistency with other bootdevs that use block devices is a bit annoying. The only real reason for it is to have a name like 'mmc0.bootdev' instead of 'mmc0.blk.bootdev'. Update bootdev_setup_sibling_blk() to drop '.blk' from the name where it appears, thus removing the only reason to use the bootdev_setup_for_dev(). Switch MMC over to the subling function. Signed-off-by: Simon Glass --- (no changes since v1) boot/bootdev-uclass.c | 42 ++++++++++++++++++++++++++++------------ drivers/mmc/mmc-uclass.c | 2 +- include/bootdev.h | 5 ++++- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c index cffa01824c0..97f75cba49d 100644 --- a/boot/bootdev-uclass.c +++ b/boot/bootdev-uclass.c @@ -234,13 +234,27 @@ int bootdev_setup_for_dev(struct udevice *parent, const char *drv_name) return 0; } +static int bootdev_get_suffix_start(struct udevice *dev, const char *suffix) +{ + int len, slen; + + len = strlen(dev->name); + slen = strlen(suffix); + if (len > slen && !strcmp(suffix, dev->name + len - slen)) + return len - slen; + + return len; +} + int bootdev_setup_sibling_blk(struct udevice *blk, const char *drv_name) { struct udevice *parent, *dev; char dev_name[50]; - int ret; + int ret, len; - snprintf(dev_name, sizeof(dev_name), "%s.%s", blk->name, "bootdev"); + len = bootdev_get_suffix_start(blk, ".blk"); + snprintf(dev_name, sizeof(dev_name), "%.*s.%s", len, blk->name, + "bootdev"); parent = dev_get_parent(blk); ret = device_find_child_by_name(parent, dev_name, &dev); @@ -271,20 +285,22 @@ int bootdev_get_sibling_blk(struct udevice *dev, struct udevice **blkp) struct udevice *parent = dev_get_parent(dev); struct udevice *blk; int ret, len; - char *p; if (device_get_uclass_id(dev) != UCLASS_BOOTDEV) return -EINVAL; /* This should always work if bootdev_setup_sibling_blk() was used */ - p = strstr(dev->name, ".bootdev"); - if (!p) - return log_msg_ret("str", -EINVAL); - - len = p - dev->name; + len = bootdev_get_suffix_start(dev, ".bootdev"); ret = device_find_child_by_namelen(parent, dev->name, len, &blk); - if (ret) - return log_msg_ret("find", ret); + if (ret) { + char dev_name[50]; + + snprintf(dev_name, sizeof(dev_name), "%.*s.blk", len, + dev->name); + ret = device_find_child_by_name(parent, dev_name, &blk); + if (ret) + return log_msg_ret("find", ret); + } *blkp = blk; return 0; @@ -295,13 +311,15 @@ static int bootdev_get_from_blk(struct udevice *blk, struct udevice **bootdevp) struct udevice *parent = dev_get_parent(blk); struct udevice *bootdev; char dev_name[50]; - int ret; + int ret, len; if (device_get_uclass_id(blk) != UCLASS_BLK) return -EINVAL; /* This should always work if bootdev_setup_sibling_blk() was used */ - snprintf(dev_name, sizeof(dev_name), "%s.%s", blk->name, "bootdev"); + len = bootdev_get_suffix_start(blk, ".blk"); + snprintf(dev_name, sizeof(dev_name), "%.*s.%s", len, blk->name, + "bootdev"); ret = device_find_child_by_name(parent, dev_name, &bootdev); if (ret) return log_msg_ret("find", ret); diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c index 759a6b728c8..01d9b0201f2 100644 --- a/drivers/mmc/mmc-uclass.c +++ b/drivers/mmc/mmc-uclass.c @@ -421,7 +421,7 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg) mmc->cfg = cfg; mmc->priv = dev; - ret = bootdev_setup_for_dev(dev, "mmc_bootdev"); + ret = bootdev_setup_sibling_blk(bdev, "mmc_bootdev"); if (ret) return log_msg_ret("bootdev", ret); diff --git a/include/bootdev.h b/include/bootdev.h index 9fc219839fe..d0ca51c6d5e 100644 --- a/include/bootdev.h +++ b/include/bootdev.h @@ -204,7 +204,10 @@ int bootdev_setup_iter_order(struct bootflow_iter *iter, struct udevice **devp); #if CONFIG_IS_ENABLED(BOOTSTD) /** - * bootdev_setup_for_dev() - Bind a new bootdev device + * bootdev_setup_for_dev() - Bind a new bootdev device (deprecated) + * + * Please use bootdev_setup_sibling_blk() instead since it supports multiple + * (child) block devices for each media device. * * Creates a bootdev device as a child of @parent. This should be called from * the driver's bind() method or its uclass' post_bind() method. -- 2.39.0.314.g84b9a713c41-goog