[Pdbg] [PATCH v4 05/19] libpdbg: Use PDBG_BACKEND_DRIVER to specify drivers to load

Amitay Isaacs amitay at ozlabs.org
Tue Apr 21 14:16:41 AEST 2020


When PDBG_BACKEND_DTB is specified, backend may not be set.  This means
only the drivers registered with PDBG_DEFAULT_BACKEND will be loaded.
To be able to match backend specific drivers for targets in system tree,
use the backend specified in PDBG_BACKEND_DRIVER environment variable.

Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 libpdbg/hwunit.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/libpdbg/hwunit.c b/libpdbg/hwunit.c
index 074ddef..3d6a05d 100644
--- a/libpdbg/hwunit.c
+++ b/libpdbg/hwunit.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 
@@ -70,12 +71,44 @@ static const struct hw_unit_info *find_compatible(enum pdbg_backend backend,
 	return NULL;
 }
 
+static enum pdbg_backend get_backend_driver(void)
+{
+	const char *tmp;
+	enum pdbg_backend backend = PDBG_DEFAULT_BACKEND;
+
+	tmp = getenv("PDBG_BACKEND_DRIVER");
+	if (tmp) {
+		if (!strcmp(tmp, "fsi"))
+			backend = PDBG_BACKEND_FSI;
+		else if (!strcmp(tmp, "i2c"))
+			backend = PDBG_BACKEND_I2C;
+		else if (!strcmp(tmp, "kernel"))
+			backend = PDBG_BACKEND_KERNEL;
+		else if (!strcmp(tmp, "fake"))
+			backend = PDBG_BACKEND_FAKE;
+		else if (!strcmp(tmp, "host"))
+			backend = PDBG_BACKEND_HOST;
+		else if (!strcmp(tmp, "cronus"))
+			backend = PDBG_BACKEND_CRONUS;
+	}
+
+	return backend;
+}
+
 const struct hw_unit_info *pdbg_hwunit_find_compatible(const char *compat_list,
 						       uint32_t len)
 {
-	const struct hw_unit_info *p;
+	const struct hw_unit_info *p = NULL;
+	enum pdbg_backend backend = pdbg_get_backend();
+
+	if (backend == PDBG_DEFAULT_BACKEND) {
+		backend = get_backend_driver();
+		if (backend != PDBG_DEFAULT_BACKEND)
+			p = find_compatible(backend, compat_list, len);
+	} else {
+		p = find_compatible(backend, compat_list, len);
+	}
 
-	p = find_compatible(pdbg_get_backend(), compat_list, len);
 	if (!p)
 		p = find_compatible(PDBG_DEFAULT_BACKEND, compat_list, len);
 
-- 
2.25.3



More information about the Pdbg mailing list