From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0A3C325714 for ; Fri, 14 Nov 2025 17:56:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763142965; cv=none; b=VtgLsUS7Xv45UGuevl+lv6bfi6onMKNk/ZAoDxac3rSuFiuk5vp2d+MGTe5x1bqqyLnvh2vOX7+oZNfBPbjZ2wnuuMi+dTtrTvYo2ozDVpsBb0yNw3Mi1LhzyKLL/dTvBG0WTIQ4P3ATlKM4zrcroo6sEjq6nIxex6mOLMIA/pU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763142965; c=relaxed/simple; bh=96gY4OoV+j/U4lPl8Ra/LZFkbNnag8dJ4ghrAL1dj/0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=l8/p4Hog+4RXSjrkWSLyzH5veiD3Oex5911xPlx/koyu24s+UT9xVFZ4IyiMJqu7Sndgd/sWRuKN9y0D3N2w11aWsNbEGcjCHjiV77yGZjJZHfbNNm/INv2ApjxBsjB668VX+26CZH7NC09ncESIPJhEmIa5SSo+RWzejXYFrjA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=BVdnbfkM; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="BVdnbfkM" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 450191A1AAD; Fri, 14 Nov 2025 17:56:02 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 0F0D76060E; Fri, 14 Nov 2025 17:56:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 318A910371986; Fri, 14 Nov 2025 18:56:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763142961; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=SW2ZIM9oLxfFffo3rWzZoaXBX8dzI2c+UoXAbtyAfs0=; b=BVdnbfkMfsLefuj59s7ARxHyfXx7iE9qKZDtSnwmqVGb/ytHO9FBrictprEUZTi8Dq/NBZ W4sKxXjl30O0V6OVszvv/KXcPVd6Ew52/lIuFELEj/GJgH6NtX8bBKhCYxLJoMp/OysmiH e+TMT8gF1/fqTjefSc0gYWpwgJ6XO8iyeyFlGS3D/nnwb+Gv8RiL8rdzvYYOQ7UrIDs1E5 ha/5n5wiji5A0mzS4gMVXWuL46nUR7ihoMLbABdtnyUbVhoOtQQ4RWcjbWmGyETvKTlzOK F0Hb2kIVMW9afUQGjXX1IsYD4n2biweiE8MyX2fP8DzUxw7oPgz22dGxnbJEXA== From: Miquel Raynal To: Sean Anderson Cc: Tudor Ambarus , Pratyush Yadav , Michael Walle , linux-mtd@lists.infradead.org, Richard Weinberger , linux-kernel@vger.kernel.org, Vignesh Raghavendra Subject: Re: [PATCH] mtd: spi-nor: Enable locking for n25q00a In-Reply-To: <3f415ff1-834e-4544-a093-dcb4fd25d5c9@linux.dev> (Sean Anderson's message of "Thu, 13 Nov 2025 10:32:05 -0500") References: <20251006223409.3475001-1-sean.anderson@linux.dev> <4888cefa-e8be-4f0d-9d4a-c82f9ff6cda0@linux.dev> <26a795ac-e6ff-4363-a8b9-38793a9be794@linux.dev> <33cbbac1-c247-4644-b555-998eea6e8305@linaro.org> <92e99a96-5582-48a5-a4f9-e9b33fcff171@linux.dev> <871pm3iegf.fsf@bootlin.com> <3f415ff1-834e-4544-a093-dcb4fd25d5c9@linux.dev> User-Agent: mu4e 1.12.7; emacs 30.2 Date: Fri, 14 Nov 2025 18:55:59 +0100 Message-ID: <87ldk8fqhc.fsf@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Hello, >> I am also working on locking these days, have you already started >> writing extra SPI NOR Documentation/process based on this thread? > > I haven't started writing anything. > >> I am also trying to clarify what is expected and what the API somehow >> does, as it was not fully clear for me at first sight. > > I agree, as you could probably have figured out. > >>> # flash_lock -u /dev/mtd/by-name/spi0.1 >>> # test spi0.1 64 >>> 83a8dc6125ec9672d18f7f18f92e16f867354dbe8e2f3b0aca52b9d0ad7d8ffe spi0.1 >>> 83a8dc6125ec9672d18f7f18f92e16f867354dbe8e2f3b0aca52b9d0ad7d8ffe - >>> # flash_lock -l /dev/mtd/by-name/spi0.1 $((1024 * 64 * 1024)) 1024 >>> # flash_lock -i /dev/mtd/by-name/spi0.1=20 >>> Device: /dev/mtd/by-name/spi0.1 >>> Start: 0 >>> Len: 0x8000000 >>> Lock status: unlocked <<<< Wrong! >>=20 >> This isn't wrong, even though at a first glance the output is >> misleading. The API apparently does not gives you all the >> locked/unlocked sectors, it is way more basic than that: it tells you >> whether the full range you asked for is indeed locked. > > Yeah, I figured that out eventually. > > Actually, the most surprising thing to me is that the lock/unlock APIs > are not incremental. That is, if I have a flash of 8 seconds, and > sectors 0-3 are locked and I lock sectors 0-1, it will say "well, > sectors 2-3 should be unlocked now, but we're not allowed to unlock > during a lock operation" and fail to lock. I would have expected it to > say "sectors 0-1 are already locked so we don't need to do anything". > The only way to go from sectors 0-3 to 0-1 being locked is to issue an > *unlock* on sectors 2-7. > > Conversely, if what you wanted to do was ensure sectors 2-3 were > unlocked, you can't do the naive thing and unlock sectors 2-3, since > that will try to lock sectors 0-1 and 4-7, the latter being disallowed > in an unlock operation. So you actually have to unlock sectors 2-7. > > And knowing what to do is complicated by ISLOCKED only returning a > boolean instead of just telling userspace what sectors are locked (which > must be a small finite set of ranges (usually one) on all flashes I'm > familiar with). I've tried to address most of this, see: Link: https://lore.kernel.org/linux-mtd/20251114-winbond-v6-18-rc1-spi-nor-= swp-v1-0-487bc7129931@bootlin.com/T/#mbae8b874181eb0401b30142f423b73b6389a0= c54 Kind regards, Miqu=C3=A8l