annotate miscprog/cinitdump.c @ 344:2bd27d940023

fluid-mnf/serial.c: serial_recv() implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 13 Mar 2020 05:53:20 +0000
parents e493fcff28ab
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
268
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program dumps the cinit section records from a firmware image
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * sans symbols, given just the cinit start address and knowing the
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * record structure.
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 FILE *inf;
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 u_long offset;
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 u_long
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 get_word()
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 u_char bytes[4];
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 u_long word;
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 fread(bytes, 1, 4, inf);
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 word = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 printf("%8lx:\t%08lx\n", offset, word);
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 offset += 4;
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return word;
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 main(argc, argv)
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 char **argv;
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 u_long len, count;
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (argc != 3) {
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 fprintf(stderr, "usage: %s filename start-addr\n", argv[0]);
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 exit(1);
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 }
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 inf = fopen(argv[1], "r");
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (!inf) {
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 perror(argv[1]);
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 exit(1);
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 offset = strtoul(argv[2], 0, 0);
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 fseek(inf, offset, SEEK_SET);
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 for (;;) {
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 len = get_word();
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (!len)
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 break;
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 len = (len + 3) & ~3;
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 get_word(); /* bss address */
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 for (count = 0; count < len; count += 4)
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 get_word();
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 putchar('\n');
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 exit(0);
e493fcff28ab cinitdump program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }