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 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 8AAD0C433EF for ; Fri, 22 Apr 2022 22:11:20 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BF5AC83C24; Sat, 23 Apr 2022 00:11:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="Q31+2pU8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8D5B883D66; Sat, 23 Apr 2022 00:11:15 +0200 (CEST) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 328DD802EF for ; Sat, 23 Apr 2022 00:11:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=michael@amarulasolutions.com Received: by mail-wm1-x332.google.com with SMTP id o20-20020a05600c511400b0038ebbbb2ad8so6122041wms.0 for ; Fri, 22 Apr 2022 15:11:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kLG7NQBEtFdnYjP/TDuiM8VBKou8xCHguk1XH6PdSp8=; b=Q31+2pU8vX/yI2aJD99emoVgU7/KFB9IoTcWYoubWTDhj43uGsYBm/hzD843m/W6ym LVxBYiIX1wYo7bm9ijUpi2iwxyPklzcXBjIS4cz/ajoK0VElbtW0MPY/2q3AqRJpJW5n nAQa0IZ3Cn/5Om4vnYFWXw4uxv3qK+X/2vN/I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kLG7NQBEtFdnYjP/TDuiM8VBKou8xCHguk1XH6PdSp8=; b=Y1vq/eaIwcPv6FQnM0hBwNRqMHOVJuzNKq+sBlAEhbfVwqzaPySWmEFMm9rjx6sNxI GkApeCTdrSB+iLfs663+kHl8qDlCGxvhHYniT9/L/+YFnk+GtRg8g4DDMOs4E19Ufg53 4aOwWTE4f58+XfqGipDWkZ9FaP5vPhmQRofQSNWGP2TaYieDrSF/RfbKJPmSWWPBh9AJ Q9BCbtKqJ9XVjNVZBumCZPUIqD66wpnSQpuUQblg7c+8x+Qic919lrqZqLvx2WcTkggx l4cDdRFmINMluX3rwwWzn7ZuK0trMSjaDWA43mVc8z+xFNpprwNFhiC6srbP1QoSb70u RwUg== X-Gm-Message-State: AOAM530IGFeFownGO3J9sHaDDq4sZLFm0rpSEEnizxyIvVOhGost8tJI QK89+xdg1/erpMINyRR0BnSPrQ== X-Google-Smtp-Source: ABdhPJyLgZ8QvV13blba0VBSOOKtwDuIr16yIarFEqBoSka+UasuM7Os/abg/W+1GNa/r98tN9Y9kQ== X-Received: by 2002:a05:600c:3c8d:b0:38e:4bc6:abde with SMTP id bg13-20020a05600c3c8d00b0038e4bc6abdemr5818644wmb.13.1650665468610; Fri, 22 Apr 2022 15:11:08 -0700 (PDT) Received: from panicking.amarulasolutions.com ([5.171.215.34]) by smtp.gmail.com with ESMTPSA id h10-20020a05600c414a00b0038ebb6884d8sm5263271wmm.0.2022.04.22.15.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 15:11:07 -0700 (PDT) From: Michael Trimarchi To: Stefano Babic , uboot-imx@nxp.com Cc: Fabio Estevam , u-boot@lists.denx.de Subject: [RFC PATCH] arm: mach-imx: cmd_nandbcb fix bad block handling Date: Sat, 23 Apr 2022 00:11:05 +0200 Message-Id: <20220422221105.2954828-1-michael@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.5 at phobos.denx.de X-Virus-Status: Clean The badblock should be skipped properly in reading and writing. Fix the logic NOTE. This is a rfc. Working on imx8mn and found the bad block handling in nand is quite broken. Seems that bootrom does not handle it so I switch on spl nand bad block and found there other bugs. I have fixed most of them. Let's start in how to read back the nandbcb Signed-off-by: Michael Trimarchi --- arch/arm/mach-imx/cmd_nandbcb.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/arch/arm/mach-imx/cmd_nandbcb.c b/arch/arm/mach-imx/cmd_nandbcb.c index 100dc17a15..48955092b7 100644 --- a/arch/arm/mach-imx/cmd_nandbcb.c +++ b/arch/arm/mach-imx/cmd_nandbcb.c @@ -505,10 +505,6 @@ static int read_fcb(struct boot_config *boot_cfg, struct fcb_block *fcb, int ret = 0; mtd = boot_cfg->mtd; - if (mtd_block_isbad(mtd, off)) { - printf("Block %d is bad, skipped\n", (int)CONV_TO_BLOCKS(off)); - return 1; - } fcb_raw_page = kzalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL); if (!fcb_raw_page) { @@ -529,7 +525,7 @@ static int read_fcb(struct boot_config *boot_cfg, struct fcb_block *fcb, else if (plat_config.misc_flags & FCB_ENCODE_BCH_40b) mxs_nand_mode_fcb_40bit(mtd); - ret = nand_read(mtd, off, &size, (u_char *)fcb); + ret = nand_read_skip_bad(mtd, off, &size, NULL, mtd->size, (u_char *)fcb); /* switch BCH back */ mxs_nand_mode_normal(mtd); @@ -616,6 +612,7 @@ static int write_fcb(struct boot_config *boot_cfg, struct fcb_block *fcb) for (i = 0; i < g_boot_search_count; i++) { if (mtd_block_isbad(mtd, off)) { printf("Block %d is bad, skipped\n", i); + off += mtd->erasesize; continue; } @@ -675,20 +672,15 @@ static int read_dbbt(struct boot_config *boot_cfg, struct dbbt_block *dbbt, void *dbbt_data_page, loff_t off) { size_t size; + size_t actual_size; struct mtd_info *mtd; loff_t to; int ret; mtd = boot_cfg->mtd; - if (mtd_block_isbad(mtd, off)) { - printf("Block %d is bad, skipped\n", - (int)CONV_TO_BLOCKS(off)); - return 1; - } - size = sizeof(struct dbbt_block); - ret = nand_read(mtd, off, &size, (u_char *)dbbt); + ret = nand_read_skip_bad(mtd, off, &size, &actual_size, mtd->size, (u_char *)dbbt); printf("NAND DBBT read from 0x%llx offset 0x%zx read: %s\n", off, size, ret ? "ERROR" : "OK"); if (ret) @@ -696,9 +688,9 @@ static int read_dbbt(struct boot_config *boot_cfg, struct dbbt_block *dbbt, /* dbbtpages == 0 if no bad blocks */ if (dbbt->dbbtpages > 0) { - to = off + 4 * mtd->writesize; + to = off + 4 * mtd->writesize + actual_size - size; size = mtd->writesize; - ret = nand_read(mtd, to, &size, dbbt_data_page); + ret = nand_read_skip_bad(mtd, to, &size, NULL, mtd->size, dbbt_data_page); printf("DBBT data read from 0x%llx offset 0x%zx read: %s\n", to, size, ret ? "ERROR" : "OK"); @@ -728,6 +720,7 @@ static int write_dbbt(struct boot_config *boot_cfg, struct dbbt_block *dbbt, if (mtd_block_isbad(mtd, off)) { printf("Block %d is bad, skipped\n", (int)(i + CONV_TO_BLOCKS(off))); + off += mtd->erasesize; continue; } -- 2.25.1