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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27F93C47DD9 for ; Wed, 27 Mar 2024 14:27:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To:Subject:Cc:To:From :Date:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=S4BKUCSo/0upYRntVoUZ3xcCX7VxskPA1v9VaUVHsgU=; b=Psd6OSwiY0RzVrIXMgbSsRPNM3 f0He0QSvMrKvofnEhsa6b8l7gYE3GOLB5bsY8aX+YWlS2uXQQaP49tHZhJrpVnR/QEUrOmEDUgyfw xyuMQN087wrjG13kkD0mUlhTXhIoPtliLEr+zdyIjtFzYafo+yOnLHn+ph8g7CdUo9PWogpNX2AVw 8qyxRN3L9KGs1Hy/Ik3fXy2JmArGiK/jXbP0tHD04h6ykZiV2ZKxCN+sqr62zEsv9f6oYi6ZP9H9D DcCzFlVWjFaw1KkipWxbZwS/h94lHq4V+TcoqL9qc7w/7NKpjwMbaMGxAqKexXpHITX/kEMiEzZyP p8GZQB1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpUFK-00000009T05-47TF; Wed, 27 Mar 2024 14:27:18 +0000 Received: from 3.mo561.mail-out.ovh.net ([46.105.44.175]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpUFF-00000009Ssx-3X9A for linux-mtd@lists.infradead.org; Wed, 27 Mar 2024 14:27:15 +0000 Received: from director10.ghost.mail-out.ovh.net (unknown [10.109.176.198]) by mo561.mail-out.ovh.net (Postfix) with ESMTP id 4V4TWh6qHQz1HMx for ; Wed, 27 Mar 2024 14:26:56 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-5j6lf (unknown [10.110.96.237]) by director10.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 9D2931FE92; Wed, 27 Mar 2024 14:26:55 +0000 (UTC) Received: from milecki.pl ([37.59.142.103]) by ghost-submission-6684bf9d7b-5j6lf with ESMTPSA id lEULJa8sBGYx4A0AML5+ww (envelope-from ); Wed, 27 Mar 2024 14:26:55 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-103G0051bcccc50-b51a-4dd6-be14-20d89d3369be, AD8588E3BB83D84E59DEA8CE8674EAB20989D6B2) smtp.auth=rafal@milecki.pl X-OVh-ClientIp: 178.33.236.78 MIME-Version: 1.0 Date: Wed, 27 Mar 2024 15:26:55 +0100 From: =?UTF-8?Q?Rafa=C5=82_Mi=C5=82ecki?= To: Christian Marangi Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Jernej Skrabec , Claudiu Beznea , Greg Kroah-Hartman , Srinivas Kandagatla , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v3] mtd: limit OTP NVMEM Cell parse to non Nand devices In-Reply-To: <20240322040951.16680-1-ansuelsmth@gmail.com> References: <20240322040951.16680-1-ansuelsmth@gmail.com> Message-ID: <44a377b11208ff33045f12f260b667dd@milecki.pl> X-Sender: rafal@milecki.pl X-Originating-IP: 31.11.218.106 X-Webmail-UserID: rafal@milecki.pl X-Ovh-Tracer-Id: 3220073736837835577 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrudduiedggedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepggffhffvvefujghfkfigihgtgfesthejjhdttddtvdenucfhrhhomheptfgrfhgrlhcuofhilhgvtghkihcuoehrrghfrghlsehmihhlvggtkhhirdhplheqnecuggftrfgrthhtvghrnhepkeeftefghfetueetveevvddugfelfeevvedvleeljeetfefggfdtteevuddtleeunecukfhppeduvdejrddtrddtrddupdefuddruddurddvudekrddutdeipddujeekrdeffedrvdefiedrjeekpdefjedrheelrddugedvrddutdefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpehrrghfrghlsehmihhlvggtkhhirdhplhdpnhgspghrtghpthhtohepuddprhgtphhtthhopehlihhnuhigqdhmthgusehlihhsthhsrdhinhhfrhgruggvrggurdhorhhgpdfovfetjfhoshhtpehmohehiedupdhmohguvgepshhmthhpohhuth X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240327_072714_226186_8DA9BA66 X-CRM114-Status: GOOD ( 21.03 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org On 2024-03-22 05:09, Christian Marangi wrote: > MTD OTP logic is very fragile and can be problematic with some specific > kind of devices. > > NVMEM across the years had various iteration on how Cells could be > declared in DT and MTD OTP probably was left behind and > add_legacy_fixed_of_cells was enabled without thinking of the > consequences. Er... thank you? > That option enables NVMEM to scan the provided of_node and treat each > child as a NVMEM Cell, this was to support legacy NVMEM implementation > and don't cause regression. > > This is problematic if we have devices like Nand where the OTP is > triggered by setting a special mode in the flash. In this context real > partitions declared in the Nand node are registered as OTP Cells and > this cause probe fail with -EINVAL error. > > This was never notice due to the fact that till now, no Nand supported > the OTP feature. With commit e87161321a40 ("mtd: rawnand: macronix: OTP > access for MX30LFxG18AC") this changed and coincidentally this Nand is > used on an FritzBox 7530 supported on OpenWrt. So as you noticed this problem was *exposed* by adding OTP support for Macronix NAND chips. > Alternative and more robust way to declare OTP Cells are already > prossible by using the fixed-layout node or by declaring a child node > with the compatible set to "otp-user" or "otp-factory". > > To fix this and limit any regression with other MTD that makes use of > declaring OTP as direct child of the dev node, disable > add_legacy_fixed_of_cells if we detect the MTD type is Nand. > > With the following logic, the OTP NVMEM entry is correctly created with > no Cells and the MTD Nand is correctly probed and partitions are > correctly exposed. > > Fixes: 2cc3b37f5b6d ("nvmem: add explicit config option to read old > syntax fixed OF cells") It's not that commit however that introduced the problem. Introducing "add_legacy_fixed_of_cells" just added a clean way of enabling parsing of old cells syntax. Even before my commit NVMEM subsystem was looking for NVMEM cells in NAND devices. I booted kernel 6.6 which has commit e87161321a40 ("mtd: rawnand: macronix: OTP > access for MX30LFxG18AC") but does NOT have commit 2cc3b37f5b6d ("nvmem: add explicit config option to read old syntax fixed OF cells"). Look at this log from Broadcom Northstar (Linux 6.6): [ 0.410107] nand: device found, Manufacturer ID: 0xc2, Chip ID: 0xdc [ 0.416531] nand: Macronix MX30LF4G18AC [ 0.420409] nand: 512 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64 [ 0.428022] iproc_nand 18028000.nand-controller: detected 512MiB total, 128KiB blocks, 2KiB pages, 16B OOB, 8-bit, BCH-8 [ 0.438991] Scanning device for bad blocks [ 0.873598] Bad eraseblock 738 at 0x000005c40000 [ 1.030279] random: crng init done [ 1.854895] Bad eraseblock 2414 at 0x000012dc0000 [ 2.657354] Bad eraseblock 3783 at 0x00001d8e0000 [ 2.662967] Bad eraseblock 3785 at 0x00001d920000 [ 2.848418] nvmem user-otp1: nvmem: invalid reg on /nand-controller@18028000/nand@0 [ 2.856126] iproc_nand 18028000.nand-controller: error -EINVAL: Failed to register OTP NVMEM device So to summary it up: 1. Problem exists since much earlier and wasn't introduced by 2cc3b37f5b6d 2. Commit 2cc3b37f5b6d just gives you a clean way of solving this issue 3. Problem was exposed by commit e87161321a40 4. We miss fix for v6.6 which doesn't have 2cc3b37f5b6d (it hit v6.7) > Cc: > Signed-off-by: Christian Marangi ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/