1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <kernel.h>
8 #include <bsp.h>  // for CACHE_LINE_SIZE definition
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 /***********************************************************************/
15 /* Configuration                                                       */
16 /***********************************************************************/
17 #define NV_NDM_CTRL_STORE FALSE
18 
19 // To allow including FTLs with FAT/XFS or stand-alone
20 #if INC_FAT && !defined(INC_SECT_FTL)
21 #define INC_SECT_FTL TRUE
22 #endif
23 #if INC_XFS && !defined(INC_PAGE_FTL)
24 #define INC_PAGE_FTL TRUE
25 #endif
26 
27 
28 // Default is to include page cache with 512B sector-mode FTL
29 #if INC_SECT_FTL && !defined(INC_FTL_PAGE_CACHE)
30 #define INC_FTL_PAGE_CACHE TRUE
31 #endif
32 
33 /***********************************************************************/
34 /* Symbol Definitions                                                  */
35 /***********************************************************************/
36 
37 // Flag values for the file systems' driver flags field
38 
39 #define FSF_QUOTA_ENABLED   (1 << 0)
40 #define FSF_READ_ONLY       (1 << 1)
41 #define FSF_AUTO_MOUNT      (1 << 2)
42 #define FSF_EXTRA_FREE      (1 << 3)
43 #define FSF_DATA_CACHE      (1 << 4)
44 #define FSF_FAT_MIN_CLUST   (1 << 5)    // use driver min cluster size
45 #define FSF_SYNCS_ON        (1 << 6)
46 #define FSF_BLUNK_FTL       (1 << 7)
47 #define FSF_TRANSFER_PAGE   (1 << 8)
48 #define FSF_MULTI_ACCESS    (1 << 9)
49 #define FSF_SLOW_MOUNT      (1 << 10)
50 #define FSF_DRVR_SEM        (1 << 11)
51 #define FSF_XFS_MIN_SECT    (1 << 12)
52 #define FSF_FAT_SYNC_FATS   (1 << 13)   // sync FATs though both valid
53 #define FSF_CRYPT           (1 << 14)   // use encryption layer
54 #define FSF_ERASE_WAIT      (1 << 15)
55 #define FSF_NOATIME         (1 << 16)   // dont update access time
56 #define FSF_NO_OVERWRITE    (1 << 17)
57 #define FSF_FTL_PAGE_CACHE  (1 << 18)
58 #define FSF_XFS_DCACHE      (1 << 19)
59 #define FSF_FAT_SECT_SIZE   (1 << 20)   // use driver sector size
60 #define FSF_NOMODTIME       (1 << 21)   // dont update modification time
61 #define FSF_FREE_SPARE_ECC  (1 << 22)   // spare decode has no overhead
62 #define FSF_NDM_INIT_WRITE  (1 << 23)   // re-write NDM metadata on init
63 #define FSF_READ_WEAR_LIMIT (1 << 24)   // driver specs read-wear limit
64 
65 #define FSF_ALL                                                                                \
66     (FSF_QUOTA_ENABLED | FSF_READ_ONLY | FSF_AUTO_MOUNT | FSF_EXTRA_FREE | FSF_DATA_CACHE |    \
67      FSF_FAT_MIN_CLUST | FSF_SYNCS_ON | FSF_BLUNK_FTL | FSF_TRANSFER_PAGE | FSF_MULTI_ACCESS | \
68      FSF_SLOW_MOUNT | FSF_DRVR_SEM | FSF_XFS_MIN_SECT | FSF_FAT_SYNC_FATS | FSF_CRYPT |        \
69      FSF_ERASE_WAIT | FSF_NOATIME | FSF_NO_OVERWRITE | FSF_FTL_PAGE_CACHE | FSF_XFS_DCACHE |   \
70      FSF_FAT_SECT_SIZE | FSF_NOMODTIME | FSF_FREE_SPARE_ECC | FSF_NDM_INIT_WRITE |             \
71      FSF_READ_WEAR_LIMIT)
72 
73 
74 // This flag is obsolete. It is now the default for TargetNDM driver
75 // routines to use page numbers instead of byte addresses.
76 #define FSF_DRVR_PAGES 0
77 
78 // Head/Sector/Cylinder Address Conversion Constants. The specific
79 // values are not critical, but are used for consistency when our code
80 // needs to assign a value or to convert an LBA to a CHS address.
81 #define FAT_NUM_HEADS 4
82 #define FAT_SECTS_PER_TRACK 64
83 
84 // Valid TargetFAT partition types
85 #define FAT_12BIT 0x01
86 #define FAT_16BIT 0x04
87 #define FAT_BIGDOS 0x06
88 #define FAT_32BIT 0x0B
89 
90 // Size in bytes of a FAT sector
91 #define FAT_SECT_SZ 512
92 
93 /***********************************************************************/
94 /* Macro Definitions                                                   */
95 /***********************************************************************/
96 #if FS_ASSERT
97 void AssertError(int line, char* file);
98 #define PF_DEBUG
99 #define PfAssert(c)                          \
100     do {                                     \
101         if (!(c))                            \
102             AssertError(__LINE__, __FILE__); \
103     } while (0)
104 #else
105 #define PfAssert(c) \
106     do {            \
107     } while (0)
108 #endif
109 
110 // Count number of bits set to 1 in a byte/32 bit value
111 #define ONES_UI8(b) (NumberOnes[(b) >> 4] + NumberOnes[(b)&0xF])
112 #define ONES_UI32(w)                                                               \
113     (ONES_UI8(((ui8*)&w)[0]) + ONES_UI8(((ui8*)&w)[1]) + ONES_UI8(((ui8*)&w)[2]) + \
114      ONES_UI8(((ui8*)&w)[3]))
115 
116 /***********************************************************************/
117 /* Type Definitions                                                    */
118 /***********************************************************************/
119 #if FS_CRYPT
120 // FS Crypt Driver Definitions
121 typedef enum {
122     FS_AES_CTR,
123     FS_AES_XTS,
124 } FS_CRYPTS;
125 
126 typedef struct {
127     // Initialized by user
128     FS_CRYPTS type; // algorithm type
129     ui8* key;       // algorithm secret key
130     int keylen;     // key length
131 
132     // Private data for encryption/file system layer
133     ui32 page_sz; // file system min read/write size
134     ui32 buf_pgs; // encryption buffer size in pages
135     void* fs_vol; // parameter passed to FS driver functions
136     int (*fs_wr)(const void* buf, ui32 frst, int n, void* fs_vol);
137     int (*fs_rd)(void* buf, ui32 frst, int n, void* fs_vol);
138 } FSCryptDrvr;
139 #endif /* FS_CRYPT */
140 
141 // FFS NAND specific driver interface
142 typedef struct {
143     ui32 start_page;      // volume first page on flash
144     ui32 read_wear_limit; // device read-wear limit
145     int (*write_page)(const void* buffer, ui32 pn, ui32 type, void* vol);
146     int (*write_pages)(ui32 start_pn, ui32 count, const void* data, void* spare, void* ndm);
147     int (*read_page)(ui32 pn, void* buffer, void* vol);
148     int (*read_pages)(ui32 start_pn, ui32 count, void* data, void* spare, void* ndm);
149     int (*transfer_page)(ui32 old_pn, ui32 new_pn, ui8* data, ui8* spare, void* ndm);
150     int (*read_type)(ui32 pn, ui32* typep, void* vol);
151     int (*page_erased)(ui32 pn, void* vol);
152     int (*erase_block)(ui32 pn, void* vol);
153 #if INC_FFS_NDM_MLC || INC_FTL_NDM_MLC
154     ui32 (*pair_offset)(ui32 page_offset, void* vol);
155 #endif
156 #if FS_DVR_TEST
157     int spare_size;
158     void (*chip_show)(void* vol);
159     int (*rd_raw_page)(ui32 pn, void* buf, void* vol);
160     int (*is_block_bad)(ui32 addr, void* dev);
161 #endif
162 } FsNandDriver;
163 
164 // FFS NOR specific driver interface
165 typedef struct {
166     int (*read_byte)(ui32 addr, void* vol);
167     int (*write_byte)(ui32 addr, ui8 data, void* vol);
168     int (*write_page)(const void* buffer, ui32 addr, void* vol);
169     int (*page_erased)(ui32 addr, void* vol);
170     int (*read_page)(void* buffer, ui32 addr, void* vol);
171     int (*transfer_page)(ui32 old_addr, ui32 new_addr, ui8* buf, void* vol);
172     int (*erase_block)(ui32 addr, void* vol);
173     void (*erase_wait)(void* vol);
174 #if FS_DVR_TEST
175     void (*chip_show)(void* vol);
176     int (*chip_erase)(void* vol);
177 #endif
178 } FsNorDriver;
179 
180 typedef union {
181     FsNandDriver nand;
182     FsNorDriver nor;
183 } FfsDriver;
184 
185 // FFS structure holding all driver information
186 typedef struct {
187     char* name;          // name of this volume
188     ui32 type;           // vol flash type
189     ui32 block_size;     // minimum erasable block size in bytes
190     ui32 page_size;      // page size in bytes
191     ui32 num_blocks;     // number of blocks in volume
192     ui32 mem_base;       // volume base address
193     ui32 extra_free;     // extra free space for faster execution
194     ui32 file_cache_kbs; // user data cache size in KBs
195     void* vol;           // driver's volume pointer
196     void* vol_handle;    // next_sect_chain() handle
197     ui32 flags;
198     FfsDriver driver;
199 } FfsVol;
200 
201 // XFS structure holding all driver information
202 typedef struct XfsVol {
203     // Driver functions
204     int (*write_pages)(const void* buf, ui32 frst_pg, int cnt, void* vol);
205     int (*read_pages)(void* buf, ui32 frst_pg, int cnt, void* vol);
206     int (*report)(void* vol, ui32 msg, ...);
207 
208 #if FS_CRYPT
209     FSCryptDrvr fs_crypt; // handle for encryption layer
210 #endif
211 
212     const char* name;       // volume name
213     ui32 flags;             // option flags
214     ui32 start_page;        // first page in volume
215     ui32 num_pages;         // number of pages in volume
216     ui32 page_size;         // page size in bytes
217     ui32 file_cache_kbs;    // user data cache size in kbs
218     ui32 min_sect_size;     // minimum desired sector size
219     ui32 dcache_min_d_ents; // minimum/maximum number of directory
220     ui32 dcache_max_d_ents; // entries for a directory to be cached
221     ui32 dcache_size;       // number of directories to be cached
222     void* vol;              // driver's volume pointer
223     void* ftl_volume;       // ftl layer (block device) volume
224 } XfsVol;
225 
226 // FAT structure holding all driver information
227 typedef struct {
228     // Driver functions
229     int (*write_sectors)(const void* buf, ui32 f_sect, int cnt, void* vol);
230     int (*read_sectors)(void* buf, ui32 first_sect, int count, void* vol);
231     int (*report)(void* vol, ui32 msg, ...);
232     void (*slow_mount)(const char* name);
233 
234 #if FS_CRYPT
235     FSCryptDrvr fs_crypt; // handle for encryption layer
236 #endif
237 
238     const char* name;            // volume name
239     void* vol_sem;               // driver-provided volume semaphore
240     ui32 serial_num;             // volume serial number - for FSUID
241     ui32 cached_fat_sects;       // FAT cache size (# of sectors)
242     ui32 num_heads;              // number of heads
243     ui32 sects_per_trk;          // sectors per track
244     ui32 start_sect;             // starting sector for partition
245     ui32 num_sects;              // total number of volume sectors
246     ui32 sect_size;              // sector size in bytes
247     ui32 file_cache_kbs;         // user data cache size in KBs
248     ui32 dir_cache_kbs;          // directory cache size in KBs
249     ui32 min_clust_size;         // minimum cluster size in bytes
250     ui32 flags;                  // option flags
251     void* vol;                   // driver's volume pointer
252     void* vol_handle;            // next_sect_chain() handle
253     ui8 desired_sects_per_clust; // desired cluster size
254     ui8 desired_type;            // desired FAT type
255     ui8 fixed;                   // fixed/removable media flag
256 } FatVol;
257 
258 // FTL NDM structure holding all driver information
259 typedef struct {
260     ui32 block_size;       // size of a block in bytes
261     ui32 num_blocks;       // total number of blocks
262     ui32 page_size;        // flash page data size in bytes
263     ui32 eb_size;          // flash page spare size in bytes
264     ui32 start_page;       // volume first page on flash
265     ui32 cached_map_pages; // number of map pages to be cached
266 #if INC_FTL_PAGE_CACHE
267     ui32 cached_vol_pages; // number of volume pages to be cached
268 #endif
269     ui32 extra_free;      // volume percentage left unused
270     ui32 read_wear_limit; // device read-wear limit
271     void* ndm;            // driver's NDM pointer
272     ui32 flags;           // option flags
273     ui32 type;            // device type
274 
275     // Driver functions:
276     int (*write_data_and_spare)(ui32 pn, const void* data, void* spare, void* ndm);
277     int (*write_pages)(ui32 start_pn, ui32 count, const void* data, void* spare, void* ndm);
278     int (*read_spare)(ui32 pn, void* spare, void* ndm);
279     int (*read_pages)(ui32 start_pn, ui32 count, void* data, void* spare, void* ndm);
280     int (*page_check)(ui32 pn, ui8* data, ui8* spare, void* ndm);
281     int (*transfer_page)(ui32 old_pn, ui32 new_pn, ui8* data, ui8* spare, void* ndm);
282     int (*erase_block)(ui32 pn, void* ndm);
283 #if INC_FFS_NDM_MLC || INC_FTL_NDM_MLC
284     ui32 (*pair_offset)(ui32 page_offset, void* ndm);
285 #endif
286 } FtlNdmVol;
287 
288 // FTL NOR SLC/MLC/SIB/XDS structure holding all driver information
289 typedef struct {
290     ui32 block_size;       // size of a block in bytes
291     ui32 num_blocks;       // total number of blocks
292     ui32 mem_base;         // base address
293     ui32 type;             // vol flash type
294     ui32 cached_map_pages; // number of cached map pages
295     ui32 extra_free;       // volume percentage left unused
296     ui32 read_wear_limit;  // device read-wear limit
297     void* vol;             // driver's volume pointer
298     ui32 flags;            // option flags
299 
300     // Driver functions
301     int (*write_page)(ui32 addr, const void* data, void* vol);
302     int (*transfer_page)(ui32 old_addr, ui32 new_addr, ui8* buf, void* vol);
303     int (*read_page)(ui32 addr, void* data, void* vol);
304     int (*read_pages)(ui32 start_addr, ui32 count, void* data, void* vol);
305     int (*and_byte)(ui32 addr, ui8 data, void* vol);
306     int (*read_byte)(ui32 addr, ui8* data, void* vol);
307     int (*write_long)(ui32 addr, ui32 data, void* vol);
308     int (*read_long)(ui32 addr, ui32* data, void* vol);
309     int (*erase_block)(ui32 addr, void* vol);
310 #if FS_DVR_TEST
311     void (*chip_show)(void* vol);
312     int (*chip_erase)(void* vol);
313 #endif
314 } FtlNorVol;
315 
316 // FTL NOR WR1 structure holding all driver information
317 typedef struct {
318     ui32 block_size;       // size of a block in bytes
319     ui32 num_blocks;       // total number of blocks
320     ui32 mem_base;         // base address
321     ui32 cached_map_pages; // number of cached map pages
322     ui32 extra_free;       // volume percentage left unused
323     ui32 read_wear_limit;  // device read-wear limit
324     void* vol;             // driver's volume pointer
325     ui32 flags;            // option flags
326 
327     // Driver functions
328     int (*write_512B)(ui32 addr, const void* data, void* vol);
329     int (*transfer_512B)(ui32 old_addr, ui32 new_addr, ui8* buf, void* vol);
330     int (*read_512B)(ui32 start_addr, ui32 count, void* data, void* vol);
331     int (*erased_512B)(ui32 addr, void* vol);
332     int (*write_32B)(ui32 addr, const void* data, void* vol);
333     int (*read_32B)(ui32 addr, void* data, void* vol);
334     int (*erased_32B)(ui32 addr, void* vol);
335     int (*erase_block)(ui32 addr, void* vol);
336 #if FS_DVR_TEST
337     void (*chip_show)(void* vol);
338     int (*chip_erase)(void* vol);
339 #endif
340 } FtlWr1Vol;
341 
342 // A partition entry in the partition table
343 // Following values for system_id are supported:
344 // 0x01 = FAT12 partition with fewer than 32680 sectors
345 // 0x04 = FAT16 partition with between 32680 and 65535 sectors
346 // 0x05 = extended DOS partition
347 // 0x06 = BIGDOS FAT primary or logical drive
348 // 0x0B = FAT32 partition up to 2047 GB
349 typedef struct {
350     ui32 first_sect; // first actual sector of partition (from 0)
351     ui32 num_sects;  // total number of sectors in partition
352     ui16 start_cyl;  // starting cylinder
353     ui16 end_cyl;    // ending cylinder
354     ui8 boot_id;     // 0x80 if bootable partition, 0x00 otherwise
355     ui8 start_head;  // starting head
356     ui8 start_sect;  // starting sector in track
357     ui8 type;        // partition type
358     ui8 end_head;    // ending head
359     ui8 end_sect;    // ending sector in track
360 } FATPartition;
361 
362 // Opaque Definition of TargetFAT's Internal Control Block
363 typedef struct fat FAT;
364 
365 // FS Report Events
366 typedef enum {
367     FS_MOUNT,
368     FS_UNMOUNT,
369     FS_FORMAT,
370     FS_VCLEAN,
371     FS_MARK_UNUSED,
372     FS_SYNC,
373     FS_FLUSH_SECT,
374     FS_VSTAT,
375     FS_UNFORMAT,
376     FS_PAGE_SZ,
377     FS_FAT_SECTS,
378     FS_FORMAT_RESET_WC,
379 } FS_EVENTS;
380 
381 // Flash Controller Configuration Codes
382 typedef enum {
383     AMD_LVM_CFG,
384     HY27US08B_CFG,
385     MT29F_CLR_CFG,
386     MT29F_SLC_CFG,
387     MT29F_SPI_CFG,
388     MT29F_ECC_CFG,
389     SAMS_K9GAG_CFG,
390     SAMS_K9WAG_CFG,
391     SAMS_ETC_CFG,
392     SAMS_KFK_CFG,
393     SPSN_FLP_CFG,
394     SPSN_GLN_CFG,
395     SPSN_GLS_CFG,
396     SPSN_WSP_CFG,
397     SPSN_XDS_CFG,
398     S25FL032_CFG,
399     S34ML01G1_CFG,
400     S34ML02G1_CFG,
401     ST_NANDA_CFG,
402     ST_NANDB_CFG,
403     ST_25P32_CFG,
404     NMX_MLC_CFG,
405     NMX_M29EW_CFG,
406     NMX_SIB_CFG,
407     M25PE80_CFG,
408     TC58BVG0S_CFG,
409     RAM_DVR_CFG,
410     SAMS_K9F1G_CFG
411 } FL_BUS_CFG;
412 
413 /***********************************************************************/
414 /* Variable Declarations                                               */
415 /***********************************************************************/
416 extern SEM FileSysSem;
417 extern SEM FsNvramSem;
418 extern const ui8 NumberOnes[];
419 
420 /***********************************************************************/
421 /* Function Prototypes                                                 */
422 /***********************************************************************/
423 int FfsAddVol(FfsVol* vol);
424 int FfsAddNdmVol(FfsVol* vol, ui8* spare_buf);
425 int FatAddVol(FatVol* vol);
426 int XfsAddVol(XfsVol* vol);
427 int FtlNorAddFatVol(FtlNorVol* ftl_dvr, FatVol* fat_dvr);
428 int FtlWr1AddFatVol(FtlWr1Vol* ftl_dvr, FatVol* fat_dvr);
429 int FtlNorAddXfsVol(FtlNorVol* ftl_dvr, XfsVol* xfs_dvr);
430 int FtlWr1AddXfsVol(FtlWr1Vol* ftl_dvr, XfsVol* xfs_dvr);
431 
432 // FAT interface to its underlying driver
433 FAT* FatVolOpen(const char* name);
434 int FatVolClose(FAT** fat);
435 int FatVolSync(FAT* fat);
436 int FatVolWriteSectors(FAT* fat, void* buf, ui32 first_sect, int count);
437 int FatVolReadSectors(FAT* fat, void* buf, ui32 first_sect, int count);
438 int FatVolSize(const FAT* fat, ui32* num_sects, ui32* sect_size);
439 
440 // FAT recovery API
441 int FatVolCheck(const char* name);
442 int FatVolFix(const char* name);
443 
444 // FAT volume label setting/retrieval APIs
445 int FatReadLabel(const char* vol_name, char* label, size_t label_sz);
446 int FatWriteLabel(const char* vol_name, const char* label);
447 
448 // Partition access/modification functions
449 int FatRdPartitions(const FatVol* fat_vol, FATPartition* partitions, int max_partitions);
450 int FatWrPartitions(const FatVol* fat_vol, FATPartition* partitions, int num_partitions);
451 int FatWrPartition(const FatVol* fat_vol);
452 int FatGetPartitions(const ui8* boot_rec, FATPartition* partitions, int max_partitions);
453 int FatTotNumPartitions(const FatVol* fat_vol);
454 
455 // FAT-Lite functions
456 int FatlAddVol(FatVol* driver);
457 int FatlDelVol(void);
458 int FatlRdPartitions(const FatVol* fat_vol, FATPartition* partitions, int max_partitions);
459 int FatlNumPartitions(const FatVol* fat_vol);
460 int FatlError(int err_code);
461 
462 // 1 bit correction ECC encoding/decoding functions
463 void eccEnc512B1E(const ui8* data, ui8* ecc); // 3 bytes of ECC
464 int eccDec512B1E(ui8* data, const ui8* ecc);  // 3 bytes of ECC
465 int eccDec512B1E2(ui8* data, const ui8* read_ecc, const ui8* calc_ecc);
466 void eccEnc14B1E(const ui8* data, ui8* ecc); // 2 bytes of ECC
467 int eccDec14B1E(ui8* data, const ui8* ecc);  // 2 bytes of ECC
468 
469 // 4 bit correction ECC encoding/decoding functions
470 void eccEnc512B4E(const ui8* data, ui8* ecc); // 10 bytes of ECC
471 int eccDec512B4E(ui8* data, const ui8* ecc);  // 10 bytes of ECC
472 void eccEnc14B4E(const ui8* data, ui8* ecc);  // 5 bytes of ECC
473 int eccDec14B4E(ui8* data, const ui8* ecc);   // 5 bytes of ECC
474 
475 // File System API to interact with NVRAM
476 void FsSaveMeta(ui32 vol_id, ui32 meta, const char* vol_name);
477 int FsReadMeta(ui32 vol_id, ui32* meta, const char* vol_name);
478 
479 // Driver Test Routines
480 int FfsNorDvrTestAdd(const FfsVol* vol);
481 int FtlrDvrTestAdd(const FtlNorVol* ftl_vol);
482 int FtlWr1DvrTestAdd(const FtlWr1Vol* ftl_vol);
483 
484 // NAND Flash Controller
485 int nandInit(FL_BUS_CFG config);
486 void nandCfgShow(char* beg, char* end);
487 void nandWrEn(void);
488 void nandWrDis(void);
489 void nandLowerCE(int instance);
490 void nandRaiseCE(int instance);
491 void nandAddr1B(uint b1);
492 void nandAddr2B(uint b1, uint b2);
493 void nandAddr3B(uint b1, uint b2, uint b3);
494 void nandAddr4B(uint b1, uint b2, uint b3, uint b4);
495 void nandAddr5B(uint b1, uint b2, uint b3, uint b4, uint b5);
496 void nandCmd(uint cnd);
497 void nandBusyWait(int instance);
498 void nandWrData8(const ui8* src, uint number);
499 void nandRdData8(ui8* dst, uint number);
500 int nandErased8(uint number);
501 void nandEccStart(void);
502 void nandEccStop(void);
503 void nandGet512B1E(ui8* ecc_ptr);
504 void nandGet512B1ETest(ui8* data, ui8* ecc);
505 int nandDec512B1E(ui8* data, const ui8* read_ecc, const ui8* calc_ecc);
506 void nandKeyStart(void);
507 ui32 nandValidKey(const void* data, uint page_len, ui32 init_val);
508 void nandIntrWait(void);
509 
510 // NOR Flash Controller
511 ui32 norInit(FL_BUS_CFG config);
512 void norCfgShow(char* beg, char* end);
513 void norLowerCE(int instance);
514 ui32 norEnable(ui32 addr, int instance);
515 void norDisable(void);
516 void norWaitINT(void);
517 
518 // SPI Flash Controller
519 void* spiConfig(FL_BUS_CFG config);
520 
521 extern ui32 (*FlCfgFirst)(void);
522 extern ui32 (*FlCfgFaster)(int rc);
523 extern ui32 (*FlCfgSlower)(void);
524 extern void (*FlCfgShow)(char* beg, char* end);
525 extern void (*FlCfgSet)(ui32 cfg);
526 
527 // TargetNDM NVRAM Control Page Storage
528 void NvNdmCtrlPgWr(ui32 frst);
529 ui32 NvNdmCtrlPgRd(void);
530 
531 int next_sect_chain(void* vol_handle, ui32 curr_sect, ui32* next_sect);
532 
533 #ifdef __cplusplus
534 }
535 #endif
536