annotate miscprog/pirbattextr.c @ 239:7a394cc1c72a

pirelli/fw-disasm: spi_env code located
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 23 Dec 2017 01:13:07 +0000
parents 30804198d5d0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
226
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program extracts the a_pwr_thresholds[] table from one of Pirelli's
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * fw images and converts the numbers to decimal.
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/file.h>
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <unistd.h>
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 struct entry {
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 u_char mvolt[2];
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 u_char percent;
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 u_char pad;
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 };
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 struct entry array[21];
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 read_array_from_image(filename, offset_arg)
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char *filename, *offset_arg;
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 int fd;
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 fd = open(filename, O_RDONLY);
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (fd < 0) {
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 perror(filename);
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 exit(1);
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 lseek(fd, strtoul(offset_arg, 0, 0), 0);
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 read(fd, array, sizeof array);
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 close(fd);
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 dump_array()
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 int i;
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 unsigned mvolt;
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 for (i = 0; i < 21; i++) {
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 mvolt = array[i].mvolt[0] | (array[i].mvolt[1] << 8);
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 printf("%4u\t%u\n", mvolt, array[i].percent);
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 main(argc, argv)
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 char **argv;
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 {
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (argc != 3) {
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 fprintf(stderr, "usage: %s fw-image offset\n", argv[0]);
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 exit(1);
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 read_array_from_image(argv[1], argv[2]);
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 dump_array();
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 exit(0);
30804198d5d0 Pirelli's a_pwr_thresholds[] table found
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }