Received: by 10.213.65.68 with SMTP id h4csp3220593imn; Mon, 9 Apr 2018 16:50:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx492Tduq+biTutb/fmyM3BBcWwNTALG0km9mqzmH7VyvRsiYipRmmoAec8pU2sU/V51BRPB2 X-Received: by 10.101.90.140 with SMTP id c12mr26634831pgt.191.1523317805943; Mon, 09 Apr 2018 16:50:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523317805; cv=none; d=google.com; s=arc-20160816; b=RFieeSrSyE560EC0VsLxt68bfe6hhbEd6uj60OEWaeYM5IO8VnkJa7laVNjmIKQMAA LPQZfZO9ceeuFcCcNucK0qkK4V6PzTEeiTptHUn8PDcArgXBhrddD0Nb1NZ3y/ym8SZt kPOVEUlyTU6fNX0Yz66CTkVFrtpMEC5oEV0pMHg2BoeNs3A6ollCqPgexKYcLm5nu8Fi pxITlqLS1ee27KYgSK4gSmLkpghivp0go9gIDPkaaOt66BEW6qCwoGpHERoPFT/ihYbY NbRqeJk1fzM0T1RoJ+L7Q0gICwNFMgag7XKHzESMyp1vd4IaqLPXkrjp4/B432f0We0z wL7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=N6VBKX88tkcBef38fIPUPmH+iBuqPREPwaeBu480vhI=; b=qlHqLkCDE4n0seVvmMV7XmNlNjOwA/WXJAhqKHL+js1JH7O3MMtxRFaO/UFVF/1LmI bhRx0x5OiOup4vop4jpFCSBFq1eL6QS72PER7aagxrOBgcPmBq9Sk7x2anq6s/SwWPQJ Na8LmpHmWzbNQVKstndKe4XHE/lfO9AsH8QdfhZyYx2piu2a8azsQQLqDPCh6MW8q1Pn 7u8toPC37fAHiiUjgfimm5NPO+qjLG205VG4Nv1T7XJXBs3RD7S4kmsKaoNiakka3BFc adUSB4y4N9hko2NS8XTbGxy3bzUU2h+IfIbxjDYOlbIwNSQwJYKEQKtiWhBoXUSe23dw AmHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MFxPQXej; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8-v6si1328226pls.368.2018.04.09.16.49.29; Mon, 09 Apr 2018 16:50:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MFxPQXej; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752215AbeDIXqM (ORCPT + 99 others); Mon, 9 Apr 2018 19:46:12 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:51102 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752178AbeDIXqG (ORCPT ); Mon, 9 Apr 2018 19:46:06 -0400 Received: by mail-wm0-f42.google.com with SMTP id t67so22560215wmt.0 for ; Mon, 09 Apr 2018 16:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=N6VBKX88tkcBef38fIPUPmH+iBuqPREPwaeBu480vhI=; b=MFxPQXejWV6MX8xJlYL67JEimqavQNPx1xP3edJ2GUUi5rs4vU9aLHq1d++lutWN1R xmdOu7MBME998GoKptkFz7ClINZJNe8pa4JI79dGxkl/vf+XQMbAcpbtqVMbGfsN70FW NKn9q+MsvDuSrEY+7CsWeDGycFq+9KKZoyupSkv4jSZyY1Zvl7JDrIKY6KOkU/fiHHWG 4nPoxFOaoZIlMJAWSRN6fwqIQAx0SVfTDKFi8KQexZUiqZ52r3xaYawPwBFQB/h9X5VY JU8K7wd9GGaa8y6pSpGvcGPgfnRQQXfV0O+w+V/RcpOgyT3xOK4sQ/Hyaq7irokIl45S fzzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=N6VBKX88tkcBef38fIPUPmH+iBuqPREPwaeBu480vhI=; b=H/Dfai6lLo3rUFDlQJzPqFTaOyLT4gi6G/PoBr8wLTGL4W4GXN7Dxn3k649bFSonjZ NJo/789ABxHmBLWvp0KYJfyCfwUH8NoWzZV4rOFeU5PU09Gihep2YZHIQwf7BcpAdx+E DueJfnm4G5sARPlf+NraKVdYchueGzHGJx1L58HKAVggii4ehuWjBbl7H4A8ss/aTRbZ Lxx0ejhtXPsVLLJX8xewFm+YdThibChl4+ub93Csaekqc17f8FinWueZJt3oFgOt63V9 m8UH+2EcfgyDtYew8nnNbV17xfHFFKaAVA8EinhkZqVUb/P3KZ19Rn6a0AdbMD8yDDr3 Y4Ww== X-Gm-Message-State: ALQs6tDDIDhU2xVRrQsm222Of2dX6XwWnLcZMnR3+lu0UbCoiLIRvNeS vzpOPdNdshh7IG1aXYgMOuqNw8J6 X-Received: by 10.28.45.9 with SMTP id t9mr108424wmt.161.1523317564508; Mon, 09 Apr 2018 16:46:04 -0700 (PDT) Received: from [192.168.1.4] (ip-86-49-107-50.net.upcbroadband.cz. [86.49.107.50]) by smtp.gmail.com with ESMTPSA id p187sm253706wme.8.2018.04.09.16.46.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Apr 2018 16:46:04 -0700 (PDT) Subject: Re: [PATCH] mtd: spi-nor: clear Extended Address Reg on switch to 3-byte addressing. To: NeilBrown , Cyrille Pitchen Cc: David Woodhouse , Brian Norris , Boris Brezillon , Richard Weinberger , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org References: <874lkmw54j.fsf@notabene.neil.brown.name> <61e255fa-ece4-5566-d63a-730aaa25f18c@gmail.com> <87sh85uzu3.fsf@notabene.neil.brown.name> From: Marek Vasut Message-ID: Date: Mon, 9 Apr 2018 23:58:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <87sh85uzu3.fsf@notabene.neil.brown.name> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/08/2018 11:56 PM, NeilBrown wrote: > On Sun, Apr 08 2018, Marek Vasut wrote: > >> On 04/08/2018 09:04 AM, NeilBrown wrote: >>> >>> According to section >>> 8.2.7 Write Extended Address Register (C5h) >>> >>> of the Winbond W25Q256FV data sheet (256M-BIT SPI flash) >>> >>> The Extended Address Register is only effective when the device is >>> in the 3-Byte Address Mode. When the device operates in the 4-Byte >>> Address Mode (ADS=1), any command with address input of A31-A24 >>> will replace the Extended Address Register values. It is >>> recommended to check and update the Extended Address Register if >>> necessary when the device is switched from 4-Byte to 3-Byte Address >>> Mode. >>> >>> This patch adds code to implement that recommendation. Without this, >>> my GNUBEE-PC1 will not successfully reboot, as the Extended Address >>> Register is left with a value of '1'. When the SOC attempts to read >>> (in 3-byte address mode) the boot loader, it reads from the wrong >>> location. >> >> Your board is broken by design and does not implement proper reset logic >> for the SPI NOR chip, right ? That is, when the CPU resets, the SPI NOR >> is left in some random undefined state instead of being reset too, yes? > > Thanks for the reply. Sorry for the delay. > "Broken" is an emotive word :-) Certain the board *doesn't* reset the NOR > chip on reset. It's not emotive, it is descriptive of what it really is. Such boards which do not correctly reset the SPI NOR can, during ie. reset, get into a state where the system is unbootable or corrupts the content of the SPI NOR. This stuff came up over and over on the ML, it seems HW designers never learn. > However the NOR chip doesn't have a dedicated RESET pin. It has a pin > that defaults to "HOLD" and can be programmed to act as "RESET". This > pin is tied to 3V3 on my board. If it were tied to a reset line, it > would still need code changes to work (or switch from the default). I'm afraid this needs HW changes. The solution for SPI NORs without a dedicated reset line is to just hard cut the power to them for a while in case the CPU core reset out is asserted. > A few month ago: > Commit: 8dee1d971af9 ("mtd: spi-nor: add an API to restore the status of SPI flash chip") > Commit: 59b356ffd0b0 ("mtd: m25p80: restore the status of SPI flash when exiting") This works when reloading the driver, but not when restarting the system. > were added to Linux. They appear to be designed to address a very > similar situation to mine. Unfortunately they aren't complete as the > code to disable 4-byte addressing doesn't follow documented requirements > (at least for winbond) and doesn't work as intended (at least in one > case - mine). This code should either be fixed (e.g. with my patch), or removed. > >> >> Doesn't this chip support 4-byte addressing opcodes ? If so, we should >> use those and keep the chip in 3-byte addressing mode. Would that work? > > Yes and no. > If I > - { "w25q256", INFO(0xef4019, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, > + { "w25q256", INFO(0xef4019, 0, 64 * 1024, 512, > + SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | > + SPI_NOR_4B_OPCODES) }, > > then I can still read all the flash and it never gets switched to > 4-byte mode. Yes, dedicated opcodes are the way to go ... although, it doesn't solve the reset problem completely. Imagine your CPU ie. restarts during a page program operation and then the BootROM sends data over the SPI. Those data might get written into the SPI NOR, thus corrupting the content. > However, if the last address read from the flash is beyond 16M, the > extended address register gets implicitly set to 1, and reboot doesn't > work. > i.e. the problem isn't 4-byte mode exactly. The problem is the Extended > Address Register being set implicitly, and not being zero at reboot. Uh oh, I seems to remember something like this with the winbond flash. I think this was also the reason why zynqmp couldn't boot from those, because it was somehow weirdly configured by default. > It looks like we need to clear the extended address register before > reboot, either by: > - software-reset the flash at shutdown Doesn't work if CPU resets without executing this hook. > - write '0' in the shutdown handler See above > - write '0' after every transfer (or every transfer beyond 16M). What happens if CPU resets during the transfer ? System fails to boot. > Which would you prefer, or is there another option? Neither, and I am really sorry I don't have a suggestion for you here. But I think there might be something eluding me regarding this winbond extended something register. How is the behavior of the chip different exactly from a convention > 16 MiB SPI NOR (ie. Spansion one) ? -- Best regards, Marek Vasut