mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Stefan Christ <s.christ@phytec.de>
To: barebox@lists.infradead.org
Subject: [PATCH] ARM: i.MX6: use generic calculation in nand bbu handler
Date: Tue, 27 Jan 2015 14:14:19 +0100	[thread overview]
Message-ID: <1422364459-31395-1-git-send-email-s.christ@phytec.de> (raw)

The parameters ECC Strength, BadBlockMarkerByte and BadBlockMarkerStartBit in
the FCB structure depends on the nand chip's pagesize and oobsize. Instead of
hardcoding these values into the imx6 bbu handler calculate these values on the
fly. Therefore we export the necessary functions from the nand_mxs driver to
use them in the bbu handler.

Signed-off-by: Stefan Christ <s.christ@phytec.de>
---
 arch/arm/mach-imx/Kconfig                 |  1 +
 arch/arm/mach-imx/imx6-bbu-nand.c         | 28 +++++------------------
 arch/arm/mach-imx/include/mach/nand_mxs.h | 37 +++++++++++++++++++++++++++++++
 drivers/mtd/nand/nand_mxs.c               |  7 +++---
 4 files changed, 48 insertions(+), 25 deletions(-)
 create mode 100644 arch/arm/mach-imx/include/mach/nand_mxs.h

diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 9ac36e1..42074a2 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -119,6 +119,7 @@ config BAREBOX_UPDATE_IMX6_NAND
 	depends on BAREBOX_UPDATE
 	depends on MTD
 	depends on MTD_WRITE
+	select NAND_MXS
 	default y
 
 comment "Freescale i.MX System-on-Chip"
diff --git a/arch/arm/mach-imx/imx6-bbu-nand.c b/arch/arm/mach-imx/imx6-bbu-nand.c
index 1b46e51..fb7224c 100644
--- a/arch/arm/mach-imx/imx6-bbu-nand.c
+++ b/arch/arm/mach-imx/imx6-bbu-nand.c
@@ -32,6 +32,7 @@
 #include <linux/mtd/mtd-abi.h>
 #include <linux/mtd/mtd.h>
 #include <linux/stat.h>
