Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp377590ybl; Wed, 29 Jan 2020 02:09:38 -0800 (PST) X-Google-Smtp-Source: APXvYqyYRxXbLSLcQ/qow4ONjr7nEDC+3tvQDFKaQR0JwwjNN2YcXiXMeQ8B3OeiqYjMHpuqLRUY X-Received: by 2002:aca:8d5:: with SMTP id 204mr5729162oii.141.1580292578296; Wed, 29 Jan 2020 02:09:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580292578; cv=none; d=google.com; s=arc-20160816; b=qmnDltQXQdHzCNO5wObtmt3GWcDs60KhqBDDLcI8po9FtEhLhFMf0o13C22zGJ//59 9At9+Yyn5nv6nr8RpOTNGn8aLy91d+FHjjJUx+ry4HVSMpHK3V14gR9Pc3r46iCAWuoe I3SRn81tNPSZF7CgHPE9k7HT07yrFIB4/aZlVESgSdBgOXHlbfOe+TKusCt+N4fjg2U2 zL/tmNcGaqWDQpC+axjzBgLTXMYBdHcxU3AKa70/eMBdfvlW0Bfvx3cUk/foPZZ0ZFsK 8P8/bgOd8+62cOu6uIowr2b9pXr/ENrGsCFUObyX+1l3aYaJWDL7gFGZtwiGqoMDZwik wBpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature:dkim-filter; bh=asGT5gvhVUjsXPA0Xqj1pjk/7V5+RsenU1Ws7cXf5Rs=; b=SMn4W+1mRRIDkTeWe98Qz4TS1DpFa4DG9JFURM3PFDmMX0MGxVzaVNex9ccTVBUCIm qYXoMe4x4wfJZcpEcjl9xgrmOYuvk2snSvbyUCza+Bs8l7FJyvJ+HZrIJTDsduLEBBmj OeCHiWCZ+bd0OorszycfwHwVs2pUTa5M4jd7HrPGdu5j1mw2pBdJc4bXB/REsa61o696 Yw0J/3sGLi0UkjaIxY4vlwD0PAXH8Cgjfh/xxO2ypf+qUEvZi+1dX6wcguVPJEMGEBqa 2Jof1tvvnRwyy8HOxB8+S2YyWySzz50rzFdXZvvYaRCZxoD8opkYiEEko/zYv2j2Ycss i+BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=gRKcq4Mt; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9si867574oib.59.2020.01.29.02.09.25; Wed, 29 Jan 2020 02:09:38 -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; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=gRKcq4Mt; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726157AbgA2KH3 (ORCPT + 99 others); Wed, 29 Jan 2020 05:07:29 -0500 Received: from conssluserg-03.nifty.com ([210.131.2.82]:41920 "EHLO conssluserg-03.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbgA2KH3 (ORCPT ); Wed, 29 Jan 2020 05:07:29 -0500 Received: from mail-vs1-f53.google.com (mail-vs1-f53.google.com [209.85.217.53]) (authenticated) by conssluserg-03.nifty.com with ESMTP id 00TA7NT0026716 for ; Wed, 29 Jan 2020 19:07:24 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-03.nifty.com 00TA7NT0026716 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1580292444; bh=asGT5gvhVUjsXPA0Xqj1pjk/7V5+RsenU1Ws7cXf5Rs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=gRKcq4MtPpT7WifrCx+vbmE/wwvbO3bkB/HuRG9AdoEobkc5LiG8ZOcXaWDfJ3OAT nXHJ8RKEO/u3vQsFzWumVZDM2U2/Ma5iOcqm1JAl161HXMuq3v+g8bhfiWQ7dLftBs QvTM2Yb9YVNlrlaaOuTR9lc4qRuKLE0Puj3af1a2Am69lN9sDkPv2MVw5py6woQLp6 k6qqcrIRqU9vzmrZ2/v0WNvTtTlnTbwUWzf5cxyGz69fuZr9oehILgd5gmU8uI+/NO CNbHdh9jinyUvyyCjWLFvbBSQ79jXcEv+S48yr+dupaODY4ZllVhlNnziPLGI7Q5Wg 38V9uK/v0KF4g== X-Nifty-SrcIP: [209.85.217.53] Received: by mail-vs1-f53.google.com with SMTP id b79so10028663vsd.9 for ; Wed, 29 Jan 2020 02:07:23 -0800 (PST) X-Gm-Message-State: APjAAAUkFrZYq8KLxrVDxcRYNr0lcuVhywTb1pb7huAPQKYpa+SWN/oA 90BGkybW4ONxYqDa7R+WgJOCPgWcu28E+Y9DtPA= X-Received: by 2002:a05:6102:48b:: with SMTP id n11mr16641316vsa.181.1580292442635; Wed, 29 Jan 2020 02:07:22 -0800 (PST) MIME-Version: 1.0 References: <20200127153559.60a83e76@xps13> <20200127164554.34a21177@collabora.com> <20200127164755.29183962@xps13> <20200128075833.129902f6@collabora.com> In-Reply-To: <20200128075833.129902f6@collabora.com> From: Masahiro Yamada Date: Wed, 29 Jan 2020 19:06:46 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: How to handle write-protect pin of NAND device ? To: Boris Brezillon Cc: Miquel Raynal , linux-mtd , Linux Kernel Mailing List , Boris Brezillon Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 28, 2020 at 3:58 PM Boris Brezillon wrote: > > On Mon, 27 Jan 2020 16:47:55 +0100 > Miquel Raynal wrote: > > > Hi Hello, > > > > Boris Brezillon wrote on Mon, 27 Jan > > 2020 16:45:54 +0100: > > > > > On Mon, 27 Jan 2020 15:35:59 +0100 > > > Miquel Raynal wrote: > > > > > > > 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? > > > > > > FWIW, I've always considered the WP pin as a way to protect against > > > spurious destructive command emission, which is most likely to happen > > > during transition phases (bootloader -> linux, linux -> kexeced-linux, > > > platform reset, ..., or any other transition where the pin state might > > > be undefined at some point). This being said, if you're worried about > > > other sources of spurious cmds (say your bus is shared between > > > different kind of memory devices, and the CS pin is unreliable), you > > > might want to leave the NAND in a write-protected state de-asserting WP > > > only when explicitly issuing a destructive command (program page, erase > > > block). > > > > Ok so with this in mind, only the brcmnand driver does a useful use of > > the WP output. > > Well, I'd just say that brcmnand is more paranoid, which is a good > thing I guess, but that doesn't make other solutions useless, just less > safe. We could probably flag operations as 'destructive' at the > nand_operation level, so drivers can assert/de-assert the pin on a > per-operation basis. Sounds a good idea. If it is supported in the NAND framework, I will be happy to implement in the Denali NAND driver. Thank you. -- Best Regards Masahiro Yamada