Skip to contentSkip to conversation

nand: Merge BCH code from Linux nand driver

PATCH New Hitz 4 participants 5 messages Oct 5, 2011 – Oct 7, 2011

Subsystems (3)
lore
Share & tools
lore

Hitz

#0 lore raw

PATCH 1/2 nand: Merge BCH code from Linux nand driver

This patch merges the BCH ECC algorithm from the 3.0 Linux kernel. This enables U-Boot to support modern NAND flash chips that require more than 1-bit of ECC in software.

---
 drivers/mtd/nand/Makefile    |    1 +
 drivers/mtd/nand/nand_base.c |   39 ++-
 drivers/mtd/nand/nand_bch.c  |  236 ++++++++
 drivers/mtd/nand/nand_ids.c  |   35 ++
 include/linux/bch.h          |   79 +++
 include/linux/mtd/nand.h     |   10 +-
 include/linux/mtd/nand_bch.h |   72 +++
 lib/Makefile                 |    1 +
 lib/bch.c                    | 1358 ++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 1823 insertions(+), 8 deletions(-)
 create mode 100644 drivers/mtd/nand/nand_bch.c
 create mode 100644 include/linux/bch.h
 create mode 100644 include/linux/mtd/nand_bch.h
 create mode 100644 lib/bch.c
drivers/mtd/nand/Makefile +1 -0
index dae2442..3781cc1 100644
@@ -38,6 +38,7 @@ COBJS-y += nand_util.o
 endif
 COBJS-y += nand_ecc.o
 COBJS-y += nand_base.o
+COBJS-$(CONFIG_NAND_ECC_BCH) += nand_bch.o
 
 COBJS-$(CONFIG_NAND_ATMEL) += atmel_nand.o
 COBJS-$(CONFIG_DRIVER_NAND_BFIN) += bfin_nand.o
drivers/mtd/nand/nand_base.c +38 -1
index 6aac6a2..8212319 100644
@@ -43,6 +43,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/nand_ecc.h>
+#include <linux/mtd/nand_bch.h>
 
 #ifdef CONFIG_MTD_PARTITIONS
 #include <linux/mtd/partitions.h>
@@ -2763,7 +2764,7 @@ int nand_scan_tail(struct mtd_info *mtd)
        /*
         * If no default placement scheme is given, select an appropriate one
         */
