summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyril Bur <cyrilbur@gmail.com>2018-02-09 15:38:42 +1100
committerAlistair Popple <alistair@popple.id.au>2018-02-16 16:22:23 +1100
commitdeb1a32745301039b17fbacd6bb2f0a64d0b4109 (patch)
tree3c2c341677d33d12bb1e4a8855743d6822e6fa92
parent34a70c8810e3b643748aca3061cf09961de9eb18 (diff)
downloadpdbg-deb1a32745301039b17fbacd6bb2f0a64d0b4109.tar.gz
pdbg-deb1a32745301039b17fbacd6bb2f0a64d0b4109.zip
main: Use new command handling for scoms
Signed-off-by: Cyril Bur <cyrilbur@gmail.com>
-rw-r--r--src/main.c20
-rw-r--r--src/scom.c51
-rw-r--r--src/scom.h3
3 files changed, 52 insertions, 22 deletions
diff --git a/src/main.c b/src/main.c
index 708f314..2dd4f24 100644
--- a/src/main.c
+++ b/src/main.c
@@ -86,6 +86,8 @@ static struct {
} actions[] = {
{ "getcfam", "<address>", "Read system cfam", &handle_cfams },
{ "putcfam", "<address> <value> [<mask>]", "Write system cfam", &handle_cfams },
+ { "getscom", "<address>", "Read system scom", &handle_scoms },
+ { "putscom", "<address> <value> [<mask>]", "Write system scom", &handle_scoms }
};
static void print_usage(char *pname)
@@ -146,17 +148,7 @@ enum command parse_cmd(char *optarg)
{
cmd_max_arg_count = 0;
- if (strcmp(optarg, "getscom") == 0) {
- cmd = GETSCOM;
- cmd_min_arg_count = 1;
- } else if (strcmp(optarg, "putscom") == 0) {
- cmd = PUTSCOM;
- cmd_min_arg_count = 2;
- cmd_max_arg_count = 3;
-
- /* No mask by default */
- cmd_args[2] = -1ULL;
- } else if (strcmp(optarg, "getmem") == 0) {
+ if (strcmp(optarg, "getmem") == 0) {
cmd = GETMEM;
cmd_min_arg_count = 2;
} else if (strcmp(optarg, "putmem") == 0) {
@@ -615,12 +607,6 @@ int main(int argc, char *argv[])
return -1;
switch(cmd) {
- case GETSCOM:
- rc = for_each_target("pib", getscom, &cmd_args[0], NULL);
- break;
- case PUTSCOM:
- rc = for_each_target("pib", putscom, &cmd_args[0], &cmd_args[1]);
- break;
case GETMEM:
buf = malloc(cmd_args[1]);
assert(buf);
diff --git a/src/scom.c b/src/scom.c
index f9102cc..4073d88 100644
--- a/src/scom.c
+++ b/src/scom.c
@@ -13,12 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <inttypes.h>
+#include <errno.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
#include <target.h>
-int getscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *unused)
+#include "main.h"
+
+static int getscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *unused)
{
uint64_t value;
@@ -30,7 +35,7 @@ int getscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t
return 1;
}
-int putscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *data)
+static int putscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *data)
{
if (pib_write(target, *addr, *data))
return 0;
@@ -39,3 +44,43 @@ int putscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t
}
+int handle_scoms(int optind, int argc, char *argv[])
+{
+ uint64_t addr;
+ char *endptr;
+
+ if (optind + 1 >= argc) {
+ printf("%s: command '%s' requires an address\n", argv[0], argv[optind]);
+ return -1;
+ }
+
+ errno = 0;
+ addr = strtoull(argv[optind + 1], &endptr, 0);
+ if (errno || *endptr != '\0') {
+ printf("%s: command '%s' couldn't parse address '%s'\n",
+ argv[0], argv[optind], argv[optind + 1]);
+ return -1;
+ }
+
+ if (strcmp(argv[optind], "putscom") == 0) {
+ uint64_t data;
+
+ if (optind + 2 >= argc) {
+ printf("%s: command '%s' requires data\n", argv[0], argv[optind]);
+ return -1;
+ }
+
+ errno = 0;
+ data = strtoull(argv[optind + 2], &endptr, 0);
+ if (errno || *endptr != '\0') {
+ printf("%s: command '%s' couldn't parse data '%s'\n",
+ argv[0], argv[optind], argv[optind + 1]);
+ return -1;
+ }
+
+ return for_each_target("pib", putscom, &addr, &data);
+ }
+
+ return for_each_target("pib", getscom, &addr, NULL);
+}
+
diff --git a/src/scom.h b/src/scom.h
index afda6af..890207f 100644
--- a/src/scom.h
+++ b/src/scom.h
@@ -17,5 +17,4 @@
#include <target.h>
-int getscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *unused);
-int putscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *data);
+int handle_scoms(int optind, int argc, char *argv[]);
OpenPOWER on IntegriCloud