1 /***************************************************************************
2 * Copyright (C) 2004, 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * Copyright (C) 2007,2008 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
27 #include "configuration.h"
28 // @todo the inclusion of server.h here is a layering violation
33 static int help_flag
, version_flag
;
35 static const struct option long_options
[] =
37 {"help", no_argument
, &help_flag
, 1},
38 {"version", no_argument
, &version_flag
, 1},
39 {"debug", optional_argument
, 0, 'd'},
40 {"file", required_argument
, 0, 'f'},
41 {"search", required_argument
, 0, 's'},
42 {"log_output", required_argument
, 0, 'l'},
43 {"command", required_argument
, 0, 'c'},
44 {"pipe", no_argument
, 0, 'p'},
48 int configuration_output_handler(struct command_context
*context
, const char* line
)
50 LOG_USER_N("%s", line
);
55 static void add_default_dirs(void)
58 /* Add the parent of the directory where openocd.exe resides to the
59 * config script search path.
63 * event\at91eb40a_reset.cfg
64 * target\at91eb40a.cfg
67 char strExePath
[MAX_PATH
];
68 GetModuleFileName (NULL
, strExePath
, MAX_PATH
);
69 /* Either this code will *always* work or it will SEGFAULT giving
70 * excellent information on the culprit.
72 *strrchr(strExePath
, '\\') = 0;
73 strcat(strExePath
, "\\..");
74 add_script_search_dir(strExePath
);
77 * Add support for the default (as of 20080121) layout when
78 * using autotools and cygwin to build native MinGW binary.
79 * Path separator is converted to UNIX style so that MinGW is
83 * lib/openocd/event/at91eb40a_reset.cfg
84 * lib/openocd/target/at91eb40a.cfg
87 char strExePath
[MAX_PATH
];
89 GetModuleFileName (NULL
, strExePath
, MAX_PATH
);
90 *strrchr(strExePath
, '\\') = 0;
91 strcat(strExePath
, "/../lib/"PACKAGE
);
92 for (p
= strExePath
; *p
; p
++) {
96 add_script_search_dir(strExePath
);
100 * The directory containing OpenOCD-supplied scripts should be
101 * listed last in the built-in search order, so the user can
102 * override these scripts with site-specific customizations.
104 /// @todo Implement @c add_script_search_dir("${HOME}/.openocd").
105 add_script_search_dir(PKGDATADIR
"/site");
106 add_script_search_dir(PKGDATADIR
"/scripts");
110 int parse_cmdline_args(struct command_context
*cmd_ctx
, int argc
, char *argv
[])
113 char command_buffer
[128];
117 /* getopt_long stores the option index here. */
118 int option_index
= 0;
120 c
= getopt_long(argc
, argv
, "hvd::l:f:s:c:p", long_options
, &option_index
);
122 /* Detect the end of the options. */
130 case 'h': /* --help | -h */
133 case 'v': /* --version | -v */
136 case 'f': /* --file | -f */
138 snprintf(command_buffer
, 128, "script {%s}", optarg
);
139 add_config_command(command_buffer
);
142 case 's': /* --search | -s */
143 add_script_search_dir(optarg
);
145 case 'd': /* --debug | -d */
147 snprintf(command_buffer
, 128, "debug_level %s", optarg
);
149 snprintf(command_buffer
, 128, "debug_level 3");
150 command_run_line(cmd_ctx
, command_buffer
);
152 case 'l': /* --log_output | -l */
155 snprintf(command_buffer
, 128, "log_output %s", optarg
);
156 command_run_line(cmd_ctx
, command_buffer
);
159 case 'c': /* --command | -c */
162 add_config_command(optarg
);
165 case 'p': /* --pipe | -p */
166 #if BUILD_ECOSBOARD == 1
167 /* pipes unsupported on hosted platforms */
168 LOG_WARNING("pipes not supported on this platform");
170 server_use_pipes
= 1;
178 LOG_OUTPUT("Open On-Chip Debugger\n(c) 2005-2008 by Dominic Rath\n\n");
179 LOG_OUTPUT("--help | -h\tdisplay this help\n");
180 LOG_OUTPUT("--version | -v\tdisplay OpenOCD version\n");
181 LOG_OUTPUT("--file | -f\tuse configuration file <name>\n");
182 LOG_OUTPUT("--search | -s\tdir to search for config files and scripts\n");
183 LOG_OUTPUT("--debug | -d\tset debug level <0-3>\n");
184 LOG_OUTPUT("--log_output | -l\tredirect log output to file <name>\n");
185 LOG_OUTPUT("--command | -c\trun <command>\n");
186 LOG_OUTPUT("--pipe | -p\tuse pipes for gdb communication\n");
192 /* Nothing to do, version gets printed automatically. */
193 // It is not an error to request the VERSION number.
197 /* paths specified on the command line take precedence over these