-       if (!chip->ecc.layout) {
+       if (!chip->ecc.layout && (chip->ecc.mode != NAND_ECC_SOFT_BCH)) {
                switch (mtd->oobsize) {
                case 8:
                        chip->ecc.layout = &nand_oob_8;
@@ -2864,6 +2865,39 @@ int nand_scan_tail(struct mtd_info *mtd)
                chip->ecc.bytes = 3;
                break;
 
+       case NAND_ECC_SOFT_BCH:
+               if (!mtd_nand_has_bch()) {
+                       printk(KERN_WARNING "CONFIG_MTD_ECC_BCH not enabled\n");
+                       BUG();
+               }
+               chip->ecc.calculate = nand_bch_calculate_ecc;
+               chip->ecc.correct = nand_bch_correct_data;
+               chip->ecc.read_page = nand_read_page_swecc;
+               chip->ecc.read_subpage = nand_read_subpage;
+               chip->ecc.write_page = nand_write_page_swecc;
+               chip->ecc.read_page_raw = nand_read_page_raw;
+               chip->ecc.write_page_raw = nand_write_page_raw;
+               chip->ecc.read_oob = nand_read_oob_std;
+               chip->ecc.write_oob = nand_write_oob_std;
+               /*
+                * Board driver should supply ecc.size and ecc.bytes values to
+                * select how many bits are correctable; see nand_bch_init()
+                * for details.
+                * Otherwise, default to 4 bits for large page devices
+                */
+               if (!chip->ecc.size && (mtd->oobsize >= 64)) {
+                       chip->ecc.size = 512;
+                       chip->ecc.bytes = 7;
+               }
+               chip->ecc.priv = nand_bch_init(mtd,
+                                              chip->ecc.size,
+                                              chip->ecc.bytes,
+                                              &chip->ecc.layout);
+               if (!chip->ecc.priv) {
+                       printk(KERN_WARNING "BCH ECC initialization failed!\n");
+               }
+               break;
+
        case NAND_ECC_NONE:
                printk(KERN_WARNING "NAND_ECC_NONE selected by board driver. "
                       "This is not recommended !!\n");
@@ -2989,6 +3023,9 @@ void nand_release(struct mtd_info *mtd)
 {
        struct nand_chip *chip = mtd->priv;
 
+       if (chip->ecc.mode == NAND_ECC_SOFT_BCH)
+               nand_bch_free((struct nand_bch_control *)chip->ecc.priv);
+
 #ifdef CONFIG_MTD_PARTITIONS
        /* Deregister partitions */
        del_mtd_partitions(mtd);
drivers/mtd/nand/nand_bch.c new file +236 -0

236 lines not on this page · raw message

drivers/mtd/nand/nand_ids.c +35 -0
index 8d7ea76..3953549 100644
@@ -76,9 +76,13 @@ const struct nand_flash_dev nand_flash_ids[] = {
 
        /*512 Megabit */
        {"NAND 64MiB 1,8V 8-bit",       0xA2, 0,  64, 0, LP_OPTIONS},
+       {"NAND 64MiB 1,8V 8-bit",       0xA0, 0,  64, 0, LP_OPTIONS},
        {"NAND 64MiB 3,3V 8-bit",       0xF2, 0,  64, 0, LP_OPTIONS},
+       {"NAND 64MiB 3,3V 8-bit",       0xD0, 0,  64, 0, LP_OPTIONS},
        {"NAND 64MiB 1,8V 16-bit",      0xB2, 0,  64, 0, LP_OPTIONS16},
+       {"NAND 64MiB 1,8V 16-bit",      0xB0, 0,  64, 0, LP_OPTIONS16},
        {"NAND 64MiB 3,3V 16-bit",      0xC2, 0,  64, 0, LP_OPTIONS16},
+       {"NAND 64MiB 3,3V 16-bit",      0xC0, 0,  64, 0, LP_OPTIONS16},
 
        /* 1 Gigabit */
        {"NAND 128MiB 1,8V 8-bit",      0xA1, 0, 128, 0, LP_OPTIONS},
@@ -86,6 +90,7 @@ const struct nand_flash_dev nand_flash_ids[] = {
        {"NAND 128MiB 3,3V 8-bit",      0xD1, 0, 128, 0, LP_OPTIONS},
        {"NAND 128MiB 1,8V 16-bit",     0xB1, 0, 128, 0, LP_OPTIONS16},
        {"NAND 128MiB 3,3V 16-bit",     0xC1, 0, 128, 0, LP_OPTIONS16},
+       {"NAND 128MiB 1,8V 16-bit",     0xAD, 0, 128, 0, LP_OPTIONS16},
 
        /* 2 Gigabit */
        {"NAND 256MiB 1,8V 8-bit",      0xAA, 0, 256, 0, LP_OPTIONS},
@@ -111,6 +116,36 @@ const struct nand_flash_dev nand_flash_ids[] = {
        {"NAND 2GiB 1,8V 16-bit",       0xB5, 0, 2048, 0, LP_OPTIONS16},
        {"NAND 2GiB 3,3V 16-bit",       0xC5, 0, 2048, 0, LP_OPTIONS16},
 
+       /* 32 Gigabit */
+       {"NAND 4GiB 1,8V 8-bit",        0xA7, 0, 4096, 0, LP_OPTIONS},
+       {"NAND 4GiB 3,3V 8-bit",        0xD7, 0, 4096, 0, LP_OPTIONS},
+       {"NAND 4GiB 1,8V 16-bit",       0xB7, 0, 4096, 0, LP_OPTIONS16},
+       {"NAND 4GiB 3,3V 16-bit",       0xC7, 0, 4096, 0, LP_OPTIONS16},
+
+       /* 64 Gigabit */
+       {"NAND 8GiB 1,8V 8-bit",        0xAE, 0, 8192, 0, LP_OPTIONS},
+       {"NAND 8GiB 3,3V 8-bit",        0xDE, 0, 8192, 0, LP_OPTIONS},
+       {"NAND 8GiB 1,8V 16-bit",       0xBE, 0, 8192, 0, LP_OPTIONS16},
+       {"NAND 8GiB 3,3V 16-bit",       0xCE, 0, 8192, 0, LP_OPTIONS16},
+
+       /* 128 Gigabit */
+       {"NAND 16GiB 1,8V 8-bit",       0x1A, 0, 16384, 0, LP_OPTIONS},
+       {"NAND 16GiB 3,3V 8-bit",       0x3A, 0, 16384, 0, LP_OPTIONS},
+       {"NAND 16GiB 1,8V 16-bit",      0x2A, 0, 16384, 0, LP_OPTIONS16},
+       {"NAND 16GiB 3,3V 16-bit",      0x4A, 0, 16384, 0, LP_OPTIONS16},
+
+       /* 256 Gigabit */
+       {"NAND 32GiB 1,8V 8-bit",       0x1C, 0, 32768, 0, LP_OPTIONS},
+       {"NAND 32GiB 3,3V 8-bit",       0x3C, 0, 32768, 0, LP_OPTIONS},
+       {"NAND 32GiB 1,8V 16-bit",      0x2C, 0, 32768, 0, LP_OPTIONS16},
+       {"NAND 32GiB 3,3V 16-bit",      0x4C, 0, 32768, 0, LP_OPTIONS16},
+
+       /* 512 Gigabit */
+       {"NAND 64GiB 1,8V 8-bit",       0x1E, 0, 65536, 0, LP_OPTIONS},
+       {"NAND 64GiB 3,3V 8-bit",       0x3E, 0, 65536, 0, LP_OPTIONS},
+       {"NAND 64GiB 1,8V 16-bit",      0x2E, 0, 65536, 0, LP_OPTIONS16},
+       {"NAND 64GiB 3,3V 16-bit",      0x4E, 0, 65536, 0, LP_OPTIONS16},
+
        /*
         * Renesas AND 1 Gigabit. Those chips do not support extended id and
         * have a strange page/block layout !  The chosen minimum erasesize is
include/linux/bch.h new file +79 -0

79 lines not on this page · raw message

include/linux/mtd/nand.h +3 -7
index 987a2ec..969fda1 100644
@@ -18,13 +18,6 @@
 #ifndef __LINUX_MTD_NAND_H
 #define __LINUX_MTD_NAND_H
 
-/* XXX U-BOOT XXX */
-#if 0
-#include <linux/wait.h>
-#include <linux/spinlock.h>
-#include <linux/mtd/mtd.h>
-#endif
-
 #include "config.h"
 
 #include "linux/mtd/compat.h"
@@ -132,6 +125,7 @@ typedef enum {
        NAND_ECC_HW,
        NAND_ECC_HW_SYNDROME,
        NAND_ECC_HW_OOB_FIRST,
+       NAND_ECC_SOFT_BCH,
 } nand_ecc_modes_t;
 
 /*
@@ -308,6 +302,7 @@ struct nand_hw_control {
  * @prepad:    padding information for syndrome based ecc generators
  * @postpad:   padding information for syndrome based ecc generators
  * @layout:    ECC layout control struct pointer
+ * @priv:       pointer to private ecc control data
  * @hwctl:     function to control hardware ecc generator. Must only
  *             be provided if an hardware ECC is available
  * @calculate: function for ecc calculation or readback from ecc hardware
@@ -328,6 +323,7 @@ struct nand_ecc_ctrl {
        int                     prepad;
        int                     postpad;
        struct nand_ecclayout   *layout;
+       void                    *priv;
        void                    (*hwctl)(struct mtd_info *mtd, int mode);
        int                     (*calculate)(struct mtd_info *mtd,
                                             const uint8_t *dat,
include/linux/mtd/nand_bch.h new file +72 -0

72 lines not on this page · raw message

lib/Makefile +1 -0
index 884f64c..46cc31a 100644
@@ -27,6 +27,7 @@ LIB   = $(obj)libgeneric.o
 
 ifndef CONFIG_SPL_BUILD
 COBJS-$(CONFIG_ADDR_MAP) += addr_map.o
+COBJS-$(CONFIG_BCH) += bch.o
 COBJS-$(CONFIG_BZIP2) += bzlib.o
 COBJS-$(CONFIG_BZIP2) += bzlib_crctable.o
 COBJS-$(CONFIG_BZIP2) += bzlib_decompress.o
lib/bch.c new file +1358 -0

1,358 lines not on this page · raw message

--
1.7.4.1

#1 lore raw

PATCH 1/2 nand: Merge BCH code from Linux nand driver

Dear "Hitz, Christian",

Quoted 5 lines · In message <CD1B567EF015FE41B29FF476B8600DDD26BBF25B88@vsrv-mail01.newtechgroup…

This patch merges the BCH ECC algorithm from the 3.0 Linux kernel. This enables U-Boot to support modern NAND flash chips that require more than 1-bit of ECC in software.

Quoted 15 lines
---
 drivers/mtd/nand/Makefile    |    1 +
 drivers/mtd/nand/nand_base.c |   39 ++-
 drivers/mtd/nand/nand_bch.c  |  236 ++++++++
 drivers/mtd/nand/nand_ids.c  |   35 ++
 include/linux/bch.h          |   79 +++
 include/linux/mtd/nand.h     |   10 +-
 include/linux/mtd/nand_bch.h |   72 +++
 lib/Makefile                 |    1 +
 lib/bch.c                    | 1358 ++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 1823 insertions(+), 8 deletions(-)
 create mode 100644 drivers/mtd/nand/nand_bch.c
 create mode 100644 include/linux/bch.h
 create mode 100644 include/linux/mtd/nand_bch.h
 create mode 100644 lib/bch.c

Checkpatch says:

total: 566 errors, 1052 warnings, 1912 lines checked

Please clean up and resubmit. Thanks.

Best regards,

Wolfgang Denk

Signature · 9 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Do you know the one -- "All I ask is a tall ship, and a star to steer
her by ..." You could feel the wind at your back, about you  ...  the
sounds of the sea beneath you. And even if you take away the wind and
the  water,  it's  still the same. The ship is yours ... you can feel
her ... and the stars are still there.
	-- Kirk, "The Ultimate Computer", stardate 4729.4
#2 lore raw

PATCH 1/2 nand: Merge BCH code from Linux nand driver

Quoted 24 lines · Wolfgang Denk

Dear "Hitz, Christian",

Quoted 15 lines · In message <CD1B567EF015FE41B29FF476B8600DDD26BBF25B88@vsrv-mail01.newtechgroup…

This patch merges the BCH ECC algorithm from the 3.0 Linux kernel. This enables U-Boot to support modern NAND flash chips that require more than 1-bit of ECC in software.

---

?drivers/mtd/nand/Makefile ? ?| ? ?1 +
?drivers/mtd/nand/nand_base.c | ? 39 ++-
?drivers/mtd/nand/nand_bch.c ?| ?236 ++++++++
?drivers/mtd/nand/nand_ids.c ?| ? 35 ++
?include/linux/bch.h ? ? ? ? ?| ? 79 +++
?include/linux/mtd/nand.h ? ? | ? 10 +-
?include/linux/mtd/nand_bch.h | ? 72 +++
?lib/Makefile ? ? ? ? ? ? ? ? | ? ?1 +
?lib/bch.c ? ? ? ? ? ? ? ? ? ?| 1358 ++++++++++++++++++++++++++++++++++++++++++
Quoted 5 lines

?9 files changed, 1823 insertions(+), 8 deletions(-) ?create mode 100644 drivers/mtd/nand/nand_bch.c ?create mode 100644 include/linux/bch.h ?create mode 100644 include/linux/mtd/nand_bch.h ?create mode 100644 lib/bch.c

Quoted 5 lines

Checkpatch says:

total: 566 errors, 1052 warnings, 1912 lines checked

Please clean up and resubmit. ?Thanks.

Not that I've checked personally but might this be a case of matching the kernel code and keeping in sync there?

Signature · 1 line
Tom
#3 lore raw

PATCH 1/2 nand: Merge BCH code from Linux nand driver

Dear Tom Rini,

Quoted 7 lines · In message <CA+M6bX=DQ=pwDD0PkNNLR1LcfCiKwfwwoNnqiroz4xuGwV2SQA@mail.gmail.com>…
Quoted 4 lines

total: 566 errors, 1052 warnings, 1912 lines checked

Please clean up and resubmit.

Not that I've checked personally but might this be a case of matching the kernel code and keeping in sync there?

This is just too bad. If needed, the kernel code should be cleaned up in sync.

BTW: if this is copied from Linux, then you failed to provide exavct reference - see bullet # 4 at
http://www.denx.de/wiki/view/U-Boot/Patches#Attributing_Code_Copyrights_Sign

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"The bad reputation UNIX has gotten is totally undeserved, laid on by
people who don't understand, who have not gotten in there  and  tried
anything."          -- Jim Joyce, owner of Jim Joyce's UNIX Bookstore
#4 lore raw

PATCH 1/2 nand: Merge BCH code from Linux nand driver

Hello,

Am 07.10.2011 07:29, schrieb Wolfgang Denk:

Quoted 9 lines
Quoted 7 lines · In message<CA+M6bX=DQ=pwDD0PkNNLR1LcfCiKwfwwoNnqiroz4xuGwV2SQA@mail.gmail.com>…
Quoted 4 lines

total: 566 errors, 1052 warnings, 1912 lines checked

Please clean up and resubmit.

Not that I've checked personally but might this be a case of matching the kernel code and keeping in sync there?

Quoted 6 lines

This is just too bad. If needed, the kernel code should be cleaned up in sync.

BTW: if this is copied from Linux, then you failed to provide exavct reference - see bullet # 4 at
http://www.denx.de/wiki/view/U-Boot/Patches#Attributing_Code_Copyrights_Sign

I will resubmit using a real email client and also add the exact reference.

Regards,
Christian

Signature · 2 lines
Christian Hitz
aizo ag, Schlieren, Switzerland, www.aizo.com