Commit a17d25bb authored by Federico Vaga's avatar Federico Vaga

tool: use getopt in svec-flasher

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent e30926af
......@@ -427,6 +427,13 @@ static void bitstream_buffer_free(struct bitstream *bitstream)
}
static void help(const char *name)
{
printf("usage: %s slot bitstream.bin [-b]\n", name);
printf(" -b: updates the bootloader itself\n");
printf(" -f: loads the bitstream straight to the Application FPGA (without programming the flash)\n");
}
int main(int argc, char *argv[])
{
struct bitstream bitstream;
......@@ -438,38 +445,47 @@ int main(int argc, char *argv[])
int direct_boot = 0;
int rv;
int err;
if (argc < 3) {
printf("usage: %s slot bitstream.bin [-b]\n", argv[0]);
printf(" -b: updates the bootloader itself\n");
printf(" -f: loads the bitstream straight to the Application FPGA (without programming the flash)\n");
return 0;
char opt;
while ((opt = getopt(argc, argv, "h?bf")) != -1) {
switch (opt) {
default:
case 'h':
case '?':
help(argv[0]);
exit(EXIT_SUCCESS);
break;
case 'b':
program_boot = 1;
break;
case 'f':
direct_boot = 1;
break;
}
}
if(argc > 3 && !strcmp(argv[3], "-b"))
{
program_boot = 1;
} else if(argc > 3 && !strcmp(argv[3], "-f"))
{
direct_boot = 1;
}
bitstream.path = argv[2];
err = bitstream_buffer_alloc_and_fill(&bitstream);
if (err) {
fprintf(stderr, "Can't read bitstream '%s'. %s",
bitstream.path, strerror(errno));
return -1;
if (argc - optind != 2) {
help(argv[0]);
exit(EXIT_FAILURE);
}
rv = sscanf(argv[1], "%i", &slot);
rv = sscanf(argv[optind], "%i", &slot);
if (!rv) {
rv = sscanf(argv[1], "VME.%i", &slot);
rv = sscanf(argv[optind], "VME.%i", &slot);
if (!rv) {
fprintf(stderr, "Can't parse slot '%s'\n", argv[1]);
fprintf(stderr, "Can't parse slot '%s'\n", argv[optind]);
return -1;
}
}
optind++;
bitstream.path = argv[optind];
err = bitstream_buffer_alloc_and_fill(&bitstream);
if (err) {
fprintf(stderr, "Can't read bitstream '%s'. %s",
bitstream.path, strerror(errno));
return -1;
}
init_vme(slot);
enter_bootloader();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment