[PATCH v2 3/3] tools: kwboot: Allow to mix positional arguments with option -b
Stefan Roese
sr at denx.de
Wed Mar 9 06:51:28 CET 2022
On 3/8/22 20:22, Pali Rohár wrote:
> On Monday 07 March 2022 21:23:29 Tony Dinh wrote:
>> Hi Pali,
>>
>> I've tested this patch series and it's all working fine!
>
> Perfect!
>
> Stefan, I think that this change should go into 2022.04 as it is fixing
> regression introduced during 2022.04 development.
I agree.
> Could you do more checks/testing of kwboot if everything is also working
> fine for you?
I'll try to do this later this week, yes.
Thanks,
Stefan
>> Thanks,
>> Tony
>>
>> Tested-by: Tony Dinh <mibodhi at gmail.com>
>>
>>
>> On Mon, Mar 7, 2022 at 10:04 AM Pali Rohár <pali at kernel.org> wrote:
>>>
>>> Commit 9e6d71d2b55f ("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: 9e6d71d2b55f ("tools: kwboot: Allow to use -b without image path as the last getopt() option")
>>> Signed-off-by: Pali Rohár <pali at kernel.org>
>>> Reported-by: Tony Dinh <mibodhi at gmail.com>
>>> ---
>>> Tony and Marcel, could you test this change if all your kwboot use cases
>>> still work correctly?
>>> ---
>>> tools/kwboot.c | 18 ++++++++++++++----
>>> 1 file changed, 14 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/tools/kwboot.c b/tools/kwboot.c
>>> index 3b45e19a30aa..9f2dd2de4ef5 100644
>>> --- a/tools/kwboot.c
>>> +++ b/tools/kwboot.c
>>> @@ -2073,7 +2073,8 @@ main(int argc, char **argv)
>>> bootmsg = 1;
>>> if (prev_optind == optind)
>>> 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++];
>>> break;
>>>
>>> @@ -2128,10 +2129,19 @@ main(int argc, char **argv)
>>> if (!bootmsg && !term && !debugmsg && !imgpath)
>>> goto usage;
>>>
>>> - ttypath = argv[optind++];
>>> -
>>> - if (optind != argc)
>>> + /*
>>> + * If there is no remaining argument but optional imgpath was parsed
>>> + * 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;
>>> + }
>>>
>>> /* boot and debug message use baudrate 115200 */
>>> if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {
>>> --
>>> 2.20.1
>>>
Viele Grüße,
Stefan Roese
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
More information about the U-Boot
mailing list