From patchwork Sun Sep 19 21:49:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1529892 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=laZA+O8w; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HCLvj64P2z9sX3 for ; Mon, 20 Sep 2021 07:50:09 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5712182DA1; Sun, 19 Sep 2021 23:49:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="laZA+O8w"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CAA4480202; Sun, 19 Sep 2021 23:49:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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-oo1-xc2c.google.com (mail-oo1-xc2c.google.com [IPv6:2607:f8b0:4864:20::c2c]) (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 39DD48048A for ; Sun, 19 Sep 2021 23:49:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oo1-xc2c.google.com with SMTP id t2-20020a4ae9a2000000b0028c7144f106so5210024ood.6 for ; Sun, 19 Sep 2021 14:49:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pt0hv6rnD5HMINaAQCTNMeChp7BdZx4LQ22bGBmsNeI=; b=laZA+O8w5Ah9nj9aWjYqBzM+J7w6pwvb/NyXij5Brlj34sfZvIQdfisx46onuPtSMB 8RSbqAEezXR/00UP7HnaW5g/G6XA2Q9uM3FNA63yzf9G/+tSsxpT+/WyHrOuvjgOkRoC Lo9iqGacIwqGOwrumSzN5Afdh+mraaJnvq+/8= 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:mime-version:content-transfer-encoding; bh=Pt0hv6rnD5HMINaAQCTNMeChp7BdZx4LQ22bGBmsNeI=; b=Px4W9k9wooKzDJDBzc9lGdFuWlRkHPXhJyLHcV8oFH39cXjYRjwNV31OtUY7IN2Ira yerPH7rBf7XQNphUCTXYxSjk/6y5u+DCND4N+seNl3vpaoaSHfCS2O/uICeZGMjWbUB+ B+5Tc1rLE9Hmk9Pl3nATf1LfTEqIxfazBwIK1TKQtOYcK4Bq+te4Ap8BaPdoVUebEfox BJfi9UMKKVOU0JOiffkhGLBgZUQko0J3CDfCLEZFjWRv0DCm7mLHokjdy+FHhAojM6eT xttYnu6DkzFTQCyC0fFycR6yWOufjw5pmT0KGuudHr/eJyigffgytkWpkhe4L3Br8sIz CoQw== X-Gm-Message-State: AOAM5326fdBXZvFurwYeonE6wStPdYjRn+/Dxc7AaYG0tEZjtvV31Ff/ xmov3Wi8inFNx7WXq2MbvTz1bPR6vPr1DA== X-Google-Smtp-Source: ABdhPJz04J7SKzSzl/UVatwZvC9irhHap847AbVvB7CBhIpyrRiT/oyj68xhldH3zzIYKZV7BcEElA== X-Received: by 2002:a4a:e9e4:: with SMTP id w4mr9324858ooc.13.1632088181674; Sun, 19 Sep 2021 14:49:41 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id q25sm519897oof.33.2021.09.19.14.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 14:49:41 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Jagan Teki , Heinrich Schuchardt , Simon Glass Subject: [PATCH v4 1/5] command: Use a constant pointer for the help Date: Sun, 19 Sep 2021 15:49:32 -0600 Message-Id: <20210919214937.3829422-2-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog In-Reply-To: <20210919214937.3829422-1-sjg@chromium.org> References: <20210919214937.3829422-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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 text should never change during execution, so it makes sense to use a const char * so that it can be declared as const in the code. Update struct cmd_tbl with a const char * pointer for 'help'. We cannot make usage const because of the bmode command, used on mx53ppd for example. Signed-off-by: Simon Glass Reviewed-by: Jagan Teki Reviewed-by: Heinrich Schuchardt Reviewed-by: Heinrich Schuchardt Reviewed-by: Heinrich Schuchardt --- (no changes since v2) Changes in v2: - Explain why 'usage' cannot be const include/command.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/command.h b/include/command.h index 137cfbc3231..f8e07a591c6 100644 --- a/include/command.h +++ b/include/command.h @@ -45,7 +45,7 @@ struct cmd_tbl { char *const argv[]); char *usage; /* Usage message (short) */ #ifdef CONFIG_SYS_LONGHELP - char *help; /* Help message (long) */ + const char *help; /* Help message (long) */ #endif #ifdef CONFIG_AUTO_COMPLETE /* do auto completion on the arguments */ From patchwork Sun Sep 19 21:49:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1529893 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=hUUQSkkz; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HCLvz6W27z9sX3 for ; Mon, 20 Sep 2021 07:50:23 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CE2F383267; Sun, 19 Sep 2021 23:50:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="hUUQSkkz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A275183252; Sun, 19 Sep 2021 23:49:50 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) (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 8A2BA82DA1 for ; Sun, 19 Sep 2021 23:49:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x334.google.com with SMTP id l16-20020a9d6a90000000b0053b71f7dc83so20945163otq.7 for ; Sun, 19 Sep 2021 14:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ltsZl6v9OgHf5XjzPGMGQVtwkGN/7fLKS3I498w/HeA=; b=hUUQSkkz9QIBa7/HTdLPExVEBg9EM1cC/+taSzQ3c3d9i3A56fT2NGeBEeop4RUA+D 5DP1qGVl5A5RmYFRJ2d1jhZOIwcKCX1Y2n9S8lEUc2SwXJgkD4g2zFeH7cTLglPa9qRa OnqVZffq146O6/k1qdP/428h/eUY06LhxS07o= 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:mime-version:content-transfer-encoding; bh=ltsZl6v9OgHf5XjzPGMGQVtwkGN/7fLKS3I498w/HeA=; b=K4lrsKBTAkGSsNHAP8iJ1BGKrkkI6qKMTqXPPB/wmF+NxBWOFBZUN9lWVcKwuXEJQn TfJzFo6UsZqzUM3FBVH1HpQoXVQyBdqmYanNCLfeUyMbAW318pq029wEpmPANf8WCs0S cYMmEOBcoxruqVu/ivUXSm/irtCuTodT/xFzqKXDlPvcOaTrnBMJu13GLfBBhT/CkoUF IYnJNYABQ+WcQclqIM58vU7AT+Pv6FrhQGmaYukk2G1dhb2/HK1C0Dda5uBKyuoRwxSk ZDTq1u4oehAinnrPuXz7EPYhsZjzJbCWBXnaa5pLG3WfU/9YY5Afwbo+4JENX5ZqhXEA giyA== X-Gm-Message-State: AOAM533kRQGDTwqcLONAWBB6aryxyG1lvDWRY6R6oYtUyr85WhL1PcZq BFpiDuFSpcRs8OC80EAVYaahrTybsFzE3A== X-Google-Smtp-Source: ABdhPJzIx25RPUuX1bwi8cW18riqREIt57CX5Ye68OZQCSS30YnFFqLeKmiMk5ZF8EFspvO/RRmp+A== X-Received: by 2002:a9d:1708:: with SMTP id i8mr10811791ota.233.1632088182749; Sun, 19 Sep 2021 14:49:42 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id q25sm519897oof.33.2021.09.19.14.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 14:49:42 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Jagan Teki , Heinrich Schuchardt , Simon Glass , Mike Frysinger Subject: [PATCH v4 2/5] sf: Use const for the stage name Date: Sun, 19 Sep 2021 15:49:33 -0600 Message-Id: <20210919214937.3829422-3-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog In-Reply-To: <20210919214937.3829422-1-sjg@chromium.org> References: <20210919214937.3829422-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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 is not updated at runtime so should be marked const. Update the code accordingly. Signed-off-by: Simon Glass Reviewed-by: Jagan Teki Reviewed-by: Heinrich Schuchardt Reviewed-by: Heinrich Schuchardt Reviewed-by: Heinrich Schuchardt --- (no changes since v1) cmd/sf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/sf.c b/cmd/sf.c index eac27ed2d77..15361a4bddf 100644 --- a/cmd/sf.c +++ b/cmd/sf.c @@ -394,7 +394,7 @@ enum { STAGE_COUNT, }; -static char *stage_name[STAGE_COUNT] = { +static const char *stage_name[STAGE_COUNT] = { "erase", "check", "write", From patchwork Sun Sep 19 21:49:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1529894 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=PWTlOj5K; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HCLw758mYz9ssD for ; Mon, 20 Sep 2021 07:50:31 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2082A8324B; Sun, 19 Sep 2021 23:50:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="PWTlOj5K"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4612582DA1; Sun, 19 Sep 2021 23:49:51 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) (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 483DE8322E for ; Sun, 19 Sep 2021 23:49:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oo1-xc32.google.com with SMTP id p22-20020a4a8156000000b002a8c9ea1858so1255100oog.11 for ; Sun, 19 Sep 2021 14:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tVY7LBTwYLmpQAp2cn0ryy/324h0a8qRUWymKGB1kDQ=; b=PWTlOj5KhUI8AMf72GL0YKRp6GEgmRFD8lHDbmTIMZTJBBCDdzfutPY9XzMuG//15o RkD/B364fZReXiVwJGXFJ8UywyAD59amL2t9200d5Imv3va6bwnQ/QPu9FEXpLapxCBf Sw9TpwXDC+M4z0fgBp2prPj6V1vv6/81Ac92o= 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:mime-version:content-transfer-encoding; bh=tVY7LBTwYLmpQAp2cn0ryy/324h0a8qRUWymKGB1kDQ=; b=ilv4TjXYAHMNm3A+LWobT79XnteGiUeZ6jKWnKuaiS6pVosYrDF/xl3KhlxKRTOx7H Lbjh5i3u5q9ES3efrqFJbjgFV3LebhQgtuHai802iw4jilM00NqWzrqGOzQXCPN43ilr +xtrqVtsXcurReEMuETZ1s2PKEl0RfcSCzGWoa+3YmPoNUCEAhBWuAKzGioRuvbqAeXB y/NT2dt5eFRDYcDo6FscwAjbn5hcjjrZj31u9bYr2ot3biTGqnm3gVJ+egQp2N73pdqS CsJREihapd5euiKl9GYko/szFaKinrbxp+IzqvDuzymI8cWAN/gIABxBSMaBDGf6PW5L Ryxw== X-Gm-Message-State: AOAM532ZzySFNkgr8HdFOxPj+T0yGGWqLujSCgoncqnA0eL9/k0Qkq4G /qlFSICQrl6IlNSEBYPUmo56E3zCD44FQA== X-Google-Smtp-Source: ABdhPJzPxWRxauwd50q1dw5makI5uG5/xmHuOKS+jBFrF/FXeLppeCdVZ07T80e376TEnSFB7X8WJw== X-Received: by 2002:a4a:df01:: with SMTP id i1mr5282735oou.52.1632088183718; Sun, 19 Sep 2021 14:49:43 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id q25sm519897oof.33.2021.09.19.14.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 14:49:43 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Jagan Teki , Heinrich Schuchardt , Simon Glass , Pratyush Yadav , Mike Frysinger Subject: [PATCH v4 3/5] sf: Tidy up code to avoid #ifdef Date: Sun, 19 Sep 2021 15:49:34 -0600 Message-Id: <20210919214937.3829422-4-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog In-Reply-To: <20210919214937.3829422-1-sjg@chromium.org> References: <20210919214937.3829422-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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 Update this code to use IS_ENABLED() instead. Signed-off-by: Simon Glass Reviewed-by: Pratyush Yadav Reviewed-by: Jagan Teki Reviewed-by: Jagan Teki Reviewed-by: Jagan Teki --- (no changes since v1) cmd/sf.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/cmd/sf.c b/cmd/sf.c index 15361a4bddf..72246d912fe 100644 --- a/cmd/sf.c +++ b/cmd/sf.c @@ -384,7 +384,6 @@ static int do_spi_protect(int argc, char *const argv[]) return ret == 0 ? 0 : 1; } -#ifdef CONFIG_CMD_SF_TEST enum { STAGE_ERASE, STAGE_CHECK, @@ -548,7 +547,6 @@ static int do_spi_flash_test(int argc, char *const argv[]) return 0; } -#endif /* CONFIG_CMD_SF_TEST */ static int do_spi_flash(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) @@ -582,10 +580,8 @@ static int do_spi_flash(struct cmd_tbl *cmdtp, int flag, int argc, ret = do_spi_flash_erase(argc, argv); else if (strcmp(cmd, "protect") == 0) ret = do_spi_protect(argc, argv); -#ifdef CONFIG_CMD_SF_TEST - else if (!strcmp(cmd, "test")) + else if (IS_ENABLED(CONFIG_CMD_SF_TEST) && !strcmp(cmd, "test")) ret = do_spi_flash_test(argc, argv); -#endif else ret = -1; @@ -597,16 +593,8 @@ usage: return CMD_RET_USAGE; } -#ifdef CONFIG_CMD_SF_TEST -#define SF_TEST_HELP "\nsf test offset len " \ - "- run a very basic destructive test" -#else -#define SF_TEST_HELP -#endif - -U_BOOT_CMD( - sf, 5, 1, do_spi_flash, - "SPI flash sub-system", +#ifdef CONFIG_SYS_LONGHELP +static const char long_help[] = "probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n" " and chip select\n" "sf read addr offset|partition len - read `len' bytes starting at\n" @@ -622,6 +610,14 @@ U_BOOT_CMD( " at `addr' to flash at `offset'\n" " or to start of mtd `partition'\n" "sf protect lock/unlock sector len - protect/unprotect 'len' bytes starting\n" - " at address 'sector'\n" - SF_TEST_HELP + " at address 'sector'" +#ifdef CONFIG_CMD_SF_TEST + "\nsf test offset len - run a very basic destructive test" +#endif +#endif /* CONFIG_SYS_LONGHELP */ + ; + +U_BOOT_CMD( + sf, 5, 1, do_spi_flash, + "SPI flash sub-system", long_help ); From patchwork Sun Sep 19 21:49:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1529896 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=VRE6S9h/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HCLwZ2xpFz9sX3 for ; Mon, 20 Sep 2021 07:50:54 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9B0C183271; Sun, 19 Sep 2021 23:50:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="VRE6S9h/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8953281BC8; Sun, 19 Sep 2021 23:49:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) (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 8D6AA81BC8 for ; Sun, 19 Sep 2021 23:49:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x32d.google.com with SMTP id k12-20020a056830150c00b0051abe7f680bso20982314otp.1 for ; Sun, 19 Sep 2021 14:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bKx/eKPJlhIpcvbom4Isee5uFVx+A5ZdvXYL3eXqnGs=; b=VRE6S9h/YyYOTGqaWFvKyx7f9nb4ARJw1XoCOJr1hh7kb+2gTrh4q0M9InyrUE5Xsa wUizFiLGc6mU9vykgaK3i1E+n2lhx2XIlXf/rB/i6gzsl+8Paugv6W7PiAKztLKWFg1j nE6vaWclV8mRaKvX7xS+zFv6N4L093EEf8i0o= 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:mime-version:content-transfer-encoding; bh=bKx/eKPJlhIpcvbom4Isee5uFVx+A5ZdvXYL3eXqnGs=; b=WvyWzMiLuUpt7bOS81HVHDlG+5ut2Teb8OSBRr9Z1ZtqJtisHsBi5FFvc1R+E0/Deu KRLLRv18OS7kdEmjGLsVPoRtx8XDJYUI8bhu6Bpk6o1e21Argejkf8nYaXu1EBnJIIwM 4QJTcwTcHCjQmFE5w15a7Ha1pZgdYNHQwPRacSNMQE7CcmnmJQKUetxnunKmPFjR/0kW GMa3djUChenrVIlAuZhi9f0R2lXlcaoHKwmd8V8GkL27eDziK+aceyTPHbQZs11wt/Oo F/3Zd2AM5pvOI1nfl4danD1I3VV2alu8gJ0T8tNO/1BGUfHqjnB8Hs3ucHCaduclbY7Q Fihw== X-Gm-Message-State: AOAM530PcSLh2llEg5PRWwRbtYnJ0w7K7ucJ27Wr3UZdWttJQ7Zu6EMV pol5Cy7cgeKVSjXRobuJlWTieGCp9MruAA== X-Google-Smtp-Source: ABdhPJzFyLf5NABYaCwFy2Y77BZsgVlu7UZviU4V9LVp/Wd0E9SViZnDFKVixTpnnCp3y52butMqPA== X-Received: by 2002:a05:6830:1db3:: with SMTP id z19mr19291260oti.369.1632088184773; Sun, 19 Sep 2021 14:49:44 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id q25sm519897oof.33.2021.09.19.14.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 14:49:44 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Jagan Teki , Heinrich Schuchardt , Simon Glass , Pratyush Yadav , Mike Frysinger Subject: [PATCH v4 4/5] sf: doc: Add documentation for the 'sf' command Date: Sun, 19 Sep 2021 15:49:35 -0600 Message-Id: <20210919214937.3829422-5-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog In-Reply-To: <20210919214937.3829422-1-sjg@chromium.org> References: <20210919214937.3829422-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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 command is fairly complicated so documentation is useful. Unfortunately I an not sure how the MTD side of things works and cannot find information about that. Signed-off-by: Simon Glass Acked-by: Pratyush Yadav Reviewed-by: Jagan Teki Acked-by: Heinrich Schuchardt --- Changes in v4: - Split out the 'const' change into a separate patch - Show the 'sf probe' output in the examples Changes in v2: - Many fixes as suggested by Heinrich doc/usage/index.rst | 1 + doc/usage/sf.rst | 245 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 246 insertions(+) create mode 100644 doc/usage/sf.rst diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 356f2a56181..9a7b12b7c54 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -43,6 +43,7 @@ Shell commands qfw reset sbi + sf scp03 setexpr size diff --git a/doc/usage/sf.rst b/doc/usage/sf.rst new file mode 100644 index 00000000000..71bd1be5175 --- /dev/null +++ b/doc/usage/sf.rst @@ -0,0 +1,245 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +sf command +========== + +Synopis +------- + +:: + + sf probe [[[:]] [ []]] + sf read | + sf write | + sf erase | + sf update | + sf protect lock|unlock + sf test | + +Description +----------- + +The *sf* command is used to access SPI flash, supporting read/write/erase and +a few other functions. + +Probe +----- + +The flash must first be probed with *sf probe* before any of the other +subcommands can be used. All of the parameters are optional: + +bus + SPI bus number containing the SPI-flash chip, e.g. 0. If you don't know + the number, you can use 'dm uclass' to see all the spi devices, + and check the value for 'seq' for each one (here 0 and 2):: + + uclass 89: spi + 0 spi@0 @ 05484960, seq 0 + 1 spi@1 @ 05484b40, seq 2 + +cs + SPI chip-select to use for the chip. This is often 0 and can be omitted, + but in some cases multiple slaves are attached to a SPI controller, + selected by a chip-select line for each one. + +hz + Speed of the SPI bus in hertz. This normally defaults to 100000, i.e. + 100KHz, which is very slow. Note that if the device exists in the + device tree, there might be a speed provided there, in which case this + setting is ignored. + +mode + SPI mode to use: + + ===== ================ + Mode Meaning + ===== ================ + 0 CPOL=0, CPHA=0 + 1 CPOL=0, CPHA=1 + 2 CPOL=1, CPHA=0 + 3 CPOL=1, CPHA=1 + ===== ================ + + Clock phase (CPHA) 0 means that data is transferred (sampled) on the + first clock edge; 1 means the second. + + Clock polarity (CPOL) controls the idle state of the clock, 0 for low, + 1 for high. + The active state is the opposite of idle. + + You may find this `SPI documentation`_ useful. + +Parameters for other subcommands (described below) are as follows: + +addr + Memory address to start transfer + +offset + Flash offset to start transfer + +partition + If the parameter is not numeric, it is assumed to be a partition + description in the format , which is not + covered here. This requires CONFIG_CMD_MTDPARTS. + +len + Number of bytes to transfer + +Read +~~~~ + +Use *sf read* to read from SPI flash to memory. The read will fail if an +attempt is made to read past the end of the flash. + + +Write +~~~~~ + +Use *sf write* to write from memory to SPI flash. The SPI flash should be +erased first, since otherwise the result is undefined. + +The write will fail if an attempt is made to read past the end of the flash. + + +Erase +~~~~~ + +Use *sf erase* to erase a region of SPI flash. The erase will fail if any part +of the region to be erased is protected or lies past the end of the flash. It +may also fail if the start offset or length are not aligned to an erase region +(e.g. 256 bytes). + + +Update +~~~~~~ + +Use *sf update* to automatically erase and update a region of SPI flash from +memory. This works a sector at a time (typical 4KB or 64KB). For each +sector it first checks if the sector already has the right data. If so it is +skipped. If not, the sector is erased and the new data written. Note that if +the length is not a multiple of the erase size, the space after the data in +the last sector will be erased. If the offset does not start at the beginning +of an erase block, the operation will fail. + +Speed statistics are shown including the number of bytes that were already +correct. + + +Protect +~~~~~~~ + +SPI-flash chips often have a protection feature where the chip is split up into +regions which can be locked or unlocked. With *sf protect* it is possible to +change these settings, if supported by the driver. + +lock|unlock + Selects whether to lock or unlock the sectors + + + Start sector number to lock/unlock. This may be the byte offset or some + other value, depending on the chip. + + + Number of bytes to lock/unlock + + +Test +~~~~ + +A convenient and fast *sf test* subcommand provides a way to check that SPI +flash is working as expected. This works in four stages: + + * erase - erases the entire region + * check - checks that the region is erased + * write - writes a test pattern to the region, consisting of the U-Boot code + * read - reads back the test pattern to check that it was written correctly + +Memory is allocated for two buffers, each bytes in size. At typical +size is 64KB to 1MB. The offset and size must be aligned to an erase boundary. + +Note that this test will fail if any part of the SPI flash is write-protected. + + +Examples +-------- + +This first example uses sandbox:: + + => sf probe + SF: Detected m25p16 with page size 256 Bytes, erase size 64 KiB, total 2 MiB + => sf read 1000 1100 80000 + device 0 offset 0x1100, size 0x80000 + SF: 524288 bytes @ 0x1100 Read: OK + => md 1000 + 00001000: edfe0dd0 f33a0000 78000000 84250000 ......:....x..%. + 00001010: 28000000 11000000 10000000 00000000 ...(............ + 00001020: 6f050000 0c250000 00000000 00000000 ...o..%......... + 00001030: 00000000 00000000 00000000 00000000 ................ + 00001040: 00000000 00000000 00000000 00000000 ................ + 00001050: 00000000 00000000 00000000 00000000 ................ + 00001060: 00000000 00000000 00000000 00000000 ................ + 00001070: 00000000 00000000 01000000 00000000 ................ + 00001080: 03000000 04000000 00000000 01000000 ................ + 00001090: 03000000 04000000 0f000000 01000000 ................ + 000010a0: 03000000 08000000 1b000000 646e6173 ............sand + 000010b0: 00786f62 03000000 08000000 21000000 box............! + 000010c0: 646e6173 00786f62 01000000 61696c61 sandbox.....alia + 000010d0: 00736573 03000000 07000000 2c000000 ses............, + 000010e0: 6332692f 00003040 03000000 07000000 /i2c@0.......... + 000010f0: 31000000 6963702f 00003040 03000000 ...1/pci@0...... + => sf erase 0 80000 + SF: 524288 bytes @ 0x0 Erased: OK + => sf read 1000 1100 80000 + device 0 offset 0x1100, size 0x80000 + SF: 524288 bytes @ 0x1100 Read: OK + => md 1000 + 00001000: ffffffff ffffffff ffffffff ffffffff ................ + 00001010: ffffffff ffffffff ffffffff ffffffff ................ + 00001020: ffffffff ffffffff ffffffff ffffffff ................ + 00001030: ffffffff ffffffff ffffffff ffffffff ................ + 00001040: ffffffff ffffffff ffffffff ffffffff ................ + 00001050: ffffffff ffffffff ffffffff ffffffff ................ + 00001060: ffffffff ffffffff ffffffff ffffffff ................ + 00001070: ffffffff ffffffff ffffffff ffffffff ................ + 00001080: ffffffff ffffffff ffffffff ffffffff ................ + 00001090: ffffffff ffffffff ffffffff ffffffff ................ + 000010a0: ffffffff ffffffff ffffffff ffffffff ................ + 000010b0: ffffffff ffffffff ffffffff ffffffff ................ + 000010c0: ffffffff ffffffff ffffffff ffffffff ................ + 000010d0: ffffffff ffffffff ffffffff ffffffff ................ + 000010e0: ffffffff ffffffff ffffffff ffffffff ................ + 000010f0: ffffffff ffffffff ffffffff ffffffff ................ + +This second example is running on coral, an x86 Chromebook:: + + => sf probe + SF: Detected w25q128fw with page size 256 Bytes, erase size 4 KiB, total 16 MiB + => sf erase 300000 80000 + SF: 524288 bytes @ 0x300000 Erased: OK + => sf update 1110000 300000 80000 + device 0 offset 0x300000, size 0x80000 + 524288 bytes written, 0 bytes skipped in 0.457s, speed 1164578 B/s + + # This does nothing as the flash is already updated + => sf update 1110000 300000 80000 + device 0 offset 0x300000, size 0x80000 + 0 bytes written, 524288 bytes skipped in 0.196s, speed 2684354 B/s + => sf test 00000 80000 # try a protected region + SPI flash test: + Erase failed (err = -5) + Test failed + => sf test 800000 80000 + SPI flash test: + 0 erase: 18 ticks, 28444 KiB/s 227.552 Mbps + 1 check: 192 ticks, 2666 KiB/s 21.328 Mbps + 2 write: 227 ticks, 2255 KiB/s 18.040 Mbps + 3 read: 189 ticks, 2708 KiB/s 21.664 Mbps + Test passed + 0 erase: 18 ticks, 28444 KiB/s 227.552 Mbps + 1 check: 192 ticks, 2666 KiB/s 21.328 Mbps + 2 write: 227 ticks, 2255 KiB/s 18.040 Mbps + 3 read: 189 ticks, 2708 KiB/s 21.664 Mbps + + +.. _SPI documentation: + https://en.wikipedia.org/wiki/Serial_Peripheral_Interface From patchwork Sun Sep 19 21:49:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1529895 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=FCgF6Em1; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HCLwL6DmVz9sX3 for ; Mon, 20 Sep 2021 07:50:42 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CDDA783273; Sun, 19 Sep 2021 23:50:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="FCgF6Em1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CE9858048A; Sun, 19 Sep 2021 23:49:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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-oo1-xc2c.google.com (mail-oo1-xc2c.google.com [IPv6:2607:f8b0:4864:20::c2c]) (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 7725380202 for ; Sun, 19 Sep 2021 23:49:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oo1-xc2c.google.com with SMTP id l17-20020a4ae391000000b00294ad0b1f52so5190262oov.10 for ; Sun, 19 Sep 2021 14:49:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gWrFm+iJP4g2VCpjmU/UUFxbSFVKdcTUbJFfSgkzbnQ=; b=FCgF6Em1maEZoH79PSG+UJGdScTVsYlWSyxAEOx6imsNUI6n7OLNl7r9898osQ6nWE +qvWTXSNzk7xFWuHfI9WAbiN6mrXpZgBstuluNAT2hL8VXUX6AfMdSlTQnIo/03VfwxD dcD+UKN18P7oCumisM0xUHDfhJ2auP1Vud9sY= 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:mime-version:content-transfer-encoding; bh=gWrFm+iJP4g2VCpjmU/UUFxbSFVKdcTUbJFfSgkzbnQ=; b=YinzxRRiGioqs/PqMgiyddC2+kcR7yhXHqxRQpv1bW93eDdRYj7c4yeB6R6nngDnyf ldlRw+1TljTV5V1r8R2JUC8gctI5rZe8+KwhdkCPiRDjHnfuXNCJgK6QBWlB1+1xwIe2 Rb8GDKXnvq9Ww5MsEjUberIuSsJtqRNklDnR6//oegN7NoPxkm6akogpzjIZsvYd21Gl oGBvrV3/vdD13XQiVtit+qxGbqpQpZJcHlgLLiJtVXyOu+rUrrPJhKgmrMgMvEbDBBpI nt0X7naSx6BqSqRlhaVW3GWY2wn0uqJ3lYCXSjtgWUUqwtTIdUK8SdOTebcgiiqrYuAa 3jEw== X-Gm-Message-State: AOAM533mSgWMwmG48Wp4P1zG8U7xBztlsbyjwYfxtSjKrPLIvx8cbUb0 d2bBh2s+pFjPHJJ6QRlbIGfWvS+Bk7mUUA== X-Google-Smtp-Source: ABdhPJz21K+urUSxmOu5ii0I8p1Y4M9nuAjTRX5oNqGAneY3+b3NcL6LuqwOJ5DIHVRsDKtZK6Hn/w== X-Received: by 2002:a4a:e499:: with SMTP id s25mr17531719oov.46.1632088185785; Sun, 19 Sep 2021 14:49:45 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id q25sm519897oof.33.2021.09.19.14.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 14:49:45 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Jagan Teki , Heinrich Schuchardt , Simon Glass , Mike Frysinger Subject: [PATCH v4 5/5] sf: Provide a command to access memory-mapped SPI Date: Sun, 19 Sep 2021 15:49:36 -0600 Message-Id: <20210919214937.3829422-6-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog In-Reply-To: <20210919214937.3829422-1-sjg@chromium.org> References: <20210919214937.3829422-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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 Add a new 'sf mmap' function to show the address of a SPI offset, if the hardware supports it. This is useful on x86 systems. Signed-off-by: Simon Glass --- (no changes since v3) Changes in v3: - Add configuration and return value also arch/Kconfig | 2 ++ cmd/Kconfig | 8 ++++++ cmd/sf.c | 35 +++++++++++++++++++++++++++ doc/usage/sf.rst | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 8f8daadcf92..406e5a6c627 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -136,6 +136,7 @@ config SANDBOX imply CMD_LZMADEC imply CMD_SATA imply CMD_SF + imply CMD_SF_MMAP imply CMD_SF_TEST imply CRC32_VERIFY imply FAT_WRITE @@ -200,6 +201,7 @@ config X86 imply CMD_IRQ imply CMD_PCI imply CMD_SF + imply CMD_SF_MMAP imply CMD_SF_TEST imply CMD_ZBOOT imply DM_ETH diff --git a/cmd/Kconfig b/cmd/Kconfig index 3a857b3f6e2..44485f1588c 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1273,6 +1273,14 @@ config CMD_SF help SPI Flash support +config CMD_SF_MMAP + bool "sf mmap - Access memory-mapped SPI flash" + depends on CMD_SF + help + On some systems part of the SPI flash is mapped into mmemory. This + command provides a way to map a SPI-flash offset to a memory address, + so that the contents can be browsed using 'md', for example. + config CMD_SF_TEST bool "sf test - Allow testing of SPI flash" depends on CMD_SF diff --git a/cmd/sf.c b/cmd/sf.c index 72246d912fe..c78cd7e6342 100644 --- a/cmd/sf.c +++ b/cmd/sf.c @@ -384,6 +384,36 @@ static int do_spi_protect(int argc, char *const argv[]) return ret == 0 ? 0 : 1; } +static int do_spi_flash_mmap(int argc, char *const argv[]) +{ + loff_t offset, len, maxsize; + uint map_offset, map_size; + ulong map_base; + int dev = 0; + int ret; + + if (argc < 2) + return CMD_RET_USAGE; + + ret = mtd_arg_off_size(argc - 1, &argv[1], &dev, &offset, &len, + &maxsize, MTD_DEV_TYPE_NOR, flash->size); + if (ret) + return ret; + + ret = dm_spi_get_mmap(flash->dev, &map_base, &map_size, &map_offset); + if (ret) { + printf("Mapping not available (err=%d)\n", ret); + return CMD_RET_FAILURE; + } + if (offset < 0 || offset + len > map_size) { + printf("Offset out of range (map size %x)\n", map_size); + return CMD_RET_FAILURE; + } + printf("%lx\n", map_base + (ulong)offset); + + return 0; +} + enum { STAGE_ERASE, STAGE_CHECK, @@ -580,6 +610,8 @@ static int do_spi_flash(struct cmd_tbl *cmdtp, int flag, int argc, ret = do_spi_flash_erase(argc, argv); else if (strcmp(cmd, "protect") == 0) ret = do_spi_protect(argc, argv); + else if (IS_ENABLED(CONFIG_CMD_SF_MMAP) && !strcmp(cmd, "mmap")) + ret = do_spi_flash_mmap(argc, argv); else if (IS_ENABLED(CONFIG_CMD_SF_TEST) && !strcmp(cmd, "test")) ret = do_spi_flash_test(argc, argv); else @@ -611,6 +643,9 @@ static const char long_help[] = " or to start of mtd `partition'\n" "sf protect lock/unlock sector len - protect/unprotect 'len' bytes starting\n" " at address 'sector'" +#ifdef CONFIG_CMD_SF_MMAP + "\nsf mmap offset len - get memory address of SPI-flash offset\n" +#endif #ifdef CONFIG_CMD_SF_TEST "\nsf test offset len - run a very basic destructive test" #endif diff --git a/doc/usage/sf.rst b/doc/usage/sf.rst index 71bd1be5175..93fb8409370 100644 --- a/doc/usage/sf.rst +++ b/doc/usage/sf.rst @@ -14,6 +14,7 @@ Synopis sf erase | sf update | sf protect lock|unlock + sf mmap | sf test | Description @@ -143,6 +144,16 @@ lock|unlock Number of bytes to lock/unlock +Memory-mapped flash +------------------- + +On some systems part of the SPI flash is mapped into mmemory. With *sf mmap* +you can map a SPI-flash offset to a memory address, so that the contents can be +browsed using 'md', for example. + +The command will fail if this is not supported by the hardware or driver. + + Test ~~~~ @@ -240,6 +251,58 @@ This second example is running on coral, an x86 Chromebook:: 2 write: 227 ticks, 2255 KiB/s 18.040 Mbps 3 read: 189 ticks, 2708 KiB/s 21.664 Mbps + # On coral, SPI flash offset 0 corresponds to address ff081000 in memory + => sf mmap 0 1000 + device 0 offset 0x0, size 0x1000 + ff081000 + + # See below for how this address was obtained + => sf mmap e80000 11e18 + device 0 offset 0xe80000, size 0x11e18 + fff01000 + => md fff01000 + fff01000: b2e8e089 89000030 30b4e8c4 c0310000 ....0......0..1. + fff01010: 002c95e8 2ce8e800 feeb0000 dfe8c489 ..,....,........ + fff01020: f400002c 83f4fdeb d4e80cec 3100001e ,..............1 + fff01030: 0cc483c0 f883c3c3 8b0b770a df408504 .........w....@. + fff01040: c085fef1 c8b80575 c3fef1e5 53565755 ....u.......UWVS + fff01050: 89c38951 2404c7c5 80000002 8924048b Q......$......$. + fff01060: 89a20fdf 89fb89de 75890045 084d8904 ........E..u..M. + fff01070: ff0c5589 c5832404 243c8110 80000005 .U...$....<$.... + fff01080: 43c6da75 3b800030 43037520 d889f8eb u..C0..; u.C.... + fff01090: 5f5e5b5a 80e6c35d 535657c3 e7e8c689 Z[^_]....WVS.... + fff010a0: 89000069 00a164c3 8b000000 408b4c56 i....d......VL.@ + fff010b0: 0cec837c ddb9ff6a e8fef1e5 00004e01 |...j........N.. + fff010c0: a1640389 00000000 1c80b60f 66000001 ..d............f + fff010d0: b80c4389 00000001 a20fdf89 fb89de89 .C.............. + fff010e0: 89104389 c4831453 5bc03110 56c35f5e .C..S....1.[^_.V + fff010f0: 14ec8353 ce89d389 0000a164 b60f0000 S.......d....... + + +The offset e80000 was obtained using the following binman command, to find the +location of U-Boot SPL:: + + $ binman ls -i /tmp/b/chromebook_coral/u-boot.rom + Name Image-pos Size Entry-type Offset Uncomp-size + ------------------------------------------------------------------------------------------------------ + main-section 0 1000000 section 0 + spl e80000 11e18 u-boot-spl ffe80000 + u-boot d00000 9106e u-boot ffd00000 + ... + .. _SPI documentation: https://en.wikipedia.org/wiki/Serial_Peripheral_Interface + + +Configuration +------------- + +The *sf* command is only available if `CONFIG_CMD_SF=y`. Note that it depends on +`CONFIG_DM_SPI_FLASH`. + +Return value +------------ + +The return value $? is set to 0 (true) if the command succeded and to 1 (false) +otherwise.