mtd: Make sure UBIFS does not do multi-pass page programming on flashes that don't support it
v3 cover mtd: Make sure UBIFS does not do multi-pass page programming on flashes that don't support it
Hi,
The Cypress Semper S28 flash family uses 2-bit ECC by default. Under this ECC scheme, multi-pass page programs result in a program error. This means that unlike many other SPI NOR flashes, bit-walking cannot be done. In other words, once a page is programmed, its bits cannot then be flipped to 0 without an erase in between.
This causes problems with UBIFS because it uses bit-walking to clear EC and VID magic numbers from a PEB before issuing an erase to preserve the file system correctness in case of power cuts.
This series fixes that by setting mtd->writesize to the ECC block size
(16) and making sure UBIFS does not try to do a multi-pass write on flashes with writesize > 1.
It is based on the xSPI/8D series that adds support for Cypress S28 flash [0] (it is in next now). The patches themselves are independent of that series in the sense that they don't rely on 8D support. But since S28 flash is not supported without that series, these patches don't make much sense without it.
Tested on Cypress S28HS512T and MT35XU512ABA on J7200 and J721E respectively.
[0] https://lore.kernel.org/linux-mtd/[email protected]/
Pratyush Yadav (3):
UBI: Do not zero out EC and VID on ECC-ed NOR flashes
mtd: spi-nor: core: Allow flashes to specify MTD writesize
mtd: spi-nor: spansion: Set ECC block size
drivers/mtd/spi-nor/core.c | 3 ++- drivers/mtd/spi-nor/core.h | 3 +++ drivers/mtd/spi-nor/spansion.c | 1 + drivers/mtd/ubi/build.c | 4 +--- drivers/mtd/ubi/io.c | 9 ++++++++- 5 files changed, 15 insertions(+), 5 deletions(-)
--
2.28.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v3 1/3 UBI: Do not zero out EC and VID on ECC-ed NOR flashes
For NOR flashes EC and VID are zeroed out before an erase is issued to make sure UBI does not mistakenly treat the PEB as used and associate it with an LEB.
But on some flashes, like the Cypress Semper S28 SPI NOR flash family, multi-pass page programming is not allowed on the default ECC scheme. This means zeroing out these magic numbers will result in the flash throwing a page programming error.
Do not zero out EC and VID for such flashes. A writesize > 1 is an indication of an ECC-ed flash.
---
Notes:
No changes in v3.
Changes in v2:
- Use mtd->writesize to check if multi-pass programming can be done instead of using MTD_NO_MULTI_PASS_WRITE.
- Remove the assertion that a NOR flash most have writesize of 1.
drivers/mtd/ubi/build.c | 4 +--- drivers/mtd/ubi/io.c | 9 ++++++++- 2 files changed, 9 insertions(+), 4 deletions(-)
drivers/mtd/ubi/build.c +1 -3
@@ -628,10 +628,8 @@ static int io_init(struct ubi_device *ubi, int max_beb_per1024) ubi->bad_peb_limit =get_bad_peb_limit (ubi, max_beb_per1024); } -if (ubi->mtd->type ==MTD_NORFLASH ) { -ubi_assert (ubi->mtd->writesize ==1 ); +if (ubi->mtd->type ==MTD_NORFLASH ) ubi->nor_flash =1 ; - } ubi->min_io_size = ubi->mtd->writesize; ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft;
drivers/mtd/ubi/io.c +8 -1
@@ -535,7 +535,14 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture)return -EROFS ; } -if (ubi->nor_flash) { +/* +* If the flash is ECC-ed then we have to erase the ECC block before we +* can write to it. But the write is in preparation to an erase in the +* first place. This means we cannot zero out EC and VID before the +* erase and we just have to hope the flash starts erasing from the +* start of the page. +*/ +if (ubi->nor_flash && ubi->mtd->writesize ==1 ) { err =nor_erase_prepare (ubi, pnum);if (err)return err;
Signature · 6 lines
2.28.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v3 1/3] UBI: Do not zero out EC and VID on ECC-ed NOR flashes
Richard,
Quoted 11 lines · Pratyush Yadav
For NOR flashes EC and VID are zeroed out before an erase is issued to make sure UBI does not mistakenly treat the PEB as used and associate it with an LEB.
But on some flashes, like the Cypress Semper S28 SPI NOR flash family, multi-pass page programming is not allowed on the default ECC scheme. This means zeroing out these magic numbers will result in the flash throwing a page programming error.
Do not zero out EC and VID for such flashes. A writesize > 1 is an indication of an ECC-ed flash.
Patches 2/3 and 3/3 have been picked up in the spi-nor tree. Can you please pick this patch up?
Signature · 7 lines
Regards, Pratyush Yadav Texas Instruments India ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v3 1/3] UBI: Do not zero out EC and VID on ECC-ed NOR flashes
Quoted 13 lines · Pratyush Yadav
Richard,
Quoted 9 lines · Pratyush Yadav
For NOR flashes EC and VID are zeroed out before an erase is issued to make sure UBI does not mistakenly treat the PEB as used and associate it with an LEB.
But on some flashes, like the Cypress Semper S28 SPI NOR flash family, multi-pass page programming is not allowed on the default ECC scheme. This means zeroing out these magic numbers will result in the flash throwing a page programming error.
Quoted 5 lines
Quoted 2 lines
Do not zero out EC and VID for such flashes. A writesize > 1 is an indication of an ECC-ed flash.
Patches 2/3 and 3/3 have been picked up in the spi-nor tree. Can you please pick this patch up?
Yep, patch is in my next tree.
Signature · 2 lines
Thanks, //richard
PATCH v3 2/3 mtd: spi-nor: core: Allow flashes to specify MTD writesize
In reply to Pratyush YadavSome flashes like the Cypress S28 family use ECC. Under this ECC scheme, multi-pass writes to an ECC block is not allowed. In other words, once data is programmed to an ECC block, it can't be programmed again without erasing it first.
Upper layers like file systems need to be given this information so they do not cause error conditions on the flash by attempting multi-pass programming. This can be done by setting 'writesize' in 'struct mtd_info'.
Set the default to 1 but allow flashes to modify it in fixup hooks. If more flashes show up with this constraint in the future it might be worth it to add it to 'struct flash_info', but for now increasing its size is not worth it.
---
Notes:
Changes in v3:
- Initialize params->writesize in spi_nor_info_init_params() instead of spi_nor_init_params().
- Put writesize before page_size in struct spi_nor_flash_parameter.
New in v2.
drivers/mtd/spi-nor/core.c | 3 ++- drivers/mtd/spi-nor/core.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/core.c +2 -1
@@ -2885,6 +2885,7 @@ static void spi_nor_info_init_params(struct spi_nor *nor) nor->flags |=SNOR_F_HAS_16BIT_SR ;/* Set SPI NOR sizes. */ + params->writesize =1 ; params->size = (u64 )info->sector_size * info->n_sectors; params->page_size = info->page_size;
@@ -3430,7 +3431,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, mtd->name =dev_name (dev); mtd->priv = nor; mtd->type =MTD_NORFLASH ; - mtd->writesize =1 ; + mtd->writesize = nor->params->writesize; mtd->flags =MTD_CAP_NORFLASH ; mtd->size = nor->params->size; mtd->_erase = spi_nor_erase;
drivers/mtd/spi-nor/core.h +3 -0
@@ -193,6 +193,8 @@ struct spi_nor_locking_ops {* Serial Flash Discoverable Parameters (SFDP) tables. * * @size: the flash memory density in bytes. +* @writesize Minimal writable flash unit size. Defaults to 1. Set to +* ECC unit size for ECC-ed flashes. * @page_size: the page size of the SPI NOR flash memory. * @rdsr_dummy: dummy cycles needed for Read Status Register command. * @rdsr_addr_nbytes: dummy address bytes needed for Read Status Register
@@ -219,6 +221,7 @@ struct spi_nor_locking_ops {*/ struct spi_nor_flash_parameter {u64 size; +u32 writesize;u32 page_size;u8 rdsr_dummy;u8 rdsr_addr_nbytes;
Signature · 6 lines
2.28.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v3 2/3] mtd: spi-nor: core: Allow flashes to specify MTD writesize
Hi Pratyush,
Quoted 10 lines · Pratyush Yadav
Some flashes like the Cypress S28 family use ECC. Under this ECC scheme, multi-pass writes to an ECC block is not allowed. In other words, once data is programmed to an ECC block, it can't be programmed again without erasing it first.
Upper layers like file systems need to be given this information so they do not cause error conditions on the flash by attempting multi-pass programming. This can be done by setting 'writesize' in 'struct
mtd_info'.
Quoted 9 lines
Set the default to 1 but allow flashes to modify it in fixup hooks. If more flashes show up with this constraint in the future it might be worth it to add it to 'struct
flash_info', but for now increasing its size is not worth it.Signed-off-by Pratyush Yadav <[email protected]>Reviewed-by Tudor Ambarus <[email protected]>---
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git
spi-nor/next, thanks!
[2/3] mtd: spi-nor: core: Allow flashes to specify MTD writesize
https://git.kernel.org/mtd/c/afd473e858
Regards
Vignesh
PATCH v3 3/3 mtd: spi-nor: spansion: Set ECC block size
In reply to Pratyush YadavThe S28 flash family uses 2-bit ECC by default with each ECC block being 16 bytes. Under this scheme multi-pass programming to an ECC block is not allowed. Set the writesize to make sure multi-pass programming is not attempted on the flash.
---
Notes:
No changes in v3
New in v2.
drivers/mtd/spi-nor/spansion.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/spi-nor/spansion.c +1 -0
@@ -109,6 +109,7 @@ static int spi_nor_cypress_octal_dtr_enable(struct spi_nor *nor, bool enable)static void s28hs512t_default_init (struct spi_nor *nor) { nor->params->octal_dtr_enable = spi_nor_cypress_octal_dtr_enable; + nor->params->writesize =16 ; }static void s28hs512t_post_sfdp_fixup (struct spi_nor *nor)
Signature · 6 lines
2.28.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v3 3/3] mtd: spi-nor: spansion: Set ECC block size
Quoted 8 lines · Pratyush Yadav
The S28 flash family uses 2-bit ECC by default with each ECC block being 16 bytes. Under this scheme multi-pass programming to an ECC block is not allowed. Set the writesize to make sure multi-pass programming is not attempted on the flash.
Signed-off-by Pratyush Yadav <[email protected]>Reviewed-by Tudor Ambarus <[email protected]>---
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-nor/next, thanks! [3/3] mtd: spi-nor: spansion: Set ECC block size
https://git.kernel.org/mtd/c/294cca6ce5
Quoted 15 lines
Notes:
No changes in v3New in v2.
drivers/mtd/spi-nor/spansion.c | 1 + 1 file changed, 1 insertion(+)drivers/mtd/spi-nor/spansion.c +0
-0
drivers/mtd/spi-nor/spansion.c static int spi_nor_cypress_octal_dtr_enable(struct spi_nor *nor, bool enable) · line 115
Quoted 7 lines
drivers/mtd/spi-nor/spansion.c +1
-0@@ -109,6 +109,7 @@ static int spi_nor_cypress_octal_dtr_enable(struct spi_nor *nor, bool enable)static void s28hs512t_default_init (struct spi_nor *nor) { nor->params->octal_dtr_enable = spi_nor_cypress_octal_dtr_enable; + nor->params->writesize =16 ; }static void s28hs512t_post_sfdp_fixup (struct spi_nor *nor)
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/