Skip to content

Commit 5c020f3

Browse files
committed
Increase handled port number up to 20
1 parent 466e26d commit 5c020f3

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

main.c

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void usage(int error)
8484
fprintf(dest, " -v : Verbose\n");
8585
fprintf(dest, " -V : Displays the version string and exits\n");
8686
fprintf(dest, " -s : Signed using bootsig.bin\n");
87-
fprintf(dest, " -0/1/2/3/4/5/6 : Only look for CMs attached to USB port number 0-6\n");
87+
fprintf(dest, " -0/1/2/.../20 : Only look for CMs attached to USB port number 0-20\n");
8888
fprintf(dest, " -p [pathname] : Only look for CM with USB pathname\n");
8989
fprintf(dest, " -i [serialno] : Only look for a Raspberry Pi Device with a given serialno\n");
9090
fprintf(dest, " -j [path] : Enable output of metadata JSON files in a given directory for BCM2712/2711\n");
@@ -556,33 +556,15 @@ void get_options(int argc, char *argv[])
556556
target_serialno = *argv;
557557
}
558558
}
559-
else if(strcmp(*argv, "-0") == 0)
559+
else if((*argv)[0] == '-' && isdigit((unsigned char)(*argv)[1]))
560560
{
561-
targetPortNo = 0;
562-
}
563-
else if(strcmp(*argv, "-1") == 0)
564-
{
565-
targetPortNo = 1;
566-
}
567-
else if(strcmp(*argv, "-2") == 0)
568-
{
569-
targetPortNo = 2;
570-
}
571-
else if(strcmp(*argv, "-3") == 0)
572-
{
573-
targetPortNo = 3;
574-
}
575-
else if(strcmp(*argv, "-4") == 0)
576-
{
577-
targetPortNo = 4;
578-
}
579-
else if(strcmp(*argv, "-5") == 0)
580-
{
581-
targetPortNo = 5;
582-
}
583-
else if(strcmp(*argv, "-6") == 0)
584-
{
585-
targetPortNo = 6;
561+
char *endptr;
562+
long port = strtol(*argv + 1, &endptr, 10);
563+
if (*endptr == '\0' && port >= 0 && port <= 20) {
564+
targetPortNo = (uint8_t)port;
565+
} else {
566+
usage(1);
567+
}
586568
}
587569
else
588570
{

0 commit comments

Comments
 (0)