1 From bd4a694934e348acb930f05fe25dcee6b53b3685 Mon Sep 17 00:00:00 2001
2 From: Jason Liu <r64343@freescale.com>
3 Date: Fri, 7 May 2010 17:46:36 +0800
4 Subject: [PATCH] ENGR00123265 UBOOT:Preserve NAND bad block indication
6 Preserve NAND bad block indication
8 Signed-off-by:Jason Liu <r64343@freescale.com>
10 drivers/mtd/nand/mxc_nand.c | 30 +++++++++++++++++++++++++++++-
11 include/asm-arm/arch-mx25/mxc_nand.h | 26 +++++++++++++++++++++++++-
12 include/asm-arm/arch-mx35/mxc_nand.h | 26 +++++++++++++++++++++++++-
13 include/asm-arm/arch-mx51/mxc_nand.h | 25 ++++++++++++++++++++++++-
14 4 files changed, 103 insertions(+), 4 deletions(-)
16 diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
17 index 5961b4c..ccb7af1 100644
18 --- a/drivers/mtd/nand/mxc_nand.c
19 +++ b/drivers/mtd/nand/mxc_nand.c
22 - * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
23 + * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
27 @@ -57,6 +57,27 @@ static struct nand_ecclayout nand_hw_eccoob_4k = {
32 +static void mxc_nand_bi_swap(struct mtd_info *mtd)
34 + struct nand_chip *this = mtd->priv;
35 + struct nand_info *info = this->priv;
36 + u16 ma, sa, nma, nsa;
38 + if (!IS_LARGE_PAGE_NAND)
41 + ma = __raw_readw(BAD_BLK_MARKER_MAIN);
42 + sa = __raw_readw(BAD_BLK_MARKER_SP);
44 + nma = (ma & 0xFF00) | (sa >> 8);
45 + nsa = (sa & 0x00FF) | (ma << 8);
47 + __raw_writew(nma, BAD_BLK_MARKER_MAIN);
48 + __raw_writew(nsa, BAD_BLK_MARKER_SP);
53 * @defgroup NAND_MTD NAND Flash MTD Driver for MXC processors
55 @@ -325,6 +346,7 @@ static void send_cmd_interleave(struct mtd_info *mtd, u16 cmd)
57 nfc_memcpy(MAIN_AREA0, dbuf, dlen);
58 copy_spare(mtd, obuf, SPARE_AREA0, olen, 0);
59 + mxc_nand_bi_swap(mtd);
61 /* update the value */
63 @@ -358,6 +380,7 @@ static void send_cmd_interleave(struct mtd_info *mtd, u16 cmd)
64 mxc_nand_ecc_status(mtd);
67 + mxc_nand_bi_swap(mtd);
68 nfc_memcpy(dbuf, MAIN_AREA0, dlen);
69 copy_spare(mtd, obuf, SPARE_AREA0, olen, 1);
71 @@ -906,6 +929,7 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
72 nfc_memcpy(MAIN_AREA0, info->data_buf, mtd->writesize);
73 copy_spare(mtd, info->oob_buf, SPARE_AREA0,
75 + mxc_nand_bi_swap(mtd);
78 send_prog_page(mtd, 0);
79 @@ -938,6 +962,7 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
81 if (!info->auto_mode) {
82 mxc_nand_ecc_status(mtd);
83 + mxc_nand_bi_swap(mtd);
84 nfc_memcpy(info->data_buf, MAIN_AREA0, mtd->writesize);
85 copy_spare(mtd, info->oob_buf, SPARE_AREA0,
87 @@ -1184,6 +1209,9 @@ skip_it:
88 /* jffs2 not write oob */
89 /*mtd->flags &= ~MTD_OOB_WRITEABLE;*/
91 + /* fix up the offset */
92 + largepage_memorybased.offs = BAD_BLK_MARKER_OOB_OFFS;
94 /* use flash based bbt */
95 this->bbt_td = &bbt_main_descr;
96 this->bbt_md = &bbt_mirror_descr;
97 diff --git a/include/asm-arm/arch-mx25/mxc_nand.h b/include/asm-arm/arch-mx25/mxc_nand.h
98 index 9b2eec6..de273ac 100644
99 --- a/include/asm-arm/arch-mx25/mxc_nand.h
100 +++ b/include/asm-arm/arch-mx25/mxc_nand.h
103 - * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
104 + * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
109 #define IS_LARGE_PAGE_NAND ((mtd->writesize / info->num_of_intlv) > 512)
111 #define GET_NAND_OOB_SIZE (mtd->oobsize / info->num_of_intlv)
112 +#define GET_NAND_PAGE_SIZE (mtd->writesize / info->num_of_intlv)
115 + * main area for bad block marker is in the last data section
116 + * the spare area for swapped bad block marker is the second
117 + * byte of last spare section
119 +#define NAND_SECTIONS (GET_NAND_PAGE_SIZE >> 9)
120 +#define NAND_OOB_PER_SECTION (((GET_NAND_OOB_SIZE / NAND_SECTIONS) >> 1) << 1)
121 +#define NAND_CHUNKS (GET_NAND_PAGE_SIZE / (512 + NAND_OOB_PER_SECTION))
123 +#define BAD_BLK_MARKER_MAIN_OFFS \
124 + (GET_NAND_PAGE_SIZE - NAND_CHUNKS * NAND_OOB_PER_SECTION)
126 +#define BAD_BLK_MARKER_SP_OFFS (NAND_CHUNKS * SPARE_LEN)
128 +#define BAD_BLK_MARKER_OOB_OFFS (NAND_CHUNKS * NAND_OOB_PER_SECTION)
130 +#define BAD_BLK_MARKER_MAIN \
131 + ((u32)MAIN_AREA0 + BAD_BLK_MARKER_MAIN_OFFS)
133 +#define BAD_BLK_MARKER_SP \
134 + ((u32)SPARE_AREA0 + BAD_BLK_MARKER_SP_OFFS)
136 #define NAND_PAGESIZE_2KB 2048
137 #define NAND_PAGESIZE_4KB 4096
138 #define NAND_MAX_PAGESIZE 4096
139 diff --git a/include/asm-arm/arch-mx35/mxc_nand.h b/include/asm-arm/arch-mx35/mxc_nand.h
140 index 5946703..c672e54 100644
141 --- a/include/asm-arm/arch-mx35/mxc_nand.h
142 +++ b/include/asm-arm/arch-mx35/mxc_nand.h
145 - * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
146 + * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
151 #define IS_LARGE_PAGE_NAND ((mtd->writesize / info->num_of_intlv) > 512)
153 #define GET_NAND_OOB_SIZE (mtd->oobsize / info->num_of_intlv)
154 +#define GET_NAND_PAGE_SIZE (mtd->writesize / info->num_of_intlv)
156 #define NAND_PAGESIZE_2KB 2048
157 #define NAND_PAGESIZE_4KB 4096
160 + * main area for bad block marker is in the last data section
161 + * the spare area for swapped bad block marker is the second
162 + * byte of last spare section
164 +#define NAND_SECTIONS (GET_NAND_PAGE_SIZE >> 9)
165 +#define NAND_OOB_PER_SECTION (((GET_NAND_OOB_SIZE / NAND_SECTIONS) >> 1) << 1)
166 +#define NAND_CHUNKS (GET_NAND_PAGE_SIZE / (512 + NAND_OOB_PER_SECTION))
168 +#define BAD_BLK_MARKER_MAIN_OFFS \
169 + (GET_NAND_PAGE_SIZE - NAND_CHUNKS * NAND_OOB_PER_SECTION)
171 +#define BAD_BLK_MARKER_SP_OFFS (NAND_CHUNKS * SPARE_LEN)
173 +#define BAD_BLK_MARKER_OOB_OFFS (NAND_CHUNKS * NAND_OOB_PER_SECTION)
175 +#define BAD_BLK_MARKER_MAIN \
176 + ((u32)MAIN_AREA0 + BAD_BLK_MARKER_MAIN_OFFS)
178 +#define BAD_BLK_MARKER_SP \
179 + ((u32)SPARE_AREA0 + BAD_BLK_MARKER_SP_OFFS)
183 * Addresses for NFC registers
185 #define NFC_REG_BASE (NFC_BASE_ADDR + 0x1000)
186 diff --git a/include/asm-arm/arch-mx51/mxc_nand.h b/include/asm-arm/arch-mx51/mxc_nand.h
187 index ee5bf91..843f080 100644
188 --- a/include/asm-arm/arch-mx51/mxc_nand.h
189 +++ b/include/asm-arm/arch-mx51/mxc_nand.h
192 - * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
193 + * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
198 #define IS_LARGE_PAGE_NAND ((mtd->writesize / info->num_of_intlv) > 512)
200 #define GET_NAND_OOB_SIZE (mtd->oobsize / info->num_of_intlv)
201 +#define GET_NAND_PAGE_SIZE (mtd->writesize / info->num_of_intlv)
204 + * main area for bad block marker is in the last data section
205 + * the spare area for swapped bad block marker is the second
206 + * byte of last spare section
208 +#define NAND_SECTIONS (GET_NAND_PAGE_SIZE >> 9)
209 +#define NAND_OOB_PER_SECTION (((GET_NAND_OOB_SIZE / NAND_SECTIONS) >> 1) << 1)
210 +#define NAND_CHUNKS (GET_NAND_PAGE_SIZE / (512 + NAND_OOB_PER_SECTION))
212 +#define BAD_BLK_MARKER_MAIN_OFFS \
213 + (GET_NAND_PAGE_SIZE - NAND_CHUNKS * NAND_OOB_PER_SECTION)
215 +#define BAD_BLK_MARKER_SP_OFFS (NAND_CHUNKS * SPARE_LEN)
217 +#define BAD_BLK_MARKER_OOB_OFFS (NAND_CHUNKS * NAND_OOB_PER_SECTION)
219 +#define BAD_BLK_MARKER_MAIN \
220 + ((u32)MAIN_AREA0 + BAD_BLK_MARKER_MAIN_OFFS)
222 +#define BAD_BLK_MARKER_SP \
223 + ((u32)SPARE_AREA0 + BAD_BLK_MARKER_SP_OFFS)
225 #define NAND_PAGESIZE_2KB 2048
226 #define NAND_PAGESIZE_4KB 4096