[PATCH 26/28] mmc: Add a bootmethod
Simon Glass
sjg at chromium.org
Thu Aug 19 05:45:59 CEST 2021
Add a bootmethod for MMC. It mostly just calls the bootmethod 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 at chromium.org>
---
MAINTAINERS | 1 +
drivers/mmc/Makefile | 5 ++++
drivers/mmc/mmc-uclass.c | 19 +++++++++++++++
drivers/mmc/mmc_bootmethod.c | 46 ++++++++++++++++++++++++++++++++++++
include/mmc.h | 12 +++++++++-
5 files changed, 82 insertions(+), 1 deletion(-)
create mode 100644 drivers/mmc/mmc_bootmethod.c
diff --git a/MAINTAINERS b/MAINTAINERS
index f472a589f61..246c5e60270 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -640,6 +640,7 @@ F: cmd/bootmethod.c
F: doc/develop/bootflow.rst
F: doc/usage/bootflow.rst
F: doc/usage/bootmethod.rst
+F: drivers/mmc/mmc_bootmethod.c
F: include/bootmethod.h
F: include/distro.h
F: test/boot/bootmethod.c
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index dde6cd563ff..0b6ddfb5165 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_)BOOTMETHOD) += mmc_bootmethod.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 9e39fdd6c44..42474bc197e 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 <bootmethod.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;
@@ -403,6 +418,10 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
mmc->cfg = cfg;
mmc->priv = dev;
+ ret = bootmethod_setup_for_dev(dev, "mmc_bootmethod");
+ if (ret)
+ return log_msg_ret("bootmethod", ret);
+
/* the following chunk was from mmc_register() */
/* Setup dsr related values */
diff --git a/drivers/mmc/mmc_bootmethod.c b/drivers/mmc/mmc_bootmethod.c
new file mode 100644
index 00000000000..eab13036d89
--- /dev/null
+++ b/drivers/mmc/mmc_bootmethod.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootmethod for MMC
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <sjg at chromium.org>
+ */
+
+#include <common.h>
+#include <bootmethod.h>
+#include <dm.h>
+#include <mmc.h>
+
+static int mmc_get_bootflow(struct udevice *dev, int seq,
+ 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 = bootmethod_find_in_blk(dev, blk, seq, bflow);
+ if (ret)
+ return log_msg_ret("find", ret);
+
+ return 0;
+}
+
+struct bootmethod_ops mmc_bootmethod_ops = {
+ .get_bootflow = mmc_get_bootflow,
+};
+
+U_BOOT_DRIVER(mmc_bootmethod) = {
+ .name = "mmc_bootmethod",
+ .id = UCLASS_BOOTMETHOD,
+ .ops = &mmc_bootmethod_ops,
+};
diff --git a/include/mmc.h b/include/mmc.h
index 0bf19de20e5..1cd274f6253 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -959,10 +959,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.rc1.237.g0d66db33f3-goog
More information about the U-Boot
mailing list