FreeCalypso > hg > fc-usbser-tools
annotate cp2102/patch_ee_file.c @ 107:bc3367755586 default tip
add INSTALL document
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Tue, 21 Nov 2023 22:11:09 +0000 |
| parents | 915a6fa7723e |
| children |
| rev | line source |
|---|---|
|
92
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads a CP2102 EEPROM image from an Intel HEX file, |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * applies patches to it from a patch specification file, and writes out |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * a new Intel HEX image. |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "cp210x_defs.h" |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 u_char eeprom[SIZE_EEPROM]; |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 main(argc, argv) |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char **argv; |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 FILE *outf; |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 if (argc != 4) { |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 fprintf(stderr, |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 "usage: %s input-hex-file patch-spec output-hex-file\n", |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 argv[0]); |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 exit(1); |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 } |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 read_intel_hex(argv[1]); |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 apply_eeprom_patch_file(argv[2]); |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 outf = fopen(argv[3], "w"); |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (!outf) { |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 perror(argv[3]); |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 exit(1); |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 intel_hex_out(eeprom, outf); |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 fclose(outf); |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 exit(0); |
|
915a6fa7723e
cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
