All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories
@ 2018-11-13 16:58 Sverdlin, Alexander (Nokia - DE/Ulm)
  2018-11-14  8:00 ` Tudor.Ambarus
  0 siblings, 1 reply; 6+ messages in thread
From: Sverdlin, Alexander (Nokia - DE/Ulm) @ 2018-11-13 16:58 UTC (permalink / raw)
  To: linux-mtd, Marek Vasut, David Woodhouse, Brian Norris,
	Boris Brezillon, Richard Weinberger, Cristian Birsan,
	Tudor Ambarus

Hello Tudor and all,

first of all, thank you for your work on SFDP support in Linux!

Unfortunately, I'm debugging a regression caused by 5390a8df769ec
"mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories"
in [out of tree] support for S25FS128S.

The culprit is the following part of your patch:

	/*
	 * For non-uniform SPI flash memory, set mtd->erasesize to the
	 * maximum erase sector size. No need to set nor->erase_opcode.
	 */
	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
		if (map->erase_type[i].size) {
			erase = &map->erase_type[i];
			break;
		}
	}

The problem in our case is, we have existing partitioning with 128k partitions
(the Flash itself supports 256k and 64k erasesize, depending on configuration).
The chip is configured for 64k erasesize, non-uniform mapping.

The mapping itself is being detected correctly, but when it comes to the code
snippet above, it selects the biggest erasesize from all sizes advertised in
SFDP, including 256k, which is not applicable to the current configuration.

Finally when mtd registers the partitions, they are forced read-only:

	partition "..." doesn't start on an erase block boundary -- force read-only

So this change is not backwards compatible to the existing partitionings.

I cannot come with the justification for the above decision myself, so
I have to ask you guys, what is the reason for setting mtd->erasesize to
the *maximum* erase sector size?

I'd appreciate any ideas on the above, maybe I can convert them to a patch.

Or should mtdpart.c be updated to handle non-uniform erase regions?
But they seem to be spi-nor.c-specific currently...

-- 
Best regards,
Alexander Sverdlin.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories
  2018-11-13 16:58 [RFC] mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories Sverdlin, Alexander (Nokia - DE/Ulm)
@ 2018-11-14  8:00 ` Tudor.Ambarus
  2018-11-14  9:10   ` Boris Brezillon
  2018-11-15 10:46   ` Boris Brezillon
  0 siblings, 2 replies; 6+ messages in thread
From: Tudor.Ambarus @ 2018-11-14  8:00 UTC (permalink / raw)
  To: alexander.sverdlin, linux-mtd, marek.vasut, dwmw2,
	computersforpeace, boris.brezillon, richard, Cristian.Birsan

Hi, Alexander,

On 11/13/2018 06:58 PM, Sverdlin, Alexander (Nokia - DE/Ulm) wrote:
> Hello Tudor and all,
> 
> first of all, thank you for your work on SFDP support in Linux!
> 
> Unfortunately, I'm debugging a regression caused by 5390a8df769ec
> "mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories"
> in [out of tree] support for S25FS128S.
> 
> The culprit is the following part of your patch:
> 
> 	/*
> 	 * For non-uniform SPI flash memory, set mtd->erasesize to the
> 	 * maximum erase sector size. No need to set nor->erase_opcode.
> 	 */
> 	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
> 		if (map->erase_type[i].size) {
> 			erase = &map->erase_type[i];
> 			break;
> 		}
> 	}
> 
> The problem in our case is, we have existing partitioning with 128k partitions
> (the Flash itself supports 256k and 64k erasesize, depending on configuration).
> The chip is configured for 64k erasesize, non-uniform mapping.
> 
> The mapping itself is being detected correctly, but when it comes to the code
> snippet above, it selects the biggest erasesize from all sizes advertised in
> SFDP, including 256k, which is not applicable to the current configuration.

The fix would be to save the supported erase types when parsing the SFDP SMPT
table and use those instead.

> 
> Finally when mtd registers the partitions, they are forced read-only:
> 
> 	partition "..." doesn't start on an erase block boundary -- force read-only
> 
> So this change is not backwards compatible to the existing partitionings.

Maybe you have a partition that is not divisible by 256k?

> 
> I cannot come with the justification for the above decision myself, so
> I have to ask you guys, what is the reason for setting mtd->erasesize to
> the *maximum* erase sector size?

"Major" _valid_ erase sector size. It's an API requirement described at the
mtd_info struct definition. I guess it's for performance reasons. You would like
to use the biggest valid erase commands instead of multiple smaller. Also, one
might require the erase starting address to be aligned with major erase size,
for performance reasons as well.

