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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 89755C54EBC for ; Tue, 10 Jan 2023 11:59:47 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AA1A4852EF; Tue, 10 Jan 2023 12:59:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=fris.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=fris.de header.i=@fris.de header.b="ZoC0THAz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 650DE85301; Tue, 10 Jan 2023 12:59:43 +0100 (CET) Received: from mail.fris.de (mail.fris.de [IPv6:2a01:4f8:c2c:390b::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D3390852A1 for ; Tue, 10 Jan 2023 12:59:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=fris.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=frieder@fris.de Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 258EAC0154; Tue, 10 Jan 2023 12:59:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fris.de; s=dkim; t=1673351978; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=j8YD3SH/MtfCefLhOrYN4pwRvo7WaOqEqq8fV6xIR8w=; b=ZoC0THAzoPOrrY5ahD4eOFtzJ8G9wk8e/vdWMRrb1ChFuai0+ZNcILshBE1NnhM/5gifUs /vKIjgolHNBGrcIr+WXDi8dshI/WfHb6yXxgMy7Cp+f3YaihLFIqQNwCyQVdWb8Vub3Zzl piYFGCG123xaR3Pdi5BbMORG6j36p51nsLFFUHH2aZtJAhGI1xK+SXuDbb2sFjtVwi5t++ dU8WG0mF7FXLM9xfZc5QWTeekUiF2qpH+E8TDGH+gd3wBhDT7ReJBChx993/fABvvTLxYt IeyiRBuu/J174pkI9FJq0kTg1fiXLsTp/gc+G3mh+pYNKWaEBAP/SydxuftKfw== From: Frieder Schrempf To: u-boot@lists.denx.de Cc: Mikhail Kshevetskiy , Frieder Schrempf , Simon Glass , Stefan Roese Subject: [PATCH 2/5] mtd/spinand: sync core spinand code with linux-5.10.118 Date: Tue, 10 Jan 2023 12:58:39 +0100 Message-Id: <20230110115843.391630-2-frieder@fris.de> In-Reply-To: <20230110115843.391630-1-frieder@fris.de> References: <20230110115843.391630-1-frieder@fris.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Mikhail Kshevetskiy This brings us closer to the current Linux kernel implementation of the spinand core and makes backporting features and fixes easier. This does not include the latest kernel implementation as this would require a substantial amount of extra work due to the missing ECC engine abstraction layer in U-Boot. Signed-off-by: Mikhail Kshevetskiy Signed-off-by: Frieder Schrempf (add commit message) --- drivers/mtd/nand/spi/core.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index d92de9c24e3..886e66e7847 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -326,6 +326,13 @@ static int spinand_write_to_cache_op(struct spinand_device *spinand, u16 column = 0; int ret; + /* + * Looks like PROGRAM LOAD (AKA write cache) does not necessarily reset + * the cache content to 0xFF (depends on vendor implementation), so we + * must fill the page cache entirely even if we only want to program + * the data portion of the page, otherwise we might corrupt the BBM or + * user data previously programmed in OOB area. + */ memset(spinand->databuf, 0xff, nanddev_page_size(nand) + nanddev_per_page_oobsize(nand)); @@ -598,12 +605,12 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from, if (ret == -EBADMSG) { ecc_failed = true; mtd->ecc_stats.failed++; - ret = 0; } else { mtd->ecc_stats.corrected += ret; max_bitflips = max_t(unsigned int, max_bitflips, ret); } + ret = 0; ops->retlen += iter.req.datalen; ops->oobretlen += iter.req.ooblen; } @@ -669,16 +676,9 @@ static bool spinand_isbad(struct nand_device *nand, const struct nand_pos *pos) .oobbuf.in = marker, .mode = MTD_OPS_RAW, }; - int ret; - - ret = spinand_select_target(spinand, pos->target); - if (ret) - return ret; - - ret = spinand_read_page(spinand, &req, false); - if (ret) - return ret; + spinand_select_target(spinand, pos->target); + spinand_read_page(spinand, &req, false); if (marker[0] != 0xff || marker[1] != 0xff) return true; @@ -722,6 +722,10 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos) if (ret) return ret; + ret = spinand_write_enable_op(spinand); + if (ret) + return ret; + return spinand_write_page(spinand, &req); } -- 2.39.0