+#include <mach/nand_mxs.h>
 
 struct dbbt_block {
 	uint32_t Checksum;
@@ -235,22 +236,9 @@ static int fcb_create(struct fcb_block *fcb, struct mtd_info *mtd)
 	fcb->TotalPageSize = mtd->writesize + mtd->oobsize;
 	fcb->SectorsPerBlock = mtd->erasesize / mtd->writesize;
 
-	if (mtd->writesize == 2048) {
-		fcb->EccBlock0EccType = 4;
-	} else if (mtd->writesize == 4096) {
-		if (mtd->oobsize == 218) {
-			fcb->EccBlock0EccType = 8;
-		} else if (mtd->oobsize == 128) {
-			fcb->EccBlock0EccType = 4;
-		} else {
-			pr_err("Illegal oobsize %d\n", mtd->oobsize);
-			return -EINVAL;
-		}
-	} else {
-		pr_err("Illegal writesize %d\n", mtd->writesize);
-		return -EINVAL;
-	}
-
+	/* Divide ECC strength by two and save the value into FCB structure. */
+	fcb->EccBlock0EccType =
+		mxs_nand_get_ecc_strength(mtd->writesize, mtd->oobsize) >> 1;
 	fcb->EccBlockNEccType = fcb->EccBlock0EccType;
 
 	/* Also hardcoded in kobs-ng */
@@ -267,12 +255,8 @@ static int fcb_create(struct fcb_block *fcb, struct mtd_info *mtd)
 	/* DBBT search area starts at third block */
 	fcb->DBBTSearchAreaStartAddress = mtd->erasesize / mtd->writesize * 2;
 
-	if (mtd->writesize == 2048) {
-		fcb->BadBlockMarkerByte = 0x000007cf;
-	} else {
-		pr_err("BadBlockMarkerByte unknown for writesize %d\n", mtd->writesize);
-		return -EINVAL;
-	}
+	fcb->BadBlockMarkerByte = mxs_nand_mark_byte_offset(mtd);
+	fcb->BadBlockMarkerStartBit = mxs_nand_mark_bit_offset(mtd);
 
 	fcb->BBMarkerPhysicalOffset = mtd->writesize;
 
diff --git a/arch/arm/mach-imx/include/mach/nand_mxs.h b/arch/arm/mach-imx/include/mach/nand_mxs.h
new file mode 100644
index 0000000..eca3177
--- /dev/null
+++ b/arch/arm/mach-imx/include/mach/nand_mxs.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2015 PHYTEC Messtechnik GmbH,
+ * Author: Stefan Christ <s.christ@phytec.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __NAND_MXS_H
+#define __NAND_MXS_H
+
+/*
+ * Functions are definied in drivers/mtd/nand/nand_mxs.c.  They are used to
+ * calculate the ECC Strength, BadBlockMarkerByte and BadBlockMarkerStartBit
+ * which are placed into the FCB structure. The i.MX6 ROM needs these
+ * parameters to read the firmware from NAND.
+ *
+ * The parameters depends on the pagesize and oobsize of NAND chips and are
+ * different for each combination. To avoid placing hardcoded values in the bbu
+ * update handler code, the generic calculation from the driver code is used.
+ */
+
+uint32_t mxs_nand_get_ecc_strength(uint32_t page_data_size,
+						uint32_t page_oob_size);
+
+uint32_t mxs_nand_mark_byte_offset(struct mtd_info *mtd);
+
+uint32_t mxs_nand_mark_bit_offset(struct mtd_info *mtd);
+
+#endif /* __NAND_MXS_H */
diff --git a/drivers/mtd/nand/nand_mxs.c b/drivers/mtd/nand/nand_mxs.c
index 94101a3..4c5bdfa 100644
--- a/drivers/mtd/nand/nand_mxs.c
+++ b/drivers/mtd/nand/nand_mxs.c
@@ -34,6 +34,7 @@
 #include <stmp-device.h>
 #include <asm/mmu.h>
 #include <mach/generic.h>
+#include <mach/nand_mxs.h>
 
 #define	MX28_BLOCK_SFTRST				(1 << 31)
 #define	MX28_BLOCK_CLKGATE				(1 << 30)
@@ -231,7 +232,7 @@ static uint32_t mxs_nand_aux_status_offset(void)
 	return (MXS_NAND_METADATA_SIZE + 0x3) & ~0x3;
 }
 
-static inline uint32_t mxs_nand_get_ecc_strength(uint32_t page_data_size,
+uint32_t mxs_nand_get_ecc_strength(uint32_t page_data_size,
 						uint32_t page_oob_size)
 {
 	int ecc_chunk_count = mxs_nand_ecc_chunk_cnt(page_data_size);
@@ -294,14 +295,14 @@ static inline uint32_t mxs_nand_get_mark_offset(uint32_t page_data_size,
 	return block_mark_bit_offset;
 }
 
-static uint32_t mxs_nand_mark_byte_offset(struct mtd_info *mtd)
+uint32_t mxs_nand_mark_byte_offset(struct mtd_info *mtd)
 {
 	uint32_t ecc_strength;
 	ecc_strength = mxs_nand_get_ecc_strength(mtd->writesize, mtd->oobsize);
 	return mxs_nand_get_mark_offset(mtd->writesize, ecc_strength) >> 3;
 }
 
-static uint32_t mxs_nand_mark_bit_offset(struct mtd_info *mtd)
+uint32_t mxs_nand_mark_bit_offset(struct mtd_info *mtd)
 {
 	uint32_t ecc_strength;
 	ecc_strength = mxs_nand_get_ecc_strength(mtd->writesize, mtd->oobsize);
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2015-01-27 13:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-27 13:14 Stefan Christ [this message]
2015-01-28  9:11 ` Sascha Hauer

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=1422364459-31395-1-git-send-email-s.christ@phytec.de \
    --to=s.christ@phytec.de \
    --cc=barebox@lists.infradead.org \
    /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