From patchwork Wed Aug 14 10:24:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Kshevetskiy X-Patchwork-Id: 1972331 X-Patchwork-Delegate: dario.binacchi@amarulasolutions.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=iopsys.eu header.i=@iopsys.eu header.a=rsa-sha256 header.s=selector2 header.b=BNiu5hXU; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WkPXB2vxqz1yZl for ; Wed, 14 Aug 2024 20:25:14 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0D31088A11; Wed, 14 Aug 2024 12:24:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=iopsys.eu 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=iopsys.eu header.i=@iopsys.eu header.b="BNiu5hXU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3876D88A11; Wed, 14 Aug 2024 12:24:50 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on20702.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1a::702]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3217087C69 for ; Wed, 14 Aug 2024 12:24:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=iopsys.eu Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mikhail.kshevetskiy@genexis.eu ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=L3Z9wD0OlIJcq2KHsLtok+VTjyo+n2q2BiCY5UlhJ+kZW2D1aunHFybMtAZkS+01KljHLjjSAzTBmQSTCWAckmpy/ZLJl50TOvRGaODVlf0IWOejQNle4nYi/Xw6RjepECKABqjXAxjlEe7znw+4Ry1TjO2ends5yyptEN+NgbA1gp2LfaAfTNVwloEwZfduoHDpQhi89WJE4OEIzg93Uq02vk64l0Y+1h8OyHjyi/bCO7KMVD6A8MRd7K8mAaK+fP3bSvOcFOaJ/sBovhjM1dVuTxCwD4dgbGX2qT4WuH0rxbg2CB6PSTBps3A/rLo8O1iyxJAiHDwBSKwRuBzPfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Sq+hEIHrPPr+MS3jI3m5Xyu7rWAqaXE7gqna+fAulh8=; b=brNrrGvXHdA5zrX42YhXd7nOoGvxg4UICj+fN0fBJgcNKD1mNRyklDYM1HWwL4wZLb0yTA4MVA+JtEFhjoT95kuMpplmeskrJLj/0fHvlErzS6hHACcZOkafqrCm2LNL++5p+kr4DxKFI3Q71zdclO/zEo3Hz/gAd31z9ZEmM5BMFka67ZNYme7Exj3APm5Vi5Bng0Kpe+ufG4kwiEdjh/XQb97MSkqQ4ero1SRVEqac1MhLfBlgT4biOoadnvcSjlwn658VxxBWFIS6bXAizU5Ib7TgoPdBHOI1N13GhUkP43zU3dgSxSpDlGiJ2XzclZHZVhPBp5wVaUKsyiyw2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=genexis.eu; dmarc=pass action=none header.from=iopsys.eu; dkim=pass header.d=iopsys.eu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iopsys.eu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Sq+hEIHrPPr+MS3jI3m5Xyu7rWAqaXE7gqna+fAulh8=; b=BNiu5hXUDCiGmz4zep2kd8t/xO6xYq+PsFge9ZdiDSBEJt3LBqQm0O8eVSYCvAT2f759OYOu8K1SGBfFVXQsScnaOTngB0CDd/GDr6Rzxj4YDGmic+3IKNCEvlwND3h6INFQ4ObPNtk7TOE7diWZ1VFAeYBt1eFm9/A7/bFida7gk0/jOy2puyAR6qZbjxWZ+ATKknsGwmy/ygTmeC/HydifNeDb0zdQeMOQ7UReWZ0LBR4hHyt0mdxJj2AWDx5TbgjFOiezkAX+8g7XnULrOwoxUAvyXPyjBJ7UrMXDq1AD/5NJV63c2RJ1i57Eho18yQt3OPWp2iZfP0Zfxn/iAg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=iopsys.eu; Received: from GV2PR08MB8121.eurprd08.prod.outlook.com (2603:10a6:150:7d::22) by AS8PR08MB8491.eurprd08.prod.outlook.com (2603:10a6:20b:566::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.13; Wed, 14 Aug 2024 10:24:46 +0000 Received: from GV2PR08MB8121.eurprd08.prod.outlook.com ([fe80::4cd3:da80:2532:daa0]) by GV2PR08MB8121.eurprd08.prod.outlook.com ([fe80::4cd3:da80:2532:daa0%2]) with mapi id 15.20.7875.012; Wed, 14 Aug 2024 10:24:46 +0000 From: Mikhail Kshevetskiy To: Tom Rini , Simon Glass , Mattijs Korpershoek , AKASHI Takahiro , Heinrich Schuchardt , Michal Simek , Francis Laniel , Anand Moon , Dario Binacchi , Miquel Raynal , Arseniy Krasnov , u-boot@lists.denx.de Cc: Mikhail Kshevetskiy Subject: [RESEND PATCH v2 3/3] cmd: mtd: add nandtest command support Date: Wed, 14 Aug 2024 14:24:28 +0400 Message-Id: <20240814102428.1347425-4-mikhail.kshevetskiy@iopsys.eu> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240814102428.1347425-1-mikhail.kshevetskiy@iopsys.eu> References: <20240814102428.1347425-1-mikhail.kshevetskiy@iopsys.eu> X-ClientProxiedBy: LO4P265CA0307.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:391::15) To GV2PR08MB8121.eurprd08.prod.outlook.com (2603:10a6:150:7d::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV2PR08MB8121:EE_|AS8PR08MB8491:EE_ X-MS-Office365-Filtering-Correlation-Id: 475b0604-b669-4c09-4630-08dcbc4b51e0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|52116014|7416014|366016|1800799024|376014|38350700014|921020; X-Microsoft-Antispam-Message-Info: +/1GnAS9b5CUUA4UkDxHjtJ7vUis3f7Hd0TD+jsz7M/QbYedQXPbKKhtCzFr7yyA/XEID7zIzLISIq3juUtZpYtywBsckCSmJ5s1L9jI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tbOBr+wq16W8VSFsX1RbMRJkBarC9egUUoZrDC9qDipaSIsDL0KKMcd07KBrCvw6Pbfcin0On4+TvHTitwcMOA/ZCoAJlQoAAEjvYKbASTXN9itsjfSXpT9Pkt2mCphyMyFCYbmoFa9XkCZuulxVyzwnYWJ0Kj1QhQN9837ts+p2gt5WxWymxDs+4DuZkXQ1N0nFHd64BHMpXB3/713RfaxrDjKWxcw8+lUqEOHeWPbet1Q/PvjmSmRWXLbNlwK8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:GV2PR08MB8121.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(52116014)(7416014)(366016)(1800799024)(376014)(38350700014)(921020); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kF/k5JVUCvBErK9qA6kDhgxdH+tdXe0krF4KGmUjIM5xQFn+2hEptydc3MVH4ON9JANXC/iWsxDvNHdpmPQlTrRef0pkuio6QLwiHfqbF3E0cn3POekwDavssRJLgvDTonpZIKH3oOSrNc/p4lV1rhfw+ri1XU/00yu3iOyvYirPDUcCZP/uSO3+7zFA2ljENH/TjXnOq0Qn+OaP22qxcwJqSK+ANCiqUxO8744KeEQHCS/cziJo024g0WqWHovof9swre/9EIZxoKPm8gppU2K5MO+M6SHIyxMsETwaDBoUTvIiD3ByltfRL+3dG16jziEWoGQDNvIbrxGel+xDSg35Y00bLSZe+2uyz5epRT21byXlmXq3d5F5ejaHU+BemCBhnPDTX6vNKrsWJE2DeL+K/RtJ4wns9dAR9NI+xxtVKX24aH43SL9y8TfOiRNrn4ZuzABj2ZQhGZyCenFyIaRqtrOcgbomEtue/byMH+VN8lv0BL96jzLjeHGTxW4MH3ydrp2wRvupkDhi1swc1yoJZuHRM4S56cIfTZh5nJmVoXpxALX+VqXu9ITZGkkStOe17paeIiR26htvOhYTXdkbvfb/dcH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4b51e0 X-MS-Exchange-CrossTenant-AuthSource: GV2PR08MB8121.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2024 10:24:46.4271 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8d891be1-7bce-4216-9a99-bee9de02ba58 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iGYfckrSXWY1rxdciSn/Um3Ls7b6J3VgsVYnRNCLy+2ub8Z06pS/3XZDrPljE4cAvuPK64CeoTpQIBcbAOgi17hOY7fvtR3e1q30EuAvsFc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB8491 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.8 at phobos.denx.de X-Virus-Status: Clean This patch implements readonly test of nand flashes. Signed-off-by: Mikhail Kshevetskiy --- cmd/Kconfig | 6 ++ cmd/mtd.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 209 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index 698e0e697f2..db5113e016b 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1445,6 +1445,12 @@ config CMD_MTD_TORTURE help MTD torture command support. +config CMD_MTD_NANDTEST + bool "mtd nandtest" + depends on CMD_MTD + help + MTD nandtest command support. + config CMD_MUX bool "mux" depends on MULTIPLEXER diff --git a/cmd/mtd.c b/cmd/mtd.c index 69ddfe1d9c6..4a380dcaf83 100644 --- a/cmd/mtd.c +++ b/cmd/mtd.c @@ -931,6 +931,202 @@ out_put_mtd: } #endif +#ifdef CONFIG_CMD_MTD_NANDTEST +enum nandtest_status { + NANDTEST_STATUS_UNKNOWN = 0, + NANDTEST_STATUS_NONECC_READ_FAIL, + NANDTEST_STATUS_ECC_READ_FAIL, + NANDTEST_STATUS_BAD_BLOCK, + NANDTEST_STATUS_BITFLIP_ABOVE_MAX, + NANDTEST_STATUS_BITFLIP_MISMATCH, + NANDTEST_STATUS_BITFLIP_MAX, + NANDTEST_STATUS_OK, +}; + +static enum nandtest_status nandtest_block_check(struct mtd_info *mtd, + loff_t off, size_t blocksize) +{ + struct mtd_oob_ops ops = {}; + u_char *buf; + int i, d, ret, len, pos, cnt, max; + + if (blocksize % mtd->writesize != 0) { + printf("\r block at %llx: bad block size\n", off); + return NANDTEST_STATUS_UNKNOWN; + } + + buf = malloc_cache_aligned(2 * blocksize); + if (buf == NULL) { + printf("\r block at %llx: can't allocate memory\n", off); + return NANDTEST_STATUS_UNKNOWN; + } + + ops.mode = MTD_OPS_RAW; + ops.len = blocksize; + ops.datbuf = buf; + ops.ooblen = 0; + ops.oobbuf = NULL; + + if (mtd->_read_oob) + ret = mtd->_read_oob(mtd, off, &ops); + else + ret = mtd->_read(mtd, off, ops.len, &ops.retlen, ops.datbuf); + + if (ret != 0) { + free(buf); + printf("\r block at %llx: non-ecc reading error %d\n", + off, ret); + return NANDTEST_STATUS_NONECC_READ_FAIL; + } + + ops.mode = MTD_OPS_AUTO_OOB; + ops.datbuf = buf + blocksize; + + if (mtd->_read_oob) + ret = mtd->_read_oob(mtd, off, &ops); + else + ret = mtd->_read(mtd, off, ops.len, &ops.retlen, ops.datbuf); + + if (ret == -EBADMSG) { + free(buf); + printf("\r block at %llx: bad block\n", off); + return NANDTEST_STATUS_BAD_BLOCK; + } + + if (ret < 0) { + free(buf); + printf("\r block at %llx: ecc reading error %d\n", off, ret); + return NANDTEST_STATUS_ECC_READ_FAIL; + } + + if (mtd->ecc_strength == 0) { + free(buf); + return NANDTEST_STATUS_OK; + } + + if (ret > mtd->ecc_strength) { + free(buf); + printf("\r block at %llx: returned bit-flips value %d " + "is above maximum value %d\n", + off, ret, mtd->ecc_strength); + return NANDTEST_STATUS_BITFLIP_ABOVE_MAX; + } + + max = 0; + pos = 0; + len = blocksize; + while (len > 0) { + cnt = 0; + for (i = 0; i < mtd->ecc_step_size; i++) { + d = buf[pos + i] ^ buf[blocksize + pos + i]; + if (d == 0) + continue; + + while (d > 0) { + d &= (d - 1); + cnt++; + } + } + if (cnt > max) + max = cnt; + + len -= mtd->ecc_step_size; + pos += mtd->ecc_step_size; + } + + free(buf); + + if (max > ret) { + printf("\r block at %llx: bitflip mismatch, " + "read %d but actual %d\n", off, ret, max); + return NANDTEST_STATUS_BITFLIP_MISMATCH; + } + + if (ret == mtd->ecc_strength) { + printf("\r block at %llx: max bitflip reached, " + "block is unreliable\n", off); + return NANDTEST_STATUS_BITFLIP_MAX; + } + + return NANDTEST_STATUS_OK; +} + +static int do_mtd_nandtest(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct mtd_info *mtd; + loff_t off, len; + int stat[NANDTEST_STATUS_OK + 1]; + enum nandtest_status ret; + size_t block_size; + + if (argc < 2) + return CMD_RET_USAGE; + + mtd = get_mtd_by_name(argv[1]); + if (IS_ERR_OR_NULL(mtd)) + return CMD_RET_FAILURE; + + if (!mtd_can_have_bb(mtd)) { + printf("Only NAND-based devices can be checked\n"); + goto out_put_mtd; + } + + off = 0; + len = mtd->size; + block_size = mtd->erasesize; + + printf("ECC strength: %d\n", mtd->ecc_strength); + printf("ECC step size: %d\n", mtd->ecc_step_size); + printf("Erase block size: 0x%x\n", mtd->erasesize); + printf("Total blocks: %d\n", (u32)len / mtd->erasesize); + + memset(stat, 0, sizeof(stat)); + while (len > 0) { + if (mtd_is_aligned_with_block_size(mtd, off)) + printf("\r block at %llx ", off); + + ret = nandtest_block_check(mtd, off, block_size); + stat[ret]++; + + switch (ret) { + case NANDTEST_STATUS_BAD_BLOCK: + case NANDTEST_STATUS_BITFLIP_MAX: + if (!mtd_block_isbad(mtd, off)) + printf("\r block at %llx: should be marked " + "as BAD\n", off); + break; + + case NANDTEST_STATUS_OK: + if (mtd_block_isbad(mtd, off)) + printf("\r block at %llx: marked as BAD, but " + "probably is GOOD\n", off); + break; + + default: + break; + } + + off += block_size; + len -= block_size; + } + +out_put_mtd: + put_mtd_device(mtd); + printf("\n"); + printf("results:\n"); + printf(" Good blocks: %d\n", stat[NANDTEST_STATUS_OK]); + printf(" Physically bad blocks: %d\n", stat[NANDTEST_STATUS_BAD_BLOCK]); + printf(" Unreliable blocks: %d\n", stat[NANDTEST_STATUS_BITFLIP_MAX]); + printf(" Non checked blocks: %d\n", stat[NANDTEST_STATUS_UNKNOWN]); + printf(" Failed to check blocks: %d\n", stat[NANDTEST_STATUS_NONECC_READ_FAIL] + + stat[NANDTEST_STATUS_ECC_READ_FAIL]); + printf(" Suspictious blocks: %d\n", stat[NANDTEST_STATUS_BITFLIP_ABOVE_MAX] + + stat[NANDTEST_STATUS_BITFLIP_MISMATCH]); + return CMD_RET_SUCCESS; +} +#endif + static int do_mtd_bad(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -1019,6 +1215,9 @@ U_BOOT_LONGHELP(mtd, #endif #ifdef CONFIG_CMD_MTD_TORTURE "mtd torture [ []]\n" +#endif +#ifdef CONFIG_CMD_MTD_NANDTEST + "mtd nandtest \n" #endif "\n" "With:\n" @@ -1060,6 +1259,10 @@ U_BOOT_CMD_WITH_SUBCMDS(mtd, "MTD utils", mtd_help_text, #ifdef CONFIG_CMD_MTD_TORTURE U_BOOT_SUBCMD_MKENT_COMPLETE(torture, 4, 0, do_mtd_torture, mtd_name_complete), +#endif +#ifdef CONFIG_CMD_MTD_NANDTEST + U_BOOT_SUBCMD_MKENT_COMPLETE(nandtest, 2, 0, do_mtd_nandtest, + mtd_name_complete), #endif U_BOOT_SUBCMD_MKENT_COMPLETE(bad, 2, 1, do_mtd_bad, mtd_name_complete));