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 AE5EBC46467 for ; Sun, 8 Jan 2023 02:55:44 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 355DB8564E; Sun, 8 Jan 2023 03:52:38 +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="lDTX+vOe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 384F5856C0; Sun, 8 Jan 2023 03:51:58 +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 C384C85627 for ; Sun, 8 Jan 2023 03:51:10 +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 a9so2670073ilp.6 for ; Sat, 07 Jan 2023 18:51:10 -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=Mn+8YtC4a1u0Tz3V+N8lWO8a70zmySL5momtO4b9pG8=; b=lDTX+vOel6PlxpBCNrlffFHE5ZRFeXhiCa3xTUQhy7CUMmwbpXKEfycR5zAldx9HzS IpvlCkWdSQwdKVCyYfi7/kI+mgkQsRzRT9E0+47yQXF+80Rf0ieAZDdbWEdlGhyY0bge DCU70zZC8YEd+GO2JIvu2ocPGxBFDzV/Sd5HY= 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=Mn+8YtC4a1u0Tz3V+N8lWO8a70zmySL5momtO4b9pG8=; b=ME3rFPp4ucIhBZ17YRlxsYBJYYo07t4Fv4S8HAJhLZfndYABj8NV2OhLfatRLx7QAu ytpuenD2v/wbcWnZXwWwAMBMKsIzb276VCqKLb59In4GJZnrMQhkzTh48nnVfp+P2LqX Y0MbhoWLXdVGHxy4+o1yTXsbdYQiRJFs54M+AcatAxcdQIUwaFRnQm+ble2IiOwKz+Nf ShNOXbhqns00ZYSkPB/6I+eNKb/I/bqttw8Kd3xgVq3GOc+hVRp5qu9SVRPWokyh2/6d pI9c5n1Stil6JFBlVVnUP7GvIatAjyEUjPalcwYNRb7vxCWdmyDpW+/6ueyjogBaue+c FETw== X-Gm-Message-State: AFqh2krlEHVkN48wmEBgZJfM2S5v96UbhBXG2vZSrc3tdEY/IhBobC7s 1kXFsF9b1MtL6GfswUPVoFDApZfLew3HHXko X-Google-Smtp-Source: AMrXdXuWwMjhYpLblIPxO6mNuEnFJoKu8bKHjzejFJwU44wcFRzLoWU5vrwr69iAzQPYEzE6PkRmIA== X-Received: by 2002:a92:d0cb:0:b0:304:c91b:4a5d with SMTP id y11-20020a92d0cb000000b00304c91b4a5dmr39991990ila.9.1673146269365; Sat, 07 Jan 2023 18:51:09 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 18:51:09 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass Subject: [PATCH v2 16/71] bootstd: Add a default method to get bootflows Date: Sat, 7 Jan 2023 19:49:52 -0700 Message-Id: <20230108025047.522240-17-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 The code in these functions turns out to often be the same. Add a default get_bootflow() function and allow the drivers to select it by setting the method to NULL. This saves a little code space. Signed-off-by: Simon Glass --- (no changes since v1) boot/bootdev-uclass.c | 27 +++++++++++++++++++++++++-- drivers/mmc/mmc_bootdev.c | 25 ------------------------- drivers/usb/host/usb_bootdev.c | 24 ------------------------ include/bootdev.h | 5 ++++- 4 files changed, 29 insertions(+), 52 deletions(-) diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c index 97f75cba49d..0ef3daf24cb 100644 --- a/boot/bootdev-uclass.c +++ b/boot/bootdev-uclass.c @@ -450,14 +450,37 @@ int bootdev_find_by_any(const char *name, struct udevice **devp) return 0; } +static int default_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, + struct bootflow *bflow) +{ + struct udevice *blk; + int ret; + + ret = bootdev_get_sibling_blk(dev, &blk); + /* + * If there is no media, indicate that no more partitions should be + * checked + */ + if (ret == -EOPNOTSUPP) + ret = -ESHUTDOWN; + if (ret) + return log_msg_ret("blk", ret); + assert(blk); + ret = bootdev_find_in_blk(dev, blk, iter, bflow); + if (ret) + return log_msg_ret("find", ret); + + return 0; +} + int bootdev_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, struct bootflow *bflow) { const struct bootdev_ops *ops = bootdev_get_ops(dev); - if (!ops->get_bootflow) - return -ENOSYS; bootflow_init(bflow, dev, iter->method); + if (!ops->get_bootflow) + return default_get_bootflow(dev, iter, bflow); return ops->get_bootflow(dev, iter, bflow); } diff --git a/drivers/mmc/mmc_bootdev.c b/drivers/mmc/mmc_bootdev.c index b4f41fb3a67..037b67bc0ff 100644 --- a/drivers/mmc/mmc_bootdev.c +++ b/drivers/mmc/mmc_bootdev.c @@ -11,30 +11,6 @@ #include #include -static int mmc_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, - struct bootflow *bflow) -{ - struct udevice *mmc_dev = dev_get_parent(dev); - struct udevice *blk; - int ret; - - ret = mmc_get_blk(mmc_dev, &blk); - /* - * If there is no media, indicate that no more partitions should be - * checked - */ - if (ret == -EOPNOTSUPP) - ret = -ESHUTDOWN; - if (ret) - return log_msg_ret("blk", ret); - assert(blk); - ret = bootdev_find_in_blk(dev, blk, iter, bflow); - if (ret) - return log_msg_ret("find", ret); - - return 0; -} - static int mmc_bootdev_bind(struct udevice *dev) { struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); @@ -45,7 +21,6 @@ static int mmc_bootdev_bind(struct udevice *dev) } struct bootdev_ops mmc_bootdev_ops = { - .get_bootflow = mmc_get_bootflow, }; static const struct udevice_id mmc_bootdev_ids[] = { diff --git a/drivers/usb/host/usb_bootdev.c b/drivers/usb/host/usb_bootdev.c index b85f699933d..b2d157faf33 100644 --- a/drivers/usb/host/usb_bootdev.c +++ b/drivers/usb/host/usb_bootdev.c @@ -11,29 +11,6 @@ #include #include -static int usb_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, - struct bootflow *bflow) -{ - struct udevice *blk; - int ret; - - ret = bootdev_get_sibling_blk(dev, &blk); - /* - * If there is no media, indicate that no more partitions should be - * checked - */ - if (ret == -EOPNOTSUPP) - ret = -ESHUTDOWN; - if (ret) - return log_msg_ret("blk", ret); - assert(blk); - ret = bootdev_find_in_blk(dev, blk, iter, bflow); - if (ret) - return log_msg_ret("find", ret); - - return 0; -} - static int usb_bootdev_bind(struct udevice *dev) { struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); @@ -44,7 +21,6 @@ static int usb_bootdev_bind(struct udevice *dev) } struct bootdev_ops usb_bootdev_ops = { - .get_bootflow = usb_get_bootflow, }; static const struct udevice_id usb_bootdev_ids[] = { diff --git a/include/bootdev.h b/include/bootdev.h index d0ca51c6d5e..1e91d4130e7 100644 --- a/include/bootdev.h +++ b/include/bootdev.h @@ -50,7 +50,10 @@ struct bootdev_uc_plat { /** struct bootdev_ops - Operations for the bootdev uclass */ struct bootdev_ops { /** - * get_bootflow() - get a bootflow + * get_bootflow() - get a bootflow (optional) + * + * If this is NULL then the default implementaton is used, which is + * default_get_bootflow() * * @dev: Bootflow device to check * @iter: Provides current dev, part, method to get. Should update -- 2.39.0.314.g84b9a713c41-goog