From patchwork Mon Jan 31 02:52:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 538473 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp1405611imr; Sun, 30 Jan 2022 18:52:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzavicVprj6llMvCbGsF9FBJiuKhbMBELcgQA53/FOQDkbZbod9IKDHlHSexKICkeXCZh41 X-Received: by 2002:a05:6402:22bb:: with SMTP id cx27mr18261779edb.304.1643597553512; Sun, 30 Jan 2022 18:52:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643597553; cv=none; d=google.com; s=arc-20160816; b=0MNiXpVqFFAnL4fOhFUe3Z2Zuysi1uKipTCIr2UgWPdwCZwSnXsmb41nfG2SPYVmw4 zdJiS1QeLN4NzlKKyUSFK6crERSuGUWVCLkTOcZyPWEE74eh5Cx5Tbw+A9yK94Hp+BNP DFW6Pri82FzOySK8CbVyEHWgcudiI/AyS4IFa69n8oHi60kYDTMOrG5vScPNNn/lZYfR vRiXpL+TDLgyOTliAkizK3Ghh6d6IpsRcGcx0Q270WuTQlqmZ9tEg73dd17rbMAeeKrg a9uaHPeapUPxUxkvIC7Sa8glf2GfNhdWrgCd6znMYGXnHb8UqDqTpeRXzMd/2tCiKM5H YovA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Z2ROnf8FiP3NdigMZdG7gXUWT9ksrzqvxWkcZavbpuA=; b=IrQ3WERdURI3JYORg67beu+6kiNHSMcvzCotDMeJS5tLApDvTMxxf8NSFektAgt07V ATZJG0Wtzm6tzmw2oZJlNsimpWy8rQVeDzDAs4aF96kFzXvuzXYVuI6UHOp4cJVmbi2v /Unw3KsclrfjFhYvZ4hPTnGorxctczu1FrqYMhIpVy+77jY5Ts9kAfPgQjJcZoT54IrX /0N8thFZ/jzYdNtZ8b88tIG8l6I2K+ZmT16+cWW5n+ME+UIxsrQbqC0epyl4x8E8bTT2 kEOvmtzqM2YHfH1ZxC9Yf09cPpjjEzlKX/Oe0SkldZRfC9dSsBdiomSsa35UElzmj5Ju 20lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fr6o/1Z3"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 9si7301667ejd.50.2022.01.30.18.52.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 18:52:33 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fr6o/1Z3"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7E5D7835BA; Mon, 31 Jan 2022 03:52:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.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=linaro.org header.i=@linaro.org header.b="Fr6o/1Z3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1B1ED8339D; Mon, 31 Jan 2022 03:52:28 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3D2F58339D for ; Mon, 31 Jan 2022 03:52:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masami.hiramatsu@linaro.org Received: by mail-pg1-x52b.google.com with SMTP id e16so11001689pgn.4 for ; Sun, 30 Jan 2022 18:52:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=Z2ROnf8FiP3NdigMZdG7gXUWT9ksrzqvxWkcZavbpuA=; b=Fr6o/1Z3bwyntT3KOgMQZTx3DToWbSxCJBmvzY2vfBCW4zu1nZwHi3oCJgTXeIoacT 0jj8Ve3+V8hcFNQFoEDuvhzuRYp50OS2Fo+W/ucu1DM/frFZ20sltkjf+ad6OfE2+Ar3 jSepq/zSHHHm0BWjpICYBNgvn/63KZmOJZ+HoVzKmEBS/oaBkNnN103rWPpWiYonoHh8 WN2UxAfDxxvCiIrSdmZ0mKXzj2GUy1gPnFzmlhWWbgXNe+qMvl7l4ZcXwfGCfE4BDmUE 5VxOfZH2t8gdv3Km3mmlUFd+OkJfuUW1ETwf+H9D8rliMaGACknRu5AgWIHjrVo4UKJH q9yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=Z2ROnf8FiP3NdigMZdG7gXUWT9ksrzqvxWkcZavbpuA=; b=prQnjTzxNzjetZeBtM72xzQ7WzuP/elCiBMtQnboNLTb3KGig9qBwLJ88uhnvCPAYU mgTMRVUDCPZ6u0vR1UUAa0WRnkYU63+9UIwkVvb9R7Slkl39ShQ+0l5GvQ8KvikUfko6 yX47j4UcRD93HhF50HrgyMB8bhzmH4C4qgtaLRdqRiharfaRvIIPZ38GwExU9AgO+ZPn D7wqtu+mpfb6bkt/L5SE4It+ab9NkDvFaOyLYE0xWVTP5fwyEGuD0kgU4pXo4MbLJb0S Qj+IA3meO4p+D2oawnet4idR+TIBkGOtBZr/9yXE7ozhX7t7giOyGmWbBkTQESqv1jca zzzg== X-Gm-Message-State: AOAM531XnsiZV3OvxxCQvuVvcdtbhPHW7pb2V9GfjzvBq77IQoG1QVTw FznUn9fqu1LR5VEAREz+JpX0DA== X-Received: by 2002:a63:e250:: with SMTP id y16mr14927001pgj.147.1643597543701; Sun, 30 Jan 2022 18:52:23 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id s37sm12089955pfg.144.2022.01.30.18.52.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 18:52:23 -0800 (PST) From: Masami Hiramatsu To: Tom Rini , Lukasz Majewski Cc: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, jaswinder.singh@linaro.org Subject: [PATCH v2 1/5] DFU: Do not copy the entity name over the buffer size Date: Mon, 31 Jan 2022 11:52:20 +0900 Message-Id: <164359754070.280839.249007223441412046.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164359753172.280839.8310577813724924540.stgit@localhost> References: <164359753172.280839.8310577813724924540.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 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 Use strlcpy() instead of strcpy() to prevent copying the entity name over the name buffer size. Signed-off-by: Masami Hiramatsu --- drivers/dfu/dfu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index af3975925a..66c41b5e76 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -503,7 +503,7 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt, debug("%s: %s interface: %s dev: %s\n", __func__, s, interface, devstr); st = strsep(&s, " "); - strcpy(dfu->name, st); + strlcpy(dfu->name, st, DFU_NAME_SIZE); dfu->alt = alt; dfu->max_buf_size = 0; From patchwork Mon Jan 31 02:52:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 538474 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp1405666imr; Sun, 30 Jan 2022 18:52:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxv/2aP6rROUWOY9kIUyOHH2l/TB95TzW+BvgTRDWiEV55V8r9qbPo5sHdo0N1XFaZfJopK X-Received: by 2002:a17:907:6e09:: with SMTP id sd9mr11891683ejc.259.1643597563999; Sun, 30 Jan 2022 18:52:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643597563; cv=none; d=google.com; s=arc-20160816; b=R3IZLWHcb4tdVXpt5/flgPIp6ovUYQQgnkY+NrEJUS3yI5H1tAwl+rMeEuSM+G52ms 5SPO5Tjp6vkbcpLv3kmct0yfv/urcGotR3EgJvAkbry3SXnZeC6T7T/3BtqDo2mCvwFs JtXENeQk6e7+sRT67Y0qnklkBi1m+LbIaMuAIgsrWSF9DC9a0rCDkP+sby5I3tab4T+T /quWPwTcrKXCC6I7iT0oxnzuaAI+6MA1gJ+zCsYbVk3P1V2kH2lQfuHRAPGgj4vss8rV ukewHuAUrxfkH06n8ucQU+KSMKef3n6fhFBUSMPxFWHKsCBne1Nz64ea1/I45k/A8EXZ HOTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=5ZnnKK4lyRFbdYdMV44O8d6xk7WoVOi45h9RZoqvpzs=; b=vpQWFMVMzShvFAH5PwEDHsRmeXWZEEJwbCUaZZsG4GGTg1CU0/UPxGDhzguQVILQWE AKZ4ynL09naNUnUL94IdKX5nVm6QBnaTn5WiD5hPb1aHUhubUC2WIq3heaLWHoua8CW7 rWq11+rj9vNkuIHJWMmnXHziw0k4Vn1apqM0zdZVb5i2jqyWFlKkhLAEurmPP91RwksN Najibxe4KjkvvclOc61d1hDFRGA2b4o3rSaKzKnoYqWCFNeuVvtj7eS+J6yPzQcvoDhX eiiJyiQa4aWVlcJdImJXguxYCI6KLA+0saxOSgmMipv/CAvJwmpzEOcDPGDaAjJna5sz wLzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mz20xJUR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id b8si6340230ejl.928.2022.01.30.18.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 18:52:43 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mz20xJUR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 874788366A; Mon, 31 Jan 2022 03:52:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.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=linaro.org header.i=@linaro.org header.b="Mz20xJUR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7F095833A2; Mon, 31 Jan 2022 03:52:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 095FB833BE for ; Mon, 31 Jan 2022 03:52:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masami.hiramatsu@linaro.org Received: by mail-pj1-x102d.google.com with SMTP id h12so12551394pjq.3 for ; Sun, 30 Jan 2022 18:52:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=5ZnnKK4lyRFbdYdMV44O8d6xk7WoVOi45h9RZoqvpzs=; b=Mz20xJURs4LSfeWwWrNQtuvCq5YgUUjtGscQXiNK7XCElFVFhLXe7QKtkhxw/EXzWs ypqUNWx4/DKaVsEqpIBb4AjMOp1wA60IRCyr1hbu+B7kVAPktJ5IFPIY20umeUT5Stp9 zPw68EHL+tduu5tsqviFMTxzDK9ywZZDcuTgvmYCRu0cEGzBzhWzvA7hPs8+2d+BcvSr kCom++nex1f5HZyqLx+dvhNFVBjUBKZt5f7KlmN3B20btKStyRuXdkp7spPNkJte5/OG K8MWPbp2K+z+XhSU8fowdgDFaYF2PKT2zMo0tvXcDbBJGsGOiftIhO/BvcBdkBVedWj2 gJkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=5ZnnKK4lyRFbdYdMV44O8d6xk7WoVOi45h9RZoqvpzs=; b=GyxJUb+6q1duMegxQTVzbIXQie2MpOwo/G7WB8FCd+MSZLPExjCp5BmGH3PNxIhkB7 mxHYmFqoj9qjbIofwhzj/FRXsQAiMSgKydN1to4g/hdAOwZXV13XKWWojl7VKjltyF48 dyXVZbP3eYgKEfgfcEKO0NQ2xq1M1zQcvFlT7EbrtfK/6k2Heeb6su/AYDFZtXpcedJw DGuoqvnfy7/s9YgyIEzlAgbhR3306jFjTvPwLKJ/rla8jpedWnzITFLX3oJTtyGzedle 9IJ54Usd5VkTEbvajOdfYfPZlWbRUrcNXGOXWdsCBDga0iUN6fqWqdqQPFLqf87qXWso x/ug== X-Gm-Message-State: AOAM531fGygY3PUnOn2RzICjOqsActelXqT+2YZP3NfU58MBHx+21g+x 244BtfwLaP+unBEF01RG5yPMEA== X-Received: by 2002:a17:902:6948:: with SMTP id k8mr19237554plt.136.1643597552207; Sun, 30 Jan 2022 18:52:32 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id h19sm8739874pjv.38.2022.01.30.18.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 18:52:31 -0800 (PST) From: Masami Hiramatsu To: Tom Rini , Lukasz Majewski Cc: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, jaswinder.singh@linaro.org Subject: [PATCH v2 2/5] DFU: Accept redundant spaces and tabs in dfu_alt_info Date: Mon, 31 Jan 2022 11:52:29 +0900 Message-Id: <164359754906.280839.1412862787511934825.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164359753172.280839.8310577813724924540.stgit@localhost> References: <164359753172.280839.8310577813724924540.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 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 If dfu_alt_info has repeated spaces or tab (for indentation or readability), the dfu fails to parse it. For example, if dfu_alt_info="mtd nor1=image raw 100000 200000" (double spaces after "raw"), the image entity start address is '0' and the size '0x100000'. This is because the repeated space is not skipped. Use space and tab as a separater and apply skip_spaces() to skip redundant spaces and tabs. Signed-off-by: Masami Hiramatsu --- drivers/dfu/dfu.c | 6 ++++-- drivers/dfu/dfu_mmc.c | 11 ++++++++--- drivers/dfu/dfu_mtd.c | 8 ++++++-- drivers/dfu/dfu_nand.c | 11 ++++++++--- drivers/dfu/dfu_ram.c | 3 ++- drivers/dfu/dfu_sf.c | 12 +++++++++--- 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index 66c41b5e76..18154774f9 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -123,9 +123,10 @@ int dfu_config_interfaces(char *env) s = env; while (s) { ret = -EINVAL; - i = strsep(&s, " "); + i = strsep(&s, " \t"); if (!i) break; + s = skip_spaces(s); d = strsep(&s, "="); if (!d) break; @@ -502,8 +503,9 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt, char *st; debug("%s: %s interface: %s dev: %s\n", __func__, s, interface, devstr); - st = strsep(&s, " "); + st = strsep(&s, " \t"); strlcpy(dfu->name, st, DFU_NAME_SIZE); + s = skip_spaces(s); dfu->alt = alt; dfu->max_buf_size = 0; diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index 3dab5a5f63..d747ede66c 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -351,11 +351,12 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) dfu->data.mmc.dev_num = dectoul(devstr, NULL); for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { - *parg = strsep(&s, " "); + *parg = strsep(&s, " \t"); if (*parg == NULL) { pr_err("Invalid number of arguments.\n"); return -ENODEV; } + s = skip_spaces(s); } entity_type = argv[0]; @@ -390,9 +391,11 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) * specifying the mmc HW defined partition number */ if (s) - if (!strcmp(strsep(&s, " "), "mmcpart")) + if (!strcmp(strsep(&s, " \t"), "mmcpart")) { + s = skip_spaces(s); dfu->data.mmc.hw_partition = simple_strtoul(s, NULL, 0); + } } else if (!strcmp(entity_type, "part")) { struct disk_partition partinfo; @@ -412,8 +415,10 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) * specifying the mmc HW defined partition number */ if (s) - if (!strcmp(strsep(&s, " "), "offset")) + if (!strcmp(strsep(&s, " \t"), "offset")) { + s = skip_spaces(s); offset = simple_strtoul(s, NULL, 0); + } dfu->layout = DFU_RAW_ADDR; dfu->data.mmc.lba_start = partinfo.start + offset; diff --git a/drivers/dfu/dfu_mtd.c b/drivers/dfu/dfu_mtd.c index cce9ce0845..27c011f537 100644 --- a/drivers/dfu/dfu_mtd.c +++ b/drivers/dfu/dfu_mtd.c @@ -12,6 +12,7 @@ #include #include #include +#include static bool mtd_is_aligned_with_block_size(struct mtd_info *mtd, u64 size) { @@ -285,11 +286,14 @@ int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char *s) dfu->data.mtd.info = mtd; dfu->max_buf_size = mtd->erasesize; - st = strsep(&s, " "); + st = strsep(&s, " \t"); + s = skip_spaces(s); if (!strcmp(st, "raw")) { dfu->layout = DFU_RAW_ADDR; dfu->data.mtd.start = hextoul(s, &s); - s++; + if (!isspace(*s)) + return -1; + s = skip_spaces(s); dfu->data.mtd.size = hextoul(s, &s); } else if ((!strcmp(st, "part")) || (!strcmp(st, "partubi"))) { char mtd_id[32]; diff --git a/drivers/dfu/dfu_nand.c b/drivers/dfu/dfu_nand.c index e53b35e42b..76761939ab 100644 --- a/drivers/dfu/dfu_nand.c +++ b/drivers/dfu/dfu_nand.c @@ -201,11 +201,14 @@ int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s) dfu->data.nand.ubi = 0; dfu->dev_type = DFU_DEV_NAND; - st = strsep(&s, " "); + st = strsep(&s, " \t"); + s = skip_spaces(s); if (!strcmp(st, "raw")) { dfu->layout = DFU_RAW_ADDR; dfu->data.nand.start = hextoul(s, &s); - s++; + if (!isspace(*s)) + return -1; + s = skip_spaces(s); dfu->data.nand.size = hextoul(s, &s); } else if ((!strcmp(st, "part")) || (!strcmp(st, "partubi"))) { char mtd_id[32]; @@ -216,7 +219,9 @@ int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s) dfu->layout = DFU_RAW_ADDR; dev = dectoul(s, &s); - s++; + if (!isspace(*s)) + return -1; + s = skip_spaces(s); part = dectoul(s, &s); sprintf(mtd_id, "%s%d,%d", "nand", dev, part - 1); diff --git a/drivers/dfu/dfu_ram.c b/drivers/dfu/dfu_ram.c index cc7e45ba33..361a3ff8af 100644 --- a/drivers/dfu/dfu_ram.c +++ b/drivers/dfu/dfu_ram.c @@ -60,11 +60,12 @@ int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s) const char **parg = argv; for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { - *parg = strsep(&s, " "); + *parg = strsep(&s, " \t"); if (*parg == NULL) { pr_err("Invalid number of arguments.\n"); return -ENODEV; } + s = skip_spaces(s); } dfu->dev_type = DFU_DEV_RAM; diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c index b72493ced8..993e951bc3 100644 --- a/drivers/dfu/dfu_sf.c +++ b/drivers/dfu/dfu_sf.c @@ -13,6 +13,7 @@ #include #include #include +#include static int dfu_get_medium_size_sf(struct dfu_entity *dfu, u64 *size) { @@ -178,11 +179,14 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s) dfu->dev_type = DFU_DEV_SF; dfu->max_buf_size = dfu->data.sf.dev->sector_size; - st = strsep(&s, " "); + st = strsep(&s, " \t"); + s = skip_spaces(s); if (!strcmp(st, "raw")) { dfu->layout = DFU_RAW_ADDR; dfu->data.sf.start = hextoul(s, &s); - s++; + if (!isspace(*s)) + return -1; + s = skip_spaces(s); dfu->data.sf.size = hextoul(s, &s); } else if (CONFIG_IS_ENABLED(DFU_SF_PART) && (!strcmp(st, "part") || !strcmp(st, "partubi"))) { @@ -195,7 +199,9 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s) dfu->layout = DFU_RAW_ADDR; dev = dectoul(s, &s); - s++; + if (!isspace(*s)) + return -1; + s = skip_spaces(s); part = dectoul(s, &s); sprintf(mtd_id, "%s%d,%d", "nor", dev, part - 1); From patchwork Mon Jan 31 02:52:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 538475 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp1405734imr; Sun, 30 Jan 2022 18:52:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJwoLErw/5ZnTU83cwGbpbD02CbD1ob7AjQDaQK28GDne1C2blb3ZGPz2pHPta3dlPwWNamg X-Received: by 2002:a17:907:6e0e:: with SMTP id sd14mr15580652ejc.274.1643597574282; Sun, 30 Jan 2022 18:52:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643597574; cv=none; d=google.com; s=arc-20160816; b=eFEwClbsPDKIHi+8fmMz9wRQjUyvIAKV5GVEEBdGcAJr5sCa/G1atD0NNO21ZYh8IC ILtroLG1hfXl26GTU2WIp6i+ZF4ObNB+JkelQ7iErb4IcWgb+fZMJcH4WYEtLQYT5NOC gAQN7qwuMkDy3Iu2F23nwfx+iMMNcfzlrcjZ8Vfi8xGubijZNI5h9wczF7bfLu5rVLaK LC3M5S9k8hdmCwrZln/qm6amac0tqABH75VVUNTyIsg23ZHGw1tTLrnI7R14L4bB38gB P95NiM8sdsTB5HIceGZkkontPY77jjtr7J+AdANOupCOy2+pyXsHRHa53jby0oiJbrum c44Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=dCp2iG006IZc1O+TufYhLXV9TMlDS6DxMUCA3W9PwjU=; b=VIec+IBonqrTbUVtLoF9WUaZXBlv+gRSh8wWz7mNVhSU5pnD0vwWbmUR3jW5EAoys4 qrFJNaZrzY0nGMZoPB+F3Rl7yT8nnpzPk2wnczNfMoEy/MIALDUyEBa0LKiHI1kbrPeL CI+NORVzWRkHcBdNvIVQ4ePdW1qa5XHsKaVVRiYdbxp1HCx3tv+LnWJe8yLXJtjgmKMq Lgf38UBVDaEcGIHdyF9cqR/OqxxUvqddmQ7NeQrjsw1O1ZBcJvChJaP4pRyrJx4MRIS9 lElCcDNQ4EHNxHVNGuzjx0Pv2fLKkIkdmDhWkXKKBjV4QR0yyMrDIA8ZdaOly3TcWzlR mvyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rOzj8vvi; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 24si8349318edv.621.2022.01.30.18.52.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 18:52:54 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rOzj8vvi; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CAE91836A4; Mon, 31 Jan 2022 03:52:48 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.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=linaro.org header.i=@linaro.org header.b="rOzj8vvi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C99A7836A3; Mon, 31 Jan 2022 03:52:46 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4212D833BE for ; Mon, 31 Jan 2022 03:52:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masami.hiramatsu@linaro.org Received: by mail-pl1-x630.google.com with SMTP id d18so11304110plg.2 for ; Sun, 30 Jan 2022 18:52:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=dCp2iG006IZc1O+TufYhLXV9TMlDS6DxMUCA3W9PwjU=; b=rOzj8vviQqNJP4IZjBDeHbQQmf8VO+BeRqyTguzK5XzMpujifNlDtTqOuXTPeyYjwA IOtagBFvF9J4731Rv6JJuPLj5nN9mHYaEbIjuIGg+qsQpHez1z6Dz/AFoSlDpIohTFSA CAoQhFMtKPs8Wk7QJcw5L+jqGGnduBvqLAN9Eu6b6GZAAq4XLCLcRHbc5CUIh3V4n2yR Rcjp1R11R9seNLOR7OZKIuziQH91+3WG+vXy424XfqYznF+n0qYStlrFrwTJQykxjQhz R3v8U5/wrR6rORA32z6iDyJ3UD6Vg6UZhDnHedeSbGENbqG9zS/8M+lsISUnX/OcuErL P7MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=dCp2iG006IZc1O+TufYhLXV9TMlDS6DxMUCA3W9PwjU=; b=GrEcHZrhSs7Zosyzd4nZ0EdqgBN03vq13OBzreNmA0BnJhWkN2klGuykHq5AyizGHm BBlJKnA6KNOnDeMjEwDAze84bYsWAEhJAB7Ls7fPePBZ2Y5BIuWJON8mi/MTDrTQ33Xk jQuZxKtJ5/V4e4eRU5FoTuuR3t2PbiSGVn9gnobzW1bcF3tAgnTDPW1DzZLLbIY7duzH uU8WYCiSKesJZSlTby8KdDmsxcSxUz+E/ly10cvtHSXZDDj6ONg5TcjVLhKnQoMruPEh ZBZxleiVCZhHs1WO92Wt3FzlcWgfq9v3/J9uOQJqMI1xpC33BknvE+41pi3ihiXNNkB1 n3cw== X-Gm-Message-State: AOAM533ExVNvZMiv56Eg6DgSOGzd4BSTEzzCCHF54wa/lfPh9cP9jj8i YvNugp8CZ6IF+d2B+hHWJzGA+g== X-Received: by 2002:a17:902:e842:: with SMTP id t2mr19575031plg.69.1643597560588; Sun, 30 Jan 2022 18:52:40 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id h6sm16723601pfc.35.2022.01.30.18.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 18:52:40 -0800 (PST) From: Masami Hiramatsu To: Tom Rini , Lukasz Majewski Cc: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, jaswinder.singh@linaro.org Subject: [PATCH v2 3/5] DFU: Check the number of arguments and argument string strictly Date: Mon, 31 Jan 2022 11:52:37 +0900 Message-Id: <164359755758.280839.2217137492784656400.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164359753172.280839.8310577813724924540.stgit@localhost> References: <164359753172.280839.8310577813724924540.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 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 When parsing the dfu_alt_info, check the number of arguments and argument string strictly. If there is any garbage data (which is not able to be parsed correctly) in dfu_alt_info, that means something wrong and user may make a typo or mis- understanding about the syntax. Since the dfu_alt_info is used for updating the firmware, this mistake may lead to brick the hardware. Thus it should be checked strictly for making sure there is no mistake. Signed-off-by: Masami Hiramatsu --- drivers/dfu/dfu.c | 31 +++++++++++++++++++++------ drivers/dfu/dfu_mmc.c | 56 ++++++++++++++++++++++++++---------------------- drivers/dfu/dfu_mtd.c | 36 +++++++++++++++++++------------ drivers/dfu/dfu_nand.c | 39 ++++++++++++++++++--------------- drivers/dfu/dfu_ram.c | 25 ++++++++++----------- drivers/dfu/dfu_sf.c | 38 +++++++++++++++++---------------- drivers/dfu/dfu_virt.c | 5 +++- include/dfu.h | 33 ++++++++++++++++++---------- 8 files changed, 154 insertions(+), 109 deletions(-) diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index 18154774f9..516dda6179 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -500,12 +500,29 @@ int dfu_read(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt, char *interface, char *devstr) { + char *argv[DFU_MAX_ENTITY_ARGS]; + int argc; char *st; debug("%s: %s interface: %s dev: %s\n", __func__, s, interface, devstr); st = strsep(&s, " \t"); strlcpy(dfu->name, st, DFU_NAME_SIZE); - s = skip_spaces(s); + + /* Parse arguments */ + for (argc = 0; s && argc < DFU_MAX_ENTITY_ARGS; argc++) { + s = skip_spaces(s); + if (!*s) + break; + argv[argc] = strsep(&s, " \t"); + } + + if (argc == DFU_MAX_ENTITY_ARGS && s) { + s = skip_spaces(s); + if (*s) { + log_err("Too many arguments for %s\n", dfu->name); + return -EINVAL; + } + } dfu->alt = alt; dfu->max_buf_size = 0; @@ -513,22 +530,22 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt, /* Specific for mmc device */ if (strcmp(interface, "mmc") == 0) { - if (dfu_fill_entity_mmc(dfu, devstr, s)) + if (dfu_fill_entity_mmc(dfu, devstr, argv, argc)) return -1; } else if (strcmp(interface, "mtd") == 0) { - if (dfu_fill_entity_mtd(dfu, devstr, s)) + if (dfu_fill_entity_mtd(dfu, devstr, argv, argc)) return -1; } else if (strcmp(interface, "nand") == 0) { - if (dfu_fill_entity_nand(dfu, devstr, s)) + if (dfu_fill_entity_nand(dfu, devstr, argv, argc)) return -1; } else if (strcmp(interface, "ram") == 0) { - if (dfu_fill_entity_ram(dfu, devstr, s)) + if (dfu_fill_entity_ram(dfu, devstr, argv, argc)) return -1; } else if (strcmp(interface, "sf") == 0) { - if (dfu_fill_entity_sf(dfu, devstr, s)) + if (dfu_fill_entity_sf(dfu, devstr, argv, argc)) return -1; } else if (strcmp(interface, "virt") == 0) { - if (dfu_fill_entity_virt(dfu, devstr, s)) + if (dfu_fill_entity_virt(dfu, devstr, argv, argc)) return -1; } else { printf("%s: Device %s not (yet) supported!\n", diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index d747ede66c..a91da972d4 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -337,35 +337,34 @@ void dfu_free_entity_mmc(struct dfu_entity *dfu) * 4th (optional): * mmcpart (access to HW eMMC partitions) */ -int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) +int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char **argv, int argc) { const char *entity_type; ssize_t second_arg; size_t third_arg; - struct mmc *mmc; + char *s; - const char *argv[3]; - const char **parg = argv; - - dfu->data.mmc.dev_num = dectoul(devstr, NULL); - - for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { - *parg = strsep(&s, " \t"); - if (*parg == NULL) { - pr_err("Invalid number of arguments.\n"); - return -ENODEV; - } - s = skip_spaces(s); + if (argc < 3) { + pr_err("The number of parameters are not enough.\n"); + return -EINVAL; } + dfu->data.mmc.dev_num = dectoul(devstr, &s); + if (*s) + return -EINVAL; + entity_type = argv[0]; /* * Base 0 means we'll accept (prefixed with 0x or 0) base 16, 8, * with default 10. */ - second_arg = simple_strtol(argv[1], NULL, 0); - third_arg = simple_strtoul(argv[2], NULL, 0); + second_arg = simple_strtol(argv[1], &s, 0); + if (*s) + return -EINVAL; + third_arg = simple_strtoul(argv[2], &s, 0); + if (*s) + return -EINVAL; mmc = find_mmc_device(dfu->data.mmc.dev_num); if (mmc == NULL) { @@ -390,12 +389,14 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) * Check for an extra entry at dfu_alt_info env variable * specifying the mmc HW defined partition number */ - if (s) - if (!strcmp(strsep(&s, " \t"), "mmcpart")) { - s = skip_spaces(s); - dfu->data.mmc.hw_partition = - simple_strtoul(s, NULL, 0); + if (argc > 3) { + if (argc != 5 || strcmp(argv[3], "mmcpart")) { + pr_err("DFU mmc raw accept 'mmcpart ' option.\n"); + return -EINVAL; } + dfu->data.mmc.hw_partition = + simple_strtoul(argv[4], NULL, 0); + } } else if (!strcmp(entity_type, "part")) { struct disk_partition partinfo; @@ -414,15 +415,18 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) * Check for an extra entry at dfu_alt_info env variable * specifying the mmc HW defined partition number */ - if (s) - if (!strcmp(strsep(&s, " \t"), "offset")) { - s = skip_spaces(s); - offset = simple_strtoul(s, NULL, 0); + if (argc > 3) { + if (argc != 5 || strcmp(argv[3], "offset")) { + pr_err("DFU mmc raw accept 'mmcpart ' option.\n"); + return -EINVAL; } + dfu->data.mmc.hw_partition = + simple_strtoul(argv[4], NULL, 0); + } dfu->layout = DFU_RAW_ADDR; dfu->data.mmc.lba_start = partinfo.start + offset; - dfu->data.mmc.lba_size = partinfo.size-offset; + dfu->data.mmc.lba_size = partinfo.size - offset; dfu->data.mmc.lba_blk_size = partinfo.blksz; } else if (!strcmp(entity_type, "fat")) { dfu->layout = DFU_FS_FAT; diff --git a/drivers/dfu/dfu_mtd.c b/drivers/dfu/dfu_mtd.c index 27c011f537..c7075f12ec 100644 --- a/drivers/dfu/dfu_mtd.c +++ b/drivers/dfu/dfu_mtd.c @@ -271,9 +271,9 @@ static unsigned int dfu_polltimeout_mtd(struct dfu_entity *dfu) return DFU_DEFAULT_POLL_TIMEOUT; } -int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char *s) +int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char **argv, int argc) { - char *st; + char *s; struct mtd_info *mtd; int ret, part; @@ -285,25 +285,33 @@ int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char *s) dfu->dev_type = DFU_DEV_MTD; dfu->data.mtd.info = mtd; dfu->max_buf_size = mtd->erasesize; + if (argc < 1) + return -EINVAL; - st = strsep(&s, " \t"); - s = skip_spaces(s); - if (!strcmp(st, "raw")) { + if (!strcmp(argv[0], "raw")) { + if (argc != 3) + return -EINVAL; dfu->layout = DFU_RAW_ADDR; - dfu->data.mtd.start = hextoul(s, &s); - if (!isspace(*s)) - return -1; - s = skip_spaces(s); - dfu->data.mtd.size = hextoul(s, &s); - } else if ((!strcmp(st, "part")) || (!strcmp(st, "partubi"))) { + dfu->data.mtd.start = hextoul(argv[1], &s); + if (*s) + return -EINVAL; + dfu->data.mtd.size = hextoul(argv[2], &s); + if (*s) + return -EINVAL; + } else if ((!strcmp(argv[0], "part")) || (!strcmp(argv[0], "partubi"))) { char mtd_id[32]; struct mtd_device *mtd_dev; u8 part_num; struct part_info *pi; + if (argc != 2) + return -EINVAL; + dfu->layout = DFU_RAW_ADDR; - part = dectoul(s, &s); + part = dectoul(argv[1], &s); + if (*s) + return -EINVAL; sprintf(mtd_id, "%s,%d", devstr, part - 1); printf("using id '%s'\n", mtd_id); @@ -318,10 +326,10 @@ int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char *s) dfu->data.mtd.start = pi->offset; dfu->data.mtd.size = pi->size; - if (!strcmp(st, "partubi")) + if (!strcmp(argv[0], "partubi")) dfu->data.mtd.ubi = 1; } else { - printf("%s: Memory layout (%s) not supported!\n", __func__, st); + printf("%s: Memory layout (%s) not supported!\n", __func__, argv[0]); return -1; } diff --git a/drivers/dfu/dfu_nand.c b/drivers/dfu/dfu_nand.c index 76761939ab..08e8cf5cdb 100644 --- a/drivers/dfu/dfu_nand.c +++ b/drivers/dfu/dfu_nand.c @@ -194,23 +194,25 @@ unsigned int dfu_polltimeout_nand(struct dfu_entity *dfu) return DFU_DEFAULT_POLL_TIMEOUT; } -int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s) +int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char **argv, int argc) { - char *st; + char *s; int ret, dev, part; dfu->data.nand.ubi = 0; dfu->dev_type = DFU_DEV_NAND; - st = strsep(&s, " \t"); - s = skip_spaces(s); - if (!strcmp(st, "raw")) { + if (argc != 3) + return -EINVAL; + + if (!strcmp(argv[0], "raw")) { dfu->layout = DFU_RAW_ADDR; - dfu->data.nand.start = hextoul(s, &s); - if (!isspace(*s)) - return -1; - s = skip_spaces(s); - dfu->data.nand.size = hextoul(s, &s); - } else if ((!strcmp(st, "part")) || (!strcmp(st, "partubi"))) { + dfu->data.nand.start = hextoul(argv[1], &s); + if (*s) + return -EINVAL; + dfu->data.nand.size = hextoul(argv[2], &s); + if (*s) + return -EINVAL; + } else if ((!strcmp(argv[0], "part")) || (!strcmp(argv[0], "partubi"))) { char mtd_id[32]; struct mtd_device *mtd_dev; u8 part_num; @@ -218,11 +220,12 @@ int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s) dfu->layout = DFU_RAW_ADDR; - dev = dectoul(s, &s); - if (!isspace(*s)) - return -1; - s = skip_spaces(s); - part = dectoul(s, &s); + dev = dectoul(argv[1], &s); + if (*s) + return -EINVAL; + part = dectoul(argv[2], &s); + if (*s) + return -EINVAL; sprintf(mtd_id, "%s%d,%d", "nand", dev, part - 1); debug("using id '%s'\n", mtd_id); @@ -237,10 +240,10 @@ int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s) dfu->data.nand.start = pi->offset; dfu->data.nand.size = pi->size; - if (!strcmp(st, "partubi")) + if (!strcmp(argv[0], "partubi")) dfu->data.nand.ubi = 1; } else { - printf("%s: Memory layout (%s) not supported!\n", __func__, st); + printf("%s: Memory layout (%s) not supported!\n", __func__, argv[0]); return -1; } diff --git a/drivers/dfu/dfu_ram.c b/drivers/dfu/dfu_ram.c index 361a3ff8af..9d10303164 100644 --- a/drivers/dfu/dfu_ram.c +++ b/drivers/dfu/dfu_ram.c @@ -54,18 +54,13 @@ static int dfu_read_medium_ram(struct dfu_entity *dfu, u64 offset, return dfu_transfer_medium_ram(DFU_OP_READ, dfu, offset, buf, len); } -int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s) +int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char **argv, int argc) { - const char *argv[3]; - const char **parg = argv; - - for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { - *parg = strsep(&s, " \t"); - if (*parg == NULL) { - pr_err("Invalid number of arguments.\n"); - return -ENODEV; - } - s = skip_spaces(s); + char *s; + + if (argc != 3) { + pr_err("Invalid number of arguments.\n"); + return -EINVAL; } dfu->dev_type = DFU_DEV_RAM; @@ -75,8 +70,12 @@ int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s) } dfu->layout = DFU_RAM_ADDR; - dfu->data.ram.start = hextoul(argv[1], NULL); - dfu->data.ram.size = hextoul(argv[2], NULL); + dfu->data.ram.start = hextoul(argv[1], &s); + if (*s) + return -EINVAL; + dfu->data.ram.size = hextoul(argv[2], &s); + if (*s) + return -EINVAL; dfu->write_medium = dfu_write_medium_ram; dfu->get_medium_size = dfu_get_medium_size_ram; diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c index 993e951bc3..25a9c81850 100644 --- a/drivers/dfu/dfu_sf.c +++ b/drivers/dfu/dfu_sf.c @@ -166,9 +166,9 @@ static struct spi_flash *parse_dev(char *devstr) return dev; } -int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s) +int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char **argv, int argc) { - char *st; + char *s; char *devstr_bkup = strdup(devstr); dfu->data.sf.dev = parse_dev(devstr_bkup); @@ -179,17 +179,18 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s) dfu->dev_type = DFU_DEV_SF; dfu->max_buf_size = dfu->data.sf.dev->sector_size; - st = strsep(&s, " \t"); - s = skip_spaces(s); - if (!strcmp(st, "raw")) { + if (argc != 3) + return -EINVAL; + if (!strcmp(argv[0], "raw")) { dfu->layout = DFU_RAW_ADDR; - dfu->data.sf.start = hextoul(s, &s); - if (!isspace(*s)) - return -1; - s = skip_spaces(s); - dfu->data.sf.size = hextoul(s, &s); + dfu->data.sf.start = hextoul(argv[1], &s); + if (*s) + return -EINVAL; + dfu->data.sf.size = hextoul(argv[2], &s); + if (*s) + return -EINVAL; } else if (CONFIG_IS_ENABLED(DFU_SF_PART) && - (!strcmp(st, "part") || !strcmp(st, "partubi"))) { + (!strcmp(argv[0], "part") || !strcmp(argv[0], "partubi"))) { char mtd_id[32]; struct mtd_device *mtd_dev; u8 part_num; @@ -198,11 +199,12 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s) dfu->layout = DFU_RAW_ADDR; - dev = dectoul(s, &s); - if (!isspace(*s)) - return -1; - s = skip_spaces(s); - part = dectoul(s, &s); + dev = dectoul(argv[1], &s); + if (*s) + return -EINVAL; + part = dectoul(argv[2], &s); + if (*s) + return -EINVAL; sprintf(mtd_id, "%s%d,%d", "nor", dev, part - 1); printf("using id '%s'\n", mtd_id); @@ -216,10 +218,10 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s) } dfu->data.sf.start = pi->offset; dfu->data.sf.size = pi->size; - if (!strcmp(st, "partubi")) + if (!strcmp(argv[0], "partubi")) dfu->data.sf.ubi = 1; } else { - printf("%s: Memory layout (%s) not supported!\n", __func__, st); + printf("%s: Memory layout (%s) not supported!\n", __func__, argv[0]); spi_flash_free(dfu->data.sf.dev); return -1; } diff --git a/drivers/dfu/dfu_virt.c b/drivers/dfu/dfu_virt.c index 80c99cb06e..29f7a08f67 100644 --- a/drivers/dfu/dfu_virt.c +++ b/drivers/dfu/dfu_virt.c @@ -32,10 +32,13 @@ int __weak dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset, return 0; } -int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, char *s) +int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, char **argv, int argc) { debug("%s: devstr = %s\n", __func__, devstr); + if (argc != 0) + return -EINVAL; + dfu->dev_type = DFU_DEV_VIRT; dfu->layout = DFU_RAW_ADDR; dfu->data.virt.dev_num = dectoul(devstr, NULL); diff --git a/include/dfu.h b/include/dfu.h index f6868982df..dcb9cd9d79 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -432,11 +432,15 @@ static inline void dfu_set_defer_flush(struct dfu_entity *dfu) int dfu_write_from_mem_addr(struct dfu_entity *dfu, void *buf, int size); /* Device specific */ +/* Each entity has 5 arguments in maximum. */ +#define DFU_MAX_ENTITY_ARGS 5 + #if CONFIG_IS_ENABLED(DFU_MMC) -extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s); +extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, + char **argv, int argc); #else static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, - char *s) + char **argv, int argc) { puts("MMC support not available!\n"); return -1; @@ -444,10 +448,11 @@ static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, #endif #if CONFIG_IS_ENABLED(DFU_NAND) -extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s); +extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, + char **argv, int argc); #else static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, - char *s) + char **argv, int argc) { puts("NAND support not available!\n"); return -1; @@ -455,10 +460,11 @@ static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, #endif #if CONFIG_IS_ENABLED(DFU_RAM) -extern int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s); +extern int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, + char **argv, int argc); #else static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, - char *s) + char **argv, int argc) { puts("RAM support not available!\n"); return -1; @@ -466,10 +472,11 @@ static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, #endif #if CONFIG_IS_ENABLED(DFU_SF) -extern int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s); +extern int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, + char **argv, int argc); #else static inline int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, - char *s) + char **argv, int argc) { puts("SF support not available!\n"); return -1; @@ -477,10 +484,11 @@ static inline int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, #endif #if CONFIG_IS_ENABLED(DFU_MTD) -int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char *s); +extern int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, + char **argv, int argc); #else static inline int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, - char *s) + char **argv, int argc) { puts("MTD support not available!\n"); return -1; @@ -488,7 +496,8 @@ static inline int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, #endif #ifdef CONFIG_DFU_VIRT -int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, char *s); +int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, + char **argv, int argc); int dfu_write_medium_virt(struct dfu_entity *dfu, u64 offset, void *buf, long *len); int dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size); @@ -496,7 +505,7 @@ int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset, void *buf, long *len); #else static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, - char *s) + char **argv, int argc) { puts("VIRT support not available!\n"); return -1; From patchwork Mon Jan 31 02:52:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 538476 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp1405816imr; Sun, 30 Jan 2022 18:53:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuIaiAVJQjbGzdsOwRrRZnEPNo4gs9TiIn9aZ5Vhqc9UcO/2E8pVzTR2mE2fRrtXW0T4SM X-Received: by 2002:a17:906:2dd1:: with SMTP id h17mr15235735eji.113.1643597586064; Sun, 30 Jan 2022 18:53:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643597586; cv=none; d=google.com; s=arc-20160816; b=J/Vc5nW/JC+aXdVVz1PI0djBveZZuUY3EqrXP5yhTB7WQ5sfjfuQl4+FeGyORxxSZz tWdUchIsX7EwitC0KPFSkpnRRkIXYdtz7JquKaLctPYsvqCT8oMBWBOEk5v2zX0HvTKC uyygVvi92ntl6drB61smiDqtWPfD0SQh4Bb9ICnB6qNT0hBmQY50H8SWC7YTPlh65Yj8 1HvgdTQ9Y7f77ZK0QeIVUlmwVdsmYoN97+CQ6jsRrEqfM/bNIorwlIWIzlFD8q2h/JPI nux85LjijnjHgR5yccslziMl0ir9foHNz/3aN3Kt6ila7G6aBJALQ/s7b3GbOMElYuAX yeTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=CLqRMktc+XAN1vyHP67n8zLu6z9KiN8YVEfbtM81pvs=; b=UKdNe51EdV7hHMk+/Rooca75BelklP7BfSBvqsZAjDOCDQ3EDKJt85MNy6hYJGjJQg LRkFl4gftNHXH6fBs5bEwu+CoDdR1h82/zMDWsQ0/1n2IpcQE+dnMCzDotsV+HgHxiXb CeK8VRzfD8PWYtpDe08idlW2G/+bxuUnrn4w7XjMVcdqhkNKIttHu2KBu8RShgv1CJ5K skg8QnG+Sbex0NN7CevY0gBrt/xUKxW2o1sq34LJv3gqjdoGBJ6XURr9MePeUMs589jM btelKabx8ox6Nqqx718pzeiaLR00GQuvqeK9LJIlnsoceqDDYbCdwKK1anSDRCsB/S1K Ju8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ypFwy92X; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id y13si9944586edc.413.2022.01.30.18.53.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 18:53:06 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ypFwy92X; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 56F9F83678; Mon, 31 Jan 2022 03:52:55 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.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=linaro.org header.i=@linaro.org header.b="ypFwy92X"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5C711836A8; Mon, 31 Jan 2022 03:52:54 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8B38F836A3 for ; Mon, 31 Jan 2022 03:52:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masami.hiramatsu@linaro.org Received: by mail-pj1-x1036.google.com with SMTP id o16-20020a17090aac1000b001b62f629953so9497635pjq.3 for ; Sun, 30 Jan 2022 18:52:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=CLqRMktc+XAN1vyHP67n8zLu6z9KiN8YVEfbtM81pvs=; b=ypFwy92X/RqkeHZeB+m4qFtZGxB3yeHCq3PnnNHKh0Nh3OhFzVAZNM+wfE7XmAp4Y1 +9YH2vSA8xsYUq2Sw+EnWx3aNNnTWf8yyIWnGiPTC6YEW4YOi6ELsGgy5XY5rjn15kiC PbeaHPKNScDCodIhSkeNG0bjL8LhwtKFunr4iZbr0WFvuu4vr51MaJ1Pn2S9Blj7n+rO 2//rY72cRjoulf04jpWhaNdNc+5GQUtC1oUBGxlv1x49/BdO4MNtp08UE3FK9Hz73X44 e1q1jjnApXVJZlpWwuM88zNq+khC2jS8YIYzLwYv4eDGF46/wAsWgqTV7nZJKJTDrsb2 CdGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=CLqRMktc+XAN1vyHP67n8zLu6z9KiN8YVEfbtM81pvs=; b=OPno6cF8MkpuCU/VCRVh41oxqDRZwug2mWY1fOwdj2F207m4X4x4wS2u8zGw8SAPN0 qaZsWhBxlZ9ks5WZemQCzjM2ZLLLTf75qWxrEjRUTnUCM4pG3AqVrMHoH+UWyDVROoGa KVzqav9w0LWzORVpwHsBvUJh9u8KNB7nSeBveDNCbRimafjg9s+QYjXZ73v+FXE+5J0i JHnNBgVbt3At69EdTbWSMjac7tSHqGkrkPTwN9X1nweFJn/Z/TuL3ZfftY+hUuqoB5Pf X/Owf3JDMLxqE7VY4Wa5X4WDl5Nt5jqoW7GzKRqzxmi2BOi1vz45oQyYk18yUi3cC+W3 tNHw== X-Gm-Message-State: AOAM5312SMDJ7KW8j36weC8dNwvGxqtvpdLHas62TnJx4DlGK3qT5UUg iwUL3A9axc0XNKLq5xzfHvWnvQ== X-Received: by 2002:a17:90b:4d84:: with SMTP id oj4mr22027072pjb.192.1643597569010; Sun, 30 Jan 2022 18:52:49 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id f16sm17384059pfa.147.2022.01.30.18.52.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 18:52:48 -0800 (PST) From: Masami Hiramatsu To: Tom Rini , Lukasz Majewski Cc: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, jaswinder.singh@linaro.org Subject: [PATCH v2 4/5] doc: usage: DFU: Fix dfu_alt_info document Date: Mon, 31 Jan 2022 11:52:46 +0900 Message-Id: <164359756596.280839.6668664818943333738.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164359753172.280839.8310577813724924540.stgit@localhost> References: <164359753172.280839.8310577813724924540.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 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 Fix some typo and wrong information about dfu_alt_info. - Add the parameter format, decimal only or hexadecimal. - Use same parameter name for the same kind of parameters. (e.g. dev -> dev_id) Signed-off-by: Masami Hiramatsu --- doc/usage/dfu.rst | 57 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/doc/usage/dfu.rst b/doc/usage/dfu.rst index 11c88072b8..ed47ff561e 100644 --- a/doc/usage/dfu.rst +++ b/doc/usage/dfu.rst @@ -113,9 +113,9 @@ mmc each element in *dfu_alt_info* being * raw [mmcpart ] raw access to mmc device - * part [mmcpart ] raw access to partition - * fat [mmcpart ] file in FAT partition - * ext4 [mmcpart ] file in EXT4 partition + * part [offset ] raw access to partition + * fat file in FAT partition + * ext4 file in EXT4 partition * skip 0 0 ignore flashed data * script 0 0 execute commands in shell @@ -169,14 +169,20 @@ nand each element in *dfu_alt_info* being either of - * raw raw access to mmc device - * part raw acces to partition - * partubi raw acces to ubi partition + * raw raw access to nand device + * part raw access to partition + * partubi raw access to ubi partition with - partid - is the MTD partition index + offset + is the offset in the nand device (hexadecimal without "0x") + size + is the size of the access area (hexadecimal without "0x") + dev_id + is the NAND device index (decimal only) + part_id + is the NAND partition index (decimal only) ram raw access to ram:: @@ -190,6 +196,13 @@ ram ram raw access to ram + with + + offset + is the offset in the ram device (hexadecimal without "0x") + size + is the size of the access area (hexadecimal without "0x") + sf serial flash : NOR:: @@ -198,13 +211,19 @@ sf each element in *dfu_alt_info* being either of: * raw raw access to sf device - * part raw acces to partition - * partubi raw acces to ubi partition + * part raw acces to partition + * partubi raw acces to ubi partition with - partid - is the MTD partition index + offset + is the offset in the sf device (hexadecimal without "0x") + size + is the size of the access area (hexadecimal without "0x") + dev_id + is the sf device index (the device is "nor") (deximal only) + part_id + is the MTD partition index (decimal only) mtd all MTD device: NAND, SPI-NOR, SPI-NAND,...:: @@ -219,14 +238,18 @@ mtd each element in *dfu_alt_info* being either of: - * raw forraw access to mtd device - * part for raw acces to partition - * partubi for raw acces to ubi partition + * raw for raw access to mtd device + * part for raw access to partition + * partubi for raw access to ubi partition with - partid - is the MTD partition index + offset + is the offset in the mtd device (hexadecimal without "0x") + size + is the size of the access area (hexadecimal without "0x") + part_id + is the MTD partition index (decimal only) virt virtual flash back end for DFU From patchwork Mon Jan 31 02:52:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 538477 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp1405901imr; Sun, 30 Jan 2022 18:53:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSaTr5d3aCE4VemHxlLiSREWbr8c37lBs+hMNwPyqoaPqAkrzg+vVjV+okolkJwTIacs/q X-Received: by 2002:a17:906:4fcd:: with SMTP id i13mr14989803ejw.644.1643597597226; Sun, 30 Jan 2022 18:53:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643597597; cv=none; d=google.com; s=arc-20160816; b=K9CXZFVe6JV+4Yjv6ZhKJJkN/3JU0y4BIvfto5H3S+zC3JHW2bWVXqefdIBB0s4GCX l+95KWnbzjqDWQ7ihiKZs28fRybA82eGMjXN3i5UDZz1anwEMVL9PBp77+bsAMH38BPL qckXAgKPSUIwCuE+6EYSjb9RAer/SZcuMGNLE4hAhPPRE7agIIoLXolsUAmeSGfFi24J rVx9MYSH+jabqDQObhQPqqapKVfaMcuIYBdIpm953d57rpZ2AAvBAkDe7EIOhy7OLpMv eNdr6Cy7ucqduzqmDyM4OHreQxtmX6G/spAl2ydXjdZw13mNI4YI/2K4eGDsj8Xvnts3 hTuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=QixfSxC73opvidNTp3ooyYomH4KG6pzub50jFwg54aE=; b=FMJUvMwOZsUNoij/AMYnvUKj5u8q38jooj+58sEh2yTu943H+FvILMak5f2yPSmS3k kkZhnGiBXBnJDkWPCgcdhrXHHew8hveJxsO18sdG2spwLoZemN3lIHrilY37QHhHu5KL 4tg33+Al20BIi4R2nkDkDAGpHviv6Im2JfKnGaPaDzVn6I5SHljIvwcZUSDomn8VhKVU 2te0OhAw9wJ8UJL2lH/VXZcOf//cJ6MZtM6vnSR6t+jY/3LT38/IkSBMKr0SSoJmgOlk rCWzN0V5hYlnK/6iMGPDusOWXqUqtv8is6GoPeEYWWtdhkZF2Vx3uMsp+mDEJhEmAzVT MDCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NK0B0TTc; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id z21si7981447edb.187.2022.01.30.18.53.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 18:53:17 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NK0B0TTc; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BB69C836B8; Mon, 31 Jan 2022 03:53:06 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.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=linaro.org header.i=@linaro.org header.b="NK0B0TTc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 738FB836AC; Mon, 31 Jan 2022 03:53:05 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 21F80836BF for ; Mon, 31 Jan 2022 03:52:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masami.hiramatsu@linaro.org Received: by mail-pl1-x62f.google.com with SMTP id x11so11277681plg.6 for ; Sun, 30 Jan 2022 18:52:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=QixfSxC73opvidNTp3ooyYomH4KG6pzub50jFwg54aE=; b=NK0B0TTcwc85CFyTQHtpSITGciehe1Xx95L8lblR9Au4vn0crqt7MciKRQ/0jq3Eow yfUDd4Pdfvx33e3eJ9eXE1rMjJV2tbA7P/8UZHo5i7+y+To/qvCNOBvGWERHUhZHk6vJ DyWR7jfMVmiOK9dYiirxCeCs2GS7a7Zei9Ta22QxyljNtT/ygFVr9UN+N7ufctPMd9kC CuyJX7YhcooOG/sj7FXvs8AONYHYaKosh3qF4x77ZRWIzi8Y1y17vJbAAnPWHo04nWCB 335dsKihAn0S85DkqJkxiVmMY9X52UzUmroNf850jXB0rP5rLEP3Im9VSqY+47DH0bCT oisA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=QixfSxC73opvidNTp3ooyYomH4KG6pzub50jFwg54aE=; b=mj/wPZYgZBlTlV5fhWOcUs33qlryggFcE+BNT4Fj7f8T2NaqribOZotnvfIPNGTJaX Rhi5/lV5G+fYcdBLMBG7LgyvoaMzYLDllhOIUYLPRjPV/X0d0L7zydc/OGSTNcSytZVh rrrPFQ94eoMAbrGW1ABtyrYg78CFaRzpg970BTxEdwF6HfWunZz4qoCY8VcJuDGJEk48 lUZ6FkUpF4fZcv7eoPuwvgD70gt+cmmFPi5oFrWy7cs3Tulz15kt2lRhTKE9s7vKlCBB omrHCx3NHaZOTcPtOPcha1FkWhY44rKFl1K4KDgxpPjdyMqlfYm/EUlmSFt7sBmQk2WO LE6A== X-Gm-Message-State: AOAM532qc6rNMrjFRu/7pA8zSMxMKxyzIZwfpJMzJv/OqA4oUkzesGue So5jSZU5c9eCPw7W+Ztg+5DNwA== X-Received: by 2002:a17:903:124f:: with SMTP id u15mr18876408plh.15.1643597577430; Sun, 30 Jan 2022 18:52:57 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id h6sm16692961pfc.96.2022.01.30.18.52.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 18:52:57 -0800 (PST) From: Masami Hiramatsu To: Tom Rini , Lukasz Majewski Cc: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, jaswinder.singh@linaro.org Subject: [PATCH v2 5/5] cmd/dfu: Enable 'dfu list' command without DFU_OVER_USB Date: Mon, 31 Jan 2022 11:52:54 +0900 Message-Id: <164359757437.280839.2615214689304951773.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164359753172.280839.8310577813724924540.stgit@localhost> References: <164359753172.280839.8310577813724924540.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 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 Since dfu is not only used for USB, and some platform only supports DFU_OVER_TFTP or EFI capsule update, dfu_alt_info is defined on such platforms too. For such platform, 'dfu list' command is useful to check how the current dfu_alt_info setting is parsed. Signed-off-by: Masami Hiramatsu --- Changes in v2: Fix a compile error if CONFIG_DFU_OVER_USB=n && CONFIG_DFU_OVER_TFTP=n. --- cmd/dfu.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cmd/dfu.c b/cmd/dfu.c index 4a288f74c2..d7bfb535dc 100644 --- a/cmd/dfu.c +++ b/cmd/dfu.c @@ -28,7 +28,6 @@ static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) #ifdef CONFIG_DFU_OVER_USB char *usb_controller = argv[1]; #endif -#if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP) char *interface = NULL; char *devstring = NULL; #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP) @@ -42,7 +41,6 @@ static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP) if (argc == 5 || argc == 3) value = simple_strtoul(argv[argc - 1], NULL, 0); -#endif #endif int ret = 0; @@ -50,7 +48,6 @@ static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (!strcmp(argv[1], "tftp")) return update_tftp(value, interface, devstring); #endif -#ifdef CONFIG_DFU_OVER_USB ret = dfu_init_env_entities(interface, devstring); if (ret) goto done; @@ -65,6 +62,7 @@ static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) goto done; } +#ifdef CONFIG_DFU_OVER_USB int controller_index = simple_strtoul(usb_controller, NULL, 0); bool retry = false; do { @@ -79,9 +77,9 @@ static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } } while (retry); +#endif done: dfu_free_entities(); -#endif return ret; } @@ -100,8 +98,8 @@ U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, #ifdef CONFIG_DFU_TIMEOUT " [] - specify inactivity timeout in seconds\n" #endif - " [list] - list available alt settings\n" #endif + " [list] - list available alt settings\n" #ifdef CONFIG_DFU_OVER_TFTP #ifdef CONFIG_DFU_OVER_USB "dfu "