飞思卡尔BIN转S19软件
时间:10-02
整理:3721RD
点击:
谁有飞思卡尔BIN转S19软件,网上找到源程序,但不知道怎么弄;
源程序如下:
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#define LINE_BYTES 0x10
#define min(a, b) ((a) < (b) ? (a) : (b))
static unsigned char data_buf[LINE_BYTES];
static char line_buf[64] = { 'S' };
static int str2hex(char *);
static void show_help(char *);
static int file_conv(FILE *, FILE *, unsigned long, size_t);
static int line_conv(size_t *, unsigned long);
int main(int argc, char **argv)
{
int err;
FILE *bin, *s19;
if (argc < 5) {
show_help(argv[0]);
return EINVAL;
}
bin = fopen(argv[1], "rb");
if (!bin) {
err = errno;
printf("cannot open file %s!\n", argv[1]);
return err;
}
s19 = fopen(argv[4], "wb");
if (!s19) {
err = errno;
printf("cannot open file %s!\n", argv[4]);
} else {
err = file_conv(bin, s19, str2hex(argv[2]), str2hex(argv[3]));
fclose(s19);
}
fclose(bin);
return err;
}
static int str2hex(char *s)
{
int hex;
sscanf(s, "%x", &hex);
return hex;
}
static void show_help(char *app)
{
printf("Usage:\n\t%s [bin-file] [offset] [size] [s19-file]\n", app);
}
static int file_conv(FILE *bin, FILE *s19, unsigned long offset, size_t size)
{
int err;
size_t rd_size;
do {
rd_size = fread(data_buf, 1, min(size, LINE_BYTES), bin);
if (!rd_size)
break;
err = line_conv(&rd_size, offset);
size -= rd_size;
offset += rd_size;
fputs(line_buf, s19);
} while (!err);
return err;
}
static int line_conv(size_t *size, unsigned long offset)
{
int i, err;
size_t off_size;
unsigned long checksum;
char *p;
unsigned char *off_buf;
err = 0;
if (offset + *size < *size) {
printf("offset out of range!\n");
err = EFBIG;
*size = ~offset;
if (!*size)
return err;
}
p = line_buf + 1;
if (offset + *size > 0x1000000)
off_size = 4;
else if (offset + *size > 0x10000)
off_size = 3;
else
off_size = 2;
checksum = off_size + *size + 1;
*p++ = '0' + off_size - 1;
p += sprintf(p, "%02X", checksum);
off_buf = (unsigned char *)(&offset);
for (i = off_size - 1; i >= 0; i--) {
p += sprintf(p, "%02X", off_buf);
checksum += off_buf;
}
for (i = 0; i < *size; i++) {
p += sprintf(p, "%02X", data_buf);
checksum += data_buf;
}
checksum = ~checksum;
p += sprintf(p, "%02X", checksum & 0xff);
strcat(p, "\r\n");
return err;
}
好像要用GCC编译什么的,
另外谁能提供个S19进行反汇编的软件啊,。
QQ:595456785