Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2537548ybk; Tue, 12 May 2020 01:46:41 -0700 (PDT) X-Google-Smtp-Source: APiQypLHK6M9dn4fCn7wBrb9Xxi1IuVQfoLWVqjsF0gttoUeW3XSh11K1CAp7N5gHf95pfqHaqx0 X-Received: by 2002:a17:906:391:: with SMTP id b17mr16380167eja.91.1589273201229; Tue, 12 May 2020 01:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589273201; cv=none; d=google.com; s=arc-20160816; b=nEXPIDDOi7ooeUKSbakR0k/pxj9aN3EEVbacvFn64A8/NpuGc4Aoe4Xd7VilyypZYF cS7wKf9ManWxczIDMnVErZkMkgBnD03HhZjVEVEwrv46GC3bxTAIgmScjudDxaqFUB/z 5LT7RtTmT5Z4vdyXi+GTikIs7iXhlgAzgWeQ/+6w/DxBs5SPOGcyQlynP3/soanVkUA5 Qeyvu7ehiHsDZlX7sXQC9A+ksS64LWZDY/VetsEuSg++KvMSQ4I/Q1vjfl2HZYJLO1tZ 5T1G6j+QOwVG604e1lBlgzYn3v6tu2T7dmpeQH8r/mmbdZX8fb+PCZhhS3coXacGH2lq Dcng== 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=rJFwL6/VQWTzcgK9QJJSygM9cZUgoQH/96SrfROAicg=; b=zpg9j5itpxg2K7LEWVuIQchGiB9xMjnBV9lfdiaWNF8QzwCzhf1/QlmO0sWQ+wirAW MpfUOb2RBhxQpn7KHviHUQlwNK9jq4+UI17W8WcpC5z2lySSEnu1uI52XAM0fzty7iCF MvIABQozqHJWX3+eQ7x2nTXoOv9uaD+Bm3TmFnObBTpsVo3XBW+qFp02KWpNhX41eFdg eXGroOY3TF22Q4R+hw6BsBfTVQFwPSbhvdLTdZDUiZHh/rFtDRmJsjXNAgUQVDUpakf3 /ZBv8Go6WeLM730LMgAr76doL5ilbgXfuSr11fRmD5IBFFI2wcuX78BTEhD14O7Q0eDG dIng== ARC-Authentication-Results: i=1; mx.google.com; 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 p59si837335edb.291.2020.05.12.01.46.17; Tue, 12 May 2020 01:46:41 -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; 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 S1728525AbgELIoc convert rfc822-to-8bit (ORCPT + 99 others); Tue, 12 May 2020 04:44:32 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:33491 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725868AbgELIob (ORCPT ); Tue, 12 May 2020 04:44:31 -0400 Received: from xps13 (unknown [91.224.148.103]) (Authenticated sender: miquel.raynal@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 6C06A240007; Tue, 12 May 2020 08:44:23 +0000 (UTC) Date: Tue, 12 May 2020 10:44:22 +0200 From: Miquel Raynal To: =?UTF-8?B?w4FsdmFybyBGZXJuw6FuZGV6?= Rojas Cc: Boris Brezillon , richard@nod.at, vigneshr@ti.com, s.hauer@pengutronix.de, masonccyang@mxic.com.tw, christophe.kerello@st.com, stefan@agner.ch, piotrs@cadence.com, devik@eaxlabs.cz, tglx@linutronix.de, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] nand: raw: use write_oob_raw for MTD_OPS_AUTO_OOB mode Message-ID: <20200512104422.4c31f7e0@xps13> In-Reply-To: <6F41AA9B-71D6-47FA-BC12-24941F84DA71@gmail.com> References: <20200504094253.2741109-1-noltari@gmail.com> <20200504123237.5c128668@collabora.com> <20200511182923.6a4961ab@xps13> <6F41AA9B-71D6-47FA-BC12-24941F84DA71@gmail.com> 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 Hello, Richard, maybe you'll have an idea to fix the situation here? Álvaro Fernández Rojas wrote on Tue, 12 May 2020 10:36:25 +0200: > Hi, > > > El 11 may 2020, a las 18:29, Miquel Raynal escribió: > > > > Hello, > > > > Boris Brezillon wrote on Mon, 4 May > > 2020 12:32:37 +0200: > > > >> On Mon, 4 May 2020 11:42:53 +0200 > >> Álvaro Fernández Rojas wrote: > >> > >>> Some NAND controllers change the ECC bytes when OOB is written with ECC > >>> enabled. > >>> This is a problem in brcmnand, since adding JFFS2 cleanmarkers after the page > >>> has been erased will change the ECC bytes to 0 and the controller will think > >>> the block is bad. > >>> It can be fixed by using write_oob_raw, which ensures ECC is disabled. > >>> > >>> Signed-off-by: Álvaro Fernández Rojas > >>> --- > >>> drivers/mtd/nand/raw/nand_base.c | 2 +- > >>> 1 file changed, 1 insertion(+), 1 deletion(-) > >>> > >>> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c > >>> index c24e5e2ba130..755d25200520 100644 > >>> --- a/drivers/mtd/nand/raw/nand_base.c > >>> +++ b/drivers/mtd/nand/raw/nand_base.c > >>> @@ -488,7 +488,7 @@ static int nand_do_write_oob(struct nand_chip *chip, loff_t to, > >>> > >>> nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops); > >>> > >>> - if (ops->mode == MTD_OPS_RAW) > >>> + if (ops->mode == MTD_OPS_AUTO_OOB || ops->mode == MTD_OPS_RAW) > >>> status = chip->ecc.write_oob_raw(chip, page & chip->pagemask); > >> > >> The doc says: > >> > >> @MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default) > >> @MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas > >> which are defined by the internal ecclayout > >> @MTD_OPS_RAW: data are transferred as-is, with no error > >> correction; this mode implies %MTD_OPS_PLACE_OOB > >> > >> To me, that means MTD_OPS_PLACE_OOB and MTD_OPS_AUTO_OOB do not imply > >> MTD_OPS_RAW. Anyway those modes are just too vague. We really should > >> separate the ECC-disabled/ECC-enabled concept (AKA raw vs non-raw mode) > >> from the OOB placement scheme. IIRC, Miquel had a patchset doing that. > >> > >> We also should have the concept of protected OOB-region vs > >> unprotected-OOB-region if we want JFFS2 to work with controllers that > >> protect part of the OOB region. Once we have that we can patch JFFS2 > >> to write things with "ECC-disabled"+"auto-OOB-placement-on-unprotected > >> area". > > > > I see the problem but as Boris said the fix is not valid as-is. > > Problem is: I don't have a better proposal yet. > > > > Is forcing JFFS2 to write cleanmarkers in raw mode only an option? > > The doc says that for MTD_OPS_AUTO_OOB "the data is automatically placed at the free areas which are defined by the internal ecclayout”. > So, if we’re placing this data in the free OOB area left by the ECC bytes it means that this automatically placed data won’t be error correctable, since it’s in the OOB, and the OOB data isn’t error corrected, right? No, free bytes sometimes are and sometimes are not covered by the ECC engine. It depends on the controller. > The problem is that "flash_erase -j” uses MTD_OPS_AUTO_OOB to write the OOB JFFS2 clean markers and if this is written with ECC enabled the NAND controller will change the ECC bytes to an invalid value (or at least brcmnand controller). > > Another option could be adding another mode, something like MTD_OPS_AUTO_OOB_RAW and using it in mtd-utils and JFFS2. No, these modes already are completely wrong, I must resend my series fixing them.