[Skiboot] [PATCH v2] external: Add a getsram command
Cédric Le Goater
clg at fr.ibm.com
Wed Mar 9 23:25:13 AEDT 2016
On 03/08/2016 04:25 PM, Cédric Le Goater wrote:
> On 03/08/2016 12:11 PM, Vasant Hegde wrote:
>> On 03/08/2016 04:00 PM, Cédric Le Goater wrote:
>>> The getsram command reads the OCC SRAM. This is useful for debug.
>>
>> .../...
>>
>>> +
>>> +static void print_usage(void)
>>> +{
>>> + printf("usage: getsram [-c|--chip chip-id] addr\n");
>>> + printf(" [--occ-channel|n <chan>]\n");
>>> + printf(" getsram -v|--version\n");
>>> +}
>>> +
>>> +#define VERSION_STR _str(VERSION)
>>> +#define _str(s) __str(s)
>>> +#define __str(s) #s
>>> +
>>> +int main(int argc, char *argv[])
>>> +{
>>> + uint64_t val, addr = -1ull;
>>> + uint32_t def_chip, chip_id = 0xffffffff;
>>> + bool show_help = false;
>>> + bool show_version = false;
>>> + bool no_work = false;
>>> + int rc;
>>> + int occ_channel = 0;
>>> +
>>> + 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'},
>>> + };
>>> + int c, oidx = 0;
>>> +
>>> + c = getopt_long(argc, argv, "-c:n:hlv", long_opts, &oidx);
>>> + if (c == EOF)
>>> + break;
>>> + switch(c) {
>>> + case 1:
>>> + addr = strtoull(optarg, NULL, 16);
>>> + break;
>>> + case 'c':
>>> + chip_id = strtoul(optarg, NULL, 0);
>>> + break;
>>> + case 'n':
>>> + occ_channel = strtoul(optarg, NULL, 0);
>>> + if (occ_channel < 0 || occ_channel > 3) {
>>> + fprintf(stderr, "occ-channel out of range 0 <= c <= 3\n");
>>> + exit(1);
>>> + }
>>> + break;
>>> + case 'h':
>>> + show_help = true;
>>
>> Better call print_usage and exit ?
>>
>>> + break;
>>> + case 'v':
>>
>> Better print version here and exit?
>
> I strictly followed the getscom pattern :) I admit it is not perfect
> but it does the job.
But your suggestion does kill a few lines in all commands. I will send a v3.
Thanks,
C.
More information about the Skiboot
mailing list