📄 tffsconfig.c
字号:
/* tffsConfig.c - TrueFFS configuration file for VxWorks *//* Copyright 1984-2001 Wind River Systems, Inc. */#include "copyright_wrs.h"/* includes */#include "tffs/stdcomp.h"#include "tffs/tffsDrv.h"#include "tffs/fatlite.h"#include "stdio.h"/* defines */#ifdef INCLUDE_SHOW_ROUTINES#define INCLUDE_TFFS_SHOW#endif /* INCLUDE_SHOW_ROUTINES */#ifdef INCLUDE_MTD_SST39VF160 FLStatus sst39vf160Identify (FLFlash vol);#endif /* INCLUDE_MTD_SST39VF160 */#ifdef INCLUDE_MTD_USRFLStatus MTD_USR_IDENTIFY (FLFlash vol);#endif /* INCLUDE_MTD_USR *//* globals */MTDidentifyRoutine mtdTable[] = /* MTD tables */ {#ifdef INCLUDE_MTD_CFIAMD cfiAmdIdentify,#endif /* INCLUDE_MTD_CFIAMD */#ifdef INCLUDE_MTD_CFISCS cfiscsIdentify,#endif /* INCLUDE_MTD_CFISCS */#ifdef INCLUDE_MTD_I28F016 i28f016Identify,#endif /* INCLUDE_MTD_I28F016 */#ifdef INCLUDE_MTD_I28F008 i28f008Identify,#endif /* INCLUDE_MTD_I28F008 */#ifdef INCLUDE_MTD_I28F008_BAJA i28f008BajaIdentify,#endif /* INCLUDE_MTD_I28F008_BAJA */#ifdef INCLUDE_MTD_AMD amdMTDIdentify,#endif /* INCLUDE_MTD_AMD */#ifdef INCLUDE_MTD_USR MTD_USR_IDENTIFY,#endif /* INCLUDE_MTD_USR */#ifdef INCLUDE_MTD_WAMD flwAmdMTDIdentify,#endif /* INCLUDE_MTD_WAMD *//* : added */#ifdef INCLUDE_MTD_SST39VF160 sst39vf160Identify,#endif /* INCLUDE_MTD_SST39VF160 */ };int noOfMTDs = NELEMENTS (mtdTable); /* number of MTDs */TLentry tlTable[] = /* TL tables */ {#ifdef INCLUDE_TL_FTL#ifdef FORMAT_VOLUME {mountFTL, formatFTL},#else mountFTL,#endif /* FORMAT_VOLUME */#endif /* INCLUDE_TL_FTL */#ifdef INCLUDE_TL_SSFDC#ifdef FORMAT_VOLUME {mountSSFDC, formatSSFDC},#else mountSSFDC,#endif /* FORMAT_VOLUME */#endif /* INCLUDE_TL_SSFDC */ };int noOfTLs = NELEMENTS (tlTable); /* number of TLs *//* locals */LOCAL char * tffsSocket[DRIVES] = {NULL}; /* name of the socket interface */#ifdef INCLUDE_TFFS_SHOW LOCAL char * tffsVersion = "2.2"; /* WRS version number of TFFS */#endif /* INCLUDE_TFFS_SHOW *//* forward declarations */LOCAL VOID sysTffsInit (void); /* BSP dependent init routine *//********************************************************************************* flRegisterComponents - register MTD and translation layer components for use** This routine registers MTD and translation layer components for use.* This function is called by FLite once only, at initialization of the* FLite system.** NOMANUAL** RETURNS: N/A*/void flRegisterComponents (void) { sysTffsInit (); }#ifdef INCLUDE_TFFS_SHOW/********************************************************************************* tffsShowAll - show device information on all socket interfaces ** This routine prints device information on all socket interfaces. ** RETURNS: N/A*/void tffsShowAll (void) { int ix; printf ("TFFS Version %s\n", tffsVersion); for (ix = 0; ix < noOfDrives; ix++) tffsShow (ix); }/********************************************************************************* tffsShow - show device information on a specific socket interface ** This routine prints device information on the specified socket interface. * This information is particularly useful when trying to determine the * number of Erase Units required to contain a boot image. The field called* unitSize reports the size of an Erase Unit.** If the process of getting physical information fails, an error code is * printed. The error codes can be found in flbase.h.** RETURNS: N/A*/void tffsShow ( int driveNo /* TFFS drive number */ ) { PhysicalInfo info; FLStatus status; if (tffsSocket[driveNo] == NULL) { printf ("%d: ---- no socket interface installed ----\n", driveNo); return; } status = tffsRawio (driveNo, TFFS_GET_PHYSICAL_INFO, (int)&info, 0, 0); if (status != OK) { printf ("%d: **** communication failed with error %d ****\n", driveNo, status); return; } printf ("%d: socket=%s: ", driveNo, tffsSocket[driveNo]); printf ("type=0x%x, unitSize=0x%x, mediaSize=0x%x\n", info.type, (UINT)info.unitSize, (UINT)info.mediaSize); }#endif /* INCLUDE_TFFS_SHOW */#ifdef INCLUDE_TFFS_BOOT_IMAGE/********************************************************************************* tffsBootImagePut - write to the boot-image region of the flash device***RETURNS: OK or ERROR*/STATUS tffsBootImagePut ( int driveNo, /* TFFS drive number */ int offset, /* offset in the flash chip/card */ char * filename /* binary format of the bootimage */ ) { PhysicalInfo info; UINT unitNo; UINT unitSize; UINT addr; char * pBuf; int fd; int ix; if (tffsSocket[driveNo] == NULL) return (ERROR); if (tffsRawio (driveNo, TFFS_GET_PHYSICAL_INFO, (int)&info, 0, 0) != OK) { printErr ("Unable to get physical info from drive\n"); return (ERROR); } if ((pBuf = (char *)malloc (info.unitSize)) == NULL) { printErr ("Can't allocate %d bytes of memory\n", info.unitSize); return( ERROR ) ; } if ((fd = open (filename, O_RDONLY, 0644)) == ERROR) { printErr ("Can't open \"%s\"\n", filename); free( pBuf ) ; return (ERROR); } addr = offset; unitNo = offset / info.unitSize; unitSize = info.unitSize - (offset % info.unitSize); if (tffsRawio (driveNo, TFFS_PHYSICAL_READ, unitNo * info.unitSize, offset % info.unitSize, (int)pBuf) != OK) { printErr ("Failed attempting to save Erase Unit %d\n", unitNo); close (fd); free( pBuf ) ; return (ERROR); } if (tffsRawio (driveNo, TFFS_PHYSICAL_ERASE, unitNo, 1, 0) != OK) { printErr ("Failed attempting to erase Erase Unit %d\n", unitNo); close (fd); free( pBuf ) ; return (ERROR); } if (tffsRawio (driveNo, TFFS_PHYSICAL_WRITE, unitNo * info.unitSize, offset % info.unitSize, (int)pBuf) != OK) { printErr ("Failed attempting to restore Erase Unit %d\n", unitNo); close (fd); free( pBuf ) ; return (ERROR); } while (unitSize) { if ((ix = read (fd, pBuf, unitSize)) == ERROR) { printErr ("Error reading inputfile: 0x%x\n", errno); free( pBuf ) ; return (ERROR); } if (ix == 0) break; if ((addr + ix) > info.mediaSize) { printErr ("Error : Attempting to write beyond Flash boundary\n"); close (fd); free( pBuf ) ; return (ERROR); } if (tffsRawio (driveNo, TFFS_PHYSICAL_WRITE, addr, ix, (int)pBuf) != OK) { printErr ("Physical write failed at address 0x%x\n", addr); close (fd); free( pBuf ) ; return (ERROR); } addr += ix; unitSize -= ix; if (unitSize == 0) { unitSize = info.unitSize; unitNo++; if (tffsRawio (driveNo, TFFS_PHYSICAL_ERASE, unitNo, 1, 0) != OK) { printErr ("Failed attempting to erase Erase Unit %d\n", unitNo); close (fd); free( pBuf ) ; return (ERROR); } } } close (fd); free( pBuf ) ; return (OK); } #endif /* INCLUDE_TFFS_BOOT_IMAGE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -