📄 doc2exb.c
字号:
/***********************************************************************************/
/* M-Systems Confidential */
/* Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2003 */
/* All Rights Reserved */
/***********************************************************************************/
/* NOTICE OF M-SYSTEMS OEM */
/* SOFTWARE LICENSE AGREEMENT */
/* */
/* THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE */
/* AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT */
/* FOR THE SPECIFIC TERMS AND CONDITIONS OF USE, */
/* OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE: */
/* E-MAIL = info@m-sys.com */
/***********************************************************************************/
/*
* $Log: V:/PVCSDB/DiskOnChip/archives/general storage/TrueFFS/src/misc/doc2exb.c-arc $
*
* Rev 1.1 May 06 2003 11:57:14 OriS
* Was removed from the package
* Fixed Compilation errors.
*
* Rev 1.0 Apr 09 2003 12:15:56 OriS
* Initial revision.
*
*/
/*****************************************************************************
* File Header *
* ----------- *
* Project : TrueFFS source code *
* *
* Name : doc2exb.c *
* *
* Description : This file contains the code for analizing and writing *
* M-Systems EXB firmware files *
* *
*****************************************************************************/
#include "doc2exb.h"
#include "bddefs.h"
#include "blockdev.h"
#include "logicmtd.h"
#include "excustom.h"
#include "defines.h"
#include "exdevice.h"
#include "extffs.h"
#include "exparser.h"
#include "docbdk.h"
#ifdef WRITE_EXB_IMAGE
extern FLStatus absMountVolume(Volume vol);
FLByte IPL_Buffer[1024] ;
#define BUFFER exb->buffer->flData
exbStruct exbs[SOCKETS];
#define MTD_VARS ((MTDVarsStruct *) flashPtr->mtdVars)
#define roundedUpShift(a,bits) (((a - 1) >> bits)+1)
FLDword RonenCount ;
/*----------------------------------------------------------------------*/
/* g e t E x b I n f o */
/* */
/* Analize M-systems firmware file */
/* Analizes M-systems firmware (exb) file, calclating the media space */
/* required for it. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* buf : Pointer to EXB file buffer */
/* bufLen : Size of the buffer */
/* bufFlags : Flags for the EXB - specifing type of */
/* firmware to extract from the EXB file. */
/* */
/* Returns: */
/* FLStatus : flOK on success. */
/* flBadLength if buffer size is too small */
/* flBadParameter on any other failure */
/* vol.binaryLength : Total size needed in the binary partition */
/* exbs[i].firmwareStart : offset of the firmware begining in the file */
/* exbs[i].firmwareEnd : offset of the firmware end in the file */
/* exbs[i]l.splOffset : offset of the spl start in the file */
/* exbs[i]l.exbFileEnd : Total exb file size. */
/*----------------------------------------------------------------------*/
FLStatus getExbInfo(Volume vol, void FAR1 * buf, FLDword bufLen, FLWord exbFlags,
FLDword *dwLowMemFileSize)
{
FLByte i;
FLByte mediaType;
ExbGlobalHeader FAR1* globalHeader = (ExbGlobalHeader FAR1*)buf;
FirmwareHeader FAR1* firmwareHeader = (FirmwareHeader FAR1*)
BYTE_ADD_FAR(buf,sizeof(ExbGlobalHeader)) ;
if (bufLen < sizeof(FirmwareHeader) * LE4(globalHeader->noOfFirmwares) +
sizeof(ExbGlobalHeader))
{
ExPrint("ERROR - Buffer size not big enough.\r\n");
return flBadLength;
}
/* Make sure this is an M-systems EXB file */
if (tffscmp(globalHeader->mSysSign,SIGN_MSYS,SIGN_MSYS_SIZE) != 0)
{
ExPrint("ERROR - Given file is not M-systems EXB file.\r\n");
return flBadParameter;
}
i = (exbFlags & FIRMWARE_NO_MASK) >> FIRMWARE_NO_SHIFT;
if(i == 0)
{
/* Make sure this is the correct version of TrueFFS */
/* rafi temp removed : if (tffscmp(globalHeader->osakVer,BiosDriverEXBVersion,SIGN_MSYS_SIZE) != 0)
{
ExPrint("ERROR - Incorrect TrueFFS EXB file version.\r\n");
return flBadParameter;
}*/
/* Find the corrent firmware in the file */
/* Automatic firmware detection - by DiskOnChip type */
switch (vol.flash->mediaType)
{
case DOC_TYPE:
case MDOC_TYPE:
mediaType = DOC2000_FAMILY_FIRMWARE;
break;
case MDOCP_TYPE:
case MDOCP_16_TYPE:
mediaType = DOCPLUS_FAMILY_FIRMWARE;
break;
case DOC2000TSOP_TYPE:
mediaType = DOC2300_FAMILY_FIRMWARE;
break;
case DOC_OREN_TYPE:
mediaType = DOCOREN_FAMILY_FIRMWARE;
break;
default:
ExPrint("Unknown H/W - Try specifing the firmware manualy.\r\n");
return flFeatureNotSupported;
}
for (i=0;i<LE4(globalHeader->noOfFirmwares);i++,firmwareHeader++)
{
toLE4(firmwareHeader->type,DOCOREN_FAMILY_FIRMWARE);
if (LE4(firmwareHeader->type) == mediaType)
break;
}
}
else /* Use given firmware */
{
i--; /* 0 was used for automatic choose of firmware */
}
if (i >= LE4(globalHeader->noOfFirmwares))
{
ExPrint("ERROR - The EXB file does not support the required firmware.\r\n");
return flBadParameter;
}
/* Initialize the volumes EXB fields */
firmwareHeader = (FirmwareHeader FAR1*)BYTE_ADD_FAR(buf,
(sizeof(ExbGlobalHeader) + (i * sizeof(FirmwareHeader))));
i = &vol - vols;
/* Save firmware files statstics recieved from the files header */
/*** Where Firmware starts in file ***/
exbs[i].firmwareStart = LE4(firmwareHeader->startOffset);
/*** Where Firmware ends ***/
exbs[i].firmwareEnd = LE4(firmwareHeader->endOffset);
/*** Where SPL starts in file ***/
exbs[i].splStart = LE4(firmwareHeader->splStartOffset);
/*** Where SPL ends ***/
exbs[i].splEnd = LE4(firmwareHeader->splEndOffset);
/*** Where EXB file ends (file size) ***/
exbs[i].exbFileEnd = LE4(globalHeader->fileSize);
*dwLowMemFileSize = exbs[i].exbFileEnd ;
/* Calculate the binary partition size (good bytes) used to
hold the EXB file. */
exbs[i].iplMod512 = (FLWord)((exbs[i].splStart - exbs[i].firmwareStart)
>> FL_SECTOR_SIZE_BITS);
/*** Calculate how many bytes we would need to write to BDK ***/
switch (vol.flash->mediaType)
{
/* NFTL formated device - IPL is placed on the binary partition */
case DOC_TYPE:
/* Size of EXB minus IPL which is placed in ROM */
vol.binaryLength = exbs[i].firmwareEnd - exbs[i].splStart + 0x4000;
break;
case MDOC_TYPE: /* Millennium 8, write data as is */
/* Size of entire EXB */
vol.binaryLength = exbs[i].firmwareEnd - exbs[i].firmwareStart;
break;
/* INFTL formated device - IPL is not placed on the binary
partition, but on a dedicated flash area */
case DOC2000TSOP_TYPE: /* DOC2000 TSOP */
case MDOCP_TYPE: /* MDOC PLUS 32MB */
case MDOCP_16_TYPE: /* MDOC PLUS 16MB */
case DOC_OREN_TYPE: /* MDOC PLUS 16MB */
case M512_G3_TYPE:
case M256_P3_TYPE:
case M256_G3_TYPE:
case M128_P3_TYPE:
case M1G_G3_TYPE:
if (exbFlags & TWO_SPL_COPIES)
{
vol.binaryLength = (exbs[i].splEnd-exbs[i].splStart) * 2 /* SPL Size * 2 copies */
+ (exbs[i].firmwareEnd - exbs[i].splEnd) ;
}
else
{
vol.binaryLength = exbs[i].firmwareEnd - exbs[i].splStart;
}
break;
default :
ExPrint("ERROR - Firmware formater reports A None DiskOnChip media.\r\n");
return flBadParameter;
}
return flOK;
}
/*------------------------------------------------------------------------*/
/* w a i t F o r H a l f B u f f e r */
/* */
/* Increament the EXB file pointers and store the files data unit a */
/* full sector of data is read. */
/* */
/* Parameters: */
/* exbs[i].bufferOffset : size of the buffer already filled with data */
/* exbs[i].exbFileOffset : offset from the beginning of the file */
/* exbs[i].buffer.data : internal volume buffer accumulation file data */
/* buf : buffer containing the files data */
/* bufLen : Length of the buffer containing the file data */
/* length : Length of the buffer not yet used */
/* half : Wait for full 512 bytes of only 256 */
/* Returns: */
/* boolean : TRUE on full buffer otherwise FALSE. */
/* length : Updated length of unused buffer */
/*------------------------------------------------------------------------*/
FLBoolean waitForFullBuffer(Volume vol , FLByte FAR1 * buf ,
FLDword bufLen , FLSDword * length,FLBoolean half)
{
FLWord bufferEnd;
FLWord tmp;
FLByte i = &vol - vols;
if (half == TRUE)
{
bufferEnd = (FL_SECTOR_SIZE >> 1);
}
else
{
bufferEnd = FL_SECTOR_SIZE;
}
tmp = (FLWord)TFFSMIN(*length , bufferEnd - exbs[i].bufferOffset);
tffsRAMcpy(exbs[i].buffer->flData + exbs[i].bufferOffset ,
BYTE_ADD_FAR (buf,(bufLen-(*length))), tmp);
exbs[i].bufferOffset += tmp;
exbs[i].exbFileOffset += tmp;
*length -= tmp;
if (*length+tmp < bufferEnd)
return FALSE;
exbs[i].bufferOffset = 0;
return TRUE;
}
/*------------------------------------------------------------------------*/
/* f i r s t T i m e I n i t */
/* */
/* Initialize data structures for placing exb file. */
/* full sector of data is read. */
/* */
/* Actions: */
/* 1) Analize exb file buffer. */
/* 2) Calculate TFFS heap size. */
/* 3) Check if binary area with SPL signature is big enough. */
/* 4) Calculate SPL start media address */
/* 5) Calculate binary area used for the firmware. */
/* 6) Initialize the volumes EXB record. */
/* */
/* Parameters: */
/* vol : Pointer to volume record describing the volume. */
/* exb : Pointer to exb record describing the volume. */
/* buf : Exb file buffer. */
/* bufLen : Length of exb file buffer. */
/* ioreq : Internal ioreq record for binary operaions. */
/* bdk : Bdk record which is a part of the ioreq packet. */
/* */
/* Affected Variables. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -