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 49B35C433F5 for ; Mon, 15 Nov 2021 03:08:40 +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 3E29C6139D for ; Mon, 15 Nov 2021 03:08:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3E29C6139D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=163.com 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 16596834A8; Mon, 15 Nov 2021 04:08:36 +0100 (CET) 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="bAGUyHUM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 150CF834E6; Mon, 15 Nov 2021 03:38:17 +0100 (CET) Received: from m12-12.163.com (m12-12.163.com [220.181.12.12]) by phobos.denx.de (Postfix) with ESMTP id 61851834E6 for ; Mon, 15 Nov 2021 03:38:13 +0100 (CET) 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=gWlPn VHncutzZOtGe6ne3dsVeTSkuGYpPn6YBdPG9bk=; b=bAGUyHUMHXBwzFuMjekwA +ngT8FuzUTRM2zz1oMT84fwGOG4qY+eFl1RDzkZw0pP1qTz7OD6BXpjlFtCBiyTz 4RakmtZLUCgkQhba70OJa/i9lVcwvgeC3ZACptxa149scx9bCRyg3wf9cbOrmrqo e1bg2kSjwykNeGyjJEcq4E= Received: from asura.lan (unknown [182.149.135.186]) by smtp8 (Coremail) with SMTP id DMCowABXH68LyJFhSFcEAw--.62097S2; Mon, 15 Nov 2021 10:38:04 +0800 (CST) From: chaochao2021666@163.com To: jagan@amarulasolutions.com, vigneshr@ti.com, tudor.ambarus@microchip.com Cc: chao.zeng@siemens.com, jan.kiszka@siemens.com, trini@konsulko.com, u-boot@lists.denx.de, baocheng.su@siemens.com, le.jin@siemens.com Subject: [PATCH v2] sf: Querying write-protect status before operating the flash Date: Mon, 15 Nov 2021 10:37:10 +0800 Message-Id: <20211115023710.893954-1-chaochao2021666@163.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: DMCowABXH68LyJFhSFcEAw--.62097S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zw1xKr4Dur4UJw15AF17trb_yoW8XrW3pF WkA34YkF48tF47J39rJan5XasIqw17Ka47tF9ruw1fXr45XFs7KF9a9FyIqr1YyFnrJF15 KF4DJFyYkFZ7ZrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jhb18UUUUU= X-Originating-IP: [182.149.135.186] X-CM-SenderInfo: 5fkd0uhkdrjiasrwlli6rwjhhfrp/1tbiHQ1MdVSIs55bFgAAsV X-Mailman-Approved-At: Mon, 15 Nov 2021 04:08:34 +0100 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 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 --- 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 f461082e03..995801817d 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)) { + printf("SF: Flash is locked\n"); + return 0; + } + 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)) { + printf("SF: Flash is locked\n"); + return 0; + } + return mtd->_erase(mtd, &instr); } -- 2.33.1