470-mtd-spi-nor-support-limiting-4K-sectors-support-base.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Date: Sat, 4 Nov 2017 07:40:23 +0100
  3. Subject: [PATCH] mtd: spi-nor: support limiting 4K sectors support based on
  4. flash size
  5. Some devices need 4K sectors to be able to deal with small flash chips.
  6. For instance, w25x05 is 64 KiB in size, and without 4K sectors, the
  7. entire chip is just one erase block.
  8. On bigger flash chip sizes, using 4K sectors can significantly slow down
  9. many operations, including using a writable filesystem. There are several
  10. platforms where it makes sense to use a single kernel on both kinds of
  11. devices.
  12. To support this properly, allow configuring an upper flash chip size
  13. limit for 4K sectors support.
  14. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  15. ---
  16. --- a/drivers/mtd/spi-nor/Kconfig
  17. +++ b/drivers/mtd/spi-nor/Kconfig
  18. @@ -39,6 +39,17 @@ config SPI_ASPEED_SMC
  19. and support for the SPI flash memory controller (SPI) for
  20. the host firmware. The implementation only supports SPI NOR.
  21. +config MTD_SPI_NOR_USE_4K_SECTORS_LIMIT
  22. + int "Maximum flash chip size to use 4K sectors on (in KiB)"
  23. + depends on MTD_SPI_NOR_USE_4K_SECTORS
  24. + default "4096"
  25. + help
  26. + There are many flash chips that support 4K sectors, but are so large
  27. + that using them significantly slows down writing large amounts of
  28. + data or using a writable filesystem.
  29. + Any flash chip larger than the size specified in this option will
  30. + not use 4K sectors.
  31. +
  32. config SPI_ATMEL_QUADSPI
  33. tristate "Atmel Quad SPI Controller"
  34. depends on ARCH_AT91 || (ARM && COMPILE_TEST)
  35. --- a/drivers/mtd/spi-nor/spi-nor.c
  36. +++ b/drivers/mtd/spi-nor/spi-nor.c
  37. @@ -2561,10 +2561,12 @@ static int spi_nor_select_erase(struct s
  38. #ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
  39. /* prefer "small sector" erase if possible */
  40. - if (info->flags & SECT_4K) {
  41. + if ((info->flags & SECT_4K) && (mtd->size <=
  42. + CONFIG_MTD_SPI_NOR_USE_4K_SECTORS_LIMIT * 1024)) {
  43. nor->erase_opcode = SPINOR_OP_BE_4K;
  44. mtd->erasesize = 4096;
  45. - } else if (info->flags & SECT_4K_PMC) {
  46. + } else if ((info->flags & SECT_4K_PMC) && (mtd->size <=
  47. + CONFIG_MTD_SPI_NOR_USE_4K_SECTORS_LIMIT * 1024)) {
  48. nor->erase_opcode = SPINOR_OP_BE_4K_PMC;
  49. mtd->erasesize = 4096;
  50. } else