annotate cp2102/apply_eeprom_patch.c @ 104:866eae65dbea

LICENSE: same as other FreeCalypso tools
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 29 Sep 2023 18:20:04 +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 function implemented in this module reads a CP2102 EEPROM patch
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * specification file (which can also be a baud rate table file) and applies
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * patches to the EEPROM image in RAM.
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 <ctype.h>
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdio.h>
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "cp210x_defs.h"
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern u_char eeprom[SIZE_EEPROM];
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 static char cp2102_install_dir[] = "/opt/freecalypso/cp2102";
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 static void
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 apply_baud_entry(filename, lineno, args)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char *filename, *args;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 unsigned entry_idx, intend_baud, baudgen_val, timeout_val;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 unsigned prescaler, extra_byte;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 char *cp = args;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 u_char *eerec;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (!isdigit(*cp)) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 inv: fprintf(stderr, "%s line %d: invalid syntax for baud-entry\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 entry_idx = strtoul(cp, &cp, 10);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (*cp++ != ':')
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (!isdigit(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 intend_baud = strtoul(cp, &cp, 10);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (*cp++ != '=')
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (!isxdigit(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 baudgen_val = strtoul(cp, &cp, 16);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (*cp++ != ',')
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (!isxdigit(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 timeout_val = strtoul(cp, &cp, 16);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (*cp++ != ',')
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (!isdigit(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 prescaler = strtoul(cp, &cp, 10);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (*cp++ != ',')
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (!isdigit(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 extra_byte = strtoul(cp, &cp, 10);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (*cp && *cp != '#')
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 /* done with parsing, get to EEPROM */
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 if (entry_idx > 31) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 fprintf(stderr, "%s line %d: invalid baud-entry index\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 eerec = eeprom + entry_idx * SIZE_BAUDRATE_CFG;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 eerec[0] = baudgen_val >> 8;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 eerec[1] = baudgen_val;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 eerec[2] = timeout_val >> 8;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 eerec[3] = timeout_val;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 eerec[4] = prescaler;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 eerec[5] = extra_byte;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 eerec[6] = intend_baud;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 eerec[7] = intend_baud >> 8;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 eerec[8] = intend_baud >> 16;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 eerec[9] = intend_baud >> 24;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 static void
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 apply_patch_8bit(filename, lineno, args)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 char *filename, *args;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 unsigned patch_loc, patch_val;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 char *cp = args;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 if (!isxdigit(*cp)) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 inv: fprintf(stderr, "%s line %d: invalid syntax for patch8\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 patch_loc = strtoul(cp, &cp, 16);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 if (!isxdigit(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 patch_val = strtoul(cp, &cp, 16);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 if (*cp && *cp != '#')
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 /* validate range */
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 if (patch_loc >= EEPROM_START_ADDR &&
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 patch_loc <= EEPROM_START_ADDR + SIZE_EEPROM - 1)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 patch_loc -= EEPROM_START_ADDR;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 else if (patch_loc > SIZE_EEPROM - 1) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 fprintf(stderr, "%s line %d: invalid patch address\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 if (patch_val > 0xFF) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 fprintf(stderr,
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 "%s line %d: patch value does not fit into 8 bits\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 /* checks done, proceed */
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 eeprom[patch_loc] = patch_val;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 static void
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 apply_patch_16bit(filename, lineno, args)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 char *filename, *args;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 unsigned patch_loc, patch_val;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 char *cp = args;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 if (!isxdigit(*cp)) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 inv: fprintf(stderr, "%s line %d: invalid syntax for patch16\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 patch_loc = strtoul(cp, &cp, 16);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 if (!isxdigit(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 patch_val = strtoul(cp, &cp, 16);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 if (*cp && *cp != '#')
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 /* validate range */
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 if (patch_loc >= EEPROM_START_ADDR &&
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 patch_loc <= EEPROM_START_ADDR + SIZE_EEPROM - 2)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 patch_loc -= EEPROM_START_ADDR;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 else if (patch_loc > SIZE_EEPROM - 2) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 fprintf(stderr, "%s line %d: invalid patch address\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 if (patch_val > 0xFFFF) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 fprintf(stderr,
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 "%s line %d: patch value does not fit into 16 bits\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 /* checks done, proceed */
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 eeprom[patch_loc] = patch_val;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 eeprom[patch_loc+1] = patch_val >> 8;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 static void
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 apply_patch_vid(filename, lineno, args)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 char *filename, *args;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 unsigned patch_val;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 char *cp = args;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 if (!isxdigit(*cp)) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 inv: fprintf(stderr, "%s line %d: invalid syntax for vid\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 patch_val = strtoul(cp, &cp, 16);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 if (*cp && *cp != '#')
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 /* validate range */
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 if (patch_val > 0xFFFF) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 fprintf(stderr, "%s line %d: VID does not fit into 16 bits\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 /* checks done, proceed */
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 eeprom[0x390] = patch_val;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 eeprom[0x391] = patch_val >> 8;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 static void
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 apply_patch_pid(filename, lineno, args)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 char *filename, *args;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 unsigned patch_val;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 char *cp = args;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 if (!isxdigit(*cp)) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 inv: fprintf(stderr, "%s line %d: invalid syntax for pid\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 patch_val = strtoul(cp, &cp, 16);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 if (*cp && *cp != '#')
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 goto inv;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 /* validate range */
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 if (patch_val > 0xFFFF) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 fprintf(stderr, "%s line %d: PID does not fit into 16 bits\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 /* checks done, proceed */
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 eeprom[0x392] = patch_val;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 eeprom[0x393] = patch_val >> 8;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 static void
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 set_string_desc(start_offset, str)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 unsigned start_offset;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 char *str;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 char *cp;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 u_char *dp;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 dp = eeprom + start_offset;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 *dp++ = strlen(str) * 2 + 2;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 *dp++ = 0x03;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 for (cp = str; *cp; ) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 *dp++ = *cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 *dp++ = 0;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 static void
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 set_manuf_string(filename, lineno, arg)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 char *filename, *arg;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 if (strlen(arg) > 29) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 fprintf(stderr, "%s line %d: manuf string is too long\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 set_string_desc(0x3C3, arg);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 static void
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 set_product_string(filename, lineno, arg)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 char *filename, *arg;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 if (strlen(arg) > 126) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 fprintf(stderr, "%s line %d: product string is too long\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 set_string_desc(0x208, arg);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 static void
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 set_serial_string(filename, lineno, arg)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 char *filename, *arg;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 if (strlen(arg) > 63) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 fprintf(stderr, "%s line %d: serial string is too long\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 set_string_desc(0x307, arg);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 static void
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 apply_eeprom_patch_int(filename, inf)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 char *filename;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 FILE *inf;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 char linebuf[1024];
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 int lineno;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 char *cp, *np;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 cp = index(linebuf, '\n');
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 if (!cp) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 fprintf(stderr,
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 "%s line %d: too long or unterminated\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 filename, lineno);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 *cp = '\0';
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 for (cp = linebuf; isspace(*cp); cp++)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 ;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 if (*cp == '\0' || *cp == '#')
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 continue;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 for (np = cp; *cp && !isspace(*cp); cp++)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 ;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 if (*cp)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 *cp++ = '\0';
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 while (isspace(*cp))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321 cp++;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322 if (*cp == '\0' || *cp == '#') {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 fprintf(stderr,
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324 "%s line %d: \"%s\" setting without argument\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325 filename, lineno, np);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 if (!strcmp(np, "baud-entry"))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 apply_baud_entry(filename, lineno, cp);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 else if (!strcmp(np, "patch8"))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 apply_patch_8bit(filename, lineno, cp);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332 else if (!strcmp(np, "patch16"))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 apply_patch_16bit(filename, lineno, cp);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 else if (!strcmp(np, "vid"))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 apply_patch_vid(filename, lineno, cp);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336 else if (!strcmp(np, "pid"))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337 apply_patch_pid(filename, lineno, cp);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 else if (!strcmp(np, "manuf"))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339 set_manuf_string(filename, lineno, cp);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 else if (!strcmp(np, "product"))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341 set_product_string(filename, lineno, cp);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342 else if (!strcmp(np, "serial"))
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 set_serial_string(filename, lineno, cp);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 else {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345 fprintf(stderr, "%s line %d: unknown \"%s\" setting\n",
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346 filename, lineno, np);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
349 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
351
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352 static FILE *
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 open_with_search(req_filename)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 char *req_filename;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 char pathbuf[256];
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357 FILE *f;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359 if (!index(req_filename, '/') && strlen(req_filename) < 128) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360 sprintf(pathbuf, "%s/%s", cp2102_install_dir, req_filename);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361 f = fopen(pathbuf, "r");
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362 if (f)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
363 return f;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
364 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365 f = fopen(req_filename, "r");
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
366 return f;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
368
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 void
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
370 apply_eeprom_patch_file(filename)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
371 char *filename;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
372 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
373 FILE *inf;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
374
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375 inf = open_with_search(filename);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376 if (!inf) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
377 perror(filename);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
378 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
379 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
380 apply_eeprom_patch_int(filename, inf);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
381 fclose(inf);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
382 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
383
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
384 void
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
385 apply_eeprom_patch_baud(baud_spec_name)
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
386 char *baud_spec_name;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
387 {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
388 char pathbuf[256];
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
389 FILE *inf;
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
390
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
391 if (strlen(baud_spec_name) > 63) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
392 fprintf(stderr, "error: no buffer overflow attacks, please\n");
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
393 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
394 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
395 sprintf(pathbuf, "%s/baudtab-%s", cp2102_install_dir, baud_spec_name);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
396 inf = fopen(pathbuf, "r");
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
397 if (!inf) {
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
398 perror(pathbuf);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
399 exit(1);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
400 }
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
401 apply_eeprom_patch_int(pathbuf, inf);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
402 fclose(inf);
915a6fa7723e cp2102-patch-ee-image program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
403 }