mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-25 06:00:43 +00:00
tools: kwboot: Allow to mix positional arguments with option -b
Commit9e6d71d2b5
("tools: kwboot: Allow to use -b without image path as the last getopt() option") broke usage of kwboot with following arguments: kwboot -t -B 115200 /dev/ttyUSB0 -b u-boot-spl.kwb Fix parsing of option -b with optional argument again. Fixes:9e6d71d2b5
("tools: kwboot: Allow to use -b without image path as the last getopt() option") Signed-off-by: Pali Rohár <pali@kernel.org> Reported-by: Tony Dinh <mibodhi@gmail.com> Tested-by: Tony Dinh <mibodhi at gmail.com> Reviewed-by: Stefan Roese <sr@denx.de>
This commit is contained in:
parent
3782f55ae8
commit
c497ae7023
1 changed files with 14 additions and 4 deletions
|
@ -2073,7 +2073,8 @@ main(int argc, char **argv)
|
||||||
bootmsg = 1;
|
bootmsg = 1;
|
||||||
if (prev_optind == optind)
|
if (prev_optind == optind)
|
||||||
goto usage;
|
goto usage;
|
||||||
if (optind < argc - 1 && argv[optind] && argv[optind][0] != '-')
|
/* Option -b could have optional argument which specify image path */
|
||||||
|
if (optind < argc && argv[optind] && argv[optind][0] != '-')
|
||||||
imgpath = argv[optind++];
|
imgpath = argv[optind++];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -2128,10 +2129,19 @@ main(int argc, char **argv)
|
||||||
if (!bootmsg && !term && !debugmsg && !imgpath)
|
if (!bootmsg && !term && !debugmsg && !imgpath)
|
||||||
goto usage;
|
goto usage;
|
||||||
|
|
||||||
ttypath = argv[optind++];
|
/*
|
||||||
|
* If there is no remaining argument but optional imgpath was parsed
|
||||||
if (optind != argc)
|
* then it means that optional imgpath was eaten by getopt parser.
|
||||||
|
* Reassing imgpath to required ttypath argument.
|
||||||
|
*/
|
||||||
|
if (optind == argc && imgpath) {
|
||||||
|
ttypath = imgpath;
|
||||||
|
imgpath = NULL;
|
||||||
|
} else if (optind + 1 == argc) {
|
||||||
|
ttypath = argv[optind];
|
||||||
|
} else {
|
||||||
goto usage;
|
goto usage;
|
||||||
|
}
|
||||||
|
|
||||||
/* boot and debug message use baudrate 115200 */
|
/* boot and debug message use baudrate 115200 */
|
||||||
if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {
|
if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {
|
||||||
|
|
Loading…
Reference in a new issue