All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: "Michal Simek" <michal.simek@xilinx.com>,
	"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
	"Tom Rini" <trini@konsulko.com>,
	"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"Daniel Schwierzeck" <daniel.schwierzeck@gmail.com>,
	"Steffen Jaeckel" <jaeckel-floss@eyet-services.de>,
	"Marek Behún" <marek.behun@nic.cz>,
	"Lukas Auer" <lukas.auer@aisec.fraunhofer.de>,
	"Dennis Gilmore" <dennis@ausil.us>,
	"Simon Glass" <sjg@chromium.org>,
	"Jaehoon Chung" <jh80.chung@samsung.com>,
	"Peng Fan" <peng.fan@nxp.com>
Subject: [PATCH v2 28/41] bootstd: mmc: Add a bootdev driver
Date: Sat, 23 Oct 2021 17:26:22 -0600	[thread overview]
Message-ID: <20211023172618.v2.28.Idda0c29539776a431958d22f1ac59dd20eec9697@changeid> (raw)
In-Reply-To: <20211023232635.9195-1-sjg@chromium.org>

Add a bootdev driver for MMC. It mostly just calls the bootdev helper
function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 MAINTAINERS               |  1 +
 drivers/mmc/Makefile      |  5 ++++
 drivers/mmc/mmc-uclass.c  | 23 +++++++++++++++
 drivers/mmc/mmc_bootdev.c | 62 +++++++++++++++++++++++++++++++++++++++
 include/mmc.h             | 12 +++++++-
 5 files changed, 102 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mmc/mmc_bootdev.c

diff --git a/MAINTAINERS b/MAINTAINERS
index fc05570f11d..8a19d08623f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -642,6 +642,7 @@ F:	boot/bootmeth*.c
 F:	boot/bootstd.c
 F:	cmd/bootdev.c
 F:	cmd/bootflow.c
+F:	drivers/mmc/mmc_bootdev.c
 F:	include/bootdev.h
 F:	include/bootflow.h
 F:	include/bootmeth.h
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index 7e819d2b3a2..06d67718ddb 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -5,6 +5,11 @@
 
 obj-y += mmc.o
 obj-$(CONFIG_$(SPL_)DM_MMC) += mmc-uclass.o
+
+ifdef CONFIG_$(SPL_TPL_)DM_MMC
+obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += mmc_bootdev.o
+endif
+
 obj-$(CONFIG_$(SPL_)MMC_WRITE) += mmc_write.o
 obj-$(CONFIG_MMC_PWRSEQ) += mmc-pwrseq.o
 obj-$(CONFIG_MMC_SDHCI_ADMA_HELPERS) += sdhci-adma.o
diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
index b80e838066c..35b8cdbe35f 100644
--- a/drivers/mmc/mmc-uclass.c
+++ b/drivers/mmc/mmc-uclass.c
@@ -8,6 +8,7 @@
 #define LOG_CATEGORY UCLASS_MMC
 
 #include <common.h>
+#include <bootdev.h>
 #include <log.h>
 #include <mmc.h>
 #include <dm.h>
@@ -315,6 +316,20 @@ int mmc_get_next_devnum(void)
 	return blk_find_max_devnum(IF_TYPE_MMC);
 }
 
