* [U-Boot] [PATCH v3 0/3] mtd: nand: mxs: Calculate ECC strength dynamically
@ 2015-04-15 7:27 Jörg Krause
2015-04-15 7:27 ` [U-Boot] [PATCH v3 1/3] mtd:mxs:nand calculate ecc " Jörg Krause
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Jörg Krause @ 2015-04-15 7:27 UTC (permalink / raw)
To: u-boot
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(-)
--
2.3.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH v3 1/3] mtd:mxs:nand calculate ecc strength dynamically
2015-04-15 7:27 [U-Boot] [PATCH v3 0/3] mtd: nand: mxs: Calculate ECC strength dynamically Jörg Krause
@ 2015-04-15 7:27 ` Jörg Krause
2015-04-15 7:27 ` [U-Boot] [PATCH v3 2/3] mtd: nand: mxs: Replace magic number for bits per ECC level with macro Jörg Krause
2015-04-15 7:27 ` [U-Boot] [PATCH v3 3/3] tools: mxsboot: Calculate ECC strength dynamically Jörg Krause
2 siblings, 0 replies; 6+ messages in thread
From: Jörg Krause @ 2015-04-15 7:27 UTC (permalink / raw)
To: u-boot
From: Peng Fan <Peng.Fan@freescale.com>
Calculate ecc strength according oobsize, but not hardcoded
which is not aligned with kernel driver
Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
Signed-off-by: Ye.Li <b37916@freescale.com>
Reviewed-by: Marek Vasut <marex@denx.de>
Signed-off-by: J?rg Krause <joerg.krause@embedded.rocks>
---
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(-)
diff --git a/drivers/mtd/nand/mxs_nand.c b/drivers/mtd/nand/mxs_nand.c
index 7a064ab..a463de7 100644
--- a/drivers/mtd/nand/mxs_nand.c
+++ b/drivers/mtd/nand/mxs_nand.c
@@ -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,
--
2.3.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH v3 2/3] mtd: nand: mxs: Replace magic number for bits per ECC level with macro
2015-04-15 7:27 [U-Boot] [PATCH v3 0/3] mtd: nand: mxs: Calculate ECC strength dynamically Jörg Krause
2015-04-15 7:27 ` [U-Boot] [PATCH v3 1/3] mtd:mxs:nand calculate ecc " Jörg Krause
@ 2015-04-15 7:27 ` Jörg Krause
2015-04-16 20:18 ` Marek Vasut
2015-04-15 7:27 ` [U-Boot] [PATCH v3 3/3] tools: mxsboot: Calculate ECC strength dynamically Jörg Krause
2 siblings, 1 reply; 6+ messages in thread
From: Jörg Krause @ 2015-04-15 7:27 UTC (permalink / raw)
To: u-boot
Signed-off-by: J?rg Krause <joerg.krause@embedded.rocks>
---
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(-)
diff --git a/drivers/mtd/nand/mxs_nand.c b/drivers/mtd/nand/mxs_nand.c
index a463de7..aa06446 100644
--- a/drivers/mtd/nand/mxs_nand.c
+++ b/drivers/mtd/nand/mxs_nand.c
@@ -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);
}
diff --git a/tools/mxsboot.c b/tools/mxsboot.c
index 6d48cfb..aaa872b 100644
--- a/tools/mxsboot.c
+++ b/tools/mxsboot.c
@@ -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 32
struct 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,
--
2.3.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH v3 3/3] tools: mxsboot: Calculate ECC strength dynamically
2015-04-15 7:27 [U-Boot] [PATCH v3 0/3] mtd: nand: mxs: Calculate ECC strength dynamically Jörg Krause
2015-04-15 7:27 ` [U-Boot] [PATCH v3 1/3] mtd:mxs:nand calculate ecc " Jörg Krause
2015-04-15 7:27 ` [U-Boot] [PATCH v3 2/3] mtd: nand: mxs: Replace magic number for bits per ECC level with macro Jörg Krause
@ 2015-04-15 7:27 ` Jörg Krause
2015-04-16 20:19 ` Marek Vasut
2 siblings, 1 reply; 6+ messages in thread
From: Jörg Krause @ 2015-04-15 7:27 UTC (permalink / raw)
To: u-boot
Calculating the ECC strength dynamically to be aligned with the mxs NAND
driver and the Linux Kernel.
Signed-off-by: J?rg Krause <joerg.krause@embedded.rocks>
---
Changes for v3:
- Coding Style cleanup
Changes for v2:
- New patch
---
tools/mxsboot.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/tools/mxsboot.c b/tools/mxsboot.c
index aaa872b..53de452 100644
--- a/tools/mxsboot.c
+++ b/tools/mxsboot.c
@@ -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,
--
2.3.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH v3 2/3] mtd: nand: mxs: Replace magic number for bits per ECC level with macro
2015-04-15 7:27 ` [U-Boot] [PATCH v3 2/3] mtd: nand: mxs: Replace magic number for bits per ECC level with macro Jörg Krause
@ 2015-04-16 20:18 ` Marek Vasut
0 siblings, 0 replies; 6+ messages in thread
From: Marek Vasut @ 2015-04-16 20:18 UTC (permalink / raw)
To: u-boot
On Wednesday, April 15, 2015 at 09:27:22 AM, J?rg Krause wrote:
> Signed-off-by: J?rg Krause <joerg.krause@embedded.rocks>
> ---
> Changes for v3:
> - Replace space with tab for macro definition
> Changes for v2:
> - New patch
> ---
Reviewed-by: Marek Vasut <marex@denx.de>
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH v3 3/3] tools: mxsboot: Calculate ECC strength dynamically
2015-04-15 7:27 ` [U-Boot] [PATCH v3 3/3] tools: mxsboot: Calculate ECC strength dynamically Jörg Krause
@ 2015-04-16 20:19 ` Marek Vasut
0 siblings, 0 replies; 6+ messages in thread
From: Marek Vasut @ 2015-04-16 20:19 UTC (permalink / raw)
To: u-boot
On Wednesday, April 15, 2015 at 09:27:23 AM, J?rg Krause wrote:
> Calculating the ECC strength dynamically to be aligned with the mxs NAND
> driver and the Linux Kernel.
>
> Signed-off-by: J?rg Krause <joerg.krause@embedded.rocks>
Reviewed-by: Marek Vasut <marex@denx.de>
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-04-16 20:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-15 7:27 [U-Boot] [PATCH v3 0/3] mtd: nand: mxs: Calculate ECC strength dynamically Jörg Krause
2015-04-15 7:27 ` [U-Boot] [PATCH v3 1/3] mtd:mxs:nand calculate ecc " Jörg Krause
2015-04-15 7:27 ` [U-Boot] [PATCH v3 2/3] mtd: nand: mxs: Replace magic number for bits per ECC level with macro Jörg Krause
2015-04-16 20:18 ` Marek Vasut
2015-04-15 7:27 ` [U-Boot] [PATCH v3 3/3] tools: mxsboot: Calculate ECC strength dynamically Jörg Krause
2015-04-16 20:19 ` Marek Vasut
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox