annotate ffstools/tiffs-rd/decode.c @ 726:d68275d47a32

tiffs IVA: decode command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 28 Aug 2020 03:11:16 +0000
parents
children ed983d4040a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
726
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This C module implements the decode command, displaying certain
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * FFS files in a developer-friendly decoded form.
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <unistd.h>
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "types.h"
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "struct.h"
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "globals.h"
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "pathname.h"
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern void write_afcdac_ascii();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern void write_stdmap_ascii();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern void write_adccal_table();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern void write_afcparams_table();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 extern void write_tx_ramps_table();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern void write_tx_levels_table();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern void write_tx_calchan_table();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern void write_tx_caltemp_table();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 extern void write_rx_calchan_table();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 extern void write_rx_caltemp_table();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 extern void write_rx_agcparams_table();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 static struct map {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 char *req_name;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 char *pathname;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 int need_band;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 unsigned size;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 void (*decode_func)();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 } map_table[] = {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {"adccal", "/sys/adccal", 0, 36, write_adccal_table},
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {"afcdac", "/gsm/rf/afcdac", 0, 2, write_afcdac_ascii},
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {"afcparams", "/gsm/rf/afcparams", 0, 24, write_afcparams_table},
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {"stdmap", "/gsm/rf/stdmap", 0, 2, write_stdmap_ascii},
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 {"tx-ramps", "/gsm/rf/tx/ramps.%s", 1, 512, write_tx_ramps_table},
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 {"tx-levels", "/gsm/rf/tx/levels.%s", 1, 128, write_tx_levels_table},
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {"tx-calchan", "/gsm/rf/tx/calchan.%s", 1, 128, write_tx_calchan_table},
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {"tx-caltemp", "/gsm/rf/tx/caltemp.%s", 1, 40, write_tx_caltemp_table},
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {"rx-calchan", "/gsm/rf/rx/calchan.%s", 1, 40, write_rx_calchan_table},
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {"rx-caltemp", "/gsm/rf/rx/caltemp.%s", 1, 44, write_rx_caltemp_table},
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {"rx-agcparams", "/gsm/rf/rx/agcparams.%s", 1, 8, write_rx_agcparams_table},
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 {0, 0, 0, 0, 0}
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 };
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 static u8 file_read_buf[512];
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 static unsigned file_expected_size;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 static unsigned file_read_ptr;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 static void
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 read_chunk(ch)
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 struct chunkinfo *ch;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (!ch->len)
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 return;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (file_read_ptr + ch->len > file_expected_size) {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 fprintf(stderr, "error: FFS file is longer than expected\n");
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 exit(1);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 bcopy(ch->start, file_read_buf + file_read_ptr, ch->len);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 file_read_ptr += ch->len;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 static void
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 segment_read_callback(inf, opaque)
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 struct inode_info *inf;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 u_long opaque;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 struct chunkinfo chi;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 size_extra_chunk(inf, &chi);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 read_chunk(&chi);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 cmd_decode(argc, argv)
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 char **argv;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 struct map *map;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 char pathname[PATHNAME_BUF_SIZE];
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 int headino;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 struct inode_info *inf;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 struct chunkinfo chi;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (argc < 2) {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 usage: fprintf(stderr, "usage: decode file-keyword [band]\n");
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 exit(1);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 for (map = map_table; map->req_name; map++)
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 if (!strcmp(map->req_name, argv[1]))
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 break;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 if (!map->req_name) {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 fprintf(stderr, "error: file keyword \"%s\" not known\n",
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 argv[1]);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 exit(1);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (map->need_band) {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 if (argc < 3) {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 fprintf(stderr,
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 "error: band not specified for %s table\n",
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 map->req_name);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 exit(1);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 }
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 if (argc > 3)
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 goto usage;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 if (strlen(argv[2]) > 7) {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 fprintf(stderr,
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 "error: band name argument is too long\n");
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 exit(1);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 }
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 sprintf(pathname, map->pathname, argv[2]);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 } else {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 if (argc > 2)
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 goto usage;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 strcpy(pathname, map->pathname);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 file_expected_size = map->size;
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 read_ffs_image();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 find_inode_block();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 alloc_inode_table();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 find_root_inode();
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 headino = find_pathname(pathname);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 inf = inode_info[headino];
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 if (inf->type != 0xF1) {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 fprintf(stderr, "error: FFS object is not a regular file\n");
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 exit(1);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 }
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 size_head_chunk(inf, &chi);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 read_chunk(&chi);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 iterate_seg_file(headino, segment_read_callback, 0L, 0, 0);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 if (file_read_ptr < file_expected_size) {
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 fprintf(stderr, "error: FFS file is shorter than expected\n");
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 exit(1);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 }
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 map->decode_func(file_read_buf, stdout);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 exit(0);
d68275d47a32 tiffs IVA: decode command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 }