FreeCalypso > hg > freecalypso-hwlab
annotate ee2232/ee2232-read.c @ 136:a21d348e01db
fc-uicc-tool: pb-dump command ported over
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 04 Feb 2021 03:40:55 +0000 |
parents | ef43bbfa8d16 |
children |
rev | line source |
---|---|
3
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <string.h> |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <strings.h> |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <stdio.h> |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdlib.h> |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <unistd.h> |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <ftdi.h> |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 char *device_selector = "i:0x0403:0x6010"; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 unsigned eeprom_size = 64; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 process_cmdline(argc, argv) |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 char **argv; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 { |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int c; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern char *optarg; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 while ((c = getopt(argc, argv, "d:t:")) != EOF) { |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 switch (c) { |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 case 'd': |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 device_selector = optarg; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 continue; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 case 't': |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (!strcmp(optarg, "46")) |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 eeprom_size = 64; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 else if (!strcmp(optarg, "56")) |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 eeprom_size = 128; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 else if (!strcmp(optarg, "66")) |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 eeprom_size = 256; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 else { |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 fprintf(stderr, |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 "error: -t option invalid value \"%s\"\n", |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 optarg); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 exit(1); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 continue; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 default: |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 /* error msg already printed */ |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 exit(1); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 main(argc, argv) |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 char **argv; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 { |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 struct ftdi_context ftdi; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 u_short word; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 unsigned n, col; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 process_cmdline(argc, argv); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 ftdi_init(&ftdi); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (ftdi_usb_open_string(&ftdi, device_selector) < 0) { |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 exit(1); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 for (n = 0; n < eeprom_size; n++) { |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (ftdi_read_eeprom_location(&ftdi, n, &word) < 0) { |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 fprintf(stderr, "EEPROM read error: %s\n", |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 ftdi.error_str); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 exit(1); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 col = n & 7; |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (col == 0) |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 printf("%02X:", n * 2); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 printf(" %04X", word); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (col == 7) |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 putchar('\n'); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 ftdi_usb_close(&ftdi); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 exit(0); |
ef43bbfa8d16
ee2232-read program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |