FreeCalypso > hg > freecalypso-hwlab
annotate simtool/writecmd.c @ 174:4f5abad5dd40
doc/Unbuffered-FT2232x-JTAG: update for fc-usbser-tools
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Sep 2023 07:23:18 +0000 |
parents | d515cfbb3f39 |
children |
rev | line source |
---|---|
101
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <stdio.h> |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <stdlib.h> |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <pcsclite.h> |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <winscard.h> |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include "globals.h" |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 cmd_update_bin(argc, argv) |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 char **argv; |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 { |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 unsigned offset, len; |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 u_char data[255]; |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 int rc; |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 offset = strtoul(argv[1], 0, 0); |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 if (offset > 0xFFFF) { |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 fprintf(stderr, "error: offset argument is out of range\n"); |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 return(-1); |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 } |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 rc = read_hex_data_file(argv[2], data); |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (rc < 0) |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 return(rc); |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 len = rc; |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 return update_bin_op(offset, data, len); |
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
102
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
26 |
109
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
27 cmd_update_bin_imm(argc, argv) |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
28 char **argv; |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
29 { |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
30 unsigned offset, len; |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
31 u_char data[255]; |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
32 int rc; |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
33 |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
34 offset = strtoul(argv[1], 0, 0); |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
35 if (offset > 0xFFFF) { |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
36 fprintf(stderr, "error: offset argument is out of range\n"); |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
37 return(-1); |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
38 } |
151
d515cfbb3f39
fc-simtool: hex string parsing: add minimum length parameter
Mychaela Falconia <falcon@freecalypso.org>
parents:
150
diff
changeset
|
39 rc = decode_hex_data_from_string(argv[2], data, 1, 255); |
109
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
40 if (rc < 0) |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
41 return(rc); |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
42 len = rc; |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
43 return update_bin_op(offset, data, len); |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
44 } |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
45 |
102
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
46 cmd_update_rec(argc, argv) |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
47 char **argv; |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
48 { |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
49 unsigned recno; |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
50 u_char data[255]; |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
51 int rc; |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
52 |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
53 recno = strtoul(argv[1], 0, 0); |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
54 if (recno < 1 || recno > 255) { |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
55 fprintf(stderr, |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
56 "error: record number argument is out of range\n"); |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
57 return(-1); |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
58 } |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
59 rc = read_hex_data_file(argv[2], data); |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
60 if (rc < 0) |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
61 return(rc); |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
62 if (rc != curfile_record_len) { |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
63 fprintf(stderr, "error: hex data length != EF record length\n"); |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
64 return(-1); |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
65 } |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
66 return update_rec_op(recno, 0x04, data, curfile_record_len); |
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
67 } |