📄 docfile.c
字号:
/****************************************************************************/
/* */
/* Copyright 2000 Detlef Jenett */
/* */
/* This software is supplied under the terms of a license */
/* agreement or nondisclosure agreement and may not be copied */
/* or disclosed except in accordance with the terms of that */
/* agreement. */
/* */
/****************************************************************************/
/* */
/* Author : Detlef Jenett */
/* Creation date : 04.07.2000 */
/* Filename : doc_file.c */
/* */
/* Abstract : */
/* Image read routines */
/* */
/****************************************************************************/
/* */
/* Rev. Date Author Description */
/*--------------------------------------------------------------------------*/
/* 1.0 04.07.2000 D.Jenett initial version */
/****************************************************************************/
/****************************************************************************/
/* common include files */
/****************************************************************************/
/* #include <fcntl.h> */
/* #include <sys/types.h> */
/* #include <sys/stat.h> */
/* #include <io.h> */
/* #include <stdio.h> */
/****************************************************************************/
/* proprietary include files */
/****************************************************************************/
#include "unitinc.h"
extern EXDWORD ext_busConfig;
extern byte bbt_was_printed;
/****************************************************************************/
/* static declarations */
/****************************************************************************/
/****************************************************************************/
/* Function to open the specified image file */
/*--------------------------------------------------------------------------*/
/* Input: */
/* pName: pointer to file name buffer */
/* Output: */
/* Status: successfull -> STATUS_NOERROR */
/* unsuccessfull -> STATUS_ERROR */
/****************************************************************************/
FLStatus DINFO_flInit( void )
{
FLStatus Status = flOK;
if( Option.ImageFile.ImgFileName ) {
/*
* work with image file
*/
/* Option.ImageFile.ImgFileHandle = _open( Option.ImageFile.ImgFileName, O_RDONLY | O_BINARY );
if( Option.ImageFile.ImgFileHandle == -1 ) {
Status = flBadParameter;
}
else
{
Option.ImageFile.ImgFileSize = filelength( Option.ImageFile.ImgFileHandle );
Option.ImageFile.ImgFileSize = ( Option.ImageFile.ImgFileSize / BLOCK + 16 ) * BLOCK;
if( Option.ImageFile.ImgFileSize != -1 )
{
PRINT( OL_1, EX_TEXT("\n GENERAL \n") );
for ( j = 0 ; j < 11 ; j++ )
PRINT( OL_1, EX_TEXT("%c"), 223 );
PRINT( OL_1, EX_TEXT("\n") ) ;
PRINT( OL_0, EX_TEXT("DiskOnChip Image: %s\n"), Option.ImageFile.ImgFileName ) ;
PRINT( OL_1, EX_TEXT("\n") ) ;
Status = flOK;
}
}
*/
}
else
{
/*
* work with hardware
*/
if(Option.busConfig == 0)
{
Option.busConfig |= ext_busConfig;
}
if(Option.busConfig != 0)
{
FLDword tmp;
Status = flSetEnvAll(FL_MTD_BUS_ACCESS_TYPE ,
(FLDword)Option.busConfig, &tmp);
if(Status != flOK)
{
DinfoPrint( EX_TEXT("\nFailed setting DiskOnChip access configuration (with status %s)\n"),TranslateFLStatus(Status) );
return Status;
}
}
Status = flInit();
if(Status != flOK)
{
DinfoPrint( EX_TEXT("\nFailed initializing TrueFFS (with status %s)\n"),TranslateFLStatus(Status) );
return Status ;
}
if ( noOfSockets <= 0 )
{
DinfoPrint( EX_TEXT("\nNo DiskOnChip found\n") ) ;
return flBadDriveHandle ;
}
}
return( Status );
}
/****************************************************************************/
/* Function to close the image file */
/*--------------------------------------------------------------------------*/
/* Input: */
/* Output: */
/* Status: successfull -> STATUS_NOERROR */
/* unsuccessfull -> STATUS_ERROR */
/****************************************************************************/
void DINFO_flExit( void )
{
/* EXDWORD ImgFileSize; */
/* if( Option.ImageFile.ImgFileHandle != -1 ) */
/* { */
/*
* work with image file
*/
/* _close( Option.ImageFile.ImgFileHandle ); */
/*
* initialize values
*/
/* ImgFileSize = (FLDWORD) -1; */
/* Option.ImageFile.ImgFileHandle = -1; */
/* } */
/* else */
{
/*
* work with hardware
*/
flExit();
}
}
/*----------------------------------------------------------------------*/
/* D I N F O _ f l R e a d */
/* */
/* Read from a physical address. */
/* */
/* Parameters: */
/* SocketNo : Socket number (0,1,..) */
/* Address : Physical address to read from. */
/* Count : Number of bytes to read. */
/* Data : Address of user buffer to read into. */
/* Flags : Method mode */
/* EDC: Activate ECC/EDC */
/* EXTRA: Read/write spare area */
/* Returns: */
/* FLStatus : 0 on success, otherwise failed */
/*----------------------------------------------------------------------*/
FLStatus DINFO_flRead( EXBYTE Socket, EXDWORD Address, EXDWORD Count, EXBYTE* Data )
{
FLStatus Status;
EXBYTE handle = Socket;
if( Option.ImageFile.ImgFileName )
{
/*
* work with image file
*/
if( !Data ) {
/*
* data pointer is not valid
*/
return flNotEnoughMemory;
}
if( !Count ) {
/*
* no data requested, block count zero
*/
return flOK;
}
/*if( Option.ImageFile.ImgFileHandle != -1 )
{
} */
return flOK;
}
else
{
/*
* work with hardware
*/
curFlash->args.opFlags = MTD_DATA ;
curFlash->args.startSector = Address >> FL_SECTOR_SIZE_BITS ;
curFlash->args.noOfSectors = (Count >> FL_SECTOR_SIZE_BITS) + 1;
curFlash->args.extraBuf = Data;
Status = curFlash->flashRead(vols[0].flash);
if (Status != flOK)
{
DinfoPrint( EX_TEXT(" Read Error. \n"));
return Status;
}
return flOK;
}
}
/*------------------------------------------------------------------*/
/* done by preMountSAFTL that return noOfBDTLPartitions into ioreqPtr->irFlags */
FLStatus DINFO_flCountVolumes(IOreq* ioreq)
{
if( Option.ImageFile.ImgFileName )
{
return flOK;
}
else
{
return flCountVolumes(ioreq) ;
}
}
FLStatus DINFO_flMountVolume(IOreq* ioreq)
{
if( Option.ImageFile.ImgFileName )
{
return flOK;
}
else
{
return flMountVolume(ioreq) ;
}
}
FLStatus DINFO_flAbsMountVolume(IOreq* ioreq)
{
if( Option.ImageFile.ImgFileName )
{
return flOK;
}
else
{
return flAbsMountVolume(ioreq) ;
}
}
/* get info such as : unit-size,flash geometry, DOC type, lifetime , bootAreaSize */
FLStatus DINFO_flVolumeInfo(IOreq* ioreq)
{
if( Option.ImageFile.ImgFileName )
{
return flOK;
}
else
{
return flVolumeInfo(ioreq) ;
}
}
/* done by protectionSAFTL */
FLStatus DINFO_flIdentifyProtection(IOreq* ioreq)
{
if( Option.ImageFile.ImgFileName )
{
return flOK;
}
else
{
#ifdef HW_PROTECTION
return flIdentifyProtection(ioreq) ;
#else
return flFeatureNotSupported;
#endif /* HW_PROTECTION */
}
}
/* get media_type , unit size and media size. */
FLStatus DINFO_flGetPhysicalInfo(IOreq* ioreq)
{
if( Option.ImageFile.ImgFileName )
{
return flOK;
}
else
{
return flGetPhysicalInfo(ioreq) ;
}
}
FLStatus DINFO_flDismountVolume(IOreq* ioreq)
{
if( Option.ImageFile.ImgFileName )
{
return flOK;
}
else
{
return flDismountVolume(ioreq) ;
}
}
FLStatus DINFO_bdkPartitionInfo(IOreq* ioreq)
{
if( Option.ImageFile.ImgFileName )
{
return flOK;
}
else
{
return bdkPartitionInfo(ioreq) ;
}
}
FLStatus DINFO_bdkIdentifyProtection(IOreq* ioreq)
{
if( Option.ImageFile.ImgFileName )
{
return flOK;
}
else
{
#ifdef HW_PROTECTION
return bdkIdentifyProtection(ioreq) ;
#else
return flFeatureNotSupported;
#endif /* HW_PROTECTION */
}
}
/* Get the customer otp size */
FLStatus DINFO_flOTPSize(IOreq* ioreq)
{
if( Option.ImageFile.ImgFileName )
{
return flOK;
}
else
{
return flOTPSize(ioreq) ;
}
}
/* This is the unique ID of the flash */
FLStatus DINFO_flGetUniqueID(IOreq* ioreq)
{
if( Option.ImageFile.ImgFileName )
{
return flOK;
}
else
{
return flGetUniqueID(ioreq) ;
}
}
/*----------------------------------------------------------------------*/
/* D I N F O _ R e a d B B T */
/* */
/* Read Bad Blocks Table of device to user buffer */
/* */
/* Note: The user buffer is filled with the address of the bad units */
/* the buffer maximum size is 2% of the number of TL units of the */
/* specific device * 4 bytes. therfore a 8M device of 8KB erase */
/* zone will need a maximum size buffer of 1024 * 0.02 * 4 = 82B */
/* and a 192M with 16KB erase zones will need 960Bytes */
/* */
/* Note: the buffer is not initialized by the function */
/* */
/* Parameters: */
/* irData : User buffer. */
/* */
/* Returns: */
/* FLStatus : 0 on success, otherwise failed */
/* irLength : returns the media size */
/* irFlags : returns the actual number of badBlocks */
/*----------------------------------------------------------------------*/
FLStatus DINFO_flReadBBT( IOreq* ioreq ,EXBYTE print_msg)
{
#define MAX_NUM_OF_BAD_BLOCKS 0x100
#define BBT_BUF_SIZE 0x400
static EXBYTE Buffer[BBT_BUF_SIZE];
FLStatus Status;
FLStatus read_bbt_status;
FLStatus phy_info_status;
PhysicalInfo pInfo;
EXWORD num_of_bad_blocks=0;
EXWORD unit_cnt;
EXBYTE handle=0;
EXDWORD current_unit;
void* saved_irData;
/* save irData, because it will be changed by other calls */
saved_irData = ioreq->irData;
if( Option.ImageFile.ImgFileName )
{
return flOK;
}
else
{
Status = flAbsMountVolume( ioreq );
if( STATUS_OK )
{
Status = flReadBBT( ioreq ) ;
}
else
{
/* print msg to screen only if you asked to do it */
if (print_msg == PRINT_MSG)
{
DinfoPrint( EX_TEXT("\nflAbsMountVolume failed\n") );
DinfoPrint( EX_TEXT("reading bbt using physical read\n\n") );
}
/* first get media size and unit size */
ioreq->irHandle = handle;
ioreq->irData = &pInfo;
phy_info_status = DINFO_flGetPhysicalInfo(ioreq);
if(phy_info_status != flOK)
{
return phy_info_status;
}
/* output is a byte array with BBT_GOOD_UNIT or BBT_BAD_UNIT enums */
curFlash->args.readMainBuf=Buffer;
curFlash->args.startUnit=0;
curFlash->args.noOfUnits=BBT_BUF_SIZE;
read_bbt_status = curFlash->readBBT(vols[0].flash);
if (read_bbt_status != flOK)
{
DinfoPrint( EX_TEXT(" Can not read bbt using MTD. \n"));
return read_bbt_status;
}
/* scan Buffer for bad blocks and insert their */
/* number into ioreq.irData */
ioreq->irData = saved_irData;
current_unit=0;
for(unit_cnt=0;unit_cnt<BBT_BUF_SIZE;unit_cnt++)
{
if ((Buffer[unit_cnt]==BBT_BAD_UNIT) || (Buffer[unit_cnt]==BBT_UNAVAIL_UNIT))
{
((EXDWORD *)(ioreq->irData))[current_unit] = pInfo.unitSize * unit_cnt;
current_unit++;
}
}
/* update the field irFlags that normaly holds number of units */
ioreq->irFlags = current_unit;
/* print msg to screen only if you asked to do it */
if (print_msg == PRINT_MSG)
{
num_of_bad_blocks=0;
for(unit_cnt=0;unit_cnt<BBT_BUF_SIZE;unit_cnt++)
{
if ((Buffer[unit_cnt]==BBT_BAD_UNIT) || (Buffer[unit_cnt]==BBT_UNAVAIL_UNIT))
{
DinfoPrint( EX_TEXT(" Unit Number : %d is bad unit.(address 0x%lX)\n"),unit_cnt,pInfo.unitSize * unit_cnt);
num_of_bad_blocks++;
}
}
DinfoPrint( EX_TEXT("\n Number of bad blocks is %d \n"),num_of_bad_blocks);
DinfoPrint( EX_TEXT(" Bad Units Percentage : %.4f\n"), (float)num_of_bad_blocks / ( pInfo.mediaSize / pInfo.unitSize) * 100 );
bbt_was_printed = TRUE;
}
return flOK;
} /* else */
return Status;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -