Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2E65C433F5 for ; Wed, 15 Sep 2021 06:03:38 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B2F1A61209 for ; Wed, 15 Sep 2021 06:03:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B2F1A61209 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AFF7582849; Wed, 15 Sep 2021 08:03:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1631685816; bh=mgNzOs7NZn0nieWKNNaokBLAG75OGmFZFmOKA6vmzg4=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=vZ494NqXMyrw1wns3N/KpljoAEDWwDJjNahsEs7Jp6f0plbB2a4n6fiUK1IB9ItXn oRYnCRjYJZ+jRjQbEumsgOQUwwRX1R+dY2sEcWOo6AULI7lnhKpZ4BFJbo19Ix1yjX fTDMBK9v+zvKy3VAxxTZprj/5+ADKSKm1zO3PWtfGGjD1KZoRLlzIrHmsMxXWyUdKq bD19caPxNu5+ng4j677pXiT46lAFRZ0KcQvFCe66dvqmHn1JGO+47CEbe1A2Vt1iT2 PbzQxBnyagyIo2jRKFRBm9sGN2qZq6h5i95ngkpxUsAF7oyc2X5CTdo6KIWYbaUFbA xlYqr9Y5OlHkQ== Received: from [127.0.0.1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 4411D80EC5; Wed, 15 Sep 2021 08:03:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1631685814; bh=mgNzOs7NZn0nieWKNNaokBLAG75OGmFZFmOKA6vmzg4=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Zv7ar5/dkNB2au7+3lbnL4Tw0CJMMblaV8T1WpRrq4nC8VO+ZdJVsleYo8w22Lz4y aDLZidb0BzX0cpu4zEQrcKXwLNbBOfY5OxTB50mAUmOuNXDCc7jEGrgn8BOO1bwvkn Kxl2JzevpQUAfxQ3wAb9aM33Y+sle3kYZC0sUkxOiMlzAdoLGC4XwhY1JzBUgurfzl hcFtJ3YBh/YZT1pGTRAfosmM12aTrAQW2wN5b5HWNwS607xN93O3HNO6JEqlWZbIRE 4NZ2Vt1+UcoHpJ367ACMPyqPGPmc2eGoF7wSbUqT46v5jxxmgFGAOI8jHz7kdEek33 PMpMcmbgsw2BQ== Subject: Re: [PATCH] mtd: spi-nor: Fix SF MTDIDS when registering multiple MTDs with DM enabled To: hs@denx.de, u-boot@lists.denx.de Cc: Jagan Teki , =?UTF-8?Q?Marek_Beh=c3=ban?= , Miquel Raynal , =?UTF-8?Q?Pali_Roh=c3=a1r?= , Patrice Chotard , Patrick Delaunay , Priyanka Jain , Simon Glass References: <20210914230622.245747-1-marex@denx.de> <58930899-7190-9c36-6377-cc0c41d1800a@denx.de> From: Marek Vasut Message-ID: Date: Wed, 15 Sep 2021 07:59:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <58930899-7190-9c36-6377-cc0c41d1800a@denx.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean On 9/15/21 6:23 AM, Heiko Schocher wrote: > Hi Marek, > > On 15.09.21 01:06, Marek Vasut wrote: >> The flash->mtd.name used to be nor%d before, now it is the type of the >> SPI NOR like e.g. mt25ql02g. It is possible to find plenty of examples >> of the former in U-Boot configs by searching for MTDIDS.*nor.*spi, while >> the later is ambiguous if there are multiple flashes of the same type in >> the system and breaks existing environments. >> >> This does no longer get recognized when running 'mtdparts' for example: >> CONFIG_MTDIDS_DEFAULT="nor0=47040000.spi.0" >> >> Fix this by setting the correct mtd.name to nor%d. >> >> Fixes: b7f060565e3 ("mtd: spi-nor: allow registering multiple MTDs when DM is enabled") >> Signed-off-by: Marek Vasut >> Cc: Heiko Schocher >> Cc: Jagan Teki >> Cc: Marek Behún >> Cc: Miquel Raynal >> Cc: Pali Rohár >> Cc: Patrice Chotard >> Cc: Patrick Delaunay >> Cc: Priyanka Jain >> Cc: Simon Glass >> --- >> drivers/mtd/spi/sf_mtd.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) > > Seem fixes the same problem as Patrick already posted here: > > https://patchwork.ozlabs.org/project/uboot/patch/20210913095742.v2.1.I73dae4b93f0587dc130e512e95a1f4794e0b0233@changeid/ > > I find your approach cleaner, so: > > Acked-by: Heiko Schocher > > @Patrick: Could you test this patch please? The option from Patrick does look more predictable, but looking at the old implementation of spi_flash_mtd_number(), that one handled even cases of parallel-nor and spi-nor (both using the nor%d) present on the same system. This: static int spi_flash_mtd_number(void) { #ifdef CONFIG_SYS_MAX_FLASH_BANKS return CONFIG_SYS_MAX_FLASH_BANKS; #else return 0; #endif } ... sprintf(sf_mtd_name, "nor%d", spi_flash_mtd_number()); The patch from Patrick does not, it does per-spi-nor-only counting using the dev_seq() there, which is more predictable, but local to spi-nor. The MTD core has its own IDR counting, which is used by this patch and is global to the MTD core. That has two issues, one is that it is possibly too global and counts both nor%d and nand%d, which means it would fail on systems with both SPI NOR and regular NAND. The other is it is likely less predictable (what happens if the SPI NOR and parallel NOR gets probed in the reverse order ? I know it is unlikely, but it can happen in the future). So I think we need a third option which I would suggest be based on the patch from Patrick, but which would take into account the other nor%d devices like parallel NOR flashes. That would likely have to happen in the mtd core using some modified IDR counting. I think you might need to modify it such that you would pass in the prefix of the device (like 'nor') and then do per-prefix counting, with the special case that parallel NORs are counted first. Also, that would also have to consider probing of multiple SPI NORs in either order (say you have two, if you do 'sf probe 0:0 ; sf probe 0:1' vs. 'sf probe 0:1 ; sf probe 0:0'), and make sure they get enumerated with the same nor%d value either way, that might be where the dev_seq() would come in.