Skip to content

Commit

Permalink
xscom-utils: Rework getsram
Browse files Browse the repository at this point in the history
Allow specifying a file on the command line to read OCC SRAM data into.
If no file is specified then we print it to stdout as text. This is a
bit inconsistent, but it retains compatibility with the existing tool.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
  • Loading branch information
oohal authored and stewartsmith committed Sep 20, 2018
1 parent 57a17c2 commit 6e52466
Showing 1 changed file with 47 additions and 7 deletions.
54 changes: 47 additions & 7 deletions external/xscom-utils/getsram.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,38 @@

static void print_usage(int code)
{
printf("usage: getsram [-c|--chip chip-id] addr\n");
printf(" [--occ-channel|n <chan>]\n");
printf(" getsram -v|--version\n");
printf("usage: getsram [opts] addr\n");
printf(" -c|--chip <chip-id>\n");
printf(" -l|--length <size to read>\n");
printf(" -n|--occ-channel <chan>\n");
printf(" -f|--file <filename>\n");
printf(" -v|--version\n");
exit(code);
}

extern const char version[];

int main(int argc, char *argv[])
{
uint64_t val, addr = -1ull;
uint64_t val, addr = -1ull, length = 8;
uint32_t def_chip, chip_id = 0xffffffff;
int rc;
int occ_channel = 0;
char *filename = NULL;
FILE *f = stdout;

while(1) {
static struct option long_opts[] = {
{"chip", required_argument, NULL, 'c'},
{"occ-channel", required_argument, NULL, 'n'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{"length", required_argument, NULL, 'l'},
{"file", required_argument, NULL, 'f'},
};
int c, oidx = 0;

c = getopt_long(argc, argv, "-c:n:hlv", long_opts, &oidx);
c = getopt_long(argc, argv, "-c:n:hl:vf:", long_opts, &oidx);
if (c == EOF)
break;
switch(c) {
Expand All @@ -73,6 +80,13 @@ int main(int argc, char *argv[])
case 'v':
printf("xscom utils version %s\n", version);
exit(0);
case 'f':
filename = optarg;
break;
case 'l':
length = strtoul(optarg, NULL, 0);
length = (length + 7) & ~0x7; /* round up to an eight byte interval */
break;
default:
exit(1);
}
Expand All @@ -91,11 +105,37 @@ int main(int argc, char *argv[])
if (chip_id == 0xffffffff)
chip_id = def_chip;

rc = sram_read(chip_id, occ_channel, addr, &val);
if (filename) {
f = fopen(filename, "wb");
if (!f) {
fprintf(stderr, "unable to open %s for writing\n", filename);
exit(1);
}
}

rc = 0;
while (length) {
rc = sram_read(chip_id, occ_channel, addr, &val);
if (rc)
break;

if (f) {
int i;

/* make sure we write it out big endian */
for (i = 1; i <= 8; i++)
fputc((val >> (64 - i * 8)) & 0xff, f);
} else {
printf("OCC%d: %" PRIx64 "\n", occ_channel, val);
}

length -= 8;
addr += 8;
}

if (rc) {
fprintf(stderr,"Error %d reading XSCOM\n", rc);
exit(1);
}
printf("OCC%d: %" PRIx64 "\n", occ_channel, val);
return 0;
}

0 comments on commit 6e52466

Please sign in to comment.