[PATCH 13/16] bootsource: implement bootsource_of_cdev_find

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Apr 1 03:48:03 PDT 2025


For use on device tree systems that especially boot from SD/eMMC,
introduce a new helper function that returns the cdev of the boot medium.

Calling this function for unknown boot media will return NULL and
callers will have to handle that gracefully.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/bootsource.c  | 17 +++++++++++++++++
 include/bootsource.h |  1 +
 2 files changed, 18 insertions(+)

diff --git a/common/bootsource.c b/common/bootsource.c
index d054427c6e78..e78237ff36b8 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <of.h>
 #include <bootsource.h>
 #include <environment.h>
 #include <magicvar.h>
@@ -123,6 +124,22 @@ struct device_node *bootsource_of_node_get(struct device_node *root)
 	return np;
 }
 
+struct cdev *bootsource_of_cdev_find(void)
+{
+	struct device_node *np;
+	struct cdev *cdev;
+
+	np = bootsource_of_node_get(NULL);
+	if (!np)
+		return NULL;
+
+	cdev = of_cdev_find(np);
+	if (IS_ERR(cdev))
+		return NULL;
+
+	return cdev;
+}
+
 void bootsource_set_alias_name(const char *name)
 {
 	bootsource_alias_name = name;
diff --git a/include/bootsource.h b/include/bootsource.h
index 9fb77a0bb0a9..c9c58daf096c 100644
--- a/include/bootsource.h
+++ b/include/bootsource.h
@@ -34,6 +34,7 @@ const char *bootsource_to_string(enum bootsource src);
 const char *bootsource_get_alias_stem(enum bootsource bs);
 int bootsource_of_alias_xlate(enum bootsource bs, int instance);
 struct device_node *bootsource_of_node_get(struct device_node *root);
+struct cdev *bootsource_of_cdev_find(void);
 
 /**
  * bootsource_set - set bootsource with optional DT mapping table
-- 
2.39.5




More information about the barebox mailing list