From patchwork Sun May 15 09:35:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Nazzareno Trimarchi X-Patchwork-Id: 1953 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id D37A13F18B for ; Sun, 15 May 2022 11:35:48 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id r8-20020a056402018800b00428b43999fesf7801914edv.5 for ; Sun, 15 May 2022 02:35:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1652607348; cv=pass; d=google.com; s=arc-20160816; b=n1TLy6FqCIDllsJWZnPj5KQmropKIoQcAXo+gHfsmsJAfcu1kzhyTeezemIQ6asQkX NbPUQhZa5Paovpf979UUbic6mGFJIc5KBXvYu6OHKguihztFlklTk+VuRV8X3ePltxBH dYEe56QzyPt9tK6zrKfVxXdrFASyWq2AFwWs/bLEc9s1lxT6BUe3imEuROZSJ6cAOtS3 P/JHwRzmzDGrmFbr0XUQWEr0FaxwHsK7cWAoyj5rqs53xtUc/UIzzr3iI12oRbWYyd04 Z6B47eWY98dFwdd4rbyQ8x+xRPjOVaeM5IuXYcOK3MmsdlfcVi6ij5q3ahtz5neZGYXY +9lQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=NGkYUA9IgD7ZaTlXNkG3L06LQgBIh2Ozso3u6c9bwXw=; b=cjl3ZwYCFW3riZxYaOq13jMk3CUA7BO05exDgOey80IYXhVKo9SwRqDL/s3WQL7Bow ckUGHIPcOSocN0O+nUzMNdW+F4ubpj/qYYqHlKX4zC8Gjf8WrnT0RaCUrBt4YB5PVKBE Lh2xlFv61/Uv8OuDNXYo0zkP8g+qY7Yj/Pnc6Y+mZFaFHC6xawz73Pm5IuZ5Ft56/SGR NDHUtuuoywbNm7iJn0uaBYZQySeJvDB8l7Va6fC8/LpP+pdGBU8lGG05+g0EhYNfbV8g 7UwwXds4UEtQYkSI6FF5cdeYD97ioWdsqLWMziCzyt8WnOPp7dL8q5Byj/kMpJo6IVTi dh9g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=U0dlHY63; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=NGkYUA9IgD7ZaTlXNkG3L06LQgBIh2Ozso3u6c9bwXw=; b=c1arqhPorWPPOQRsbKXJKT/Mes54HDjXb/f8IpoXtrRgXSc4+VHGO7UUDf2MhwbSiR GwIXYNApo3lPZxmZs59Xxg1R8RYq5b3DzxTPgBsF3lFs3Oatpcd0aS4W1WRbW+bRCJlr zfSX+un51Y5Any3mswgh3XW5bAeynHia5Hi2I= 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:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=NGkYUA9IgD7ZaTlXNkG3L06LQgBIh2Ozso3u6c9bwXw=; b=q5k8YqyM9wdCHo42miEB/aUWj0e1u6M6ciIzo/K3DqbCNClwh5gKqfUzyy7BUex/vu u3Gk3CLXQNpdDPZfaglmSAqkxAF3aXHjjcndsA1rZXII7Nf2EL4zz8JjhedVit8+RayS et+FjaGgC8DkQo4oXsaQ6F25av+IhzyxGQTemrVrJoBVGA5N+44a8ErostOuO3KkaAQ3 ex8ZrceQnomCB2S/aTpHdomGlcxsgvOFiR+/zua0go2we3izknNOBo7CC4OhWat2+jXf pZo70a1SXfK3CZjTfFCgSTRESWiRKX5aYgZHRydOfrJrXC6auSbFzyv9hQW3P3iVrWt9 3+HQ== X-Gm-Message-State: AOAM530kJUPYugrGZswaYSee9p6qTvbKtXwqsWEw/BQZ/OGYEsWVnRRM xULus/5ET6KjFT02tjffJsRBFKdF X-Google-Smtp-Source: ABdhPJx9SpAVWH/p3Cf1IN0gL/053FSPIQFOshKljggL+rYa2mWmiIP7keOeWBc7SUnfBYM22IhXeA== X-Received: by 2002:a17:907:16ac:b0:6f4:60e1:723b with SMTP id hc44-20020a17090716ac00b006f460e1723bmr10967910ejc.272.1652607348370; Sun, 15 May 2022 02:35:48 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:26d2:b0:428:f87:ccd8 with SMTP id x18-20020a05640226d200b004280f87ccd8ls3101792edd.1.gmail; Sun, 15 May 2022 02:35:47 -0700 (PDT) X-Received: by 2002:a05:6402:2710:b0:427:d087:b with SMTP id y16-20020a056402271000b00427d087000bmr7588687edd.11.1652607347187; Sun, 15 May 2022 02:35:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652607347; cv=none; d=google.com; s=arc-20160816; b=MWPJvvKutT5KZ/9eNo7evEjlkuHaW7xAfoQDarymlGk+f+E4OKSi+GONuoUfq4qdpY LXZ5TA+v9I3GPGNqJ3EQeXWaYCZtymFV7Trq7CcHDMtdXCZorubwdi39ff72sRye4wvp 0TrWyMihZRaSs/9TRNb/w37iNKVpFaLsJsqo8c3kZYwiGNvghMwrNJNWI6JZB2grmVNW 6i3yalRsPrU4uVy78/R+KnpjcYX6uqGAiToKEJ1g75fUFsnuQtxrH8Dz876/qp3+TTbF btiXxsiAbXYhmxL/DKLNT5vkvy3MvsL09h+iN7VG2PPyh+ed9yOof+DGHar5aDpPLNxb vk4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=t5a7/1Ug70eiPR+eA+idZWDvK7u/qPwhFkVCMusaVJ0=; b=nQyStYtuI/yKgCGgXmUgAEC+ETM0bUQO16CRg3c71bJTySOtSUEEgWbiGhNz29WTAI LlrRXNz0/q+FpTCNFU2KzACgHvRbUHwhtwmwFEuVazsH49jtJBLCsRtc8i6ZVlrB9nuM RRHkfiSk7PfofKQG0Y3nhEr7abyxQXa0URLyvQ0ey58pUD9GbpDFWJ5SwcDiVEZ/DF1l OPz9IX+YXXnQEJytVnWv39CFogExv6gT/goB363eul8Asvj4BrTXXVLHlQWqstpZRr6L 3xFAQP2TLqj0/7jLwfqcHxWuwmdTh0NCvDlVofufBDDzgOdzmXOCcYRVX2JiEVLeMAk3 yXjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=U0dlHY63; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id e11-20020a170906648b00b006e7fd3de9f6sor2649967ejm.49.2022.05.15.02.35.47 for (Google Transport Security); Sun, 15 May 2022 02:35:47 -0700 (PDT) Received-SPF: pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:907:968d:b0:6f4:9f9e:3e5f with SMTP id hd13-20020a170907968d00b006f49f9e3e5fmr11315583ejc.540.1652607346927; Sun, 15 May 2022 02:35:46 -0700 (PDT) Received: from localhost.localdomain (mob-109-118-140-232.net.vodafone.it. [109.118.140.232]) by smtp.gmail.com with ESMTPSA id p6-20020a17090664c600b006f3ef214de8sm2516582ejn.78.2022.05.15.02.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 May 2022 02:35:46 -0700 (PDT) From: Michael Trimarchi To: Han Xu , U-Boot-Denx Cc: Ye Li , Stefano Babic , Miquel Raynal , Fabio Estevam , Dario Binacchi , Sean Anderson , linux-amarula@amarulasolutions.com, Jagan Teki , Ariel D'Alessandro , Tom Rini , Tim Harvey Subject: [PATCH V4 3/5] arm: mach-imx: cmd_nandbcb fix bad block handling Date: Sun, 15 May 2022 11:35:32 +0200 Message-Id: <20220515093534.1737172-4-michael@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220515093534.1737172-1-michael@amarulasolutions.com> References: <20220515093534.1737172-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=U0dlHY63; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The badblock should be skipped properly in reading and writing. Fix the logic. The bcb struct is written, skipping the bad block, so we need to read using the same logic. This was tested create bad block in the area and then flash it and read it back. Acked-by: Han Xu Tested-By: Tim Harvey Signed-off-by: Michael Trimarchi --- V3->V4: - none V2->V3: - Add tested-by from Tim - Add ack from Han Xu V1->V2: - Adjust the commit message - Add Cc Han Xu and Fabio - move out from RFC --- 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 f119e9f88d..c54f52b343 100644 --- a/arch/arm/mach-imx/cmd_nandbcb.c +++ b/arch/arm/mach-imx/cmd_nandbcb.c @@ -506,10 +506,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) { @@ -530,7 +526,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); @@ -617,6 +613,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; } @@ -676,20 +673,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) @@ -697,9 +689,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"); @@ -729,6 +721,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; }