2010-03-17 06:54:21 +00:00
|
|
|
/* MSPDebug - debugging tool for MSP430 MCUs
|
2012-03-02 22:56:26 +00:00
|
|
|
* Copyright (C) 2009-2012 Daniel Beer
|
2009-11-16 23:52:10 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-11-17 02:11:46 +00:00
|
|
|
#include <unistd.h>
|
2010-05-18 23:48:01 +00:00
|
|
|
#include <getopt.h>
|
2009-11-16 23:52:10 +00:00
|
|
|
|
|
|
|
#include "dis.h"
|
2010-01-06 03:17:55 +00:00
|
|
|
#include "device.h"
|
2010-01-05 04:21:45 +00:00
|
|
|
#include "binfile.h"
|
2010-01-05 11:09:08 +00:00
|
|
|
#include "stab.h"
|
2010-01-08 05:03:51 +00:00
|
|
|
#include "util.h"
|
2010-06-28 03:13:51 +00:00
|
|
|
#include "usbutil.h"
|
2010-03-22 06:12:51 +00:00
|
|
|
#include "gdb.h"
|
2010-04-08 01:15:30 +00:00
|
|
|
#include "rtools.h"
|
2010-04-10 02:00:00 +00:00
|
|
|
#include "sym.h"
|
2010-04-10 02:35:36 +00:00
|
|
|
#include "devcmd.h"
|
2010-05-01 05:54:10 +00:00
|
|
|
#include "expr.h"
|
2010-08-13 03:14:15 +00:00
|
|
|
#include "opdb.h"
|
2010-08-13 04:40:58 +00:00
|
|
|
#include "reader.h"
|
2010-08-16 23:07:03 +00:00
|
|
|
#include "output.h"
|
2012-10-08 21:03:10 +00:00
|
|
|
#include "output_util.h"
|
2011-03-09 21:48:59 +00:00
|
|
|
#include "simio.h"
|
2012-10-08 20:55:48 +00:00
|
|
|
#include "ctrlc.h"
|
2009-11-16 23:52:10 +00:00
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
#include "sim.h"
|
|
|
|
#include "bsl.h"
|
|
|
|
#include "fet.h"
|
2010-05-19 00:08:50 +00:00
|
|
|
#include "vector.h"
|
2010-05-18 23:48:01 +00:00
|
|
|
#include "fet_db.h"
|
2012-10-03 00:37:29 +00:00
|
|
|
#include "fet_olimex_db.h"
|
2010-09-17 14:04:33 +00:00
|
|
|
#include "flash_bsl.h"
|
2011-06-06 03:47:52 +00:00
|
|
|
#include "gdbc.h"
|
2011-10-13 23:49:04 +00:00
|
|
|
#include "tilib.h"
|
2012-07-18 00:26:55 +00:00
|
|
|
#include "goodfet.h"
|
2012-10-09 01:52:02 +00:00
|
|
|
#include "input.h"
|
2012-10-09 02:42:54 +00:00
|
|
|
#include "input_async.h"
|
2012-10-11 22:33:20 +00:00
|
|
|
#include "pif.h"
|
2010-04-30 04:57:57 +00:00
|
|
|
|
2012-10-09 02:41:06 +00:00
|
|
|
#define OPT_NO_RC 0x01
|
|
|
|
#define OPT_EMBEDDED 0x02
|
|
|
|
|
2010-06-28 02:36:05 +00:00
|
|
|
struct cmdline_args {
|
2011-03-15 01:20:06 +00:00
|
|
|
const char *driver_name;
|
2013-03-25 21:07:32 +00:00
|
|
|
const char *alt_config;
|
2012-10-09 02:41:06 +00:00
|
|
|
int flags;
|
2011-03-15 01:20:06 +00:00
|
|
|
struct device_args devarg;
|
2010-06-28 02:36:05 +00:00
|
|
|
};
|
|
|
|
|
2011-03-15 01:56:07 +00:00
|
|
|
static const struct device_class *const driver_table[] = {
|
|
|
|
&device_rf2500,
|
|
|
|
&device_olimex,
|
2011-12-25 22:22:04 +00:00
|
|
|
&device_olimex_v1,
|
2011-03-15 01:56:07 +00:00
|
|
|
&device_olimex_iso,
|
2012-09-13 01:55:14 +00:00
|
|
|
&device_olimex_iso_mk2,
|
2011-03-15 01:56:07 +00:00
|
|
|
&device_sim,
|
|
|
|
&device_uif,
|
|
|
|
&device_bsl,
|
2011-06-06 03:47:52 +00:00
|
|
|
&device_flash_bsl,
|
2011-10-13 23:49:04 +00:00
|
|
|
&device_gdbc,
|
2012-07-18 00:26:55 +00:00
|
|
|
&device_tilib,
|
2012-10-11 22:33:20 +00:00
|
|
|
&device_goodfet,
|
|
|
|
&device_pif
|
2010-06-28 02:36:05 +00:00
|
|
|
};
|
|
|
|
|
2010-10-28 01:08:22 +00:00
|
|
|
static const char *version_text =
|
2012-11-25 23:27:48 +00:00
|
|
|
"MSPDebug version 0.21 - debugging tool for MSP430 MCUs\n"
|
2012-03-02 22:56:26 +00:00
|
|
|
"Copyright (C) 2009-2012 Daniel Beer <dlbeer@gmail.com>\n"
|
2010-08-31 03:50:00 +00:00
|
|
|
"This is free software; see the source for copying conditions. There is NO\n"
|
|
|
|
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR "
|
2010-10-28 01:08:22 +00:00
|
|
|
"PURPOSE.\n";
|
2010-08-31 03:50:00 +00:00
|
|
|
|
2009-11-17 02:11:46 +00:00
|
|
|
static void usage(const char *progname)
|
|
|
|
{
|
2010-06-28 02:36:05 +00:00
|
|
|
int i;
|
|
|
|
|
2013-05-20 19:54:07 +00:00
|
|
|
printc("Usage: %s [options] <driver> [command ...]\n"
|
2009-11-17 02:34:10 +00:00
|
|
|
"\n"
|
2010-08-31 03:50:00 +00:00
|
|
|
" -q\n"
|
|
|
|
" Start in quiet mode.\n"
|
2010-06-28 02:36:05 +00:00
|
|
|
" -d device\n"
|
|
|
|
" Connect via the given tty device, rather than USB.\n"
|
2010-06-28 03:13:51 +00:00
|
|
|
" -U bus:dev\n"
|
|
|
|
" Specify a particular USB device to connect to.\n"
|
2011-07-18 02:56:29 +00:00
|
|
|
" -s serial\n"
|
|
|
|
" Specify a particular device serial number to connect to.\n"
|
2010-01-04 09:34:23 +00:00
|
|
|
" -j\n"
|
2010-06-15 01:13:51 +00:00
|
|
|
" Use JTAG, rather than Spy-Bi-Wire (UIF devices only).\n"
|
2010-01-06 08:08:01 +00:00
|
|
|
" -v voltage\n"
|
|
|
|
" Set the supply voltage, in millivolts.\n"
|
2010-04-08 02:43:19 +00:00
|
|
|
" -n\n"
|
2013-03-25 21:07:32 +00:00
|
|
|
" Do not read a configuration file on startup.\n"
|
|
|
|
" -C <file>\n"
|
|
|
|
" Load an alternative configuration file.\n"
|
2010-09-17 14:15:33 +00:00
|
|
|
" --long-password\n"
|
|
|
|
" Send 32-byte IVT as BSL password (flash-bsl only)\n"
|
2010-05-18 23:48:01 +00:00
|
|
|
" --help\n"
|
2010-04-08 02:43:19 +00:00
|
|
|
" Show this help text.\n"
|
2010-05-18 23:48:01 +00:00
|
|
|
" --fet-list\n"
|
|
|
|
" Show a list of devices supported by the FET driver.\n"
|
2010-05-18 23:54:15 +00:00
|
|
|
" --fet-force-id string\n"
|
|
|
|
" Override the device ID returned by the FET.\n"
|
2010-06-28 03:13:51 +00:00
|
|
|
" --usb-list\n"
|
|
|
|
" Show a list of available USB devices.\n"
|
2011-03-23 15:13:03 +00:00
|
|
|
" --force-reset\n"
|
|
|
|
" Force target reset in initialization sequence.\n"
|
2011-10-13 23:49:04 +00:00
|
|
|
" --allow-fw-update\n"
|
|
|
|
" Update FET firmware (tilib only) if necessary.\n"
|
2011-12-14 00:11:29 +00:00
|
|
|
" --require-fw-update <image.txt>\n"
|
2012-09-11 02:35:31 +00:00
|
|
|
" Require FET firmware update. The required image format depends\n"
|
|
|
|
" on the driver.\n"
|
2010-08-31 03:50:00 +00:00
|
|
|
" --version\n"
|
|
|
|
" Show copyright and version information.\n"
|
2012-10-09 02:41:06 +00:00
|
|
|
" --embedded\n"
|
|
|
|
" Run in embedded mode.\n"
|
2010-01-04 09:34:23 +00:00
|
|
|
"\n"
|
2010-06-28 02:36:05 +00:00
|
|
|
"Most drivers connect by default via USB, unless told otherwise via the\n"
|
2010-06-28 03:13:51 +00:00
|
|
|
"-d option. By default, the first USB device found is opened.\n"
|
2009-11-17 02:34:10 +00:00
|
|
|
"\n"
|
|
|
|
"If commands are given, they will be executed. Otherwise, an interactive\n"
|
2010-06-28 02:36:05 +00:00
|
|
|
"command reader is started.\n\n",
|
|
|
|
progname);
|
|
|
|
|
2010-08-16 23:07:03 +00:00
|
|
|
printc("Available drivers are:\n");
|
2010-06-28 02:36:05 +00:00
|
|
|
for (i = 0; i < ARRAY_LEN(driver_table); i++) {
|
2011-03-15 01:56:07 +00:00
|
|
|
const struct device_class *drv = driver_table[i];
|
2010-06-28 02:36:05 +00:00
|
|
|
|
2010-08-16 23:07:03 +00:00
|
|
|
printc(" %s\n %s\n", drv->name, drv->help);
|
2010-06-28 02:36:05 +00:00
|
|
|
}
|
2009-11-17 02:11:46 +00:00
|
|
|
}
|
|
|
|
|
2013-03-25 21:07:32 +00:00
|
|
|
static void process_rc_file(const char *config)
|
2010-04-08 02:43:19 +00:00
|
|
|
{
|
|
|
|
char text[256];
|
|
|
|
|
2013-03-25 21:07:32 +00:00
|
|
|
if (!config) {
|
2013-04-04 02:53:38 +00:00
|
|
|
if (!access(".mspdebug", F_OK)) {
|
|
|
|
config = ".mspdebug";
|
|
|
|
} else {
|
|
|
|
const char *home = getenv("HOME");
|
|
|
|
|
|
|
|
if (home) {
|
|
|
|
snprintf(text, sizeof(text), "%s/.mspdebug",
|
|
|
|
home);
|
|
|
|
if (!access(text, F_OK))
|
|
|
|
config = text;
|
|
|
|
}
|
|
|
|
}
|
2013-03-25 21:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
process_file(config, 0);
|
2010-04-08 02:43:19 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 00:08:50 +00:00
|
|
|
static int add_fet_device(void *user_data, const struct fet_db_record *r)
|
2010-05-18 23:48:01 +00:00
|
|
|
{
|
2010-05-19 00:08:50 +00:00
|
|
|
struct vector *v = (struct vector *)user_data;
|
|
|
|
|
|
|
|
return vector_push(v, &r->name, 1);
|
|
|
|
}
|
|
|
|
|
2012-10-03 00:37:29 +00:00
|
|
|
static int add_fet_olimex_device(void *user_data, const char *name)
|
|
|
|
{
|
|
|
|
struct vector *v = (struct vector *)user_data;
|
|
|
|
|
|
|
|
return vector_push(v, &name, 1);
|
|
|
|
}
|
|
|
|
|
2010-05-19 00:08:50 +00:00
|
|
|
static int list_devices(void)
|
|
|
|
{
|
|
|
|
struct vector v;
|
|
|
|
|
|
|
|
vector_init(&v, sizeof(const char *));
|
|
|
|
if (fet_db_enum(add_fet_device, &v) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
pr_error("couldn't allocate memory");
|
2010-05-19 00:08:50 +00:00
|
|
|
vector_destroy(&v);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-08-16 23:07:03 +00:00
|
|
|
printc("Devices supported by FET driver:\n");
|
2010-10-11 23:02:17 +00:00
|
|
|
namelist_print(&v);
|
2010-05-19 00:08:50 +00:00
|
|
|
vector_destroy(&v);
|
2010-10-11 23:02:17 +00:00
|
|
|
|
2012-10-03 00:37:29 +00:00
|
|
|
vector_init(&v, sizeof(const char *));
|
|
|
|
if (fet_olimex_db_enum(add_fet_olimex_device, &v) < 0) {
|
|
|
|
pr_error("couldn't allocate memory");
|
|
|
|
vector_destroy(&v);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printc("\n");
|
|
|
|
printc("Devices supported by Olimex FET driver:\n");
|
|
|
|
namelist_print(&v);
|
|
|
|
vector_destroy(&v);
|
|
|
|
|
2010-05-18 23:48:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-29 03:56:47 +00:00
|
|
|
static int parse_cmdline_args(int argc, char **argv,
|
|
|
|
struct cmdline_args *args)
|
2009-11-17 02:11:46 +00:00
|
|
|
{
|
2013-01-31 00:21:20 +00:00
|
|
|
enum {
|
|
|
|
LOPT_HELP = 0x100,
|
|
|
|
LOPT_FET_LIST,
|
|
|
|
LOPT_FET_FORCE_ID,
|
|
|
|
LOPT_USB_LIST,
|
|
|
|
LOPT_VERSION,
|
|
|
|
LOPT_LONG_PASSWORD,
|
|
|
|
LOPT_FORCE_RESET,
|
|
|
|
LOPT_ALLOW_FW_UPDATE,
|
|
|
|
LOPT_REQUIRE_FW_UPDATE,
|
|
|
|
LOPT_EMBEDDED
|
|
|
|
};
|
|
|
|
|
2011-11-15 11:28:37 +00:00
|
|
|
static const struct option longopts[] = {
|
2013-01-31 00:21:20 +00:00
|
|
|
{"help", 0, 0, LOPT_HELP},
|
|
|
|
{"fet-list", 0, 0, LOPT_FET_LIST},
|
|
|
|
{"fet-force-id", 1, 0, LOPT_FET_FORCE_ID},
|
|
|
|
{"usb-list", 0, 0, LOPT_USB_LIST},
|
|
|
|
{"version", 0, 0, LOPT_VERSION},
|
|
|
|
{"long-password", 0, 0, LOPT_LONG_PASSWORD},
|
|
|
|
{"force-reset", 0, 0, LOPT_FORCE_RESET},
|
|
|
|
{"allow-fw-update", 0, 0, LOPT_ALLOW_FW_UPDATE},
|
|
|
|
{"require-fw-update", 1, 0, LOPT_REQUIRE_FW_UPDATE},
|
|
|
|
{"embedded", 0, 0, LOPT_EMBEDDED},
|
2010-05-18 23:48:01 +00:00
|
|
|
{NULL, 0, 0, 0}
|
|
|
|
};
|
2013-01-31 00:21:20 +00:00
|
|
|
|
|
|
|
int opt;
|
2011-03-15 01:20:06 +00:00
|
|
|
int want_usb = 0;
|
2010-05-18 23:48:01 +00:00
|
|
|
|
2013-03-25 21:07:32 +00:00
|
|
|
while ((opt = getopt_long(argc, argv, "d:jv:nU:s:qC:",
|
2010-05-18 23:48:01 +00:00
|
|
|
longopts, NULL)) >= 0)
|
2009-11-17 02:11:46 +00:00
|
|
|
switch (opt) {
|
2013-03-25 21:07:32 +00:00
|
|
|
case 'C':
|
|
|
|
args->alt_config = optarg;
|
|
|
|
break;
|
|
|
|
|
2010-08-31 03:50:00 +00:00
|
|
|
case 'q':
|
|
|
|
{
|
2011-11-15 11:28:37 +00:00
|
|
|
static const union opdb_value v = {
|
2010-08-31 03:50:00 +00:00
|
|
|
.boolean = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
opdb_set("quiet", &v);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-01-31 00:21:20 +00:00
|
|
|
case LOPT_EMBEDDED:
|
2012-10-09 02:41:06 +00:00
|
|
|
args->flags |= OPT_EMBEDDED;
|
|
|
|
break;
|
|
|
|
|
2013-01-31 00:21:20 +00:00
|
|
|
case LOPT_ALLOW_FW_UPDATE:
|
2011-10-13 23:49:04 +00:00
|
|
|
args->devarg.flags |= DEVICE_FLAG_DO_FWUPDATE;
|
|
|
|
break;
|
|
|
|
|
2013-01-31 00:21:20 +00:00
|
|
|
case LOPT_USB_LIST:
|
2010-06-28 03:13:51 +00:00
|
|
|
usb_init();
|
|
|
|
usb_find_busses();
|
|
|
|
usb_find_devices();
|
|
|
|
usbutil_list();
|
|
|
|
exit(0);
|
|
|
|
|
2010-06-28 02:36:05 +00:00
|
|
|
case 'd':
|
2011-03-15 01:20:06 +00:00
|
|
|
args->devarg.path = optarg;
|
|
|
|
args->devarg.flags |= DEVICE_FLAG_TTY;
|
2010-06-15 02:53:38 +00:00
|
|
|
break;
|
|
|
|
|
2013-01-31 00:21:20 +00:00
|
|
|
case LOPT_REQUIRE_FW_UPDATE:
|
2011-12-14 00:11:29 +00:00
|
|
|
args->devarg.require_fwupdate = optarg;
|
|
|
|
break;
|
|
|
|
|
2010-06-28 03:13:51 +00:00
|
|
|
case 'U':
|
2011-03-15 01:20:06 +00:00
|
|
|
args->devarg.path = optarg;
|
|
|
|
want_usb = 1;
|
2010-06-28 03:13:51 +00:00
|
|
|
break;
|
|
|
|
|
2011-07-18 02:56:29 +00:00
|
|
|
case 's':
|
|
|
|
args->devarg.requested_serial = optarg;
|
|
|
|
break;
|
|
|
|
|
2013-01-31 00:21:20 +00:00
|
|
|
case LOPT_FET_LIST:
|
2010-05-19 00:08:50 +00:00
|
|
|
exit(list_devices());
|
2010-05-18 23:48:01 +00:00
|
|
|
|
2013-01-31 00:21:20 +00:00
|
|
|
case LOPT_FET_FORCE_ID:
|
2011-03-15 01:20:06 +00:00
|
|
|
args->devarg.forced_chip_id = optarg;
|
2010-05-18 23:54:15 +00:00
|
|
|
break;
|
|
|
|
|
2013-01-31 00:21:20 +00:00
|
|
|
case LOPT_HELP:
|
2010-05-18 23:54:15 +00:00
|
|
|
usage(argv[0]);
|
|
|
|
exit(0);
|
|
|
|
|
2013-01-31 00:21:20 +00:00
|
|
|
case LOPT_VERSION:
|
2010-10-28 01:08:22 +00:00
|
|
|
printc("%s", version_text);
|
2010-08-31 03:50:00 +00:00
|
|
|
exit(0);
|
|
|
|
|
2010-01-06 08:08:01 +00:00
|
|
|
case 'v':
|
2011-03-15 01:20:06 +00:00
|
|
|
args->devarg.vcc_mv = atoi(optarg);
|
2010-01-06 08:08:01 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-04 09:34:23 +00:00
|
|
|
case 'j':
|
2011-03-15 01:20:06 +00:00
|
|
|
args->devarg.flags |= DEVICE_FLAG_JTAG;
|
2010-01-04 09:34:23 +00:00
|
|
|
break;
|
|
|
|
|
2010-04-08 02:43:19 +00:00
|
|
|
case 'n':
|
2012-10-09 02:41:06 +00:00
|
|
|
args->flags |= OPT_NO_RC;
|
2010-04-08 02:43:19 +00:00
|
|
|
break;
|
|
|
|
|
2013-01-31 00:21:20 +00:00
|
|
|
case LOPT_LONG_PASSWORD:
|
2011-03-15 01:20:06 +00:00
|
|
|
args->devarg.flags |= DEVICE_FLAG_LONG_PW;
|
2010-09-17 14:04:33 +00:00
|
|
|
break;
|
|
|
|
|
2013-01-31 00:21:20 +00:00
|
|
|
case LOPT_FORCE_RESET:
|
2011-03-23 15:13:03 +00:00
|
|
|
args->devarg.flags |= DEVICE_FLAG_FORCE_RESET;
|
|
|
|
break;
|
|
|
|
|
2010-03-17 05:40:03 +00:00
|
|
|
case '?':
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("Try --help for usage information.\n");
|
2009-11-17 02:11:46 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-15 01:20:06 +00:00
|
|
|
if (want_usb && (args->devarg.flags & DEVICE_FLAG_TTY)) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("You can't simultaneously specify a serial and "
|
2010-06-28 03:13:51 +00:00
|
|
|
"a USB device.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-06-28 02:36:05 +00:00
|
|
|
if (optind >= argc) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("You need to specify a driver. Try --help for "
|
2010-06-28 02:36:05 +00:00
|
|
|
"a list.\n");
|
2010-03-17 05:40:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-06-28 02:36:05 +00:00
|
|
|
args->driver_name = argv[optind];
|
|
|
|
optind++;
|
2010-03-17 05:40:03 +00:00
|
|
|
|
2010-04-29 03:56:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-13 04:40:58 +00:00
|
|
|
int setup_driver(struct cmdline_args *args)
|
2010-04-30 04:01:03 +00:00
|
|
|
{
|
2010-06-28 02:36:05 +00:00
|
|
|
int i;
|
2010-04-30 04:01:03 +00:00
|
|
|
|
2010-06-28 02:36:05 +00:00
|
|
|
i = 0;
|
|
|
|
while (i < ARRAY_LEN(driver_table) &&
|
2011-03-15 01:56:07 +00:00
|
|
|
strcasecmp(driver_table[i]->name, args->driver_name))
|
2010-06-28 02:36:05 +00:00
|
|
|
i++;
|
|
|
|
if (i >= ARRAY_LEN(driver_table)) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("Unknown driver: %s. Try --help for a list.\n",
|
2010-06-28 02:36:05 +00:00
|
|
|
args->driver_name);
|
2010-08-13 04:40:58 +00:00
|
|
|
return -1;
|
2010-06-28 02:36:05 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 02:20:50 +00:00
|
|
|
if (stab_init() < 0)
|
2010-08-13 04:40:58 +00:00
|
|
|
return -1;
|
2010-05-01 06:34:43 +00:00
|
|
|
|
2011-03-15 01:56:07 +00:00
|
|
|
device_default = driver_table[i]->open(&args->devarg);
|
2010-08-13 00:25:28 +00:00
|
|
|
if (!device_default) {
|
2011-03-15 02:20:50 +00:00
|
|
|
stab_exit();
|
2010-08-13 04:40:58 +00:00
|
|
|
return -1;
|
2010-04-30 04:01:03 +00:00
|
|
|
}
|
|
|
|
|
2010-08-13 04:40:58 +00:00
|
|
|
return 0;
|
2010-04-30 04:01:03 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 23:02:22 +00:00
|
|
|
#ifdef __Windows__
|
2011-07-26 13:21:44 +00:00
|
|
|
static int sockets_init(void)
|
|
|
|
{
|
|
|
|
WSADATA data;
|
|
|
|
|
|
|
|
if (WSAStartup(MAKEWORD(2, 2), &data)) {
|
|
|
|
printc_err("Winsock init failed");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sockets_exit(void)
|
|
|
|
{
|
|
|
|
WSACleanup();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int sockets_init(void) { return 0; }
|
|
|
|
static void sockets_exit(void) { }
|
|
|
|
#endif
|
|
|
|
|
2010-04-29 03:56:47 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct cmdline_args args = {0};
|
|
|
|
int ret = 0;
|
|
|
|
|
2012-03-02 22:06:46 +00:00
|
|
|
setvbuf(stderr, NULL, _IOFBF, 0);
|
|
|
|
setvbuf(stdout, NULL, _IOFBF, 0);
|
|
|
|
|
2010-08-31 03:50:00 +00:00
|
|
|
opdb_reset();
|
2011-07-26 16:38:54 +00:00
|
|
|
ctrlc_init();
|
2010-04-29 03:56:47 +00:00
|
|
|
|
2011-03-15 01:20:06 +00:00
|
|
|
args.devarg.vcc_mv = 3000;
|
2011-07-18 02:56:29 +00:00
|
|
|
args.devarg.requested_serial = NULL;
|
2010-04-29 03:56:47 +00:00
|
|
|
if (parse_cmdline_args(argc, argv, &args) < 0)
|
2012-10-30 20:52:47 +00:00
|
|
|
goto fail_parse;
|
2010-04-29 03:56:47 +00:00
|
|
|
|
2012-10-09 02:42:54 +00:00
|
|
|
if (args.flags & OPT_EMBEDDED)
|
|
|
|
input_module = &input_async;
|
2012-10-09 01:52:02 +00:00
|
|
|
if (input_module->init() < 0)
|
2012-10-30 20:52:47 +00:00
|
|
|
goto fail_input;
|
2012-10-09 01:52:02 +00:00
|
|
|
|
2012-10-09 02:41:06 +00:00
|
|
|
output_set_embedded(args.flags & OPT_EMBEDDED);
|
|
|
|
|
2012-10-30 20:52:47 +00:00
|
|
|
if (sockets_init() < 0) {
|
|
|
|
ret = -1;
|
|
|
|
goto fail_sockets;
|
|
|
|
}
|
2011-07-26 13:21:44 +00:00
|
|
|
|
2010-10-28 01:08:22 +00:00
|
|
|
printc_dbg("%s\n", version_text);
|
2011-07-26 13:21:44 +00:00
|
|
|
if (setup_driver(&args) < 0) {
|
2012-10-30 20:52:47 +00:00
|
|
|
ret = -1;
|
|
|
|
goto fail_driver;
|
2011-07-26 13:21:44 +00:00
|
|
|
}
|
2010-04-21 04:56:56 +00:00
|
|
|
|
2012-08-09 03:33:56 +00:00
|
|
|
if (device_probe_id(device_default) < 0)
|
|
|
|
printc_err("warning: device ID probe failed\n");
|
|
|
|
|
2011-03-09 21:48:59 +00:00
|
|
|
simio_init();
|
|
|
|
|
2012-10-09 02:41:06 +00:00
|
|
|
if (!(args.flags & OPT_NO_RC))
|
2013-03-25 21:07:32 +00:00
|
|
|
process_rc_file(args.alt_config);
|
2009-11-17 02:11:46 +00:00
|
|
|
|
2010-01-08 05:39:07 +00:00
|
|
|
/* Process commands */
|
2009-11-17 02:34:10 +00:00
|
|
|
if (optind < argc) {
|
2010-04-08 01:15:30 +00:00
|
|
|
while (optind < argc) {
|
2010-08-13 04:40:58 +00:00
|
|
|
if (process_command(argv[optind++]) < 0) {
|
2010-04-08 01:15:30 +00:00
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-17 02:34:10 +00:00
|
|
|
} else {
|
2010-08-13 04:40:58 +00:00
|
|
|
reader_loop();
|
2009-11-17 02:34:10 +00:00
|
|
|
}
|
|
|
|
|
2011-03-09 21:48:59 +00:00
|
|
|
simio_exit();
|
2011-03-15 00:12:48 +00:00
|
|
|
device_destroy();
|
2012-10-30 20:52:47 +00:00
|
|
|
stab_exit();
|
|
|
|
fail_driver:
|
2011-07-26 13:21:44 +00:00
|
|
|
sockets_exit();
|
2012-10-30 20:52:47 +00:00
|
|
|
fail_sockets:
|
2012-10-09 01:52:02 +00:00
|
|
|
input_module->exit();
|
2012-10-30 20:52:47 +00:00
|
|
|
fail_input:
|
|
|
|
fail_parse:
|
|
|
|
|
|
|
|
/* We need to do this on Windows, because in embedded mode we
|
|
|
|
* may still have a running background thread for input. If so,
|
|
|
|
* returning from main() won't cause the process to terminate.
|
|
|
|
*/
|
|
|
|
#if defined(__Windows__) || defined(__CYGWIN__)
|
|
|
|
ExitProcess(ret);
|
|
|
|
#endif
|
2010-04-08 01:15:30 +00:00
|
|
|
return ret;
|
2009-11-16 23:52:10 +00:00
|
|
|
}
|