+int mmc_get_blk(struct udevice *dev, struct udevice **blkp)
+{
+	struct udevice *blk;
+	int ret;
+
+	device_find_first_child_by_uclass(dev, UCLASS_BLK, &blk);
+	ret = device_probe(blk);
+	if (ret)
+		return ret;
+	*blkp = blk;
+
+	return 0;
+}
+
 struct blk_desc *mmc_get_blk_desc(struct mmc *mmc)
 {
 	struct blk_desc *desc;
@@ -406,6 +421,10 @@ 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");
+	if (ret)
+		return log_msg_ret("bootdev", ret);
+
 	/* the following chunk was from mmc_register() */
 
 	/* Setup dsr related values */
@@ -424,12 +443,16 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 int mmc_unbind(struct udevice *dev)
 {
 	struct udevice *bdev;
+	int ret;
 
 	device_find_first_child_by_uclass(dev, UCLASS_BLK, &bdev);
 	if (bdev) {
 		device_remove(bdev, DM_REMOVE_NORMAL);
 		device_unbind(bdev);
 	}
+	ret = bootdev_unbind_dev(dev);
+	if (ret)
+		return log_msg_ret("bootdev", ret);
 
 	return 0;
 }
diff --git a/drivers/mmc/mmc_bootdev.c b/drivers/mmc/mmc_bootdev.c
new file mode 100644
index 00000000000..b4f41fb3a67
--- /dev/null
+++ b/drivers/mmc/mmc_bootdev.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootdevice for MMC
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <bootdev.h>
+#include <dm.h>
+#include <mmc.h>
+
+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);
+
+	ucp->prio = BOOTDEVP_0_INTERNAL_FAST;
+
+	return 0;
+}
+
+struct bootdev_ops mmc_bootdev_ops = {
+	.get_bootflow	= mmc_get_bootflow,
+};
+
+static const struct udevice_id mmc_bootdev_ids[] = {
+	{ .compatible = "u-boot,bootdev-mmc" },
+	{ }
+};
+
+U_BOOT_DRIVER(mmc_bootdev) = {
+	.name		= "mmc_bootdev",
+	.id		= UCLASS_BOOTDEV,
+	.ops		= &mmc_bootdev_ops,
+	.bind		= mmc_bootdev_bind,
+	.of_match	= mmc_bootdev_ids,
+};
diff --git a/include/mmc.h b/include/mmc.h
index b92e2553402..668a8634a04 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -961,10 +961,20 @@ int mmc_get_env_dev(void);
  * mmc_get_blk_desc() - Get the block descriptor for an MMC device
  *
  * @mmc:	MMC device
- * @return block device if found, else NULL
+ * @return block descriptor if found, else NULL
  */
 struct blk_desc *mmc_get_blk_desc(struct mmc *mmc);
 
