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 BE860EB64D8 for ; Thu, 22 Jun 2023 13:59:35 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3BA5686281; Thu, 22 Jun 2023 15:59:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="POW2YG3A"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D20FA8479D; Thu, 22 Jun 2023 15:59:29 +0200 (CEST) Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) (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 5A46D8628F for ; Thu, 22 Jun 2023 15:59:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jbx6244@gmail.com Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-51beb527a89so754975a12.1 for ; Thu, 22 Jun 2023 06:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687442367; x=1690034367; h=content-transfer-encoding:content-language:cc:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=3CWgYwpgZ7TKr4RaUUdZjElkgKJ1BOdVFIoL5uq1oNo=; b=POW2YG3A6s8X4cY9JQye6EFlykoMjQ0eXOUmsTAHIa5i9WYMer2yR8UU4w4FV6gpcE RfKNdO43tG4Y8deoTY15rMPxux6u2tjSWaX3IM4JreRMCYIbgvAFjNOsihgrYEwywFw9 XkUAe6tZXWHsTV/Ccj+eq0zG1Mr9eDsfIbL2oQIprNPAgQ0xv2NcgTW0U8umrOoXCYZJ UkuDAXbv/R0OOkayoCWZcVRjOPA8ZBZD3KMkufpNpq7A9FY6R0c0qrMG4+AiWbno3OGs q4bgRUSBJicgHjrsNoPQmfPoCYYtbAubFaYBuyj52lcN78h669xpAV7T5gae4BwOo77J YAVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687442367; x=1690034367; h=content-transfer-encoding:content-language:cc:to:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=3CWgYwpgZ7TKr4RaUUdZjElkgKJ1BOdVFIoL5uq1oNo=; b=EDDhL1qxcevwA1bjv3neifbCodS6AxF7hSpmPmMrA9CBI/B4ksAVv42mJktO1+BQ92 ONcQw2QI+WnLZHzum4IM31f944rxpn4sZroGngs6A4rbFy/CfbzEne/CrrYMzNeBqFk5 5SX/ATmje1fL2H1vDLOvyqxTV4LcYeRkb1Ncr4CEELSTHHYbXVz5/VOTZnczw40fCAvG UjpLO/7ve3FVwQqqRA6gs0N3FK8cN5ONzuZG8+aoeAZ+fFOSEpZN3yBLslu2EKvpHFl5 hH1jamW5AzdQ8kNsvBpgwgmglJcXpQO4DZ3q7eLzY6taDF7gIJ1rw2+x77+h94tuoAZe ysKg== X-Gm-Message-State: AC+VfDzl6fV3SbF3Ckag+Y9C3oAl8Pb0Suz5bLvl6/AYWhUbfxP2A9sO KhuEdAPjQfJuKo1PH86TrmM= X-Google-Smtp-Source: ACHHUZ4/Lij9JnI1sun8Yrl0uv8g761xpAF3SIdsaf/V9vFDZaiUfYRKZvEMjAT+UJQsS/Gb+JmkKQ== X-Received: by 2002:a05:6402:517:b0:51a:53e0:843f with SMTP id m23-20020a056402051700b0051a53e0843fmr9279571edv.37.1687442366589; Thu, 22 Jun 2023 06:59:26 -0700 (PDT) Received: from [192.168.2.1] (81-204-249-205.fixed.kpn.net. [81.204.249.205]) by smtp.gmail.com with ESMTPSA id d8-20020a056402078800b005187a42b44fsm4027867edy.58.2023.06.22.06.59.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Jun 2023 06:59:25 -0700 (PDT) Message-ID: <295d48d1-5289-1b16-99a5-fbbb79ef96e0@gmail.com> Date: Thu, 22 Jun 2023 15:59:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 From: Johan Jonker Subject: [PATCH v1] mtd: nand: raw: rockchip_nfc: copy hwecc PA data to oob_poi buffer To: kever.yang@rock-chips.com Cc: sjg@chromium.org, philipp.tomsich@vrull.eu, michael@amarulasolutions.com, dario.binacchi@amarulasolutions.com, u-boot@lists.denx.de, yifeng.zhao@rock-chips.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 Rockchip boot blocks are written per 4 x 512 byte sectors per page. Each page must have a page address (PA) pointer in OOB to the next page. Pages are written in a pattern depending on the NAND chip ID. This logic used to build a page pattern table is not fully disclosed and is not easy to fit in the MTD framework. The formula in rk_nfc_write_page_hwecc() function is not correct. Make hwecc and raw behavior identical. Generate boot block page address and pattern for hwecc in user space and copy PA data to/from the already reserved last 4 bytes before EEC in the chip->oob_poi data layout. Signed-off-by: Johan Jonker --- drivers/mtd/nand/raw/rockchip_nfc.c | 34 ++++++++++++++++++----------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/mtd/nand/raw/rockchip_nfc.c b/drivers/mtd/nand/raw/rockchip_nfc.c index 5fcf6a6b..274489ec 100644 --- a/drivers/mtd/nand/raw/rockchip_nfc.c +++ b/drivers/mtd/nand/raw/rockchip_nfc.c @@ -525,7 +525,7 @@ static int rk_nfc_write_page_hwecc(struct mtd_info *mtd, int pages_per_blk = mtd->erasesize / mtd->writesize; int ret = 0, i, boot_rom_mode = 0; dma_addr_t dma_data, dma_oob; - u32 reg; + u32 tmp; u8 *oob; nand_prog_page_begin_op(chip, page, 0, NULL, 0); @@ -552,6 +552,13 @@ static int rk_nfc_write_page_hwecc(struct mtd_info *mtd, * * 0xFF 0xFF 0xFF 0xFF | BBM OOB1 OOB2 OOB3 | ... * + * The code here just swaps the first 4 bytes with the last + * 4 bytes without losing any data. + * + * The chip->oob_poi data layout: + * + * BBM OOB1 OOB2 OOB3 |......| PA0 PA1 PA2 PA3 + * * Configure the ECC algorithm supported by the boot ROM. */ if (page < (pages_per_blk * rknand->boot_blks)) { @@ -561,21 +568,17 @@ static int rk_nfc_write_page_hwecc(struct mtd_info *mtd, } for (i = 0; i < ecc->steps; i++) { - if (!i) { - reg = 0xFFFFFFFF; - } else { + if (!i) + oob = chip->oob_poi + (ecc->steps - 1) * NFC_SYS_DATA_SIZE; + else oob = chip->oob_poi + (i - 1) * NFC_SYS_DATA_SIZE; - reg = oob[0] | oob[1] << 8 | oob[2] << 16 | - oob[3] << 24; - } - if (!i && boot_rom_mode) - reg = (page & (pages_per_blk - 1)) * 4; + tmp = oob[0] | oob[1] << 8 | oob[2] << 16 | oob[3] << 24; if (nfc->cfg->type == NFC_V9) - nfc->oob_buf[i] = reg; + nfc->oob_buf[i] = tmp; else - nfc->oob_buf[i * (oob_step / 4)] = reg; + nfc->oob_buf[i * (oob_step / 4)] = tmp; } dma_data = dma_map_single((void *)nfc->page_buf, @@ -720,12 +723,17 @@ static int rk_nfc_read_page_hwecc(struct mtd_info *mtd, goto timeout_err; } - for (i = 1; i < ecc->steps; i++) { - oob = chip->oob_poi + (i - 1) * NFC_SYS_DATA_SIZE; + for (i = 0; i < ecc->steps; i++) { + if (!i) + oob = chip->oob_poi + (ecc->steps - 1) * NFC_SYS_DATA_SIZE; + else + oob = chip->oob_poi + (i - 1) * NFC_SYS_DATA_SIZE; + if (nfc->cfg->type == NFC_V9) tmp = nfc->oob_buf[i]; else tmp = nfc->oob_buf[i * (oob_step / 4)]; + *oob++ = (u8)tmp; *oob++ = (u8)(tmp >> 8); *oob++ = (u8)(tmp >> 16); -- 2.30.2