Re: [PATCH] spi-nor: Verify written data in paranoid mode

From: Csókás Bence
Date: Thu May 08 2025 - 05:42:53 EST


Hi Richard,

On 2025. 04. 16. 20:41, Richard Weinberger wrote:
----- Ursprüngliche Mail -----
Von: "Csókás Bence" <csokas.bence@xxxxxxxxx>
I'm not so sure whether it makes sense at all.
In it's current form, there is no recovery. So anything non-trivial
on top of the MTD will just see an -EIO and has to give up.
E.g. a filesystem will remount read-only.

In our case, we use UBIFS on top of UBI, which in this case chooses
another eraseblock to hold the data instead, then re-tests (erase+write
cycles) the one which gave -EIO. Since the bus error is only transient,
it goes away by this time, and thus UBIFS will recover from this cleanly.

Are you sure about that?

I'd expect UBI to go into RO mode via a call path like:
ubi_eba_write_leb() -> ubi_io_write() -> mtd_write()
If mtd_write() returns an EIO, UBI will go into RO mode immediately.

(I'm assuming, your SPI-NOR has no bad block support, so ubi->bad_allowed
is false).

You are right, in our case we had to patch bad_allowed to be true. But the point is, that UBIFS _does_ get notified, and it _does_ go into RO mode, instead of getting success from mtd_write(), even though the written data was corrupted.

On 2025. 04. 16. 14:38, Csókás Bence wrote:
> We _could_ make it MTD-wide, in our case we only have a NOR Flash
> onboard so this is where we added it. If it were in the MTD core, where
> would it make sense?
>
> * mtd_write()
> * mtd_write_oob()
> * mtd_write_oob_std()
> * or somewhere else entirely?

I'm now starting to think mtd_write_oob() would be the right place for it. Thoughts?

Bence