Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3579973ybl; Mon, 27 Jan 2020 06:38:13 -0800 (PST) X-Google-Smtp-Source: APXvYqz6O5VTNIxN4b+hYRB5Y12tVukTzyElwF3SQWxtR1HNYuLzRB5AD+ROl54jN9d+fxTPxvDM X-Received: by 2002:a9d:65cf:: with SMTP id z15mr13205562oth.238.1580135893798; Mon, 27 Jan 2020 06:38:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580135893; cv=none; d=google.com; s=arc-20160816; b=vujfdqVyU8u/DFyejZjmVTXBTy1SAYx1ZiiEP73w5b8pswV3V24Gpobyu0yzVpxXDF wEpS7CuTiJZ5Ucw/KdYU5xG1T9YXos05+uAAojxeJi51OaUdoe2re/lcXPTOYV8qfxuh KbdES3OXfsfoPcW/0sni8PD8mCeH2ESRN0ON5ER3CctYkaTZQSAnqya9imUAFCtwkfYU zfKcBw1f85XhQm+GLaSiv+ZtWkNsUjb0f7gURJ5+vEqLjO3U73I++oxtAmvoxkdgCxHD upJPAfjXQB2Fv4ZCF26u46LERPLNrbPqVEYadyF5/A4Guo2Ig53m979uANcjUZaZ/9dj ChDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=95w+Kxhpp4PB6AxFXnWa2BCwBv2uc+oKI1PmZvudOHk=; b=qTdFuRG9jlHHj2iCSox5LyMArktJ3CykjWBshXNJZFfVTlEQJ16CBUZ+p08CziXRkh 8Ibxejsa2f+6b1uxRQGA0ZwU9ZIo/I/N/S+SriF2HoUp8pGCAp2IKiIrypnuxNJCPYZs n6/ARVgdk8u0WrxngOaPB4hAv6m9JJ9574SyEeEvjxesYYzr4u4EFeB53v4cd+I91ztL QKHiqI26EGmZ20TtVm+/D2NuxKKSUJk/o0c42ekKwauoxIZuO4b1gEMyaEY/f9g4ihow CmvzzMN8T/DE6K/vajJxZDOMLfe/K0e7NIrbR4Zn0GCo33uizDeVKEh4DLKkqhWZS+cz IpIA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e64si3705823oib.4.2020.01.27.06.38.02; Mon, 27 Jan 2020 06:38:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728931AbgA0OgC convert rfc822-to-8bit (ORCPT + 99 others); Mon, 27 Jan 2020 09:36:02 -0500 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:55089 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725828AbgA0OgC (ORCPT ); Mon, 27 Jan 2020 09:36:02 -0500 X-Originating-IP: 90.76.211.102 Received: from xps13 (lfbn-tou-1-1151-102.w90-76.abo.wanadoo.fr [90.76.211.102]) (Authenticated sender: miquel.raynal@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 588AC1BF204; Mon, 27 Jan 2020 14:36:00 +0000 (UTC) Date: Mon, 27 Jan 2020 15:35:59 +0100 From: Miquel Raynal To: Masahiro Yamada Cc: linux-mtd , Boris Brezillon , Linux Kernel Mailing List Subject: Re: How to handle write-protect pin of NAND device ? Message-ID: <20200127153559.60a83e76@xps13> In-Reply-To: References: Organization: Bootlin X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Masahiro, Masahiro Yamada wrote on Mon, 27 Jan 2020 21:55:25 +0900: > Hi. > > I have a question about the > WP_n pin of a NAND chip. > > > As far as I see, the NAND framework does not > handle it. There is a nand_check_wp() which reads the status of the pin before erasing/writing. > > Instead, it is handled in a driver level. > I see some DT-bindings that handle the WP_n pin. > > $ git grep wp -- Documentation/devicetree/bindings/mtd/ > Documentation/devicetree/bindings/mtd/brcm,brcmnand.txt:- > brcm,nand-has-wp : Some versions of this IP include a > write-protect Just checked: brcmnand de-assert WP when writing/erasing and asserts it otherwise. IMHO this switching is useless. > Documentation/devicetree/bindings/mtd/ingenic,jz4780-nand.txt:- > wp-gpios: GPIO specifier for the write protect pin. > Documentation/devicetree/bindings/mtd/ingenic,jz4780-nand.txt: > wp-gpios = <&gpf 22 GPIO_ACTIVE_LOW>; > Documentation/devicetree/bindings/mtd/nvidia-tegra20-nand.txt:- > wp-gpios: GPIO specifier for the write protect pin. > Documentation/devicetree/bindings/mtd/nvidia-tegra20-nand.txt: > wp-gpios = <&gpio TEGRA_GPIO(S, 0) GPIO_ACTIVE_LOW>; In both cases, the WP GPIO is unused in the code, just de-asserted at boot time like what you do in the patch below. > > > > I wrote a patch to avoid read-only issue in some cases: > http://patchwork.ozlabs.org/patch/1229749/ > > Generally speaking, we expect NAND devices > are writable in Linux. So, I think my patch is OK. I think the patch is fine. > > > However, I asked this myself: > Is there a useful case to assert the write protect > pin in order to make the NAND chip really read-only? > For example, the system recovery image is stored in > a read-only device, and the write-protect pin is > kept asserted to assure nobody accidentally corrupts it. It is very likely that the same device is used for RO and RW storage so in most cases this is not possible. We already have squashfs which is actually read-only at filesystem level, I'm not sure it is needed to enforce this at a lower level... Anyway if there is actually a pin for that, one might want to handle the pin directly as a GPIO, what do you think? > But, I am not sure if it should be handled in the > framework level with a more generic DT-binding. > > > Comments are appreciated. > > -- > Best Regards > Masahiro Yamada Thanks, Miquèl