git-svn-id: http://moon:8086/svn/software/trunk/libsrc/ihexparse@1 b431acfa-c32f-4a4a-93f1-934dc6c82436
69 lines
1.3 KiB
C
Executable File
69 lines
1.3 KiB
C
Executable File
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "types.h"
|
|
#include "ihexparse.h"
|
|
#include <memory.h>
|
|
|
|
#define BUFSIZE 65536
|
|
UINT8 *pBuffer;
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
FILE *pFile;
|
|
HEXREC recIn, recOut;
|
|
INT32 count;
|
|
UINT16 maxAddress, fileLen;
|
|
|
|
if (argc < 2)
|
|
{
|
|
printf("Usage: IHexParse <HEX-File>\n");
|
|
return 1;
|
|
}
|
|
|
|
HexOpen(&recIn, argv[1]);
|
|
HexCreate(&recOut, "out.hex");
|
|
|
|
pFile = fopen("out.bin","wb");
|
|
if (pFile <= 0)
|
|
return 1;
|
|
|
|
pBuffer = malloc(BUFSIZE);
|
|
memset(pBuffer, 0xFF, BUFSIZE);
|
|
maxAddress = 0;
|
|
|
|
count = 1;
|
|
|
|
while (count > 0)
|
|
{
|
|
count = HexReadRecord(&recIn);
|
|
if (count > 0)
|
|
{
|
|
memcpy(recOut.recData, recIn.recData, recIn.length);
|
|
recOut.dataStart = recIn.dataStart;
|
|
recOut.length = recIn.length;
|
|
recOut.type = recIn.type;
|
|
HexWriteRecord(&recOut);
|
|
}
|
|
if (maxAddress > recIn.dataStart)
|
|
continue;
|
|
else
|
|
{
|
|
maxAddress = recIn.dataStart;
|
|
fileLen = maxAddress + recIn.length;
|
|
}
|
|
}
|
|
memcpy(&pBuffer[recIn.dataStart], recIn.recData, recIn.length);
|
|
if ((INT32)count < 0)
|
|
printf("Error in HEX file\n");
|
|
|
|
HexClose(&recOut);
|
|
HexClose(&recIn);
|
|
|
|
fwrite(pBuffer, sizeof(UINT8), fileLen, pFile);
|
|
fclose (pFile);
|
|
free(pBuffer);
|
|
return 0;
|
|
}
|
|
|