annotate cp2102/patch_ee_file.c @ 98:1cacc1ae56f0

cp2102 tools: convert to -d option for non-default device
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 28 Sep 2023 04:45:13 +0000
parents 915a6fa7723e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 }