Debian Codegraph @

src/arguments.h

raw
1 /*
2 * dfu-programmer
3 *
4 * $Id$
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #ifndef __ARGUMENTS_H__
22 #define __ARGUMENTS_H__
23
24 #include <stdbool.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include "dfu-device.h"
31 #include "atmel.h"
32
33 #define DEVICE_TYPE_STRING_MAX_LENGTH 6
34 /*
35 * atmel_programmer target command
36 *
37 * configure {BSB|SBV|SSB|EB|HSB} [--suppress-validation, --quiet, --debug level] value
38 * dump [--quiet, --debug level]
39 * erase [--suppress-validation, --quiet, --debug level]
40 * flash [--suppress-validation, --quiet, --debug level] file
41 * get {bootloader-version|ID1|ID2|BSB|SBV|SSB|EB|manufacturer|family|product-name|product-revision|HSB} [--quiet, --debug level]
42 * launch [--no-reset]
43 */
44
45 enum return_codes_enum {
46 SUCCESS = 0,
47 UNSPECIFIED_ERROR, /* general error */
48 ARGUMENT_ERROR, /* invalid command for target etc. */
49 DEVICE_ACCESS_ERROR, /* security bit etc. */
50 BUFFER_INIT_ERROR, /* hex files problems etc. */
51 FLASH_READ_ERROR,
52 FLASH_WRITE_ERROR,
53 VALIDATION_ERROR_IN_REGION,
54 VALIDATION_ERROR_OUTSIDE_REGION };
55
56 enum targets_enum { tar_at89c51snd1c,
57 tar_at89c51snd2c,
58 tar_at89c5130,
59 tar_at89c5131,
60 tar_at89c5132,
61 tar_at90usb1287,
62 tar_at90usb1286,
63 tar_at90usb1287_4k,
64 tar_at90usb1286_4k,
65 tar_at90usb647,
66 tar_at90usb646,
67 tar_at90usb162,
68 tar_at90usb82,
69 tar_atmega32u6,
70 tar_atmega32u4,
71 tar_atmega32u2,
72 tar_atmega16u4,
73 tar_atmega16u2,
74 tar_atmega8u2,
75 tar_at32uc3b064,
76 tar_at32uc3b164,
77 tar_at32uc3b0128,
78 tar_at32uc3b1128,
79 tar_at32uc3b0256,
80 tar_at32uc3b1256,
81 tar_at32uc3b0256es,
82 tar_at32uc3b1256es,
83 tar_at32uc3b0512,
84 tar_at32uc3b1512,
85 tar_at32uc3a0128,
86 tar_at32uc3a1128,
87 tar_at32uc3a0256,
88 tar_at32uc3a1256,
89 tar_at32uc3a0512,
90 tar_at32uc3a1512,
91 tar_at32uc3a0512es,
92 tar_at32uc3a1512es,
93 tar_at32uc3a364,
94 tar_at32uc3a364s,
95 tar_at32uc3a3128,
96 tar_at32uc3a3128s,
97 tar_at32uc3a3256,
98 tar_at32uc3a3256s,
99 tar_at32uc3a4256s,
100 tar_at32uc3c064,
101 tar_at32uc3c0128,
102 tar_at32uc3c0256,
103 tar_at32uc3c0512,
104 tar_at32uc3c164,
105 tar_at32uc3c1128,
106 tar_at32uc3c1256,
107 tar_at32uc3c1512,
108 tar_at32uc3c264,
109 tar_at32uc3c2128,
110 tar_at32uc3c2256,
111 tar_at32uc3c2512,
112 tar_atxmega64a1u,
113 tar_atxmega128a1u,
114 tar_atxmega64a3u,
115 tar_atxmega128a3u,
116 tar_atxmega192a3u,
117 tar_atxmega256a3u,
118 tar_atxmega16a4u,
119 tar_atxmega32a4u,
120 tar_atxmega64a4u,
121 tar_atxmega128a4u,
122 tar_atxmega256a3bu,
123 tar_atxmega64b1,
124 tar_atxmega128b1,
125 tar_atxmega64b3,
126 tar_atxmega128b3,
127 tar_atxmega64c3,
128 tar_atxmega128c3,
129 tar_atxmega256c3,
130 tar_atxmega384c3,
131 tar_atxmega16c4,
132 tar_atxmega32c4,
133 tar_stm32f4_B,
134 tar_stm32f4_C,
135 tar_stm32f4_E,
136 tar_stm32f4_G,
137 tar_none };
138
139 enum commands_enum { com_none, com_erase, com_flash, com_user, com_eflash,
140 com_configure, com_get, com_getfuse, com_dump, com_edump,
141 com_udump, com_setfuse, com_setsecure, com_start_app,
142 com_reset, com_launch, com_read, com_hex2bin, com_bin2hex };
143
144 enum configure_enum { conf_BSB = ATMEL_SET_CONFIG_BSB,
145 conf_SBV = ATMEL_SET_CONFIG_SBV,
146 conf_SSB = ATMEL_SET_CONFIG_SSB,
147 conf_EB = ATMEL_SET_CONFIG_EB,
148 conf_HSB = ATMEL_SET_CONFIG_HSB };
149
150 enum setfuse_enum { set_lock, set_epfl, set_bootprot, set_bodlevel,
151 set_bodhyst, set_boden, set_isp_bod_en,
152 set_isp_io_cond_en, set_isp_force };
153
154 enum get_enum { get_bootloader, get_ID1, get_ID2, get_BSB, get_SBV, get_SSB,
155 get_EB, get_manufacturer, get_family, get_product_name,
156 get_product_rev, get_HSB };
157
158 enum getfuse_enum { get_lock, get_epfl, get_bootprot, get_bodlevel,
159 get_bodhyst, get_boden, get_isp_bod_en,
160 get_isp_io_cond_en, get_isp_force };
161
162 struct programmer_arguments {
163 /* target-specific inputs */
164 enum targets_enum target;
165 uint16_t vendor_id;
166 uint16_t chip_id;
167 uint16_t bus_id; /* if non-zero, use bus_id and device_address */
168 uint16_t device_address; /* to identify the specific target device. */
169 atmel_device_class_t device_type;
170 char device_type_string[DEVICE_TYPE_STRING_MAX_LENGTH];
171 uint32_t memory_address_top; /* the maximum flash memory addr. */
172 uint32_t memory_address_bottom; /* including bootloader region */
173 uint32_t flash_address_top; /* the maximum flash-able address */
174 uint32_t flash_address_bottom; /* excludes bootloader region */
175 uint32_t bootloader_top; /* top of the bootloader region */
176 uint32_t bootloader_bottom; /* bottom of the bootloader region */
177 size_t flash_page_size; /* size of a page in bytes */
178 bool initial_abort;
179 bool honor_interfaceclass;
180 size_t eeprom_memory_size;
181 size_t eeprom_page_size;
182
183 /* command-specific state */
184 enum commands_enum command;
185 char quiet;
186 char suppressBootloader;
187
188 union {
189 struct com_configure_struct {
190 enum configure_enum name;
191 int32_t suppress_validation;
192 int32_t value;
193 } com_configure_data;
194
195 struct com_setfuse_struct {
196 enum setfuse_enum name;
197 int32_t value;
198 } com_setfuse_data;
199
200 struct com_read_struct {
201 bool bin;
202 bool force; /* do not remove blank pages */
203 enum atmel_memory_unit_enum segment;
204 } com_read_data;
205
206 struct com_erase_struct {
207 bool force;
208 int32_t suppress_validation;
209 } com_erase_data;
210
211 struct com_launch_struct {
212 bool noreset;
213 } com_launch_config;
214
215 struct com_flash_struct {
216 int32_t suppress_validation;
217 char original_first_char;
218 char *file;
219 int16_t *serial_data; /* serial number or other device specific bytes */
220 size_t serial_offset; /* where the serial_data should be written */
221 size_t serial_length; /* how many bytes to write */
222 bool force; /* bootloader configuration for UC3 devices
223 is on last one or two words in the user
224 page depending on the version of the
225 bootloader - force overwrite required */
226 bool validate_first; /* Do a validate before flashing */
227 bool ignore_outside; /* Ignore validate errors outside region */
228 bool erase_first; /* Erase flash before writing */
229 enum atmel_memory_unit_enum segment;
230 } com_flash_data;
231
232 struct com_convert_struct {
233 size_t bin_offset; // where the bin data starts
234 char original_first_char;
235 bool force; /* do not remove blank pages */
236 char *file; // for bin2hex / hex2bin conversions
237 enum atmel_memory_unit_enum segment; // to auto-select offset
238 } com_convert_data;
239
240 struct com_get_struct {
241 enum get_enum name;
242 } com_get_data;
243
244 struct com_getfuse_struct {
245 enum getfuse_enum name;
246 } com_getfuse_data;
247 };
248 };
249
250 int32_t parse_arguments( struct programmer_arguments *args,
251 const size_t argc,
252 char **argv );
253
254 #ifdef __cplusplus
255 }
256 #endif
257
258 #endif