From patchwork Thu May 27 22:27:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 1484911 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=i7LpnFs/; 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=rpDLn5Ob; 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 4FrjD94YmTz9s24 for ; Fri, 28 May 2021 08:29:29 +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: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:In-Reply-To:References: List-Owner; bh=1xQpWF+pZZmGH7QSM6xYttTsomjtZcM516qVvNSheG8=; b=i7LpnFs/FdAFVB BsJNFspppexK6xTp8C1RObfZYYhcQBEbJsD5p3EBOf/0jvW4cyfSM0VaBuqXX9ZkbowtPfnU1oink S4bw5u+3PRzFtpAcdwWp984R83O7bvRpKyWNNmzyHKyX119GPMMqkjWtaqSDyoebMPO4Q8V8kJ8LL TzK3enQCyFt4X7GeMwnUIryM1PmR3Okm8DkUTx0DAZCR1Mx+LcboISf3eMf7Yj3HlhiCq9o4dJH+K GtFTgEcXhKPOjI+VQrAkPtXCXyoRwaZgJjWSETotnYPdgxEt5NjI+CD9rcw2+4fJOP1NJ3A61xukJ hY1GESYaCLpYe12ohMMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lmOTJ-009tSa-2H; Thu, 27 May 2021 22:27:21 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lmOTF-009tQb-1F for openwrt-devel@lists.openwrt.org; Thu, 27 May 2021 22:27:18 +0000 Received: by mail-lf1-x136.google.com with SMTP id q1so2406037lfo.3 for ; Thu, 27 May 2021 15:27:16 -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:mime-version :content-transfer-encoding; bh=Iry71z+4EvHaNsP0DQfWYPPko0OE4uBDMlFRr9RIp54=; b=rpDLn5ObPb+mzvjnY/9LfhHOkg4CKPe0af3sUoHmA6ynwZKrgh+7YBLTqDmqemP3Lu c9Y/svq67PGwduQ0isgpEOVXZateLcIGYAuMQ9n0g+LZrrys5USn9VBclMgceXs5OGoK JgMtDlCPR5/wNnsQiq6t9mgzVijm3umd1nLrxhZUENwZyXDvCB/sm01hulqdKLNl8YOR JwEHnWwFuXDt5Xft6AbIypnljr6cduyEpUnH8WZdnqtQ/fHQ1MsV/ZsSyEcuVjCYZ1I+ fLg8ikvBJZLSBY5b1TwheZeDPAcDvPYIU9zP5LOcoSLp0Fuh9Kr3XKN67Tlcxx+kAIDl Nc8g== 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:mime-version :content-transfer-encoding; bh=Iry71z+4EvHaNsP0DQfWYPPko0OE4uBDMlFRr9RIp54=; b=SH0BYOQz+1JnF39N+/54UkBuSwJiOe0NoJDc6qtqDeOgd8YFp4i27K3lToGV4HT3y/ +aiwjkHGNahVur6GMOzWGAE39LYlN2y7ia2EJzB4hUIjqmQX8okJpdb17PaweSrR16iA s3rDQcxQbK9bAuPFsyZj/S0RV8489DKuOkp5Mzjs6FR4XflEI62/F7WIbCGL5nWAx7ve PTIGAy7TTM+FyGyeD1lwipYREwTM/GmhNZhB3bfKEEhwR0wyb2+C978z4trdS0ZMgxGA jQW0DPhSJKszl1ZMb50iA5Lx0pOwVvemZlL78h+77HB57HUlGkO3xk/utpY1htrNLWWh qMRw== X-Gm-Message-State: AOAM533Ij8g7QXs0OLM78Cl5+/5RjeB3HIw7vzAotmo5tUhai3nSQhAc Ew2UwnQVdYT3tKmxOI10CbJcdNUUs0k= X-Google-Smtp-Source: ABdhPJzn4HogfHoUv2wG2b8/MBxm/JwOY9kGPdZiuxTYbil8Qw8/nTWSZWfQlZ0Bg+Z51HTil33t5Q== X-Received: by 2002:a19:f719:: with SMTP id z25mr3276763lfe.324.1622154434386; Thu, 27 May 2021 15:27:14 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id s15sm303004lfc.181.2021.05.27.15.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 15:27:13 -0700 (PDT) From: Sergey Ryazanov To: OpenWrt Development List , Christopher Hill Cc: Adrian Schmutzler , =?utf-8?q?Thibaut_VAR?= =?utf-8?q?=C3=88NE?= Subject: [PATCH] ath79: rb4xx-nand: fix 512 byte pages compatibility Date: Fri, 28 May 2021 01:27:06 +0300 Message-Id: <20210527222706.10360-1-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210527_152717_104650_4312D4CC X-CRM114-Status: GOOD ( 17.60 ) 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 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.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:136 listed in] [list.dnswl.org] -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 --- .../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 50bd69f6a4..00c65d14ae 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); + + /* + * Now we knows flash parameters and can tweak OOB the layout for old + * (usually 64MiB) flashes. + * + * 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); - nand->chip.ecc.mode = NAND_ECC_SOFT; nand->chip.ecc.algo = NAND_ECC_HAMMING; nand->chip.options = NAND_NO_SUBPAGE_WRITE; @@ -199,6 +217,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)