+/**
+ * mmc_get_blk() - Get the block device for an MMC device
+ *
+ * @dev:	MMC device
+ * @blkp:	Returns pointer to probed block device on sucesss
+ *
+ * @return 0 on success, -ve on error
+ */
+int mmc_get_blk(struct udevice *dev, struct udevice **blkp);
+
 /**
  * mmc_send_ext_csd() - read the extended CSD register
  *
-- 
2.33.0.1079.g6e70778dc9-goog


  parent reply	other threads:[~2021-10-23 23:32 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAPnjgZ2TFOQGoQ1+Vt6LRMk+nULj9joS0C7fMMiXfg7JNien7g@mail.gmail.com>
2021-10-23 23:25 ` [PATCH v2 00/41] Initial implementation of standard boot Simon Glass
2021-10-23 23:25   ` [PATCH v2 01/41] lib: Add a way to find the postiion of a trailing number Simon Glass
2021-10-27 12:13     ` Heinrich Schuchardt
2021-10-23 23:25   ` [PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build Simon Glass
2021-10-27  8:50     ` Ilias Apalodimas
2021-10-27 12:21       ` Heinrich Schuchardt
2021-10-27 13:13         ` Tom Rini
2021-10-31 23:46           ` Simon Glass
2021-11-01 21:58             ` Tom Rini
2021-11-04  2:49               ` Simon Glass
2021-11-04 14:55                 ` Tom Rini
2021-11-04 15:12                   ` Simon Glass
2021-11-04 16:44                     ` Tom Rini
2021-10-31 23:45         ` Simon Glass
2021-10-23 23:25   ` [PATCH v2 03/41] test/py: Allow passing input to a program Simon Glass
2021-10-23 23:25   ` [PATCH v2 04/41] sandbox: Support unmapping a file Simon Glass
2021-10-23 23:25   ` [PATCH v2 05/41] sandbox: mmc: Support a backing file Simon Glass
2021-10-23 23:26   ` [PATCH v2 06/41] mmc: Allow for children other than the block device Simon Glass
2021-10-23 23:26   ` [PATCH v2 07/41] mbr: Correct verification check Simon Glass
2021-10-27  7:41     ` Ilias Apalodimas
2021-11-24 22:22     ` Simon Glass
2021-10-23 23:26   ` [PATCH v2 08/41] disk: part_dos: Fix a NULL pointer error Simon Glass
2021-10-23 23:26   ` [PATCH v2 09/41] common: Allow a smaller console-recording pre-reloc Simon Glass
2021-10-23 23:26   ` [PATCH v2 10/41] dm: core: Add tests for stringlist functions Simon Glass
2021-10-23 23:26   ` [PATCH v2 11/41] dm: core: Fix handling of uclass pre_unbind method Simon Glass
2021-10-23 23:26   ` [PATCH v2 12/41] dm: core: Fix up string-function documentation Simon Glass
2021-10-23 23:26   ` [PATCH v2 13/41] dm: core: Add a way to obtain a string list Simon Glass
2021-10-26 19:20     ` Ilias Apalodimas
2021-11-24 22:22       ` Simon Glass
2021-11-24 22:23       ` Simon Glass
2021-10-23 23:26   ` [PATCH v2 14/41] dm: core: Allow finding children / uclasses by partial name Simon Glass
2021-10-23 23:26   ` [PATCH v2 15/41] dm: core: Add a way to count the devices in a uclass Simon Glass
2021-10-23 23:26   ` [PATCH v2 16/41] sandbox: Enable HEXDUMP for sandbox_flattree Simon Glass
2021-10-23 23:26   ` [PATCH v2 17/41] test/py: Relax the naming rules for unit tests Simon Glass
2021-10-23 23:26   ` [PATCH v2 18/41] test/py: Raise a ValueError if a command fails Simon Glass
2021-10-23 23:26   ` [PATCH v2 19/41] bootstd: Add the concept of a bootflow Simon Glass
2021-10-23 23:26   ` [PATCH v2 20/41] bootstd: Add the bootstd uclass and core implementation Simon Glass
2021-10-23 23:26   ` [PATCH v2 21/41] bootstd: Add the bootdev uclass Simon Glass
2021-10-23 23:26   ` [PATCH v2 22/41] bootstd: Add the bootmeth uclass and helpers Simon Glass
2021-10-23 23:26   ` [PATCH v2 23/41] bootstd: Add support for bootflows Simon Glass
2021-10-27  7:37     ` Ilias Apalodimas
2022-03-12  2:24       ` Simon Glass
2021-10-23 23:26   ` [PATCH v2 24/41] bootstd: Add a bootdev command Simon Glass
2021-10-23 23:26   ` [PATCH v2 25/41] bootstd: Add a bootflow ommand Simon Glass
2021-10-23 23:26   ` [PATCH v2 26/41] bootstd: Add a bootmeth command Simon Glass
2021-10-23 23:26   ` [PATCH v2 27/41] bootstd: Add an implementation of distro boot Simon Glass
2021-10-23 23:26   ` Simon Glass [this message]
2021-10-23 23:26   ` [PATCH v2 29/41] bootstd: ethernet: Add a bootdev driver Simon Glass
2021-10-23 23:26   ` [PATCH v2 30/41] bootstd: Add an implementation of distro PXE boot Simon Glass
2021-10-23 23:26   ` [PATCH v2 31/41] bootstd: Add an implementation of EFI boot Simon Glass
2021-10-27  8:35     ` Ilias Apalodimas
2021-10-27 14:09       ` Simon Glass
2021-10-27 14:47         ` Ilias Apalodimas
2021-10-27 18:34           ` Simon Glass
2021-10-29  5:45             ` Ilias Apalodimas
2021-10-29 12:39               ` Tom Rini
2021-10-29 13:42                 ` Ilias Apalodimas
2021-10-29 14:03                   ` AKASHI Takahiro
2021-10-29 14:39                     ` Ilias Apalodimas
2021-10-29 16:37                   ` Mark Kettenis
2021-10-29 17:08                     ` Ilias Apalodimas
2021-10-27 11:57     ` Heinrich Schuchardt
2021-10-27 14:08       ` Simon Glass
2021-10-23 23:26   ` [PATCH v2 32/41] bootstd: Add a system bootdev for strange boot methods Simon Glass
2021-10-23 23:26   ` [PATCH v2 33/41] bootstd: Add an implementation of EFI bootmgr Simon Glass
2021-10-23 23:26   ` [PATCH v2 34/41] bootstd: Add a sandbox bootmeth driver Simon Glass
2021-10-23 23:26   ` [PATCH v2 35/41] bootstd: usb: Add a bootdev driver Simon Glass
2021-10-23 23:26   ` [PATCH v2 36/41] test: fastboot: Avoid using mmc1 Simon Glass
2021-10-23 23:26   ` [PATCH v2 37/41] test: dm: Restart USB before assuming it is stopped Simon Glass
2021-10-23 23:26   ` [PATCH v2 38/41] bootstd: Add tests for bootstd including all uclasses Simon Glass
2021-10-23 23:26   ` [PATCH v2 39/41] bootstd: Add setup for the bootflow tests Simon Glass
2021-10-23 23:26   ` [PATCH v2 40/41] bootstd: doc: Add documentation Simon Glass
2021-10-23 23:26   ` [PATCH v2 41/41] RFC: Switch rpi over to use bootstd Simon Glass
2021-10-28 15:13     ` Tom Rini
2021-10-28 16:43     ` Tom Rini
2021-10-28 17:16       ` Simon Glass
2021-10-28 17:29         ` Tom Rini
2021-10-23 23:27   ` [PATCH v2 00/41] Initial implementation of standard boot Simon Glass
2021-10-27 11:38   ` Heinrich Schuchardt
2021-10-27 14:11     ` Simon Glass
2021-10-28 17:37       ` Peter Robinson
2021-10-28 17:47         ` Tom Rini
2021-10-28 17:50           ` Peter Robinson
2021-10-28 17:59             ` Tom Rini
2021-10-28 18:09               ` Heinrich Schuchardt
2021-10-28 18:13                 ` Tom Rini
2021-10-28 18:17               ` François Ozog
2021-10-28 18:27                 ` Tom Rini
2021-10-28 18:28                   ` François Ozog
2021-10-28 21:40           ` Mark Kettenis
2021-10-27 15:20     ` François Ozog
2021-10-27 18:33     ` Simon Glass
2021-10-28 16:27   ` Tom Rini
2021-10-28 17:29     ` Simon Glass
2021-10-28 17:52       ` Tom Rini
2021-10-28 18:13         ` Simon Glass
2021-10-28 18:36           ` Tom Rini
2021-10-28 18:48             ` Simon Glass
2021-10-28 19:19               ` Tom Rini
2021-10-28 22:22                 ` Simon Glass
2021-10-28 22:50                   ` Tom Rini
2021-10-29  1:13                     ` Simon Glass
2021-11-24 22:22   ` [PATCH v2 17/41] test/py: Relax the naming rules for unit tests Simon Glass
2021-11-24 22:22   ` [PATCH v2 18/41] test/py: Raise a ValueError if a command fails Simon Glass
2021-11-24 22:22   ` [PATCH v2 16/41] sandbox: Enable HEXDUMP for sandbox_flattree Simon Glass
2021-11-24 22:22   ` [PATCH v2 15/41] dm: core: Add a way to count the devices in a uclass Simon Glass
2021-11-24 22:22   ` [PATCH v2 14/41] dm: core: Allow finding children / uclasses by partial name Simon Glass
2021-11-24 22:22   ` [PATCH v2 11/41] dm: core: Fix handling of uclass pre_unbind method Simon Glass
2021-11-24 22:22   ` [PATCH v2 12/41] dm: core: Fix up string-function documentation Simon Glass
2021-11-24 22:22   ` [PATCH v2 08/41] disk: part_dos: Fix a NULL pointer error Simon Glass
2021-11-24 22:22   ` [PATCH v2 09/41] common: Allow a smaller console-recording pre-reloc Simon Glass
2021-11-24 22:22   ` [PATCH v2 10/41] dm: core: Add tests for stringlist functions Simon Glass
2021-11-24 22:22   ` [PATCH v2 06/41] mmc: Allow for children other than the block device Simon Glass
2021-11-24 22:22   ` [PATCH v2 05/41] sandbox: mmc: Support a backing file Simon Glass
2021-11-24 22:22   ` [PATCH v2 04/41] sandbox: Support unmapping a file Simon Glass
2021-11-24 22:22   ` [PATCH v2 03/41] test/py: Allow passing input to a program Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211023172618.v2.28.Idda0c29539776a431958d22f1ac59dd20eec9697@changeid \
    --to=sjg@chromium.org \
    --cc=daniel.schwierzeck@gmail.com \
    --cc=dennis@ausil.us \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jaeckel-floss@eyet-services.de \
    --cc=jh80.chung@samsung.com \
    --cc=lukas.auer@aisec.fraunhofer.de \
    --cc=marek.behun@nic.cz \
    --cc=michal.simek@xilinx.com \
    --cc=peng.fan@nxp.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.