sysTffs.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:12k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* sysTffs.c - Motorola 860ads system-dependent TrueFFS library */
  2. /* Copyright 1984-1997 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. DESCRIPTION
  6. This library provides board-specific hardware access routines for TrueFFS.
  7. In effect, these routines comprise the socket component driver (or drivers)
  8. for your flash device hardware.  At socket registration time, TrueFFS stores
  9. pointers to the functions of this socket component driver in an 'FLSocket'
  10. structure.  When TrueFFS needs to access the flash device, it uses these
  11. functions. 
  12.  
  13. Because this file is, for the most part, a device driver that exports its
  14. functionality by registering function pointers with TrueFFS, very few of the
  15. functions defined here are externally callable.  For the record, these
  16. external functions are flFitInSocketWindow() and flDelayLoop().  You should
  17. never have any need to call these functions.
  18.  
  19. However, one of the most import functions defined in this file is neither
  20. referenced in an 'FLSocket' structure, nor is it externally callable.  This
  21. function is sysTffsInit().  TrueFFS calls this function at initialization
  22. time to register socket component drivers for all the flash devices attached
  23. to your target.  It is this call to sysTffs() that results in assigning
  24. drive numbers to the flash devices on your target hardware.  Drive numbers
  25. are assigned by the order in which the socket component drivers are registered.
  26. The first to be registered is drive 0, the second is drive 1, and so on up to
  27. 4.  As shipped, TrueFFS supports up to five flash drives.
  28.  
  29. After registering socket component drivers for a flash device, you may
  30. format the flash medium even though there is not yet a block device driver
  31. associated with the flash (see the reference entry for the tffsDevCreate()
  32. routine).  To format the flash medium for use with TrueFFS,
  33. call tffsDevFormat() or, for some BSPs, sysTffsFormat().
  34.  
  35. The sysTffsFormat() routine is an optional but BSP-specific externally
  36. callable helper function.  Internally, it calls tffsDevFormat() with a
  37. pointer to a 'FormatParams' structure initialized to values that leave a
  38. space on the flash device for a boot image. This space is outside the
  39. region managed by TrueFFS.  This special region is necessary for boot
  40. images because the normal translation and wear-leveling services of TrueFFS
  41. are incompatible with the needs of the boot program and the boot image it
  42. relies upon.  To write a boot image (or any other data) into this area,
  43. use tffsBootImagePut(). 
  44.  
  45. Finally, this file also contains define statements for symbolic constants
  46. that determine which MTDs, translation layer modules, and other utilities
  47. are ultimately included in TrueFFS.  These defines are as follows:
  48. .IP "INCLUDE_TL_NFTL"
  49. To include the NAND-based translation layer module.
  50. .IP "INCLUDE_TL_FTL"
  51. To include the NOR-based translation layer module.
  52. .IP "INCLUDE_TL_SSFDC"
  53. To include the SSFDC-appropriate translation layer module.
  54. .IP "INCLUDE_MTD_I28F016"
  55. For Intel 28f016 flash devices.
  56. .IP "INCLUDE_MTD_I28F008"
  57. For Intel 28f008 flash devices.
  58. .IP "INCLUDE_MTD_I28F008_BAJA"
  59. For Intel 28f008 flash devices on the Heurikon Baja 4700.
  60. .IP "INCLUDE_MTD_AMD"
  61. For AMD, Fujitsu: 29F0{40,80,16} 8-bit flash devices.
  62. .IP "INCLUDE_MTD_CDSN"
  63. For Toshiba, Samsung: NAND CDSN flash devices.
  64. .IP "INCLUDE_MTD_DOC2"
  65. For Toshiba, Samsung: NAND DOC flash devices.
  66. .IP "INCLUDE_MTD_CFISCS"
  67. For CFI/SCS flash devices.
  68. .IP "INCLUDE_MTD_WAMD"
  69. For AMD, Fujitsu 29F0{40,80,16} 16-bit flash devices.
  70. .IP "INCLUDE_TFFS_BOOT_IMAGE"
  71. To include tffsBootImagePut() in TrueFFS for Tornado.
  72. .LP
  73. To exclude any of the modules mentioned above, edit sysTffs.c and undefine
  74. its associated symbolic constant.
  75. The function sysTffsFormat() is provided so one might seasily format the 
  76. Flash SIMM to have the TFFS file system in one half of it.
  77. INCLUDE FILES: flsocket.h, tffsDrv.h
  78. */
  79. /* includes */
  80. #include "vxWorks.h"
  81. #include "taskLib.h"
  82. #include "config.h"
  83. #include "tffs/flsocket.h"
  84. #include "tffs/tffsDrv.h"
  85. #include "ixp425rfMap.h"
  86. #if defined(INCLUDE_TFFS)
  87. /* defines */
  88. #define  INCLUDE_MTD_28F128 /* CFI/SCS */
  89. #define INCLUDE_TL_FTL /* FTL translation layer */
  90. #define INCLUDE_TL_SSFDC /* SSFDC translation layer */
  91. #define INCLUDE_TFFS_BOOT_IMAGE /* include tffsBootImagePut() */
  92. /* forward declarations */
  93. LOCAL FLBoolean rfaCardDetected (FLSocket vol);
  94. LOCAL void rfaVccOn (FLSocket vol);
  95. LOCAL void rfaVccOff (FLSocket vol);
  96. #ifdef SOCKET_12_VOLTS
  97. LOCAL FLStatus rfaVppOn (FLSocket vol);
  98. LOCAL void rfaVppOff (FLSocket vol);
  99. #endif /* SOCKET_12_VOLTS */
  100. LOCAL FLStatus rfaInitSocket (FLSocket vol);
  101. LOCAL void rfaSetWindow (FLSocket vol);
  102. LOCAL void rfaSetMappingContext (FLSocket vol, unsigned page);
  103. LOCAL FLBoolean rfaGetAndClearCardChangeIndicator (FLSocket vol);
  104. LOCAL FLBoolean rfaWriteProtected (FLSocket vol);
  105. LOCAL void rfaRegister (void);
  106. #ifndef DOC
  107. #include "tffs/tffsConfig.c"
  108. #endif /* DOC */
  109. /*******************************************************************************
  110. *
  111. * sysTffsInit - board level initialization for TFFS
  112. *
  113. * This routine calls the socket registration routines for the socket component
  114. * drivers that will be used with this BSP. The order of registration signifies
  115. * the logical drive number given to the drive associated with the socket.
  116. *
  117. * RETURNS: N/A
  118. */
  119. LOCAL void sysTffsInit (void)
  120.     {
  121.     rfaRegister (); /* SIMM socket interface register */
  122.     }
  123. /*******************************************************************************
  124. *
  125. * rfaRegister - install routines for the Flash 
  126. *
  127. * This routine installs necessary functions for the Flash.
  128. *
  129. * RETURNS: N/A
  130. */
  131. LOCAL void rfaRegister (void)
  132.     {
  133.     FLSocket vol = flSocketOf (noOfDrives);
  134.     tffsSocket[noOfDrives] = "RFA";
  135.     vol.window.baseAddress = IXP425_EXPANSION_BUS_CS1_BASE>> 12;
  136.     vol.cardDetected = rfaCardDetected;
  137.     vol.VccOn = rfaVccOn;
  138.     vol.VccOff = rfaVccOff;
  139. #ifdef SOCKET_12_VOLTS
  140.     vol.VppOn = rfaVppOn;
  141.     vol.VppOff = rfaVppOff;
  142. #endif
  143.     vol.initSocket = rfaInitSocket;
  144.     vol.setWindow = rfaSetWindow;
  145.     vol.setMappingContext = rfaSetMappingContext;
  146.     vol.getAndClearCardChangeIndicator = rfaGetAndClearCardChangeIndicator;
  147.     vol.writeProtected = rfaWriteProtected;
  148.     noOfDrives++;
  149.     }
  150. /*******************************************************************************
  151. *
  152. * rfaCardDetected - detect if a card is present (inserted)
  153. *
  154. * This routine detects if a card is present (inserted).
  155. *
  156. * RETURNS: TRUE, or FALSE if the card is not present.
  157. */
  158. LOCAL FLBoolean rfaCardDetected
  159.     (
  160.     FLSocket vol /* pointer identifying drive */
  161.     )
  162.     {
  163.     return (TRUE);
  164.     }
  165. /*******************************************************************************
  166. *
  167. * rfaVccOn - turn on Vcc (3.3/5 Volts)
  168. *
  169. * This routine turns on Vcc (3.3/5 Volts).  Vcc must be known to be good
  170. * on exit.
  171. *
  172. * RETURNS: N/A
  173. */
  174. LOCAL void rfaVccOn
  175.     (
  176.     FLSocket vol /* pointer identifying drive */
  177.     )
  178.     {
  179.     }
  180. /*******************************************************************************
  181. *
  182. * rfaVccOff - turn off Vcc (3.3/5 Volts)
  183. *
  184. * This routine turns off Vcc (3.3/5 Volts). 
  185. *
  186. * RETURNS: N/A
  187. */
  188. LOCAL void rfaVccOff
  189.     (
  190.     FLSocket vol /* pointer identifying drive */
  191.     )
  192.     {
  193.     }
  194. #ifdef SOCKET_12_VOLTS
  195. /*******************************************************************************
  196. *
  197. * rfaVppOn - turns on Vpp (12 Volts)
  198. *
  199. * This routine turns on Vpp (12 Volts). Vpp must be known to be good on exit.
  200. *
  201. * RETURNS: flOK always.
  202. */
  203. LOCAL FLStatus rfaVppOn
  204.     (
  205.     FLSocket vol /* pointer identifying drive */
  206.     )
  207.     {
  208.     return (flOK);
  209.     }
  210. /*******************************************************************************
  211. *
  212. * rfaVppOff - turns off Vpp (12 Volts)
  213. *
  214. * This routine turns off Vpp (12 Volts).
  215. *
  216. * RETURNS: N/A
  217. */
  218. LOCAL void rfaVppOff
  219.     (
  220.     FLSocket vol /* pointer identifying drive */
  221.     )
  222.     {
  223.     }
  224. #endif /* SOCKET_12_VOLTS */
  225. /*******************************************************************************
  226. *
  227. * rfaInitSocket - perform all necessary initializations of the socket
  228. *
  229. * This routine performs all necessary initializations of the socket.
  230. *
  231. * RETURNS: flOK always.
  232. */
  233. LOCAL FLStatus rfaInitSocket
  234.     (
  235.     FLSocket vol /* pointer identifying drive */
  236.     )
  237.     {
  238.     return (flOK);
  239.     }
  240. /*******************************************************************************
  241. *
  242. * rfaSetWindow - set current window attributes, Base address, size, etc
  243. *
  244. * This routine sets current window hardware attributes: Base address, size,
  245. * speed and bus width.  The requested settings are given in the 'vol.window' 
  246. * structure.  If it is not possible to set the window size requested in
  247. * 'vol.window.size', the window size should be set to a larger value, 
  248. * if possible. In any case, 'vol.window.size' should contain the 
  249. * actual window size (in 4 KB units) on exit.
  250. *
  251. * RETURNS: N/A
  252. */
  253. LOCAL void rfaSetWindow
  254.     (
  255.     FLSocket vol /* pointer identifying drive */
  256.     )
  257.     {
  258.     /* Physical base as a 4K page */
  259.     vol.window.baseAddress = IXP425_EXPANSION_BUS_CS1_BASE >> 12;
  260.     flSetWindowSize (&vol, FLASH_SECOND_SIZE >> 12);
  261.     }
  262. /*******************************************************************************
  263. *
  264. * rfaSetMappingContext - sets the window mapping register to a card address
  265. *
  266. * This routine sets the window mapping register to a card address.
  267. * The window should be set to the value of 'vol.window.currentPage',
  268. * which is the card address divided by 4 KB. An address over 128MB,
  269. * (page over 32K) specifies an attribute-space address. On entry to this 
  270. * routine vol.window.currentPage is the page already mapped into the window.
  271. * (In otherwords the page that was mapped by the last call to this routine.)
  272. *
  273. * The page to map is guaranteed to be on a full window-size boundary.
  274. *
  275. * RETURNS: N/A
  276. */
  277. LOCAL void rfaSetMappingContext
  278.     (
  279.     FLSocket vol, /* pointer identifying drive */
  280.     unsigned page /* page to be mapped */
  281.     )
  282.     {
  283.     }
  284. /*******************************************************************************
  285. *
  286. * rfaGetAndClearCardChangeIndicator - return the hardware card-change indicator
  287. *
  288. * This routine returns the hardware card-change indicator and clears it if set.
  289. *
  290. * RETURNS: FALSE, or TRUE if the card has been changed
  291. */
  292. LOCAL FLBoolean rfaGetAndClearCardChangeIndicator
  293.     (
  294.     FLSocket vol /* pointer identifying drive */
  295.     )
  296.     {
  297.     return (FALSE);
  298.     }
  299. /*******************************************************************************
  300. *
  301. * rfaWriteProtected - return the write-protect state of the media
  302. *
  303. * This routine returns the write-protect state of the media
  304. *
  305. * RETURNS: FALSE, or TRUE if the card is write-protected
  306. */
  307. LOCAL FLBoolean rfaWriteProtected
  308.     (
  309.     FLSocket vol /* pointer identifying drive */
  310.     )
  311.     {
  312.     return (FALSE);
  313.     }
  314. /*******************************************************************************
  315. *
  316. * flFitInSocketWindow - check whether the flash array fits in the socket window
  317. *
  318. * This routine checks whether the flash array fits in the socket window.
  319. *
  320. * RETURNS: A chip size guaranteed to fit in the socket window.
  321. */
  322. long int flFitInSocketWindow 
  323.     (
  324.     long int chipSize, /* size of single physical chip in bytes */
  325.     int      interleaving, /* flash chip interleaving (1,2,4 etc) */
  326.     long int windowSize /* socket window size in bytes */
  327.     )
  328.     {
  329.     if (chipSize*interleaving > windowSize) /* doesn't fit in socket window */
  330.         {
  331.         int  roundedSizeBits;
  332.         /* fit chip in the socket window */
  333.         chipSize = windowSize / interleaving;
  334.         /* round chip size at powers of 2 */
  335.         for (roundedSizeBits = 0; (0x1L << roundedSizeBits) <= chipSize;
  336.              roundedSizeBits++)
  337.     ;
  338.         chipSize = (0x1L << (roundedSizeBits - 1));
  339.         }
  340.     return (chipSize);
  341.     }
  342. /*******************************************************************************
  343. *
  344. * flDelayLoop - consume the specified time
  345. *
  346. * This routine consumes the specified time.
  347. *
  348. * RETURNS: N/A
  349. */
  350. void flDelayLoop 
  351.     (
  352.     int  cycles
  353.     )
  354.     {
  355.     }
  356. #endif /*INCLUDE_TFFS */