📄 flashfslib.c
字号:
/* flashFsLib.c */
/* Copyright 1984 - 2001 Wind River Systems, Inc. */
/* modification history */
/*-----------------------------------------------------------------------------
V1.09:---------------------------------------------------------------------
05/13/2004 pcd
1. Added to support AMD AM29LV033 flash chip. This code will be used for
KS8695/X/P CPU board
-----------------------------------------------------------------------------*/
/*
DESCRIPTION
* Configure the RFA (flash) device for use by dosFs file system.
*/
#include "types.h"
#include "vxWorks.h"
#include "stdio.h"
#include "stdlib.h"
#include "errno.h"
#include "dosFsLib.h"
#include "rawFsLib.h"
#include "fioLib.h"
#include "blkIo.h"
#include "string.h"
#include "errnoLib.h"
#include "flashFsLib.h"
#include "flashMem.h"
/* Driver debug control */
#define FLASH_DEBUGFS
/* Driver debug control */
#ifdef FLASH_DEBUGFS
#define FLASHFS_DEBUG_OFF 0x0000
#define FLASHFS_DEBUG_ERROR 0x0001
#define FLASHFS_DEBUG_BLKWRITE 0x0002
#define FLASHFS_DEBUG_BLKREAD 0x0004
#define FLASHFS_DEBUG_IOCTL 0x0008
#define FLASHFS_DEBUG_GETPHYS 0x0010
#define FLASHFS_DEBUG_INIT 0x0020
#define FLASHFS_DEBUG_ALL 0xffff
LOCAL int flashFsDebug = ( FLASHFS_DEBUG_ERROR /*| FLASHFS_DEBUG_BLKWRITE */);
#define FS_DRV_PRINT(FLG, X) \
do { \
if (flashFsDebug & FLG) \
printf X; \
} while (0)
#else /* FLASH_DEBUGFS */
#define FS_DRV_PRINT(FLG, X)
#endif /* FLASH_DEBUGFS */
/*
* The 4MB flash part (AMD AM29LV033) is divided into three sections - rfa0/rawFs, flash/dosFs, and rfa2/dosFs.
* /rfa0 begins at sector 0 and ends at sector 15. stored bootrom, total size 1MByte, address 0x02800000
* flash begins at sector 16 and ends at sector 47. stored vxWorks, total size 2MByte, address 0x02900000
* /rfa2 begins at sector 48 and ends at sector 62. stored NVM+, total size (1M-64K)Byte, address 0x02B00000
*/
STATUS flashFsLibInit();
STATUS flashFsBlkRead (FLASH_DEV *, int, int, char *);
STATUS flashFsBlkWrite(FLASH_DEV *, int, int, char *);
STATUS flashFsIoctl(BLK_DEV *, int, int);
STATUS flashFsSync();
STATUS flashFsGetPhys(int, int *, int *);
LOCAL STATUS flashFsRfaConfig (char *, ulong_t, ulong_t, ulong_t, ulong_t);
LOCAL BLK_DEV *flashDevCreate (UINT32, FAST int, int, int);
IMPORT STATUS dosFsConfigInit ( DOS_VOL_CONFIG *, char, UINT8, short, char, UINT16, short, UINT, UINT );
/******************************************************************************
*
* flashFsLibInit - Initializes flash files system for /rfa0, /rfa1, /rfa2
*
* This routine calls flashDrvLibInit and then calls flashFsRfaConfig to setup
* individual rfa sections on the flash.
*
* RETURNS: ERROR if flashDrvLibInit fails, else OK.
*/
STATUS flashFsLibInit()
{
char *name0 = BOOTROM_BASE_FS;
char *name1 = APPL_BASE_FS;
#ifdef INCLUDE_NVM_SPACE
char *name2 = NVM_BASE_FS;
#endif /* INCLUDE_NVM_SPACE */
if( flashDrvLibInit() == ERROR )
{
FS_DRV_PRINT (FLASHFS_DEBUG_ERROR,
( "flashFsLibInit(): flashDrvLibInit() failed\n" ));
return( ERROR );
}
/* AMD AM29LV033 */
/* rawFS (bootrom) starting at sector 0 boot sector (1MByte) */
flashFsRfaConfig(name0, 0, BOOT_SECTOR_BASE_ADDRESS-FLASH_BASE_ADDRESS,
FLASH_FS_DOS_SECTOR_SIZE, FLASH_RAW_NUM_BLK);
/* dosFS1 (vxWorks) starting at sector 32(2MBytes) */
flashFsRfaConfig(name1, 1, APPLICATION_SECTOR_BASE_ADDRESS-FLASH_BASE_ADDRESS,
FLASH_FS_DOS_SECTOR_SIZE, FLASH_FS2_NUM_BLK);
#ifdef INCLUDE_NVM_SPACE
/* dosFS2 (NVM+) starting at sector 16 (1MBytes) */
flashFsRfaConfig(name2, 2, NVM_SECTOR_BASE_ADDRESS-FLASH_BASE_ADDRESS,
FLASH_FS_DOS_SECTOR_SIZE, FLASH_FS1_NUM_BLK);
#endif
FS_DRV_PRINT (FLASHFS_DEBUG_INIT,
("flashFsLibInit(): Success.\n" ));
return( 0 );
}
/******************************************************************************
*
* flashFsRfaConfig - Configure the RFA (flash) device for use by file system.
*
* This routine creates the flash devices. For unit 0, the flash device is attached
* to rawFs and for units 1 and 2, the device is attached to the dosFs and mounted.
*
*
* RETURNS: OK if operation succeeds, ERROR otherwise.
*/
LOCAL STATUS flashFsRfaConfig
(
char * name,
ulong_t unit,
ulong_t offset,
ulong_t sectorSize,
ulong_t sectorCnt
)
{
STATUS rc;
BLK_DEV * pBlkDev;
DOS_VOL_DESC * pDosVolDesc;
RAW_VOL_DESC * pRawVolDesc;
static BOOL rfaMounted[NUM_RFA_DEVICES] = { 0 };
if ( (unit >= NUM_RFA_DEVICES) || (rfaMounted[unit] == TRUE) )
return OK;
rc = OK;
FS_DRV_PRINT (FLASHFS_DEBUG_INIT,
("flashFsRfaConfig(): Initializing device (%s) ... offset 0x%x, sectorSize %d, sectorCnt %d\n",
name, (int)offset, (int)sectorSize, (int)sectorCnt ));
/* Mount the file system */
pBlkDev = flashDevCreate(offset, sectorSize, sectorCnt, 0);
if (pBlkDev == NULL)
{
FS_DRV_PRINT (FLASHFS_DEBUG_ERROR,
("flashFsRfaConfig(): flashDevCreate Flash Device Failure.\n"));
return ERROR;
}
else
FS_DRV_PRINT (FLASHFS_DEBUG_INIT,
("flashFsRfaConfig(): flashDevCreate Success on Unit %d %s.\n", (int)unit, name));
/* The zero device is treated as a RAW file system. */
if (unit == 0)
{
pRawVolDesc = rawFsDevInit(name, pBlkDev);
if ( pRawVolDesc == NULL )
{
FS_DRV_PRINT (FLASHFS_DEBUG_ERROR,
("flashFsRfaConfig(): %s:%d rawFsDevInit(%s) failed\n",
__FILE__, __LINE__, name));
rc = -1;
}
else
{
FS_DRV_PRINT (FLASHFS_DEBUG_INIT,
("flashFsRfaConfig(): Unit %d %s Success.\n", (int)unit, name));
rc = 0;
rfaMounted[unit] = TRUE;
}
return rc;
}
/* unit != 0 */
else
{
pDosVolDesc = dosFsMkfs(name,pBlkDev);
if (pDosVolDesc == NULL)
rc = ERROR;
if ( rc == OK )
{
FS_DRV_PRINT (FLASHFS_DEBUG_INIT,
("flashFsRfaConfig(): Unit %ld %s Success.\n", unit, name));
rfaMounted[unit] = TRUE;
}
else
FS_DRV_PRINT (FLASHFS_DEBUG_ERROR,
("flashFsRfaConfig(): Unit %ld %s Failure.\n", unit, name));
return rc;
} /* else if (unit != 0) */
return -1;
}
/*******************************************************************************
*
* flashDevCreate - create a FLASH disk device
*
* This routine creates a FLASH disk device.
*
* Memory for the FLASH disk can be pre-allocated separately; if so, the
* <flashAddr> parameter should be the address of the pre-allocated device
* memory. Or, memory can be automatically allocated with malloc() by
* setting <flashAddr> to zero.
*
* The <bytesPerBlk> parameter specifies the size of each logical block
* on the FLASH disk. If <bytesPerBlk> is zero, 512 is used.
*
* The <nBlocks> parameter specifies the size of the disk, in blocks.
* If <nBlocks> is zero, a default size is used. The default is calculated
* using a total disk size of either 51,200 bytes or one-half of the size
* of the largest memory area available, whichever is less. This default
* disk size is then divided by <bytesPerBlk> to determine the number
* of blocks.
*
* The <blkOffset> parameter specifies an offset, in blocks, from the start
* of the device to be used when writing or reading the FLASH disk. This
* offset is added to the block numbers passed by the file system during
* disk accesses. (VxWorks file systems always use block numbers beginning
* at zero for the start of a device.) This offset value is typically useful
* only if a specific address is given for <flashAddr>. Normally, <blkOffset>
* is 0.
*
* FILE SYSTEMS:
* Once the device has been created, it must be associated with a name and a
* file system (dosFs, rt11Fs, or rawFs). This is accomplished using the
* file system's device initialization routine or make-file-system routine,
* e.g., dosFsDevInit() or dosFsMkfs(). The flashDevCreate() call returns a
* pointer to a block device structure (BLK_DEV). This structure contains
* fields that describe the physical properties of a disk device and specify
* the addresses of routines within the flashDrv driver. The BLK_DEV structure
* address must be passed to the desired file system (dosFs, rt11Fs or rawFs)
* via the file system's device initialization or make-file-system routine.
* Only then is a name and file system associated with the device, making it
* available for use.
*
* EXAMPLE:
* In the following example, a 200-Kbyte FLASH disk is created with
* automatically allocated memory, 512-byte blocks, a single track, and no
* block offset. The device is then initialized for use with dosFs and assigned
* the name "DEV1:":
* .CS
* BLK_DEV *pBlkDev;
* DOS_VOL_DESC *pVolDesc;
*
* pBlkDev = flashDevCreate (0, 512, 400, 0);
* pVolDesc = dosFsMkfs ("DEV1:", pBlkDev);
* .CE
* The dosFsMkfs() routine calls dosFsDevInit() with default parameters and
* initializes the file system on the disk by calling ioctl() with the
* \%FIODISKINIT function.
*
* If the FLASH disk memory already contains a disk image created elsewhere,
* the first argument to flashDevCreate() should be the address in memory, and
* the formatting parameters -- <bytesPerBlk>, <blksPerTrack>, <nBlocks>, and
* <blkOffset> -- must be identical to those used when the image was
* created. For example:
* .CS
* pBlkDev = flashDevCreate (0xc0000, 512, 400, 0);
* pVolDesc = dosFsDevInit ("DEV1:", pBlkDev, NULL);
* .CE
* In this case, dosFsDevInit() must be used instead of dosFsMkfs(), because
* the file system already exists on the disk and should not be
* re-initialized. This procedure is useful if a FLASH disk is to be created
* at the same address used in a previous boot of VxWorks. The contents of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -