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 BA9B0C433F5 for ; Mon, 15 Nov 2021 14:02:48 +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 7A2686108F for ; Mon, 15 Nov 2021 14:02:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7A2686108F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.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 E6C068360F; Mon, 15 Nov 2021 15:02:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.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=amarulasolutions.com header.i=@amarulasolutions.com header.b="mRxkz1f2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D5E8A8364A; Mon, 15 Nov 2021 15:02:43 +0100 (CET) Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 53D1B82F5E for ; Mon, 15 Nov 2021 15:02:40 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jagan@amarulasolutions.com Received: by mail-ed1-x530.google.com with SMTP id m14so72675550edd.0 for ; Mon, 15 Nov 2021 06:02:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wzMoojPw7GaYDsM/GnZbZQjHtPkC0jFUXcjkLBJ6wA0=; b=mRxkz1f2bITgVSRQYfD7/2UxILD7Eyj67/OqcLDJbBoY5D7/OEX6L3GMbQARKNoo6x kYHPEPuM4ORq1JeZ7EF5V7WbPAw3KzbWEp5utiqSC6cmbKr6i5OR0Tz7k6+lu8Q8Lrb8 DqLTqLzr5mU/fcrid2pDCsEgn35cNUCrwIrVg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wzMoojPw7GaYDsM/GnZbZQjHtPkC0jFUXcjkLBJ6wA0=; b=IXwx3I2n0SC8y/GoNC4WE0/FQ86UQofBjT6V5/aIZuqc83D29sqkCYQYERxOv5NEhw AU0djdToHGtB6KUDbh0Qy+I4x/pyPq+dNEVbBANvx6WIWLvcU1Xqf2BdSzXJvgbximCo 4XChfshT5ME7XJ64eBb+ohyfMAdVhHrVRFZQ8M1I99e+ay+qJ7n8hguNnXuD5/MdtitD iyyt4ObeOLRYNxCvQPg/pGtt5ejMOs9Tr15daNI07kGNNVEkEPfz4qf21XiOjAUBBC73 aZ6qG0jIDCBoHS4pScmKMhoe9bGVtqccSRK2QwxRiFN/x5ecGbLzu+0laspOms9MoXdh 0WOw== X-Gm-Message-State: AOAM533NDVL4OGE3UtG7kLDPDO241WavjrfQtbqFwfrQ127hzZM8zRCF uIU+5zyPcLeNFM3VQ60T02soKalGxRGnHyNisF5nkw== X-Google-Smtp-Source: ABdhPJzksMZ5MJs0y/RX3joDwLd02taFEvT2AxuRX7cHbOlXXI1J+OAzA0K9kparo4SzwJxDJpQabE1uRsf5YgeIUNk= X-Received: by 2002:a05:6402:1d52:: with SMTP id dz18mr55999259edb.246.1636984959798; Mon, 15 Nov 2021 06:02:39 -0800 (PST) MIME-Version: 1.0 References: <20211115023710.893954-1-chaochao2021666@163.com> <6a0f1988-73ff-9fb8-2006-e6a7374ef630@163.com> In-Reply-To: <6a0f1988-73ff-9fb8-2006-e6a7374ef630@163.com> From: Jagan Teki Date: Mon, 15 Nov 2021 19:32:29 +0530 Message-ID: Subject: Re: [PATCH v2] sf: Querying write-protect status before operating the flash To: "chaochao2021666@163.com" Cc: Tudor.Ambarus@microchip.com, vigneshr@ti.com, michael@walle.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, 464759471@qq.com Content-Type: text/plain; charset="UTF-8" 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 On Mon, Nov 15, 2021 at 6:51 PM chaochao2021666@163.com wrote: > > On 2021/11/15 13:57, Tudor.Ambarus@microchip.com wrote: > > Hi, > > + Michael > > On 11/15/21 4:37 AM, chaochao2021666@163.com wrote: > > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe > > 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"); > > I would use a debug message, it's a flash specific thing. Also, I would update > a bit the message, something like > "SF: Flash has protected areas in the requested length. Writes will be ignored on those." > > + return 0; > > Michael has suggested to drop this line. I agree with him, check the conversation > on the previous email thread. > > Cheers, > ta > > + } > + > 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 > > > > the background is we like to use sf command to operate the flash under uboot shell, > > "sf erase" command still would show the prompt "erase ok" even though write-enable has enabled. > > > So at the beginning I'd like to return an error ,so the sf operation would show "erase failed" when operating the write-enabled devices. > > > I'm agree with only output information to prompt the user the operation unsuccessful. > > But It should explicitly give clear hints,so I suggest at here using printf not debug. We cannot encourage sf to show non operational prints like locked or unlocked on command line. Just check the contents via read and compare and understand whether flash is written properly, if not written properly user has to debug on his own. Jagan.