Cheers,
ta

> 
> I'd appreciate any ideas on the above, maybe I can convert them to a patch.
> 
> Or should mtdpart.c be updated to handle non-uniform erase regions?
> But they seem to be spi-nor.c-specific currently...
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories
  2018-11-14  8:00 ` Tudor.Ambarus
@ 2018-11-14  9:10   ` Boris Brezillon
  2018-11-15 10:46   ` Boris Brezillon
  1 sibling, 0 replies; 6+ messages in thread
From: Boris Brezillon @ 2018-11-14  9:10 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: alexander.sverdlin, linux-mtd, marek.vasut, dwmw2,
	computersforpeace, richard, Cristian.Birsan

On Wed, 14 Nov 2018 08:00:44 +0000
<Tudor.Ambarus@microchip.com> wrote:

> Hi, Alexander,
> 
> On 11/13/2018 06:58 PM, Sverdlin, Alexander (Nokia - DE/Ulm) wrote:
> > Hello Tudor and all,
> > 
> > first of all, thank you for your work on SFDP support in Linux!
> > 
> > Unfortunately, I'm debugging a regression caused by 5390a8df769ec
> > "mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories"
> > in [out of tree] support for S25FS128S.
> > 
> > The culprit is the following part of your patch:
> > 
> > 	/*
> > 	 * For non-uniform SPI flash memory, set mtd->erasesize to the
> > 	 * maximum erase sector size. No need to set nor->erase_opcode.
> > 	 */
> > 	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
> > 		if (map->erase_type[i].size) {
> > 			erase = &map->erase_type[i];
> > 			break;
> > 		}
> > 	}
> > 
> > The problem in our case is, we have existing partitioning with 128k partitions
> > (the Flash itself supports 256k and 64k erasesize, depending on configuration).
> > The chip is configured for 64k erasesize, non-uniform mapping.
> > 
> > The mapping itself is being detected correctly, but when it comes to the code
> > snippet above, it selects the biggest erasesize from all sizes advertised in
> > SFDP, including 256k, which is not applicable to the current configuration.  
> 
> The fix would be to save the supported erase types when parsing the SFDP SMPT
> table and use those instead.
> 
> > 
> > Finally when mtd registers the partitions, they are forced read-only:
> > 
> > 	partition "..." doesn't start on an erase block boundary -- force read-only
> > 
> > So this change is not backwards compatible to the existing partitionings.  
> 
> Maybe you have a partition that is not divisible by 256k?

Yes, but apparently it was working before the non-uniform erase
changes, so this is a regression. And I fear this is not the only thing
that breaks when mtd->erasesize changes: UBI relies on mtd->erasesize
to figure out its LEB/PEB size, so exiting UBI partitions won't work
anymore on this flash.

> 
> > 
> > I cannot come with the justification for the above decision myself, so
> > I have to ask you guys, what is the reason for setting mtd->erasesize to
> > the *maximum* erase sector size?  
> 
> "Major" _valid_ erase sector size. It's an API requirement described at the
> mtd_info struct definition. I guess it's for performance reasons. You would like
> to use the biggest valid erase commands instead of multiple smaller. Also, one
> might require the erase starting address to be aligned with major erase size,
> for performance reasons as well.

I don't think this is related to perfs (at least not only), it's just
that some flashes have different erase size across the device, and some
MTD users don't want to deal with that, so instead, they use the
biggest erase size assuming this biggest erasesize is a multiple of the
smaller ones and will always work. That's typically what UBI does.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories
  2018-11-14  8:00 ` Tudor.Ambarus
  2018-11-14  9:10   ` Boris Brezillon
@ 2018-11-15 10:46   ` Boris Brezillon
  2018-11-15 11:36     ` Sverdlin, Alexander (Nokia - DE/Ulm)
  2018-11-16 11:43     ` Tudor.Ambarus
  1 sibling, 2 replies; 6+ messages in thread
From: Boris Brezillon @ 2018-11-15 10:46 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: alexander.sverdlin, linux-mtd, marek.vasut, dwmw2,
	computersforpeace, richard, Cristian.Birsan

On Wed, 14 Nov 2018 08:00:44 +0000
<Tudor.Ambarus@microchip.com> wrote:

