1 |
dpavlin |
2 |
/* |
2 |
|
|
* Copyright (C) 2003-2005 Anders Gavare. All rights reserved. |
3 |
|
|
* |
4 |
|
|
* Redistribution and use in source and binary forms, with or without |
5 |
|
|
* modification, are permitted provided that the following conditions are met: |
6 |
|
|
* |
7 |
|
|
* 1. Redistributions of source code must retain the above copyright |
8 |
|
|
* notice, this list of conditions and the following disclaimer. |
9 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
10 |
|
|
* notice, this list of conditions and the following disclaimer in the |
11 |
|
|
* documentation and/or other materials provided with the distribution. |
12 |
|
|
* 3. The name of the author may not be used to endorse or promote products |
13 |
|
|
* derived from this software without specific prior written permission. |
14 |
|
|
* |
15 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
16 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
21 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
|
|
* SUCH DAMAGE. |
26 |
|
|
* |
27 |
|
|
* |
28 |
|
|
* $Id: decprom_dump_txt_to_bin.c,v 1.4 2005/02/21 07:18:10 debug Exp $ |
29 |
|
|
* |
30 |
|
|
* decprom_dump_txt_to_bin.c |
31 |
|
|
* |
32 |
|
|
* This program takes a textfile containing a DECstation |
33 |
|
|
* PROM memory dump of the following format: |
34 |
|
|
* |
35 |
|
|
* bfc00000: 0x12345678 |
36 |
|
|
* bfc00004: 0x9a8a8a7f |
37 |
|
|
* and so on |
38 |
|
|
* |
39 |
|
|
* and turns it into a binary image (32-bit little-endian words -> bytes), |
40 |
|
|
* |
41 |
|
|
* 0x78 0x56 0x34 0x12 0x7f 0x8a ... |
42 |
|
|
* |
43 |
|
|
* To produce such a dump, hook up a serial terminal capable of capturing |
44 |
|
|
* data to a file, and enter the commands |
45 |
|
|
* |
46 |
|
|
* setenv more 0 |
47 |
|
|
* e -w 0xbfc00000:0xbfffffff |
48 |
|
|
* |
49 |
|
|
* at the DECstation's PROM prompt. |
50 |
|
|
*/ |
51 |
|
|
|
52 |
|
|
#include <stdio.h> |
53 |
|
|
#include <string.h> |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
int main(int argc, char *argv[]) |
57 |
|
|
{ |
58 |
|
|
FILE *fin, *fout; |
59 |
|
|
char s[500]; |
60 |
|
|
|
61 |
|
|
if (argc != 3) { |
62 |
|
|
fprintf(stderr, "usage: %s dump.txt dump.bin\n", argv[0]); |
63 |
|
|
fprintf(stderr, "The resulting dump binary will be written" |
64 |
|
|
" to dump.bin\n"); |
65 |
|
|
exit(1); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
fin = fopen(argv[1], "r"); |
69 |
|
|
if (fin == NULL) { |
70 |
|
|
perror(argv[1]); |
71 |
|
|
exit(1); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
fout = fopen(argv[2], "w"); |
75 |
|
|
if (fout == NULL) { |
76 |
|
|
perror(argv[2]); |
77 |
|
|
exit(1); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
while (!feof(fin)) { |
81 |
|
|
s[0] = 0; |
82 |
|
|
fgets(s, sizeof(s), fin); |
83 |
|
|
if (s[0]=='b' && s[1]=='f' && strlen(s)>15) { |
84 |
|
|
unsigned long addr = strtoul(s, NULL, 16); |
85 |
|
|
unsigned long data = strtoul(s + 12, NULL, 16); |
86 |
|
|
unsigned char obuf[4]; |
87 |
|
|
|
88 |
|
|
printf("addr = 0x%0l8x data = 0x%08lx\n", |
89 |
|
|
(long)addr, (long)data); |
90 |
|
|
|
91 |
|
|
addr -= 0xbfc00000L; |
92 |
|
|
obuf[0] = data & 255; |
93 |
|
|
obuf[1] = (data >> 8) & 255; |
94 |
|
|
obuf[2] = (data >> 16) & 255; |
95 |
|
|
obuf[3] = (data >> 24) & 255; |
96 |
|
|
|
97 |
|
|
fseek(fout, addr, SEEK_SET); |
98 |
|
|
fwrite(obuf, 1, 4, fout); |
99 |
|
|
} |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
fclose(fin); |
103 |
|
|
fclose(fout); |
104 |
|
|
|
105 |
|
|
return 0; |
106 |
|
|
} |
107 |
|
|
|