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

VxWorks

开发平台:

C/C++

  1. /* tffsConfig.c - TrueFFS configuration file for VxWorks */
  2. /* Copyright 1984-2001 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /* FAT-FTL Lite Software Development Kit
  5.  * Copyright (C) M-Systems Ltd. 1995-2001 */
  6. /*
  7. modification history
  8. --------------------
  9. 01w,02oct02,nrv  fixing diab build error
  10. 01v,28mar02,nrv  adding INCLUDE_MTD_CFIAMD
  11. 01u,12dec01,nrv  supressing the compiler warning on tffsVersion
  12. 01t,07nov01,yp  fixing SPR #63838
  13. 01s,02nov01,nrv  changing the version number to 2.2
  14. 01r,17sep01,yp  merging code changes from T3. Preserving T2 specifics that
  15.                  were removed in T3
  16. 01q,25apr01,mem  Remove NFTL, CDSN and DOC2.
  17. 01p,20dec00,tlc  Add user-defined "Identify" routine to MTD table.
  18. 01t,23apr01,yp  Incrementing version number to 2.1
  19. 01s,29nov00,tlc  Added MTD_USR_IDENTIFY to the mtdTable. This allows
  20.                  user-defined identify routines to be used for trueFFS
  21.                   support.
  22. 01r,06Sep00,csh  Added code to free pBuf on error SPR #34246
  23. 01q,06Sep00,csh  Added check for pBuf == NULL SPR #34246
  24. 01p,01Sep00,csh  Removed MACRO for INCLUDE_SHOW_ROUTINES
  25. 01o,04feb99,yp   added MACRO INCLUDE_TFFS_SHOW for better scalability.
  26. 01m,21apr98,yp   added tffs subdir to include path
  27. 01n,28feb98,kbw  made man page edits to fix problems found by QE
  28. 01m,28feb98,kbw  made man page edits
  29. 01l,19jan98,hdn  added new function tffsShowAll().
  30. 01k,08jan98,hdn  added new MTD for Heurikon Baja4700.
  31. 01j,06jan98,hdn  cleaned up tffsShow() and tffsBootImagePut().
  32. 01i,18dec97,yp   added documentation on sharing bootrom with TFFS
  33. 01h,15dec97,yp   doc cleanup
  34. 01g,11dec97,hdn  added tffsRawio()'s return value check in tffsShow().
  35. 01f,08dec97,hdn  renamed mkbootTffs() to tffsCopy().
  36. 01e,05dec97,hdn  changed tffsSocket[] to LOCAL variable.
  37. 01d,05dec97,hdn  added tffsShow() and mkbootTffs().
  38. 01c,11nov97,hdn  fixed documentation of flRegisterComponents().
  39. 01b,07nov97,hdn  cleaned up.
  40. 01a,07jul97,ami  written by Amirban at M-Systems
  41. */
  42. /*
  43. DESCRIPTION
  44. This source file, with the help of sysTffs.c, configures TrueFFS for VxWorks.  
  45. The functions defined here are generic to all BSPs.  To include these functions
  46. in the BSP-specific module, the BSP's sysTffs.c file includes this file.  
  47. Within the sysTffs.c file, define statements determine which functions from 
  48. the tffsConfig.c file are ultimately included in TrueFFS.
  49. The only externally callable routines defined in this file 
  50. are tffsShow(), tffsShowAll(), and tffsBootImagePut().  You can
  51. exclude the show utilities if you edit config.h and 
  52. undefine INCLUDE_SHOW_ROUTINES.  You can exclude tffsBootImagePut() if you
  53. edit sysTffs.c and undefine INCLUDE_TFFS_BOOT_IMAGE.  (If you find these
  54. utilities are missing and you want them included, edit config.h and 
  55. define INCLUDE_SHOW_ROUTINES and INCLUDE_TFFS_BOOT_IMAGE.)
  56. If you wish to include only the TrueFFS specific show routines you could
  57. define INCLUDE_TFFS_SHOW instead of INCLUDE_SHOW_ROUTINES in config.h.
  58. However, for the most part, these externally callable routines are only 
  59. a small part of the TrueFFS configuration needs handled by this file.  
  60. The routines internal to this file make calls into the MTDs and translation 
  61. layer modules of TrueFFS.  At link time, resolving the symbols associated 
  62. with these calls pulls MTD and translation layer modules into VxWorks. 
  63. However, each of these calls to the MTDs and the translation layer modules
  64. is only conditionally included.  The constants that control the includes
  65. are defined in sysTffs.c.  To exclude an MTD or translation layer module,
  66. you edit sysTffs.c, undefine the appropriate constant, and rebuild sysTffs.o.
  67. These constants are described in the reference entry for 'sysTffs'. 
  68. INCLUDE FILES: stdcomp.h
  69. */
  70. /* includes */
  71. #include "tffs/stdcomp.h"
  72. #include "tffs/tffsDrv.h"
  73. #include "tffs/fatlite.h"
  74. #include "stdio.h"
  75. /* defines */
  76. #ifdef INCLUDE_SHOW_ROUTINES
  77. #define INCLUDE_TFFS_SHOW
  78. #endif /* INCLUDE_SHOW_ROUTINES */
  79. /* externs */
  80. #ifdef INCLUDE_MTD_USR
  81. FLStatus  MTD_USR_IDENTIFY (FLFlash vol);
  82. #endif /* INCLUDE_MTD_USR */
  83. /* globals */
  84. MTDidentifyRoutine mtdTable[] =  /* MTD tables */
  85.     {
  86. #ifdef  INCLUDE_MTD_CFIAMD
  87.     cfiAmdIdentify,
  88. #endif  /* INCLUDE_MTD_CFIAMD */
  89. #ifdef INCLUDE_MTD_CFISCS
  90.     cfiscsIdentify,
  91. #endif /* INCLUDE_MTD_CFISCS */
  92. #ifdef INCLUDE_MTD_I28F016
  93.     i28f016Identify,
  94. #endif /* INCLUDE_MTD_I28F016 */
  95. #ifdef INCLUDE_MTD_I28F008
  96.     i28f008Identify,
  97. #endif /* INCLUDE_MTD_I28F008 */
  98. #ifdef INCLUDE_MTD_I28F008_BAJA
  99.     i28f008BajaIdentify,
  100. #endif /* INCLUDE_MTD_I28F008_BAJA */
  101. #ifdef INCLUDE_MTD_AMD
  102.     amdMTDIdentify,
  103. #endif /* INCLUDE_MTD_AMD */
  104. #ifdef INCLUDE_MTD_USR
  105.     MTD_USR_IDENTIFY,
  106. #endif  /* INCLUDE_MTD_USR */
  107. #ifdef INCLUDE_MTD_WAMD
  108.     flwAmdMTDIdentify,
  109. #endif /* INCLUDE_MTD_WAMD */
  110. #ifdef INCLUDE_MTD_28F128
  111.     i28f128Identify, 
  112. #endif
  113.     NULL
  114.     };
  115. int noOfMTDs = NELEMENTS (mtdTable) - 1; /* number of MTDs */
  116. TLentry tlTable[] =  /* TL tables */
  117.     {
  118. #ifdef INCLUDE_TL_FTL
  119. #ifdef FORMAT_VOLUME
  120.     {mountFTL, formatFTL},
  121. #else
  122.     mountFTL,
  123. #endif /* FORMAT_VOLUME */
  124. #endif /* INCLUDE_TL_FTL */
  125. #ifdef INCLUDE_TL_SSFDC
  126. #ifdef FORMAT_VOLUME
  127.     {mountSSFDC, formatSSFDC},
  128. #else
  129.     mountSSFDC,
  130. #endif /* FORMAT_VOLUME */
  131. #endif /* INCLUDE_TL_SSFDC */
  132. #ifdef FORMAT_VOLUME
  133.     {NULL, NULL}
  134. #else
  135.     NULL
  136. #endif
  137.     };
  138. int noOfTLs = NELEMENTS (tlTable) - 1; /* number of TLs */
  139. /* locals */
  140. LOCAL char * tffsSocket[DRIVES] = {NULL}; /* name of the socket interface */
  141. #ifdef INCLUDE_TFFS_SHOW 
  142. LOCAL char * tffsVersion = "2.2"; /* WRS version number of TFFS */
  143. #endif /* INCLUDE_TFFS_SHOW */
  144. /* forward declarations */
  145. LOCAL VOID sysTffsInit (void); /* BSP dependent init routine */
  146. /*******************************************************************************
  147. *
  148. * flRegisterComponents - register MTD and translation layer components for use
  149. *
  150. * This routine registers MTD and translation layer components for use.
  151. * This function is called by FLite once only, at initialization of the
  152. * FLite system.
  153. *
  154. * NOMANUAL
  155. *
  156. * RETURNS: N/A
  157. */
  158. void flRegisterComponents (void)
  159.     {
  160.     sysTffsInit ();
  161.     }
  162. #ifdef INCLUDE_TFFS_SHOW
  163. /*******************************************************************************
  164. *
  165. * tffsShowAll - show device information on all socket interfaces 
  166. *
  167. * This routine prints device information on all socket interfaces. 
  168. *
  169. * RETURNS: N/A
  170. */
  171. void tffsShowAll (void)
  172.     {
  173.     int ix;
  174.     printf ("TFFS Version %sn", tffsVersion);
  175.     printf("noOfDrives = %dn", noOfDrives);
  176.     for (ix = 0; ix < noOfDrives; ix++)
  177. tffsShow (ix);
  178.     }
  179. /*******************************************************************************
  180. *
  181. * tffsShow - show device information on a specific socket interface 
  182. *
  183. * This routine prints device information on the specified socket interface. 
  184. * This information is particularly useful when trying to determine the 
  185. * number of Erase Units required to contain a boot image.  The field called
  186. * unitSize reports the size of an Erase Unit.
  187. *
  188. * If the process of getting physical information fails, an error code is 
  189. * printed. The error codes can be found in flbase.h.
  190. *
  191. * RETURNS: N/A
  192. */
  193. void tffsShow 
  194.     (
  195.     int driveNo /* TFFS drive number */
  196.     )
  197.     {
  198.     PhysicalInfo info;
  199.     FLStatus status;
  200.     printf("tffSocket[%d] = %sn", driveNo, tffsSocket[driveNo] );
  201.     if (tffsSocket[driveNo] == NULL)
  202. {
  203.         printf ("%d: ---- no socket interface installed ----n", driveNo);
  204. return;
  205. }
  206.     status = tffsRawio (driveNo, TFFS_GET_PHYSICAL_INFO, (int)&info, 0, 0);
  207.     if (status != OK)
  208. {
  209.         printf ("%d: **** communication failed with error %d ****n",
  210.                 driveNo, status);
  211. return;
  212. }
  213.     printf ("%d: socket=%s: ", driveNo, tffsSocket[driveNo]);
  214.     printf ("type=0x%x, unitSize=0x%x, mediaSize=0x%xn", info.type, 
  215.     (UINT)info.unitSize, (UINT)info.mediaSize);
  216.     }
  217. #endif /* INCLUDE_TFFS_SHOW */
  218. #ifdef INCLUDE_TFFS_BOOT_IMAGE
  219. /*******************************************************************************
  220. *
  221. * tffsBootImagePut - write to the boot-image region of the flash device
  222. *
  223. * This routine writes an input stream to the boot-image region (if any) of 
  224. * a flash memory device.  Typically, the input stream contains a boot image, 
  225. * such as the VxWorks boot image, but you are free to use this function to 
  226. * write any data needed. The size of the boot-image region is set by 
  227. * the tffsDevFormat() call (or the sysTffsFormat() call, a BSP-specific helper 
  228. * function that calls tffsDevFormat() internally) that formats the flash 
  229. * device for use with TrueFFS.  
  230. * If tffsBootImagePut() is used to put a VxWorks boot image in flash, you 
  231. * should not use the s-record version of the boot image typically produced 
  232. * by make.  Instead, you should take the pre s-record version (usually 
  233. * called 'bootrom' instead of 'bootrom.hex'), and filter out its loader 
  234. * header information using an <xxx>'ToBin' utility.  For example: 
  235. * .CS
  236. * elfToBin < bootrom > bootrom.bin
  237. * .CE
  238. * Use the resulting 'bootrom.bin' as input to tffsBootImagePut(). 
  239. * The discussion above assumes that you want only to use the flash device to
  240. * store a VxWorks image that is retrieved from the flash device and then run 
  241. * out of RAM. However, because it is possible to map many flash devices 
  242. * directly into the target's memory, it is also possible run the VxWorks 
  243. * image from flash memory, although there are some restrictions:
  244. * .IP "-"
  245. * The flash device must be non-NAND. 
  246. * .IP "-"
  247. * Only the text segment of the VxWorks image ('vxWorks.res_rom') may run out 
  248. * of flash memory. The data segment of the image must reside in standard RAM. 
  249. * .IP "-"
  250. * No part of the flash device may be erased while the VxWorks image is running 
  251. * from flash memory. 
  252. * .LP
  253. * Because TrueFFS garbage collection triggers an erase, this last restriction 
  254. * means that you cannot run a VxWorks boot image out of a flash device that 
  255. * must also support a writable file system (although a read-only file system 
  256. * is OK). 
  257. * This last restriction arises from the way in which flash devices are
  258. * constructed. The current physical construction of flash memory devices does 
  259. * not allow access to the device while an erase is in 
  260. * progress anywhere on the flash device. As a result, if TrueFFS tries to 
  261. * erase a portion of the flash device, the entire device becomes inaccessible 
  262. * to all other users.  If that other user happens to be the VxWorks image 
  263. * looking for its next instruction, the VxWorks image crashes.
  264. *
  265. *RETURNS: OK or ERROR
  266. */
  267. STATUS tffsBootImagePut 
  268.     (
  269.     int driveNo, /* TFFS drive number */
  270.     int offset, /* offset in the flash chip/card */
  271.     char * filename /* binary format of the bootimage */
  272.     )
  273.     {
  274.     PhysicalInfo info;
  275.     UINT unitNo;
  276.     UINT unitSize;
  277.     UINT addr;
  278.     char * pBuf;
  279.     int fd;
  280.     int ix;
  281.     if (tffsSocket[driveNo] == NULL)
  282. return (ERROR);
  283.     if (tffsRawio (driveNo, TFFS_GET_PHYSICAL_INFO, (int)&info, 0, 0) != OK)
  284.         {
  285.         printErr ("Unable to get physical info from driven");
  286. return (ERROR);
  287. }
  288.     if ((pBuf = (char *)malloc (info.unitSize)) == NULL)
  289. {
  290.         printErr ("Can't allocate %d bytes of memoryn", info.unitSize);
  291. return( ERROR ) ;
  292. }
  293.     if ((fd = open (filename, O_RDONLY, 0644)) == ERROR)
  294.         {
  295.         printErr ("Can't open "%s"n", filename);
  296. free( pBuf ) ;
  297.         return (ERROR);
  298. }
  299.     addr = offset;
  300.     unitNo = offset / info.unitSize;
  301.     unitSize = info.unitSize - (offset % info.unitSize);
  302.     /* If the offset is not Erase Unit aligned we need to save the the
  303.      * contents of the region begining at the start of this erase unit 
  304.      * and ending at the specified address so we can restore it after
  305.      * we erase the Erase Unit
  306.      */
  307.     if (tffsRawio (driveNo, TFFS_PHYSICAL_READ, unitNo * info.unitSize,
  308.            offset % info.unitSize, (int)pBuf) != OK)
  309.         {
  310. printErr ("Failed attempting to save Erase Unit %dn", unitNo);
  311. close (fd);
  312. free( pBuf ) ;
  313. return (ERROR);
  314. }
  315.         
  316.     if (tffsRawio (driveNo, TFFS_PHYSICAL_ERASE, unitNo, 1, 0) != OK)
  317. {
  318. printErr ("Failed attempting to erase Erase Unit %dn", unitNo);
  319. close (fd);
  320. free( pBuf ) ;
  321. return (ERROR);
  322. }
  323.     if (tffsRawio (driveNo, TFFS_PHYSICAL_WRITE, unitNo * info.unitSize,
  324.            offset % info.unitSize, (int)pBuf) != OK)
  325.         {
  326. printErr ("Failed attempting to restore Erase Unit %dn", unitNo);
  327. close (fd);
  328. free( pBuf ) ;
  329. return (ERROR);
  330. }
  331.     while (unitSize)
  332. {
  333.         if ((ix = read (fd, pBuf, unitSize)) == ERROR)
  334.             {
  335.             printErr ("Error reading inputfile: 0x%xn", errno);
  336.     free( pBuf ) ;
  337.             return (ERROR);
  338.             }
  339.         if (ix == 0)
  340.     break;
  341.         if ((addr + ix) > info.mediaSize)
  342.     {
  343.     printErr ("Error : Attempting to write beyond Flash boundaryn");
  344.     close (fd);
  345.     free( pBuf ) ;
  346.     return (ERROR);
  347.     }
  348.         if (tffsRawio (driveNo, TFFS_PHYSICAL_WRITE, addr, ix, (int)pBuf) != OK)
  349.     {
  350.     printErr ("Physical write failed at address 0x%xn", addr);
  351.     close (fd);
  352.     free( pBuf ) ;
  353.     return (ERROR);
  354.     }
  355. addr += ix;
  356. unitSize -= ix;
  357. if (unitSize == 0)
  358.     {
  359.             unitSize = info.unitSize;
  360.             unitNo++;
  361.             if (tffsRawio (driveNo, TFFS_PHYSICAL_ERASE, unitNo, 1, 0) != OK)
  362.         {
  363. printErr ("Failed attempting to erase Erase Unit %dn", unitNo);
  364.         close (fd);
  365.         free( pBuf ) ;
  366.         return (ERROR);
  367.         }
  368.     }
  369. }
  370.     close (fd);
  371.     free( pBuf ) ;
  372.     return (OK);
  373.     }
  374.     
  375. #endif /* INCLUDE_TFFS_BOOT_IMAGE */