summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2011-04-06 17:30:31 +0200
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2011-04-06 17:30:31 +0200
commitee6ea2f21e2516047db66004fda060a23b152103 (patch)
treef3e40a44a03e3f487f17080109cf1e759294f4be
parenta5fc8db4f29a38089c5f81433b90702ef7db60d1 (diff)
downloadpcitool-ee6ea2f21e2516047db66004fda060a23b152103.tar.gz
pcitool-ee6ea2f21e2516047db66004fda060a23b152103.tar.bz2
pcitool-ee6ea2f21e2516047db66004fda060a23b152103.tar.xz
pcitool-ee6ea2f21e2516047db66004fda060a23b152103.zip
Support memset operation
-rw-r--r--cli.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/cli.c b/cli.c
index 16151fc..4fe56c9 100644
--- a/cli.c
+++ b/cli.c
@@ -121,6 +121,11 @@ void Usage(int argc, char *argv[], const char *format, ...) {
" -s <size> - Number of words (default: 1)\n"
" -a <bitness> - Bits per word (default: 32)\n"
" -e <l|b> - Endianess Little/Big (default: host)\n"
+"\n"
+" Data:\n"
+" Data can be specified as sequence of hexdecimal number or\n"
+" a single value prefixed with '*'. In this case it will be\n"
+" replicated the specified amount of times\n"
"\n\n",
argv[0]);
@@ -565,6 +570,8 @@ int main(int argc, char **argv) {
const char *addr = NULL;
const char *reg = NULL;
const char *bank = NULL;
+ char **data = NULL;
+
uintptr_t start = -1;
size_t size = 1;
access_t access = 4;
@@ -665,7 +672,16 @@ int main(int argc, char **argv) {
switch (mode) {
case MODE_WRITE:
if (!addr) Usage(argc, argv, "The address is not specified");
- if ((argc - optind) != size) Usage(argc, argv, "The %i data values is specified, but %i required", argc - optind, size);
+ if (((argc - optind) == 1)&&(*argv[optind] == '*')) {
+ int vallen = strlen(argv[optind]);
+ data = (char**)malloc(size * (vallen + sizeof(char*)));
+ if (!data) Error("Error allocating memory for data array");
+ for (i = 0; i < size; i++) {
+ data[i] = ((char*)data) + size * sizeof(char*) + i * vallen;
+ strcpy(data[i], argv[optind] + 1);
+ }
+ } else if ((argc - optind) == size) data = argv + optind;
+ else Usage(argc, argv, "The %i data values is specified, but %i required", argc - optind, size);
break;
case MODE_READ:
if (!addr) {
@@ -735,13 +751,15 @@ int main(int argc, char **argv) {
else ReadRegisterRange(handle, model, bank, start, size);
break;
case MODE_WRITE:
- WriteData(handle, bar, start, size, access, endianess, argv + optind);
+ WriteData(handle, bar, start, size, access, endianess, data);
break;
case MODE_WRITE_REGISTER:
- if (reg) WriteRegister(handle, model, bank, reg, argv + optind);
- else WriteRegisterRange(handle, model, bank, start, size, argv + optind);
+ if (reg) WriteRegister(handle, model, bank, reg, data);
+ else WriteRegisterRange(handle, model, bank, start, size, data);
break;
}
pcilib_close(handle);
+
+ if (data != argv + optind) free(data);
}