Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp47736pxk; Wed, 30 Sep 2020 17:28:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOMnHgURHPuMX8JMounK06XnPr7k+Z58THADZFK763jwW/kYhb9FQUwyGspdQrsXThA5Ga X-Received: by 2002:a17:906:c55:: with SMTP id t21mr5674696ejf.276.1601512094879; Wed, 30 Sep 2020 17:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601512094; cv=none; d=google.com; s=arc-20160816; b=P50aSjneaw/2/OVu3fIHLktgeBN4Zi0xYod80R7EUg5LAXBtA8IVdSutrM/rY12jsw sgz+6eBDnDxZPu3AR6S8klPkEd9/nrRgUSntJ0wQ3Unn/sn+Xar8jsH+5ajJz6k+6Dnz e/XFMknRNeB3l7ppV6cKa+G8jVFnupiaep86NS2tLAjjT+3fSYVTGfeL6e9kgP2Rc7SL vMdEpAfk6Op/9KC2pFLxHJE2I4xGAMzpTTP/jsx+QLMP5IF/E/pSg2oB54/3iipnicSp FHh+xlAex1BsmEf6FBIqfpGarJJ7B+NUixVHI/4+uJF0UJboVPtkft1gC6Xhv/4HL0x4 GLow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:user-agent:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :dkim-signature; bh=0yBPgimlAnB9qjnYhtR1UnHNO8xcwVbFDrDVCIQ51JU=; b=lMmK8DpnAJCRkqo5AyCbyu+dKqzZArXOGNuwT8OBsjgSrKNQIrJfIzSwoH46acjCfl vrgn5NuHFhbY9bHhFEq56A0z6k63rHSWWCg6WLXmB48T0v6KZdj4hH8UuejfNYe1VYGw cHQA6cNlwC4VUs1soI3PRuAR483OgkFulWV56YifsxcDLlD1oBMOlRAD9tbmu2HK5tH2 mA9cq/tvzGhmTqMyZ/HPRyz2oAjESQBpNjv/m1GRhAOTARRrLGtyMCH3S1yN4eSQVPjH RyT3AlHUJVtRIeWziKN+58HoBybgwHnMWS3D4N5GBf+inhq1exZGRvnSqZS76y5nIpE1 oF5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=MAY7Kkf6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o17si2328363ejg.470.2020.09.30.17.27.52; Wed, 30 Sep 2020 17:28:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=MAY7Kkf6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731893AbgI3Wvm (ORCPT + 99 others); Wed, 30 Sep 2020 18:51:42 -0400 Received: from ssl.serverraum.org ([176.9.125.105]:51025 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731808AbgI3Wvm (ORCPT ); Wed, 30 Sep 2020 18:51:42 -0400 Received: from ssl.serverraum.org (web.serverraum.org [172.16.0.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 1E4A022EDE; Thu, 1 Oct 2020 00:51:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1601506300; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0yBPgimlAnB9qjnYhtR1UnHNO8xcwVbFDrDVCIQ51JU=; b=MAY7Kkf68Sql2fBLQ6/Lvko6HSUWAvwe/B5CgSYoWPkGYLvwVAHJBDBMJXxqRohGAP47l+ lPmpi1vWpo9AKiRyDghQImyvmtnm8uepVcNJBnIO0Q7U/QjCKM5/t7u82KxSlm5loB0ywn igk0rUL33G1BHdeicVH8DvZsL6ilroc= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 01 Oct 2020 00:51:39 +0200 From: Michael Walle To: Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Miquel Raynal , Richard Weinberger , Tudor Ambarus , Boris Brezillon Subject: Re: [PATCH v3] mtd: spi-nor: keep lock bits if they are non-volatile In-Reply-To: <523c3645-e37d-5d86-ba91-5c1be9e3881e@ti.com> References: <20200327155939.13153-1-michael@walle.cc> <523c3645-e37d-5d86-ba91-5c1be9e3881e@ti.com> User-Agent: Roundcube Webmail/1.4.8 Message-ID: X-Sender: michael@walle.cc Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 2020-09-30 12:35, schrieb Vignesh Raghavendra: [..] >> Signed-off-by: Michael Walle >> --- >> changes since v2: >> - add Kconfig option to be able to retain legacy behaviour >> - rebased the patch due to the spi-nor rewrite >> - dropped the Fixes: tag, it doens't make sense after the spi-nor >> rewrite >> - mention commit 3e0930f109e76 which further modified the unlock >> behaviour. >> >> changes since v1: >> - completely rewrote patch, the first version used a device tree flag >> >> drivers/mtd/spi-nor/Kconfig | 35 +++++++++++++++++++++++++++++ >> drivers/mtd/spi-nor/atmel.c | 24 +++++++++++++------- >> drivers/mtd/spi-nor/core.c | 44 >> ++++++++++++++++++++++++++++--------- >> drivers/mtd/spi-nor/core.h | 6 +++++ >> drivers/mtd/spi-nor/esmt.c | 6 ++--- >> drivers/mtd/spi-nor/intel.c | 6 ++--- >> drivers/mtd/spi-nor/sst.c | 21 +++++++++--------- >> include/linux/mtd/spi-nor.h | 6 +++++ >> 8 files changed, 114 insertions(+), 34 deletions(-) >> >> diff --git a/drivers/mtd/spi-nor/Kconfig b/drivers/mtd/spi-nor/Kconfig >> index 6e816eafb312..647de17c81e2 100644 >> --- a/drivers/mtd/spi-nor/Kconfig >> +++ b/drivers/mtd/spi-nor/Kconfig >> @@ -24,6 +24,41 @@ config MTD_SPI_NOR_USE_4K_SECTORS >> Please note that some tools/drivers/filesystems may not work with >> 4096 B erase size (e.g. UBIFS requires 15 KiB as a minimum). >> >> +choice >> + prompt "Write protection at boot" >> + default MTD_SPI_NOR_WP_DISABLE > > These choice control how BP0-X bits are manipulated on boot. Hence, to > be consistent should use Block Protection (BP) terminology throughout. > > This would also be inline with most flash datasheets which also use > term BP Where should I mention the BP bits? In the choice or in the help text. I tried to keep the choice prompt as easy to understand as possible, so an user who doesn't know anything about how the write protection actually works can still make that choice (without first reading a datasheet). Also keep in mind, that there is also the per sector locking. Wouldn't this option also apply to that? Therefore, I'd mention in the help text, that (currently) the BP bits are affected. >> + >> +config MTD_SPI_NOR_WP_DISABLE >> + bool "Disable WP on any flashes (legacy behaviour)" >> + help >> + This option disables the write protection on any SPI flashes at >> + boot-up. >> + >> + Don't use this if you intent to use the write protection of your >> + SPI flash. This is only to keep backwards compatibility. >> + >> +config MTD_SPI_NOR_WP_DISABLE_ON_VOLATILE >> + bool "Disable WP on flashes w/ volatile protection bits" >> + help >> + Some SPI flashes have volatile block protection bits, ie. after a >> + power-up or a reset the flash is write protected by default. >> + >> + This option disables the write protection for these kind of >> flashes >> + while keeping it enabled for any other SPI flashes which have >> + non-volatile block protection bits. >> + >> + If you are unsure, select this option. >> + >> +config MTD_SPI_NOR_WP_KEEP >> + bool "Keep write protection as is" >> + help >> + If you select this option the write protection of any SPI flashes >> + will not be changed. If your flash is write protected or will be >> + automatically write protected after power-up you have to manually >> + unlock it before you are able to write to it. >> + >> +endchoice >> + >> source "drivers/mtd/spi-nor/controllers/Kconfig" >> >> endif # MTD_SPI_NOR > > [...] > >> diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h >> index 6f2f6b27173f..9a33c023717f 100644 >> --- a/drivers/mtd/spi-nor/core.h >> +++ b/drivers/mtd/spi-nor/core.h >> @@ -26,6 +26,7 @@ enum spi_nor_option_flags { >> SNOR_F_HAS_SR_TB_BIT6 = BIT(11), >> SNOR_F_HAS_4BIT_BP = BIT(12), >> SNOR_F_HAS_SR_BP3_BIT6 = BIT(13), >> + SNOR_F_NEED_UNPROTECT = BIT(14), >> }; >> >> struct spi_nor_read_command { >> @@ -311,6 +312,11 @@ struct flash_info { >> * BP3 is bit 6 of status register. >> * Must be used with SPI_NOR_4BIT_BP. >> */ >> +#define SPI_NOR_UNPROTECT BIT(19) /* >> + * Flash is write-protected after >> + * power-up and needs a global >> + * unprotect. >> + */ >> > > It would be better to name the flag to indicate BP bits are volatile or > powers up locked instead of SPI_NOR_UNPROTECT. This makes it easier to > understand what this flag means wrt flash HW feature. Maybe: > > SPI_NOR_LOCKED_ON_POWER_UP or SPI_NOR_BP_IS_VOLATILE SPI_NOR_BP_IS_VOLATILE sounds good to me. -michael