mtd: spi: Add SYS_SPI_BLOCK_SIZE to Kconfig
PATCH 1/2 mtd: spi: Add SYS_SPI_BLOCK_SIZE to Kconfig
From: Tien Fong Chee <[email protected]>
Different SPI flash has different block erase size configuration, it can be configured as block erase size or sub-block erase size, so SYS_SPI_BLOCK_SIZE is created to provide UBI a consistent block reading. UBI block reading would be eventually translated to offset access into SPI regardless how the block erase size is configured on SPI. This would made the UBI transparent from SPI layer.
--- drivers/mtd/spi/Kconfig | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/mtd/spi/Kconfig +7 -0
@@ -196,4 +196,11 @@ config SPI_FLASH_MTD If unsure, say N +config SYS_SPI_BLOCK_SIZE + hex "SPI chip eraseblock size for UBI reading" + depends on SPL_SPI_FLASH_SUPPORT + default 65536 + help + Number of data bytes in a physical eraseblock for UBI reading. + endmenu # menu "SPI Flash Support"
Signature · 1 line
2.13.0
PATCH 2/2 drivers: ubi: Adding UBI loader for SPI flash
From: Tien Fong Chee <[email protected]>
Adding UBI support for SPI flash.
--- common/spl/spl_ubi.c | 11 ++++++++++- drivers/mtd/spi/sf-uclass.c | 30 ++++++++++++++++++++++++++++++ include/spi_flash.h | 10 ++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-)
common/spl/spl_ubi.c +10 -1
@@ -9,6 +9,8 @@#include <nand.h> #include <onenand_uboot.h> #include <ubispl.h> +#include <spi.h> +#include <spi_flash.h> #include <spl.h> int spl_ubi_load_image(struct spl_image_info *spl_image,
@@ -33,6 +35,12 @@ int spl_ubi_load_image(struct spl_image_info *spl_image, info.peb_size =CONFIG_SYS_ONENAND_BLOCK_SIZE ;break ;#endif +#ifdef CONFIG_SPL_SPI_FLASH_SUPPORT +case BOOT_DEVICE_SPI : + info.read = spi_flash_read_block; + info.peb_size =CONFIG_SYS_SPI_BLOCK_SIZE ; +break ; +#endif default : goto out; }
@@ -82,6 +90,7 @@ out:#endif return ret; } -/* Use priorty 0 so that Ubi will override NAND and ONENAND methods */ +/* Use priorty 0 so that Ubi will override SPI, NAND and ONENAND methods */ +SPL_LOAD_IMAGE_METHOD ("SPI" ,0 ,BOOT_DEVICE_SPI , spl_ubi_load_image);SPL_LOAD_IMAGE_METHOD ("NAND" ,0 ,BOOT_DEVICE_NAND , spl_ubi_load_image);SPL_LOAD_IMAGE_METHOD ("OneNAND" ,0 ,BOOT_DEVICE_ONENAND , spl_ubi_load_image);
drivers/mtd/spi/sf-uclass.c +30 -0
@@ -12,6 +12,36 @@DECLARE_GLOBAL_DATA_PTR ; +/** +* spi_flash_read_block - Read data from physical eraseblock into a buffer +* @block: Number of the physical eraseblock +* @offset: Data offset from the start of @peb +* @len: Data size to read +* @buf: Address of the destination buffer +* @return 0 if OK, -ve on error +*/ +int spi_flash_read_block (int block,int offset,int len,void *buf) +{ +struct udevice *dev; + +int ret =spi_flash_probe_bus_cs (CONFIG_SF_DEFAULT_BUS , +CONFIG_SF_DEFAULT_CS , +CONFIG_SF_DEFAULT_SPEED , +CONFIG_SF_DEFAULT_MODE , &dev); +if (ret) { +printf ("Failed to initialize SPI flash at " ); +printf ("%u:%u (error %d)\n" ,CONFIG_SF_DEFAULT_BUS , +CONFIG_SF_DEFAULT_CS , ret); +return ret; + } + +dev_get_uclass_priv (dev); + +return log_ret (sf_get_ops (dev)->read (dev, +CONFIG_SYS_SPI_BLOCK_SIZE * + block + offset, len, buf)); +} +int spi_flash_read_dm (struct udevice *dev,u32 offset,size_t len,void *buf) {return log_ret (sf_get_ops (dev)->read (dev, offset, len, buf));
include/spi_flash.h +10 -0
@@ -102,6 +102,16 @@ int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len);*/ int spl_flash_get_sw_write_prot (struct udevice *dev); +/** +* spi_flash_read_block - Read data from physical eraseblock into a buffer +* @block: Number of the physical eraseblock +* @offset: Data offset from the start of @peb +* @len: Data size to read +* @buf: Address of the destination buffer +* @return 0 if OK, -ve on error +*/ +int spi_flash_read_block (int block,int offset,int len,void *dst); +int spi_flash_probe_bus_cs (unsigned int busnum,unsigned int cs,unsigned int max_hz,unsigned int spi_mode,struct udevice **devp);
Signature · 1 line
2.13.0
Chee
PATCH 2/2 drivers: ubi: Adding UBI loader for SPI flash
common/spl/spl_ubi.c
Quoted 15 lines · tien.fong.chee at intel.com
From: Tien Fong Chee <[email protected]>
Adding UBI support for SPI flash.
Signed-off-by Tien Fong Chee <[email protected]>---
common/spl/spl_ubi.c | 11 ++++++++++-drivers/mtd/spi/sf-uclass.c| 30 ++++++++++++++++++++++++++++++ include/spi_flash.h | 10 ++++++++++3 files changed, 50 insertions(+), 1 deletion(-)common/spl/spl_ubi.c +0
-0
[...]
Any comment?
THanks.
Chee
PATCH 1/2 mtd: spi: Add SYS_SPI_BLOCK_SIZE to Kconfig
In reply to tien.fong.chee at intel.comQuoted 31 lines · tien.fong.chee at intel.com
From: Tien Fong Chee <[email protected]>
Different SPI flash has different block erase size configuration, it can
be configured as block erase size or sub-block erase size, soSYS_SPI_BLOCK_SIZEis created to provide UBI a consistent block reading.
UBI block reading would be eventually translated to offset access into SPI regardless how the block erase size is configured on SPI.
This would made the UBI transparent from SPI layer.Signed-off-by Tien Fong Chee <[email protected]>---
drivers/mtd/spi/Kconfig | 7 +++++++1 file changed, 7 insertions(+)drivers/mtd/spi/Kconfig +0
-0@@ -196,4 +196,11 @@ config SPI_FLASH_MTD
If unsure, say Ndrivers/mtd/spi/Kconfig +6
-0+config SYS_SPI_BLOCK_SIZE + hex "SPI chip eraseblock size for UBI reading" + depends on SPL_SPI_FLASH_SUPPORT + default 65536 + help + Number of data bytes in a physical eraseblock for UBI
Quoted 3 lines
reading.
+
endmenu # menu "SPI Flash Support"
Any comment?
Thanks.
PATCH 1/2 mtd: spi: Add SYS_SPI_BLOCK_SIZE to Kconfig
Quoted 29 lines · Tien Fong
Quoted 28 lines · tien.fong.chee at intel.com
From: Tien Fong Chee <[email protected]>
Different SPI flash has different block erase size configuration, it can
be configured as block erase size or sub-block erase size, soSYS_SPI_BLOCK_SIZEis created to provide UBI a consistent block reading.
UBI block reading would be eventually translated to offset access into SPI regardless how the block erase size is configured on SPI.
This would made the UBI transparent from SPI layer.Signed-off-by Tien Fong Chee <[email protected]>---
drivers/mtd/spi/Kconfig | 7 +++++++1 file changed, 7 insertions(+)drivers/mtd/spi/Kconfig +0
-0@@ -196,4 +196,11 @@ config SPI_FLASH_MTD
If unsure, say Ndrivers/mtd/spi/Kconfig +3
-0+config SYS_SPI_BLOCK_SIZE + hex "SPI chip eraseblock size for UBI reading" + depends on SPL_SPI_FLASH_SUPPORT
Quoted 8 lines
Quoted 6 lines
drivers/mtd/spi/Kconfig +3
-0+ default 65536 + help + Number of data bytes in a physical eraseblock for UBIreading.
+
endmenu # menu "SPI Flash Support"Any comment?
UBI is able to obtain underlying media erase block size from the MTD subsystem, just let it do that. Besides, any such compile-time config would fail the next time you change the SPI NOR (e.g. because it's EOL), as that would force you to rebuild U-Boot, which might ultimately not be possible.
Chee
PATCH 1/2 mtd: spi: Add SYS_SPI_BLOCK_SIZE to Kconfig
Quoted 41 lines · Marek Vasut
Quoted 32 lines · Tien Fong
Quoted 30 lines · tien.fong.chee at intel.com
From: Tien Fong Chee <[email protected]>
Different SPI flash has different block erase size configuration, it
can
be configured as block erase size or sub-block erase size, soSYS_SPI_BLOCK_SIZEis created to provide UBI a consistent block reading.
UBI block reading would be eventually translated to offset access into SPI regardless how the block erase size is configured on
SPI.
This would made the UBI transparent from SPI layer.Signed-off-by Tien Fong Chee <[email protected]>---
drivers/mtd/spi/Kconfig | 7 +++++++1 file changed, 7 insertions(+)drivers/mtd/spi/Kconfig +0
-0@@ -196,4 +196,11 @@ config SPI_FLASH_MTD
If unsure, say Ndrivers/mtd/spi/Kconfig +2
-0+config SYS_SPI_BLOCK_SIZE + hex "SPI chip eraseblock size for UBI reading"Quoted 8 lines
Quoted 7 lines
drivers/mtd/spi/Kconfig +4
-0+ depends on SPL_SPI_FLASH_SUPPORT + default 65536 + help + Number of data bytes in a physical eraseblock for UBIreading.
+
endmenu # menu "SPI Flash Support"Any comment?
Quoted 7 lines
UBI is able to obtain underlying media erase block size from the MTD subsystem, just let it do that. Besides, any such compile-time config would fail the next time you change the SPI NOR (e.g. because it's EOL),
as that would force you to rebuild U-Boot, which might ultimately not be
possible.
Okay, let me check how to get this info from MTD. If you have some ideas, you can let me know too :) .
PATCH 1/2 mtd: spi: Add SYS_SPI_BLOCK_SIZE to Kconfig
Quoted 50 lines · Tien Fong
Quoted 41 lines · Marek Vasut
Quoted 32 lines · Tien Fong
Quoted 30 lines · tien.fong.chee at intel.com
From: Tien Fong Chee <[email protected]>
Different SPI flash has different block erase size configuration, it
can
be configured as block erase size or sub-block erase size, soSYS_SPI_BLOCK_SIZEis created to provide UBI a consistent block reading.
UBI block reading would be eventually translated to offset access into SPI regardless how the block erase size is configured on
SPI.
This would made the UBI transparent from SPI layer.Signed-off-by Tien Fong Chee <[email protected]>---
drivers/mtd/spi/Kconfig | 7 +++++++1 file changed, 7 insertions(+)drivers/mtd/spi/Kconfig +0
-0@@ -196,4 +196,11 @@ config SPI_FLASH_MTD
If unsure, say Ndrivers/mtd/spi/Kconfig +2
-0+config SYS_SPI_BLOCK_SIZE + hex "SPI chip eraseblock size for UBI reading"Quoted 8 lines
Quoted 7 lines
drivers/mtd/spi/Kconfig +4
-0+ depends on SPL_SPI_FLASH_SUPPORT + default 65536 + help + Number of data bytes in a physical eraseblock for UBIreading.
+
endmenu # menu "SPI Flash Support"Any comment?
Quoted 7 lines
UBI is able to obtain underlying media erase block size from the MTD subsystem, just let it do that. Besides, any such compile-time config would fail the next time you change the SPI NOR (e.g. because it's EOL),
as that would force you to rebuild U-Boot, which might ultimately not be
possible.
Quoted 2 lines
Okay, let me check how to get this info from MTD. If you have some ideas, you can let me know too :) .
It should all be there already, since you can already attach UBI on SPI NOR from U-Boot.