public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 8/9] spl, nand: add 4bit HW ecc oob first nand_read_page function
Date: Sat, 16 Jul 2011 12:06:49 +0200	[thread overview]
Message-ID: <1310810810-5322-9-git-send-email-hs@denx.de> (raw)
In-Reply-To: <1310810810-5322-1-git-send-email-hs@denx.de>

Signed-off-by: Heiko Schocher <hs@denx.de>
cc: Scott Wood <scottwood@freescale.com>
---
 nand_spl/nand_boot.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/nand_spl/nand_boot.c b/nand_spl/nand_boot.c
index 4683c7c..615ef25 100644
--- a/nand_spl/nand_boot.c
+++ b/nand_spl/nand_boot.c
@@ -135,6 +135,47 @@ static int nand_is_bad_block(struct mtd_info *mtd, int block)
 	return 0;
 }
 
+#if defined(CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST)
+static int nand_read_page(struct mtd_info *mtd, int block, int page, uchar *dst)
+{
+	struct nand_chip *this = mtd->priv;
+	u_char *ecc_calc;
+	u_char *ecc_code;
+	u_char *oob_data;
+	int i;
+	int eccsize = CONFIG_SYS_NAND_ECCSIZE;
+	int eccbytes = CONFIG_SYS_NAND_ECCBYTES;
+	int eccsteps = CONFIG_SYS_NAND_ECCSTEPS;
+	uint8_t *p = dst;
+	int stat;
+
+	/*
+	 * No malloc available for now, just use some temporary locations
+	 * in SDRAM
+	 */
+	ecc_calc = (u_char *)(CONFIG_SYS_SDRAM_BASE + 0x10000);
+	ecc_code = ecc_calc + 0x100;
+	oob_data = ecc_calc + 0x200;
+
+	nand_command(mtd, block, page, 0, NAND_CMD_READOOB);
+	this->read_buf(mtd, oob_data, CONFIG_SYS_NAND_OOBSIZE);
+	nand_command(mtd, block, page, 0, NAND_CMD_READ0);
+
+	/* Pick the ECC bytes out of the oob data */
+	for (i = 0; i < CONFIG_SYS_NAND_ECCTOTAL; i++)
+		ecc_code[i] = oob_data[nand_ecc_pos[i]];
+
+
+	for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
+		this->ecc.hwctl(mtd, NAND_ECC_READ);
+		this->read_buf(mtd, p, eccsize);
+		this->ecc.calculate(mtd, p, &ecc_calc[i]);
+		stat = this->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
+	}
+
+	return 0;
+}
+#else
 static int nand_read_page(struct mtd_info *mtd, int block, int page, uchar *dst)
 {
 	struct nand_chip *this = mtd->priv;
@@ -181,6 +222,7 @@ static int nand_read_page(struct mtd_info *mtd, int block, int page, uchar *dst)
 
 	return 0;
 }
+#endif /* #if defined(CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST) */
 
 static int nand_load(struct mtd_info *mtd, unsigned int offs,
 		     unsigned int uboot_size, uchar *dst)
-- 
1.7.6

  parent reply	other threads:[~2011-07-16 10:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-16 10:06 [U-Boot] [PATCH 0/9] arm, davinci: add support for dm368 based cam_enc_4xx board Heiko Schocher
2011-07-16 10:06 ` [U-Boot] [PATCH 1/9] mkimage: add UBL header support for booting davinci cpus Heiko Schocher
2011-07-28 14:52   ` Wolfgang Denk
2011-07-16 10:06 ` [U-Boot] [PATCH 2/9] arm, arm926: fix missing symbols in NAND_SPL mode Heiko Schocher
2011-07-16 10:06 ` [U-Boot] [PATCH 3/9] nand: add a hw specific subcommand to the nand command Heiko Schocher
2011-08-02 20:19   ` [U-Boot] [U-Boot, " Scott Wood
2011-08-03  5:14     ` Heiko Schocher
2011-08-03 15:56       ` Scott Wood
2011-08-04  5:40         ` Heiko Schocher
2011-08-04 19:42           ` Scott Wood
2011-08-04 20:14             ` Wolfgang Denk
2011-08-04 20:28               ` Scott Wood
2011-08-04 20:46                 ` Wolfgang Denk
2011-07-16 10:06 ` [U-Boot] [PATCH 4/9] arm, davinci: add header files for dm365 Heiko Schocher
2011-10-05 14:28   ` [U-Boot] [PATCH v2 06/10] " Heiko Schocher
2011-07-16 10:06 ` [U-Boot] [PATCH 5/9] arm, davinci: add lowlevel function for dm365 soc Heiko Schocher
2011-07-16 10:06 ` [U-Boot] [PATCH 6/9] arm926ejs, davinci: add cpuinfo for dm365 Heiko Schocher
2011-10-05 14:29   ` [U-Boot] [PATCH v2 07/10] arm, davinci: add lowlevel function for dm365 soc Heiko Schocher
2011-10-05 14:29   ` [U-Boot] [PATCH v2 08/10] arm926ejs, davinci: add cpuinfo for dm365 Heiko Schocher
2011-07-16 10:06 ` [U-Boot] [PATCH 7/9] arm926ejs, davinci: add missing spi defines " Heiko Schocher
2011-07-16 10:06 ` Heiko Schocher [this message]
2011-08-02 20:49   ` [U-Boot] [U-Boot, 8/9] spl, nand: add 4bit HW ecc oob first nand_read_page function Scott Wood
2011-07-16 10:06 ` [U-Boot] [PATCH 9/9] arm, davinci: add cam_enc_4xx support Heiko Schocher
2011-10-05 14:30   ` [U-Boot] [PATCH v2 10/10] " Heiko Schocher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1310810810-5322-9-git-send-email-hs@denx.de \
    --to=hs@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox