diff mbox series

[05/23] libpdbg: Backend device tree cannot be overriden

Message ID 20200414024750.20170-6-amitay@ozlabs.org
State Superseded
Headers show
Series Enable drivers per backend | expand

Checks

Context Check Description
snowpatch_ozlabs/build-multiarch success Test build-multiarch on branch master
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (6ae2ba655ca5e24b403a33bf15dff7261d3e7052)

Commit Message

Amitay Isaacs April 14, 2020, 2:47 a.m. UTC
With drivers getting registered per backend, backend needs to be
initialised before any device tree can be parsed.  PDBG_BACKEND_DTB
allowed to override backend device tree without specifying backend,
which cannot work any more.

To be able to dynamically update backend introduce PDBG_BACKEND and
PDBG_BACKEND_OPTION variables instead of PDBG_BACKEND_DTB.

Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 libpdbg/dtb.c                     | 32 ++++++++++++++++++++++---------
 tests/test_p9_fapi_translation.sh |  2 +-
 2 files changed, 24 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c
index 70b7962..077bc62 100644
--- a/libpdbg/dtb.c
+++ b/libpdbg/dtb.c
@@ -234,7 +234,7 @@  static void bmc_target(struct pdbg_dtb *dtb)
 }
 
 /* Opens a dtb at the given path */
-static void mmap_dtb(char *file, bool readonly, struct pdbg_mfile *mfile)
+static void mmap_dtb(const char *file, bool readonly, struct pdbg_mfile *mfile)
 {
 	int fd;
 	void *dtb;
@@ -308,21 +308,36 @@  const char *pdbg_get_backend_option(void)
 struct pdbg_dtb *pdbg_default_dtb(void *system_fdt)
 {
 	struct pdbg_dtb *dtb = &pdbg_dtb;
-	char *fdt;
+	const char *fdt, *backend;
 
 	dtb->backend.fdt = NULL;
 	dtb->system.fdt = system_fdt;
 
-	fdt = getenv("PDBG_BACKEND_DTB");
-	if (fdt)
-		mmap_dtb(fdt, false, &dtb->backend);
-
 	fdt = getenv("PDBG_DTB");
 	if (fdt)
 		mmap_dtb(fdt, false, &dtb->system);
 
-	if (dtb->backend.fdt && dtb->system.fdt)
-		goto done;
+	backend = getenv("PDBG_BACKEND");
+	if (backend) {
+		const char *arg;
+
+		arg = getenv("PDBG_BACKEND_OPTION");
+
+		if (!strcmp(backend, "fsi"))
+			pdbg_set_backend(PDBG_BACKEND_FSI, arg);
+		else if (!strcmp(backend, "i2c"))
+			pdbg_set_backend(PDBG_BACKEND_I2C, arg);
+		else if (!strcmp(backend, "kernel"))
+			pdbg_set_backend(PDBG_BACKEND_KERNEL, arg);
+		else if (!strcmp(backend, "fake"))
+			pdbg_set_backend(PDBG_BACKEND_FAKE, arg);
+		else if (!strcmp(backend, "host"))
+			pdbg_set_backend(PDBG_BACKEND_HOST, arg);
+		else if (!strcmp(backend, "cronus"))
+			pdbg_set_backend(PDBG_BACKEND_CRONUS, arg);
+		else
+			pdbg_log(PDBG_ERROR, "Invalid backend '%s', ignoring\n", backend);
+	}
 
 	if (!pdbg_backend)
 		pdbg_backend = default_backend();
@@ -412,7 +427,6 @@  struct pdbg_dtb *pdbg_default_dtb(void *system_fdt)
 		break;
 	}
 
-done:
 	return dtb;
 }
 
diff --git a/tests/test_p9_fapi_translation.sh b/tests/test_p9_fapi_translation.sh
index a5a09b1..9891d39 100755
--- a/tests/test_p9_fapi_translation.sh
+++ b/tests/test_p9_fapi_translation.sh
@@ -4,7 +4,7 @@ 
 
 test_group "p9 fapi translation tests"
 
-export PDBG_BACKEND_DTB=p9-kernel.dtb
+export PDBG_BACKEND=kernel
 export PDBG_DTB=p9.dtb
 
 test_result 0 <<EOF