From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D748CC00454 for ; Sat, 14 Dec 2019 19:20:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC1002467A for ; Sat, 14 Dec 2019 19:20:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=walle.cc header.i=@walle.cc header.b="D8XNfnrQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726931AbfLNTUi (ORCPT ); Sat, 14 Dec 2019 14:20:38 -0500 Received: from ssl.serverraum.org ([176.9.125.105]:59171 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726783AbfLNTUh (ORCPT ); Sat, 14 Dec 2019 14:20:37 -0500 Received: from apollo.fritz.box (unknown [IPv6:2a02:810c:c200:2e91:6257:18ff:fec4:ca34]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 6787C23D22; Sat, 14 Dec 2019 20:20:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1576351234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gjxbYEaca/vTHscXtSMHgXjg4LOanuSO0Q2tZkdqZ94=; b=D8XNfnrQ0Rvc7fo0XUilIeXZDPX4+zGsPHQRj8NGTrYC5GT6Pd2ERbPRA943sdNFxp9wZy /4OJWhne1cOtfLCaT7B053rSLwF0h1fyyg9A9L7cxJALgYWjsZovTiTdBcxtxkAf08YNxu NLqh24+qhYvfQLufa3nQpZ8DVXZ45v4= From: Michael Walle To: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Mark Rutland , Tudor Ambarus , Michael Walle Subject: [PATCH 2/2] mtd: spi-nor: add option to keep lock bits Date: Sat, 14 Dec 2019 20:19:43 +0100 Message-Id: <20191214191943.3679-2-michael@walle.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191214191943.3679-1-michael@walle.cc> References: <20191214191943.3679-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: ++++++ X-Rspamd-Server: web X-Rspamd-Queue-Id: 6787C23D22 X-Spamd-Result: default: False [6.40 / 15.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[dt]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; DKIM_SIGNED(0.00)[]; RCPT_COUNT_SEVEN(0.00)[10]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM(-0.00)[-0.709]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:31334, ipnet:2a02:810c::/31, country:DE]; SUSPICIOUS_RECIPS(1.50)[] X-Spam: Yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Traditionally, linux unlocks the whole flash because there are legacy devices which has the write protections bits set by default at startup. If you actually want to use the flash protection bits, eg. because there is a read-only part for a bootloader, this automatic unlocking is harmful. If there is no hardware write protection in place (usually called WP#), a startup of the kernel just discards this protection. Introduce a new device tree flag to indicate that the flash should not be automatically unlocked. Signed-off-by: Michael Walle --- drivers/mtd/spi-nor/spi-nor.c | 5 ++++- include/linux/mtd/spi-nor.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index f4afe123e9dc..d0bec0adf2f8 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -4910,7 +4910,7 @@ static int spi_nor_quad_enable(struct spi_nor *nor) */ static int spi_nor_unlock_all(struct spi_nor *nor) { - if (nor->flags & SNOR_F_HAS_LOCK) + if (nor->flags & SNOR_F_HAS_LOCK && !(nor->flags & SNOR_F_NO_UNLOCK)) return spi_nor_unlock(&nor->mtd, 0, nor->params.size); return 0; @@ -5159,6 +5159,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, if (of_property_read_bool(np, "broken-flash-reset")) nor->flags |= SNOR_F_BROKEN_RESET; + if (of_property_read_bool(np, "no-unlock")) + nor->flags |= SNOR_F_NO_UNLOCK; + /* * Configure the SPI memory: * - select op codes for (Fast) Read, Page Program and Sector Erase. diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 5a4623fc586b..4cba5dda2d38 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -244,6 +244,7 @@ enum spi_nor_option_flags { SNOR_F_HAS_LOCK = BIT(8), SNOR_F_HAS_16BIT_SR = BIT(9), SNOR_F_NO_READ_CR = BIT(10), + SNOR_F_NO_UNLOCK = BIT(11), }; -- 2.20.1