From patchwork Tue Jun 22 05:21:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chaochao X-Patchwork-Id: 1495638 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=cfNqTC3/; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4G8QbT3wxWz9srZ for ; Tue, 22 Jun 2021 22:25:38 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D74A58020E; Tue, 22 Jun 2021 14:25:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=163.com 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; unprotected) header.d=163.com header.i=@163.com header.b="cfNqTC3/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 72E8D8296A; Tue, 22 Jun 2021 07:21:47 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from m12-12.163.com (m12-12.163.com [220.181.12.12]) by phobos.denx.de (Postfix) with ESMTP id 097C482958 for ; Tue, 22 Jun 2021 07:21:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=chaochao2021666@163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=4TR5N dr1X/1nXiYor55PbLhwGX59Rj86HLfap+B5RUE=; b=cfNqTC3/2DYCf3jn5B3uH 2XL2DhQ1m8zfBxzYHxk4jX/GAkyCU4r0jnDkXV3lomJqLYBs8zlQ5LwQiWgOMVDD lneMpJ1cBzgrlO1/wtecdadUUIjEAyXJKYkvJ05Cvk5c5t601TWppse+ZA5Q9HsP dTRnlOUgLqixaQO+WHI4Vg= Received: from asura.lan (unknown [182.149.135.186]) by smtp8 (Coremail) with SMTP id DMCowADHxdFdc9FgXmLYLA--.13654S2; Tue, 22 Jun 2021 13:21:33 +0800 (CST) From: chao zeng To: u-boot@lists.denx.de Cc: jagan@amarulasolutions.com, vigneshr@ti.com, Chao Zeng Subject: [PATCH] sf: Querying write-protect status before operating the flash Date: Tue, 22 Jun 2021 13:21:26 +0800 Message-Id: <20210622052126.49853-1-chaochao2021666@163.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-CM-TRANSID: DMCowADHxdFdc9FgXmLYLA--.13654S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zw1xKr4DZFWrWryDtrW7CFg_yoW8GrWxpF WkA343Cr4UGF17J39rJan8WasIq347KFy7tF9rur1fZw45XFs7KF9a9ryIqr1YyFnrAF45 KF4DGFyYyFZ7ZrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bnManUUUUU= X-Originating-IP: [182.149.135.186] X-CM-SenderInfo: 5fkd0uhkdrjiasrwlli6rwjhhfrp/1tbiERi5dV7+3y-o8QABsN X-Mailman-Approved-At: Tue, 22 Jun 2021 14:25:23 +0200 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 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 if the write-protection has enbale before operating the flash. Signed-off-by: Chao Zeng --- drivers/mtd/spi/sf_probe.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index 3befbe91ca..f06e6b88bd 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -109,6 +109,11 @@ 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)) { + debug("SF: Flash is locked\n"); + return -ENOPROTOOPT; + } + return mtd->_write(mtd, offset, len, &retlen, buf); } @@ -127,6 +132,11 @@ 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)) { + debug("SF: Flash is locked\n"); + return -ENOPROTOOPT; + } + return mtd->_erase(mtd, &instr); }