{"id":2219646,"url":"http://patchwork.ozlabs.org/api/patches/2219646/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-mtd/patch/20260403-winbond-v6-18-rc1-spi-nor-swp-v4-19-833dab5e7288@bootlin.com/","project":{"id":3,"url":"http://patchwork.ozlabs.org/api/projects/3/?format=json","name":"Linux MTD development","link_name":"linux-mtd","list_id":"linux-mtd.lists.infradead.org","list_email":"linux-mtd@lists.infradead.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260403-winbond-v6-18-rc1-spi-nor-swp-v4-19-833dab5e7288@bootlin.com>","list_archive_url":null,"date":"2026-04-03T16:09:37","name":"[v4,19/27] mtd: spi-nor: Add steps for testing locking support","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"78ed50e48564a6b0341a33cf98dc0c23c09f20a1","submitter":{"id":73368,"url":"http://patchwork.ozlabs.org/api/people/73368/?format=json","name":"Miquel Raynal","email":"miquel.raynal@bootlin.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-mtd/patch/20260403-winbond-v6-18-rc1-spi-nor-swp-v4-19-833dab5e7288@bootlin.com/mbox/","series":[{"id":498652,"url":"http://patchwork.ozlabs.org/api/series/498652/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-mtd/list/?series=498652","date":"2026-04-03T16:09:18","name":"mtd: spi-nor: Enhance software protection","version":4,"mbox":"http://patchwork.ozlabs.org/series/498652/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2219646/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219646/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=vvP/F952;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256\n header.s=casper.20170209 header.b=vfHT+B8g;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256\n header.s=dkim header.b=WRUdMRLi;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fnNxN5ttZz1yCs\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 04 Apr 2026 03:10:48 +1100 (AEDT)","from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8h6X-00000002HuU-1Eyx;\n\tFri, 03 Apr 2026 16:10:41 +0000","from casper.infradead.org ([2001:8b0:10b:1236::1])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8h6T-00000002HoI-2Ox5\n\tfor linux-mtd@bombadil.infradead.org;\n\tFri, 03 Apr 2026 16:10:37 +0000","from smtpout-02.galae.net ([185.246.84.56])\n\tby casper.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8h6I-0000000EgfX-32MW\n\tfor linux-mtd@lists.infradead.org;\n\tFri, 03 Apr 2026 16:10:36 +0000","from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233])\n\tby smtpout-02.galae.net (Postfix) with ESMTPS id 8E41A1A312C;\n\tFri,  3 Apr 2026 16:10:22 +0000 (UTC)","from mail.galae.net (mail.galae.net [212.83.136.155])\n\tby smtpout-01.galae.net (Postfix) with ESMTPS id 5B0EC603C1;\n\tFri,  3 Apr 2026 16:10:22 +0000 (UTC)","from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon)\n with ESMTPSA id B134B1045010A;\n\tFri,  3 Apr 2026 18:10:19 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id\n\t:MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=pfThXVAoZQAb/MRL5fkJ4EU0SrkB/QB/CfEt1oGW/gA=; b=vvP/F952O/X/4H\n\tGosQEWlbids2ADQGoFPl0WIvOve3lp1KCP8EveeL1dBPVlrlztJFNqSCCQ9GLBgg2ceL0crbral9P\n\ttj2pQqub4S6RKhGjtNc6y/bCk8uUlsUzHgHsgC3uiuVEUhxX/YKS+sv+hebQKIJNGkYseTkVfeQ/U\n\tfP1odFiuVvbFShzGjnU/4RAkwKKYXOocTycws2F4kP2URRdp+r68U68C0ra4exHzBrH8jBM0BrdR9\n\tm1rqguXSTtb3uSCBAyng1g9zPTyMqcYjLvk2BKcLREb4Pb/fBefGNtL5LllpxuDZsWJVKkHgS7Lz9\n\tBFZkuHQCRqdj9a9s5lag==;","v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=infradead.org; s=casper.20170209; h=Cc:To:In-Reply-To:References:Message-Id\n\t:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender\n\t:Reply-To:Content-ID:Content-Description;\n\tbh=rBjeS7Y+svFeJ3kkZc7HFjvdCDhIs6VUadHpnKxpakQ=; b=vfHT+B8gSoq3AjNKWiZVZianxG\n\tkotSfQ4dlSvUVsBBxat/A5bFdG/2meHolxzD8bOgDDpFNe6K9mWvzz8iLxPm6BsNIlYmHiHKID0tp\n\tqalP2daXiG9bhw92tT8hZoqqZskcjAG8cNujOs0iOrt0Pu4GCeUiXQK0Wez0Fx9az3sUvU2NuvlE0\n\tKfNVa4WHBWepulwMgjagt1yoX183oKEX6+B0bmgREX/9d3qi0nqkbL7qtBIZNGTn+FJXY5gI1QZ8W\n\t6iu6S3GS5Fad8LfyRQxBaUvybfR5yAaClAmPeQrCoEiHtP5/NPQX4+oln+KUrj7DPuc9wFSnZGl0/\n\t33Oz5pPw==;","v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim;\n\tt=1775232621; h=from:subject:date:message-id:to:cc:mime-version:content-type:\n\t content-transfer-encoding:in-reply-to:references;\n\tbh=rBjeS7Y+svFeJ3kkZc7HFjvdCDhIs6VUadHpnKxpakQ=;\n\tb=WRUdMRLiLM1dBCv2ifyVz44zPpLmIdO2W03YMcMUY3RA99giK6iDbI2wWn5X8XOQ3PAg4r\n\tTCiHrBfOG4vwqwTdDysuV4RsgmyVc5aU1+HTyUlHmIbhUERt+EaltFEZhB24WTcORNe0Ig\n\tl7aOYDzYfriGmuzfNaQ+Ux4GSy7r8v/N5YVRZ7pOYsTo/Fd3veSZM2uUQTjXE8ezCLw3FO\n\trDGh3RTgU3v89VRZOzL9vrxB0e7wBwDSmQuS4T//zzC+AlC7JdWj3JONyINHgQroc1GEOR\n\tQggETdPkVe8V0efdjIWFt+6eJbS36cbSnqs7nUD9NX7Q0SD05RLZRqKsTsF8jA=="],"From":"Miquel Raynal <miquel.raynal@bootlin.com>","Date":"Fri, 03 Apr 2026 18:09:37 +0200","Subject":"[PATCH v4 19/27] mtd: spi-nor: Add steps for testing locking\n support","MIME-Version":"1.0","Message-Id":"\n <20260403-winbond-v6-18-rc1-spi-nor-swp-v4-19-833dab5e7288@bootlin.com>","References":"\n <20260403-winbond-v6-18-rc1-spi-nor-swp-v4-0-833dab5e7288@bootlin.com>","In-Reply-To":"\n <20260403-winbond-v6-18-rc1-spi-nor-swp-v4-0-833dab5e7288@bootlin.com>","To":"Pratyush Yadav <pratyush@kernel.org>, Michael Walle <mwalle@kernel.org>,\n Takahiro Kuwano <takahiro.kuwano@infineon.com>,\n Richard Weinberger <richard@nod.at>, Vignesh Raghavendra <vigneshr@ti.com>,\n Jonathan Corbet <corbet@lwn.net>","Cc":"Sean Anderson <sean.anderson@linux.dev>,\n Thomas Petazzoni <thomas.petazzoni@bootlin.com>,\n Steam Lin <STLin2@winbond.com>, linux-mtd@lists.infradead.org,\n linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,\n Miquel Raynal <miquel.raynal@bootlin.com>","X-Mailer":"b4 0.14.3","X-Last-TLS-Session-Version":"TLSv1.3","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20260403_171027_348906_2ACEC03E ","X-CRM114-Status":"GOOD (  14.11  )","X-Spam-Score":"-2.1 (--)","X-Spam-Report":"SpamAssassin version 4.0.1 on casper.infradead.org summary:\n Content analysis details:   (-2.1 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n -0.0 SPF_HELO_PASS          SPF: HELO matches SPF record\n -0.0 SPF_PASS               SPF: sender matches SPF record\n  0.1 DKIM_SIGNED            Message has a DKIM or DK signature,\n not necessarily valid\n -0.1 DKIM_VALID             Message has at least one valid DKIM or DK\n signature\n -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from\n                             envelope-from domain\n -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from\n author's\n                             domain\n -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n                             [score: 0.0000]\n  0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The\n                             query to Validity was blocked.  See\n                             https://knowledge.validity.com/hc/en-us/articles/20961730681243\n                              for more information.\n                          [185.246.84.56 listed in\n sa-trusted.bondedsender.org]\n  0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to\n                              Validity was blocked.  See\n                             https://knowledge.validity.com/hc/en-us/articles/20961730681243\n                              for more information.\n                             [185.246.84.56 listed in sa-accredit.habeas.com]\n  0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to\n                              Validity was blocked.  See\n                             https://knowledge.validity.com/hc/en-us/articles/20961730681243\n                              for more information.\n                             [185.246.84.56 listed in\n bl.score.senderscore.com]","X-BeenThere":"linux-mtd@lists.infradead.org","X-Mailman-Version":"2.1.34","Precedence":"list","List-Id":"Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-mtd>,\n <mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-mtd/>","List-Post":"<mailto:linux-mtd@lists.infradead.org>","List-Help":"<mailto:linux-mtd-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-mtd>,\n <mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-mtd\" <linux-mtd-bounces@lists.infradead.org>","Errors-To":"linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"As recently raised on the mailing list, it may be useful to propose a\nlist of steps to go through in order to proove the devices have been\ndescribed correctly, especially since all the block protection\ninformation is not stored in any kind of table and is instead filled\nmanually by developpers.\n\nUse the debugfs output to ease the comparison between expectations and\nreality.\n\nSigned-off-by: Miquel Raynal <miquel.raynal@bootlin.com>\n---\n Documentation/driver-api/mtd/spi-nor.rst | 128 +++++++++++++++++++++++++++++++\n 1 file changed, 128 insertions(+)","diff":"diff --git a/Documentation/driver-api/mtd/spi-nor.rst b/Documentation/driver-api/mtd/spi-nor.rst\nindex 148fa4288760..4755eb75fe5e 100644\n--- a/Documentation/driver-api/mtd/spi-nor.rst\n+++ b/Documentation/driver-api/mtd/spi-nor.rst\n@@ -203,3 +203,131 @@ section, after the ``---`` marker.\n     mtd.writesize = 1\n     mtd.oobsize = 0\n     regions = 0\n+\n+5) If your flash supports locking, please go through the following test\n+   procedure to make sure it correctly behaves. The below example\n+   expects the typical situation where eraseblocks and lock sectors have\n+   the same size. In case you enabled MTD_SPI_NOR_USE_4K_SECTORS, you\n+   must adapt `bs` accordingly.\n+\n+   Warning: These tests may hard lock your device! Make sure:\n+   - The device is not hard locked already (#WP strapped to low and\n+     SR_SRWD bit set)\n+   - If you have a WPn pin, you may want to set `no-wp` in your DT for\n+     the time of the test, to only make use of software protection.\n+     Otherwise, clearing the locking state depends on the WPn\n+     signal and if it is tied to low, the flash will be permanently\n+     locked.\n+\n+   Test full chip locking and make sure expectations, the MEMISLOCKED\n+   ioctl output, the debugfs output and experimental results are all\n+   aligned::\n+\n+    root@1:~# alias show_sectors='grep -A4 \"locked sectors\" /sys/kernel/debug/spi-nor/spi0.0/params'\n+    root@1:~# flash_lock -u /dev/mtd0\n+    root@1:~# flash_lock -i /dev/mtd0\n+    Device: /dev/mtd0\n+    Start: 0\n+    Len: 0x4000000\n+    Lock status: unlocked\n+    Return code: 0\n+    root@1:~# mtd_debug erase /dev/mtd0 0 2097152\n+    Erased 2097152 bytes from address 0x00000000 in flash\n+    root@1:~# mtd_debug write /dev/mtd0 0 2097152 spi_test\n+    Copied 2097152 bytes from spi_test to address 0x00000000 in flash\n+    root@1:~# mtd_debug read /dev/mtd0 0 2097152 spi_read\n+    Copied 2097152 bytes from address 0x00000000 in flash to spi_read\n+    root@1:~# sha256sum spi*\n+    c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8  spi_read\n+    c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8  spi_test\n+    root@1:~# show_sectors\n+    software locked sectors\n+     region (in hex)   | status   | #blocks\n+     ------------------+----------+--------\n+     00000000-03ffffff | unlocked | 1024\n+\n+    root@1:~# flash_lock -l /dev/mtd0\n+    root@1:~# flash_lock -i /dev/mtd0\n+    Device: /dev/mtd0\n+    Start: 0\n+    Len: 0x4000000\n+    Lock status: locked\n+    Return code: 1\n+    root@1:~# mtd_debug erase /dev/mtd0 0 2097152\n+    Erased 2097152 bytes from address 0x00000000 in flash\n+    root@1:~# mtd_debug read /dev/mtd0 0 2097152 spi_read\n+    Copied 2097152 bytes from address 0x00000000 in flash to spi_read\n+    root@1:~# sha256sum spi*\n+    c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8  spi_read\n+    c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8  spi_test\n+    root@1:~# dd if=/dev/urandom of=./spi_test2 bs=1M count=2\n+    2+0 records in\n+    2+0 records out\n+    root@1:~# mtd_debug write /dev/mtd0 0 2097152 spi_test2\n+    Copied 2097152 bytes from spi_test to address 0x00000000 in flash\n+    root@1:~# mtd_debug read /dev/mtd0 0 2097152 spi_read2\n+    Copied 2097152 bytes from address 0x00000000 in flash to spi_read\n+    root@1:~# sha256sum spi*\n+    c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8  spi_read\n+    c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8  spi_read2\n+    c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8  spi_test\n+    bea9334df51c620440f86751cba0799214a016329f1736f9456d40cf40efdc88  spi_test2\n+    root@1:~# show_sectors\n+    software locked sectors\n+     region (in hex)   | status   | #blocks\n+     ------------------+----------+--------\n+     00000000-03ffffff |   locked | 1024\n+\n+   Once we trust the debugfs output we can use it to test various\n+   situations. Check top locking/unlocking (end of the device)::\n+\n+    root@1:~# bs=$(cat /sys/class/mtd/mtd0/erasesize)\n+    root@1:~# size=$(cat /sys/class/mtd/mtd0/size)\n+\n+    root@1:~# flash_lock -u /dev/mtd0\n+    root@1:~# flash_lock -l /dev/mtd0 $(($size - (2 * $bs))) 2 # last two\n+    root@1:~# show_sectors\n+    software locked sectors\n+     region (in hex)   | status   | #blocks\n+     ------------------+----------+--------\n+     00000000-03fdffff | unlocked | 1022\n+     03fe0000-03ffffff |   locked | 2\n+    root@1:~# flash_lock -u /dev/mtd0 $(($size - (2 * $bs))) 1 # last one\n+    root@1:~# show_sectors\n+    software locked sectors\n+     region (in hex)   | status   | #blocks\n+     ------------------+----------+--------\n+     00000000-03feffff | unlocked | 1023\n+     03ff0000-03ffffff |   locked | 1\n+\n+   If the flash features 4 block protection bits (BP), we can protect\n+   more than 4MB (typically 128 64kiB-blocks or more), with a finer\n+   grain than locking the entire device::\n+\n+    root@1:~# flash_lock -u /dev/mtd0\n+    root@1:~# flash_lock -l /dev/mtd0 $(($size - (2**7 * $bs))) $((2**7))\n+    root@1:~# show_sectors\n+    software locked sectors\n+     region (in hex)   | status   | #blocks\n+     ------------------+----------+--------\n+     00000000-037fffff | unlocked | 896\n+     03800000-03ffffff |   locked | 128\n+\n+   If the flash features a Top/Bottom (TB) bit, we can protect the\n+   beginning of the flash::\n+\n+    root@1:~# flash_lock -u /dev/mtd0\n+    root@1:~# flash_lock -l /dev/mtd0 0 2 # first two\n+    root@1:~# show_sectors\n+    software locked sectors\n+     region (in hex)   | status   | #blocks\n+     ------------------+----------+--------\n+     00000000-0001ffff |   locked | 2\n+     00020000-03ffffff | unlocked | 1022\n+    root@1:~# flash_lock -u /dev/mtd0 $bs 1 # first one\n+    root@1:~# show_sectors\n+    software locked sectors\n+     region (in hex)   | status   | #blocks\n+     ------------------+----------+--------\n+     00000000-0000ffff |   locked | 1\n+     00010000-03ffffff | unlocked | 1023\n","prefixes":["v4","19/27"]}