]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/include/xnandpsu_bbm.h
Add in the CORTEX_A53_64-bit_UltraScale_MPSoC demo application (a demo has been inclu...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / include / xnandpsu_bbm.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2015 Xilinx, Inc. All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xnandpsu_bbm.h
36 *
37 * This file implements the Bad Block Management(BBM) functionality. This is
38 * similar to the Bad Block Management which is a part of the MTD subsystem in
39 * Linux.  The factory marked bad blocks are scanned initially and a Bad Block
40 * Table(BBT) is created in the memory.  This table is also written to the flash
41 * so that upon reboot, the BBT is read back from the flash and loaded into the
42 * memory instead of scanning every time. The Bad Block Table(BBT) is written
43 * into one of the the last four blocks in the flash memory. The last four
44 * blocks are marked as Reserved so that user can't erase/program those blocks.
45 *
46 * There are two bad block tables, a primary table and a mirror table. The
47 * tables are versioned and incrementing version number is used to detect and
48 * recover from interrupted updates. Each table is stored in a separate block,
49 * beginning in the first page of that block. Only two blocks would be necessary
50 * in the absence of bad blocks within the last four; the range of four provides
51 * a little slack in case one or two of those blocks is bad. These blocks are
52 * marked as reserved and cannot be programmed by the user. A NAND Flash device
53 * with 3 or more factory bad blocks in the last 4 cannot be used. The bad block
54 * table signature is written into the spare data area of the pages containing
55 * bad block table so that upon rebooting the bad block table signature is
56 * searched and the bad block table is loaded into RAM. The signature is "Bbt0"
57 * for primary Bad Block Table and "1tbB" for Mirror Bad Block Table. The
58 * version offset follows the signature offset in the spare data area. The
59 * version number increments on every update to the bad block table and the
60 * version wraps at 0xff.
61 *
62 * Each block in the Bad Block Table(BBT) is represented by 2 bits.
63 * The two bits are encoded as follows in RAM BBT.
64 * 0'b00 -> Good Block
65 * 0'b01 -> Block is bad due to wear
66 * 0'b10 -> Reserved block
67 * 0'b11 -> Factory marked bad block
68 *
69 * While writing to the flash the two bits are encoded as follows.
70 * 0'b00 -> Factory marked bad block
71 * 0'b01 -> Reserved block
72 * 0'b10 -> Block is bad due to wear
73 * 0'b11 -> Good Block
74 *
75 * The user can check for the validity of the block using the API
76 * XNandPsu_IsBlockBad and take the action based on the return value. Also user
77 * can update the bad block table using XNandPsu_MarkBlockBad API.
78 *
79 * @note         None
80 *
81 * <pre>
82 * MODIFICATION HISTORY:
83 *
84 * Ver   Who    Date        Changes
85 * ----- ----   ----------  -----------------------------------------------
86 * 1.0   nm     05/06/2014  First release
87 * 2.0   sb     01/12/2015  Added support for writing BBT signature and version
88 *                          in page section by enabling XNANDPSU_BBT_NO_OOB.
89 *                          Modified Bbt Signature and Version Offset value for
90 *                          Oob and No-Oob region.
91 * </pre>
92 *
93 ******************************************************************************/
94 #ifndef XNANDPSU_BBM_H          /* prevent circular inclusions */
95 #define XNANDPSU_BBM_H          /* by using protection macros */
96
97 #ifdef __cplusplus
98 extern "C" {
99 #endif
100
101 /***************************** Include Files *********************************/
102 #include "xnandpsu.h"
103
104 /************************** Constant Definitions *****************************/
105 /*
106  * Block definitions for RAM based Bad Block Table (BBT)
107  */
108 #define XNANDPSU_BLOCK_GOOD                     0x0U    /**< Block is good */
109 #define XNANDPSU_BLOCK_BAD                      0x1U    /**< Block is bad */
110 #define XNANDPSU_BLOCK_RESERVED                 0x2U    /**< Reserved block */
111 #define XNANDPSU_BLOCK_FACTORY_BAD              0x3U    /**< Factory marked bad
112                                                           block */
113 /*
114  * Block definitions for FLASH based Bad Block Table (BBT)
115  */
116 #define XNANDPSU_FLASH_BLOCK_GOOD               0x3U    /**< Block is good */
117 #define XNANDPSU_FLASH_BLOCK_BAD                0x2U    /**< Block is bad */
118 #define XNANDPSU_FLASH_BLOCK_RESERVED           0x1U    /**< Reserved block */
119 #define XNANDPSU_FLASH_BLOCK_FAC_BAD    0x0U    /**< Factory marked bad
120                                                           block */
121
122 #define XNANDPSU_BBT_SCAN_2ND_PAGE              0x00000001U     /**< Scan the
123                                                                   second page
124                                                                   for bad block
125                                                                   information
126                                                                   */
127 #define XNANDPSU_BBT_DESC_PAGE_OFFSET           0U      /**< Page offset of Bad
128                                                           Block Table Desc */
129 #define XNANDPSU_BBT_DESC_SIG_OFFSET            8U      /**< Bad Block Table
130                                                           signature offset */
131 #define XNANDPSU_BBT_DESC_VER_OFFSET            12U     /**< Bad block Table
132                                                           version offset */
133 #define XNANDPSU_NO_OOB_BBT_DESC_SIG_OFFSET     0U      /**< Bad Block Table
134                                                           signature offset in
135                                                           page memory */
136 #define XNANDPSU_NO_OOB_BBT_DESC_VER_OFFSET     4U      /**< Bad block Table
137                                                           version offset in
138                                                           page memory */
139 #define XNANDPSU_BBT_DESC_SIG_LEN               4U      /**< Bad block Table
140                                                           signature length */
141 #define XNANDPSU_BBT_DESC_MAX_BLOCKS            64U     /**< Bad block Table
142                                                           max blocks */
143
144 #define XNANDPSU_BBT_BLOCK_SHIFT                2U      /**< Block shift value
145                                                           for a block in BBT */
146 #define XNANDPSU_BBT_ENTRY_NUM_BLOCKS           4U      /**< Num of blocks in
147                                                           one BBT entry */
148 #define XNANDPSU_BB_PTRN_OFF_SML_PAGE   5U      /**< Bad block pattern
149                                                           offset in a page */
150 #define XNANDPSU_BB_PTRN_LEN_SML_PAGE   1U      /**< Bad block pattern
151                                                           length */
152 #define XNANDPSU_BB_PTRN_OFF_LARGE_PAGE 0U      /**< Bad block pattern
153                                                           offset in a large
154                                                           page */
155 #define XNANDPSU_BB_PTRN_LEN_LARGE_PAGE 2U      /**< Bad block pattern
156                                                           length */
157 #define XNANDPSU_BB_PATTERN                     0xFFU   /**< Bad block pattern
158                                                           to search in a page
159                                                           */
160 #define XNANDPSU_BLOCK_TYPE_MASK                0x03U   /**< Block type mask */
161 #define XNANDPSU_BLOCK_SHIFT_MASK               0x06U   /**< Block shift mask
162                                                           for a Bad Block Table
163                                                           entry byte */
164
165 #define XNANDPSU_ONDIE_SIG_OFFSET               0x4U
166 #define XNANDPSU_ONDIE_VER_OFFSET               0x14U
167
168 #define XNANDPSU_BBT_VERSION_LENGTH     1U
169 #define XNANDPSU_BBT_SIG_LENGTH         4U
170
171 #define XNANDPSU_BBT_BUF_LENGTH         ((XNANDPSU_MAX_BLOCKS >>                \
172                                          XNANDPSU_BBT_BLOCK_SHIFT) +    \
173                                         (XNANDPSU_BBT_DESC_SIG_OFFSET + \
174                                          XNANDPSU_BBT_SIG_LENGTH +      \
175                                          XNANDPSU_BBT_VERSION_LENGTH))
176 /**************************** Type Definitions *******************************/
177
178 /***************** Macros (Inline Functions) Definitions *********************/
179
180 /****************************************************************************/
181 /**
182 *
183 * This macro returns the Block shift value corresponding to a Block.
184 *
185 * @param        Block is the block number.
186 *
187 * @return       Block shift value
188 *
189 * @note         None.
190 *
191 *****************************************************************************/
192 #define XNandPsu_BbtBlockShift(Block) \
193                         ((u8)(((Block) * 2U) & XNANDPSU_BLOCK_SHIFT_MASK))
194
195 /************************** Variable Definitions *****************************/
196
197 /************************** Function Prototypes ******************************/
198
199 void XNandPsu_InitBbtDesc(XNandPsu *InstancePtr);
200
201 s32 XNandPsu_ScanBbt(XNandPsu *InstancePtr);
202
203 s32 XNandPsu_IsBlockBad(XNandPsu *InstancePtr, u32 Block);
204
205 s32 XNandPsu_MarkBlockBad(XNandPsu *InstancePtr, u32 Block);
206
207 #ifdef __cplusplus
208 }
209 #endif
210
211 #endif /* end of protection macro */