From patchwork Mon May 31 20:40:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 1485777 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=rCMNRwAZ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=AbcArGvJ; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fv6fw5FFCz9sXL for ; Tue, 1 Jun 2021 06:42:32 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=L9ANIjlqz7sEHUtQuKEGzKYJ3EvguQY7twRE5h/zfhc=; b=rCMNRwAZymm1Mk uPHYZrLUEoVAVQ0NgJlqse5UEu5EzhL2Kbrr/eULg9EYKzhjcql2ghaKDG7a7jZubRTZ8vxz3sMuK IstATCEsAPDeAW6G4JqrIbZt0MPrnRF2A5jAtaLNRBz9TWaCwGrOmcPvqPvP+bZqpTqpsnC3OIRtV zrOkrD8RlAA0jlQmsMKzrRYY34eMMmMYP2tptuC017vWnqv6mEfEBpQe9WNT9Dq7Vhn0FGPXNshke u8VNxCJjS1dJW8aCgfRH888Z+bd/e3wOk3gKsyIqIFr6Gqg4PFabrEXX4qhQFFj126ElJjTwWiWXo VPDK4MxZpadH1NBx5UrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnoiF-00DO6W-GT; Mon, 31 May 2021 20:40:39 +0000 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnoiC-00DO5e-Lj for openwrt-devel@lists.openwrt.org; Mon, 31 May 2021 20:40:38 +0000 Received: by mail-lj1-x22c.google.com with SMTP id v5so16381489ljg.12 for ; Mon, 31 May 2021 13:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Nq6p8u8TByeTpgjUc79pwaaJEVGwbbsK5DFTgqRt0Kk=; b=AbcArGvJQOOcRyxRztIki0X2eI/FRvBwzAE0B7BjaJzTq2M9Vg0f47hcSA0ZC+VJLF HyRH1BSz2Llt8Yb/25oWjXg3X1WjTPruvGSZCxSw1di+JRQuh9YBmCwfg5VRLLi14xOD XJQOVO5SNONRXmGWPEUhuAJ6PDpj7Gv9mgbVsEEj9Xpf5cO6OkskmcZ22fCVCfUlXDPT 10zER0fIyMAF7cVQz78IOIJgGC++HjuCb5LeHkgslDxFqBaqf4LOxXrhRa9tFmZk3Mjj C/xaFPISWWOaLZtVsCVxuhhz7bEGJbVFkrsB+0zI8VvelSY2nHennIR1MFHkLFROmKGB oKeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Nq6p8u8TByeTpgjUc79pwaaJEVGwbbsK5DFTgqRt0Kk=; b=XFPKf77eVzXM+CFbZD8lw/Lev+U1d7y+SsFX11FI+QGGKNZkQfgz8lOkFv1vpD+9bU bGh7V0swRH+fuq1fo01WYABfrBPwZV78k63Sl2BS03c/33n/x513etavj1TR7iQ/j1Iw Q/8tdcBowp2FFXdMZGLqiI+GaONwEXKQYpAmC5b2GiRHSQ1fHcNggl4uU9zMpREty0Wp 5+uh8sYE7FlSd7z7ZRI+BUcOPmEidEIXtFH/TsiCqnFUVv66O+bUAXrSiXjE/e1gbrCs isEQqRJbf1XtqDcyGxQuepOjuBeLVGi+qtXz71ecS4INZR0pUJ89JxddCSKmv8nN7w7R P6yA== X-Gm-Message-State: AOAM5323pwhsIqgz/p6RAug3Zn/ojFqY6muyvT7RXJGaeSLaP4oddoVs rS4V6yHO5dNUd2gPj9FX8bIDZPLs/1aI/Q== X-Google-Smtp-Source: ABdhPJxLUbXsMC4rQ5gSB+IxkCcZdJGFxFSTZdWI2fELXY2a6bbI466BnMmspYNL7TRAeQupzLUZPQ== X-Received: by 2002:a05:651c:211f:: with SMTP id a31mr17767318ljq.39.1622493634488; Mon, 31 May 2021 13:40:34 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id v24sm1458160lfp.37.2021.05.31.13.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 May 2021 13:40:33 -0700 (PDT) From: Sergey Ryazanov To: OpenWrt Development List , Christopher Hill Cc: Adrian Schmutzler , =?utf-8?q?Thibaut_VAR?= =?utf-8?q?=C3=88NE?= , Bas Mevissen Subject: [PATCH v2] ath79: rb4xx-nand: fix 512 byte pages compatibility Date: Mon, 31 May 2021 23:40:29 +0300 Message-Id: <20210531204029.28784-1-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210527222706.10360-1-ryazanov.s.a@gmail.com> References: <20210527222706.10360-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210531_134036_758780_405886B7 X-CRM114-Status: GOOD ( 20.32 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: MikroTik boards with 512 byte NAND pages require the old YAFFS1 OOB layout for compatibility with the RouterBoot bootloader. The RB4xx NAND driver supports such OOB layout, but checks a NAND page size [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:22c listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ryazanov.s.a[at]gmail.com] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org MikroTik boards with 512 byte NAND pages require the old YAFFS1 OOB layout for compatibility with the RouterBoot bootloader. The RB4xx NAND driver supports such OOB layout, but checks a NAND page size too early before the flash identification, what effectively preventing the old OOB layout from being used. To fix this issue, move the page size check and OOB layout configuration to the chip attaching hook, which is specially intorduced for ECC and OOB tweaking. While at it, copy a comment from the old AR71xx driver to make it clear, why do we need this OOB layout tweaking. Run tested with MikroTik RB411U board. Signed-off-by: Sergey Ryazanov --- Changes since v1: * rebased on top of latest master * rephrased the comment in the hook function, thanks to Bas for noticing this .../files/drivers/mtd/nand/raw/nand_rb4xx.c | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/target/linux/ath79/files/drivers/mtd/nand/raw/nand_rb4xx.c b/target/linux/ath79/files/drivers/mtd/nand/raw/nand_rb4xx.c index 22e2660b38..6778e70d34 100644 --- a/target/linux/ath79/files/drivers/mtd/nand/raw/nand_rb4xx.c +++ b/target/linux/ath79/files/drivers/mtd/nand/raw/nand_rb4xx.c @@ -81,6 +81,23 @@ static const struct mtd_ooblayout_ops rb4xx_nand_ecclayout_ops = { .free = rb4xx_ooblayout_free, }; +static int rb4xx_nand_attach_chip(struct nand_chip *chip) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + + /* + * At this point, we know the flash params and can tweak the OOB layout + * for 512-byte page (usually this is a 64MiB flash). + * + * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB + * bootloader will not be able to find the kernel that we load. + */ + if (mtd->writesize == 512) + mtd_set_ooblayout(mtd, &rb4xx_nand_ecclayout_ops); + + return 0; +} + static u8 rb4xx_nand_read_byte(struct nand_chip *chip) { struct rb4xx_nand *nand = chip->priv; @@ -135,6 +152,10 @@ static int rb4xx_nand_dev_ready(struct nand_chip *chip) return gpiod_get_value_cansleep(nand->rdy); } +static const struct nand_controller_ops rb4xx_nand_controller_ops = { + .attach_chip = rb4xx_nand_attach_chip, +}; + static int rb4xx_nand_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -185,9 +206,6 @@ static int rb4xx_nand_probe(struct platform_device *pdev) mtd->dev.parent = dev; mtd_set_of_node(mtd, dev->of_node); - if (mtd->writesize == 512) - mtd_set_ooblayout(mtd, &rb4xx_nand_ecclayout_ops); - #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0) nand->chip.ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT; nand->chip.ecc.algo = NAND_ECC_ALGO_HAMMING; @@ -204,6 +222,7 @@ static int rb4xx_nand_probe(struct platform_device *pdev) nand->chip.legacy.cmd_ctrl = rb4xx_nand_cmd_ctrl; nand->chip.legacy.dev_ready = rb4xx_nand_dev_ready; nand->chip.legacy.chip_delay = 25; + nand->chip.legacy.dummy_controller.ops = &rb4xx_nand_controller_ops; ret = nand_scan(&nand->chip, 1); if (ret)