rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2005 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * NAND_FDM.h |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * MAUI |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * This is a NAND FDM header file |
| 49 | * |
| 50 | * Author: |
| 51 | * ------- |
| 52 | * ------- |
| 53 | * |
| 54 | *============================================================================== |
| 55 | * HISTORY |
| 56 | * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 57 | *------------------------------------------------------------------------------ |
| 58 | * removed! |
| 59 | * removed! |
| 60 | * removed! |
| 61 | * |
| 62 | * removed! |
| 63 | * removed! |
| 64 | * removed! |
| 65 | * |
| 66 | * removed! |
| 67 | * removed! |
| 68 | * removed! |
| 69 | * |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * removed! |
| 73 | * |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * removed! |
| 77 | * |
| 78 | * removed! |
| 79 | * removed! |
| 80 | * removed! |
| 81 | * |
| 82 | * removed! |
| 83 | * removed! |
| 84 | * removed! |
| 85 | * |
| 86 | * removed! |
| 87 | * removed! |
| 88 | * removed! |
| 89 | * |
| 90 | * removed! |
| 91 | * removed! |
| 92 | * removed! |
| 93 | * |
| 94 | * removed! |
| 95 | * removed! |
| 96 | * removed! |
| 97 | * removed! |
| 98 | * removed! |
| 99 | * removed! |
| 100 | * |
| 101 | * removed! |
| 102 | * removed! |
| 103 | * removed! |
| 104 | * |
| 105 | * removed! |
| 106 | * removed! |
| 107 | * removed! |
| 108 | * |
| 109 | * removed! |
| 110 | * removed! |
| 111 | * removed! |
| 112 | * |
| 113 | * removed! |
| 114 | * removed! |
| 115 | * removed! |
| 116 | * |
| 117 | * removed! |
| 118 | * removed! |
| 119 | * |
| 120 | * |
| 121 | * removed! |
| 122 | * removed! |
| 123 | * removed! |
| 124 | * removed! |
| 125 | * |
| 126 | * removed! |
| 127 | * removed! |
| 128 | * |
| 129 | * |
| 130 | * removed! |
| 131 | * removed! |
| 132 | * removed! |
| 133 | * |
| 134 | * removed! |
| 135 | * removed! |
| 136 | * removed! |
| 137 | * removed! |
| 138 | * removed! |
| 139 | * |
| 140 | * removed! |
| 141 | * removed! |
| 142 | * removed! |
| 143 | * removed! |
| 144 | * removed! |
| 145 | * |
| 146 | * removed! |
| 147 | * removed! |
| 148 | * removed! |
| 149 | * removed! |
| 150 | * removed! |
| 151 | * removed! |
| 152 | * removed! |
| 153 | * |
| 154 | * removed! |
| 155 | * removed! |
| 156 | * removed! |
| 157 | * |
| 158 | * removed! |
| 159 | * removed! |
| 160 | * removed! |
| 161 | * removed! |
| 162 | * |
| 163 | * removed! |
| 164 | * removed! |
| 165 | * |
| 166 | * |
| 167 | * removed! |
| 168 | * removed! |
| 169 | * |
| 170 | * |
| 171 | * removed! |
| 172 | * removed! |
| 173 | * |
| 174 | * |
| 175 | * removed! |
| 176 | * removed! |
| 177 | * |
| 178 | * |
| 179 | * removed! |
| 180 | * removed! |
| 181 | * |
| 182 | * |
| 183 | * removed! |
| 184 | * removed! |
| 185 | * |
| 186 | * |
| 187 | * removed! |
| 188 | * removed! |
| 189 | * |
| 190 | * |
| 191 | * removed! |
| 192 | * removed! |
| 193 | * |
| 194 | * |
| 195 | * removed! |
| 196 | * removed! |
| 197 | * removed! |
| 198 | * removed! |
| 199 | * |
| 200 | * removed! |
| 201 | * removed! |
| 202 | * removed! |
| 203 | * |
| 204 | * removed! |
| 205 | * removed! |
| 206 | * removed! |
| 207 | * |
| 208 | * removed! |
| 209 | * removed! |
| 210 | * removed! |
| 211 | * |
| 212 | * removed! |
| 213 | * removed! |
| 214 | * removed! |
| 215 | * |
| 216 | * removed! |
| 217 | * removed! |
| 218 | * removed! |
| 219 | * |
| 220 | * removed! |
| 221 | * removed! |
| 222 | * removed! |
| 223 | * |
| 224 | * removed! |
| 225 | * removed! |
| 226 | * removed! |
| 227 | * |
| 228 | * removed! |
| 229 | * removed! |
| 230 | * removed! |
| 231 | * |
| 232 | * removed! |
| 233 | * removed! |
| 234 | * removed! |
| 235 | * |
| 236 | * removed! |
| 237 | * removed! |
| 238 | * removed! |
| 239 | * |
| 240 | * removed! |
| 241 | * removed! |
| 242 | * removed! |
| 243 | * |
| 244 | * removed! |
| 245 | * removed! |
| 246 | * removed! |
| 247 | * |
| 248 | * removed! |
| 249 | * removed! |
| 250 | * |
| 251 | * removed! |
| 252 | * removed! |
| 253 | * removed! |
| 254 | * |
| 255 | * removed! |
| 256 | * removed! |
| 257 | * |
| 258 | * removed! |
| 259 | * removed! |
| 260 | * removed! |
| 261 | * |
| 262 | * removed! |
| 263 | * removed! |
| 264 | * removed! |
| 265 | * removed! |
| 266 | * removed! |
| 267 | * |
| 268 | * removed! |
| 269 | * removed! |
| 270 | * removed! |
| 271 | *------------------------------------------------------------------------------ |
| 272 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 273 | *============================================================================== |
| 274 | *******************************************************************************/ |
| 275 | |
| 276 | #ifndef NAND_FDM_H |
| 277 | #define NAND_FDM_H |
| 278 | |
| 279 | |
| 280 | /******************************************************************************* |
| 281 | * Include Header Files |
| 282 | * FLASH_DISKDRV_DEBUG indicates simulation environment |
| 283 | *******************************************************************************/ |
| 284 | #ifdef __MTK_TARGET__ //Keneng |
| 285 | #include "flash_opt.h" |
| 286 | #endif |
| 287 | #if defined(FLASH_DISKDRV_DEBUG) && !defined(__MTK_TARGET__) |
| 288 | #include <stdio.h> |
| 289 | #include <stdlib.h> |
| 290 | #include <assert.h> |
| 291 | #else |
| 292 | // RHR Remove #include "kal_release.h" |
| 293 | #endif |
| 294 | |
| 295 | // RHR Remove #include <string.h> |
| 296 | // Add for RHR |
| 297 | #include "fs_type.h" |
| 298 | // RHR Remove #include "kal_non_specific_general_types.h" |
| 299 | #include "kal_general_types.h" |
| 300 | // Add for RHR |
| 301 | /******************************************************************************* |
| 302 | * Compiler definition |
| 303 | *******************************************************************************/ |
| 304 | #if defined(__MTK_TARGET__) |
| 305 | #ifdef __DYNAMIC_SWITCH_CACHEABILITY__ |
| 306 | #if defined (__ARMCC_VERSION) |
| 307 | #define __nandfdm_cache_align(x) __attribute__ ((aligned(x), zero_init, section ("DYNAMICCACHEABLEZI_C"))) |
| 308 | #elif defined (__GNUC__) |
| 309 | #define __nandfdm_cache_align(x) __attribute__ ((aligned(x), section ("DYNAMICCACHEABLEZI_C"))) |
| 310 | #endif /* ARMCC , GNUC */ |
| 311 | |
| 312 | #else |
| 313 | #define __nandfdm_cache_align(x) |
| 314 | #endif |
| 315 | #else /* __MTK_TARGET__ */ |
| 316 | #define __nandfdm_cache_align(x) |
| 317 | #endif /* __MTK_TARGET__ */ |
| 318 | |
| 319 | /******************************************************************************* |
| 320 | * parameter definition |
| 321 | *******************************************************************************/ |
| 322 | |
| 323 | //#define POWERLOSS_TEST // power recovery test in simulation |
| 324 | //#define ERROR_HANDLING_TEST // error handling test in simulation |
| 325 | #define DDWORD_INVALID ((kal_uint64)~0) |
| 326 | #define DWORD_INVALID 0xFFFFFFFF |
| 327 | #define WORD_INVALID 0xFFFF |
| 328 | #define BYTE_INVALID 0xFF |
| 329 | #define FDM_ERROR 1 |
| 330 | #define FDM_NO_ERROR 0 |
| 331 | |
| 332 | /* Public drive size customization constraints */ |
| 333 | #define NAND_MINIMUM_PARTITION_SIZE (400) |
| 334 | #define MAX_DATA_SIZE 2048 // Max NAND page size used for MMU. |
| 335 | |
| 336 | #if defined(__NAND_FDM_50__) |
| 337 | |
| 338 | #include "NAND_MTD_FDM50_internal.h" |
| 339 | #include "NAND_DAL.h" |
| 340 | #include "NAND_DAL_internal.h" |
| 341 | |
| 342 | |
| 343 | |
| 344 | // If support RAW disk |
| 345 | #define RAW_DISK_INDEX 5 |
| 346 | |
| 347 | #define NUM_ACTIVESLOT 5 |
| 348 | #define NUM_ACTIVESECT 4 // This number should be one less than NUM_ACTIVESLOT because need to consider the power-loss. |
| 349 | |
| 350 | // Block mark in spare area. |
| 351 | #define BM_LBM 0x6688 |
| 352 | #define BM_PMT 0x8866 |
| 353 | #define BM_NONBMR 0xf0d0 |
| 354 | #define BM_BRMT 0x0d0f |
| 355 | #define BM_FDM4XCTL 0xf00f |
| 356 | #define BRMT_FDM52 0x5200 |
| 357 | #define BM_RAW 0x7264 // Raw disk, rd |
| 358 | |
| 359 | // Newest data location. |
| 360 | #define SOURCEDATA_NONBMR 0 |
| 361 | #define SOURCEDATA_BMR 1 |
| 362 | #define SOURCEDATA_DATA 2 |
| 363 | |
| 364 | #define R_SHIFT 10 // Region shift bit number. |
| 365 | #define LSMT_SECTORNUM 5 // 2K for LSMT and 512 for active block information. |
| 366 | #define LSMT_SIZE 1024 |
| 367 | #define BRMT_SIZE 256 // The number of entries in BRMT load into RAM one time. |
| 368 | #define PMT_SIZE 512 // The number of entries in PMT. |
| 369 | #define NUM_OF_ZONES 8 |
| 370 | #define NUM_OF_BANK 8 |
| 371 | #define NUM_OF_REGION 8 //** Max number of regions per zone. This is used to save LSMT block address. |
| 372 | #define PSECTION_NUM_R 1024 |
| 373 | #define LSECTION_NUM_R 1010 |
| 374 | #define NUM_ERASE_QUEUE 14 |
| 375 | #define BMR_THRESHOLD 16 |
| 376 | |
| 377 | #define LSMT_EMPTY 0x8000 |
| 378 | #define LSMT_NOT_EMPTY 0x7fff |
| 379 | #define LSMT_NOT_REMAP 0x4000 |
| 380 | #define LSMT_REMAP 0xbfff |
| 381 | #define LSMT_SS 0x3000 |
| 382 | #define LSMT_VALID 0x0800 |
| 383 | #define LSMT_PSA 0x07ff |
| 384 | |
| 385 | |
| 386 | #define NONBMR_INVALID 0 |
| 387 | #define NONBMR_ONLYVALID_AFTER_BMRLAST 1 |
| 388 | #define NONBMR_VALID 2 |
| 389 | |
| 390 | #ifdef __MTK_TARGET__ |
| 391 | #include <ex_public.h> |
| 392 | #endif |
| 393 | |
| 394 | |
| 395 | // Structure definition for FDM |
| 396 | |
| 397 | typedef struct |
| 398 | { |
| 399 | kal_uint16 LSectionAddr; |
| 400 | kal_uint16 BMR_PSection; |
| 401 | kal_uint16 BMR_LastPage; |
| 402 | kal_uint16 NonBMR_PSection; |
| 403 | kal_uint16 NonBMR_LastPage; |
| 404 | kal_uint16 NonBMR_TablePage; |
| 405 | kal_uint16 NumNoUse; |
| 406 | } ACTIVE_INFO; |
| 407 | |
| 408 | typedef struct |
| 409 | { |
| 410 | kal_uint16 PSectionAddr; |
| 411 | kal_uint16 EmptyPageAddr; |
| 412 | kal_uint8 CurActive; |
| 413 | } PMT_INFO; |
| 414 | |
| 415 | typedef struct |
| 416 | { |
| 417 | kal_uint32 total_FAT_sectors; // total sectors that FAT can use |
| 418 | kal_uint32 partition_sectors; // partiton sectors that FAT can use |
| 419 | } FAT_INFO; |
| 420 | |
| 421 | typedef struct |
| 422 | { |
| 423 | kal_uint16 PSect; |
| 424 | kal_uint16 Page; |
| 425 | } LSMT_INFO; |
| 426 | |
| 427 | typedef struct |
| 428 | { |
| 429 | kal_uint16 SectionBuf[16]; |
| 430 | kal_uint8 Head; |
| 431 | kal_uint8 Tail; |
| 432 | } ERASE_QUEUE; |
| 433 | |
| 434 | |
| 435 | |
| 436 | typedef struct |
| 437 | { |
| 438 | kal_uint8 Zone; |
| 439 | kal_uint8 NewZone; |
| 440 | kal_uint8 Region; |
| 441 | kal_uint8 NewRegion; |
| 442 | kal_uint16 LSect; |
| 443 | kal_uint16 PSect; |
| 444 | kal_uint16 LPage; |
| 445 | kal_uint16 PPage; |
| 446 | } ADDR_INFO; |
| 447 | |
| 448 | typedef struct |
| 449 | { |
| 450 | kal_uint16 LSectAddr; |
| 451 | kal_uint16 NumCycles; |
| 452 | } WEAR_INFO; |
| 453 | |
| 454 | #if defined(__NANDFDM_TOTAL_BBM__) |
| 455 | |
| 456 | typedef union _FDMTABLE { |
| 457 | struct { |
| 458 | kal_uint32 Sector[1024]; |
| 459 | } All; |
| 460 | struct { |
| 461 | kal_uint16 LSM[LSMT_SIZE]; // Map logical to physical block. |
| 462 | kal_uint16 PMT[PMT_SIZE]; // Map logical to physical page. Need to enlarge in case of MLC+interleave+2P (128*2*2) |
| 463 | // kal_uint16 BRMT[BRMT_SIZE]; // Map bad block into good block in replacement area. |
| 464 | kal_uint16 RESERVRD[BRMT_SIZE]; // Map bad block into good block in replacement area. |
| 465 | kal_uint16 Buffer[256]; // Temp buffer. |
| 466 | } T; |
| 467 | struct { |
| 468 | kal_uint16 BRMT[2048]; // Low level format use. One time 4K write for future 4K page flash. |
| 469 | } A; |
| 470 | struct { |
| 471 | kal_uint8 Sector[8][512]; |
| 472 | } S; |
| 473 | } FDM_TABLE; |
| 474 | |
| 475 | typedef struct |
| 476 | { |
| 477 | kal_uint8 RegionNum; |
| 478 | kal_uint16 LSectionNum; |
| 479 | kal_uint16 PSectionNumLastR; |
| 480 | kal_uint16 LSectionNumLastR; |
| 481 | kal_uint16 RegionInitMask; |
| 482 | LSMT_INFO LSMT[NUM_OF_REGION]; |
| 483 | } ZONE_INFO; |
| 484 | |
| 485 | typedef struct |
| 486 | { |
| 487 | kal_bool ParameterReady; |
| 488 | kal_bool NoReplace; |
| 489 | kal_uint16 BRMT_Addr; |
| 490 | kal_uint16 BRMT_LastPSection; // Global , must be (0x8000|xxxx) |
| 491 | kal_uint16 ReplaceBeginSection; // Global , must be (0x8000|xxxx) |
| 492 | kal_uint16 ReplaceBlockBegin[NUM_OF_BANK]; // Global , must be (0x8000|xxxx) |
| 493 | kal_uint16 CurSectorInRAM; |
| 494 | kal_uint16 LastPage; |
| 495 | kal_uint16 BRMT_Table[BRMT_SIZE]; // Map bad block into good block in replacement area. |
| 496 | } BBM_BRMT_INFO; |
| 497 | |
| 498 | typedef struct |
| 499 | { |
| 500 | kal_uint8 PageNumInBuffer; |
| 501 | kal_uint8 CurActive; |
| 502 | kal_bool NeedRebuildAll; |
| 503 | kal_bool WriteProtect; |
| 504 | kal_bool PMTInRAMModified; |
| 505 | kal_bool NewActive; |
| 506 | kal_uint16 TotalPSectionNum; |
| 507 | ERASE_QUEUE EraseQueue; |
| 508 | ZONE_INFO ZoneInfo[NUM_OF_ZONES]; |
| 509 | ACTIVE_INFO ActiveInfo[NUM_ACTIVESLOT]; |
| 510 | FDM_TABLE FDMTable; |
| 511 | PMT_INFO PMTInfo; |
| 512 | WEAR_INFO WearInfo; |
| 513 | kal_uint16 DATA_PSection; |
| 514 | kal_uint16 DataBank[NUM_OF_BANK]; |
| 515 | kal_uint16 NewBank[NUM_OF_BANK]; |
| 516 | kal_uint16 BMRBank[NUM_OF_BANK]; |
| 517 | kal_uint16 NonBMRBank[NUM_OF_BANK]; |
| 518 | kal_uint16 NewPSect; |
| 519 | kal_uint16 ActiveOrder; |
| 520 | #if defined(__NANDFDM_MULTI_INSTANCE__) |
| 521 | kal_uint8 DiskIndex; |
| 522 | kal_bool is_mount; |
| 523 | #endif // defined(__NANDFDM_MULTI_INSTANCE__) |
| 524 | } NANDFDM5_DATA; |
| 525 | |
| 526 | #else // defined(__NANDFDM_TOTAL_BBM__) |
| 527 | typedef union _FDMTABLE { |
| 528 | struct { |
| 529 | kal_uint32 Sector[1024]; |
| 530 | } All; |
| 531 | struct { |
| 532 | kal_uint16 LSM[LSMT_SIZE]; // Map logical to physical block. |
| 533 | kal_uint16 PMT[PMT_SIZE]; // Map logical to physical page. Need to enlarge in case of MLC+interleave+2P (128*2*2) |
| 534 | kal_uint16 BRMT[BRMT_SIZE]; // Map bad block into good block in replacement area. |
| 535 | kal_uint16 Buffer[256]; // Temp buffer. |
| 536 | } T; |
| 537 | struct { |
| 538 | kal_uint16 BRMT[2048]; // Low level format use. One time 4K write for future 4K page flash. |
| 539 | } A; |
| 540 | struct { |
| 541 | kal_uint8 Sector[8][512]; |
| 542 | } S; |
| 543 | } FDM_TABLE; |
| 544 | |
| 545 | typedef struct |
| 546 | { |
| 547 | kal_uint16 BRMT_Addr[NUM_OF_ZONES]; |
| 548 | kal_uint16 ReplaceBlockBegin[NUM_OF_BANK]; |
| 549 | kal_uint16 CurSectorInRAM; |
| 550 | kal_uint16 LastPage[NUM_OF_ZONES]; |
| 551 | } BRMT_INFO; |
| 552 | |
| 553 | typedef struct |
| 554 | { |
| 555 | kal_uint16 LSectionNum; |
| 556 | kal_bool NoReplace; |
| 557 | kal_uint8 ReplaceBeginRegion; |
| 558 | kal_uint16 ReplaceBeginSection; |
| 559 | kal_uint16 PSectionNumLastR; |
| 560 | kal_uint16 LSectionNumLastR; |
| 561 | kal_uint8 RegionNum; |
| 562 | kal_uint16 RegionInitMask; |
| 563 | LSMT_INFO LSMT[NUM_OF_REGION]; |
| 564 | } ZONE_INFO; |
| 565 | |
| 566 | typedef struct |
| 567 | { |
| 568 | kal_uint8 PageNumInBuffer; |
| 569 | kal_uint8 CurActive; |
| 570 | kal_bool WriteProtect; |
| 571 | kal_bool PMTInRAMModified; |
| 572 | kal_bool NewActive; |
| 573 | kal_uint16 TotalPSectionNum; |
| 574 | ERASE_QUEUE EraseQueue; |
| 575 | ZONE_INFO ZoneInfo[NUM_OF_ZONES]; |
| 576 | BRMT_INFO BRMTInfo; |
| 577 | ACTIVE_INFO ActiveInfo[NUM_ACTIVESLOT]; |
| 578 | FDM_TABLE FDMTable; |
| 579 | PMT_INFO PMTInfo; |
| 580 | WEAR_INFO WearInfo; |
| 581 | kal_uint16 DATA_PSection; |
| 582 | kal_uint16 DataBank[NUM_OF_BANK]; |
| 583 | kal_uint16 NewBank[NUM_OF_BANK]; |
| 584 | kal_uint16 BMRBank[NUM_OF_BANK]; |
| 585 | kal_uint16 NonBMRBank[NUM_OF_BANK]; |
| 586 | kal_uint16 NewPSect; |
| 587 | kal_uint16 ActiveOrder; |
| 588 | #if defined(__NANDFDM_MULTI_INSTANCE__) |
| 589 | kal_uint8 DiskIndex; |
| 590 | kal_bool is_mount; |
| 591 | #endif // defined(__NANDFDM_MULTI_INSTANCE__) |
| 592 | } NANDFDM5_DATA; |
| 593 | |
| 594 | #endif // defined(__NANDFDM_TOTAL_BBM__) |
| 595 | |
| 596 | typedef struct |
| 597 | { |
| 598 | #ifndef __MTK_TARGET__ |
| 599 | const char *file_name; |
| 600 | void *flash_device; |
| 601 | #endif |
| 602 | // kal_uint32 *MainBuf; |
| 603 | // kal_uint32 *SpareBuf; |
| 604 | FAT_INFO flash_info; |
| 605 | #if defined(__NANDFDM_MULTI_INSTANCE__) |
| 606 | NANDFDM5_DATA NAND_FDMData; |
| 607 | FLASH_INFO FlashInfo; |
| 608 | ADDR_INFO CurAddr; |
| 609 | #endif // defined(__NANDFDM_MULTI_INSTANCE__) |
| 610 | } NAND_FLASH_DRV_DATA; |
| 611 | |
| 612 | // FDM I/F function declaration |
| 613 | |
| 614 | kal_int32 FDM5_MountDevice (void * DriveData, int DeviceNumber, int DeviceType, kal_uint32 Flags); |
| 615 | kal_int32 FDM5_ShutDown (void * DriveData); |
| 616 | kal_int32 FDM5_ReadSectors (void * DriveData, kal_uint32 Sector, kal_uint32 Sectors, void * Data); |
| 617 | kal_int32 FDM5_WriteSectors (void * DriveData, kal_uint32 Sector, kal_uint32 Sectors, void * Data); |
| 618 | kal_int32 FDM5_MediaChanged (void * DriveData); |
| 619 | kal_int32 FDM5_DiscardSectors (void * DriveData, kal_uint32 Sector, kal_uint32 Sectors); |
| 620 | kal_int32 FDM5_GetDiskGeometry (void * DriveData, FS_PartitionRecord * DiskGeometry, kal_uint8 * MediaDescriptor); |
| 621 | kal_int32 FDM5_LowLevelFormat (void * DriveData, const char * DeviceName, FS_FormatCallback Progress, kal_uint32 Flags); |
| 622 | int FDM5_CopySectors (void *DriveData, kal_uint32 SrcSector , kal_uint32 DstSector, kal_uint32 Sectors); |
| 623 | kal_int32 FDM5_DiskNeedFormat (void * DriveData); |
| 624 | kal_int32 FDM5_OTPAccess (void * DriveData, kal_int32 accesstype, kal_uint32 Offset, void * BufferPtr, kal_uint32 Length); |
| 625 | kal_int32 FDM5_OTPQueryLength (void * DriveData, kal_uint32 *LengthPtr); |
| 626 | kal_int32 FDM5_IOCtrl (void * DriveData, UINT CtrlAction, void * CtrlData); |
| 627 | kal_int32 FDM5_LSN2PPN(void * DriveData, kal_uint32 Sector); |
| 628 | #if defined(_NAND_FLASH_BOOTING_) |
| 629 | kal_uint32 EraseRawDataItem(kal_uint32 block_idx); |
| 630 | kal_uint32 ReadRawDataItem(kal_uint32 block_idx, kal_uint32 page_idx, kal_uint32 length, kal_uint8* data_ptr); |
| 631 | kal_uint32 WriteRawDataItem(kal_uint32 block_idx, kal_uint32 page_idx, kal_uint32 length, kal_uint8* data_ptr); |
| 632 | #endif //#if defined(_NAND_FLASH_BOOTING_) |
| 633 | #if defined(__AUDIO_DSP_LOWPOWER__) |
| 634 | void FDM5_Fill_PSTMap(void * DriveData, FS_NANDPMapQuery *pPSTMapQuery); |
| 635 | #endif //#if defined(__AUDIO_DSP_LOWPOWER__) |
| 636 | |
| 637 | |
| 638 | |
| 639 | #else // __NAND_FDM_50__ |
| 640 | |
| 641 | |
| 642 | #include "NAND_MTD.h" |
| 643 | #include "NAND_MTD_internal.h" |
| 644 | |
| 645 | |
| 646 | #if !defined __NFI_VERSION2__ |
| 647 | #define LSN_INVALID (DWORD_INVALID) |
| 648 | #else |
| 649 | #define LSN_INVALID (0x00FFFFFF) |
| 650 | #endif |
| 651 | |
| 652 | |
| 653 | // FIXME - Remember to rocover correct value check in. |
| 654 | #define POOL_SIZE 12 // used for non-data blocks in a region (double in first region) |
| 655 | #define GC_THRESHOLD 25 |
| 656 | #define TRY_TIMES 3 |
| 657 | |
| 658 | |
| 659 | #define MAX_REGION_NUM 72 // max disk volumn = 2GB |
| 660 | #define MAX_PAGES_PER_BLOCK 64 |
| 661 | #define MAX_SECTORS_PER_PAGE 4 |
| 662 | |
| 663 | #define MAX_PAGE_SIZE 2112 |
| 664 | #define MAX_SPARE_SIZE 64 |
| 665 | #define SECTOR_SIZE 512 |
| 666 | #define MAX_CTRL_LOG_NUM 5 /*Max number of control_log block*/ |
| 667 | /* page size */ |
| 668 | enum |
| 669 | { |
| 670 | PAGE_512, |
| 671 | PAGE_2K |
| 672 | }; |
| 673 | |
| 674 | /* indicate if write ECC fields while program page */ |
| 675 | enum |
| 676 | { |
| 677 | ECC_SKIP = 0, // don't program spare area |
| 678 | ECC_FIRST_HALF, // only program first and second ECC fields |
| 679 | ECC_SECOND_HALF, // only program third and fourth ECC fields |
| 680 | ECC_WHOLE, // program whole ECC fields |
| 681 | ECC_NFB // program whole ECC fields in NFB format |
| 682 | }; |
| 683 | |
| 684 | |
| 685 | |
| 686 | /******************************************************************************* |
| 687 | * block/page/sector state ID |
| 688 | *******************************************************************************/ |
| 689 | #define BLOCK_EMPTY 0xFF |
| 690 | #define BLOCK_CONTROL 0xFC |
| 691 | #define BLOCK_ALLOCATED 0xAF /*use to avoid double allocate at LocateBlock or LocateEmptyBlock*/ |
| 692 | #define BLOCK_ACTIVE 0xAE |
| 693 | #define BLOCK_DATA 0xAC |
| 694 | #define BLOCK_BAD 0x00 |
| 695 | #define BLOCK_NG_CONTROL 0xC3 |
| 696 | #define BLOCK_CTRL_LOG 0xC0 // Old control block, reserve as a record |
| 697 | #define BLOCK_COPY_DST 0xAA /*copy destination block*/ |
| 698 | #define BLOCK_MERGE_BMR0 0xA9 /*active merge destination when BMR = 0*/ |
| 699 | #define BLOCK_MERGE_BMR1 0xA8 /*active merge destination when BMR = 1*/ |
| 700 | #define BLOCK_ERASING 0x07 /*Ready to erase*/ |
| 701 | |
| 702 | #define PAGE_EMPTY 0xFF |
| 703 | #define PAGE_DATA 0x0F |
| 704 | #define PAGE_DELETED 0x00 |
| 705 | #define PAGE_LOG 0x3F /*For log section - 2007/05/29 Yehudi*/ |
| 706 | |
| 707 | #define SECTOR_EMPTY 0xFF |
| 708 | #define SECTOR_DATA 0x0F |
| 709 | #define SECTOR_CONTROL 0xF0 // control block header |
| 710 | #define SECTOR_CTRL_LOG 0xC0 // Old control block, reserve as a record |
| 711 | #define SECTOR_BST 0x33 // block status table |
| 712 | #define SECTOR_LBM 0xCC // logical block mapping |
| 713 | #define SECTOR_SPOT 0x55 // yoda add for reserving spot |
| 714 | #define SECTOR_DELETED 0x00 |
| 715 | #define SECTOR_LOG 0x3F /*For log section - 2007/05/29 Yehudi*/ |
| 716 | |
| 717 | /******************************************************************************* |
| 718 | * Macro definition used for code simplification |
| 719 | *******************************************************************************/ |
| 720 | #define R_BLOCKS 256 /* Default(Maximun) value of block number of region. REGION_B(b) is the real block number of region(b)*/ |
| 721 | #define B_PAGES (D->flash_info.pages_per_block) |
| 722 | #define P_SECTORS ((D->flash_info.page_type==PAGE_2K) ? 4 : 1) |
| 723 | #define DATA_SIZE ((D->flash_info.page_type==PAGE_2K) ? 2048 : 512) |
| 724 | #define SPARE_SIZE ((D->flash_info.page_type==PAGE_2K) ? 64 : 16) |
| 725 | #define LOG_BLOCKS ((D->flash_info.page_type==PAGE_2K) ? 3 : 6) /*Block number of log section - Yehudi*/ |
| 726 | #define PAGE_SIZE ((DATA_SIZE)+(SPARE_SIZE)) |
| 727 | #define P_SHIFTS ((D->flash_info.page_type==PAGE_2K) ? 2 : 0) |
| 728 | |
| 729 | /* region info */ |
| 730 | #define CUR_R (D->region_info.current_region) |
| 731 | #define BASE_B (D->region_info.base_block) |
| 732 | #define REGION_B(b) (D->region_info.region_block[(b)]) /*2007/05/26 Yehudi*/ |
| 733 | |
| 734 | /* control info */ |
| 735 | #define LBM(b) (D->control_table.block_mapping[(b)]) |
| 736 | #define BST(b) (D->control_table.block_state[(b)]) |
| 737 | #define CNT_PB (D->control_info.physical_block) |
| 738 | |
| 739 | /* active info */ |
| 740 | #define ACT_LB (D->active_info.logical_block) |
| 741 | #define ACT_PB (D->active_info.physical_block) |
| 742 | #define ACT_LPM(p) (D->active_info.page_mapping[(p)]) |
| 743 | |
| 744 | #define IS_VALID_DATA_BLOCK(b) (LBM(b)!=BYTE_INVALID || (LBM(b)==255 && LBM(255)==b)) |
| 745 | #define IS_INVALID_DATA_BLOCK(b)(LBM(b)==BYTE_INVALID && LBM(255) != b) |
| 746 | #define SET_FLAG_FOR_PHY255(log_b,phy_b)\ |
| 747 | {\ |
| 748 | if( ((kal_uint8)(phy_b)) == 255)\ |
| 749 | LBM(255) = (kal_uint8)(log_b);\ |
| 750 | } |
| 751 | |
| 752 | #define IS_2K_CNTL_TABLE(half,ptr)\ |
| 753 | ( ((half)==0) && (((spare_2k*)(ptr))->spare[0].SS == SECTOR_BST)\ |
| 754 | && (((spare_2k*)(ptr))->spare[1].SS == SECTOR_LBM) )\ |
| 755 | || ( ((half)==1) && (((spare_2k*)(ptr))->spare[2].SS == SECTOR_BST)\ |
| 756 | && (((spare_2k*)(ptr))->spare[3].SS == SECTOR_LBM) ) |
| 757 | |
| 758 | #define IS_2K_CNTL_SPOT(half,ptr)\ |
| 759 | ( ((half)==0) && (((spare_2k*)(ptr))->spare[0].SS == SECTOR_SPOT))\ |
| 760 | || ( ((half)==1) && (((spare_2k*)(ptr))->spare[2].SS == SECTOR_SPOT)) |
| 761 | |
| 762 | #define IS_2K_NEXT_CNTL_TABLE(half,ptr)\ |
| 763 | ( ((half)==0) && (((spare_2k*)(ptr))->spare[0].SS == SECTOR_EMPTY)\ |
| 764 | && (((spare_2k*)(ptr))->spare[1].SS == SECTOR_EMPTY) )\ |
| 765 | || ( ((half)==1) && (((spare_2k*)(ptr))->spare[2].SS == SECTOR_EMPTY)\ |
| 766 | && (((spare_2k*)(ptr))->spare[3].SS == SECTOR_EMPTY) ) |
| 767 | |
| 768 | #define IS_512_CNTL_TABLE(spare0,spare1)\ |
| 769 | spare_512_PS(spare0)==SECTOR_BST && spare_512_PS(spare1)==SECTOR_LBM |
| 770 | |
| 771 | #define IS_512_CNTL_SPOT(spare0,spare1)\ |
| 772 | spare_512_PS(spare0)==SECTOR_SPOT |
| 773 | |
| 774 | |
| 775 | #define IS_512_NEXT_CNTL_TABLE(spare0,spare1)\ |
| 776 | spare_512_PS(spare0)==SECTOR_EMPTY && spare_512_PS(spare1)==SECTOR_EMPTY |
| 777 | |
| 778 | /* MTK FDM signature mark */ |
| 779 | #define BAD_BLOCK_MARK_2K (0x4242) |
| 780 | #define BAD_BLOCK_MARK_512 (0x42) |
| 781 | #define MTK_SIGNATURE_MARK (0x4B544D) |
| 782 | #define FDM_SIGNATURE_MARK (0x4D4446) |
| 783 | #define FDM_CHECK_MARK_1 (0xF0) |
| 784 | #define FDM_CHECK_MARK_2 (0x0F) |
| 785 | #define FDM_NG_CONTROL_BLOCK_MARK (0x8000) /*This mark means the correct control block does not exist - Yehudi*/ |
| 786 | |
| 787 | #define FDM_TABLE_MARK_POSITION (2) /*Use by Control Table*/ |
| 788 | |
| 789 | /* MTK NAND FDM control block header layout */ |
| 790 | #define FDM_CONTROL_BACKUP_POSITION (256) |
| 791 | #define FDM_RESERVED_POOL_SIZE_POSITION (64) /*Reserve 4 byte - Yehudi*/ |
| 792 | #define FDM_VERSION_POSITION (68) /*Reserve 4 byte - Yehudi*/ |
| 793 | |
| 794 | //#define FDM_REGION_BLOCK_POSITION (72) /*Reserve 4 byte - Yehudi*/ |
| 795 | //#define FDM_TIME_INFO_POSITION (76) /*Reserve 8 byte - Yehudi*/ |
| 796 | //#define FDM_CBLK_PROGRAM_COUNT_POSITION (80) /*Reserve 4 byte - Yehudi*/ |
| 797 | /******************************************************************************* |
| 798 | * structure definition for spare area of 2k/512 page-size |
| 799 | *******************************************************************************/ |
| 800 | #ifdef __MTK_TARGET__ |
| 801 | #include <ex_public.h> |
| 802 | #else |
| 803 | #define INT_QueryExceptionStatus() (KAL_FALSE) |
| 804 | |
| 805 | // pragma is used for specific bytes in a structure |
| 806 | #pragma pack(1) |
| 807 | #endif |
| 808 | |
| 809 | typedef struct control_block_header_tag |
| 810 | { |
| 811 | kal_uint8 mtk_fdm_mark[64]; |
| 812 | kal_uint8 erase_pool_size; /*position 64*/ |
| 813 | kal_uint8 reserve1[3]; |
| 814 | kal_uint16 version_info; /*position 68*/ |
| 815 | kal_uint8 reserve2[2]; |
| 816 | kal_uint16 cur_region_block; /*position 72*/ |
| 817 | kal_uint16 next_region_block; /*position 74*/ |
| 818 | kal_uint32 create_time; /*position 76*/ |
| 819 | kal_uint64 program_count; /*position 80 (position at 8 byte alignment for PC )*/ |
| 820 | }control_block_header; /*The total size should not over FDM_CONTROL_BACKUP_POSITION - Yehudi*/ |
| 821 | |
| 822 | #if !defined __NFI_VERSION2__ |
| 823 | typedef struct spare_2k_component_tag |
| 824 | { |
| 825 | kal_uint16 BI; // block info |
| 826 | kal_uint8 SS; // sector state |
| 827 | kal_uint8 Reserved0; |
| 828 | kal_uint32 LSN; // logical sector number |
| 829 | kal_uint32 ECC; |
| 830 | kal_uint16 Reserved; /*In FDM 4.3, spare[2].Reserved & spare[3].Reserved will put fdm_data_time_info_struct*/ |
| 831 | kal_uint16 LSN_Chk; |
| 832 | } spare_2k_component; |
| 833 | |
| 834 | /* Use spare[3]'s Reserved0 as page state */ |
| 835 | #define spare_2k_PS(p) ( ((spare_2k*)(p))->spare[3].Reserved0 ) |
| 836 | #define spare_2k_LCHK(p, s) ( ((spare_2k*)(p))->spare[s].LSN_Chk ) |
| 837 | #define spare_2k_VER(p) ( ((spare_2k*)(p))->spare[0].LSN_Chk ) |
| 838 | #define spare_2k_HCHK(p) ( ((spare_2k*)(p))->spare[0].Reserved0 ) |
| 839 | |
| 840 | #else |
| 841 | typedef struct spare_2k_component_tag |
| 842 | { |
| 843 | kal_uint16 BI; // block info |
| 844 | kal_uint8 PC; // Page state/FDM_Chk_MARK |
| 845 | kal_uint8 SS; // sector state |
| 846 | kal_uint32 LSN:24; // logical sector number |
| 847 | kal_uint32 LSN_Chk:8; // logical sector number chksum |
| 848 | kal_uint32 ECC[2]; |
| 849 | } spare_2k_component; |
| 850 | |
| 851 | #define spare_2k_PS(p) ( ((spare_2k*)(p))->spare[3].PC ) |
| 852 | #define spare_2k_LCHK(p, s) ( ((spare_2k*)(p))->spare[s].LSN_Chk ) |
| 853 | #define spare_2k_HCHK(p) ( ((spare_2k*)(p))->spare[0].PC ) |
| 854 | |
| 855 | #endif |
| 856 | |
| 857 | typedef struct spare_2k_tag |
| 858 | { |
| 859 | spare_2k_component spare[4]; |
| 860 | } spare_2k; |
| 861 | |
| 862 | #if !defined __NFI_VERSION2__ |
| 863 | typedef struct spare_512_tag |
| 864 | { |
| 865 | kal_uint32 ECC; |
| 866 | kal_uint8 SS; // sector state |
| 867 | kal_uint8 BI; // block info |
| 868 | kal_uint8 Reserved[4]; /*In FDM 4.3, it will put fdm_data_time_info_struct*/ |
| 869 | kal_uint16 LSN_Chk; |
| 870 | kal_uint32 LSN; // logical sector number |
| 871 | } spare_512; |
| 872 | |
| 873 | #define spare_512_PS(p) ( ((spare_512*)(p))->SS ) |
| 874 | #define spare_512_LCHK(p) ( ((spare_512*)(p))->LSN_Chk ) |
| 875 | #define spare_512_VER(p) ( ((spare_512*)(p))->LSN_Chk ) |
| 876 | #define spare_512_HCHK(p) ( ((spare_512*)(p))->Reserved[0] ) |
| 877 | |
| 878 | #else |
| 879 | typedef struct spare_512_tag |
| 880 | { |
| 881 | kal_uint32 LSN:24; // logical sector number |
| 882 | kal_uint32 LSN_Chk:8; // logical sector number chksum |
| 883 | kal_uint8 Reserved[1]; |
| 884 | kal_uint8 BI; // block info |
| 885 | kal_uint8 PC; // FDM_Chk_MARK |
| 886 | kal_uint8 SS; // sector state |
| 887 | kal_uint32 ECC[2]; |
| 888 | } spare_512; |
| 889 | |
| 890 | #define spare_512_PS(p) ( ((spare_512*)(p))->SS ) |
| 891 | #define spare_512_LCHK(p) ( ((spare_512*)(p))->LSN_Chk ) |
| 892 | #define spare_512_HCHK(p) ( ((spare_512*)(p))->PC ) |
| 893 | |
| 894 | #endif |
| 895 | |
| 896 | #ifndef __MTK_TARGET__ |
| 897 | #pragma pack() |
| 898 | #endif |
| 899 | |
| 900 | /******************************************************************************* |
| 901 | * structure definition for driver data |
| 902 | *******************************************************************************/ |
| 903 | typedef enum |
| 904 | { |
| 905 | BBMARK_1, // First and second page of each block. |
| 906 | BBMARK_2 // First and last page of each block. |
| 907 | } BBMARK_STYLE; |
| 908 | |
| 909 | typedef struct flash_info_tag |
| 910 | { |
| 911 | kal_uint32 id_data[2]; |
| 912 | kal_uint16 block_num; /*total FAT block number, not include log block - Yehudi*/ |
| 913 | kal_uint8 region_num; |
| 914 | kal_uint8 pages_per_block; |
| 915 | kal_uint8 page_type; |
| 916 | kal_uint8 address_cycle; |
| 917 | kal_uint8 io_width; |
| 918 | kal_uint8 log_block; /*block number of log section - Yehudi*/ |
| 919 | kal_uint16 bad_num; |
| 920 | kal_uint32 total_FAT_sectors; // total sectors that FAT can use |
| 921 | kal_uint32 partition_sectors; // partiton sectors that FAT can use |
| 922 | kal_uint32 region_sectors[MAX_REGION_NUM]; // LBB design |
| 923 | kal_uint32 TotalSize; |
| 924 | BBMARK_STYLE BBMarkStyle; |
| 925 | } flash_info_struct; |
| 926 | |
| 927 | |
| 928 | typedef struct region_info_tag |
| 929 | { |
| 930 | |
| 931 | kal_uint16 control_block[MAX_REGION_NUM]; |
| 932 | kal_uint16 region_block[MAX_REGION_NUM+1]; /*block number of the region - Yehudi*/ |
| 933 | kal_uint32 base_block; |
| 934 | /* Adjust to be 4 byte alignment */ |
| 935 | |
| 936 | kal_uint8 control_next_index[MAX_REGION_NUM]; // next programmable page |
| 937 | kal_uint8 current_region; |
| 938 | kal_uint8 erase_pool[MAX_REGION_NUM]; // LBB design |
| 939 | kal_uint32 base_LSN; |
| 940 | kal_uint32 end_LSN; |
| 941 | } region_info_struct; |
| 942 | |
| 943 | |
| 944 | typedef struct control_info_tag |
| 945 | { |
| 946 | kal_uint16 physical_block; |
| 947 | kal_uint8 next_index; // next programmable page index ?? -- kirk |
| 948 | kal_uint8 modified_flag; |
| 949 | kal_uint16 version; |
| 950 | } control_info_struct; |
| 951 | |
| 952 | |
| 953 | typedef struct control_table_tag |
| 954 | { |
| 955 | kal_uint8 block_state[R_BLOCKS]; // physical block state |
| 956 | kal_uint8 erase_count[R_BLOCKS]; // erase count of physical block |
| 957 | kal_uint8 block_mapping[R_BLOCKS]; // map logical to physical block |
| 958 | } control_table_struct; |
| 959 | |
| 960 | typedef struct ctrl_table_extra_info_tag |
| 961 | { |
| 962 | kal_uint8 reserve1[2]; |
| 963 | kal_uint8 table_mark; /* controbl table mark, must at position FDM_TABLE_MARK_POSITION*/ |
| 964 | kal_uint8 reserve2[9]; |
| 965 | kal_uint32 create_time; /*position 12*/ |
| 966 | kal_uint64 program_count; /*position 16 (position at 8 byte alignment for PC )*/ |
| 967 | kal_uint16 active_logical_block; |
| 968 | kal_uint16 active_physical_block; |
| 969 | kal_uint8 active_bmr_flag; |
| 970 | kal_uint8 active_next_index; // next programmable page index |
| 971 | kal_uint32 code_md5[16/4]; /*position 32: MD5 of BST and LBM, size must match 2rd parameter of CHE_md5_finish() */ /*MAUI_00618203*/ |
| 972 | }ctrl_table_extra_info; |
| 973 | |
| 974 | typedef enum |
| 975 | { |
| 976 | CLOSE_REGION_MARK = 0x20, |
| 977 | NORMAL_SHUTDOWN_MARK = 0x31, |
| 978 | MERGEACTIVE_MARK1 = 0x40, |
| 979 | MERGEACTIVE_MARK2 = 0x42, |
| 980 | MERGEACTIVE_MARK3 = 0x44, |
| 981 | RECONSTRUCTED_MARK = 0x52, |
| 982 | COPY_MARK = 0x60, |
| 983 | SPOT_MARK = 0x62, |
| 984 | NONE_MARK = 0xFF |
| 985 | } ControblTableMark; |
| 986 | |
| 987 | typedef struct active_info_tag |
| 988 | { |
| 989 | kal_uint16 logical_block; // logical number of active block |
| 990 | kal_uint16 physical_block; // physical number of active block |
| 991 | kal_uint8 next_index; // next programmable page index |
| 992 | kal_uint8 bmr_flag; // indicate if active block fits block mappingn rule |
| 993 | /*kal_uint8 first_page;*/ |
| 994 | kal_uint8 page_mapping[MAX_PAGES_PER_BLOCK]; // map logical to physical page |
| 995 | } active_info_struct; |
| 996 | |
| 997 | |
| 998 | typedef struct sequential_info_tag |
| 999 | { |
| 1000 | kal_uint16 physical_block; // which physical block this information is for. |
| 1001 | kal_uint8 last_index; // The page offset on which the last programming operation is performed. |
| 1002 | } seq_info_struct; |
| 1003 | |
| 1004 | |
| 1005 | typedef struct dup_block_tag |
| 1006 | { |
| 1007 | kal_uint16 l_block; |
| 1008 | kal_uint16 p_block; |
| 1009 | } dup_block_struct; |
| 1010 | |
| 1011 | |
| 1012 | typedef struct |
| 1013 | { |
| 1014 | NAND_MTD_DRIVER * MTD; |
| 1015 | |
| 1016 | #ifndef __MTK_TARGET__ |
| 1017 | const char * file_name; |
| 1018 | void * flash_device; |
| 1019 | #endif |
| 1020 | |
| 1021 | flash_info_struct flash_info; |
| 1022 | region_info_struct region_info; |
| 1023 | control_info_struct control_info; |
| 1024 | control_table_struct control_table; |
| 1025 | active_info_struct active_info; |
| 1026 | seq_info_struct seq_info; |
| 1027 | |
| 1028 | |
| 1029 | kal_uint32 buffer[MAX_PAGE_SIZE/sizeof(kal_uint32)]; |
| 1030 | kal_uint32 spare0[MAX_SPARE_SIZE/sizeof(kal_uint32)]; |
| 1031 | kal_uint32 spare1[MAX_SPARE_SIZE/sizeof(kal_uint32)]; |
| 1032 | //kal_uint32 badspare[MAX_SPARE_SIZE/sizeof(kal_uint32)];//TODO: should check whether this is necessary |
| 1033 | |
| 1034 | } NAND_FLASH_DRV_DATA; |
| 1035 | |
| 1036 | typedef struct fdm_global_time_info_tag |
| 1037 | { |
| 1038 | kal_uint32 Second:6; |
| 1039 | kal_uint32 Minute:6; |
| 1040 | kal_uint32 Hour:5; |
| 1041 | kal_uint32 Day:5; |
| 1042 | kal_uint32 Month:4; |
| 1043 | kal_uint32 Year2000:6; |
| 1044 | } fdm_global_time_info_struct; |
| 1045 | |
| 1046 | |
| 1047 | typedef struct fdm_data_time_info_tag |
| 1048 | { |
| 1049 | kal_uint32 Count:9; |
| 1050 | kal_uint32 Second:6; |
| 1051 | kal_uint32 Minute:6; |
| 1052 | kal_uint32 Hour:5; |
| 1053 | kal_uint32 Day:5; |
| 1054 | kal_uint32 Month:1; |
| 1055 | } fdm_data_time_info_struct; |
| 1056 | |
| 1057 | typedef struct fdm_log_section_info_tag |
| 1058 | { |
| 1059 | kal_uint8 is_init; |
| 1060 | kal_uint32 log_start_page; |
| 1061 | kal_uint32 total_page_num; |
| 1062 | kal_uint32 cur_page; |
| 1063 | kal_uint64 program_count; /*position 16 (position at 8 byte alignment for PC simulator) */ |
| 1064 | kal_uint32 buffer[MAX_PAGE_SIZE/sizeof(kal_uint32)]; |
| 1065 | kal_uint32 spare0[MAX_SPARE_SIZE/sizeof(kal_uint32)]; |
| 1066 | kal_uint32 spare1[MAX_SPARE_SIZE/sizeof(kal_uint32)]; |
| 1067 | } fdm_log_section_info_struct; |
| 1068 | /******************************************************************************* |
| 1069 | * Definition for power loss test |
| 1070 | *******************************************************************************/ |
| 1071 | #if defined(FLASH_DISKDRV_DEBUG) && defined(POWERLOSS_TEST) |
| 1072 | |
| 1073 | enum |
| 1074 | { |
| 1075 | MERGE_ACTIVE = 1, |
| 1076 | COPY_BLOCK, |
| 1077 | WRITE_SECTORS, |
| 1078 | FLUSH_TABLE, |
| 1079 | }; |
| 1080 | |
| 1081 | #include <setjmp.h> |
| 1082 | extern jmp_buf mark; |
| 1083 | extern int Test_CD_Value; |
| 1084 | #define TEST_POINT(a)\ |
| 1085 | {\ |
| 1086 | switch(a)\ |
| 1087 | {\ |
| 1088 | case MERGE_ACTIVE:\ |
| 1089 | Test_CD_Value-=1;\ |
| 1090 | break;\ |
| 1091 | case COPY_BLOCK:\ |
| 1092 | Test_CD_Value-=1;\ |
| 1093 | break;\ |
| 1094 | case WRITE_SECTORS:\ |
| 1095 | Test_CD_Value-=1;\ |
| 1096 | break;\ |
| 1097 | case FLUSH_TABLE:\ |
| 1098 | Test_CD_Value-=1;\ |
| 1099 | break;\ |
| 1100 | default:\ |
| 1101 | Test_CD_Value-=1;\ |
| 1102 | break;\ |
| 1103 | }\ |
| 1104 | if(Test_CD_Value <= 0)\ |
| 1105 | longjmp(mark, a);\ |
| 1106 | } |
| 1107 | |
| 1108 | #define START_POINT setjmp(mark) |
| 1109 | |
| 1110 | #else |
| 1111 | #define TEST_POINT(a) |
| 1112 | #define START_POINT |
| 1113 | #endif |
| 1114 | |
| 1115 | #if defined(FLASH_DISKDRV_DEBUG) && defined(ERROR_HANDLING_TEST) |
| 1116 | |
| 1117 | /* for error handling test */ |
| 1118 | |
| 1119 | extern void ProgramPageFailure(kal_int32 times); |
| 1120 | extern void ProgramSpareFailure(kal_int32 times); |
| 1121 | extern void BlockEraseFailure(kal_int32 times); |
| 1122 | extern void ReadPageFailure(kal_int32 times); |
| 1123 | extern void ReadSpareFailure(kal_int32 times); |
| 1124 | |
| 1125 | typedef enum |
| 1126 | { |
| 1127 | PAGE_WRITE, |
| 1128 | SPARE_WRITE, |
| 1129 | PAGE_READ, |
| 1130 | SPARE_READ, |
| 1131 | BLOCK_ERASE, |
| 1132 | TOTAL_OPERATIONS |
| 1133 | } Operation_Type; |
| 1134 | |
| 1135 | typedef enum |
| 1136 | { |
| 1137 | WRITEDATA_ACTIVE = 0, |
| 1138 | WRITEDATA_BLOCK, |
| 1139 | COPY_BLOCK, |
| 1140 | FLUSH_TABLE, |
| 1141 | MODIFY_TABLE, |
| 1142 | MERGE_ACTIVE, |
| 1143 | DELETE_PAGE, |
| 1144 | MARK_BAD_BLOCK, |
| 1145 | DISCARD_SECTOR, |
| 1146 | INITIALIZE_REGION_DATA, |
| 1147 | READSECTOR_512, |
| 1148 | READ_SECTOR_2K, |
| 1149 | READ_TABLE, |
| 1150 | READDATA_ACTIVE, |
| 1151 | READDATA_BLOCK, |
| 1152 | FIND_CONTROL_BAD_BLOCK, |
| 1153 | ERASE_BLOCK, |
| 1154 | FIND_TABLE, |
| 1155 | BLOCK_BMR, |
| 1156 | DELETEDATA_ACTIVE, |
| 1157 | DELETEDATA_BLOCK, |
| 1158 | POWER_RECOVERY, |
| 1159 | RECONSTRUCT_TABLE, |
| 1160 | RESTORE_DD, |
| 1161 | TOTAL_FUNCTIONS |
| 1162 | } ErrorHandling_TestCase; |
| 1163 | |
| 1164 | typedef struct |
| 1165 | { |
| 1166 | kal_uint32 triggered; // test enabled or not |
| 1167 | kal_uint32 step_id; // determine which step is allowed to go |
| 1168 | ErrorHandling_TestCase case_type; |
| 1169 | Operation_Type op_type; |
| 1170 | } test_command; |
| 1171 | |
| 1172 | extern test_command test_item[]; |
| 1173 | |
| 1174 | #define TEST_ERROR_ENABLE(function, operation, step)\ |
| 1175 | {\ |
| 1176 | test_item[function].triggered = 1;\ |
| 1177 | test_item[function].op_type = operation;\ |
| 1178 | test_item[function].case_type = function;\ |
| 1179 | test_item[function].step_id = step;\ |
| 1180 | } |
| 1181 | |
| 1182 | #define TEST_ERROR_DISABLE(function, operation, step)\ |
| 1183 | {\ |
| 1184 | if( (function == test_item[function].case_type) &&\ |
| 1185 | (step == test_item[function].step_id) )\ |
| 1186 | {\ |
| 1187 | test_item[function].triggered = 0;\ |
| 1188 | test_item[function].op_type = TOTAL_OPERATIONS;\ |
| 1189 | test_item[function].case_type = TOTAL_FUNCTIONS;\ |
| 1190 | test_item[function].step_id = 0;\ |
| 1191 | }\ |
| 1192 | } |
| 1193 | |
| 1194 | /* assert( function == test_item[function].case_type);\*/ |
| 1195 | #define TEST_ERROR_EVENT(function, step)\ |
| 1196 | {\ |
| 1197 | if( test_item[function].triggered )\ |
| 1198 | {\ |
| 1199 | if( step == test_item[function].step_id )\ |
| 1200 | {\ |
| 1201 | if( PAGE_WRITE == test_item[function].op_type )\ |
| 1202 | {\ |
| 1203 | nandlog_print("Page program error is triggered!\n");\ |
| 1204 | ProgramPageFailure(1);\ |
| 1205 | test_item[function].triggered = 0;\ |
| 1206 | }else if( SPARE_WRITE == test_item[function].op_type )\ |
| 1207 | {\ |
| 1208 | nandlog_print("Spare program error is triggered!\n");\ |
| 1209 | ProgramSpareFailure(1);\ |
| 1210 | test_item[function].triggered = 0;\ |
| 1211 | } else if( PAGE_READ == test_item[function].op_type )\ |
| 1212 | {\ |
| 1213 | nandlog_print("Page read error is triggered!\n");\ |
| 1214 | ReadPageFailure(1);\ |
| 1215 | test_item[function].triggered = 0;\ |
| 1216 | } else if( SPARE_READ == test_item[function].op_type )\ |
| 1217 | {\ |
| 1218 | nandlog_print("Spare read error is triggered!\n");\ |
| 1219 | ReadSpareFailure(1);\ |
| 1220 | test_item[function].triggered = 0;\ |
| 1221 | } else if (BLOCK_ERASE == test_item[function].op_type)\ |
| 1222 | {\ |
| 1223 | nandlog_print("Block erase error is triggered!\n");\ |
| 1224 | BlockEraseFailure(1);\ |
| 1225 | test_item[function].triggered = 0;\ |
| 1226 | }\ |
| 1227 | }\ |
| 1228 | }\ |
| 1229 | } |
| 1230 | |
| 1231 | #else |
| 1232 | #define TEST_ERROR_EVENT(function, step) |
| 1233 | #define TEST_ERROR_ENABLE(function, operation, step) //Keneng |
| 1234 | #define TEST_ERROR_DISABLE(function, operation, step) //Keneng |
| 1235 | #endif |
| 1236 | |
| 1237 | |
| 1238 | /******************************************************************************* |
| 1239 | * FDM function declaration |
| 1240 | *******************************************************************************/ |
| 1241 | kal_int32 MountDevice (void * DriveData, int DeviceNumber, int DeviceType, kal_uint32 Flags); |
| 1242 | kal_int32 ShutDown (void * DriveData); |
| 1243 | kal_int32 ReadSectors (void * DriveData, kal_uint32 Sector, kal_uint32 Sectors, void * Data); |
| 1244 | kal_int32 WriteSectors (void * DriveData, kal_uint32 Sector, kal_uint32 Sectors, void * Data); |
| 1245 | kal_int32 MediaChanged (void * DriveData); |
| 1246 | kal_int32 DiscardSectors (void * DriveData, kal_uint32 Sector, kal_uint32 Sectors); |
| 1247 | kal_int32 GetDiskGeometry (void * DriveData, FS_PartitionRecord * DiskGeometry, kal_uint8 * MediaDescriptor); |
| 1248 | kal_int32 LowLevelFormat (void * DriveData, const kal_char * DeviceName, FS_FormatCallback Progress, kal_uint32 Flags); |
| 1249 | kal_int32 PowerOnAssert_DriveFormat(void * DriveData); |
| 1250 | int CopySectors(void *DriveData, kal_uint32 SrcSector , kal_uint32 DstSector, kal_uint32 Sectors); |
| 1251 | kal_int32 FDM4_OTPAccess (void * DriveData, kal_int32 accesstype, kal_uint32 Offset, void * BufferPtr, kal_uint32 Length); |
| 1252 | kal_int32 FDM4_OTPQueryLength (void * DriveData, kal_uint32 *LengthPtr); |
| 1253 | kal_int32 FDM4_IOCtrl(void * DriveData, UINT CtrlAction, void * CtrlData); |
| 1254 | |
| 1255 | |
| 1256 | /******************************************************************************* |
| 1257 | * Sub-function declaration |
| 1258 | *******************************************************************************/ |
| 1259 | kal_int32 FindControlBadBlock(NAND_FLASH_DRV_DATA * D, kal_uint8 * control_num); |
| 1260 | kal_uint8 IsGoodBlock(NAND_FLASH_DRV_DATA * D, void * Spare); |
| 1261 | kal_uint8 ReadSector_512(NAND_FLASH_DRV_DATA * D, kal_uint32 Sector, kal_uint8 * Data); |
| 1262 | kal_uint8 ReadSector_2k(NAND_FLASH_DRV_DATA * D, kal_uint32 Sector, kal_uint32 read_sectors, kal_uint8 * Data); |
| 1263 | kal_uint8 WriteSector_512(NAND_FLASH_DRV_DATA * D, kal_uint32 Sector, kal_uint8 * Data); |
| 1264 | kal_uint8 WriteSector_2k(NAND_FLASH_DRV_DATA * D, kal_uint32 Sector, kal_uint32 write_sectors, kal_uint8 * Data); |
| 1265 | kal_uint32 MapSector(NAND_FLASH_DRV_DATA * D, kal_uint32 Sector); |
| 1266 | void LocateRegion(NAND_FLASH_DRV_DATA * D, kal_uint32 Sector); |
| 1267 | kal_uint8 InitializeRegionData_byReadTableInfo(NAND_FLASH_DRV_DATA * D); |
| 1268 | void InitializeRegionData(NAND_FLASH_DRV_DATA * D); |
| 1269 | void SelfFormat(NAND_FLASH_DRV_DATA * D, kal_int32 DeviceType); |
| 1270 | kal_uint8 DeletePage(NAND_FLASH_DRV_DATA * D, kal_uint32 PageIndex); |
| 1271 | kal_uint8 EraseBlock(NAND_FLASH_DRV_DATA *D, kal_uint32 BlockIndex); |
| 1272 | kal_uint8 MarkBadBlock(NAND_FLASH_DRV_DATA * D, kal_uint32 BlockIndex); |
| 1273 | kal_uint8 LocateBlock(NAND_FLASH_DRV_DATA *D); |
| 1274 | kal_uint8 LocateEmptyBlock(NAND_FLASH_DRV_DATA *D); |
| 1275 | kal_uint8 CopyBlock(NAND_FLASH_DRV_DATA *D, kal_uint8 sourceB, kal_uint8 sourceP, kal_uint8 *destinationB, kal_uint8 destinationP, kal_uint8 num); |
| 1276 | kal_int32 FlushTable(NAND_FLASH_DRV_DATA *D, ControblTableMark mark_flag); |
| 1277 | kal_uint8 ModifyTable(NAND_FLASH_DRV_DATA *D); |
| 1278 | kal_bool FindTable(NAND_FLASH_DRV_DATA *D); |
| 1279 | kal_uint8 ReadTable(NAND_FLASH_DRV_DATA *D); |
| 1280 | kal_uint8 Read_FoundTable(NAND_FLASH_DRV_DATA *D); |
| 1281 | void LocatePage(NAND_FLASH_DRV_DATA * D, kal_uint32 Sector, kal_bool readback); |
| 1282 | kal_bool BlockBMR(NAND_FLASH_DRV_DATA *D, kal_uint16 Block , kal_uint8 Offset); |
| 1283 | kal_uint32 Writedata_Active(NAND_FLASH_DRV_DATA * D, kal_uint8 Offset, kal_uint8 * Data, kal_uint8 * Spare); |
| 1284 | kal_uint32 Writedata_Block(NAND_FLASH_DRV_DATA * D, kal_uint16 Block, kal_uint8 Offset, kal_uint8 * Data, kal_uint8 * Spare); |
| 1285 | void Deletedata_Active(NAND_FLASH_DRV_DATA *D, kal_uint8 Offset); |
| 1286 | void Deletedata_Block(NAND_FLASH_DRV_DATA *D, kal_uint16 Block, kal_uint8 Offset); |
| 1287 | void Readdata_Active(NAND_FLASH_DRV_DATA *D, kal_uint8 Offset); |
| 1288 | void Readdata_Block(NAND_FLASH_DRV_DATA *D, kal_uint16 Block, kal_uint8 Offset); |
| 1289 | void MergeActive(NAND_FLASH_DRV_DATA *D); |
| 1290 | void PowerRecovery(NAND_FLASH_DRV_DATA * D); |
| 1291 | void ReconstructTable(NAND_FLASH_DRV_DATA * D, dup_block_struct dupB[2][2]); |
| 1292 | void DeleteAllControlBlock(NAND_FLASH_DRV_DATA * D); |
| 1293 | void ReconstructAllTable(NAND_FLASH_DRV_DATA * D); |
| 1294 | void RestoreAD(NAND_FLASH_DRV_DATA * D, dup_block_struct *dupB, kal_uint8 PageState0); |
| 1295 | void RestoreDD(NAND_FLASH_DRV_DATA * D, dup_block_struct *dupB); |
| 1296 | kal_uint8 CreateControlBlock (NAND_FLASH_DRV_DATA* D); |
| 1297 | kal_uint8 LimitControlLogBlockNumber (NAND_FLASH_DRV_DATA* D); |
| 1298 | kal_bool MarkControlLogBlock(NAND_FLASH_DRV_DATA* D, kal_uint32 BlockOffset); |
| 1299 | kal_bool Find_TableNewestProgramCounter (NAND_FLASH_DRV_DATA * D, kal_uint8 region); |
| 1300 | kal_uint8 LogSectionInit (NAND_FLASH_DRV_DATA * D); |
| 1301 | kal_uint8 WriteLog (NAND_FLASH_DRV_DATA * D, kal_char* message); |
| 1302 | void SC(NAND_FLASH_DRV_DATA * D); |
| 1303 | void SC_UT(NAND_FLASH_DRV_DATA * D); |
| 1304 | |
| 1305 | #endif //__NAND_FDM_50__ |
| 1306 | |
| 1307 | |
| 1308 | /****************************************************************************** |
| 1309 | * SuperAND flash device definition * |
| 1310 | ******************************************************************************/ |
| 1311 | #if defined(WIN32) && defined(TRACE_ON) |
| 1312 | #define FDM_TRACE printf |
| 1313 | #else |
| 1314 | #define FDM_TRACE |
| 1315 | #endif |
| 1316 | |
| 1317 | #define SUPERAND_SECTOR_SIZE 2048 |
| 1318 | #define SUPERAND_FAT_API_ENTRANCE \ |
| 1319 | Sector += D->first_fat_sector_offset; |
| 1320 | |
| 1321 | typedef struct |
| 1322 | { |
| 1323 | SuperAND_MTD_DRIVER * MTD; |
| 1324 | |
| 1325 | #ifndef __MTK_TARGET__ |
| 1326 | const char * file_name; |
| 1327 | void * flash_device; |
| 1328 | #endif |
| 1329 | kal_uint8 io_width; |
| 1330 | kal_uint32 pages_of_first_device; |
| 1331 | kal_uint32 pages_of_block; |
| 1332 | kal_uint32 block_mask; |
| 1333 | kal_uint32 total_pages; |
| 1334 | |
| 1335 | kal_uint32 first_fat_sector_offset; |
| 1336 | kal_uint32 total_fat_sectors; |
| 1337 | kal_uint32 partition_sectors; |
| 1338 | |
| 1339 | kal_uint32 buffer[SUPERAND_SECTOR_SIZE/sizeof(kal_uint32)]; |
| 1340 | } SuperAND_FLASH_DRV_DATA; |
| 1341 | |
| 1342 | #define SUPERAND_MOUNTED 0x1000 |
| 1343 | |
| 1344 | void SuperAND_FDM_Init(void); |
| 1345 | void SuperAND_SelfFormat(SuperAND_FLASH_DRV_DATA *D, kal_int32 DeviceType); |
| 1346 | |
| 1347 | kal_int32 SuperAND_FDM_MountDevice(void * DriveData, int DeviceNumber, int DeviceType, kal_uint32 Flags); |
| 1348 | kal_int32 SuperAND_FDM_ShutDown(void * DriveData); |
| 1349 | kal_int32 SuperAND_FDM_ReadSectors(void * DriveData, kal_uint32 Sector, kal_uint32 Sectors, void * Buffer); |
| 1350 | kal_int32 SuperAND_FDM_WriteSectors(void * DriveData, kal_uint32 Sector, kal_uint32 Sectors, void * Buffer); |
| 1351 | kal_int32 SuperAND_FDM_MediaChanged(void * DriveData); |
| 1352 | kal_int32 SuperAND_FDM_DiscardSectors(void * DriveData, kal_uint32 Sector, kal_uint32 Sectors); |
| 1353 | kal_int32 SuperAND_FDM_GetDiskGeometry(void * DriveData, FS_PartitionRecord * DiskGeometry, kal_uint8 * MediaDescriptor); |
| 1354 | kal_int32 SuperAND_FDM_GetDiskGeometry(void * DriveData, FS_PartitionRecord * DiskGeometry, kal_uint8 * MediaDescriptor); |
| 1355 | kal_int32 SuperAND_FDM_LowLevelFormat(void * DriveData, const char * DeviceName, FS_FormatCallback Progress, kal_uint32 Flags); |
| 1356 | kal_int32 SuperAND_FDM_NonBlockWriteSectors(void * DriveData, kal_uint32 Sector, kal_uint32 Sectors, void * Buffer); |
| 1357 | kal_int32 SuperAND_FDM_RecoverableWriteSectors(void * DriveData, kal_uint32 Sector, kal_uint32 Sectors, void * Buffer); |
| 1358 | kal_int32 SuperAND_FDM_ResumeSectorStates(void * DriveData); |
| 1359 | kal_int32 SuperAND_FDM_HighLevelFormat(void); |
| 1360 | kal_int32 SuperAND_FDM_FlushData(void * DriveData); |
| 1361 | kal_int32 SuperAND_FDM_CopySectors(void * DriveData, kal_uint32 SrcSector, kal_uint32 DstSector, kal_uint32 Sectors); |
| 1362 | |
| 1363 | #endif /* NAND_FDM_H */ |
| 1364 | |