Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

304 lines
12 KiB

  1. /*
  2. * $Log: V:/Flite/archives/TrueFFS5/Src/MTDSA.C_V $
  3. *
  4. * Rev 1.14 Apr 15 2002 07:37:56 oris
  5. * flBusConfig array was changed from byte variables to dword.
  6. *
  7. * Rev 1.13 Jan 23 2002 23:33:48 oris
  8. * Bad include directive to flBuffer.h
  9. *
  10. * Rev 1.12 Jan 17 2002 23:03:24 oris
  11. * Changed flbase.h include with docsys.h and nanddefs.h
  12. * Moved boot SDK MTD related variables from docbdk.c
  13. * Define flSocketOf and flFlashOf routines.
  14. *
  15. * Rev 1.11 Jul 13 2001 01:07:40 oris
  16. * Added readback buffer allocation and flBuffer.h include directive.
  17. *
  18. * Rev 1.10 Jun 17 2001 22:29:52 oris
  19. * Removed typo *
  20. *
  21. * Rev 1.9 Jun 17 2001 16:39:12 oris
  22. * Improved documentation and remove warnings.
  23. *
  24. * Rev 1.8 May 29 2001 19:48:32 oris
  25. * Compilation problem when using the default delay routine.
  26. *
  27. * Rev 1.7 May 21 2001 16:11:02 oris
  28. * Added USE_STD_FUNC ifdef.
  29. *
  30. * Rev 1.6 May 20 2001 14:36:00 oris
  31. * Added delay routines for vx_works and psos OS.
  32. *
  33. * Rev 1.5 May 16 2001 21:20:54 oris
  34. * Bug fix - delay routine did not support delay milliseconds that did not fit into
  35. * a 2 bytes variable.
  36. *
  37. * Rev 1.4 Apr 24 2001 17:10:30 oris
  38. * Removed warnings.
  39. *
  40. * Rev 1.3 Apr 10 2001 23:55:58 oris
  41. * Added flAddLongToFarPointer routine for the standalone version.
  42. *
  43. * Rev 1.2 Apr 09 2001 15:08:36 oris
  44. * End with an empty line.
  45. *
  46. * Rev 1.1 Apr 01 2001 07:53:24 oris
  47. * copywrite notice.
  48. * Removed nested comments.
  49. *
  50. * Rev 1.0 Feb 04 2001 12:19:56 oris
  51. * Initial revision.
  52. *
  53. */
  54. /*************************************************************************/
  55. /* M-Systems Confidential */
  56. /* Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2001 */
  57. /* All Rights Reserved */
  58. /*************************************************************************/
  59. /* NOTICE OF M-SYSTEMS OEM */
  60. /* SOFTWARE LICENSE AGREEMENT */
  61. /* */
  62. /* THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE */
  63. /* AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT */
  64. /* FOR THE SPECIFIC TERMS AND CONDITIONS OF USE, */
  65. /* OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE: */
  66. /* E-MAIL = [email protected] */
  67. /*************************************************************************/
  68. /************************************************************************/
  69. /* */
  70. /* Standalone MTD Kit */
  71. /* */
  72. /************************************************************************/
  73. /************************************************************************/
  74. /* File Header */
  75. /* ----------- */
  76. /* Name : mtdsa.c */
  77. /* */
  78. /* Description : This file contains auxiliary routines for the MTD */
  79. /* standalone package, replacing TrueFFS routines. */
  80. /* */
  81. /* Note : This file should be added to the project only if the */
  82. /* MTS_STANDALONE compilation flag is defined in the file mtdsa.h*/
  83. /* IT HAS NO PART IN A TrueFFS project */
  84. /* */
  85. /************************************************************************/
  86. #include "flbase.h"
  87. #include "nanddefs.h"
  88. #include "docsys.h"
  89. #ifdef MTD_STANDALONE
  90. #include "flbuffer.h" /* defintion for READ_BACK_BUFFER_SIZE */
  91. #if (defined (VERIFY_WRITE) || defined(VERIFY_ERASE) || defined(MTD_RECONSTRUCT_BBT))
  92. byte globalReadBack[SOCKETS][READ_BACK_BUFFER_SIZE];
  93. #endif /* VERIFY_WRITE */
  94. #if (defined (HW_PROTECTION) || defined (HW_OTP) || defined (MTD_READ_BBT_CODE) || !defined (NO_IPL_CODE) || defined(MTD_READ_BBT))
  95. FLBuffer globalMTDBuffer;
  96. #endif /* HW_PROTECTION || HW_OTP || NO_IPL_CODE || MTD_READ_BBT */
  97. #ifndef FL_NO_USE_FUNC
  98. dword flBusConfig[SOCKETS] = {FL_NO_ADDR_SHIFT |
  99. FL_BUS_HAS_8BIT_ACCESS |
  100. FL_BUS_HAS_16BIT_ACCESS |
  101. FL_BUS_HAS_32BIT_ACCESS};
  102. #endif /* FL_NO_USE_FUNC */
  103. FLFlash flash[SOCKETS]; /* flash record for the stand alone version */
  104. FLSocket socket[SOCKETS]; /* socket record for the stand alone version */
  105. NFDC21Vars docMtdVars[SOCKETS]; /* flash internal record */
  106. MTDidentifyRoutine mtdTable [MTDS];
  107. SOCKETidentifyRoutine socketTable[MTDS];
  108. FREEmtd freeTable [MTDS];
  109. int noOfMTDs = 0;
  110. /************************************************************************/
  111. /* f l F l a s h O f */
  112. /* */
  113. /* Gets the flash connected to a volume no. */
  114. /* */
  115. /* Parameters: */
  116. /* volNo : Volume no. for which to get flash */
  117. /* */
  118. /* Returns: */
  119. /* flash of volume no. */
  120. /************************************************************************/
  121. FLFlash *flFlashOf(unsigned volNo)
  122. {
  123. return &flash[volNo];
  124. }
  125. /************************************************************************/
  126. /* f l S o c k e t O f */
  127. /* */
  128. /* Gets the socket connected to a volume no. */
  129. /* */
  130. /* Parameters: */
  131. /* volNo : Volume no. for which to get socket */
  132. /* */
  133. /* Returns: */
  134. /* socket of volume no. */
  135. /************************************************************************/
  136. FLSocket *flSocketOf(unsigned volNo)
  137. {
  138. return &socket[volNo];
  139. }
  140. /************************************************************************/
  141. /************************************************************************/
  142. /**** P l a t f o r m D e p e n d e n t R o u t i n e s ****/
  143. /************************************************************************/
  144. /************************************************************************/
  145. /************************************************************************/
  146. /* Delay */
  147. /*------- */
  148. /* Delay for the specified amount of milliseconds, Scaled by CPU speed. */
  149. /* The function below can be customized to one of the follwing OS: */
  150. /* VXWORKS */
  151. /* PSOS */
  152. /* DOS */
  153. /************************************************************************/
  154. #ifdef DOS_DELAY
  155. #include <dos.h>
  156. #endif /* DOS */
  157. #ifdef PSS_DELAY
  158. /* ticks per second */
  159. #include <bspfuncs.h>
  160. static unsigned long flSysClkRate = (unsigned long) KC_TICKS2SEC;
  161. #define MILLISEC2TICKS(msec) ((flSysClkRate * (msec)) / 1000L)
  162. /************************************************************************/
  163. /* p s s D e l a y M s e c s */
  164. /* */
  165. /* Wait for specified number of milliseconds */
  166. /* */
  167. /* Parameters: */
  168. /* milliseconds : Number of milliseconds to wait */
  169. /* */
  170. /************************************************************************/
  171. void pssDelayMsecs (unsigned milliseconds)
  172. {
  173. unsigned long ticksToWait = MILLISEC2TICKS(milliseconds);
  174. tm_wkafter (ticksToWait ? ticksToWait : 0x1L ); /* go to sleep */
  175. }
  176. #endif /* PSS_DELAY */
  177. #ifdef VXW_DELAY
  178. #include <vxWorks.h>
  179. #include <tickLib.h>
  180. #include <sysLib.h>
  181. void vxwDelayMsecs (unsigned milliseconds)
  182. {
  183. unsigned long stop, ticksToWait;
  184. ticksToWait = (milliseconds * sysClkRateGet()) / 500;
  185. if( ticksToWait == 0x0l )
  186. ticksToWait++;
  187. stop = tickGet() + ticksToWait;
  188. while( tickGet() <= stop );
  189. }
  190. #endif
  191. void flDelayMsecs(unsigned long msec)
  192. {
  193. unsigned curDelay;
  194. #ifdef DOS_DELAY
  195. while (msec>0)
  196. {
  197. curDelay = (unsigned)msec;
  198. delay( curDelay );
  199. msec -= curDelay;
  200. }
  201. #elif defined PSS_DELAY
  202. while (msec>0)
  203. {
  204. curDelay = (unsigned)msec;
  205. pssDelayMsecs (curDelay);
  206. msec -= curDelay;
  207. }
  208. #elif defined VXW_DELAY
  209. while (msec>0)
  210. {
  211. curDelay = (unsigned)msec;
  212. vxwDelayMsecs(curDelay);
  213. msec -= curDelay;
  214. }
  215. #else
  216. while( msec-- > 0 ) curDelay += (unsigned)msec;
  217. #endif /* DOS_DELAY */
  218. }
  219. /************************************************************************/
  220. /* Use customized tffscpy, tffsset and tffscmp routines. */
  221. /************************************************************************/
  222. #ifndef USE_STD_FUNC
  223. /************************************************************************/
  224. /* tffscpy - copy one memory block to the other. */
  225. /************************************************************************/
  226. void tffscpy(void FAR1 *dest, void FAR1 *src, unsigned length)
  227. {
  228. while( length-- )
  229. *(((char FAR1 *)dest)++) = *(((char FAR1 *)src)++);
  230. }
  231. /************************************************************************/
  232. /* tffscmp - compare two memory blocks. */
  233. /************************************************************************/
  234. int tffscmp(void FAR1 *src1, void FAR1 *src2, unsigned length)
  235. {
  236. while( length-- )
  237. if (*(((char FAR1 *)src1)++) != *(((char FAR1 *)src2)++))
  238. return(TRUE);
  239. return(FALSE);
  240. }
  241. /************************************************************************/
  242. /* tffsset - set a memory blocks to a certain value. */
  243. /************************************************************************/
  244. void tffsset(void FAR1 *dest, unsigned char value, unsigned length)
  245. {
  246. while( length-- )
  247. *(((char FAR1 *)dest)++) = value;
  248. }
  249. #endif /* USE_STD_FUNC */
  250. /************************************************************************/
  251. /* f l A d d L o n g T o F a r P o i n t e r */
  252. /* */
  253. /* Add unsigned long offset to the far pointer */
  254. /* */
  255. /* Parameters: */
  256. /* ptr : far pointer */
  257. /* offset : offset in bytes */
  258. /* */
  259. /************************************************************************/
  260. void FAR0 *flAddLongToFarPointer(void FAR0 *ptr, unsigned long offset)
  261. {
  262. return physicalToPointer( pointerToPhysical(ptr) + offset, 0,0 );
  263. }
  264. #endif /* MTD_STANDALONE */