📄 doc2exb.c
字号:
/* calculate EXB module size */
/* generate random run-time ID and write it into splHeader. */
ExSrand((FLWord)ExTime(NULL));
tmpWord = (FLWord)ExRand();
toUNAL2(spl->runtimeID, tmpWord);
spl->chksumFix -= (FLByte)(tmpWord);
spl->chksumFix -= (FLByte)(tmpWord >> 8);
/* Write TFFS heap size into splHeader. */
toUNAL2(spl->tffsHeapSize, (FLWord)exb->tffsHeapSize);
spl->chksumFix -= (FLByte)(exb->tffsHeapSize);
spl->chksumFix -= (FLByte)(exb->tffsHeapSize >> 8);
/* set explicit DOC window base */
if( docWinBase > 0 )
{
toUNAL2(spl->windowBase, docWinBase);
spl->chksumFix -= (FLByte)(docWinBase);
spl->chksumFix -= (FLByte)(docWinBase >> 8);
}
if (exbFlags & TWO_SPL_COPIES)
{
spl->NoOfCopies = 2 ;
ExPrint("- SPL 2 COPIES \r\n");
spl->chksumFix -= 2 ;
}
else
{
spl->NoOfCopies = 1 ;
ExPrint("- SPL 1 COPY \r\n");
spl->chksumFix -= 1 ;
}
break;
case 2: /* Socket Services OR interupt 13 driver */
ExPrint("Writing Low Memory Driver \r\n");
ExPrint("------------------------- \r\n");
ExPrint("- Size=%dKB \r\n",(exb->exbFileEnd-exb->splEnd)/1024);
printf ("- Heap Size=%dKB " , exb->tffsFarHeapSize/2 );
/* The doc2000 driver and or socket services start
at 0x4000 so we have to jump over there. */
if (vol.flash->mediaType == DOC_TYPE)
{
flBdkVol->actualUpdateLen -= 0x4000 - flBdkVol->curUpdateImageAddress;
flBdkVol->curUpdateImageAddress = 0x4000;
}
tffs = (TffsHeader *)BUFFER;
tffs->chksumFix -= (FLByte)(exb->tffsFarHeapSize);
tffs->chksumFix -= (FLByte)(exb->tffsFarHeapSize >> 8);
toUNAL2(tffs->heapLen, exb->tffsFarHeapSize);
exb->exbFlags &= ~NO_PNP_HEADER;
default:
/* put "install as first drive" & QUIET mark
into the TFFS header */
tffs = (TffsHeader *)BUFFER;
tffs->exbFlags = (FLByte)exb->exbFlags;
tffs->chksumFix -= (FLByte)exb->exbFlags;
break;
} /* end - switch of module type */
} /* end - first buffer of module */
exb->moduleLength--;
/* Write module and clean buffer */
switch (vol.moduleNo)
{
case 0: /* IPL data */
switch (vol.flash->mediaType)
{
case MDOC_TYPE: /* Millennium 8 - use bdk to write IPL * 2 */
if (exb->moduleLength == exb->iplMod512 - 1)
{
/* Milennium DiskOnChip is the only device that the IPL
is duplicated in the exb file. The dupplication was
needed in earlier versions but it is currently ignored.
The IPL is still written twice only that the second
copy is not taken from the file but the first copy is
simply written twice. */
if ((exbFlags & LEAVE_EMPTY) == 0)
{
checkStatus(bdkCall(FL_BINARY_WRITE_BLOCK,
&ioreq,vol.flash));
checkStatus(bdkCall(FL_BINARY_WRITE_BLOCK,
&ioreq,vol.flash));
}
}
/* Change byte #406 to non-0xFF value to force
Internal EEprom Mode */
break;
case DOC2000TSOP_TYPE: /* Doc 2000 tsop - write to block 0 */
case MDOCP_TYPE: /* Millennium Plus - use MTD specific routine */
case MDOCP_16_TYPE:
case DOC_OREN_TYPE:
case M512_G3_TYPE:
case M256_P3_TYPE:
case M256_G3_TYPE:
case M128_P3_TYPE:
case M1G_G3_TYPE:
if (vol.flash->writeIPL == NULL)
return flFeatureNotSupported;
if ((exbFlags & LEAVE_EMPTY) != 0)
{
/* Erase previous IPL if all we need is to leave
space for the firmware and not realy write it */
tffsRAMset(BUFFER,0xff,FL_SECTOR_SIZE);
}
if ((FLByte)(exb->iplMod512 - exb->moduleLength-1)==0)
{
tffsRAMset (IPL_Buffer,0xFF,1024) ;
tffsRAMcpy (IPL_Buffer,BUFFER,512) ;
}
else
{
tffsRAMcpy (&(IPL_Buffer[512]),BUFFER,512) ;
checkStatus(vol.flash->writeIPL(vol.flash,
IPL_Buffer,1024,0,
/* (FLByte)(exb->iplMod512 - exb->moduleLength-1), */
FL_IPL_MODE_NORMAL));
exb->moduleLength = 0 ;
}
default: /* DiskOnChip 2000 */
break; /* IPL is burnt onto ROM */
}
break;
default:
if ((exbFlags & LEAVE_EMPTY) == 0)
{
RonenCount += bdk.length ;
checkStatus(bdkCall(FL_BINARY_WRITE_BLOCK,&ioreq,vol.flash));
if ((exbFlags & TWO_SPL_COPIES) && (vol.moduleNo==1))
checkStatus(bdkCall(FL_BINARY_WRITE_BLOCK,&ioreq,vol.flash));
}
}
tffsRAMset(BUFFER,0xff,sizeof(BUFFER));
if (exb->moduleLength == 0)
vol.moduleNo++;
}
if (exb->exbFileOffset >= exb->firmwareEnd)
{
exb->exbFileOffset += length;
}
if (exb->exbFileOffset >= exb->exbFileEnd)
{
vol.moduleNo = INVALID_MODULE_NO;
if (vol.flash->download != NULL)
return vol.flash->download(vol.flash); /* download IPL */
}
return(flOK);
}
FLStatus cdecl WriteHighDriver (ExDevice* highMemDrv,Volume vol
,FLDword dwHighMemFileSize,FLDword dwHighMemFileStart)
{
FLStatus status;
FLDword dwBytesWritten, dwBytesToWrite,dwRetBytesRead ;
FLWord wMinValue ;
FLByte tmpWriteBuf[1024];
FLDword dwFileSize ;
#ifdef DEBUG_HIGH_DRV_LOAD
FLByte tmpReadBuf[1024];
FLDword j,dwBytesToRead ;
#endif
IOreq ioreq ;
BDKStruct BDK_Struct ;
ExPrint("Write High Memory Driver \r\n");
ExPrint("------------------------- \r\n");
ExPrint("- Size=%dKB \r\n",dwHighMemFileSize/1024);
/*** Step 1: Find BDK Partition info ***/
/*** Firmware is always in socket 0 ,partition 0 ***/
ioreq.irHandle = 0 ;
ioreq.irData = &BDK_Struct;
tffsRAMcpy (BDK_Struct.oldSign,SIGN_SPL,BDK_SIGNATURE_NAME) ;
BDK_Struct.signOffset = 8 ;
BDK_Struct.startingBlock = 0 ;
status = bdCall (FL_BINARY_PARTITION_INFO,&ioreq) ;
if(status != flOK)
{
printf("\nFailed locating blocks with the given signature with status %d\r\n",status);
return status;
}
dwFileSize = dwHighMemFileSize ;
/*** Step 3: Erase the binary partition ***/
ioreq.irData = &BDK_Struct;
ioreq.irHandle = 0 ;
BDK_Struct.length = (dwFileSize/vol.flash->erasableBlockSize) + 1 ;
tffsRAMcpy (BDK_Struct.oldSign,SIGN_SPL,BDK_SIGNATURE_NAME) ;
tffsRAMcpy (BDK_Struct.newSign,"HIGH",BDK_SIGNATURE_NAME) ;
BDK_Struct.startingBlock = 0 ;
status = bdCall (FL_BINARY_CREATE,&ioreq) ;
/*** Step 4: Write driver to binary partition ***/
ioreq.irHandle = 0 ;
ioreq.irData = &BDK_Struct;
BDK_Struct.startingBlock = 0 ;
BDK_Struct.length = dwFileSize ;
memcpy (BDK_Struct.oldSign,"HIGH",4) ;
BDK_Struct.signOffset = 8 ;
BDK_Struct.flags = BDK_COMPLETE_IMAGE_UPDATE ;
status = bdCall (FL_BINARY_WRITE_INIT ,&ioreq) ;
if (status)
{
printf ("bdkEraseBootArea returned error \r\n") ;
}
dwBytesToWrite = dwFileSize ;
dwBytesWritten = 0 ;
while (dwBytesToWrite)
{
wMinValue = (FLWord)TFFSMIN (1024,dwBytesToWrite) ;
if (wMinValue!=1024)
{
memset (&(tmpWriteBuf[wMinValue]),0x00,(1024-dwBytesToWrite)) ;
}
ReadSerialFileDevice(highMemDrv,tmpWriteBuf,wMinValue,&dwRetBytesRead ) ;
ioreq.irHandle = 0 ;
ioreq.irData = &BDK_Struct;
BDK_Struct.length = 1024 ;
memcpy (BDK_Struct.oldSign,"HIGH",4) ;
BDK_Struct.bdkBuffer = tmpWriteBuf ;
status = bdCall (FL_BINARY_WRITE_BLOCK ,&ioreq) ;
if(status != flOK)
{
printf("\r\nFailed writing after %ld bytes with status %d\r\n",dwBytesWritten,status);
return status;
}
dwBytesWritten += wMinValue ;
dwBytesToWrite -= wMinValue ;
printf("Succeeded in writing %ld bytes\r",dwBytesWritten);
}
#ifdef DEBUG_HIGH_DRV_LOAD
/*** Read the binary partition and compare the data ***/
status = bdkCopyBootAreaInit(0,dwFileSize,"HIGH");
if(status != flOK)
{
printf("Failed initializing read operation with status %d\r\n",status);
return status;
}
dwBytesToRead = dwFileSize ;
dwBytesRead = 0 ;
checkStatus (SeekSerialFileDevice(highMemDrv,dwHighMemFileStart,SEEK_SET)) ;
while (dwBytesToRead)
{
wMinValue = TFFSMIN (1024,dwBytesToRead) ;
status = bdkCopyBootAreaBlock(tmpReadBuf,wMinValue,&unused);
if(status != flOK)
{
printf("Failed reading after %ld bytes with status %d\r\n",dwBytesRead,status);
return status;
}
ReadSerialFileDevice(highMemDrv,tmpWriteBuf,wMinValue,&dwRetBytesRead ) ;
if (memcmp (tmpReadBuf,tmpWriteBuf,wMinValue))
{
for (j=0;j<1024;j++)
{
if (tmpReadBuf[j]!=tmpWriteBuf[j])
printf ("Read=%x Written=%x offset=%d\r\n",tmpReadBuf[j],tmpWriteBuf[j],j) ;
}
printf ("comparing failed") ;
return flOK ;
}
dwBytesToRead -= wMinValue ;
dwBytesRead += wMinValue ;
printf("Succeeded in reading %ld bytes\r",dwBytesRead);
}
#endif
return flOK;
}
#endif /* WRITE_EXB_IMAGE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -