]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - patches/0110-ENGR00123265-UBOOT-Preserve-NAND-bad-block-indicatio.patch
imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
[karo-tx-uboot.git] / patches / 0110-ENGR00123265-UBOOT-Preserve-NAND-bad-block-indicatio.patch
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
5
6 Preserve NAND bad block indication
7
8 Signed-off-by:Jason Liu <r64343@freescale.com>
9 ---
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(-)
15
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
20 @@ -1,5 +1,5 @@
21  /*
22 - * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
23 + * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
24   */
25  
26  /*
27 @@ -57,6 +57,27 @@ static struct nand_ecclayout nand_hw_eccoob_4k = {
28         .oobfree = {{2, 4} }
29  };
30  
31 +
32 +static void mxc_nand_bi_swap(struct mtd_info *mtd)
33 +{
34 +       struct nand_chip *this = mtd->priv;
35 +       struct nand_info *info = this->priv;
36 +       u16 ma, sa, nma, nsa;
37 +
38 +       if (!IS_LARGE_PAGE_NAND)
39 +               return;
40 +
41 +       ma = __raw_readw(BAD_BLK_MARKER_MAIN);
42 +       sa = __raw_readw(BAD_BLK_MARKER_SP);
43 +
44 +       nma = (ma & 0xFF00) | (sa >> 8);
45 +       nsa = (sa & 0x00FF) | (ma << 8);
46 +
47 +       __raw_writew(nma, BAD_BLK_MARKER_MAIN);
48 +       __raw_writew(nsa, BAD_BLK_MARKER_SP);
49 +
50 +}
51 +
52  /*!
53   * @defgroup NAND_MTD NAND Flash MTD Driver for MXC processors
54   */
55 @@ -325,6 +346,7 @@ static void send_cmd_interleave(struct mtd_info *mtd, u16 cmd)
56                         /* data transfer */
57                         nfc_memcpy(MAIN_AREA0, dbuf, dlen);
58                         copy_spare(mtd, obuf, SPARE_AREA0, olen, 0);
59 +                       mxc_nand_bi_swap(mtd);
60  
61                         /* update the value */
62                         dbuf += dlen;
63 @@ -358,6 +380,7 @@ static void send_cmd_interleave(struct mtd_info *mtd, u16 cmd)
64                         mxc_nand_ecc_status(mtd);
65  
66                         /* data transfer */
67 +                       mxc_nand_bi_swap(mtd);
68                         nfc_memcpy(dbuf, MAIN_AREA0, dlen);
69                         copy_spare(mtd, obuf, SPARE_AREA0, olen, 1);
70  
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,
74                                                 mtd->oobsize, 0);
75 +                       mxc_nand_bi_swap(mtd);
76                 }
77  
78                 send_prog_page(mtd, 0);
79 @@ -938,6 +962,7 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
80  
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,
86                                                 mtd->oobsize, 1);
87 @@ -1184,6 +1209,9 @@ skip_it:
88         /* jffs2 not write oob */
89         /*mtd->flags &= ~MTD_OOB_WRITEABLE;*/
90  
91 +       /* fix up the offset */
92 +       largepage_memorybased.offs = BAD_BLK_MARKER_OOB_OFFS;
93 +
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
101 @@ -1,5 +1,5 @@
102  /*
103 - * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
104 + * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
105   */
106  
107  /*
108 @@ -32,6 +32,30 @@
109  #define IS_LARGE_PAGE_NAND     ((mtd->writesize / info->num_of_intlv) > 512)
110  
111  #define GET_NAND_OOB_SIZE       (mtd->oobsize / info->num_of_intlv)
112 +#define GET_NAND_PAGE_SIZE      (mtd->writesize / info->num_of_intlv)
113 +
114 +/*
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
118 + */
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))
122 +
123 +#define BAD_BLK_MARKER_MAIN_OFFS \
124 +       (GET_NAND_PAGE_SIZE - NAND_CHUNKS * NAND_OOB_PER_SECTION)
125 +
126 +#define BAD_BLK_MARKER_SP_OFFS (NAND_CHUNKS * SPARE_LEN)
127 +
128 +#define BAD_BLK_MARKER_OOB_OFFS (NAND_CHUNKS * NAND_OOB_PER_SECTION)
129 +
130 +#define BAD_BLK_MARKER_MAIN  \
131 +       ((u32)MAIN_AREA0 + BAD_BLK_MARKER_MAIN_OFFS)
132 +
133 +#define BAD_BLK_MARKER_SP  \
134 +       ((u32)SPARE_AREA0 + BAD_BLK_MARKER_SP_OFFS)
135 +
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
143 @@ -1,5 +1,5 @@
144  /*
145 - * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
146 + * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
147   */
148  
149  /*
150 @@ -32,11 +32,35 @@
151  #define IS_LARGE_PAGE_NAND      ((mtd->writesize / info->num_of_intlv) > 512)
152  
153  #define GET_NAND_OOB_SIZE       (mtd->oobsize / info->num_of_intlv)
154 +#define GET_NAND_PAGE_SIZE      (mtd->writesize / info->num_of_intlv)
155  
156  #define NAND_PAGESIZE_2KB      2048
157  #define NAND_PAGESIZE_4KB      4096
158  
159  /*
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
163 + */
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))
167 +
168 +#define BAD_BLK_MARKER_MAIN_OFFS \
169 +       (GET_NAND_PAGE_SIZE - NAND_CHUNKS * NAND_OOB_PER_SECTION)
170 +
171 +#define BAD_BLK_MARKER_SP_OFFS (NAND_CHUNKS * SPARE_LEN)
172 +
173 +#define BAD_BLK_MARKER_OOB_OFFS (NAND_CHUNKS * NAND_OOB_PER_SECTION)
174 +
175 +#define BAD_BLK_MARKER_MAIN  \
176 +       ((u32)MAIN_AREA0 + BAD_BLK_MARKER_MAIN_OFFS)
177 +
178 +#define BAD_BLK_MARKER_SP  \
179 +       ((u32)SPARE_AREA0 + BAD_BLK_MARKER_SP_OFFS)
180 +
181 +
182 +/*
183   * Addresses for NFC registers
184   */
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
190 @@ -1,5 +1,5 @@
191  /*
192 - * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
193 + * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
194   */
195  
196  /*
197 @@ -32,6 +32,29 @@
198  #define IS_LARGE_PAGE_NAND      ((mtd->writesize / info->num_of_intlv) > 512)
199  
200  #define GET_NAND_OOB_SIZE      (mtd->oobsize / info->num_of_intlv)
201 +#define GET_NAND_PAGE_SIZE      (mtd->writesize / info->num_of_intlv)
202 +
203 +/*
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
207 + */
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))
211 +
212 +#define BAD_BLK_MARKER_MAIN_OFFS \
213 +       (GET_NAND_PAGE_SIZE - NAND_CHUNKS * NAND_OOB_PER_SECTION)
214 +
215 +#define BAD_BLK_MARKER_SP_OFFS (NAND_CHUNKS * SPARE_LEN)
216 +
217 +#define BAD_BLK_MARKER_OOB_OFFS (NAND_CHUNKS * NAND_OOB_PER_SECTION)
218 +
219 +#define BAD_BLK_MARKER_MAIN  \
220 +       ((u32)MAIN_AREA0 + BAD_BLK_MARKER_MAIN_OFFS)
221 +
222 +#define BAD_BLK_MARKER_SP  \
223 +       ((u32)SPARE_AREA0 + BAD_BLK_MARKER_SP_OFFS)
224  
225  #define NAND_PAGESIZE_2KB      2048
226  #define NAND_PAGESIZE_4KB      4096
227 -- 
228 1.5.4.4
229