add Intel's bin2obj tool
- this is part of http://marcbug.scc-dc.com/svn/repository/trunk/linuxkernel/bin2obj
This commit is contained in:
parent
f02655ccda
commit
a070ac6c5a
2 changed files with 153 additions and 3 deletions
|
@ -41,16 +41,19 @@ scc_bootinfo.asm: bootinfo.sh
|
|||
scc_bootinfo.bin: scc_bootinfo.asm
|
||||
$(NASM) $(NASMFLAGS) -o $@ $<
|
||||
|
||||
SCC: scc_bootinfo.bin scc_setup.bin reset_vector.bin initrd.img
|
||||
bin2obj: bin2obj.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
SCC: scc_bootinfo.bin scc_setup.bin reset_vector.bin initrd.img bin2obj
|
||||
cp ../metalsvm.elf .
|
||||
$(CROSS_OBJCOPY) -j .mboot -j .text -j .data -j .rodata -j .bss -O binary metalsvm.elf metalsvm.bin
|
||||
chmod a-x *.bin
|
||||
. ./prepare.sh
|
||||
/home/lankes/tools/bin2obj -m load.map -o metalsvm.obj
|
||||
./bin2obj -m load.map -o metalsvm.obj
|
||||
sccMerge -noimage -m 8 -n 12 -force ./metalsvm.mt
|
||||
|
||||
clean:
|
||||
$(RM) -rf *.o *~ make_initrd initrd.img *.bin *.obj *.hex *.elf obj
|
||||
$(RM) -rf *.o *~ bin2obj make_initrd initrd.img *.bin *.obj *.hex *.elf obj
|
||||
|
||||
depend:
|
||||
$(CC) -MM $(CFLAGS) *.c > Makefile.dep
|
||||
|
|
147
tools/bin2obj.c
Normal file
147
tools/bin2obj.c
Normal file
|
@ -0,0 +1,147 @@
|
|||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
const char BIN2OBJIDSTRING[] = "$Id: bin2obj.c 8016 2007-11-01 14:24:42Z tlehnig $";
|
||||
|
||||
|
||||
long long convertToHex(char *fn, unsigned long origin, FILE *outfile) {
|
||||
FILE *datafile;
|
||||
unsigned char data1, data2, data3, data4;
|
||||
int res = 0;
|
||||
long long count = 0;
|
||||
|
||||
datafile = fopen(fn, "r");
|
||||
if (!datafile) {
|
||||
printf("Datafile >%s< could not be opened, not writing data for this file\n", fn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Converting file >%s< to .32.obj format at origin 0x%08lx (0x%08lx) ... ",
|
||||
fn, origin >> 2, origin);
|
||||
fprintf(outfile, "/origin %08lx\n", origin >> 2);
|
||||
|
||||
do {
|
||||
data1 = 0;
|
||||
data2 = 0;
|
||||
data3 = 0;
|
||||
data4 = 0;
|
||||
|
||||
res = fscanf(datafile, "%c%c%c%c", &data1, &data2, &data3, &data4);
|
||||
if (res > 0) {
|
||||
count += res;
|
||||
|
||||
fprintf(outfile, "%02x%02x%02x%02x", data4, data3, data2, data1);
|
||||
|
||||
if ((count % 16) == 0)
|
||||
fprintf(outfile, "\n");
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
}
|
||||
|
||||
} while (res > 0);
|
||||
|
||||
if ((count % 16) != 0) fprintf(outfile, "\n");
|
||||
|
||||
printf("done with %lli Bytes.\n", count);
|
||||
|
||||
fclose(datafile);
|
||||
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void print_help() {
|
||||
printf("Usage: bin2obj [FLAGS] [OPTIONS]\n");
|
||||
printf("\nFLAGS: -h, -v\n");
|
||||
printf("-h Print this help\n");
|
||||
printf("-v Print Version ID\n");
|
||||
printf("\nOPTIONS: -m, -o\n");
|
||||
printf("-m <mapfile> Defines mapfile to use for bin2obj\n");
|
||||
printf("-o <outfile> Defines output file to use for bin2obj\n");
|
||||
printf("\nbin2obj converts the binary files defined in the mapfile to a hex based textfile\n");
|
||||
printf("used by MCEMU\n");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
FILE *mapfile = NULL, *outfile = NULL;
|
||||
unsigned long origin;
|
||||
char datafn[255];
|
||||
char outfn[255] = "output.obj";
|
||||
char mapfn[255] = "load.map";
|
||||
int res = 0;
|
||||
unsigned long long count = 0;
|
||||
long long thiscount = 0;
|
||||
int retval = 0;
|
||||
|
||||
int c, doOptLoop = 1;
|
||||
|
||||
while (doOptLoop) {
|
||||
c = getopt(argc, argv, "m:o:hv");
|
||||
|
||||
if (c == -1) {
|
||||
doOptLoop = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
print_help();
|
||||
return 0;
|
||||
break;
|
||||
case 'v':
|
||||
printf("%s %s\n", argv[0], BIN2OBJIDSTRING);
|
||||
return 0;
|
||||
break;
|
||||
case 'm':
|
||||
printf("Mapfile: >%s<\n", optarg);
|
||||
strncpy(mapfn, optarg, 255);
|
||||
break;
|
||||
case 'o':
|
||||
printf("Outfile: >%s<\n", optarg);
|
||||
strncpy(outfn, optarg, 255);
|
||||
break;
|
||||
default:
|
||||
print_help();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mapfile = fopen(mapfn, "r");
|
||||
if (!mapfile) {
|
||||
printf("Mapfile >%s< not found, exiting.\n", mapfn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
outfile = fopen(outfn, "w");
|
||||
if (!outfile) {
|
||||
printf("Outputfile >%s< could not be created, exiting\n", outfn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// res = fscanf(mapfile, "%lx %s\n", &origin, datafn);
|
||||
|
||||
while ((res = fscanf(mapfile, "%lx %s\n", &origin, datafn)) == 2) {
|
||||
//printf("ReadMapFile origin: 0x%08lx, filename: >%s<\n", origin, datafn);
|
||||
|
||||
thiscount = convertToHex(datafn, origin, outfile);
|
||||
if (thiscount < 0) {
|
||||
retval = -1;
|
||||
}
|
||||
else count += thiscount;
|
||||
|
||||
}
|
||||
|
||||
fprintf(outfile, "/eof\n");
|
||||
fclose(mapfile);
|
||||
fclose (outfile);
|
||||
|
||||
printf("Total conversion: %lli Bytes\n", count);
|
||||
|
||||
return retval;
|
||||
}
|
Loading…
Add table
Reference in a new issue