From patchwork Mon Dec 6 05:44:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 520957 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4223909imb; Sun, 5 Dec 2021 21:44:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJzvHAZyeHQa9CrTiTDcbaikjkgJckLcoT+iuZzr++oJZnjjU1QCrAZLE74dhYim2EEsMh8x X-Received: by 2002:a17:906:489b:: with SMTP id v27mr42051418ejq.567.1638769489984; Sun, 05 Dec 2021 21:44:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638769489; cv=none; d=google.com; s=arc-20160816; b=OBy2X1CXxhD7lZpnQACmSLKY+/E3snvnLoICpcBfQleBfMViuIzTl54gTEIMq6NCfS UATe0WDjbIV+aUeh5fZBmXuW1AMLCq3BK6Z8kZpdboEKMEp/xuOZSGcpK6Gwfs5oxgj+ IdDXkt70Babf33RcH5URmQHKlA8a1f6Ydo3XaPQCbd24skk/quqVxUglL0lkWW134T20 0vM+7he6nAkDXRn0IWtoztp1O7yx31mofJUxKNJK7HN0+AB5YxGpX1aYwibmnnszhR03 LDHVig2+rUMK0z1PBsIfbX5SY3T+HbRtQ9Tc8rzPQCuappSJjvPlIjMH3BZuVF/trJxa Fknw== 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=LPQaWBpi/AlI8Tnm+kkzOKyeVYuWeRJYS+jE3uBWsuFaAZuzci7HQp5tL2s/0f9IwV N1zT7Z29KPf/J8ylhX6XWAgWq76EMKyhBr/0fZ9fzXGstJQ6+7+0m10BeQklGSifqU6c zGRAcmkiHbf+E3+8F5I/71DUdDkZefZLIAOc9+zLThO5oe+9GSJmRPTRCuQmnIX91FZR XncY/2hVlwKCtwu5yoA7P6J8Zl3l3zLY25PC7Is7LDXMvOXtE9MKkArkIJoHRbR3onnr RuQ8PgQsUZZO9uKl88NVPwIfDRK/cmphuBx5kpHUzdb313apo+ciyTqxaJL783hZOMKH QUKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZItaLPeo; 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 l26si17036897edv.368.2021.12.05.21.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:44:49 -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=ZItaLPeo; 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 782E58307B; Mon, 6 Dec 2021 06:44: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="ZItaLPeo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8EB0083075; Mon, 6 Dec 2021 06:44: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 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 759868083E for ; Mon, 6 Dec 2021 06:44: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-pj1-x1036.google.com with SMTP id f18-20020a17090aa79200b001ad9cb23022so5214920pjq.4 for ; Sun, 05 Dec 2021 21:44: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=Z2ROnf8FiP3NdigMZdG7gXUWT9ksrzqvxWkcZavbpuA=; b=ZItaLPeoNp92vtg80yDFiFHr4PfX0ZGn0Es8tmfDSwCltpdAJwvDLBEq8UeFFo0eQ7 ScoU3CNfznxvqZ/fxcXtmNHMCicgdU5CyNL9Ti+eyEe9AuOSRSQW723dPgr+/BW6KYEr r4y6+ZeD0cTYdfmZ0I3Aps2P5TOcD3KQt4Q7b6JwgYlrQbig2+t5Zrtxs+4YjIx8+nzo z3Y/a+QugCzDGCs+2fpYuMyoTZMuNJFu7/G8jFrAdKMBAeJf2Sl46Wf7qm41MvgY4eoL ABIVnYQTfnEuniUCrXFcZg4ymC15aViHw2W8DQ/ogm/wpV2fWMgBFvEW964jhJoOW1yk 0fAg== 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=fI1IYWfbROqkH5OrqXy5tI8pyS0xqZElE19gvOw1u1rE3Yo5OOs0oBQ5kjjnVJ5T09 nvCa+FzRS2mphQ7Hfdu0CslrzeAJrECHe9Dx1/VliGT++iHNEMW+BtOQukVgFApIH320 DRpy6rzAK7CtouZz0+Fnvfx21YlXDl/1b9L3P1ZFOEZbc6RjkuajfvpzhHIkvgqHUQJ+ tXOGEF+bbE+H28bDkPGNi5XFaOmprrsvT9FnWyPP6j1rQMRzs5hZljdII62fxFOyXx7k wGoxmV9oiEkZfqtzG/PweEqPeqdvqSyafBZyisOO2PHsRixLL3F8M9oPZ2Buz1uIwQJw ipOw== X-Gm-Message-State: AOAM5335glg3nZ5oUS8SwFaDSpkvjAQPQnWazJE0ACC9bNwWdkotpJrZ 4Ors2REDXCi4juD0quNaozlqFg== X-Received: by 2002:a17:90a:1a55:: with SMTP id 21mr34670644pjl.240.1638769480898; Sun, 05 Dec 2021 21:44:40 -0800 (PST) Received: from localhost.localdomain (122x208x150x49.ap122.ftth.ucom.ne.jp. [122.208.150.49]) by smtp.gmail.com with ESMTPSA id w142sm10523644pfc.115.2021.12.05.21.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:44:40 -0800 (PST) From: Masami Hiramatsu To: Lukasz Majewski Cc: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, jaswinder.singh@linaro.org Subject: [PATCH 1/5] DFU: Do not copy the entity name over the buffer size Date: Mon, 6 Dec 2021 14:44:38 +0900 Message-Id: <163876947800.38238.12205367138412196203.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163876946986.38238.10896882043017582609.stgit@localhost> References: <163876946986.38238.10896882043017582609.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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.2 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 Reviewed-by: Ilias Apalodimas --- 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 Dec 6 05:44:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 520958 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4224026imb; Sun, 5 Dec 2021 21:45:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+uwlJIq3y4p/jaXzEyDOh4mRjGz2vDJ/UIR05oimWEbQMgin2yJWwp0LyAwqFFmo7XfLH X-Received: by 2002:a05:6402:4302:: with SMTP id m2mr51217776edc.349.1638769500966; Sun, 05 Dec 2021 21:45:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638769500; cv=none; d=google.com; s=arc-20160816; b=fDYyaSCcwWiupJC7V9B2tVnSxw307T9cYu4kslbGAZ4307sPMkHPMuUi+JDPiN7pSe AgPjBR4DoHBKsCm28Dx1ySfecDLdWY0aX2c6Ys1UlNWKIP8IU428pLsTg+43z/AJ4E6P jjbWF9t9XqjT5QVe9nyursuUzAm2kapJDBcRPJ1iipE4z0QsyQFTDQqmB4shBFsYLpvv 07HU01slG7uSibWeWVH9OIQRfmfL+xaJBvpKEcy44Cr1kycXgZXn/b+je9eQaK0i7okc SPOiaQCscucb0zqh38TDVRy4zkRzY4AdrpBwltwsFdYX4IDbW1Nd7QtKNNpNmcLkPd85 flwg== 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=EFWbjGk9JX+DSWQ6trHzI8wV6W2hXktRVKd+tGFIjOU=; b=1BC2pb7pgn4FDqq7jxbEtYbAXpeRVCCFnpLyyVnSu6/Un5Af37a1xOo4yxgU/4UmOX ZUDSWTyPOA2Y4DYAewbg/jXI6ms3NbuYFnL7CPCOSw7/dMgVyBuzhaWNAXmFY8UfrySZ LdWrUqauOKbDEdF9pb/hjSW7GPxxmitXkoV722ngYF4CZ5OeZVhGOwr0aYyibowmSP49 hWCjSCpcQxM29MN0UoTl162u9xH+8ZcwtKeRv+mMw01hEP5qNf6ZDHZ0oxzCzZLZZ0p7 nRV0Vl4n/zJQjsOaVJNBlwh78ouTICZ134Q6ij+z+/ZitWGIwiiYsIflXtcVOD/Ez0qp kEww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sxMSKMpV; 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 c12si16013996edw.378.2021.12.05.21.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:45:00 -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=sxMSKMpV; 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 7D6EB83066; Mon, 6 Dec 2021 06:44: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=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="sxMSKMpV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5BC908083E; Mon, 6 Dec 2021 06:44:58 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (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 D9436830A7 for ; Mon, 6 Dec 2021 06:44: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-pg1-x529.google.com with SMTP id m15so9390836pgu.11 for ; Sun, 05 Dec 2021 21:44: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=EFWbjGk9JX+DSWQ6trHzI8wV6W2hXktRVKd+tGFIjOU=; b=sxMSKMpVK6WqytvXjkSeOdfvLgcS/5IcpnwEhMTlFX2gfieMAwy4dRH3VLB/rJMhrr u/oGpkLX6u4Wc3/8pcrM/afiLw5ek+7cJyLiWDlylfrOhm0nFdTk56Fxevt63V/X5fZS LghZycmPHB812k1BmZjyFKKDs7yyZpQGf30+hmKMdjwUKktxjQDPjpnqxiSpvvzI71AA 5IQtVjrDnGtQhOeq6aWuTx9Oj5eqb4sxPrJSlnpc2HWapJiyBhjGkqHJKgUAoTT0Rnan 4p+rX5bU3he3h3q6lPJia4fUZGWpVaSFKFoiw0mKAuKxs+b5v7MAJn6FA1wmu+aH7yH+ qeLg== 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=EFWbjGk9JX+DSWQ6trHzI8wV6W2hXktRVKd+tGFIjOU=; b=Cjz0L5T4OgXtEy4F77ry0BAr5BG5XWlDcH/PGkMqsTB0ho3Qah+xk6VtcSLoD0A6de ibBCwhcWmgBtCRldU5zeoDDus1ijejrtw1qG+w2RNv7QOaYGZImfpIV96QaQUENdU41Y Korsu0CPN8p8n3Uhr++l72ptTh0xFIwNADnIPG+YDw54rLtNa9xHePyxJU7mtwOEQ1eE RU2cwgHGkuttQQQKIIXT+khCwfF4+hjscXRgEnxQRbHDc/LrywSpWr6ITTDzYRWyKzrU 1Rs+9ez673/hBRoWcLfDJKdzmZy8594rMwNSgDNXV9CXfNl9oRFkHoErKr9pyhLDM65B R92Q== X-Gm-Message-State: AOAM5327X5An5RSxWNHXB/jFd+bM3uzM5eDaaVwBe31d1u9x+2XAf5CA kgt8X4Q89Zfb3QmGq3hbx/lMyw== X-Received: by 2002:a63:bf4a:: with SMTP id i10mr16886468pgo.196.1638769489232; Sun, 05 Dec 2021 21:44:49 -0800 (PST) Received: from localhost.localdomain (122x208x150x49.ap122.ftth.ucom.ne.jp. [122.208.150.49]) by smtp.gmail.com with ESMTPSA id ot7sm12500452pjb.21.2021.12.05.21.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:44:48 -0800 (PST) From: Masami Hiramatsu To: Lukasz Majewski Cc: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, jaswinder.singh@linaro.org Subject: [PATCH 2/5] DFU: Accept redundant spaces and tabs in dfu_alt_info Date: Mon, 6 Dec 2021 14:44:46 +0900 Message-Id: <163876948624.38238.2558454766729057172.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163876946986.38238.10896882043017582609.stgit@localhost> References: <163876946986.38238.10896882043017582609.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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.2 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 0b7f17761f..ee534a9d10 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) { @@ -265,11 +266,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 Dec 6 05:44:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 520959 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4224213imb; Sun, 5 Dec 2021 21:45:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFnm3TYDeUHTZbkyWvx7fAvbyWqicbGqEQbnvaITHayqv/owp/QfCR1lYEyjzTe6fHSgVY X-Received: by 2002:a17:907:6d10:: with SMTP id sa16mr43866187ejc.532.1638769516783; Sun, 05 Dec 2021 21:45:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638769516; cv=none; d=google.com; s=arc-20160816; b=uTeIQjfvY4/ZgqnIuNwpdBBpqJohvu4yPu8UREGptNJazUAI1+bpumQqh9Fs2Vzi5o InjlRbHhX1KHSRiCsp6pPn3M1W/PQfY01QbsVBwPGSS6HuDEt33oVVEw8VFp96nv6n+6 2S/Ifl1DEms/weyC3ZVz78MIHRi9oVSwmtFMQZW57cl5yKe7KQzRbFKNNyryMBlvWSky 9IidJUGDW/sM+gsyh2f0kksD/MFjwz12wc82zHUnrUr30f1T7qx429KPpMwGi8N5m178 07bKZ1J4gYFTPUTWkUuIHYE0IItOPZx1qlUVcqWbtdX3ZKTCVhSU1DhyV739XK7PjE0m pASA== 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=08dcTnfJdls7OWZEZxGahKVrjoz1/3HcHomC7jdKWHQ=; b=lePCD6GtxdQNcMkRxxWK+QKkz2F2Ulc4t6dAjuFjwFKG9RPdNB/JzNZJbAiJuCq5vF arJJhCHm9PCOtAeMUCjH9VVZ89n1FjvB5heIQ9RhRpsNR7SLJauRGhNiPG1LVcXOaZ34 rtknPuvQPFv+rzwa3h2Qg+yV42IHSZrFqe8iwRN2MHOidvzqZbq492zFeE8aJFlTWSC8 X3fmJ0N+MNLpWAl72cbJCRXpz2tcRN2GkNId8bODw1od3OYHl5Wzbvvb6k8eJtFvAKRv wdkup1kbm4zYWiYJ83x1j7Fon7H5MzE2WRq4ZfH8qtl7CcauBhTgIgLd8aZv2BS3SvT3 7Ibw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Lvy3am4q; 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 b14si21643564ede.78.2021.12.05.21.45.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:45:16 -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=Lvy3am4q; 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 ADBA4830A7; Mon, 6 Dec 2021 06:45:15 +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="Lvy3am4q"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4A47D83027; Mon, 6 Dec 2021 06:45:13 +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 autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (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 3BD638083E for ; Mon, 6 Dec 2021 06:44: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-x633.google.com with SMTP id y7so6396274plp.0 for ; Sun, 05 Dec 2021 21:44: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=08dcTnfJdls7OWZEZxGahKVrjoz1/3HcHomC7jdKWHQ=; b=Lvy3am4qqQo3LT6RHeS6yydhXvtbbDXIUB+GaIDVaRPhXrV/2PNwqdP6dHQX510pQn 3gidztiY17y9SZXvdXnuK+21ZaOD35NPYrCAnVXr9PhO66l8SR1tXvyhs2xDBGfT/htu PAbE1QY/eykKzDdLd1XFEJnOkqbHg0PC91WfiLHo6f4WrlPQh7/5dXx0v/ZSXf+QTQD7 Rarb336XIct4zLnBQaIJ7WFnMKqDLgbiaNfrRu5jCTc8QbMXBWraFzNyrQHo9TsRptMN 4Pb78/VYMwAEm0JzMV9w1TE/sPHTMSDpUa0ViN66HbkeBPa5Bqu0QVN8ZdizTVHUZkpI 56ig== 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=08dcTnfJdls7OWZEZxGahKVrjoz1/3HcHomC7jdKWHQ=; b=ntLOfd0iyMAjsQOG8W4Gwbl+Z3AgXzhU4vFCqLhQhxA8P7YKTBJJdzHSs+1PLNEvfB i3O3CETEsN97iAm2w1SYVA6MvJSDhmEkAyRKGLgk4+uFeBm2HYQ0dSfx1BwYWjMJpeaA o/H6jHcoDqiq+2hy92P4lOhdU++uLcpJAKoEcvlWhiHa87TXgdMXYf3rTDV71yKfj45m CuJ33ccequ3ENgELVDy3hXp45alo7EHJj3bokUUTxYi03X4jr041fxKn8OV+84OToUXr YATMYwR7m92x2H+mNSHf6iEmoQupRsuctAYE6gWMyy6JGrlHL++AcWCSLemnLeLc83LK /QQQ== X-Gm-Message-State: AOAM533BsOjJOil/uG33cuIM+pq7Qxbw9ABB90vd0cyCkV9MwTHbYLy2 UYNU5LTlWG13ZXAn9ASY9Pqqkg== X-Received: by 2002:a17:902:b210:b0:143:789a:7418 with SMTP id t16-20020a170902b21000b00143789a7418mr41272196plr.38.1638769497476; Sun, 05 Dec 2021 21:44:57 -0800 (PST) Received: from localhost.localdomain (122x208x150x49.ap122.ftth.ucom.ne.jp. [122.208.150.49]) by smtp.gmail.com with ESMTPSA id na15sm12325143pjb.31.2021.12.05.21.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:44:57 -0800 (PST) From: Masami Hiramatsu To: Lukasz Majewski Cc: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, jaswinder.singh@linaro.org Subject: [PATCH 3/5] DFU: Check the number of arguments and argument string strictly Date: Mon, 6 Dec 2021 14:44:54 +0900 Message-Id: <163876949458.38238.8969689210906975580.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163876946986.38238.10896882043017582609.stgit@localhost> References: <163876946986.38238.10896882043017582609.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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.2 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 ee534a9d10..81357769ff 100644 --- a/drivers/dfu/dfu_mtd.c +++ b/drivers/dfu/dfu_mtd.c @@ -251,9 +251,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; @@ -265,25 +265,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); @@ -298,10 +306,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 Dec 6 05:45:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 520960 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4224387imb; Sun, 5 Dec 2021 21:45:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJxv18OM8L0CCcnobqhOSySEDzdtdh1dQEQdSXgWH7QbTOnWzoDMCm1XUsOLERID5ZAjGaem X-Received: by 2002:a17:907:728c:: with SMTP id dt12mr41471878ejc.375.1638769526363; Sun, 05 Dec 2021 21:45:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638769526; cv=none; d=google.com; s=arc-20160816; b=sN/1Y6BPQggbqeCHyolWaXUpuul3qW7xtw7AYqzVVgRI3z+6TzJRm5XXClihTSpDYx 2GeEXdCdsYNOf4HoNKSmHx5jBfWh0GiErPKGyU5IoReM/s84YU3cmTEY5vQ4eJsQPrVT xRML4K+5yBD8eWMrlFTlePmJc0+McEJ45gUr2P5kB+qabGwrcx7VF/+FP/ZXEmJEkhHF 9FFzqlckqbPKdpZ6hTLu31hdttDjTbpkchxvyiQ7F1u1HdcpIKhKiKA+3NFQq1wXDPHf XgMRa/BLLpYI1E5Pm4BlnEvCIzQDsNpzk4L+wBcCJz3DAI3qUANjn8Qh3J4PQRZeQlii /VTA== 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=bG3FMogQ/BCU7Gre3Oj2BfMLlZ+P0r2xRHPm9og47EwVWr2/a1mregGosa4AwnUuvk CsRHlCRcTEwngnnwHsArN9/WRzvdKTBNxPgJmVpLt78san6KsbXYMprauFv4w5BM+wUG FBlhST/GPyG0S0lTU1NQNBeAxSAmQFEDOAHJCL0MRpyLuoz9oZ1Vcbl+zIKlfwpec1wn BEn+bep5wME1v2JC53FrSMpC2ioQOrQvBUb0i7qQM/K1XaFYhUUCe+1gVAjgM++vfdFI yawIwHGCAETMJfMJy1WV3G1VnfI1DlbVBwLIJy9ycJzBQjjwMZhVnWmRvBQ6EX9bEAAY TpVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TzSj1euT; 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 f12si17946014edx.390.2021.12.05.21.45.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:45:26 -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=TzSj1euT; 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 CF6408307B; Mon, 6 Dec 2021 06:45:21 +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="TzSj1euT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E85F68307D; Mon, 6 Dec 2021 06:45:18 +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 autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (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 5D217830B3 for ; Mon, 6 Dec 2021 06:45:07 +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-x62c.google.com with SMTP id b13so6366828plg.2 for ; Sun, 05 Dec 2021 21:45:07 -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=TzSj1euTz0NZ39xNPkTd7RPWTXWc/4ZRE1J3Bi/YY4F+OJHN7gkxDAicf9CecgBFj+ Ujf1mbQwloBIjfa1zTaaU+e5A6wnTwn+dNCpPrFg5tZ+9ZevcWFJO/9/ZV+7+inj9LFG /dbTyguKyqsJUrA0smPTZSLX1+bHT7hibYqOOkR4LS8p6RMq9n9i8TYSqY6XliwLOqSU H6rKRLQ9p8k9AhTozt2hm6jKlxTMrLElTojEl3dDKEePU9T0e+QS6W1lD3sesLVYwEHt kPa3pWWpjf/T57H0SOn++xLqHROjETuEnmLncfA0OhUN1MmeQ8ts0BFF8+5T1qLVlbzj KcmA== 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=p9nnL0M8xCu6Wj/GFmiilj86Glq+Yuw3Ax3koHCxzkgrOaKnG+VbcEEb6nuzs8sqJa UuNzZbx1RyKfo42xWFeaEqxSKWD+YiaK1tUCT0XJE6hh0JVNsjLqhnL61/Aw6IQRIeaC Y0JEbXmJtyZeah47hTpXHrCQLpRJQh4p/WK8IFn/4n+mYiNhcrx3tVHouNteE7TbV1vq jd5HuE0j3AfEJecgSJclaw9DhwNQAh+3DWmy4R1jwCEMPyZBzr9nWDoXwQ/ddCYBxmXL quOKGyQ1y7VK4Yx9+Z1MzQAmPoYvG06JcYm7+42OpIM/hJgcs+d2Fse7saQ2WO71wSW4 mgpw== X-Gm-Message-State: AOAM533S2w3dtI6q69nyoFEi6B3XiwTO6yl+hoxSzq+Kng6I+PySIKM1 UTmZdwtUm4jA8yDYI1O5JzGp4j5JUrIlHg== X-Received: by 2002:a17:90a:e2c3:: with SMTP id fr3mr34202393pjb.187.1638769505730; Sun, 05 Dec 2021 21:45:05 -0800 (PST) Received: from localhost.localdomain (122x208x150x49.ap122.ftth.ucom.ne.jp. [122.208.150.49]) by smtp.gmail.com with ESMTPSA id v19sm11507855pju.32.2021.12.05.21.45.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:45:05 -0800 (PST) From: Masami Hiramatsu To: Lukasz Majewski Cc: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, jaswinder.singh@linaro.org Subject: [PATCH 4/5] doc: usage: DFU: Fix dfu_alt_info document Date: Mon, 6 Dec 2021 14:45:03 +0900 Message-Id: <163876950284.38238.13634509540751439795.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163876946986.38238.10896882043017582609.stgit@localhost> References: <163876946986.38238.10896882043017582609.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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.2 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 Dec 6 05:45:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 520961 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4224510imb; Sun, 5 Dec 2021 21:45:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9WZ69SIE64J4b1HdFCogFeDuH4CfzCUMwoPu4G6bTXgBE06lQeQW63nHqGb0telBhGEO0 X-Received: by 2002:a50:f18a:: with SMTP id x10mr50368195edl.193.1638769535977; Sun, 05 Dec 2021 21:45:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638769535; cv=none; d=google.com; s=arc-20160816; b=Oxyh10DcSAzCbRPynqjSaFm2LAVxD/mf87i1aiQRnIqO6s9XaE+7itSk5PwBP9hcX0 lEJlwXZ/wEIghZ4AAp165V7CZLMR90Fng/C1yZjv6oKD0qeDmRlqZvEJYBBKLy5CeFzV 7HHThhYrQE1cS6Dt/BlK0FR0OZx1H8sIqJLP6ltT4WTjS8rW/SqyjRbNUmGD/Yhe7Asy BifeYcPdTvMXKsIR2Mh1chqTkxQOly/TjXnyXeGqXoyjJfOOPS1ixLwU0OBjWkxOZQcV FVow/mmseMLgwKxPm4/yEDhd6Z23lRE1yac7WMev3UD+m04xrXPc5jQ9n2BBKi05Nss5 pFjg== 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=Fc0acCl3MnYd+Yw1Z8+lZif/U99kuk2jt8zTy4DLrMY=; b=S7t/ypkyDEgF0DpYjfUpFTqzW/wR03p2ESPUAS8tLFKvksP8xA6Oc30PK4fop3KlMb UaigrYGXEg9NAX1Fxin1tNtD2YKXPM82BRMA3Sd88PUAOA0okv05YMRPSfT05+L+SnHA AhHHH7rKjjrx8a+ic+labNkitMMmaMuA1s3k4ROG9eGUydGgD4eqZcC22MEYuTzUBSMR UAw1B+7B4axY9koualtTo3GXyiNeX9xE/OKHBra83OnxxEx9sPGbXl+W7PD/AJI3rLhB 66HTzDDKWRoCbBQ31Ljj73KF/bmm/3OWahKi8H4Ri8B7q6fTGU6z7Pn+ualQIgMbkQwR SQAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DCRpDLjc; 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 yd6si14825638ejb.108.2021.12.05.21.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:45:35 -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=DCRpDLjc; 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 3A94E830AE; Mon, 6 Dec 2021 06:45:27 +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="DCRpDLjc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 15E0A830B8; Mon, 6 Dec 2021 06:45:25 +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 autolearn=unavailable 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 890D483080 for ; Mon, 6 Dec 2021 06:45:15 +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 l64so3869489pgl.9 for ; Sun, 05 Dec 2021 21:45:15 -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=Fc0acCl3MnYd+Yw1Z8+lZif/U99kuk2jt8zTy4DLrMY=; b=DCRpDLjcqtclT2dsH8HuphqRm4BSb7dJDCKtLA7Kq7kfSgBH0t+cGkXEQtrFO/DpEU G8JrrKO1ikrbZyhBpTgF77qQdsylDlhaz7/QkRRr1hRrUTPAb2QoRNOu6/3RKqNWhEr9 +gAPVorVOFpqiYPa/7KcRS+CkdIsCadgczxvqDjw1uaaaZ3cLB9sc616AfPyAe7owg77 390zuCwqiwoDMBacNq//ksYAigEl7tF5N4jReH7IHPgjrfxMTcE53hH7X7jqbNabfmC1 aR8rfs8+FqUrVA0fV40ztlKvYZ1neVFrzwJhTULX4/XjNuwxeDPlUw3wVGSD6Lrt9ezz Q/ng== 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=Fc0acCl3MnYd+Yw1Z8+lZif/U99kuk2jt8zTy4DLrMY=; b=bOi20Z1lsEVNezlou5jSxxzwk1uwYo4MKBbA9edCdfKAy0KwZ9O6SBWawf0O5OjgUo 5ANOdtEVwWzGz+5aqwlYLW84y/NadC+Sfsw7RvqjaEC9JRKC/ze6kR9Pqlyuy8cJ1tbL 9UxxqQlg+OANw0EufYpnS5uCKaur7vbaYjSHp6pXCxHIiBns0i5o50v43OATMw2O29Sk JVeJEja0k7xA7LNySz5ELlGnBrJfeZPGc6bM1mGLXzO4z1+Ir+Ye50hbLxXSHNAIh/d2 eqnBVZ8q1NZkPmHAAsbI8YbVER5Yo0Bnx65+6TBS9+qyXeXRnU6oKBvJBwaK/Lol0uqV MAGA== X-Gm-Message-State: AOAM533H6+72MbZ6VLzzO1YsMLAsLN1T6wl3BsnI/n/oAo3N2FWQhrnT 2cHXVRAqw07kahAbtupT9wfQMg== X-Received: by 2002:a63:141d:: with SMTP id u29mr11526561pgl.412.1638769513994; Sun, 05 Dec 2021 21:45:13 -0800 (PST) Received: from localhost.localdomain (122x208x150x49.ap122.ftth.ucom.ne.jp. [122.208.150.49]) by smtp.gmail.com with ESMTPSA id x18sm10564267pfh.210.2021.12.05.21.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:45:13 -0800 (PST) From: Masami Hiramatsu To: Lukasz Majewski Cc: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, jaswinder.singh@linaro.org Subject: [PATCH 5/5] cmd/dfu: Enable 'dfu list' command without DFU_OVER_USB Date: Mon, 6 Dec 2021 14:45:11 +0900 Message-Id: <163876951112.38238.16417526355275476416.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163876946986.38238.10896882043017582609.stgit@localhost> References: <163876946986.38238.10896882043017582609.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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.2 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 --- cmd/dfu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/dfu.c b/cmd/dfu.c index 4a288f74c2..208555c888 100644 --- a/cmd/dfu.c +++ b/cmd/dfu.c @@ -50,7 +50,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 +64,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 +79,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 +100,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 "