mtd: nand: mxs: Calculate ECC strength dynamically
Subsystems (3)
v3 cover mtd: nand: mxs: Calculate ECC strength dynamically
This patchset is based on the patch from Peng Fan:
"[U-Boot,1/2] mtd:mxs:nand calculate ecc strength dynamically"
https://patchwork.ozlabs.org/patch/422756/
Instead of hard-coding every possible oob size / ECC strength combination calculate the ECC strength dynamically to be aligned with the Linux Kernel MTD NAND driver. Also adds the calculation to tools/mxsboot to be aligned with the U-Boot MTD NAND driver.
J?rg Krause (2):
mtd: nand: mxs: Replace magic number for bits per ECC level with macro
tools: mxsboot: Calculate ECC strength dynamically
Peng Fan (1):
mtd:mxs:nand calculate ecc strength dynamically
drivers/mtd/nand/mxs_nand.c | 35 +++++++++++++++-------------------- tools/mxsboot.c | 39 ++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 35 deletions(-)
Signature · 1 line
2.3.5
PATCH v3 1/3 mtd:mxs:nand calculate ecc strength dynamically
From: Peng Fan <[email protected]>
Calculate ecc strength according oobsize, but not hardcoded which is not aligned with kernel driver
---
Changes for v3:
- squashed "[U-Boot,v2,3/4] mtd: nand: mxs: Add comment for calculating
ECC strength"
https://patchwork.ozlabs.org/patch/460926/
- Coding Style cleanup
Changes for v2:
- None (original patch from Peng Fan)
---
drivers/mtd/nand/mxs_nand.c | 30 ++++++++++++------------------
1 file changed, 12 insertions(+), 18 deletions(-)drivers/mtd/nand/mxs_nand.c +12 -18
@@ -146,26 +146,20 @@ static uint32_t mxs_nand_aux_status_offset(void)static inline uint32_t mxs_nand_get_ecc_strength (uint32_t page_data_size,uint32_t page_oob_size) { -if (page_data_size ==2048 ) { -if (page_oob_size ==64 ) -return 8 ; +int ecc_strength; -if (page_oob_size ==112 ) -return 14 ; - } - -if (page_data_size ==4096 ) { -if (page_oob_size ==128 ) -return 8 ; - -if (page_oob_size ==218 ) -return 16 ; - -if (page_oob_size ==224 ) -return 16 ; - } +/* +* Determine the ECC layout with the formula: +* ECC bits per chunk = (total page spare data bits) / +* (bits per ECC level) / (chunks per page) +* where: +* total page spare data bits = +* (page oob size - meta data size) * (bits per byte) +*/ + ecc_strength = ((page_oob_size -MXS_NAND_METADATA_SIZE ) *8 ) + / (13 *mxs_nand_ecc_chunk_cnt (page_data_size)); -return 0 ; +return round_down (ecc_strength,2 ); } static inline uint32_t mxs_nand_get_mark_offset(uint32_t page_data_size,
Signature · 1 line
2.3.5
PATCH v3 2/3 mtd: nand: mxs: Replace magic number for bits per ECC level with macro
In reply to Jörg Krause---
Changes for v3:
- Replace space with tab for macro definition
Changes for v2:
- New patch
--- drivers/mtd/nand/mxs_nand.c | 7 ++++--- tools/mxsboot.c | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/mtd/nand/mxs_nand.c +4 -3
@@ -36,7 +36,7 @@#define MXS_NAND_CHUNK_DATA_CHUNK_SIZE_SHIFT 0#endif #define MXS_NAND_METADATA_SIZE 10 - +#define MXS_NAND_BITS_PER_ECC_LEVEL 13#define MXS_NAND_COMMAND_BUFFER_SIZE 32#define MXS_NAND_BCH_TIMEOUT 10000
@@ -135,7 +135,7 @@ static uint32_t mxs_nand_ecc_chunk_cnt(uint32_t page_data_size)static uint32_t mxs_nand_ecc_size_in_bits (uint32_t ecc_strength) { -return ecc_strength *13 ; +return ecc_strength *MXS_NAND_BITS_PER_ECC_LEVEL ; }static uint32_t mxs_nand_aux_status_offset (void )
@@ -157,7 +157,8 @@ static inline uint32_t mxs_nand_get_ecc_strength(uint32_t page_data_size,* (page oob size - meta data size) * (bits per byte) */ ecc_strength = ((page_oob_size -MXS_NAND_METADATA_SIZE ) *8 ) - / (13 *mxs_nand_ecc_chunk_cnt (page_data_size)); + / (MXS_NAND_BITS_PER_ECC_LEVEL * +mxs_nand_ecc_chunk_cnt (page_data_size));return round_down (ecc_strength,2 ); }
tools/mxsboot.c +2 -1
@@ -48,6 +48,7 @@ static uint32_t sd_sector = 2048;#define MXS_NAND_DMA_DESCRIPTOR_COUNT 4#define MXS_NAND_CHUNK_DATA_CHUNK_SIZE 512#define MXS_NAND_METADATA_SIZE 10 +#define MXS_NAND_BITS_PER_ECC_LEVEL 13#define MXS_NAND_COMMAND_BUFFER_SIZE 32struct mx28_nand_fcb {
@@ -127,7 +128,7 @@ struct mx28_sd_config_block {static inline uint32_t mx28_nand_ecc_size_in_bits (uint32_t ecc_strength) { -return ecc_strength *13 ; +return ecc_strength *MXS_NAND_BITS_PER_ECC_LEVEL ; } static inline uint32_t mx28_nand_get_ecc_strength(uint32_t page_data_size,
Signature · 1 line
2.3.5
PATCH v3 2/3 mtd: nand: mxs: Replace magic number for bits per ECC level with macro
Quoted 7 lines · J?rg Krause
Signed-off-by J?rg Krause <[email protected]>---
Changes for v3:
- Replace space with tab for macro definition
Changes for v2:
- New patch
---
Best regards,
Marek Vasut
PATCH v3 3/3 tools: mxsboot: Calculate ECC strength dynamically
In reply to Jörg KrauseCalculating the ECC strength dynamically to be aligned with the mxs NAND driver and the Linux Kernel.
---
Changes for v3:
- Coding Style cleanup
Changes for v2:
- New patch
--- tools/mxsboot.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-)
tools/mxsboot.c +22 -13
@@ -14,6 +14,10 @@#include "compiler.h" +/* Taken from <linux/kernel.h> */ +#define __round_mask (x, y) ((__typeof__(x))((y)-1)) +#define round_down (x, y) ((x) & ~__round_mask(x, y)) +/* * Default BCB layout. *
@@ -126,6 +130,11 @@ struct mx28_sd_config_block {struct mx28_sd_drive_info drv_info[1 ]; }; +static inline uint32_t mx28_nand_ecc_chunk_cnt (uint32_t page_data_size) +{ +return page_data_size /MXS_NAND_CHUNK_DATA_CHUNK_SIZE ; +} +static inline uint32_t mx28_nand_ecc_size_in_bits (uint32_t ecc_strength) {return ecc_strength *MXS_NAND_BITS_PER_ECC_LEVEL ;
@@ -134,21 +143,21 @@ static inline uint32_t mx28_nand_ecc_size_in_bits(uint32_t ecc_strength)static inline uint32_t mx28_nand_get_ecc_strength (uint32_t page_data_size,uint32_t page_oob_size) { -if (page_data_size ==2048 ) -return 8 ; - -if (page_data_size ==4096 ) { -if (page_oob_size ==128 ) -return 8 ; +int ecc_strength; -if (page_oob_size ==218 ) -return 16 ; - -if (page_oob_size ==224 ) -return 16 ; - } +/* +* Determine the ECC layout with the formula: +* ECC bits per chunk = (total page spare data bits) / +* (bits per ECC level) / (chunks per page) +* where: +* total page spare data bits = +* (page oob size - meta data size) * (bits per byte) +*/ + ecc_strength = ((page_oob_size -MXS_NAND_METADATA_SIZE ) *8 ) + / (MXS_NAND_BITS_PER_ECC_LEVEL * +mx28_nand_ecc_chunk_cnt (page_data_size)); -return 0 ; +return round_down (ecc_strength,2 ); } static inline uint32_t mx28_nand_get_mark_offset(uint32_t page_data_size,
Signature · 1 line
2.3.5
PATCH v3 3/3 tools: mxsboot: Calculate ECC strength dynamically
Quoted 4 lines · J?rg Krause
Calculating the ECC strength dynamically to be aligned with the mxs NAND driver and the Linux Kernel.
Signed-off-by J?rg Krause <[email protected]>
Best regards,
Marek Vasut