> Hi, Alexander,
> 
> On 11/13/2018 06:58 PM, Sverdlin, Alexander (Nokia - DE/Ulm) wrote:
> > Hello Tudor and all,
> > 
> > first of all, thank you for your work on SFDP support in Linux!
> > 
> > Unfortunately, I'm debugging a regression caused by 5390a8df769ec
> > "mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories"
> > in [out of tree] support for S25FS128S.
> > 
> > The culprit is the following part of your patch:
> > 
> > 	/*
> > 	 * For non-uniform SPI flash memory, set mtd->erasesize to the
> > 	 * maximum erase sector size. No need to set nor->erase_opcode.
> > 	 */
> > 	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
> > 		if (map->erase_type[i].size) {
> > 			erase = &map->erase_type[i];
> > 			break;
> > 		}
> > 	}
> > 
> > The problem in our case is, we have existing partitioning with 128k partitions
> > (the Flash itself supports 256k and 64k erasesize, depending on configuration).
> > The chip is configured for 64k erasesize, non-uniform mapping.
> > 
> > The mapping itself is being detected correctly, but when it comes to the code
> > snippet above, it selects the biggest erasesize from all sizes advertised in
> > SFDP, including 256k, which is not applicable to the current configuration.  
> 
> The fix would be to save the supported erase types when parsing the SFDP SMPT
> table and use those instead.

Alexander, Tudor, can one of you work on such a fix?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories
  2018-11-15 10:46   ` Boris Brezillon
@ 2018-11-15 11:36     ` Sverdlin, Alexander (Nokia - DE/Ulm)
  2018-11-16 11:43     ` Tudor.Ambarus
  1 sibling, 0 replies; 6+ messages in thread
From: Sverdlin, Alexander (Nokia - DE/Ulm) @ 2018-11-15 11:36 UTC (permalink / raw)
  To: Boris Brezillon, Tudor.Ambarus
  Cc: linux-mtd, marek.vasut, dwmw2, computersforpeace, richard,
	Cristian.Birsan

Hello Boris,

On 15/11/2018 11:46, Boris Brezillon wrote:
>>> 	/*
>>> 	 * For non-uniform SPI flash memory, set mtd->erasesize to the
>>> 	 * maximum erase sector size. No need to set nor->erase_opcode.
>>> 	 */
>>> 	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
>>> 		if (map->erase_type[i].size) {
>>> 			erase = &map->erase_type[i];
>>> 			break;
>>> 		}
>>> 	}
>>>
>>> The problem in our case is, we have existing partitioning with 128k partitions
>>> (the Flash itself supports 256k and 64k erasesize, depending on configuration).
>>> The chip is configured for 64k erasesize, non-uniform mapping.
>>>
>>> The mapping itself is being detected correctly, but when it comes to the code
>>> snippet above, it selects the biggest erasesize from all sizes advertised in
>>> SFDP, including 256k, which is not applicable to the current configuration.  
>> The fix would be to save the supported erase types when parsing the SFDP SMPT
>> table and use those instead.
> Alexander, Tudor, can one of you work on such a fix?

non-uniform case is complicated because currently I don't see the way to tell
mtdpart.c about non-uniform maps from spi-nor.c.

But same problem applies even to uniform maps, I have a patch already which
searches for minimum erase size, not maximum, I just have not tested it...

-- 
Best regards,
Alexander Sverdlin.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories
  2018-11-15 10:46   ` Boris Brezillon
  2018-11-15 11:36     ` Sverdlin, Alexander (Nokia - DE/Ulm)
@ 2018-11-16 11:43     ` Tudor.Ambarus
  1 sibling, 0 replies; 6+ messages in thread
From: Tudor.Ambarus @ 2018-11-16 11:43 UTC (permalink / raw)
  To: boris.brezillon
  Cc: alexander.sverdlin, linux-mtd, marek.vasut, dwmw2,
	computersforpeace, richard, Cristian.Birsan



On 11/15/2018 12:46 PM, Boris Brezillon wrote:
>> The fix would be to save the supported erase types when parsing the SFDP SMPT
>> table and use those instead.
> 
> Alexander, Tudor, can one of you work on such a fix?

I will fix it, probably next week.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-11-16 11:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-13 16:58 [RFC] mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories Sverdlin, Alexander (Nokia - DE/Ulm)
2018-11-14  8:00 ` Tudor.Ambarus
2018-11-14  9:10   ` Boris Brezillon
2018-11-15 10:46   ` Boris Brezillon
2018-11-15 11:36     ` Sverdlin, Alexander (Nokia - DE/Ulm)
2018-11-16 11:43     ` Tudor.Ambarus

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.