[Pdbg] [PATCH v2 13/15] main: Convert getcfam/putcfam to use path based targeting

Amitay Isaacs amitay at ozlabs.org
Fri Nov 9 18:10:09 AEDT 2018


Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 src/cfam.c           | 60 ++++++++++++++++++++++++++++++--------------
 tests/test_hw_bmc.sh |  4 +--
 2 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/src/cfam.c b/src/cfam.c
index 6dab388..69b21a4 100644
--- a/src/cfam.c
+++ b/src/cfam.c
@@ -18,42 +18,64 @@
 #include <stdlib.h>
 #include <string.h>
 #include <inttypes.h>
+#include <assert.h>
 
 #include "main.h"
 #include "optcmd.h"
+#include "path.h"
 
-static int _getcfam(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *unused)
+static int getcfam(uint32_t addr)
 {
+	struct pdbg_target *target;
+	char *path;
 	uint32_t value;
+	int count = 0;
 
-	if (fsi_read(target, *addr, &value))
-		return 0;
+	for_each_path_target_class("fsi", target) {
+		if (pdbg_target_status(target) != PDBG_TARGET_ENABLED)
+			continue;
 
-	printf("p%d:0x%x = 0x%08x\n", index, (uint32_t) *addr, value);
+		path = pdbg_target_path(target);
+		assert(path);
 
-	return 1;
-}
+		if (fsi_read(target, addr, &value)) {
+			printf("%s: failed\n", path);
+			free(path);
+			continue;
 
-static int getcfam(uint32_t addr)
-{
-	uint64_t addr64 = addr;
+		}
+
+		printf("%s: 0x%x = 0x%08x\n", path, addr, value);
+		free(path);
+		count++;
+	}
 
-	return for_each_target("fsi", _getcfam, &addr64, NULL);
+	return count;
 }
 OPTCMD_DEFINE_CMD_WITH_ARGS(getcfam, getcfam, (ADDRESS32));
 
-static int _putcfam(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *data)
+static int putcfam(uint32_t addr, uint32_t data)
 {
-	if (fsi_write(target, *addr, *data))
-		return 0;
+	struct pdbg_target *target;
+	char *path;
+	int count = 0;
 
-	return 1;
-}
+	for_each_path_target_class("fsi", target) {
+		if (pdbg_target_status(target) != PDBG_TARGET_ENABLED)
+			continue;
 
-static int putcfam(uint32_t addr, uint32_t data)
-{
-	uint64_t addr64 = addr, data64 = data;
+		path = pdbg_target_path(target);
+		assert(path);
+
+		if (fsi_write(target, addr, data)) {
+			printf("%s: failed\n", path);
+			free(path);
+			continue;
+		}
+
+		count++;
+	}
 
-	return for_each_target("fsi", _putcfam, &addr64, &data64);
+	return count;
 }
 OPTCMD_DEFINE_CMD_WITH_ARGS(putcfam, putcfam, (ADDRESS32, DATA32));
diff --git a/tests/test_hw_bmc.sh b/tests/test_hw_bmc.sh
index c35597b..9bc1deb 100755
--- a/tests/test_hw_bmc.sh
+++ b/tests/test_hw_bmc.sh
@@ -84,11 +84,11 @@ result_filter ()
 }
 
 test_result 0 <<EOF
-p0:0xc09 = HEX8
+/kernelfsi at 0: 0xc09 = HEX8
 EOF
 
 do_skip
-test_run $PDBG -p0 getcfam 0xc09
+test_run $PDBG -P fsi getcfam 0xc09
 
 test_result 0 <<EOF
 p0:0xf000f = HEX16
-- 
2.19.1



More information about the Pdbg mailing list