From patchwork Thu Jan 20 15:29:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533540 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1675684imu; Thu, 20 Jan 2022 07:29:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJzi3tSMipcwPluyofqdJOFLGzoAFyHd+a4wFFjH01n1WQyc9VVVwJw60X3YZQiywo38riEE X-Received: by 2002:a17:907:6da6:: with SMTP id sb38mr14967368ejc.705.1642692583047; Thu, 20 Jan 2022 07:29:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692583; cv=none; d=google.com; s=arc-20160816; b=qKRCEWdEBjJIssv5RtJ3hgZDNc3KBANJExg3eirvBEfVKqr6LHxwGNM5bm1mk49E76 E2p/oAWej+RzbUMi9QZ8+fPxM7KsJIhcQyTgeAMH61A4dw3AnIlAD/E9lv0Ycq50Q/D3 QviGakBQQ6OvaQWt6LPhkCPY9KyR3NG8YpIlLI6XN0XHX6ABe50Gx96w5iz+hQ79Jqwl Ob4e7hy7m12Jx3tvJkLLil11mPWAbdOluOWF9/CuB9MOVV4V9kOO0Gpu+JMnnsUaFcRp Xgi9etURxBxuhcI5FZMi9Z9Dsr28IbU9T6xcjMPH6bAAF6ZrNWNN0YOXSe+TvLd7bBhF ypeQ== 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=j0BEGQCgs/P0khL4p59Bg6iVx+uKUIPcJHjlJQUig1lAtPfPWKmtB0uCqdk8ttJ2Ew HGwZ7xeC/awfzmQpqXJpuHtP+cAC1SILRSxo+AuxtnPrdKAzwPluF/yXetu0GZK0kqgv KlWYfku3CJ/UruQ+cC8dfJZ2pfinVGxK2cgLc1RcXtTqK/qMcOmtvzxMFFmEovE7Y/oU E6q1xZDT+82WFWEJ6ELuyGPlJZtrkZ1an7mWySl/pE72zRMzvwl9A20xB+2rvZho/NIH 1E2MozbdmJx/0tKGm4kwTRrAmxASnZs0ZAvXteIBL2be5+mAl6im3BmBEYyeKa037xiu yy8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sLxu6Uk3; 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 8si1921594ejd.410.2022.01.20.07.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:29:43 -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=sLxu6Uk3; 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 65386838AC; Thu, 20 Jan 2022 16:29:40 +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="sLxu6Uk3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 106ED838A7; Thu, 20 Jan 2022 16:29:39 +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-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) (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 55A24838A6 for ; Thu, 20 Jan 2022 16:29:36 +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-x102b.google.com with SMTP id d15-20020a17090a110f00b001b4e7d27474so6092418pja.2 for ; Thu, 20 Jan 2022 07:29:36 -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=sLxu6Uk3jwlI7iiHs6YkaHHeaWUMA3cQkVtUROyX9R9tHffgXS7u5DnHgX+n71Kv26 /kP9Ar6JET4Z7IsiWuBLEc7qeUXLTRmTUKRRbsOQr8KNy+AjYcwn2952JtaO9yDD02OG XrANRfgiSA8W+Tyb/QrVipwPu2VWG7J0Vb6q9+yIB6CvYMHlmhyz7ZvUXgvPqsDdm4FW xUe5ilC/i6NSzNyL5UR2jJSQxYBwFdart5W8Sm4Ag2bmMYf4MafOcJPGsNINNSa54pqm QtvRJgY3APbAf+3cX+AQGRGANAXZ1MuOCYLndBoZbKpO1+Mw7L33H5TpAeLNka6q/PkA hYHA== 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=DM0/9rSvXJYA2XSBHilkYdcHopZOJkz/NRx3slGz87XqEHwGQnFkuIxdAFT+spLKiC BSBJIgW52uV4yLFCAD775F+L+0Q21bqmIcWs1n/wi/H5/mgURt8HM6tnA+g3gXZ8dwwe pNR8OpNUrVQlTKT9iqnyib6iJ6SY6nc3uGlRBbYq7R7iEX/OgA4nklpgJvdcHkOKPGkp Byp2tab3Kuz1agljNZZW2eF7CfBu4cZ7f8+AUNFL7ZMNbc1UEXuos+zPnLNfsUaRyiFa yOWbxOkYzBJUTM3lZ7ALaVBKAUA7cOqb/kLKXd8ShCB4E68zd6VqoEr/7tslmg9obUve fvCg== X-Gm-Message-State: AOAM533hPWHMoffBSfBkmJQrwrfyJkPJfQ6un2+aXXTeHMqktZ7F+/Jq MOLW68IOp7dlihmP282Zqxd9opYltsrc5g== X-Received: by 2002:a17:90b:3e8e:: with SMTP id rj14mr11476505pjb.179.1642692574449; Thu, 20 Jan 2022 07:29:34 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id c17sm4015405pfc.171.2022.01.20.07.29.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:29:34 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 01/14] DFU: Do not copy the entity name over the buffer size Date: Fri, 21 Jan 2022 00:29:30 +0900 Message-Id: <164269256989.39378.10399862613876371846.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.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 --- 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 Thu Jan 20 15:29:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533541 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1675825imu; Thu, 20 Jan 2022 07:29:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGuB+PBIqpPDOZCWsHKUY223367ubJb/GwUene/5h9YGTyMjKxyEceP172gfNSOaXYbMON X-Received: by 2002:aa7:cf0e:: with SMTP id a14mr3783900edy.296.1642692593999; Thu, 20 Jan 2022 07:29:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692593; cv=none; d=google.com; s=arc-20160816; b=Jw03ZKzFzjjE3i+wYTErnzxK00sXv7N7VNo/h22hcTGsodKBo/ZWMZi0LxTf0TY1jZ k03Ps75/vKH6g3aebKIfBCRkEyxXqVxO1Gl8D8d8TsKwltiANDq55VfrPU2Jyc5h5JYW V820JWyFp0jNQhfvbdC1hLesmFgPunP2JrZnnHXV++IOnc/sLHI9CkLg/qZsuHoV+beo yb4mD5qa/dUeMv4RdOH2V7/J/gXnobxZcMs5gf822yGPF5ZU8SmJRrfxc7YNRmasqQvj iqRf0KbqexDWzXS4oIYxmc/XR149TYwvLtWC3O1R+b/Prs5PJ/cyuc/ugejPHVtiULAZ oc+Q== 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=oAfZbNnXEMkgagBCBeI4ssKj7vp7G4ukdKCR8wlYyIMIk54BmvZV8z2C0qnWSV/DRE OGyNIt5D6ZpLQHROtuZ81oIvhGbdvi3rcRlO6WsoOpnLV5d83crT/Zj1D5ZkOB4T3YdS HNNDlboNC9wk2gHEIoLJ/MKZWLfLB8Dv64sEmxpg7Vb0Kfc/VzEoTyyBFTrLVqaila0J wJudglJ3sKemYhcWAoQXxviPsTrDfPhzRp5lrNeK58gEDB5R6gnm9kdYwVJbi0/3YjS8 TUUqDpjosYXv0FJFqQxXxaahdMx4BS1LQvdkw57GZ5ZkTZEuNu2zNZJO1W0egQp0Lt9a iAlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KVjvTUeE; 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 r12si2415422edd.576.2022.01.20.07.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:29:53 -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=KVjvTUeE; 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 3024D8389E; Thu, 20 Jan 2022 16:29:53 +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="KVjvTUeE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8FA228389E; Thu, 20 Jan 2022 16:29:51 +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-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 5D414838B2 for ; Thu, 20 Jan 2022 16:29:46 +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 n8so5474689plc.3 for ; Thu, 20 Jan 2022 07:29:46 -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=KVjvTUeEGEinMaCzw7Rb9XNFqRA23ZWN1kJMDK8x/g8vgjwKC1V+NuxBkhbfczeAxh RViuR6uuY0/v0NEehDUm57R+vTgDgD9/ee+dGaRhOcuDpYpdWiQ5n39HLg0tPeRwp4Eg k8jZFEwofmG/lOOrJ/ljmlZpNIf7KrPdZwrH6ia3nlEvOgmM7Cf3TQbzW3RvVggNyGeo NFnilS7om8vFjDa3IrGlNM+3X/TEklh1BMDbEIpycV8Hbxwg5t3IUrNYBpIbVGZFijcP zkGoKQ2iMGcceUiyUK6HLsafaxtMSo3D1VHK7Vz+sOwMz74J+DF9XTweoN+gtiLrhECX kh1g== 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=W324TJlb/4h0H4X2Hx20mgSM4GK+piXb+9F+HokFJ+hT1qhJ3WpNW0sXiBOxNtP0ir VeMqMTgKWFnYgn9CEweVIODMBGXTlOWLSrVfa3jPZ3YADSfGoGA1I5PEnziRUQqk5Kk4 RagIR4LYGz8yPaznYGhEM2hie/4ZuUaci5OFogZBv5MYiCxRAgDExWxdJNvwkE4mCMZW xbtakWjBjK85NxGgZP9nVoueBa2fNpHV5ckVomVS5OxVQTdgTKcnsVnxac2bMcbnpc34 spArwJTkKH/Ze4RwSJzYHdqJKn5qKiwxnO4TeQDJSbjyE7o3h3B4Xj3D+BQcvrU3OkNN 5BUQ== X-Gm-Message-State: AOAM532/ETD5415nGAnX43L1FkRgFIBVmPKJ7FkE5pSBmx+YrjsGxKnm Qz5qN0JzhF2bAKB/Chojot9q3KuQgq8dWA== X-Received: by 2002:a17:90a:380b:: with SMTP id w11mr11462052pjb.113.1642692584482; Thu, 20 Jan 2022 07:29:44 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id b6sm3889885pfl.126.2022.01.20.07.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:29:44 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 02/14] DFU: Accept redundant spaces and tabs in dfu_alt_info Date: Fri, 21 Jan 2022 00:29:40 +0900 Message-Id: <164269257981.39378.1812521347685379493.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.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 Thu Jan 20 15:29:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533542 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1676099imu; Thu, 20 Jan 2022 07:30:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJyUSeLnX1uQOjsMDjiN++ld8jWDMZIVAQwyziUFHhK8mA1/mLCUDLlonhCf01z51gfu0OjJ X-Received: by 2002:a05:6402:4244:: with SMTP id g4mr13810841edb.271.1642692611463; Thu, 20 Jan 2022 07:30:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692611; cv=none; d=google.com; s=arc-20160816; b=xXxtfJ4c3UJA1Wz6XPkDTRMgsRg8en4G5VdrmWDS+hv1XlmgOOWsuOUGsDygyoZFmx U+vDRaHC3z8sPDPePGdDuCMhBJlOwjLAk3ppZSvbat9yffUUqc15kiNo+nQK0PDuifP5 fOEFxPYwowHz0zW3ws8eTXrV3DqtEKTkOE0DS5jEHWhoo0Z7jdhwgXlFKBZ2zRVtlWu/ 95hHl7/XnTZ7JB7TrURGfcBIxGxHMphMGIUnvEO/VLc3zKLENROw8WzGtiTVlxbOsiIu b1dsTwKJWnMAN0hYnOQ264fqBwfoVvnXZiB0XsdYKZ7dF/Mg8qpqfxtMTOSKW59bxNYi ntOA== 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=gaDXLaPrZT/rNg+GNHAc9lNSNFYokYzSCT6j4DsdDVFPyISJZveydR49oDNneMEwVx hNCkN7iRFksG7CFOE4/5xkUob7377ispxIMJCcS4pmsBsakw6mUDeZimBW9OYmzxZyo3 SoBVVP/bwlKSN+oFWhNAjiFPsHkr7diU6/i7FTuxk8dFDLWqJaFxVJmIgi7zpVizGrpt aPsCOMXdUpvZey3/oWDjOYZQqOmycJYXzRBDhXlgP0S3gJ8qgAi2qGvjARrGLSvjM7Oe 28HqnWCxx9CmGYe4NknZnG+OOVjoid2OlaOlebja4Is7yb38vTmJpErJsuilz2m0t+3K yxew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HgEKa5Wv; 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 c6si2105290edr.14.2022.01.20.07.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:11 -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=HgEKa5Wv; 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 9F84B83890; Thu, 20 Jan 2022 16:30:10 +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="HgEKa5Wv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 115548389D; Thu, 20 Jan 2022 16:30:08 +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-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (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 ADBF8838B4 for ; Thu, 20 Jan 2022 16:29:56 +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-x631.google.com with SMTP id e8so5460624plh.8 for ; Thu, 20 Jan 2022 07:29:56 -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=HgEKa5WvCVW53gEnXeg8Xow+9qM2b3c9f0CpzA/ieH7FTuN3qo5lFIOcEtFLHMGema Szkox8aDR8FL0N6/Rqfe6HXDmFdPzColT2YFT9sMwom7S9LJL/8JWqhi0IzKbqyJh7T1 buKgLu93wH6HP2CKQd7KluOQk29hJ46DDafKNY7dF7vor/9rq9pZARo3uopKvFWUOFHN JuY8TzI1tlEdVdjyXObY5ImQeDqhbOVGemK8a3jNUl36A9zMV0WFiVt7lvCXFqz91lsb GnCMhcdi60OH1RpAB336VseqiDBChRidUtKI58KgRElJVYDMkGJ0zxiCpETxpjf4SVrc Jcfw== 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=S01TvQfXF400XuE03J+z12c1CkLTbEjT4l2b6NW+PZV0baqgSdwF2csBCneuPbCp8O fasJHbKCmGJeSbuumJ6bojEkxfjMScAp4zGN0aFwR63dr+ysljbTzvYbAFS8vqvY767b KM5c1JrJdzvjW00FIKxV6Et830LZCmf2DaszmFjnP2mraDVA8lhyjydspMhrst9S+oPM OgyMX8oATGG545W5mqx3bjCDfvv5Sv2CsLKhMggQtgpl8/UWafoHEY8Mt0kvEDuUCDsa oNMTNJt+fvX7eeMXtMWis31/U29Io7xVYQTV+hirSzSF+lx6oz6aXCQJAeWas1Ijem+3 E0jA== X-Gm-Message-State: AOAM530kVAfe7UThK4y5Twlwm6qvMyyb7ukNYeaVEsBzv7cmHDyZOYHw wGaH+feqegvIXEJ/CFknFEb45nyQ6DxxSQ== X-Received: by 2002:a17:90a:9284:: with SMTP id n4mr11341225pjo.109.1642692594580; Thu, 20 Jan 2022 07:29:54 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id p18sm4089215pfh.98.2022.01.20.07.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:29:54 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 03/14] DFU: Check the number of arguments and argument string strictly Date: Fri, 21 Jan 2022 00:29:50 +0900 Message-Id: <164269258984.39378.17875595141030347793.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.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 Thu Jan 20 15:30:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533543 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1676237imu; Thu, 20 Jan 2022 07:30:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjK5K+9uiJz/fKaNa9TT4CfkMoiEg48KdveW58q63M3J9SdOLXlObzPcDBNvfHApHovs3s X-Received: by 2002:a05:6402:2552:: with SMTP id l18mr36694298edb.124.1642692619897; Thu, 20 Jan 2022 07:30:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692619; cv=none; d=google.com; s=arc-20160816; b=ERAYPOx1rUa4PnNK/97g2BYViT/HGN2m/3Uf8lZwJtMoc6YBlnGQ6HegumNJXSpvhs NwxHB8ofPkKJtNLzKklo4NgyaD+9tCXUzb8RcnPcDsWfJDU+MnAUze+hptFIDBm4js0B CQcn6IR0ht6Faj9VsVLL3MtaqXUyVOjzPa62IbepxyBM9QshZNPZNNiF8Ksrgli7iXYS CtaNgJklEAikgmTGB2hB6eTBGvQOEuOpjUHqechFJH5fYWN2fxmXhZKAS1F19xFBhmL6 xwV9GohH0x3R1H5H0YBRtpTW9/e5zaxenIRBn3MdTbEGnU8M8hx0bFm/iZiqZPCkFumY mjEw== 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=bGmGu49df4XOBEYIG6dJkaB+U0VA8i/Vw3C8sJK/Thk=; b=Qb0eRIWd9BUdrICvlal1f3T762Lueg0/D6srHtsGk1q1YS4opukIr65m2pMRL0cDNf RAWjCeashknExEyneZCzc57I2kLXAV7uIgr0Vkj162hOnF4BztbDHXb/EkHOD9gvOfr9 5K3G1fXj0WK6cWa2aPHal/iQ8A5qckZiFTtkbCW7vvC2BlyPebROhXm1NSIDHb6P2uoZ BZWPIv1wZ/+UgddfAi4c/5u4D/VE4C+gp8AsI5OQyq2kradHZ8J9ezr5x0i6AJP1tdPp 71MRoZDleId5tp3dINUy48oupEX7MjoHn2GMlh0xkjAz7MP7bBlQQnuvBPwF3YFYUZ1D KFyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TyCqjwbO; 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 o23si2398504edz.311.2022.01.20.07.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:19 -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=TyCqjwbO; 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 C8FD0838C4; Thu, 20 Jan 2022 16:30: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="TyCqjwbO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5A5D683890; Thu, 20 Jan 2022 16:30:10 +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-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 B52FD838BA for ; Thu, 20 Jan 2022 16:30: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=masami.hiramatsu@linaro.org Received: by mail-pl1-x62f.google.com with SMTP id e8so5461025plh.8 for ; Thu, 20 Jan 2022 07:30:06 -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=bGmGu49df4XOBEYIG6dJkaB+U0VA8i/Vw3C8sJK/Thk=; b=TyCqjwbOv5TwsScOvow8kk7yVJegtvzGQR03XRqOVLfQa8hhyKqD46oXxuf3GKBJQN IKYvTXkcQj/FiYwBHwZSzJ4CMj0AQ3Rw8HaWvpGO5P+IpRj5sm4d+eZXpwBkQraBtDs4 uox5naXOU4s6LsSoqbI9EClqJon4FL4PlN3e97zt7CyFSdGzCl7UrZWbm8yS+ekSzP6d 24YFZB87RG6wC5BhwNlSAB3E7qcPL7nrXB8ZCEB8ChXfNUJb2SELxkmSrk7//tqaaqAW 9tPAojBlt1OCzo+CAnUp8RsiPSesulYJFfkoIMs4j/9bejGSPCQufcJgc70EZTLnIZNq 5Ylg== 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=bGmGu49df4XOBEYIG6dJkaB+U0VA8i/Vw3C8sJK/Thk=; b=faQynxTx7VPfw8GlgTHXR/uvQKglp3Pz44eETL7TiHB1ipQ5aTnVCirksY4vKQUAsI Oy5KyQ51HEHf13B4Qq3gb3GTFJkT0Tq4OndU5IiXZEJRgzZJpVYdOL5nWuifYu4aZAJb WTtSRK4AQG+nBlmBsDS+5bOYb7X/lZCKmx/O3t8rdlytt/zRUsEEZGrD/UK7CdwLdN9S 20/NTtmgQehsbB2mF0G/eFm1Ag5xvMV5HKA2fGgNavJeFkJgi2/N9FvT1iJYMCHdaLsP UuWxF9TFZayyEweO/2hXF5bakwQ8TTJ9rAf2c68hv5bSQNLRV18DkKiVptfowZYgpCcv 5WHw== X-Gm-Message-State: AOAM533a93dBfFZQZ38ev/mCr85lQAYNRfmuR+GJYxccC7PFaKqU23tZ kbfoz3P1Kf/cDEGaCAa9lLatmx7rBFzF0g== X-Received: by 2002:a17:902:a38f:b0:14a:ec8d:51ac with SMTP id x15-20020a170902a38f00b0014aec8d51acmr10981760pla.132.1642692604860; Thu, 20 Jan 2022 07:30:04 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id q21sm3822236pfj.94.2022.01.20.07.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:04 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 04/14] doc: usage: DFU: Fix dfu_alt_info document Date: Fri, 21 Jan 2022 00:30:00 +0900 Message-Id: <164269259998.39378.8996629458151622003.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.2 at phobos.denx.de X-Virus-Status: Clean Fix some typo and wrong information about dfu_alt_info. Signed-off-by: Masami Hiramatsu --- doc/usage/dfu.rst | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/doc/usage/dfu.rst b/doc/usage/dfu.rst index 11c88072b8..25517637ae 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 + offset + is the offset in the nand device (hexadecimal without "0x") + size + is the size of the access area (hexadecimal without "0x") + devid + is the NAND device index (decimal only) partid - is the MTD partition index + 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:: @@ -203,8 +216,12 @@ sf with + offset + is the offset in the mtd device (hexadecimal without "0x") + size + is the size of the access area (hexadecimal without "0x") partid - is the MTD partition index + is the MTD partition index (decimal) mtd all MTD device: NAND, SPI-NOR, SPI-NAND,...:: @@ -219,14 +236,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 + offset + is the offset in the mtd device (hexadecimal without "0x") + size + is the size of the access area (hexadecimal without "0x") partid - is the MTD partition index + is the MTD partition index (decimal only) virt virtual flash back end for DFU From patchwork Thu Jan 20 15:30:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533544 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1676382imu; Thu, 20 Jan 2022 07:30:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbEZtUpbtUMYiriXOAiz5ATQu2yJz+0JePw40VLlcSm8R/gxs0fiuX7dHqxjMFyuctW7oU X-Received: by 2002:a17:907:1c14:: with SMTP id nc20mr31311305ejc.618.1642692629520; Thu, 20 Jan 2022 07:30:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692629; cv=none; d=google.com; s=arc-20160816; b=Ax4HnA8wZRGgbsjmz2p5J/5C8noo8HnBcpiv2CkAuV513+qIFGRGECIOGNMrPVUuBj AXW4OEYOsYSA6p40c6rbZCo5UBjftOJCtvg/F0gxSdHUeMFp9MO/dEFrN3MHAJ6bdea+ LjDlRi/Mb+ll08dmObEmkRrYiHMccPGVk/g2tc+6r4KJb8NMKWk/0OfGnLPX4kIBZYKe sI4572JRgt/UNS6lEzOvBUosj26Y6bn1A9T4btdrJNhHR0eZgj7d65UZkeqcB0f5hW0V PN87MjEe3XF/vuT/qHlJY6eLPWhO9sQb7Q8fex+pxHYLMqww3TxBI+0whtpm7zcrxDg3 abow== 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=jJJz55wXyXtNLI55xBPS/jOITfyFzJb0iAJeWL7L620K179hKKZfWB5GGINifv1R/d ksbSGRaTRAzFm552EDgGPn2axHt1ADcNP/oA6VQnWG1F53DToA8KEYmGKT+7xoAgj8IP dBhm5KHVwxA+Oki3NF1PQv1T2MIFbh4qo7MHeZ/CCrlTKPs1oJUCyPydMyr5p1b38Ekd mH9jH2KvWThFJ78nVt7au4mgnMRPy6MYaxEctUyhZ5DG2pCmLo4v79ADpD5C0o/1Zevb +8n41AiWM54CP54N9OFq5YgWrZI3QwKySq9mS3cjatIY30eSneuVCGToM+Z0fnIK4RNh QVAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ntiG0+bt; 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 a2si2179407eda.251.2022.01.20.07.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:29 -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=ntiG0+bt; 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 33FDA838BB; Thu, 20 Jan 2022 16:30: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="ntiG0+bt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2B419838C7; Thu, 20 Jan 2022 16:30:20 +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-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 52C84838B7 for ; Thu, 20 Jan 2022 16:30:17 +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 n11so5475303plf.4 for ; Thu, 20 Jan 2022 07:30:17 -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=ntiG0+btHGbcp+Sw8f7so9q23NP1U7bcP/QU8jFZdiyMs7PKDCX31Pv4/8nkwekr1o Z9XZQERgNRcNs5WM2s8M2anz3UknRhZWO4Mk7PRYo5IHfwIjao6mLNxikeKObc0wt3OH QaTm9vix0E6+wyAKFNBgIRPxZ12/Gt/TcSfN8yNzfsM03U65Jknv9zEu9n/627dke94k lz48gil0Y1ygPsn+USpxghJYMq1bUcvGRW4I9NK9JKKRsZ7opOIDuwv0leHWw29kYYWj J4W+/pmHw3ZJ9I1Ji6V6nkWLSj6IXRwsjDU/CM/o2LmKwbWZst2sqcrpurTWeeihvDg2 BnGw== 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=8KPotrdobo+MRwJOuF/dylQqod7U+2b3IOkjOo0wIzeaxVQ/Owkdw78coL9KgZbmlI 6eq0db8+fKFvwTJ8GxtrAhPmq9cdPs3eeTl4VyM1sBTzYKLyhFBt7zYwLXrCX+FXhrRC uZT48/fZfdpj/ZM5zFLtTHE6p+gxelBPNqy61+0WYIEGTZEE0A/KwtUupRRh7E7b/ohI 8QVzzWMOvztZEUXwTvHrlWC6EOXFXkcaPR3MpLSO/t4fXPxnRZzZh4UocJJUl2dvwS1d D774iG43+PHykX8i200mqa80xHqSDWqLTV0zyjjBrD0grw5HDoPF3s08EzpJoPkv0qO2 oJQw== X-Gm-Message-State: AOAM530+DYCKU192d6Vy4fytSnw01DLoD+MTUDSo8Dek5oBRHMntuZkr 3N4JB875R2ZHBUniTA01RCT4JXgaooPIGQ== X-Received: by 2002:a17:903:11cf:b0:149:a17a:361b with SMTP id q15-20020a17090311cf00b00149a17a361bmr38926017plh.146.1642692614935; Thu, 20 Jan 2022 07:30:14 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id d20sm3718324pfv.23.2022.01.20.07.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:14 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 05/14] cmd/dfu: Enable 'dfu list' command without DFU_OVER_USB Date: Fri, 21 Jan 2022 00:30:10 +0900 Message-Id: <164269261023.39378.5724493870299819571.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.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 " From patchwork Thu Jan 20 15:30: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: 533545 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1676552imu; Thu, 20 Jan 2022 07:30:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxaU5zWFGeM8xQAbEz0/e3HqNBK+z6LIPcC4gATE4la/Ekx5T9O+zyAk1ecET2ORFq5Yl3d X-Received: by 2002:a17:907:162c:: with SMTP id hb44mr29566012ejc.546.1642692638986; Thu, 20 Jan 2022 07:30:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692638; cv=none; d=google.com; s=arc-20160816; b=fvHxuoPb5tSp1y6KtY+OomScA1aemXhyjnWYVHJuzyvwA3ycXZP+FyjPH3C7ktuis3 cNz2QU/ErX4Fd0OzxmuQ9X/TpH7EP2YYBiHEmAiKJkL6JZsY8m4i64KONwj2Xr1SQ+f5 IreasrraqWSGgjTba+grf2mgw9WK07YJ7ocA2Bys1S4Gf73O0STftTIIrThWvLheCPAT BzCD0iB+83UcJaGU04oN8kz1/HZMA8bwR/yXIWFMtMVM0XWtmcMbTtrJ3MeX1vpqHCth YUS3TjnFAsIABapHcsAIiAL8ekM/rMWbaPMmRwpeWrNtJL0fJMRg4j85y7/xkoqvZ6/f BD6Q== 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=DSVlRbXB4Gc30pAyBuvP8ULNSVgwj7N6BLNTZ6l0ytg=; b=d5FJh/ULjOr2dzVYW/Un7XmudTBOa4bGuMdlMQllAzIlvmhGqTQjc49gvboCNWKz3y 0gqlcnd1ckqIOY3AHBbtS9qVQv+vqxLw9Vz1uVzAEPOHRJMsT6feGs47QGvFgiLhERjH 0E4DLQdk2/pEUpfVZAM93YZ8ROUunzOoxaxqW9D9wfPND3eVShTiQn31ad2fBApqRPRV /kdMdECNcRX1TEAFA/rVl9XnjqX6Tw6FhjgGMSRvywIzhrkMrn2kLH+riOrF81A+FVpT e2EyjX0W1NybMCERupkdk8QikFotwDPvlYE75t4meQWAepGzPQVqgjmp4+5xTfvfoMcd aMoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BVc19z0j; 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 v19si2688571edc.188.2022.01.20.07.30.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:38 -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=BVc19z0j; 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 BA5C3838AE; Thu, 20 Jan 2022 16:30:31 +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="BVc19z0j"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EFF98838BD; Thu, 20 Jan 2022 16:30:29 +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-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (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 CAE0D8389E for ; Thu, 20 Jan 2022 16:30:26 +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-pf1-x434.google.com with SMTP id x16so2404442pfu.13 for ; Thu, 20 Jan 2022 07:30:26 -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=DSVlRbXB4Gc30pAyBuvP8ULNSVgwj7N6BLNTZ6l0ytg=; b=BVc19z0jDlQa+b6U5MyYMtmE3llakFvl2TDWJcoimk5lWFAokv90MMTpN79dJnCWgR XrnBb66brCKhCekC2qEWWfyF80DQ35pbtUEoxloFM9NPf4HGbmUBm+2cs83JZ/QKMMCd 5mE8YewPULc60S8E4ZKhZ13g9+GTqNUlLGGjzrXCm/bl14Rv+BQqI9+FteEL138bF8ku j7/QZPLdhIwR2OvtM4b6a4tVu6osH5bQHM/HGuOz3yugNrSrcD95UJ5Eyxj9YIPfJtzR l4fOVOYxBXQP5/92g2RqP7UQIL32ZubIseWiq3n6SdbeidO0givO5RooxG8ktPp8aEKU JU9g== 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=DSVlRbXB4Gc30pAyBuvP8ULNSVgwj7N6BLNTZ6l0ytg=; b=Xa1l0SMBZ7T5wu1wM85WnBy0Bo8JbMZYjry51FNX9Aij4ICPFGI+Tf5/0QSuOWBDLf a+vMIqvTbhALwaYco+RalmvaCzGB0vaQPYgtWa4m+Es36qQS21jAio+kdBCFg4RnrMyB NSFdkjkrLiiCTHQKQi6mcPUoapDEd9ul0+36bjhYv4Ep3j/APChsRu3uhJzRVCCaiqNR 7ShX+IDzOwlTVZoNT8MoLO2DKh+Z9F1pXtQiucYgZz5ddmK7OTJRkF65dXVUmeAUT5Bj HFk3DKvQeHxHj/OYYF9Xbm5PEc+UlHgtNP+LlH2tcS3fZKjQ+jAb5DhWUWc/AN2IXNGh ri4Q== X-Gm-Message-State: AOAM531rNeeTQFIbvRSeDNhlhUtAvyF98M/oCM60vVv9bHJ2esHTBd9L eTduE6s8hN8h8Lk7lrXM1cTQSZDlAKBMjA== X-Received: by 2002:a05:6a00:1254:b0:4c2:796d:8769 with SMTP id u20-20020a056a00125400b004c2796d8769mr31295378pfi.85.1642692624989; Thu, 20 Jan 2022 07:30:24 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id w24sm2637871pgl.11.2022.01.20.07.30.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:24 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 06/14] FWU: Calculate CRC32 in gpt_update_mdata() Date: Fri, 21 Jan 2022 00:30:20 +0900 Message-Id: <164269262036.39378.17845071044211742791.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.2 at phobos.denx.de X-Virus-Status: Clean To avoid calculating crc32 in several places, do it in gpt_update_mdata(). This also ensures the mdata crc32 is always sane. Signed-off-by: Masami Hiramatsu --- lib/fwu_updates/fwu_mdata.c | 18 ------------------ lib/fwu_updates/fwu_mdata_gpt_blk.c | 13 ++++++++----- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/lib/fwu_updates/fwu_mdata.c b/lib/fwu_updates/fwu_mdata.c index 252fcf50f6..1324771a71 100644 --- a/lib/fwu_updates/fwu_mdata.c +++ b/lib/fwu_updates/fwu_mdata.c @@ -92,7 +92,6 @@ int fwu_get_active_index(u32 *active_idx) int fwu_update_active_index(u32 active_idx) { int ret; - void *buf; struct fwu_mdata *mdata = NULL; if (active_idx > CONFIG_FWU_NUM_BANKS) { @@ -113,14 +112,6 @@ int fwu_update_active_index(u32 active_idx) mdata->previous_active_index = mdata->active_index; mdata->active_index = active_idx; - /* - * Calculate the crc32 for the updated FWU metadata - * and put the updated value in the FWU metadata crc32 - * field - */ - buf = &mdata->version; - mdata->crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32)); - /* * Now write this updated FWU metadata to both the * FWU metadata partitions @@ -205,7 +196,6 @@ int fwu_mdata_check(void) int fwu_revert_boot_index(void) { int ret; - void *buf; u32 cur_active_index; struct fwu_mdata *mdata = NULL; @@ -223,14 +213,6 @@ int fwu_revert_boot_index(void) mdata->active_index = mdata->previous_active_index; mdata->previous_active_index = cur_active_index; - /* - * Calculate the crc32 for the updated FWU metadata - * and put the updated value in the FWU metadata crc32 - * field - */ - buf = &mdata->version; - mdata->crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32)); - /* * Now write this updated FWU metadata to both the * FWU metadata partitions diff --git a/lib/fwu_updates/fwu_mdata_gpt_blk.c b/lib/fwu_updates/fwu_mdata_gpt_blk.c index 796b08e76f..0259da37c3 100644 --- a/lib/fwu_updates/fwu_mdata_gpt_blk.c +++ b/lib/fwu_updates/fwu_mdata_gpt_blk.c @@ -161,6 +161,14 @@ static int fwu_gpt_update_mdata(struct fwu_mdata *mdata) return -ENODEV; } + /* + * Calculate the crc32 for the updated FWU metadata + * and put the updated value in the FWU metadata crc32 + * field + */ + mdata->crc32 = crc32(0, (void *)&mdata->version, + sizeof(*mdata) - sizeof(u32)); + /* First write the primary partition*/ ret = gpt_write_mdata_partition(desc, mdata, primary_mpart); if (ret < 0) { @@ -457,7 +465,6 @@ int fwu_gpt_get_mdata(struct fwu_mdata **mdata) static int fwu_gpt_set_clear_image_accept(efi_guid_t *img_type_id, u32 bank, u8 action) { - void *buf; int ret, i; u32 nimages; struct fwu_mdata *mdata = NULL; @@ -480,10 +487,6 @@ static int fwu_gpt_set_clear_image_accept(efi_guid_t *img_type_id, else img_bank_info->accepted = 0; - buf = &mdata->version; - mdata->crc32 = crc32(0, buf, sizeof(*mdata) - - sizeof(u32)); - ret = fwu_gpt_update_mdata(mdata); goto out; } From patchwork Thu Jan 20 15:30:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533546 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1676746imu; Thu, 20 Jan 2022 07:30:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJLCNHp0W7knzfcOort0PJ0eoAQDnhSBe+fyrEEyl/8qfFQ/CCVuG371hdMBncz2IDeRjk X-Received: by 2002:a05:6402:2204:: with SMTP id cq4mr9178919edb.383.1642692648759; Thu, 20 Jan 2022 07:30:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692648; cv=none; d=google.com; s=arc-20160816; b=xJZCbyWLbWi9r2CBQs3NvqHWY3bioeirx207/v1BD8DEnqLAnTAHOdE0EKAkF7BR9w O+a7mvxqNlQ2c97C3oRPmyknaugZWtXetURo0x347IZ7VbuLLldsDjn/7SvnbSDalpii Bfoj6uiF4mFwuI3eQPHnvU6PcPqIxSTUt8zNk2ubRX+tYJATMEMzy3rDfAN0Db1xwagd WkjWlxwI+U/Ex49LEzSPtfvZ6P1NUJGm9i5NyxKuztLBjnuMp0uPQxF8pc9EHm5mh+UA WzY3+dzH2Aw3d7oCyTas7qoagwUyxiTYo7nGKUNPqNVBStLm+9C3zFRX8Xo1y0OINcZe 0ttA== 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=bxKyXxb7CGHdTxPJ+1fGaewoFoKvBOjzbp6rBqZ6smA=; b=K15CVMPN/PTBMdWAAcgSLkGFR8iCQja0Ag/ERr7+yJ/J+3SwVMH67UjOIRflW6ASFK ynH7maJ5isPodTViZI4YgzScwdMyEOPO3msUbl70rhkqZnJwcQClviKd7Gjmc3rsei9j 9m9L7jIJb60cnvRjgt9gOoil0jgJI36TWEvEp6iMMLIWAapN0yLQdGeyVXsvejoJ8Q7B 2nodIpA6jP6V0Z8pd3uQJu1q4HUn3DNP4jwp3NFJrzEO0GjW4yuwrQtkbHaOAdSc+i58 a+Byl9lUHD22fEe3YbrZIcGryOf8WJd1k/REX6MYQGzv9YdqKrjLZpaF6fe1vrw+KT9f eJDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oe5+37AC; 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 o10si2283001ejy.529.2022.01.20.07.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:48 -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=oe5+37AC; 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 1ECC0838CB; Thu, 20 Jan 2022 16:30:41 +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="oe5+37AC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9C52D838CB; Thu, 20 Jan 2022 16:30:39 +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-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 C394C838C7 for ; Thu, 20 Jan 2022 16:30:36 +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-x629.google.com with SMTP id d1so5449909plh.10 for ; Thu, 20 Jan 2022 07:30:36 -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=bxKyXxb7CGHdTxPJ+1fGaewoFoKvBOjzbp6rBqZ6smA=; b=oe5+37ACjEK8oOD/hD3g54TNiacTxmlzy+M094MFs7Gn51ZTZvvs4OrKAgKSLKR2wL /bOIeB5TSFuqfQCv4UhGMZJ8FpeF8reTAu2Yf7AtchLw6TUCYSUiUqeJU6XtELhnrhvN QkM6lmHGyM/zMcR8u22Q2optOVna3HEipLj0/xQ92f1D6vRZ/cZH+3XWmKf/GyVveciK kGR7q4WAZvwf6/q4EBhctZ2DIeZrKpfeHufjbus35aAIoW+JS6M53NNQJbMThQf13F3/ inhGkSZdyXOHB2FRudCUzVQP+t2tQZmQ3O4jSVwhl1tVv08hsEBbwqG6uAldkpZCJ6Fq R6fw== 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=bxKyXxb7CGHdTxPJ+1fGaewoFoKvBOjzbp6rBqZ6smA=; b=s/VZizic3QneJVZ5tI6AyaNFi7Z+cKGD7O4l+E+US5w+Z3rq12pPEFO28qMzlrGz7d Z9Dprf4YSuTmXH3MFhhz4USK0mPgT58TAAjVGwVRXzmpzTf+G490cSBKStnR1Z8ePR92 OxRbu0cbVXV6ocAEpVrHUOSJ9U+fsaAgD+9JXJPAXN7fHwZnXLelY4Jjd+dszNI9el/S utXYdgwOp1cC+h0pWo93K5ViHxt/oa1FJLcg+2gl0cf6qsDZMDYW28ESVP/L5/RDdXGT VQIBCrZf59ovr9YS2dojY6BgChwoVqsR9gFt4mzwCHD2d+VEuQfKP6DEr36I4nl5C8bC cF8Q== X-Gm-Message-State: AOAM531yKaVc06DakQUezZB4KBDZooipb95RMPpIOZvjF3oRRKegUDLX wrmdP+ueX8i5mq1Y8DCVb37//lcvgiMZBA== X-Received: by 2002:a17:90a:6d61:: with SMTP id z88mr11156578pjj.165.1642692634996; Thu, 20 Jan 2022 07:30:34 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id u21sm3852321pfi.149.2022.01.20.07.30.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:34 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 07/14] FWU: Free metadata copy if gpt_get_mdata() failed Date: Fri, 21 Jan 2022 00:30:30 +0900 Message-Id: <164269263036.39378.10026871398998590929.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.2 at phobos.denx.de X-Virus-Status: Clean It is better if a function which returns an error then release all allocated memory resources. This simplifies the mind model and less chance to forgot to free memory and double free. Signed-off-by: Masami Hiramatsu --- lib/fwu_updates/fwu_mdata_gpt_blk.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/fwu_updates/fwu_mdata_gpt_blk.c b/lib/fwu_updates/fwu_mdata_gpt_blk.c index 0259da37c3..7f8b8b68fc 100644 --- a/lib/fwu_updates/fwu_mdata_gpt_blk.c +++ b/lib/fwu_updates/fwu_mdata_gpt_blk.c @@ -215,7 +215,8 @@ static int gpt_get_mdata(struct fwu_mdata **mdata) ret = gpt_read_mdata(desc, *mdata, primary_mpart); if (ret < 0) { log_err("Failed to read the FWU metadata from the device\n"); - return -EIO; + ret = -EIO; + goto out; } ret = fwu_verify_mdata(*mdata, 1); @@ -230,7 +231,8 @@ static int gpt_get_mdata(struct fwu_mdata **mdata) ret = gpt_read_mdata(desc, *mdata, secondary_mpart); if (ret < 0) { log_err("Failed to read the FWU metadata from the device\n"); - return -EIO; + ret = -EIO; + goto out; } ret = fwu_verify_mdata(*mdata, 0); @@ -238,7 +240,10 @@ static int gpt_get_mdata(struct fwu_mdata **mdata) return 0; /* Both the FWU metadata copies are corrupted. */ - return -1; + ret = -1; +out: + free(*mdata); + return ret; } static int gpt_check_mdata_validity(void) From patchwork Thu Jan 20 15:30:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533547 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1676946imu; Thu, 20 Jan 2022 07:30:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMfYlQKqWlBrx6mLw/BsjyOolRoX7mjeDIBz3acywE3Rolv9bX39yGJUz4oMDu8F8n78BK X-Received: by 2002:aa7:cf8c:: with SMTP id z12mr29126512edx.93.1642692658800; Thu, 20 Jan 2022 07:30:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692658; cv=none; d=google.com; s=arc-20160816; b=r4pHF3Bv1r5GFQffseyvkl2oNCl2JKJzBlaVvn+RL3J2nkF5X2ExdyfgAyOzPFuR9i 6sYPRQN8G+gGTMfjlJrELXpSBR1nTzU1KBVAJfXhYwQmlcBnXZcD3G+xiMS0qpbl31xV pzKeV/A47tu2ZNDhgpW3kYH7+foqlHIZcjY95xqniE7Imo4kjgvM365HznYK2NhpwvH7 lkf314dNvONgCnpoFdmKSMidNxVVOwG9gARtg6cRtjxNtNlrkvAY0jTMfBn0n3wZsTZw OTmPBTzwAtJiSzgedLijG68TND6VK+X8nGpXBdixSbWVZN1re3RQw6gxWxS9bphkzP4H QJbA== 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=W1C9qj84hBwy+8QqJxCIUXEcLaCgpoKHW2kEN9Ee+TM=; b=GYGsNNXLsaT7ahgc/scIvmdv4PgWd0OrxO1VW84EV48YsF0ivghsJaSaA/5NIP23Qa Tw2FvqtJUwuYfx+3GIwZDLcGtBwr2J042QbTCJMjzTWJx+/sZw3bdNfCx7+pcUQwJ1Za Wklgq1eHcPXnczzMBlGQF+GtTrLptpkTNSTDrjF0KH5hq9dOv9qYaxsxfgHMWgZxJ0AH ORY5K0JsdenutVaFnTayKOOeUoIGB9khjw1ydTNhoDJ2RDVhFsbXUQMp0311yyb8V+vw 9fsmyBC4KY3/qp6BABUObwKxcEdZMmt2cD1yc/EaEofQyKORuycQziUuIJOVmNwlsK8f n8Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=puaiyDG5; 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 dn21si2179132ejc.791.2022.01.20.07.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:58 -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=puaiyDG5; 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 CF3CA838C4; Thu, 20 Jan 2022 16:30:51 +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="puaiyDG5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2A124838D6; Thu, 20 Jan 2022 16:30:50 +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-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (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 C46C683890 for ; Thu, 20 Jan 2022 16:30:46 +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-x1035.google.com with SMTP id s2-20020a17090ad48200b001b501977b23so5451249pju.2 for ; Thu, 20 Jan 2022 07:30:46 -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=W1C9qj84hBwy+8QqJxCIUXEcLaCgpoKHW2kEN9Ee+TM=; b=puaiyDG5rXQtr9ZNodydINeO/oJqgf4kYzBkHJOvFxAXZO8rtgF9wKWAT9yCNjkMJG zOOPhltT8be6gPlkaLYtrN7GBQULZ3hRM5SjYCQ8Zyz6qi7w6Vqbuy21xMfRINfRxbX+ ltDaz7dk2NoSo9HZyAHhEnMCVe18mo7p5MFK8Zok8wAF69Uz45T1sI8W7sSBBYhcA/oA jYOcV+7qqpPlY0fz6LsSFQxm3nWH/3B945WLAeTkWSNfLzkbYgQXis8lo/ABSLcV5n7A 1LGAfIp2EOsxkO3Yx20jOmT8NK+i24UtFydTkpt0/uGoCCwhRfKo84oSAdXXjtuf86me 6c0Q== 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=W1C9qj84hBwy+8QqJxCIUXEcLaCgpoKHW2kEN9Ee+TM=; b=McYwUr2U2sSvxRY6Txx3PHxnyU7KAt27u8sR7bb8YdYgIsmnnbEcfJTeZyYG81cbeU awRHvUR1/Ad92qm7SaoQKpyB3C/+vpUm0DY3q6x74jACKk1V0+coQLt7LSe2fSI3RFDw ha0ROss4VWkJtbPM4+pAWmBHKCUDknnwGekoP9pVOJLCizbFWW5qxp2kC7lDYKwo3dGE 0McVReMUh8fjwhS6Q/kW/ToJeqLH6UrWvOVDDlqghh6byyzvUCq/saqun4JgUicU+Nze EIjZhhnCTuwCFclnaktdw4xSDDAbP3TAlkCU0BjLVNcHD8cIdUVdfMn4ducBEKfI9L91 LuiQ== X-Gm-Message-State: AOAM531Hb2ctP7I48IWD9i5sz2j1sEew41Uf+EQ3DbT5V5NXKwc+DwZ/ VNAlSJsT+9uT0iBC0wbhkTTeXsuBm9h2/Q== X-Received: by 2002:a17:90b:1e4c:: with SMTP id pi12mr11372169pjb.224.1642692644976; Thu, 20 Jan 2022 07:30:44 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id l15sm2597365pgh.27.2022.01.20.07.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:44 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 08/14] FWU: Move FWU metadata operation code in fwu_mdata.c Date: Fri, 21 Jan 2022 00:30:40 +0900 Message-Id: <164269264036.39378.11024708444178044567.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.2 at phobos.denx.de X-Virus-Status: Clean Remove some FWU metadata operations which only access or modify the metadata itself from fwu_mdata_ops and move it in fwu_mdata.c. Signed-off-by: Masami Hiramatsu --- include/fwu.h | 9 --- lib/fwu_updates/fwu_mdata.c | 105 ++++++++++++++++++++++++----------- lib/fwu_updates/fwu_mdata_gpt_blk.c | 85 ---------------------------- 3 files changed, 71 insertions(+), 128 deletions(-) diff --git a/include/fwu.h b/include/fwu.h index 6c9b64a9f1..7af94988b7 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -14,26 +14,17 @@ struct fwu_mdata; /** - * @get_active_index: get the current active_index value * @get_image_alt_num: get the alt number to be used for the image * @mdata_check: check the validity of the FWU metadata partitions - * @set_accept_image: set the accepted bit for the image - * @clear_accept_image: clear the accepted bit for the image * @get_mdata() - Get a FWU metadata copy * @update_mdata() - Update the FWU metadata copy */ struct fwu_mdata_ops { - int (*get_active_index)(u32 *active_idx); - int (*get_image_alt_num)(efi_guid_t image_type_id, u32 update_bank, int *alt_num); int (*mdata_check)(void); - int (*set_accept_image)(efi_guid_t *img_type_id, u32 bank); - - int (*clear_accept_image)(efi_guid_t *img_type_id, u32 bank); - int (*get_mdata)(struct fwu_mdata **mdata); int (*update_mdata)(struct fwu_mdata *mdata); diff --git a/lib/fwu_updates/fwu_mdata.c b/lib/fwu_updates/fwu_mdata.c index 1324771a71..505f4f3630 100644 --- a/lib/fwu_updates/fwu_mdata.c +++ b/lib/fwu_updates/fwu_mdata.c @@ -3,6 +3,7 @@ * Copyright (c) 2021, Linaro Limited */ +#include #include #include #include @@ -12,6 +13,9 @@ #include #include +#define IMAGE_ACCEPT_SET BIT(0) +#define IMAGE_ACCEPT_CLEAR BIT(1) + static struct fwu_mdata_ops *get_fwu_mdata_ops(void) { struct fwu_mdata_ops *ops; @@ -66,18 +70,28 @@ int fwu_verify_mdata(struct fwu_mdata *mdata, bool pri_part) */ int fwu_get_active_index(u32 *active_idx) { - struct fwu_mdata_ops *ops; + int ret; + struct fwu_mdata *mdata = NULL; - ops = get_fwu_mdata_ops(); - if (!ops) - return -EPROTONOSUPPORT; + ret = fwu_get_mdata(&mdata); + if (ret < 0) { + log_err("Unable to get valid FWU metadata\n"); + return ret; + } - if (!ops->get_active_index) { - log_err("get_active_index() method not defined for the platform\n"); - return -ENOSYS; + /* + * Found the FWU metadata partition, now read the active_index + * value + */ + *active_idx = mdata->active_index; + if (*active_idx > CONFIG_FWU_NUM_BANKS - 1) { + printf("Active index value read is incorrect\n"); + ret = -EINVAL; } - return ops->get_active_index(active_idx); + free(mdata); + + return ret; } /** @@ -197,12 +211,12 @@ int fwu_revert_boot_index(void) { int ret; u32 cur_active_index; - struct fwu_mdata *mdata = NULL; + struct fwu_mdata *mdata; ret = fwu_get_mdata(&mdata); if (ret < 0) { log_err("Unable to get valid FWU metadata\n"); - goto out; + return ret; } /* @@ -223,6 +237,49 @@ int fwu_revert_boot_index(void) ret = -EIO; } + free(mdata); + + return ret; +} + +static int fwu_set_clear_image_accept(efi_guid_t *img_type_id, + u32 bank, u8 action) +{ + void *buf; + int ret, i; + u32 nimages; + struct fwu_mdata *mdata = NULL; + struct fwu_image_entry *img_entry; + struct fwu_image_bank_info *img_bank_info; + + ret = fwu_get_mdata(&mdata); + if (ret < 0) { + log_err("Unable to get valid FWU metadata\n"); + return ret; + } + + nimages = CONFIG_FWU_NUM_IMAGES_PER_BANK; + img_entry = &mdata->img_entry[0]; + for (i = 0; i < nimages; i++) { + if (!guidcmp(&img_entry[i].image_type_uuid, img_type_id)) { + img_bank_info = &img_entry[i].img_bank_info[bank]; + if (action == IMAGE_ACCEPT_SET) + img_bank_info->accepted |= FWU_IMAGE_ACCEPTED; + else + img_bank_info->accepted = 0; + + buf = &mdata->version; + mdata->crc32 = crc32(0, buf, sizeof(*mdata) - + sizeof(u32)); + + ret = fwu_update_mdata(mdata); + goto out; + } + } + + /* Image not found */ + ret = -EINVAL; + out: free(mdata); @@ -244,18 +301,8 @@ out: */ int fwu_accept_image(efi_guid_t *img_type_id, u32 bank) { - struct fwu_mdata_ops *ops; - - ops = get_fwu_mdata_ops(); - if (!ops) - return -EPROTONOSUPPORT; - - if (!ops->set_accept_image) { - log_err("set_accept_image() method not defined for the platform\n"); - return -ENOSYS; - } - - return ops->set_accept_image(img_type_id, bank); + return fwu_set_clear_image_accept(img_type_id, bank, + IMAGE_ACCEPT_SET); } /** @@ -274,18 +321,8 @@ int fwu_accept_image(efi_guid_t *img_type_id, u32 bank) */ int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank) { - struct fwu_mdata_ops *ops; - - ops = get_fwu_mdata_ops(); - if (!ops) - return -EPROTONOSUPPORT; - - if (!ops->clear_accept_image) { - log_err("clear_accept_image() method not defined for the platform\n"); - return -ENOSYS; - } - - return ops->clear_accept_image(img_type_id, bank); + return fwu_set_clear_image_accept(img_type_id, bank, + IMAGE_ACCEPT_CLEAR); } /** diff --git a/lib/fwu_updates/fwu_mdata_gpt_blk.c b/lib/fwu_updates/fwu_mdata_gpt_blk.c index 7f8b8b68fc..af9b1adf94 100644 --- a/lib/fwu_updates/fwu_mdata_gpt_blk.c +++ b/lib/fwu_updates/fwu_mdata_gpt_blk.c @@ -24,9 +24,6 @@ #define MDATA_READ BIT(0) #define MDATA_WRITE BIT(1) -#define IMAGE_ACCEPT_SET BIT(0) -#define IMAGE_ACCEPT_CLEAR BIT(1) - static int gpt_get_mdata_partitions(struct blk_desc *desc, u16 *primary_mpart, u16 *secondary_mpart) @@ -335,34 +332,6 @@ out: return ret; } -int fwu_gpt_get_active_index(u32 *active_idx) -{ - int ret; - struct fwu_mdata *mdata = NULL; - - ret = gpt_get_mdata(&mdata); - if (ret < 0) { - log_err("Unable to get valid FWU metadata\n"); - goto out; - } - - /* - * Found the FWU metadata partition, now read the active_index - * value - */ - *active_idx = mdata->active_index; - if (*active_idx > CONFIG_FWU_NUM_BANKS - 1) { - printf("Active index value read is incorrect\n"); - ret = -EINVAL; - goto out; - } - -out: - free(mdata); - - return ret; -} - static int gpt_get_image_alt_num(struct blk_desc *desc, efi_guid_t image_type_id, u32 update_bank, int *alt_no) @@ -467,63 +436,9 @@ int fwu_gpt_get_mdata(struct fwu_mdata **mdata) return gpt_get_mdata(mdata); } -static int fwu_gpt_set_clear_image_accept(efi_guid_t *img_type_id, - u32 bank, u8 action) -{ - int ret, i; - u32 nimages; - struct fwu_mdata *mdata = NULL; - struct fwu_image_entry *img_entry; - struct fwu_image_bank_info *img_bank_info; - - ret = gpt_get_mdata(&mdata); - if (ret < 0) { - log_err("Unable to get valid FWU metadata\n"); - goto out; - } - - nimages = CONFIG_FWU_NUM_IMAGES_PER_BANK; - img_entry = &mdata->img_entry[0]; - for (i = 0; i < nimages; i++) { - if (!guidcmp(&img_entry[i].image_type_uuid, img_type_id)) { - img_bank_info = &img_entry[i].img_bank_info[bank]; - if (action == IMAGE_ACCEPT_SET) - img_bank_info->accepted |= FWU_IMAGE_ACCEPTED; - else - img_bank_info->accepted = 0; - - ret = fwu_gpt_update_mdata(mdata); - goto out; - } - } - - /* Image not found */ - ret = -EINVAL; - -out: - free(mdata); - - return ret; -} - -static int fwu_gpt_accept_image(efi_guid_t *img_type_id, u32 bank) -{ - return fwu_gpt_set_clear_image_accept(img_type_id, bank, - IMAGE_ACCEPT_SET); -} - -static int fwu_gpt_clear_accept_image(efi_guid_t *img_type_id, u32 bank) -{ - return fwu_gpt_set_clear_image_accept(img_type_id, bank, - IMAGE_ACCEPT_CLEAR); -} - struct fwu_mdata_ops fwu_gpt_blk_ops = { - .get_active_index = fwu_gpt_get_active_index, .get_image_alt_num = fwu_gpt_get_image_alt_num, .mdata_check = fwu_gpt_mdata_check, - .set_accept_image = fwu_gpt_accept_image, - .clear_accept_image = fwu_gpt_clear_accept_image, .get_mdata = fwu_gpt_get_mdata, .update_mdata = fwu_gpt_update_mdata, }; From patchwork Thu Jan 20 15:30:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533548 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1677149imu; Thu, 20 Jan 2022 07:31:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJznKcbmJNpNi73Rt1SC+fHYo5pDzUDRgWK+xgaCfs9Ktp5jSGZdqOGnPtKaK3RIA6oLJrMh X-Received: by 2002:a05:6402:4315:: with SMTP id m21mr37071171edc.67.1642692668726; Thu, 20 Jan 2022 07:31:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692668; cv=none; d=google.com; s=arc-20160816; b=x02adw0wUcYLE9g+ILup5erJoS+/Y1GKwgfBAeExs3SQ6Dv99JvpkLu9cMruGFD8eJ FWAy/U7DVTKQmG4RXUSlM6XaYP6cZr3cVwd/Bp/sPXvlhGjFq6tDOmu7icFq5JQJYb8N +g8iQjkUkVQKWKT89ngilh9YzjI9an27Aqjb/2JNDbrdB/fCBjxvSZQSfYI81zg3nWaV st6bEXf4aZu7L9OrMn6oQvfYNL3k7WMBEkpG88fAQogZEv5YfRA40ywOBZ/l6NogpHXw zfP8EAjuIXj5H0DmuQmhqtI5z8nFElR4YTUHBw2r3l91Up/M1R3tF5yGRgc5FRTMZb+H omMg== 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=XEmObKmlmifU3tLu1J03zn6GRA8ZY8hMymHL7IiI85I=; b=k7mrrvJHIKRkQ99jICtyBbKOQcFy3DSunQdwCzf0UmBKPG9+SYRwclkO6LSanQpb9H rfjRamgVJMasJq/hUFlwM0lOdH87CPvLVwyyskhQsnJGvOzzRL6EJMw/M7nkA6EsJhAw FhpZXoQ5wLvUTQuv79JAVZxWoNDOsoV0yJBwlZ/UjrPU3N8SEqphOQ602H/tpdQ7rFkP yx12OzPltrH2jqYf38/pL0vNplA1uWhtEoyZVlu77jWXwCDC/guEf3y9ycOivr21Wx7h ghpFcOEqfcy3xZ9vMv8nc90+65uM/81HmCfrAGGylwnkoCLNBOUTOURgu4/GNvZC6J3a MU+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M2H3x7ux; 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 t22si2386333ejf.657.2022.01.20.07.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:31:08 -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=M2H3x7ux; 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 C891D838BD; Thu, 20 Jan 2022 16:31:01 +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="M2H3x7ux"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3E7C4838BB; Thu, 20 Jan 2022 16:31:00 +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-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) (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 1AE2F838BD for ; Thu, 20 Jan 2022 16:30:57 +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-pf1-x42b.google.com with SMTP id u130so1617088pfc.2 for ; Thu, 20 Jan 2022 07:30:57 -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=XEmObKmlmifU3tLu1J03zn6GRA8ZY8hMymHL7IiI85I=; b=M2H3x7uxJJewhe5BP1GhNj0z3Dv/Qkm//xYJ8APczZDM26OsDc4h27zoplxbZOuhy3 GGRgek+2wEaz4GgT+5Fp5wBroG24k79lYu9vLWbTRL1NghvjpXlF0JswWb7MwtowhHYI FOKifIUmiFQfqV0K85K8eWK4x5JAAJ18eSEIgfsXlkMNmPPQFrtdLfJq/YoN+8yPQv2K SSIX1xBwAGFSdSnCfXlkqriLl+C7seF5NrSQ2DenonW7Z4awmls+mrI1l4ZFU0s1s5eI CXezkGCl84J78U9OktVdVS1eJcJ/BBkUdStyZlBRCTSxFJfjYcLoU7Blf/6Sz366hbzl HfZA== 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=XEmObKmlmifU3tLu1J03zn6GRA8ZY8hMymHL7IiI85I=; b=3jRoj5uMOCFRrPgdOPLseB8zsz3KXUZl/ViLVCtNdecf3RmHbTcv3t4CrxHJrD/7GL BLqYhteiarM17qoyPtcQBfqxClpeSwnTrFhTS4qMu3PEPom1+aQy1l26zuv9vMl7VVZv 8oY75sPnzti7L7dORP4WvFzCLlAGbT7SvUoqhuuzsp4HZkMR9ePEzLRTZRxd7GbXrFhZ FvMm6Q3Mxrkf/djgdka6vCfU8ExqY85PSGn5Q98LPQMyyiD/XmC1JWgHtDrTAtiT2QRJ ZgcsHL+ASY6bVxbkNALsVnz8cdhJo/bI4mhneFusIl49tj2dPsexk0C/BjvX7vZk0M7Y sWZw== X-Gm-Message-State: AOAM532s5bS3QmO0wPYrLpgd7br7+f8LHSExgpz0ZXONPMU/Tsg10LbG pr+PcWdAFqePKUaYiEUxaucOL+7QDxiU6g== X-Received: by 2002:a63:705c:: with SMTP id a28mr31799457pgn.339.1642692655012; Thu, 20 Jan 2022 07:30:55 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id q9sm3758677pfj.113.2022.01.20.07.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:54 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 09/14] synquacer: Update for TBBR based new FIP layout Date: Fri, 21 Jan 2022 00:30:50 +0900 Message-Id: <164269265032.39378.8292306024930547380.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.2 at phobos.denx.de X-Virus-Status: Clean This changes SPI NOR flash partition layout for TBBR and also make the U-Boot as position independent executable again because BL33 is loaded on the memory. With enabling TBBR, TF-A BL2 loads all BL3x images from FIP image, and the U-Boot image is added to the FIP image as BL33, and loaded to memory when boot instead of XIP on SPI NOR flash. To avoid mixing up with the legacy images, this new FIP image is stored on unused area (0x600000-) and the U-Boot env vars are also stored at 0x580000 so that it will not break existing EDK2 area. Signed-off-by: Masami Hiramatsu --- .../dts/synquacer-sc2a11-developerbox-u-boot.dtsi | 26 ++++++++++++++------ configs/synquacer_developerbox_defconfig | 5 ++-- include/configs/synquacer.h | 4 +-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi b/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi index 7a56116d6f..095727e03c 100644 --- a/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi +++ b/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi @@ -56,7 +56,7 @@ }; partition@180000 { - label = "FIP-TFA"; + label = "LegacyFIP"; reg = <0x180000 0x78000>; }; @@ -66,18 +66,28 @@ }; partition@200000 { - label = "U-Boot"; - reg = <0x200000 0x100000>; + label = "EDK2"; + reg = <0x200000 0x200000>; }; - partition@300000 { - label = "UBoot-Env"; - reg = <0x300000 0x100000>; + partition@400000 { + label = "EDK2-Env"; + reg = <0x400000 0x100000>; }; partition@500000 { - label = "Ex-OPTEE"; - reg = <0x500000 0x200000>; + label = "Metadata"; + reg = <0x500000 0x80000>; + }; + + partition@580000 { + label = "UBoot-Env"; + reg = <0x580000 0x80000>; + }; + + partition@600000 { + label = "FIP"; + reg = <0x600000 0x400000>; }; }; }; diff --git a/configs/synquacer_developerbox_defconfig b/configs/synquacer_developerbox_defconfig index da57dc288f..484f6b7336 100644 --- a/configs/synquacer_developerbox_defconfig +++ b/configs/synquacer_developerbox_defconfig @@ -1,9 +1,10 @@ CONFIG_ARM=y CONFIG_ARCH_SYNQUACER=y -CONFIG_SYS_TEXT_BASE=0x08200000 +CONFIG_POSITION_INDEPENDENT=y +CONFIG_SYS_TEXT_BASE=0 CONFIG_SYS_MALLOC_LEN=0x1000000 CONFIG_ENV_SIZE=0x30000 -CONFIG_ENV_OFFSET=0x300000 +CONFIG_ENV_OFFSET=0x580000 CONFIG_ENV_SECT_SIZE=0x10000 CONFIG_DM_GPIO=y CONFIG_DEFAULT_DEVICE_TREE="synquacer-sc2a11-developerbox" diff --git a/include/configs/synquacer.h b/include/configs/synquacer.h index 0409589152..6d67bd2af5 100644 --- a/include/configs/synquacer.h +++ b/include/configs/synquacer.h @@ -48,9 +48,7 @@ /* Since U-Boot 64bit PCIe support is limited, disable 64bit MMIO support */ #define DEFAULT_DFU_ALT_INFO "dfu_alt_info=" \ - "mtd nor1=u-boot.bin raw 200000 100000;" \ - "fip.bin raw 180000 78000;" \ - "optee.bin raw 500000 100000\0" + "mtd nor1=fip.bin raw 600000 400000\0" /* Distro boot settings */ #ifndef CONFIG_SPL_BUILD From patchwork Thu Jan 20 15:31:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533549 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1677336imu; Thu, 20 Jan 2022 07:31:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBxCrijG9HTjeLmXcl4YUKu8CDM54fGSxrvaxdUCafiooFz9l9jCToHC/1IVwHDtZHfeZc X-Received: by 2002:a17:906:7003:: with SMTP id n3mr2230610ejj.160.1642692679157; Thu, 20 Jan 2022 07:31:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692679; cv=none; d=google.com; s=arc-20160816; b=beqkCx0lCzsgKfyzMry/mwYrwS49AnibR81UFA2S2vHHplkYKER3HjxEXukfwokoZG 2aJRKK67zFZC2ZDB+O7mlj8FhScF0V1D8sd3WxFCCwB99EHAIUt4Bc4aOjxigvGk5FUm AMqc3sADvu0s2bj0Z+Vf4TPhAVsS3nP+C0hWElH1gZ1Eu7r1Cuz/2Ol7y6h6Sj/Eox79 xn1+HnpyBi+A6ikxyo0xHurQUM51m0blbRc4albD/Q6tbR+5wioxiF7Gcz/TmCrcRU4b fqv49ZfSs8kKP1LZtYrRKTh2msvRTwV7iBtBA0YrHzeEgx9UD6KaH9zFNkRWy8oszp3a MMIQ== 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=D4Zki6YkegQ2RC+XsT/lrVRFJ/d4rQXSkd2m50V6YWk=; b=0XJXRQtrPRAImeKGyrF0t96I6ZxXcefnF+fucX9S340KxAiLt39W5NXQI3NYleBXqG QdusHOuCNimknQ8FcGjl1hyT/7R9vC9rKkooBR5k6/2sjPbLL98YXviSIFFrkMWic1f9 rgnA4Es0DEJHTWq0Setx/4ptX7mc41bbaI0hr0oyRCZ4F2TR5OiONfzsPft7W0r6D+2m 8LzfzAIySn96KsIJfV0qPJ1DLGauBp48J/bozKllqjKM2yGXuhZMqIGHJZiawxq5zcJJ 9fcsRTX9QJpMQNaERAhCBMajqTl0+IJzidERvzMVLEIY5oXNmvPkxUd2L0imGmSDRWKw ng8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="vh/H7b4o"; 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 l24si2184684edc.272.2022.01.20.07.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:31:19 -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="vh/H7b4o"; 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 5BF76838D4; Thu, 20 Jan 2022 16:31:11 +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="vh/H7b4o"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 175AE838AE; Thu, 20 Jan 2022 16:31:10 +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-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 2210E838DA for ; Thu, 20 Jan 2022 16:31: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-x62d.google.com with SMTP id n11so5477229plf.4 for ; Thu, 20 Jan 2022 07:31: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=D4Zki6YkegQ2RC+XsT/lrVRFJ/d4rQXSkd2m50V6YWk=; b=vh/H7b4oBUwESRCin+d2QJgZh4T4bWxkYzu6u3ZeoaFggTdllYlbSZs+xLLr9l7uKf PagJCTUjW3sfQRyf2yRO1m4Hoth6s3Y8DdFXI9EoS2cZZWac8j1fNIaT0bhBfRDccc2H nQdsXBKQWiQkzvSSNt0Lg8uhy/R3/aPp4UkTwoCDefkzYuc2JrcYhQG2gVMuTbuZCTdc wikdkc8F+D76qlwr8fSQG2N7MXGLlYn4rRGX1PchEk6SVfYC4svIbILc9KbZlIM23HI6 lTUNGSeU+64Km240Fbl4yOS8g03TSLAyL+6gDXVtHw+NSLZ2H1WZOtkLciN/hcPcStIe NwQA== 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=D4Zki6YkegQ2RC+XsT/lrVRFJ/d4rQXSkd2m50V6YWk=; b=HdQ23/twdIWEJyJXC82dx8G7xRg659ctfp1bzQCbzEpB2TNU6Sfdh9hpnxFoMdej04 JtXNVEslpLI/vfFOrigCEafpOSslQbMTX/s8HJ8xWG5G4TtmVUvM+ZIadze1FAmkMv2V pFXDcDuMSQ3KqLF5HNbyOYbgVBQ/mY3dTOl8BnXbI1g8rJR7bqT288EDCyBgyrFmK8nP 37hCdPjLCeMVyebF/abMLZBjNIuJbjVs+H+Pfh1xAhlY/yPSn4vewPtkV9fEHKyuQOTg rI7UykG6bHPTIg5rZYj+Y8RvD0X6YlF3Lgp6zZzt3Sz3noIFTaXjhFcwlGWjaai+UDyH JABQ== X-Gm-Message-State: AOAM5326qHXkxQhpno5OshjCSEvCd4O2KkImMxf6H9omrgSrSrU+zg7K tejcVpXgF4AWVBMX/cpjlhXCihQbXFCIJQ== X-Received: by 2002:a17:90a:5d17:: with SMTP id s23mr11406455pji.65.1642692665193; Thu, 20 Jan 2022 07:31:05 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id g4sm3896513pfv.8.2022.01.20.07.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:31:04 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 10/14] FWU: Reboot soon after successfully install the new firmware Date: Fri, 21 Jan 2022 00:31:00 +0900 Message-Id: <164269266038.39378.1931983995518536620.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.2 at phobos.denx.de X-Virus-Status: Clean Reboot to the trial state soon after successfully installing the new firmware to the next bank and updating the active_index. This is enabled by CONFIG_FWU_REBOOT_AFTER_UPDATE and is a recommended option. Signed-off-by: Masami Hiramatsu --- lib/efi_loader/efi_capsule.c | 10 ++++++++-- lib/fwu_updates/Kconfig | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 83c89a0cbb..0928425b5f 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -1355,10 +1355,16 @@ efi_status_t efi_launch_capsules(void) } else { log_debug("Successfully updated the active_index\n"); status = fwu_trial_state_ctr_start(); - if (status < 0) + if (status < 0) { ret = EFI_DEVICE_ERROR; - else + } else { ret = EFI_SUCCESS; + if (IS_ENABLED(CONFIG_FWU_REBOOT_AFTER_UPDATE)) { + log_info("New firmware is installed in bank#%d. Reboot from that bank.\n", + update_index); + do_reset(NULL, 0, 0, NULL); + } + } } } else if (capsule_update == true && update_status == false) { log_err("All capsules were not updated. Not updating FWU metadata\n"); diff --git a/lib/fwu_updates/Kconfig b/lib/fwu_updates/Kconfig index 6de28e0c9c..0940a90747 100644 --- a/lib/fwu_updates/Kconfig +++ b/lib/fwu_updates/Kconfig @@ -29,3 +29,12 @@ config FWU_TRIAL_STATE_CNT With FWU Multi Bank Update feature enabled, number of times the platform is allowed to boot in Trial State after an update. + +config FWU_REBOOT_AFTER_UPDATE + bool "Reboot soon after installing new firmware" + depends on FWU_MULTI_BANK_UPDATE + default y + help + Reboot the machine soon after installing a new firmware + and start trial boot. You can disable this option for + debugging or FWU development, but recommended to enable it. From patchwork Thu Jan 20 15:31:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533550 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1677476imu; Thu, 20 Jan 2022 07:31:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1H5MfpOiIp9i3tAgnrBSW3LO+8ESukVlomDi342vAdtYTQemvY+KgTNDUzRYKXqhKNvwV X-Received: by 2002:a17:906:1744:: with SMTP id d4mr30299992eje.569.1642692689270; Thu, 20 Jan 2022 07:31:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692689; cv=none; d=google.com; s=arc-20160816; b=McoGlIUwBHoEKqM7CrT5m64vmK8rRE9bcY2QumGlm8KHF16rT2s2EW1jSmL2lSjDCK DhlHmLE0EOHyeofLCE0YJhD1V8CDLqsgo72oTGyPvL1ukVtE/OlO4W3L6F9muUTQlu4W FU/SjYUl9+tkWBDma6IHS+o2yThT+qAMNSi7Ie8zzN8d2NLA9Th5iFJurx1V3MJAOBJS CrzdceNTnx5pVWVNNGfodtQb6UEN09WPgDXd/0bj3uWuU80en4xU+IMdw9ouDYKdsNXU WkcnWI5fF3GqESQcNpzWMhL6eFIM1ALMnrmhLz1rApbxD48gaue2rWmK4lxtzHKnbbHg 6GQw== 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=CNxP4yuPQA/1DdN5JN2f2VwcHuCd9bwF9iKzqvnifYQ=; b=UpiNC3X+2UBlVn1UaYPfqI11FO/z5521N9UQN9PthL6DxBthcJw4NI/ziAZAkjRUPw dSKF/wQhq8h4h7s5tt8jCgqEpPIvcYbIVdnk8aJsTfeMwdu5oJWJBPAR8dQOWd9wm3bR W5/KoXuIyb3XD8++gelGMtlHMgwIVHAOFy17MxoEEjnp40sJzGhG0+gCP6MI8SgMy0RH Cxtv5OOeukJH2W8+Ju00xi0CDLL75iRnVvfWs6gOlPPrjw+9vNFVGkOSv9kE2nkpuWsF 41z3VRabotPxXYx1LXQAihBhNKZOmIKFrCOsTrWe1x5exXpbtDcjJFB2qJyfHZRlIAJY 63CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GQh+Kyn4; 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 dd8si2517919ejc.344.2022.01.20.07.31.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:31:29 -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=GQh+Kyn4; 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 CC61C838CB; Thu, 20 Jan 2022 16:31: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="GQh+Kyn4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3E5D7838CB; Thu, 20 Jan 2022 16:31:20 +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-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 EBEFB838DB for ; Thu, 20 Jan 2022 16:31:16 +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 d7so5442287plr.12 for ; Thu, 20 Jan 2022 07:31:16 -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=CNxP4yuPQA/1DdN5JN2f2VwcHuCd9bwF9iKzqvnifYQ=; b=GQh+Kyn4bU+jU0L/D28WJW71KP9wtqOnhghndd0cD1xQI8opEeRqL/DUO33jGp/arD qbeQFiwaOUM8dSegx2aJYF9+a9/EBoReDV6RYxxFHp03H/MhRiYa29B1+kYTm+MvWuBd lfcRuvfXLWEFWItggi44KBocJEAd9PlVqH+RREeSZnq6mDMz0bmAqGhIGN0C74LNz8HS dftUomEo23nqtFl99FEUwge8O3PqIiupr+hbxcvtgMnczQKxSPAa/7vcaTkZquu+cZvx 0VN+uJdtwa3+rrb6TcPgr6IIkZwPAgHcScqKb6/dJkQ8za7qSCxY4wRuMYWrjC0hb+vm Wgcw== 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=CNxP4yuPQA/1DdN5JN2f2VwcHuCd9bwF9iKzqvnifYQ=; b=NyTjZPBrxzEcNHk4lrx8rSGabl3m5bJKvVAMfK1+C4k2JEdUoVOxHk9A9XYreSbT05 tTOXeUdYoGIJonIY95lxbYZWXcOg0GokrgbnYsPxhSrdLr4jtAUg+KfhOGscBkZ8vvlX d6g0PTuyGG+VOEBshR5uQv9uvRPbU4Cpq7YBXF2NdotLQLh+9Cay93xtVditWi+sBR+f m5AfzxQffvCRxGn1TaU87fWZRTJ9KWnQs8FMFj4gMaOH/pJdtnSB15UVtW3EmUtZX+Ej eWFplxzf/KBaWjAaMazBS0y0l7eqv7tbXQCRPAFGO52f4aiEJRyo1KULjJJutPHDTRCK 8D2A== X-Gm-Message-State: AOAM530oJIHxRHKjbsq1Zf+bIINJridmeXv7cfb6fxfIfgTXyW7Qmmll qGTepca25AmSow58m+MrXw3sxTLgdqXCfQ== X-Received: by 2002:a17:902:bf41:b0:14a:bb95:6577 with SMTP id u1-20020a170902bf4100b0014abb956577mr21531355pls.9.1642692675146; Thu, 20 Jan 2022 07:31:15 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id t7sm3689839pfj.138.2022.01.20.07.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:31:14 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 11/14] FWU: Add FWU Multi Bank Update on SPI Flash Date: Fri, 21 Jan 2022 00:31:10 +0900 Message-Id: <164269267060.39378.17392247605833481024.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.2 at phobos.denx.de X-Virus-Status: Clean Signed-off-by: Masami Hiramatsu --- include/fwu.h | 13 ++ lib/fwu_updates/Kconfig | 34 ++++++ lib/fwu_updates/Makefile | 5 - lib/fwu_updates/fwu_mdata_sf.c | 241 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 288 insertions(+), 5 deletions(-) create mode 100644 lib/fwu_updates/fwu_mdata_sf.c diff --git a/include/fwu.h b/include/fwu.h index 7af94988b7..a013170321 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -64,9 +64,18 @@ int fwu_accept_image(efi_guid_t *img_type_id, u32 bank); int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank); int fwu_plat_get_update_index(u32 *update_idx); -int fwu_plat_get_blk_desc(struct blk_desc **desc); -int fwu_plat_get_alt_num(void *identifier); int fwu_plat_fill_partition_guids(efi_guid_t **part_guid_arr); void fwu_plat_get_bootidx(void *boot_idx); +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE_GPT_BLK +int fwu_plat_get_blk_desc(struct blk_desc **desc); +int fwu_plat_get_alt_num(void *identifier); +#endif + +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE_SF +struct fwu_mdata_ops *fwu_sf_get_fwu_mdata_ops(void); +int fwu_plat_get_image_alt_num(efi_guid_t image_type_id, u32 update_bank, + int *alt_no); +#endif + #endif /* _FWU_H_ */ diff --git a/lib/fwu_updates/Kconfig b/lib/fwu_updates/Kconfig index 0940a90747..8a369b9872 100644 --- a/lib/fwu_updates/Kconfig +++ b/lib/fwu_updates/Kconfig @@ -38,3 +38,37 @@ config FWU_REBOOT_AFTER_UPDATE Reboot the machine soon after installing a new firmware and start trial boot. You can disable this option for debugging or FWU development, but recommended to enable it. + +config FWU_MULTI_BANK_UPDATE_GPT_BLK + bool "Enable FWU Multi Bank Update for GPT on blockdev" + depends on FWU_MULTI_BANK_UPDATE + select EFI_PARTITION + help + Enable FWU Multi Bank Update for GPT on a block device. This + driver depends on GPT and the block device. FWU meatadata and + firmware will be stored on a block device with GPT. + +config FWU_MULTI_BANK_UPDATE_SF + bool "Enable FWU Multi Bank Update for SPI Flash" + depends on FWU_MULTI_BANK_UPDATE + help + Enable FWU Multi Bank Update for SPI flash driver. This + driver does not depend on GPT. Instead, the platform must + provide some APIs and define the offset of the primary and + the secondary metadata. + +config FWU_SF_PRIMARY_MDATA_OFFSET + hex "The offset of the primary metadata" + depends on FWU_MULTI_BANK_UPDATE_SF + help + The offset of the primary metadata on SPI Flash in + hexadecimal. + +config FWU_SF_SECONDARY_MDATA_OFFSET + hex "The offset of the secondary metadata" + depends on FWU_MULTI_BANK_UPDATE_SF + help + The offset of the secondary metadata on SPI Flash in + hexadecimal. + This must NOT be the same offset of the primary + metadata. diff --git a/lib/fwu_updates/Makefile b/lib/fwu_updates/Makefile index 73099a30cb..80669344f2 100644 --- a/lib/fwu_updates/Makefile +++ b/lib/fwu_updates/Makefile @@ -6,6 +6,5 @@ obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu_mdata.o obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu.o -ifdef CONFIG_EFI_PARTITION -obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu_mdata_gpt_blk.o -endif +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE_GPT_BLK) += fwu_mdata_gpt_blk.o +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE_SF) += fwu_mdata_sf.o diff --git a/lib/fwu_updates/fwu_mdata_sf.c b/lib/fwu_updates/fwu_mdata_sf.c new file mode 100644 index 0000000000..9e3cae7b68 --- /dev/null +++ b/lib/fwu_updates/fwu_mdata_sf.c @@ -0,0 +1,241 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2021, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +/* + * For the FWU SPI flash driver, the platform must define below functions + * according to its dfu_alt_info. + */ +extern int fwu_plat_get_image_alt_num(efi_guid_t image_type_id, + u32 update_bank, int *alt_no); + +static struct spi_flash *fwu_spi_flash; + +static int __fwu_sf_get_flash(void) +{ + if (IS_ENABLED(CONFIG_DM_SPI_FLASH)) { + struct udevice *new; + int ret; + + ret = spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, + CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE, + &new); + if (ret) + return ret; + + fwu_spi_flash = dev_get_uclass_priv(new); + } else { + fwu_spi_flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, + CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE); + if (!fwu_spi_flash) + return -EIO; + } + return 0; +} + +static int fwu_sf_get_flash(struct spi_flash **flash) +{ + int ret = 0; + + if (!fwu_spi_flash) + ret = __fwu_sf_get_flash(); + + *flash = fwu_spi_flash; + + return ret; +} + +static int sf_load_data(u32 offs, u32 size, void **data) +{ + struct spi_flash *flash; + int ret; + + ret = fwu_sf_get_flash(&flash); + if (ret < 0) + return ret; + + *data = memalign(ARCH_DMA_MINALIGN, size); + if (!*data) + return -ENOMEM; + + ret = spi_flash_read(flash, offs, size, *data); + if (ret < 0) { + free(*data); + *data = NULL; + } + + return ret; +} + +static int sf_save_data(u32 offs, u32 size, void *data) +{ + struct spi_flash *flash; + u32 sect_size, nsect; + void *buf; + int ret; + + ret = fwu_sf_get_flash(&flash); + if (ret < 0) + return ret; + + sect_size = flash->mtd.erasesize; + nsect = DIV_ROUND_UP(size, sect_size); + ret = spi_flash_erase(flash, offs, nsect * sect_size); + if (ret < 0) + return ret; + + buf = memalign(ARCH_DMA_MINALIGN, size); + if (!buf) + return -ENOMEM; + memcpy(buf, data, size); + + ret = spi_flash_write(flash, offs, size, buf); + + free(buf); + + return ret; +} + +static int fwu_sf_load_mdata(struct fwu_mdata **mdata, u32 offs) +{ + int ret; + + ret = sf_load_data(offs, sizeof(struct fwu_mdata), (void **)mdata); + + if (ret >= 0) { + ret = fwu_verify_mdata(*mdata, + offs == CONFIG_FWU_SF_PRIMARY_MDATA_OFFSET); + if (ret < 0) { + free(*mdata); + *mdata = NULL; + } + } + + return ret; +} + +static int fwu_sf_load_primary_mdata(struct fwu_mdata **mdata) +{ + return fwu_sf_load_mdata(mdata, CONFIG_FWU_SF_PRIMARY_MDATA_OFFSET); +} + +static int fwu_sf_load_secondary_mdata(struct fwu_mdata **mdata) +{ + return fwu_sf_load_mdata(mdata, CONFIG_FWU_SF_SECONDARY_MDATA_OFFSET); +} + +static int fwu_sf_save_primary_mdata(struct fwu_mdata *mdata) +{ + return sf_save_data(CONFIG_FWU_SF_PRIMARY_MDATA_OFFSET, + sizeof(struct fwu_mdata), mdata); +} + +static int fwu_sf_save_secondary_mdata(struct fwu_mdata *mdata) +{ + return sf_save_data(CONFIG_FWU_SF_SECONDARY_MDATA_OFFSET, + sizeof(struct fwu_mdata), mdata); +} + +static int fwu_sf_get_valid_mdata(struct fwu_mdata **mdata) +{ + if (fwu_sf_load_primary_mdata(mdata) == 0) + return 0; + + log_err("Failed to load/verify primary mdata. Try secondary.\n"); + + if (fwu_sf_load_secondary_mdata(mdata) == 0) + return 0; + + log_err("Failed to load/verify secondary mdata.\n"); + + return -1; +} + +static int fwu_sf_update_mdata(struct fwu_mdata *mdata) +{ + int ret; + + /* Update mdata crc32 field */ + mdata->crc32 = crc32(0, (void *)&mdata->version, + sizeof(*mdata) - sizeof(u32)); + + /* First write the primary mdata */ + ret = fwu_sf_save_primary_mdata(mdata); + if (ret < 0) { + log_err("Failed to update the primary mdata.\n"); + return ret; + } + + /* And now the replica */ + ret = fwu_sf_save_secondary_mdata(mdata); + if (ret < 0) { + log_err("Failed to update the secondary mdata.\n"); + return ret; + } + + return 0; +} + +static int fwu_sf_mdata_check(void) +{ + struct fwu_mdata *primary = NULL, *secondary = NULL; + int ret; + + ret = fwu_sf_load_primary_mdata(&primary); + if (ret < 0) + log_err("Failed to read the primary mdata: %d\n", ret); + + ret = fwu_sf_load_secondary_mdata(&secondary); + if (ret < 0) + log_err("Failed to read the secondary mdata: %d\n", ret); + + if (primary && secondary) { + if (memcmp(primary, secondary, sizeof(struct fwu_mdata))) { + log_err("The primary and the secondary mdata are different\n"); + ret = -1; + } + } else if (primary) { + ret = fwu_sf_save_secondary_mdata(primary); + if (ret < 0) + log_err("Restoring secondary mdata partition failed\n"); + } else if (secondary) { + ret = fwu_sf_save_primary_mdata(secondary); + if (ret < 0) + log_err("Restoring primary mdata partition failed\n"); + } + + free(primary); + free(secondary); + return ret; +} + +static int fwu_sf_get_mdata(struct fwu_mdata **mdata) +{ + return fwu_sf_get_valid_mdata(mdata); +} + +static struct fwu_mdata_ops fwu_sf_mdata_ops = { + .get_image_alt_num = fwu_plat_get_image_alt_num, + .mdata_check = fwu_sf_mdata_check, + .get_mdata = fwu_sf_get_mdata, + .update_mdata = fwu_sf_update_mdata, +}; + +struct fwu_mdata_ops *fwu_sf_get_fwu_mdata_ops(void) +{ + return &fwu_sf_mdata_ops; +} From patchwork Thu Jan 20 15:31: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: 533551 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1677599imu; Thu, 20 Jan 2022 07:31:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJytwv4pxYVz3jtHuoxEiHEuecA1s97YGxVkZMf57M7RmVZ2dO4hYxi9g7YFW//yJbemRIKX X-Received: by 2002:a50:8a94:: with SMTP id j20mr12938405edj.388.1642692700188; Thu, 20 Jan 2022 07:31:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692700; cv=none; d=google.com; s=arc-20160816; b=uLaG4Qd0btSsKcwupR80UEQjhU5u1d+ThuOajxONOokiy3fgbVomkoh42HWt1+8zoC IDokT9Q+w6mvZmLT2CY5n+gaxH9cekMCkClHrAu1cC5byoBeSB1sBLBosHGSSsXYZLqE jPzPQLOuqlLJAWja8nRqCTIaRIKXfMP1OqIS6XUxff3oObzfcxjfsVldojfFuAhHDIyj gbUqLHM+nhDfh/TCE4UA6+L+GH++vAZdgAGna4vuWNCX3E6Udp0OrVyVYsJKHq2xZ3/T gG5h0OSTq0rf4oZqsu5LFcAv4GPe3jAofiT39n9kQt8qEtLncAUlfKReKnUV8HjR+AQx hGJw== 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=utOgsCpoG5dEgjvj/Dasjwnba7V0bRYQw5FAVA77OVY=; b=rhQOV1VwiS+eTMQSJUDyQuJdFkx0rg1UrvLchgFVKkBVPTNMdQ8kJDlDgVgJjzkd4d gX6Fa2BP6Pt54SxivsD5VQHejZTE5YmqhBvsY7qvNc0NVtZSbLG2+5AhMOwcvBCRU9GU niRUBoE7rDM3P/LYqvGGqwoiaxr2LttAO1ZZYlr9VxEl806QTou/u5XbxfWZshnfhm/6 oUrMqPISrAXUEQYiwC4ZK0r7jjFXy+6FCBUJhW7ls9I23T/0IPAJhsK+dDKvspmSR+4Z ZTHj/mx6F2jiN2ea2E8BVFIAdh0UcD/tkCGOwl1ynrxV8QfIMFORUQsRdfXm1r2lpr9G 35TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tTqGSkzC; 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 b14si2145137edw.116.2022.01.20.07.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:31:40 -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=tTqGSkzC; 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 C39EC838E2; Thu, 20 Jan 2022 16:31:31 +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="tTqGSkzC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8DD0F838C4; Thu, 20 Jan 2022 16:31:30 +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-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (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 42499838E3 for ; Thu, 20 Jan 2022 16:31: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=masami.hiramatsu@linaro.org Received: by mail-pj1-x1030.google.com with SMTP id d15-20020a17090a110f00b001b4e7d27474so6097579pja.2 for ; Thu, 20 Jan 2022 07:31:27 -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=utOgsCpoG5dEgjvj/Dasjwnba7V0bRYQw5FAVA77OVY=; b=tTqGSkzCrj0Bhj8H+12IKrxfRAf7zusN9doZ/xP8bczBIahKgmga7Y5+S8McgzPRdm bLl/G/Di3lcUY74bLuwNvbkDU5zzKPd7lsvonoHczO5dYwd70AF4Zk00686f4Pfz2BvO 5apd4ouADD/QqQdOBVZPReaPKj6tAIQgJsNajvECMPS81LyVmtTk7/Q1N/KWKTtY1YBY UGqVVWEt5wzghznIlQCozPPXc8oL3UCscvkv0Gfsgngiq/PUR+vV9lWdLEGOeLnom52T 6BC6w1itmuHYqa0XYHASIZva//CQlhrJDfUJUzuqbgxaTvcgr0q6kxQCz+g1JBORjrq0 zL9Q== 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=utOgsCpoG5dEgjvj/Dasjwnba7V0bRYQw5FAVA77OVY=; b=m0Uvg9arag3xnnT0m3T9KvaBqEiuNZ57pZH9CX0dc0bS76wDCJd23ftTupPLxU+fY0 KOBmDZn7mInFPSVPmm30scRxIkPCr89DLO6OUi6FFS89s4gfPl3msBYr5E/iJyy/MQOM FFgOcz0GMie32kMb+aVCZ8sD3R9priGA1wnQX0zYzCd6HIrfcS/HBuiqcpffwaC60yR3 ujbZcYcmLqR6hCUai5NMWyi8IeZa11Qs+JnIlOOZb5o/qYqtWayvoDmZcTj3IQhXK7k3 ibg0lKI8dA0eFiv/u4MtWIXMGScfjnPLKAZ8IqrpoWORFLbMFpV56rxcvFUqEozutwOB 9FCg== X-Gm-Message-State: AOAM530M8GlKPenVdx3rjW9v5y9obSaYGWMOKHcsq1dAtUI63ouoyywy EdKnEhO1nrbqT3PeoThRywmilxLJX+bPrA== X-Received: by 2002:a17:90a:de08:: with SMTP id m8mr11376925pjv.102.1642692685203; Thu, 20 Jan 2022 07:31:25 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id s7sm4128650pfu.133.2022.01.20.07.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:31:24 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 12/14] FWU: synquacer: Add FWU Multi bank update support for DeveloperBox Date: Fri, 21 Jan 2022 00:31:20 +0900 Message-Id: <164269268052.39378.8998928319603683374.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.2 at phobos.denx.de X-Virus-Status: Clean The DeveloperBox platform can support the FWU Multi bank update. SCP firmware will switch the boot mode by DSW3-4 and load the Multi bank update supported TF-A BL2 from 0x600000 offset on the SPI flash. Thus it can co-exist with the legacy boot mode (legacy U-Boot or EDK2). Signed-off-by: Masami Hiramatsu --- board/socionext/developerbox/Kconfig | 19 ++++ board/socionext/developerbox/Makefile | 1 board/socionext/developerbox/fwu_plat.c | 158 +++++++++++++++++++++++++++++++ include/configs/synquacer.h | 10 ++ include/efi_loader.h | 3 + lib/efi_loader/efi_firmware.c | 14 +-- 6 files changed, 198 insertions(+), 7 deletions(-) create mode 100644 board/socionext/developerbox/fwu_plat.c diff --git a/board/socionext/developerbox/Kconfig b/board/socionext/developerbox/Kconfig index c181d26a44..4e2c341aad 100644 --- a/board/socionext/developerbox/Kconfig +++ b/board/socionext/developerbox/Kconfig @@ -32,4 +32,23 @@ config SYS_CONFIG_NAME default "synquacer" endif + +config FWU_MULTI_BANK_UPDATE + select FWU_MULTI_BANK_UPDATE_SF + +config FWU_MULTI_BANK_UPDATE_SF + select DM_SPI_FLASH + +config FWU_NUM_BANKS + default 6 + +config FWU_NUM_IMAGES_PER_BANK + default 1 + +config FWU_SF_PRIMARY_MDATA_OFFSET + default 0x500000 + +config FWU_SF_SECONDARY_MDATA_OFFSET + default 0x520000 + endif diff --git a/board/socionext/developerbox/Makefile b/board/socionext/developerbox/Makefile index 4a46de995a..15cce9c57e 100644 --- a/board/socionext/developerbox/Makefile +++ b/board/socionext/developerbox/Makefile @@ -7,3 +7,4 @@ # obj-y := developerbox.o +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE_SF) += fwu_plat.o diff --git a/board/socionext/developerbox/fwu_plat.c b/board/socionext/developerbox/fwu_plat.c new file mode 100644 index 0000000000..dbb814f1fd --- /dev/null +++ b/board/socionext/developerbox/fwu_plat.c @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2021, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +/* SPI Flash accessors */ +static struct spi_flash *plat_spi_flash; + +static int __plat_sf_get_flash(void) +{ + struct udevice *new; + int ret; + + //TODO: use CONFIG_FWU_SPI_* + ret = spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, + CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE, + &new); + if (ret) + return ret; + + plat_spi_flash = dev_get_uclass_priv(new); + return 0; +} + +static int plat_sf_get_flash(struct spi_flash **flash) +{ + int ret = 0; + + if (!plat_spi_flash) + ret = __plat_sf_get_flash(); + + *flash = plat_spi_flash; + + return ret; +} + +static int sf_load_data(u32 offs, u32 size, void **data) +{ + struct spi_flash *flash; + int ret; + + ret = plat_sf_get_flash(&flash); + if (ret < 0) + return ret; + + *data = memalign(ARCH_DMA_MINALIGN, size); + if (!*data) + return -ENOMEM; + + ret = spi_flash_read(flash, offs, size, *data); + if (ret < 0) { + free(*data); + *data = NULL; + } + + return ret; +} + +/* Platform dependent GUIDs */ + +/* The GUID for the SNI FIP image type GUID */ +#define FWU_IMAGE_TYPE_DEVBOX_FIP_GUID \ + EFI_GUID(0x7d6dc310, 0x52ca, 0x43b8, 0xb7, 0xb9, \ + 0xf9, 0xd6, 0xc5, 0x01, 0xd1, 0x08) + +#define PLAT_METADATA_OFFSET 0x510000 +#define PLAT_METADATA_SIZE (sizeof(struct devbox_metadata)) + +struct __packed devbox_metadata { + u32 boot_index; + u32 boot_count; + u32 invert_dual; +} *devbox_plat_metadata; + +static const efi_guid_t devbox_fip_image_type_guid = FWU_IMAGE_TYPE_DEVBOX_FIP_GUID; + +int fwu_plat_get_image_alt_num(efi_guid_t image_type_id, u32 update_bank, + int *alt_no) +{ + /* DeveloperBox FWU Multi bank only supports FIP image. */ + if (guidcmp(&image_type_id, &devbox_fip_image_type_guid)) + return -EOPNOTSUPP; + + /* + * DeveloperBox FWU expects Bank:Image = 1:1, and the dfu_alt_info + * only has the entries for banks. Thus the alt_no should be equal + * to the update_bank. + */ + update_bank %= CONFIG_FWU_NUM_BANKS; + *alt_no = update_bank; + + return 0; +} + +/* SPI flash doesn't have GPT, and it's not blk device */ +int fwu_plat_fill_partition_guids(efi_guid_t **part_guid_arr) +{ + efi_status_t ret; + + free(*part_guid_arr); + + ret = efi_fill_part_guid_array(&devbox_fip_image_type_guid, part_guid_arr); + return (ret != EFI_SUCCESS) ? -ENOMEM : 0; +} + +/* TBD: add a usage counter for wear leveling */ +int fwu_plat_get_update_index(u32 *update_idx) +{ + int ret; + u32 active_idx; + + ret = fwu_get_active_index(&active_idx); + + if (ret < 0) + return -1; + + *update_idx = (active_idx + 1) % CONFIG_FWU_NUM_BANKS; + + return ret; +} + +static int devbox_load_plat_metadata(void) +{ + if (devbox_plat_metadata) + return 0; + + return sf_load_data(PLAT_METADATA_OFFSET, PLAT_METADATA_SIZE, + (void **)&devbox_plat_metadata); +} + +void fwu_plat_get_bootidx(void *boot_idx) +{ + u32 *bootidx = boot_idx; + + if (devbox_load_plat_metadata() < 0) + *bootidx = 0; + else + *bootidx = devbox_plat_metadata->boot_index; +} + +struct fwu_mdata_ops *get_plat_fwu_mdata_ops(void) +{ + return fwu_sf_get_fwu_mdata_ops(); +} + diff --git a/include/configs/synquacer.h b/include/configs/synquacer.h index 6d67bd2af5..f859237550 100644 --- a/include/configs/synquacer.h +++ b/include/configs/synquacer.h @@ -47,8 +47,18 @@ /* Since U-Boot 64bit PCIe support is limited, disable 64bit MMIO support */ +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define DEFAULT_DFU_ALT_INFO "dfu_alt_info=" \ + "mtd nor1=bank0 raw 600000 400000;" \ + "bank1 raw a00000 400000;" \ + "bank2 raw e00000 400000;" \ + "bank3 raw 1200000 400000;" \ + "bank4 raw 1600000 400000;" \ + "bank5 raw 1a00000 400000\0" +#else #define DEFAULT_DFU_ALT_INFO "dfu_alt_info=" \ "mtd nor1=fip.bin raw 600000 400000\0" +#endif /* Distro boot settings */ #ifndef CONFIG_SPL_BUILD diff --git a/include/efi_loader.h b/include/efi_loader.h index f20d361876..d6dc173feb 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -953,6 +953,9 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t n); u16 *efi_create_indexed_name(u16 *buffer, size_t buffer_size, const char *name, unsigned int index); +efi_status_t efi_fill_part_guid_array(const efi_guid_t *guid, + efi_guid_t **part_guid_arr); + extern const struct efi_firmware_management_protocol efi_fmp_fit; extern const struct efi_firmware_management_protocol efi_fmp_raw; diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 107f0cb074..c100be35d3 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -97,8 +97,8 @@ efi_status_t EFIAPI efi_firmware_set_package_info_unsupported( return EFI_EXIT(EFI_UNSUPPORTED); } -static efi_status_t fill_part_guid_array(const efi_guid_t *guid, - efi_guid_t **part_guid_arr) +efi_status_t efi_fill_part_guid_array(const efi_guid_t *guid, + efi_guid_t **part_guid_arr) { int i; int dfu_num = 0; @@ -309,8 +309,8 @@ efi_status_t EFIAPI efi_firmware_fit_get_image_info( !descriptor_size || !package_version || !package_version_name)) return EFI_EXIT(EFI_INVALID_PARAMETER); - ret = fill_part_guid_array(&efi_firmware_image_type_uboot_fit, - &part_guid_arr); + ret = efi_fill_part_guid_array(&efi_firmware_image_type_uboot_fit, + &part_guid_arr); if (ret != EFI_SUCCESS) goto out; @@ -429,7 +429,7 @@ efi_status_t EFIAPI efi_firmware_raw_get_image_info( return EFI_EXIT(EFI_INVALID_PARAMETER); if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { - ret = fill_part_guid_array(&null_guid, &part_guid_arr); + ret = efi_fill_part_guid_array(&null_guid, &part_guid_arr); if (ret != EFI_SUCCESS) goto out; @@ -444,8 +444,8 @@ efi_status_t EFIAPI efi_firmware_raw_get_image_info( goto out; } } else { - ret = fill_part_guid_array(&efi_firmware_image_type_uboot_raw, - &part_guid_arr); + ret = efi_fill_part_guid_array(&efi_firmware_image_type_uboot_raw, + &part_guid_arr); if (ret != EFI_SUCCESS) goto out; } From patchwork Thu Jan 20 15:31:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533552 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1677778imu; Thu, 20 Jan 2022 07:31:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJxCPV9UUI5OACDx0vaBMzokfQSmlpOpp+8KkDuqZotPrjc9ajUmIRb+d6WG2X2DSAFK4yGm X-Received: by 2002:a17:907:2d1e:: with SMTP id gs30mr23338104ejc.43.1642692711172; Thu, 20 Jan 2022 07:31:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692711; cv=none; d=google.com; s=arc-20160816; b=Oo4nmBjA1butBUyVXVhbvZ/vsn282jCFQ6goHpe4T4xMTINBpEfFZ4cOFp0Z8v8AMz IbMqKnRM85FdUbbGTHOQ1BJLKGakWUJEDRPge6DuS3+uMWXgFKW7agai8gLj2gGfp323 5yNbAV83hX772cGq/zggbF7k/30rxO7GfKsmyszWk4pOvDuhYUIPwicbISlEHMzSd77Y mtqfmbd0S1FiEb4mqkEApdHr5HyaAnoPzDnfF/EdDX4kdnpV0+zKP4rU5g4Izcz0O2e4 4G4j0lMN9MkUjkK1oitIr8ScVBP33ms2hkcFpJ7GoS4PGZRkIrh1kBySgZ4Y0kpaNCQ7 JJtw== 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=YfuZH/npEtxyny4JtvSk8JFITyNMadd2Rfji2/F1ZL0=; b=HAQZv/IYbpwfgoMXPe1gDekDmBktfPF9bTvgdAdzA8BMLoSRzotWXlTAWlCZhI2hII prv7YvVxziUNr2gzQM8cGszObQy7bNY0ZC8YfBEC7sNOiHikAJD7dTjLJ/CIhGcpEKuT 91h38lnf4VTBfXMErIH9Ow8yybLaTCtULeB/Aaa/2YNSIJmRFk4Q41/Bb5I+khw9OYHc bbssxKzAqQ4FjseNWnn2+Kc2ukNnYiMxNQctJHU6HEwu8bKIEIite8ec8JCFEC6mwgPJ tvQ56fjDyYLpuGqWLN6wY0s+L8oSwOz3poehnsP9C8GfBoT6KcsZuJPZxLe7RiaVjpIr Ly5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EvlPb0QB; 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 n3si2172063edd.566.2022.01.20.07.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:31:51 -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=EvlPb0QB; 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 7966C838DA; Thu, 20 Jan 2022 16:31: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=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="EvlPb0QB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 94547838BD; Thu, 20 Jan 2022 16:31:40 +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-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) (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 84051838DA for ; Thu, 20 Jan 2022 16:31:37 +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-x52c.google.com with SMTP id r11so5627699pgr.6 for ; Thu, 20 Jan 2022 07:31:37 -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=YfuZH/npEtxyny4JtvSk8JFITyNMadd2Rfji2/F1ZL0=; b=EvlPb0QBp6Kp62eI8XF1QPe8KqkXWrFOjXrV+Kcp9MP4lkLFI7rxP3FschWWQDyv7E UeOJUYqaE4o2IAvboMvyYVLIHjn7aDnumisgmoqrUC3GtcXT77phZijScR00TqvOJ7ih ay/AwM7BM2kiiA0XnLWw8yJO7t0TteOht737Svikj6dSJXzUXGSKv0Kljyg2/Dxu6ino 70in/0edm+q4sBa747+CXC3C6YBILEL/gDvm12ZrR8AJchQPlZGFeJGnuHj6ic48SaCE aHt6RoyIHzutldS+oAz3fFVOOWij7ql1zCx6wU5sSbCFNpFvhiHrdTNUp0NGBkAfATnS G4Tw== 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=YfuZH/npEtxyny4JtvSk8JFITyNMadd2Rfji2/F1ZL0=; b=P1tY3LyGej7vf8+pb2ElKrnKldfk5U3/um8ka2EsL0UHzN8WpDlEkg+pAf3uDg2MpI TUvsnbifmVEpygwTaEgXZkwDoJ+r0uf2XQLRMc2ibjzy1Ob1M4Isl5+N1prEEyH3Gy4i dDdtRRZz/wvYfN+wwSUmaBMh5XyeCy96C0bbApSLncCK/Y2fiLOZea7HCN8fYsgF4eUn IeLtHMeyj2fin+c1upu0UfAFKZlXcGzeOuDhQh3OhiUH1NwiBU3UuUwUOmYcw/tO6p3n +fpYi94U1q1EDh52kcFshrwh+rdfBe10S0/gWGJI+/UdQeBo1OE0KFlGI0oIQdAWTkDw AcXQ== X-Gm-Message-State: AOAM530bNylrCXJwpojwJ/7E5713VfaaRU3bqtj1a9kFjD3uccd6Gbn/ CafK8RtRkK1hYrLCKMiPZEHaMMx/jA3iAg== X-Received: by 2002:a05:6a00:1490:b0:4c2:7965:9512 with SMTP id v16-20020a056a00149000b004c279659512mr31679072pfu.55.1642692695652; Thu, 20 Jan 2022 07:31:35 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id bt6sm4687752pjb.3.2022.01.20.07.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:31:35 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 13/14] FWU: synquacer: Initialize broken metadata Date: Fri, 21 Jan 2022 00:31:30 +0900 Message-Id: <164269269065.39378.5600466909754039339.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.2 at phobos.denx.de X-Virus-Status: Clean Since the FWU metadata is not initialized at the installation, if it is broken, it should be initialized. Usually, the FWU metadata is not covered by capsule update, so it is safe to initialize the metadata portion if it seems broken. But for the production device, usually firmware will be installed with initialized metadata, and the broken metadata means the device can be compromized. In that case, build U-Boot without this option. Signed-off-by: Masami Hiramatsu --- board/socionext/developerbox/Kconfig | 12 ++++++ board/socionext/developerbox/fwu_plat.c | 59 +++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/board/socionext/developerbox/Kconfig b/board/socionext/developerbox/Kconfig index 4e2c341aad..1b36e10f3b 100644 --- a/board/socionext/developerbox/Kconfig +++ b/board/socionext/developerbox/Kconfig @@ -51,4 +51,16 @@ config FWU_SF_PRIMARY_MDATA_OFFSET config FWU_SF_SECONDARY_MDATA_OFFSET default 0x520000 +config FWU_INIT_BROKEN_METADATA + bool "Initialize FWU metadata if broken" + select BOARD_LATE_INIT + default n + help + Initialize FWU metadata if the metadata is broken. + This option is only for the development environment, since if the + metadata is broken, it means someone may compromize it. In that case + the production device must be bricked. + But for the development environment, or initial installation of the + FWU multi-bank update firmware, this will be useful. + endif diff --git a/board/socionext/developerbox/fwu_plat.c b/board/socionext/developerbox/fwu_plat.c index dbb814f1fd..2982e47a16 100644 --- a/board/socionext/developerbox/fwu_plat.c +++ b/board/socionext/developerbox/fwu_plat.c @@ -156,3 +156,62 @@ struct fwu_mdata_ops *get_plat_fwu_mdata_ops(void) return fwu_sf_get_fwu_mdata_ops(); } +#ifdef CONFIG_FWU_INIT_BROKEN_METADATA + +static void devbox_init_fwu_mdata(void) +{ + const efi_guid_t null_guid = NULL_GUID; + struct fwu_image_bank_info *bank; + struct fwu_mdata *metadata; + int i, j, ret; + + metadata = memalign(ARCH_DMA_MINALIGN, sizeof(*metadata)); + if (!metadata) { + log_err("Failed to allocate initial metadata.\n"); + return; + } + + metadata->version = 1; + metadata->active_index = 0; + metadata->previous_active_index = 0; + + /* + * Since the DeveloperBox doesn't use GPT, both of + * fwu_image_entry::location_uuid and + * fwu_img_bank_info::image_uuid are null GUID. + */ + for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) { + guidcpy(&metadata->img_entry[i].image_type_uuid, + &devbox_fip_image_type_guid); + guidcpy(&metadata->img_entry[i].location_uuid, + &null_guid); + bank = metadata->img_entry[i].img_bank_info; + + for (j = 0; j < CONFIG_FWU_NUM_BANKS; j++) { + guidcpy(&bank[j].image_uuid, &null_guid); + bank[j].accepted = (j == 0) ? 1 : 0; + bank[j].reserved = 0; + } + } + + ret = fwu_update_mdata(metadata); + if (ret < 0) + log_err("Failed to initialize FWU metadata\n"); + else + log_err("Initialized FWU metadata\n"); + free(metadata); +} + +int board_late_init(void) +{ + struct fwu_mdata *metadata; + + if (fwu_get_mdata(&metadata) < 0) { + // Initialize FWU metadata if broken + log_err("Unable to get a valid metadata. Initialize it.\n"); + devbox_init_fwu_mdata(); + } + return 0; +} + +#endif From patchwork Thu Jan 20 15:31:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533553 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1677961imu; Thu, 20 Jan 2022 07:32:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5QVWCT1pRcLtlAWrmd0zK4HZC4Yvf94M6Zp8whSqCOhjIP6hSflPCXDToY38MxPQsaznt X-Received: by 2002:a17:906:3197:: with SMTP id 23mr2826888ejy.215.1642692721769; Thu, 20 Jan 2022 07:32:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692721; cv=none; d=google.com; s=arc-20160816; b=G9i+LXSMODI+y8ohl02QcLN3KjNQfm5dB78dYk6BP6t2ML5N5UUB7w6okvqg9nIJMS F3zFLG/JoPL9aleLVcs01uuSxoX5oImv8EnkdRZiMqfTzFDfXxRZyLaKdRHH1ojM5/kL y8NwX9fLi2j+XPWdYjtkIy+9U8w5Stpr1sQQ1GJkVwBK7wQZmjT01eBxUozz8AAcuxUR Gx0fn1yVrveTkqdS5xhP9cC1FYXNqi0n6D//wWYHbWAPPHhTFsOx0rMSxlvZ8tO6iBaY TixpqgHdvO7RoQMbbaYC8o/7Kl8hy0hskgJEyN+50QPA2/NszdvsBd27kMnFMOgBWZj4 K9tg== 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=RGe4zOoVnE8X0miwDtdJjTCYZ36L9GxTi0cZKQJNhk8=; b=vtA0XkqklanXWNP09Fd3xgwMT/UeDdnX4tPX0YYy+yayMJXazYg98ena1wanNbVu+c IqzFEKm16ngdHYSb6gwacR1E+zHyW5Og1EJ/3d8m0aK2x2VRhyRdSDEa1D5EHSqOJxOL pMA4SkKjYgUDIyjUCj+NXWXXLPxKVcjgRv+bXPngzsSAxW9Y31QfWxXXIJHZTvoZwJNx 6VFzuezXGvUkjcpVXrkSQlHnVp/GKbWXhfrow6ErAyr60UuVSFmZdF+kh+mELONDewAn N/SA7feH1cH6k1ALcm3LrQ9IUUIdJilUydrOQiUiDby1c1VxYnxb05b4zq0VfOIQRZBA UPjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G1CjbUpU; 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 bu10si2035431ejb.957.2022.01.20.07.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:32:01 -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=G1CjbUpU; 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 18190838EE; Thu, 20 Jan 2022 16:31:52 +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="G1CjbUpU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 71EA9838D4; Thu, 20 Jan 2022 16:31:50 +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-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 B4C64838EE for ; Thu, 20 Jan 2022 16:31:47 +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-x632.google.com with SMTP id n8so5479403plc.3 for ; Thu, 20 Jan 2022 07:31:47 -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=RGe4zOoVnE8X0miwDtdJjTCYZ36L9GxTi0cZKQJNhk8=; b=G1CjbUpUY9f5P39R+cVVW4E/b/vfv45NFx2vfdzfkuvK/BuiS1qrzmjzmZDpom35Dq AZ6tndbQG2loIC7ShB9unvB3f0JDGN9IjvgkOcvbG1gXPkPEOmeOzAmFafZCALoGnr3i jQ/JdXdG6KMEkFsVLBvKvh8GlW6FW2lviyKUW0n8xPKJo6m+F9dEnWxoeNH1B8IOQoUQ bUgzi/jXJdum1NpBghmXZN2dFCNfuoZftlasaw35bgEeSjderIfLQ9m9A409hHKXkFim +ug9Q6dfLqNqeJPz0r6gWVfqG1N+q0jJgO3ljBtr3TEUSq00wq+uxbYjsPi6FKDKoLUo 3w+Q== 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=RGe4zOoVnE8X0miwDtdJjTCYZ36L9GxTi0cZKQJNhk8=; b=e76oNmlDzw3e9Mrr7DWZSFpZv4rAyQvGpCjUHiWhOcoUJEzeAIVYLANoeFOt4G52sq E/2r45LVClP8AbLoDWmdOFsTa8vYeIBcnpjXJn8iZLFVPfpBjWnYi3QdBa6IhI4vCpXB zb8Jf8GYeXOP9KT2nrPQ/wCEINRP//ZxSwm07vmpjehxv3zyDEchuUk06Jsr6VN0AWBB sokVHrMwOQfqERO3RvW+1GgzRjb+IA+Wub0KTxqfC5SBUD/2H+vGw3cYx3sEIb/vR+kG XpaXq2GVAso6n8+R3FIUyOgcyBAKNdq/8Vqq3Vy9HMltkY3nv0AHCtWc9K84fVa3bsFj NsSA== X-Gm-Message-State: AOAM531zkp9JW8f8ic3GbTITqATrp1Aml1fzW5GYd2rNFFEYDy0DwqS8 BINpUKhndAUP6qkp3YU0nGv3tbQ2TZS59A== X-Received: by 2002:a17:902:a601:b0:148:adf2:9725 with SMTP id u1-20020a170902a60100b00148adf29725mr38589114plq.136.1642692705822; Thu, 20 Jan 2022 07:31:45 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id f4sm3903911pfe.204.2022.01.20.07.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:31:45 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 14/14] configs: synquacer: Add FWU support for DeveloperBox Date: Fri, 21 Jan 2022 00:31:41 +0900 Message-Id: <164269270101.39378.7735258686987722166.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.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.2 at phobos.denx.de X-Virus-Status: Clean Enable FWU Multi-Bank support for DeveloperBox SynQuacer platform. This also enables fwu_metadata_read command and "reboot soon after update" option. Signed-off-by: Masami Hiramatsu --- configs/synquacer_developerbox_defconfig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/configs/synquacer_developerbox_defconfig b/configs/synquacer_developerbox_defconfig index 484f6b7336..02d87bc403 100644 --- a/configs/synquacer_developerbox_defconfig +++ b/configs/synquacer_developerbox_defconfig @@ -91,3 +91,10 @@ CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y CONFIG_EFI_CAPSULE_ON_DISK=y CONFIG_EFI_IGNORE_OSINDICATIONS=y CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y +CONFIG_EFI_SECURE_BOOT=y +CONFIG_FWU_MULTI_BANK_UPDATE=y +CONFIG_FWU_MULTI_BANK_UPDATE_SF=y +CONFIG_FWU_MULTI_BANK_UPDATE_GPT_BLK=n +CONFIG_CMD_FWU_METADATA=y +CONFIG_FWU_REBOOT_AFTER_UPDATE=y +CONFIG_FWU_INIT_BROKEN_METADATA=y