From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E861C433EF for ; Wed, 17 Nov 2021 08:03:33 +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 D96416128E for ; Wed, 17 Nov 2021 08:03:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D96416128E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=walle.cc 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 C25428316B; Wed, 17 Nov 2021 09:03:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=walle.cc Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=walle.cc header.i=@walle.cc header.b="Aa6ttEqt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C3D118316B; Wed, 17 Nov 2021 09:03:28 +0100 (CET) Received: from ssl.serverraum.org (ssl.serverraum.org [IPv6:2a01:4f8:151:8464::1:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 324AA82BCD for ; Wed, 17 Nov 2021 09:03:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=walle.cc Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=michael@walle.cc Received: from ssl.serverraum.org (web.serverraum.org [172.16.0.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 9B6D9223E9; Wed, 17 Nov 2021 09:03:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1637136202; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eW0rAyltRmbZgkdG9UN/GTbdmUsaIXZatfNKIjK20HI=; b=Aa6ttEqtA78RDfpjz94sZQGNl0xD0b8sVEZOMtfPZUxYMDYuYbU5mJzoTJ15O13aumYH/L aGQyudOlrRrkML36eIePeaoXuIn8ePF8aRizLdl7X4Lzqen5DWC4rdOkKt59saRKbpEuT3 9iYjxsooMNMwaWQUnF5GyP5w6Y/nVk8= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 17 Nov 2021 09:03:19 +0100 From: Michael Walle To: chaochao2021666@163.com Cc: jagan@amarulasolutions.com, Tudor.Ambarus@microchip.com, vigneshr@ti.com, jan.kiszka@siemens.com, baocheng.su@siemens.com, le.jin@siemens.com, u-boot@lists.denx.de, trini@konsulko.com, chao zeng Subject: Re: [PATCH V3] sf: Querying write-protect status before operating the flash In-Reply-To: <20211117024831.45586-1-chaochao2021666@163.com> References: <20211117024831.45586-1-chaochao2021666@163.com> User-Agent: Roundcube Webmail/1.4.11 Message-ID: <1122e19f1f4d0fc7b5cef0a02cb4439a@walle.cc> X-Sender: michael@walle.cc X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.35 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 Hi, Am 2021-11-17 03:48, schrieb chaochao2021666@163.com: > From: chao zeng > > When operating the write-protection flash,spi_flash_std_write() and > spi_flash_std_erase() would return wrong result.The flash is protected, > but write or erase the flash would show "OK". > > Check the flash write protection state before operating the flash > and give a prompt to show it has been locked if the write-protection > has enbale > > Signed-off-by: chao zeng > > --- > > Changes for V2: > - Return 0 not ENOPROTOOPT to refelect the flash feature > - Output prompt information > Changes for V3: > - Modify output information > - Delete return statement > --- > drivers/mtd/spi/sf_probe.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c > index f461082e03..f9e879aec5 100644 > --- a/drivers/mtd/spi/sf_probe.c > +++ b/drivers/mtd/spi/sf_probe.c > @@ -109,6 +109,9 @@ static int spi_flash_std_write(struct udevice > *dev, u32 offset, size_t len, > struct mtd_info *mtd = &flash->mtd; > size_t retlen; > > + if (flash->flash_is_locked && flash->flash_is_locked(flash, offset, > len)) > + printf("SF: Operate on the protected area.Writes will be > ignored\n"); I don't think this is the correct place for this output. This could also be called from a board file programmatically and then it might display this error, which is annoying. Also, this is issuing an additional command "read SR" for every write. What is your intention here? To make the user aware that he is going to write to a write-protected region when he is using the "sf" command? If that is the case, this should be added to that command instead. > + > return mtd->_write(mtd, offset, len, &retlen, buf); > } > > @@ -127,6 +130,9 @@ static int spi_flash_std_erase(struct udevice > *dev, u32 offset, size_t len) > instr.addr = offset; > instr.len = len; > > + if (flash->flash_is_locked && flash->flash_is_locked(flash, offset, > len)) > + printf("SF: Operate on the protected area.Erase will be ignored\n"); likewise. -michael