From patchwork Sun May 15 09:25:36 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: 1946 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 456943F18B for ; Sun, 15 May 2022 11:25:51 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id y1-20020a056402170100b0042aa8f679fdsf884780edu.1 for ; Sun, 15 May 2022 02:25:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1652606750; cv=pass; d=google.com; s=arc-20160816; b=ZqTvzibgByk9mdfWmx6KGUHZnGVsUaXbyp9EjbE+TOrNAeHo6jHukQCecCyUzZUnrN kGv8pqCWS2d9MOSTS+7YePikHnmZajuduucf+yxT4KxJYERsQ3v+ei0Kvgg6qwHwF5iU P1YBEmMDiuaYvaAiKktajfR2Mtq+QW7I023AeKK5KLSykG0/Msrh/RbL34q984GN+Ppo oT178eqQ0td6ZwwbPyytb6/miyjDitXsvxE8YcYnFsijyCXocsm98aD7UNS/c0r18vxG zLo0Qf5CsD3VVpFHyTVk4NsQUree4fymFcF7pzRV4a9Tt0DwOikQCLB2orK/+SJFhzyx LnWw== 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=H5C8SkiieAb2CjID/CKroqhZTkpoO9Nxn23UGdVre+4=; b=WTHXbKA71y13rztfYYLNEV8lIZlwAJnbMGFpOF7CMxCHG/mpOp95eTte3YTlROZInl YNNxMklCKzKydn7N79A7kuAxEy5GNvFrpHg3hMCPRBVBz54DoLRo4WfR1RR2Lwta1caw bEk+6LzsV7cyV0PeiRinZ6mh8X9HEhhcIRxGUsFIa0IkhFP82XFyuO8Sal16RrICU6Cl 0Yx6b5Zmg+WGPh3Z9nObxyZDnwgudpRbSh8ffQSytEgcRdF6ZbP+wbOC3Jfeht5N1Ek5 P9HY7oUgW0nLr/mTFsM9bEPeTydeCv3Ncr+Kl/TAXDwp9H9LCFC0viA0ZUmlwci/Wiw1 PTOg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Fa/MCzAw"; 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=H5C8SkiieAb2CjID/CKroqhZTkpoO9Nxn23UGdVre+4=; b=Pv6rhxaIXrfnzDwXPPRHge0HciPVdA52HzX+7AXDX4f3opM1pY5tsx0HmE9Ur4uTwx jOPGJadgk23bobOtfhSuh/0bgMJz9Wr9/OdbaxSfu5gCzeuV7CYILv0iIvMNxL+Tv64n QWaPQPRgxq45q63lRbykaVInAF7s9M2QPv3hc= 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=H5C8SkiieAb2CjID/CKroqhZTkpoO9Nxn23UGdVre+4=; b=yacPPc+iP5I9RlVaOVajE76poIYjHQbWrnpy+7AqfrzuHZUWDHzOuS1Cz2JH/zHKEm g1v0SKGME09IueZaBPa2ZunArCldRL62ZIXKSYFBG6UB3UkAri56dg7APWPHx9YbmHoG 7LEnP1oVoq8+4CjPrps5x0bQpfWGYaBu1mEoE+3/vwkDfBzf+IAiEwZjKscDhGDjjCt2 SFUZsXnjaRNQEWzegAk2gXhgNsNK2Q678q6MOTQjkv7CAXR0pnqBr4XX1d7cBsOmMPFo Ui8oLDj4tivcv4uASXn3OdLVyfck30dtvgczcGuziYmlkCaJV7KYedmvWYtvLxKhyWOA ipGw== X-Gm-Message-State: AOAM533ucrhcYia2DJqrOfSAT1r6qH9BkrrkbeCUTvB9MeE1Z71Q2vWO x+Tjq+t3yILFl6DLvS3H1HMDWRbn X-Google-Smtp-Source: ABdhPJyRvUnygKdIy5RcoJZy7BaeoeurL7IoVauK5ty210HTPzmrg3FGGWztmvjn5ckMzOWeXSJobA== X-Received: by 2002:a05:6402:5113:b0:427:f443:f63e with SMTP id m19-20020a056402511300b00427f443f63emr7506076edd.317.1652606750797; Sun, 15 May 2022 02:25:50 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:1b28:b0:6f3:ea95:a02b with SMTP id mp40-20020a1709071b2800b006f3ea95a02bls5989998ejc.9.gmail; Sun, 15 May 2022 02:25:49 -0700 (PDT) X-Received: by 2002:a17:907:7dab:b0:6f4:6650:395d with SMTP id oz43-20020a1709077dab00b006f46650395dmr10862191ejc.82.1652606749468; Sun, 15 May 2022 02:25:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652606749; cv=none; d=google.com; s=arc-20160816; b=Vp7L+IFXjHosrv9xj3QIBM/UbesfhpxRkA5AO4MsVc0GpUik1+zASHmXG3wofmwW1N SB7YIQnSSOVDQO5vUp2Atl6ASsvwmbXkBDZIpl0Kzm8oWNYDDsFeePONG8AXe6LqH9bH OC37DXlAUcwjxzZlWtlNBUnptUFFbPh2FVytIJqXrFdgJX2y0LSr++Qh8XdikE6Y8GVE smVhOAxwrLbQBb8Zu6v0ah97pJqOCwbOgxVvwh6bMfUQs9um0dNE/nMXtwBCxU0yKoMf 5Q9zgLJTX1RKDaas9ws0iV8YBVGd/9IBG3hQXNSZLOcnks5x4QQ5ImdSWe3GyoNspVh5 aZ+Q== 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=l77AqYbMqx7fcUmAt1Nphq7xS9njuYv1XHAQ4YODQ3w=; b=EW0Of6nhA+80Mu6KKYjM+R3GTvhWy+JN7+XG3bVUrGV/t1ieiHppM86QwJIyasjeNu 8nVjNZV2xdXhHz2NkN/JwNgEsPymWHXNinO0T0wRX7qLS7CIN7jVSytGsahjisLpzDxF 3Bt1K4C71T5VC3RZPAPslxAloUfMdNDy96m0LxDEFJsDPB2no0P5+a12ewUKM5qVVlGh P2xbLcbnJnFEw+KDX63u+s8UD4dyX2YjdGCGBBXMq0QGFAVZGOVv87OQjD9lF6iVCnz8 FDzn/TzJ7lVyHZ0awAH7Tk/anfdEo3HlgV78RcELxfaugfpIq6Qy8qKEb0b2NP9FZMFq y+bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Fa/MCzAw"; 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 j18-20020a170906535200b006e4e1b35024sor2591509ejo.38.2022.05.15.02.25.49 for (Google Transport Security); Sun, 15 May 2022 02:25:49 -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:62a2:b0:6e0:e201:b94e with SMTP id nd34-20020a17090762a200b006e0e201b94emr11056559ejc.730.1652606749123; Sun, 15 May 2022 02:25:49 -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 m17-20020a17090677d100b006f3ef214dc5sm2509888ejn.43.2022.05.15.02.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 May 2022 02:25:48 -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 V3 3/5] arm: mach-imx: cmd_nandbcb fix bad block handling Date: Sun, 15 May 2022 11:25:36 +0200 Message-Id: <20220515092538.1736154-4-michael@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220515092538.1736154-1-michael@amarulasolutions.com> References: <20220515092538.1736154-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="Fa/MCzAw"; 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 --- 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; }