blob: 8da1fb5393eb8b1fd4a6f298736a6b1967da32e3 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001/*****************************************************************************
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 * FlashConf.C
41 *
42 * Project:
43 * --------
44 * MAUI
45 *
46 * Description:
47 * ------------
48 * This file is used to configure flash device for FAT.
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 *
98 * removed!
99 * removed!
100 * removed!
101 *
102 * removed!
103 * removed!
104 * removed!
105 *
106 * removed!
107 * removed!
108 * removed!
109 *
110 * removed!
111 * removed!
112 * removed!
113 *
114 * removed!
115 * removed!
116 * removed!
117 *
118 * removed!
119 * removed!
120 * removed!
121 *
122 * removed!
123 * removed!
124 * removed!
125 *
126 * removed!
127 * removed!
128 * removed!
129 *
130 * removed!
131 * removed!
132 * removed!
133 *
134 * removed!
135 * removed!
136 * removed!
137 *
138 * removed!
139 * removed!
140 * removed!
141 * removed!
142 *
143 * removed!
144 * removed!
145 * removed!
146 *
147 * removed!
148 * removed!
149 * removed!
150 *
151 * removed!
152 * removed!
153 * removed!
154 *
155 * removed!
156 * removed!
157 * removed!
158 *
159 * removed!
160 * removed!
161 * removed!
162 *
163 * removed!
164 * removed!
165 * removed!
166 *
167 * removed!
168 * removed!
169 * removed!
170 *
171 * removed!
172 * removed!
173 * removed!
174 *
175 * removed!
176 * removed!
177 * removed!
178 *
179 * removed!
180 * removed!
181 * removed!
182 *
183 * removed!
184 * removed!
185 * removed!
186 *
187 * removed!
188 * removed!
189 * removed!
190 *
191 * removed!
192 * removed!
193 * removed!
194 *
195 * removed!
196 * removed!
197 * removed!
198 *
199 * removed!
200 * removed!
201 * removed!
202 *
203 * removed!
204 * removed!
205 * removed!
206 *
207 * removed!
208 * removed!
209 * removed!
210 *
211 * removed!
212 * removed!
213 * removed!
214 *
215 * removed!
216 * removed!
217 * removed!
218 *
219 * removed!
220 * removed!
221 * removed!
222 *
223 * removed!
224 * removed!
225 * removed!
226 *
227 * removed!
228 * removed!
229 * removed!
230 *
231 * removed!
232 * removed!
233 * removed!
234 *
235 * removed!
236 * removed!
237 * removed!
238 *
239 * removed!
240 * removed!
241 * removed!
242 *
243 * removed!
244 * removed!
245 * removed!
246 *
247 * removed!
248 * removed!
249 * removed!
250 *
251 * removed!
252 * removed!
253 * removed!
254 *
255 * removed!
256 * removed!
257 * removed!
258 * removed!
259 * removed!
260 * removed!
261 * removed!
262 * removed!
263 * removed!
264 * removed!
265 * removed!
266 * removed!
267 * removed!
268 * removed!
269 * removed!
270 * removed!
271 * removed!
272 * removed!
273 * removed!
274 * removed!
275 * removed!
276 * removed!
277 * removed!
278 * removed!
279 * removed!
280 * removed!
281 * removed!
282 * removed!
283 * removed!
284 * removed!
285 * removed!
286 * removed!
287 * removed!
288 *
289 * removed!
290 * removed!
291 * removed!
292 *
293 * removed!
294 * removed!
295 * removed!
296 *
297 * removed!
298 * removed!
299 * removed!
300 *
301 * removed!
302 * removed!
303 *
304 *------------------------------------------------------------------------------
305 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
306 *==============================================================================
307 *******************************************************************************/
308#ifndef DRVFLASH_H
309#define DRVFLASH_H
310
311/*---------------------------------------------
312 * Included Header Files
313 *---------------------------------------------*/
314
315#include "fs_type.h"
316#include "kal_general_types.h"
317#include "kal_public_defs.h"
318#include "kal_internal_api.h"
319#include "fs_gprot.h"
320
321// default turn on FDM4 enhancement
322#define __NOR_FDM_4_FLIPPING_TOLERABLE__
323
324#ifdef FLASH_DISKDRV_DEBUG
325#define __fs_packed_prefix
326#define __fs_packed_postfix
327#endif
328
329// MTD driver
330#define REGION_NUM 8
331#define NON_BLOCK_STATUS (0x8) //4 bit pattern for version check
332
333//FOR FDM5
334#define INVALID_BLOCK_ID 0xffff
335#define INVALID_TABLE_ID 0xffff
336#define INVALID_LOGICAL_NUM 0xffffff
337#define INVALID_NOR_ADDR 0xffffffff
338#define INVALID_PHY_PAGE 0xffffffff
339#define INVALID_ENTRY 0xffff
340
341//FOR FDM4
342#define INVALID_BLOCK_INDEX 0xFFFFFFFF
343#define INVALID_SECTOR_INDEX 0xFFFFFFFF
344#define INVALID_ERASE_COUNT 0x00FFFFFF // we only have 24 bits
345#define MAX_ERASE_COUNT (INVALID_ERASE_COUNT-1)
346
347/* Global defines */
348#define SPARE_RESERVED_RATIO (10)
349#define MINIMUM_SPARE_AMOUNT (2)
350#define SLEEP_MODE_SPARE_AMOUNT (4)
351#define GC_THRESHOLD_DIVISION (3)
352#define GC_THRESHOLD_GAP (1)
353#define RESERVED_SECTOR_FOR_MINIMUM_SPARE_SPACE (4) ///< The number of additional reserved sectors if erase queue size is set to the minimum value (2)
354#define RESERVED_SECTOR_FOR_REPEATE_POWER_LOSS_DURING_RECLAIM (6) ///< The number of additional reserved sectors if erase queue size is set to the minimum value (2)
355#define MINIMUM_SYSTEM_DRIVE_RESERVE_BLOCK (3) ///< minimum System Drive Reserved Blocks (unit: block)
356
357/******** RESULT for Single Bank ************/
358#define RESULT_FLASH_DONE (1)
359#define RESULT_FLASH_BUSY (0)
360#define RESULT_FLASH_FAIL (-1)
361
362#ifndef __MTK_TARGET__
363#pragma pack(1)
364#endif
365typedef __fs_packed_prefix struct {
366 kal_uint32 TotalBlocks;
367 kal_uint32 BlockSize[REGION_NUM];
368 kal_uint32 AvailInRegion[REGION_NUM]; ///< empty and the number of blocks in erase queue
369 kal_uint32 RegionBlocks[REGION_NUM];
370 kal_uint32 ActualRegionNum;
371 WORD PageSize;
372 kal_uint32 baseUnlockBlock; ///< Add because FOTA need to unlock different region in INTEL flash
373 kal_uint32 endUnlockBlock; ///< Add because FOTA need to unlock different region in INTEL flash
374} __fs_packed_postfix NOR_MTD_FlashInfo;
375#ifndef __MTK_TARGET__
376#pragma pack()
377#endif
378
379/* add ONE_BYTE_ALIGN_ADS keyword to this struct so that it won't violate ARM's ADS compiler rule.
380 * No need, since this structure is included into another ONE_BYTE_ALIGN_ADS structure in pointer form
381 */
382typedef struct {
383 int (* MountDevice) (void * DriveData, void * Info);
384 int (* ShutDown) (void * DriveData);
385 void * (* MapWindow) (void * DriveData, kal_uint32 BlockIndex, kal_uint32 WindowIndex);
386 int (* EraseBlock) (void * DriveData, kal_uint32 BlockIndex);
387 int (* ProgramData) (void * DriveData, void * Address, void * Data, UINT Length);
388 int (*NonBlockEraseBlock) (void * DriveData, kal_uint32 BlockIndex); /* Added by Eric */
389 int (*CheckDeviceReady) (void * DriveData, kal_uint32 BlockIndex); /* Added by Eric */
390 int (*SuspendErase) (void * DriveData, kal_uint32 BlockIndex); /* Added by Eric */
391 int (*ResumeErase) (void * DriveData, kal_uint32 BlockIndex); /* Added by Eric */
392 int (*BlankCheck) (void * DriveData, kal_uint32 BlockIndex);
393 int (*OTPAccess) (void * DriveData, int accesstype, UINT Offset, void * BufferPtr, UINT Length);
394 int (*OTPQueryLength) (void * DriveData, UINT *Length);
395 int (*LockEraseBlkAddr) (void * DriveData, void *Address,UINT Action);
396 kal_bool (*IsEraseSuspended) (void * DriveData, kal_uint32 BlockIndex);
397 int (*IOCtrl) (void * DriveData, UINT CtrlAction, void * CtrlData); // For device IO control
398 //mtk03694 : this is a new API for WAT chip, because we have NO forced suspend & resume function.
399 // So if someone use direct read while the flash is erasing or programing, the value will be wrong.
400 #ifdef __LTE_RAT__
401 int (* ReadData) (void * DriveData, void * Address, void * Data, UINT Length);
402 #endif
403} NOR_MTD_Driver;
404
405/*LockEraseBlkAddr Action*/
406#define ACTION_UNLOCK 0
407#define ACTION_LOCK 1
408#define ACTION_ERASE 2
409
410
411// This is the file MTD for testing only
412
413typedef struct {
414 const char * FileName;
415 kal_uint32 FileSize;
416 kal_uint32 BlockSize;
417 kal_uint32 WindowSize;
418 HANDLE H;
419 BYTE * BaseAddr;
420 void * CurrAddr;
421} NORMtdFileData;
422
423
424// Flash Info
425typedef struct {
426 kal_uint32 BlockSize;
427 kal_uint32 RegionBlocks;
428} FlashRegionInfo;
429#define EndRegionInfo {0, 0}
430
431typedef struct {
432 kal_uint32 BankSize;
433 kal_uint32 Banks;
434} FlashBankInfo;
435#define EndBankInfo {0, 0}
436
437// Erase block Info
438/* add ONE_BYTE_ALIGN_ADS keyword to this struct so that it won't violate ARM's ADS compiler rule.
439 * No need, since this structure is included into another ONE_BYTE_ALIGN_ADS structure in pointer form
440 */
441typedef struct {
442 kal_uint32 BlockIndex;
443 kal_uint32 EraseCount;
444} NOR_EraseInfo;
445
446
447typedef struct {
448 kal_uint32 Signature;
449 BYTE * BaseAddr;
450 kal_semid DeviceLock; // The device lock that keeps driver resource consistent
451 kal_taskid DeviceLockOwner; // The owner of the deivce lock
452 kal_int8 DeviceLockDepth; // The depth of the deivce lock
453
454 FlashRegionInfo * RegionInfo;
455 BYTE * CurrAddr;
456 FlashBankInfo *BankInfo;
457 BYTE * CurrBankAddr;
458 kal_uint32 CurrBankSize;
459 BYTE * CurrPollAddr;
460#ifndef __MTK_TARGET__
461 const char *FileName;
462 void *flash_device;
463 BYTE *rootMTDcache;
464 BYTE *MTDcache;
465 kal_uint32 first;
466 kal_uint32 last_WinAddr;
467 kal_uint32 last_region;
468#endif
469} NOR_Flash_MTD_Data;
470
471#ifndef __MTK_TARGET__
472 #ifndef FLASH_DISKDRV_DEBUG
473 #define MakeMtdFlashData(a, b) 0x0, 0x000000, b, NULL, "..\\..\\fs\\flash_device.img", NULL, NULL, NULL
474 #else
475 #define MakeMtdFlashData(a, b) 0x0, 0x000000, b, NULL, "..\\flash_device.img", NULL, NULL, NULL
476 #endif
477#else
478#define MakeMtdFlashData(a, b) a, b, NULL
479#endif
480
481/* Multi-sector Protection Entry */
482#ifndef __MTK_TARGET__
483#pragma pack(1)
484#endif
485
486
487typedef __fs_packed_prefix struct {
488 kal_uint32 LogicalSectorID;
489 kal_uint32 PysicalSectorID_new;
490}__fs_packed_postfix MS_ENTRY;
491
492
493
494// Flash driver's data
495typedef __fs_packed_prefix struct NOR_FLASH_DRV_Data{
496 kal_uint32 TotalFATSectors; ///< Total number of FAT sectors in flash (i.e., TotalPhysicalSectors - reserved sectors)
497 NOR_MTD_Driver *MTDDriver; ///< MTD driver
498 void *MTDData; ///< MTD data
499 WORD *AvailSectorsInBlock; ///< The number of SECTOR_AVAIL in each block
500 WORD *ValidSectorsInBlock; ///< The number of valid sectors (not SECTOR_AVAIL && not SECTOR_DELETED)
501 NOR_MTD_FlashInfo FlashInfo; ///< Flash information
502 kal_uint32 HeaderSize[REGION_NUM]; ///< Size (bytes) from the beginning of a block address to the first data sector (i.e., contains both block and sector headers)
503 kal_uint32 SectorsPerBlock[REGION_NUM]; ///< Number of "physical" sectors (exclude sectors for header) in each block of the same region
504 kal_uint32 ActiveBlock; ///< Current active block ID
505 kal_uint32 ReclaimEraseCount; ///< Erase count of the reclaimed block
506 kal_uint32 ReclaimBlockID; ///< Block ID of the reclaimed block
507 kal_uint32 TotalPhysicalSectors; ///< Total number of "physical" sector (exclude sectors for header) in flash. (For each region, TotalPhysicalSectors += RegionBlocks[region] * SectorsPerBlock[region])
508 kal_uint32 PartitionSectors; ///< Size of the first FAT partition (unit: sectors)
509 kal_uint32 GCThreshold; ///< GC threshold for Multi-Bank (2 maximum block + sectors for MSP)
510 kal_uint32 AvailSectors; ///< Total SECTOR_AVAIL sectors in flash (of course, exclude sectors for headers)
511 kal_uint32 DeletedSectors; ///< The number of deleted sectors in system (Increased in DeletePhysicalSector, MountDevice, ResumeSectorStates)
512 kal_uint32 StartSector; ///< Start "logical sector ID" for write or marking to process
513 kal_uint32 Sectors; ///< Total number of logical sectors to be updated (set in MarkToProcess)
514 kal_uint32 SectorsLeft; ///< The number of logical sectors left to be updated. i.e., The number of sectors whose update bit is set. (set in MarkToProcess and be decreased in MarkProcessed)
515 kal_uint32 BLOCKID_OFFSET; ///< Block offset, calculated by MaxSectorsPerBlock
516 kal_uint32 SECTORIDX_MASK; ///< Mask for retrieve sector index inside a block
517 kal_uint32 PHY_SECTOR_OFFSET; ///< Offset for retriving first 7 bits of PhysicalSector (i.e., Block offset + Local sector offset - 7)
518
519 kal_uint32 MSTABLE_ENTRY_NUM;
520 kal_uint32 MS_count; ///< The number of valid entries in MS Entry Table
521 MS_ENTRY *MSEntryTable;
522 BYTE *SectorMap; ///< Sector map, built in MountDevice
523 BYTE *Buffer; ///< FDM Buffer: SIBLEY(1024 bytes) / Others (512 bytes), used when source data is located in the same bank (ESB, movee sectors in ReclaimBlock_pre...)
524
525 void (*CompleteErase)(struct NOR_FLASH_DRV_Data * D);
526
527 kal_uint32 RegionMaxBlock; ///< (The first) region ID which contains blocks that have maximum number of sectors (to not let such block is selected as active block when the block is the only one left in this region, which makes Program Fail handle properly)
528
529 void (*ProgramFailHandle) (struct NOR_FLASH_DRV_Data * D);
530 void (*ReclaimBlock_post) (struct NOR_FLASH_DRV_Data * D);
531
532
533 WORD SystemDriveReservedUnits; ///< The number of reserved unit (1 unit = 0.5 block), default size = 6 (NOR_SYSTEM_DRIVE_RESERVED_BLOCK * 2)
534
535 kal_bool ProgramFailRetry;
536
537
538
539}__fs_packed_postfix NOR_FLASH_DRV_Data;
540
541#ifdef __MTK_TARGET__
542
543extern kal_mutexid fdm_reclaim_mutex;
544extern kal_eventgrpid nor_egid;
545#define NOR_BRECL_EVENT 0x1
546#define NOR_FRECL_EVENT 0x2
547#define NOR_DMAN_EVENT 0x4
548
549#endif
550
551/* Flash Bank Info */
552typedef struct {
553 kal_uint32 BankSize;
554 kal_uint32 Banks;
555} NORBankInfo;
556#define EndBankInfo {0, 0}
557
558/* Flash Layout Info */
559typedef struct {
560 kal_uint32 TotalLSMT;
561 kal_uint32 BlkSize;
562 kal_uint32 PageSize;
563 NORBankInfo *BankInfo;
564 WORD TblEntrys;
565 WORD TotalBlks;
566} NORLayoutInfo;
567
568typedef struct {
569 kal_uint32 Signature;
570 BYTE * BaseAddr;
571 kal_semid DeviceLock; // The device lock that protects driver resource
572 kal_taskid DeviceLockOwner; // The owner of the deivce lock
573 kal_int8 DeviceLockDepth; // The depth of the deivce lock
574
575 NORLayoutInfo * LayoutInfo;
576#ifndef __MTK_TARGET__
577 const char *FileName;
578 void *flash_device;
579 BYTE *rootMTDcache;
580 BYTE *MTDcache;
581 kal_uint32 modify; //first time, don't need to write to file
582 kal_uint32 last_WinAddr; // next address calling mapwindow
583 kal_uint32 last_region; //next region calling mapwindow
584#endif
585} NOR_MTD_DATA;
586
587typedef __fs_packed_prefix struct
588{
589 kal_uint32 MSCount;
590 kal_uint32 *LogPageID;
591 WORD *NewEntryID;
592 WORD *OldEntryID;
593}__fs_packed_postfix MS_TABLE;
594
595typedef __fs_packed_prefix struct {
596 WORD LogBlkID;
597 WORD TblIDInBlk;
598}__fs_packed_postfix LSMGEntry;
599
600//flash driver data for FDM5.0
601typedef __fs_packed_prefix struct {
602 kal_uint32 TotalFATSectors;
603 NOR_MTD_Driver * MTDDriver;
604 void * MTDData;
605 int (* DiscardSectors) (void * DriveData, UINT Sector, UINT Sectors);
606 void (*ReclaimBlock) (void* DriveData, kal_bool isBackground);
607 kal_uint32 SecondPartitionSectors;
608 kal_uint32 HeaderSize[2]; //HeaderSize[0]: data block header size
609 //HeaderSize[1]: table block header size
610 kal_uint32 *InvalidEntryInTblBlk; //valid entry in table block
611 kal_uint32 TotalAvail[2]; // TotalAvail[0]: total available pages in data block
612 //TotalAvail[0]: total available tables in table block
613 //not include empty block (2 spare block)
614 kal_uint32 TotalInvalid[2]; // TotalInvalid[0]: total invalid pages in data block
615 //TotalInvalid[0]: total invalid tables in table block
616 kal_uint32 ReclHighThreshold[2]; //unit ReclHighThreshold[0]: Pages ReclHighThreshold[1]: Tables
617 kal_uint32 ReclLowThreshold[2];
618 kal_uint32 SystemThreshold[2];
619 kal_bool NeedResumeFlag;
620 kal_bool NeedFRecl;
621 LSMGEntry *LSMG; // logical sector mapping group table
622 WORD ReclType;
623 WORD *LBM; //logical block mapping table
624 WORD *AvailInBlk; //available page in data block, available table in table block
625 WORD *InvalidInBlk; //valid page in data block, valid table in table block
626 WORD ActiveBlk[2]; // ActiveBlk[0]: active data block
627 //ActiveBlk[1]: active table block
628 WORD ReclLogBlkID; //ReclLogBlkID == INVALID_BLOCK_ID means no block need reclamation
629 WORD ErasingPhyBlk;
630 WORD ReclToPhyBlkID;
631 WORD ReclFromPhyBlkID;
632 WORD PageSizeShift;
633 WORD BlkIDShift;
634 WORD TblSizeShift;
635 WORD TblIDShift;
636 WORD PagesPerBlk;
637 WORD TblsPerBlk;
638 WORD TblBlks;
639 WORD SetTblBlks;
640 WORD DataBlks;
641 kal_uint32 MSTABLE_ENTRY_NUM;
642 MS_TABLE MSTable;
643 BYTE *Buffer;
644 BYTE *CopyBuffer;
645}__fs_packed_postfix NOR_FTL_DATA;
646
647
648#ifndef __MTK_TARGET__
649#pragma pack()
650#endif
651
652typedef struct {
653 kal_uint32 Blocks;
654 kal_uint32 BlockSize;
655 kal_uint32 EraseCountMax;
656 kal_uint32 EraseCountMin;
657 kal_uint32 EraseCountAverage;
658 kal_uint32 SectorsInUse;
659 kal_uint32 SectorsDeleted;
660 kal_uint32 SectorsAvail;
661} NORFlashInfo;
662
663/* Definition for power loss test */
664#if defined(FLASH_DISKDRV_DEBUG) && defined(POWERLOSS_TEST)
665#include <setjmp.h>
666extern jmp_buf mark;
667extern int Test_CD_Value;
668#ifndef __NOR_FDM5__
669enum
670{
671/* 1*/WriteSector_SECTOR_WRITING = 1,
672/* 2*/WriteSector_SECTOR_WRITTEN,
673/* 3*/WriteSector_SECTOR_DELETED,
674/* 4*/WriteSector_SECTOR_VALID,
675/* 5*/WriteSector_SECTOR_MS_WRITTEN,
676/* 6*/ReclaimBlock_pre_BLOCK_RECLAIM,
677/* 7*/ReclaimBlock_pre_BLOCK_VIRGINE,
678/* 8*/ReclaimBlock_post_BLOCK_EMPTY,
679/* 9*/SetActiveBlock_BLOCK_FULL,
680/*10*/SetActiveBlock_BLOCK_ACTIVE,
681/*11*/ResumeSectorStates_SECTOR_MS_BEINGVALIDATED,
682/*12*/WriteSector_SECTOR_MOVING,
683/*13*/WriteSectors_Validate_MS_Sector
684};
685
686#define TEST_POINT(a)\
687 {\
688 switch(a)\
689 {\
690 case WriteSector_SECTOR_MS_WRITTEN:\
691 case ReclaimBlock_pre_BLOCK_RECLAIM:\
692 case ReclaimBlock_pre_BLOCK_VIRGINE:\
693 case ReclaimBlock_post_BLOCK_EMPTY:\
694 case SetActiveBlock_BLOCK_FULL:\
695 case SetActiveBlock_BLOCK_ACTIVE:\
696 case WriteSectors_Validate_MS_Sector:\
697 Test_CD_Value -= 50;\
698 break;\
699 case ResumeSectorStates_SECTOR_MS_BEINGVALIDATED:\
700 Test_CD_Value -= 50;\
701 break;\
702 default:\
703 Test_CD_Value--;\
704 break;\
705 }\
706 if(Test_CD_Value <= 0)\
707 longjmp(mark, a);\
708 }
709#else /*FDM5*/
710enum
711{
712/* 1*/ReclaimBlock_MARK_BLOCK_RECLAIM = 1,
713/* 2*/ReclaimBlock_MARK_BLOCK_COPYING,
714/* 3*/ReclaimBlock_TABLE_BLOCK_COPYING,
715/* 4*/ReclaimBlock_DATA_BLOCK_COPYING,
716/* 5*/ReclaimBlock_MARK_BLOCK_ERASING,
717/* 6*/ReclaimBlock_AFTER_ERASED,
718/* 7*/CopyTable_MARK_COPYING,
719/* 8*/CopyTable_MARK_ALLOCATING,
720/* 9*/CopyTable_MARK_VALID,
721/*10*/WritePage_MARK_TABLE_ENTRY_WRITING,
722/*11*/WritePage_MARK_TABLE_ENTRY_WRITTEN,
723/*12*/WritePage_MARK_PAGE_VALID,
724/*13*/WritePage_MARD_TABLE_ENTRY_MS_WRITING,
725/*14*/WritePage_MARD_TABLE_ENTRY_MS_BEGIN_VALID,
726/*15*/SetActiveBlock_BLOCK_FULL,
727/*16*/SetActiveBlock_BLOCK_ACTIVE
728};
729
730
731#define TEST_POINT(a)\
732 {\
733 switch(a)\
734 {\
735 case ReclaimBlock_MARK_BLOCK_RECLAIM:\
736 case ReclaimBlock_MARK_BLOCK_COPYING:\
737 case ReclaimBlock_TABLE_BLOCK_COPYING:\
738 case ReclaimBlock_DATA_BLOCK_COPYING:\
739 case ReclaimBlock_MARK_BLOCK_ERASING:\
740 case ReclaimBlock_AFTER_ERASED:\
741 case CopyTable_MARK_COPYING:\
742 case CopyTable_MARK_ALLOCATING:\
743 case CopyTable_MARK_VALID:\
744 case WritePage_MARK_TABLE_ENTRY_WRITING:\
745 case WritePage_MARK_TABLE_ENTRY_WRITTEN:\
746 case WritePage_MARK_PAGE_VALID:\
747 case WritePage_MARD_TABLE_ENTRY_MS_WRITING:\
748 case WritePage_MARD_TABLE_ENTRY_MS_BEGIN_VALID:\
749 case SetActiveBlock_BLOCK_FULL:\
750 case SetActiveBlock_BLOCK_ACTIVE:\
751 Test_CD_Value -= 50;\
752 break;\
753 default:\
754 Test_CD_Value--;\
755 break;\
756 }\
757 if(Test_CD_Value <= 0)\
758 longjmp(mark, a);\
759 }
760#endif /*__NOR_FDM5__*/
761#define START_POINT setjmp(mark)
762#else
763#define TEST_POINT(a)
764#define START_POINT
765#endif /* FLASH_DISKDRV_DEBUG */
766
767
768/* Function Prototype */
769int NOR_MountDevice(void * DriveData, int DeviceNumber, int DeviceType, kal_uint32 Flags);
770int NOR_ShutDown(void * DriveData);
771int NOR_ReadSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
772int NOR_WriteSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
773int NOR_MediaChanged(void * DriveData);
774int NOR_DiscardSectors(void * DriveData, kal_uint32 Sector, UINT Sectors);
775int NOR_GetDiskGeometry(void * DriveData, FS_PartitionRecord * DiskGeometry, BYTE * MediaDescriptor);
776int NOR_LowLevelFormat(void * DriveData, const char * DeviceName, FS_FormatCallback Progress, kal_uint32 Flags);
777int NOR_NonBlockWriteSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
778int NOR_RecoverableWriteSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
779int NOR_ResumeSectorStates(void * DriveData);
780
781int SIB_MountDevice(void * DriveData, int DeviceNumber, int DeviceType, kal_uint32 Flags);
782int SIB_ReadSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
783int SIB_WriteSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
784int SIB_DiscardSectors(void * DriveData, kal_uint32 Sector, UINT Sectors);
785int SIB_GetDiskGeometry(void * DriveData, FS_PartitionRecord * DiskGeometry, BYTE * MediaDescriptor);
786int SIB_LowLevelFormat(void * DriveData, const char * DeviceName, FS_FormatCallback Progress, kal_uint32 Flags);
787int SIB_NonBlockWriteSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
788int SIB_RecoverableWriteSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
789int SIB_ResumeSectorStates(void * DriveData);
790
791int nNOR_MountDevice(void * DriveData, int DeviceNumber, int DeviceType, kal_uint32 Flags);
792int nNOR_ReadSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
793int nNOR_WriteSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
794int nNOR_MediaChanged(void * DriveData);
795int nNOR_DiscardSectors(void * DriveData, kal_uint32 Sector, UINT Sectors);
796int nNOR_LowLevelFormat(void * DriveData, const char * DeviceName, FS_FormatCallback Progress, kal_uint32 Flags);
797int nNOR_NonBlockWriteSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
798int nNOR_RecoverableWriteSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
799int nNOR_ResumeSectorStates(void * DriveData);
800void nNOR_ReclaimBlock(void* DriveData, kal_bool isBackground);
801
802int nSIB_MountDevice(void * DriveData, int DeviceNumber, int DeviceType, kal_uint32 Flags);
803int nSIB_ReadSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
804int nSIB_WriteSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
805int nSIB_DiscardSectors(void * DriveData, kal_uint32 Sector, UINT Sectors);
806int nGetDiskGeometry(void * DriveData, FS_PartitionRecord * DiskGeometry, BYTE * MediaDescriptor);
807int nSIB_LowLevelFormat(void * DriveData, const char * DeviceName, FS_FormatCallback Progress, kal_uint32 Flags);
808int nSIB_NonBlockWriteSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
809int nSIB_RecoverableWriteSectors(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
810int nSIB_ResumeSectorStates(void * DriveData);
811void nSIB_ReclaimBlock(void* DriveData, kal_bool isBackground);
812int nShutDown(void * DriveData);
813
814int NOR_MountDevice_ext(void * DriveData, int DeviceNumber, int DeviceType, kal_uint32 Flags);
815int NOR_ShutDown_ext(void * DriveData);
816int NOR_ReadSectors_ext(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
817int NOR_WriteSectors_ext(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
818int NOR_MediaChanged_ext(void * DriveData);
819int NOR_DiscardSectors_ext(void * DriveData, kal_uint32 Sector, UINT Sectors);
820int NOR_GetDiskGeometry_ext(void * DriveData, FS_PartitionRecord * DiskGeometry, BYTE * MediaDescriptor);
821int NOR_LowLevelFormat_ext(void * DriveData, const char * DeviceName, FS_FormatCallback Progress, kal_uint32 Flags);
822int NOR_NonBlockWriteSectors_ext(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
823int NOR_RecoverableWriteSectors_ext(void * DriveData, kal_uint32 Sector, UINT Sectors, void * Buffer);
824int NOR_ResumeSectorStates_ext(void * DriveData);
825
826int OTPAccess(void * DriveData, int accesstype, UINT Offset, void * BufferPtr, UINT Length);
827int OTPQueryLength(void * DriveData, UINT *Length);
828
829
830// internal function for different version of FDM
831
832extern void MB_CompleteErase(NOR_FLASH_DRV_Data * D);
833
834
835 extern void FDM_LOCK(void);
836 extern void FDM_UNLOCK(void);
837 #define retriveFDMLock FDM_LOCK
838 #define releaseFDMLock FDM_UNLOCK
839
840
841
842
843
844
845
846
847#if (defined __UBL__) || (defined __FUE__)
848 #define NORFDM_EXT_ASSERT(expr, e1, e2, e3) EXT_ASSERT(expr, e1, e2, e3)
849 #define NORFDM_ASSERT(expr) ASSERT(expr)
850#else
851 extern kal_uint32 NOR_FDM_Get_current_PC(void);
852 #define NORFDM_EXT_ASSERT(expr, e1, e2, e3) {if(!(expr)) {kal_fatal_error_handler(KAL_ERROR_FILESYS_NOR_FDM_INTERNAL_FAILED, NOR_FDM_Get_current_PC());}}
853 #if defined(DEBUG_KAL)
854 #define NORFDM_ASSERT(x) {if(!(x)) {kal_fatal_error_handler(KAL_ERROR_FILESYS_NOR_FDM_INTERNAL_FAILED, NOR_FDM_Get_current_PC());}}
855 #else
856 #define NORFDM_ASSERT(x)
857 #endif
858#endif // __UBL__ || __FUE__
859
860
861#if defined(__MTK_TARGET__)
862#if defined(__UBL__) || defined(__FUE__)
863#define __nor_section_RAM __attribute__ ((section ("INTERNCODE")))
864#define __nor_section_SECOND_PART __attribute__ ((section ("SECOND_PART")))
865#define __nor_section_EMIINITCODE __attribute__ ((section ("EMIINITCODE")))
866#else // __MTK_TARGET__ && !(__UBL__ ||__FUE__) && !__SINGLE_BANK_NOR_FLASH_SUPPORT__
867#define __nor_section_RAM
868#define __nor_section_SECOND_PART
869#define __nor_section_EMIINITCODE
870#endif
871#else //!__MTK_TARGET__
872/* Reserve for MoDIS */
873#define __nor_section_RAM
874#define __nor_section_SECOND_PART
875#define __nor_section_EMIINITCODE
876#endif //__MTK_TARGET__
877
878
879#endif /* !DRVFLASH_H */