From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 42F73C433F5 for ; Mon, 7 Mar 2022 18:04:40 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9C7AB820A3; Mon, 7 Mar 2022 19:04:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="IwJ9snpk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5C2B981DD0; Mon, 7 Mar 2022 19:04:09 +0100 (CET) Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F3CA381D4B for ; Mon, 7 Mar 2022 19:04:03 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 11A5ACE1171; Mon, 7 Mar 2022 18:04:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F06BC340E9; Mon, 7 Mar 2022 18:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646676239; bh=trDb45M7un8c4xsAFxW8q5Bqcyp/ZldXma0nod1lKIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IwJ9snpkCq/WyIlJ7Xi0e9FNp5WxTLqRo18mF/kqMCUkEvdNY+bn+3kxPrfoR/zL2 5kg70uPO81tGpbN5AKJhJEpITLEjGoa7dB1nex+mX3e0RgF/5PSavrMbaKLaYlo08Z Qbnzlt+0cA7ZgUB77J0x1P/8LR8Itd9b8FVhpAnKMNxcMAbQHkwTRhbp/mv7ZXUI/L DcOipC/lc1QQmiTOcfWYl3q052l8DcjXMyryBIK//foAtQEeDHJMzhHLOjykzv/o9j H0e16gQF6/wDF59PJzXqtc8pEEzBC1z1Oe9w+PMj8qjKlEKxVlw90HStWCN/17xP9n u05tMjmmDOzRQ== Received: by pali.im (Postfix) id D76462098; Mon, 7 Mar 2022 19:03:56 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Marcel Ziswiler , Tony Dinh Cc: u-boot@lists.denx.de Subject: [PATCH v2 3/3] tools: kwboot: Allow to mix positional arguments with option -b Date: Mon, 7 Mar 2022 19:03:09 +0100 Message-Id: <20220307180309.31275-3-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220307180309.31275-1-pali@kernel.org> References: <20220307180309.31275-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean 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 Reported-by: Tony Dinh --- 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