aboutsummaryrefslogtreecommitdiff
path: root/src/helper
diff options
context:
space:
mode:
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/Makefile.am87
-rw-r--r--src/helper/binarybuffer.c76
-rw-r--r--src/helper/binarybuffer.h4
-rw-r--r--src/helper/command.c2
-rw-r--r--src/helper/command.h6
-rw-r--r--src/helper/jep106.inc45
-rw-r--r--src/helper/log.c51
-rw-r--r--src/helper/log.h2
-rw-r--r--src/helper/options.c171
-rw-r--r--src/helper/types.h30
10 files changed, 352 insertions, 122 deletions
diff --git a/src/helper/Makefile.am b/src/helper/Makefile.am
index 64caf98..e0f7f49 100644
--- a/src/helper/Makefile.am
+++ b/src/helper/Makefile.am
@@ -1,56 +1,49 @@
-include $(top_srcdir)/common.mk
-
-METASOURCES = AUTO
-noinst_LTLIBRARIES = libhelper.la
-
-CONFIGFILES = options.c time_support_common.c
-
-libhelper_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBUSB1_CFLAGS)
-
-libhelper_la_SOURCES = \
- binarybuffer.c \
- $(CONFIGFILES) \
- configuration.c \
- log.c \
- command.c \
- time_support.c \
- replacements.c \
- fileio.c \
- util.c \
- jep106.c \
- jim-nvp.c
+noinst_LTLIBRARIES += %D%/libhelper.la
+
+%C%_libhelper_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBUSB1_CFLAGS)
+
+%C%_libhelper_la_SOURCES = \
+ %D%/binarybuffer.c \
+ %D%/options.c \
+ %D%/time_support_common.c \
+ %D%/configuration.c \
+ %D%/log.c \
+ %D%/command.c \
+ %D%/time_support.c \
+ %D%/replacements.c \
+ %D%/fileio.c \
+ %D%/util.c \
+ %D%/jep106.c \
+ %D%/jim-nvp.c \
+ %D%/binarybuffer.h \
+ %D%/configuration.h \
+ %D%/ioutil.h \
+ %D%/list.h \
+ %D%/util.h \
+ %D%/types.h \
+ %D%/log.h \
+ %D%/command.h \
+ %D%/time_support.h \
+ %D%/replacements.h \
+ %D%/fileio.h \
+ %D%/system.h \
+ %D%/jep106.h \
+ %D%/jep106.inc \
+ %D%/jim-nvp.h
if IOUTIL
-libhelper_la_SOURCES += ioutil.c
+%C%_libhelper_la_SOURCES += %D%/ioutil.c
else
-libhelper_la_SOURCES += ioutil_stubs.c
+%C%_libhelper_la_SOURCES += %D%/ioutil_stubs.c
endif
-libhelper_la_CFLAGS =
+%C%_libhelper_la_CFLAGS = $(AM_CFLAGS)
if IS_MINGW
# FD_* macros are sloppy with their signs on MinGW32 platform
-libhelper_la_CFLAGS += -Wno-sign-compare
+%C%_libhelper_la_CFLAGS += -Wno-sign-compare
endif
-noinst_HEADERS = \
- binarybuffer.h \
- configuration.h \
- ioutil.h \
- list.h \
- util.h \
- types.h \
- log.h \
- command.h \
- time_support.h \
- replacements.h \
- fileio.h \
- system.h \
- bin2char.sh \
- jep106.h \
- jep106.inc \
- update_jep106.pl \
- jim-nvp.h
-
-EXTRA_DIST = startup.tcl
-
-MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
+STARTUP_TCL_SRCS += %D%/startup.tcl
+EXTRA_DIST += \
+ %D%/bin2char.sh \
+ %D%/update_jep106.pl
diff --git a/src/helper/binarybuffer.c b/src/helper/binarybuffer.c
index c1e6322..76f657f 100644
--- a/src/helper/binarybuffer.c
+++ b/src/helper/binarybuffer.c
@@ -45,6 +45,11 @@ static const unsigned char bit_reverse_table256[] = {
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
};
+static const char hex_digits[] = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'a', 'b', 'c', 'd', 'e', 'f'
+};
+
void *buf_cpy(const void *from, void *_to, unsigned size)
{
if (NULL == from || NULL == _to)
@@ -369,31 +374,72 @@ void bit_copy_discard(struct bit_copy_queue *q)
}
}
-int unhexify(char *bin, const char *hex, int count)
+/**
+ * Convert a string of hexadecimal pairs into its binary
+ * representation.
+ *
+ * @param[out] bin Buffer to store binary representation. The buffer size must
+ * be at least @p count.
+ * @param[in] hex String with hexadecimal pairs to convert into its binary
+ * representation.
+ * @param[in] count Number of hexadecimal pairs to convert.
+ *
+ * @return The number of converted hexadecimal pairs.
+ */
+size_t unhexify(uint8_t *bin, const char *hex, size_t count)
{
- int i, tmp;
+ size_t i;
+ char tmp;
+
+ if (!bin || !hex)
+ return 0;
+
+ memset(bin, 0, count);
+
+ for (i = 0; i < 2 * count; i++) {
+ if (hex[i] >= 'a' && hex[i] <= 'f')
+ tmp = hex[i] - 'a' + 10;
+ else if (hex[i] >= 'A' && hex[i] <= 'F')
+ tmp = hex[i] - 'A' + 10;
+ else if (hex[i] >= '0' && hex[i] <= '9')
+ tmp = hex[i] - '0';
+ else
+ return i / 2;
- for (i = 0; i < count; i++) {
- if (sscanf(hex + (2 * i), "%02x", &tmp) != 1)
- return i;
- bin[i] = tmp;
+ bin[i / 2] |= tmp << (4 * ((i + 1) % 2));
}
- return i;
+ return i / 2;
}
-int hexify(char *hex, const char *bin, int count, int out_maxlen)
+/**
+ * Convert binary data into a string of hexadecimal pairs.
+ *
+ * @param[out] hex Buffer to store string of hexadecimal pairs. The buffer size
+ * must be at least @p length.
+ * @param[in] bin Buffer with binary data to convert into hexadecimal pairs.
+ * @param[in] count Number of bytes to convert.
+ * @param[in] length Maximum number of characters, including null-terminator,
+ * to store into @p hex.
+ *
+ * @returns The length of the converted string excluding null-terminator.
+ */
+size_t hexify(char *hex, const uint8_t *bin, size_t count, size_t length)
{
- int i, cmd_len = 0;
+ size_t i;
+ uint8_t tmp;
+
+ if (!length)
+ return 0;
- /* May use a length, or a null-terminated string as input. */
- if (count == 0)
- count = strlen(bin);
+ for (i = 0; i < length - 1 && i < 2 * count; i++) {
+ tmp = (bin[i / 2] >> (4 * ((i + 1) % 2))) & 0x0f;
+ hex[i] = hex_digits[tmp];
+ }
- for (i = 0; i < count; i++)
- cmd_len += snprintf(hex + cmd_len, out_maxlen - cmd_len, "%02x", bin[i] & 0xff);
+ hex[i] = 0;
- return cmd_len;
+ return i;
}
void buffer_shr(void *_buf, unsigned buf_len, unsigned count)
diff --git a/src/helper/binarybuffer.h b/src/helper/binarybuffer.h
index dd0d275..f1da8c4 100644
--- a/src/helper/binarybuffer.h
+++ b/src/helper/binarybuffer.h
@@ -234,8 +234,8 @@ void bit_copy_discard(struct bit_copy_queue *q);
/* functions to convert to/from hex encoded buffer
* used in ti-icdi driver and gdb server */
-int unhexify(char *bin, const char *hex, int count);
-int hexify(char *hex, const char *bin, int count, int out_maxlen);
+size_t unhexify(uint8_t *bin, const char *hex, size_t count);
+size_t hexify(char *hex, const uint8_t *bin, size_t count, size_t out_maxlen);
void buffer_shr(void *_buf, unsigned buf_len, unsigned count);
#endif /* OPENOCD_HELPER_BINARYBUFFER_H */
diff --git a/src/helper/command.c b/src/helper/command.c
index fc4aac7..5deaee8 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -1410,6 +1410,8 @@ DEFINE_PARSE_ULONGLONG(_u32, uint32_t, 0, UINT32_MAX)
DEFINE_PARSE_ULONGLONG(_u16, uint16_t, 0, UINT16_MAX)
DEFINE_PARSE_ULONGLONG(_u8, uint8_t, 0, UINT8_MAX)
+DEFINE_PARSE_ULONGLONG(_target_addr, target_addr_t, 0, TARGET_ADDR_MAX)
+
#define DEFINE_PARSE_LONGLONG(name, type, min, max) \
DEFINE_PARSE_WRAPPER(name, type, min, max, long long, _llong)
DEFINE_PARSE_LONGLONG(_int, int, n < INT_MIN, INT_MAX)
diff --git a/src/helper/command.h b/src/helper/command.h
index 5c39660..bd24156 100644
--- a/src/helper/command.h
+++ b/src/helper/command.h
@@ -357,10 +357,13 @@ DECLARE_PARSE_WRAPPER(_u16, uint16_t);
DECLARE_PARSE_WRAPPER(_u8, uint8_t);
DECLARE_PARSE_WRAPPER(_int, int);
+DECLARE_PARSE_WRAPPER(_s64, int64_t);
DECLARE_PARSE_WRAPPER(_s32, int32_t);
DECLARE_PARSE_WRAPPER(_s16, int16_t);
DECLARE_PARSE_WRAPPER(_s8, int8_t);
+DECLARE_PARSE_WRAPPER(_target_addr, target_addr_t);
+
/**
* @brief parses the string @a in into @a out as a @a type, or prints
* a command error and passes the error code to the caller. If an error
@@ -382,6 +385,9 @@ DECLARE_PARSE_WRAPPER(_s8, int8_t);
} \
} while (0)
+#define COMMAND_PARSE_ADDRESS(in, out) \
+ COMMAND_PARSE_NUMBER(target_addr, in, out)
+
/**
* Parse the string @c as a binary parameter, storing the boolean value
* in @c out. The strings @c on and @c off are used to match different
diff --git a/src/helper/jep106.inc b/src/helper/jep106.inc
index 1895005..c0295a6 100644
--- a/src/helper/jep106.inc
+++ b/src/helper/jep106.inc
@@ -884,7 +884,7 @@
[7][0x01 - 1] = "Siklu Communication Ltd.",
[7][0x02 - 1] = "A Force Manufacturing Ltd.",
[7][0x03 - 1] = "Strontium",
-[7][0x04 - 1] = "Abilis Systems",
+[7][0x04 - 1] = "ALi Corp (Abilis Systems)",
[7][0x05 - 1] = "Siglead, Inc.",
[7][0x06 - 1] = "Ubicom, Inc.",
[7][0x07 - 1] = "Unifosa Corporation",
@@ -893,7 +893,7 @@
[7][0x0a - 1] = "Visipro.",
[7][0x0b - 1] = "EKMemory",
[7][0x0c - 1] = "Microelectronics Institute ZTE",
-[7][0x0d - 1] = "Cognovo Ltd.",
+[7][0x0d - 1] = "u-blox AG",
[7][0x0e - 1] = "Carry Technology Co. Ltd.",
[7][0x0f - 1] = "Nokia",
[7][0x10 - 1] = "King Tiger Technology",
@@ -1101,12 +1101,12 @@
[8][0x5c - 1] = "Vitesse Enterprise Co.",
[8][0x5d - 1] = "Foxtronn International Corporation",
[8][0x5e - 1] = "Bretelon Inc.",
-[8][0x5f - 1] = "Zbit Semiconductor, Inc.",
+[8][0x5f - 1] = "Graphcore",
[8][0x60 - 1] = "Eoplex Inc",
[8][0x61 - 1] = "MaxLinear, Inc.",
[8][0x62 - 1] = "ETA Devices",
[8][0x63 - 1] = "LOKI",
-[8][0x64 - 1] = "IMS Semiconductor Co., Ltd",
+[8][0x64 - 1] = "IMS Electronics Co., Ltd.",
[8][0x65 - 1] = "Dosilicon Co., Ltd.",
[8][0x66 - 1] = "Dolphin Integration",
[8][0x67 - 1] = "Shenzhen Mic Electronics Technology",
@@ -1116,4 +1116,41 @@
[8][0x6b - 1] = "Kingred Electronic Technology Ltd.",
[8][0x6c - 1] = "Chao Yue Zhuo Computer Business Dept.",
[8][0x6d - 1] = "Guangzhou Si Nuo Electronic Technology.",
+[8][0x6e - 1] = "Crocus Technology Inc.",
+[8][0x6f - 1] = "Creative Chips GmbH",
+[8][0x70 - 1] = "GE Aviation Systems LLC.",
+[8][0x71 - 1] = "Asgard",
+[8][0x72 - 1] = "Good Wealth Technology Ltd.",
+[8][0x73 - 1] = "TriCor Technologies",
+[8][0x74 - 1] = "Nova-Systems GmbH",
+[8][0x75 - 1] = "JUHOR",
+[8][0x76 - 1] = "Zhuhai Douke Commerce Co. Ltd.",
+[8][0x77 - 1] = "DSL Memory",
+[8][0x78 - 1] = "Anvo-Systems Dresden GmbH",
+[8][0x79 - 1] = "Realtek",
+[8][0x7a - 1] = "AltoBeam",
+[8][0x7b - 1] = "Wave Computing",
+[8][0x7c - 1] = "Beijing TrustNet Technology Co. Ltd.",
+[8][0x7d - 1] = "Innovium, Inc.",
+[8][0x7e - 1] = "Starsway Technology Limited",
+[9][0x01 - 1] = "Weltronics Co. LTD",
+[9][0x02 - 1] = "VMware, Inc.",
+[9][0x03 - 1] = "Hewlett Packard Enterprise",
+[9][0x04 - 1] = "INTENSO",
+[9][0x05 - 1] = "Puya Semiconductor",
+[9][0x06 - 1] = "MEMORFI",
+[9][0x07 - 1] = "MSC Technologies GmbH",
+[9][0x08 - 1] = "Txrui",
+[9][0x09 - 1] = "SiFive, Inc.",
+[9][0x0a - 1] = "Spreadtrum Communications",
+[9][0x0b - 1] = "Paragon Technology (Shenzhen) Ltd.",
+[9][0x0c - 1] = "UMAX Technology",
+[9][0x0d - 1] = "Shenzhen Yong Sheng Technology",
+[9][0x0e - 1] = "SNOAMOO (Shenzhen Kai Zhuo Yue)",
+[9][0x0f - 1] = "Daten Tecnologia LTDA",
+[9][0x10 - 1] = "Shenzhen XinRuiYan Electronics",
+[9][0x11 - 1] = "Eta Compute",
+[9][0x12 - 1] = "Energous",
+[9][0x13 - 1] = "Raspberry Pi Trading Ltd.",
+[9][0x14 - 1] = "Shenzhen Chixingzhe Tech Co. Ltd.",
/* EOF */
diff --git a/src/helper/log.c b/src/helper/log.c
index e33f869..d4e87f6 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -191,6 +191,30 @@ void log_printf(enum log_levels level,
va_end(ap);
}
+void log_vprintf_lf(enum log_levels level, const char *file, unsigned line,
+ const char *function, const char *format, va_list args)
+{
+ char *tmp;
+
+ count++;
+
+ if (level > debug_level)
+ return;
+
+ tmp = alloc_vprintf(format, args);
+
+ if (!tmp)
+ return;
+
+ /*
+ * Note: alloc_vprintf() guarantees that the buffer is at least one
+ * character longer.
+ */
+ strcat(tmp, "\n");
+ log_puts(level, file, line, function, tmp);
+ free(tmp);
+}
+
void log_printf_lf(enum log_levels level,
const char *file,
unsigned line,
@@ -198,23 +222,10 @@ void log_printf_lf(enum log_levels level,
const char *format,
...)
{
- char *string;
va_list ap;
- count++;
- if (level > debug_level)
- return;
-
va_start(ap, format);
-
- string = alloc_vprintf(format, ap);
- if (string != NULL) {
- strcat(string, "\n"); /* alloc_vprintf guaranteed the buffer to be at least one
- *char longer */
- log_puts(level, file, line, function, string);
- free(string);
- }
-
+ log_vprintf_lf(level, file, line, function, format, ap);
va_end(ap);
}
@@ -240,9 +251,15 @@ COMMAND_HANDLER(handle_log_output_command)
{
if (CMD_ARGC == 1) {
FILE *file = fopen(CMD_ARGV[0], "w");
-
- if (file)
- log_output = file;
+ if (file == NULL) {
+ LOG_ERROR("failed to open output log '%s'", CMD_ARGV[0]);
+ return ERROR_FAIL;
+ }
+ if (log_output != stderr && log_output != NULL) {
+ /* Close previous log file, if it was open and wasn't stderr. */
+ fclose(log_output);
+ }
+ log_output = file;
}
return ERROR_OK;
diff --git a/src/helper/log.h b/src/helper/log.h
index eb222cb..6b93816 100644
--- a/src/helper/log.h
+++ b/src/helper/log.h
@@ -60,6 +60,8 @@ enum log_levels {
void log_printf(enum log_levels level, const char *file, unsigned line,
const char *function, const char *format, ...)
__attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 5, 6)));
+void log_vprintf_lf(enum log_levels level, const char *file, unsigned line,
+ const char *function, const char *format, va_list args);
void log_printf_lf(enum log_levels level, const char *file, unsigned line,
const char *function, const char *format, ...)
__attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 5, 6)));
diff --git a/src/helper/options.c b/src/helper/options.c
index b7db10f..1cfa553 100644
--- a/src/helper/options.c
+++ b/src/helper/options.c
@@ -29,6 +29,15 @@
#include <getopt.h>
+#include <limits.h>
+#include <stdlib.h>
+#if IS_DARWIN
+#include <libproc.h>
+#endif
+#ifdef HAVE_SYS_SYSCTL_H
+#include <sys/sysctl.h>
+#endif
+
static int help_flag, version_flag;
static const struct option long_options[] = {
@@ -50,52 +59,129 @@ int configuration_output_handler(struct command_context *context, const char *li
return ERROR_OK;
}
-#ifdef _WIN32
-static char *find_suffix(const char *text, const char *suffix)
+/* Return the canonical path to the directory the openocd executable is in.
+ * The path should be absolute, use / as path separator and have all symlinks
+ * resolved. The returned string is malloc'd. */
+static char *find_exe_path(void)
{
- size_t text_len = strlen(text);
- size_t suffix_len = strlen(suffix);
+ char *exepath = NULL;
- if (suffix_len == 0)
- return (char *)text + text_len;
+ do {
+#if IS_WIN32 && !IS_CYGWIN
+ exepath = malloc(MAX_PATH);
+ if (exepath == NULL)
+ break;
+ GetModuleFileName(NULL, exepath, MAX_PATH);
- if (suffix_len > text_len || strncmp(text + text_len - suffix_len, suffix, suffix_len) != 0)
- return NULL; /* Not a suffix of text */
+ /* Convert path separators to UNIX style, should work on Windows also. */
+ for (char *p = exepath; *p; p++) {
+ if (*p == '\\')
+ *p = '/';
+ }
- return (char *)text + text_len - suffix_len;
-}
+#elif IS_DARWIN
+ exepath = malloc(PROC_PIDPATHINFO_MAXSIZE);
+ if (exepath == NULL)
+ break;
+ if (proc_pidpath(getpid(), exepath, PROC_PIDPATHINFO_MAXSIZE) <= 0) {
+ free(exepath);
+ exepath = NULL;
+ }
+
+#elif defined(CTL_KERN) && defined(KERN_PROC) && defined(KERN_PROC_PATHNAME) /* *BSD */
+#ifndef PATH_MAX
+#define PATH_MAX 1024
#endif
+ char *path = malloc(PATH_MAX);
+ if (path == NULL)
+ break;
+ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
+ size_t size = PATH_MAX;
-static void add_default_dirs(void)
-{
- const char *run_prefix;
- char *path;
+ if (sysctl(mib, (u_int)ARRAY_SIZE(mib), path, &size, NULL, 0) != 0)
+ break;
-#ifdef _WIN32
- char strExePath[MAX_PATH];
- GetModuleFileName(NULL, strExePath, MAX_PATH);
+#ifdef HAVE_REALPATH
+ exepath = realpath(path, NULL);
+ free(path);
+#else
+ exepath = path;
+#endif
- /* Strip executable file name, leaving path */
- *strrchr(strExePath, '\\') = '\0';
+#elif defined(HAVE_REALPATH) /* Assume POSIX.1-2008 */
+ /* Try Unices in order of likelihood. */
+ exepath = realpath("/proc/self/exe", NULL); /* Linux/Cygwin */
+ if (exepath == NULL)
+ exepath = realpath("/proc/self/path/a.out", NULL); /* Solaris */
+ if (exepath == NULL)
+ exepath = realpath("/proc/curproc/file", NULL); /* FreeBSD (Should be covered above) */
+#endif
+ } while (0);
+
+ if (exepath != NULL) {
+ /* Strip executable file name, leaving path */
+ *strrchr(exepath, '/') = '\0';
+ } else {
+ LOG_WARNING("Could not determine executable path, using configured BINDIR.");
+ LOG_DEBUG("BINDIR = %s", BINDIR);
+#ifdef HAVE_REALPATH
+ exepath = realpath(BINDIR, NULL);
+#else
+ exepath = strdup(BINDIR);
+#endif
+ }
+
+ return exepath;
+}
+
+static char *find_relative_path(const char *from, const char *to)
+{
+ size_t i;
- /* Convert path separators to UNIX style, should work on Windows also. */
- for (char *p = strExePath; *p; p++) {
- if (*p == '\\')
- *p = '/';
+ /* Skip common /-separated parts of from and to */
+ i = 0;
+ for (size_t n = 0; from[n] == to[n]; n++) {
+ if (from[n] == '\0') {
+ i = n;
+ break;
+ }
+ if (from[n] == '/')
+ i = n + 1;
+ }
+ from += i;
+ to += i;
+
+ /* Count number of /-separated non-empty parts of from */
+ i = 0;
+ while (from[0] != '\0') {
+ if (from[0] != '/')
+ i++;
+ char *next = strchr(from, '/');
+ if (next == NULL)
+ break;
+ from = next + 1;
}
- char *end_of_prefix = find_suffix(strExePath, BINDIR);
- if (end_of_prefix != NULL)
- *end_of_prefix = '\0';
+ /* Prepend that number of ../ in front of to */
+ char *relpath = malloc(i * 3 + strlen(to) + 1);
+ relpath[0] = '\0';
+ for (size_t n = 0; n < i; n++)
+ strcat(relpath, "../");
+ strcat(relpath, to);
- run_prefix = strExePath;
-#else
- run_prefix = "";
-#endif
+ return relpath;
+}
+
+static void add_default_dirs(void)
+{
+ char *path;
+ char *exepath = find_exe_path();
+ char *bin2data = find_relative_path(BINDIR, PKGDATADIR);
LOG_DEBUG("bindir=%s", BINDIR);
LOG_DEBUG("pkgdatadir=%s", PKGDATADIR);
- LOG_DEBUG("run_prefix=%s", run_prefix);
+ LOG_DEBUG("exepath=%s", exepath);
+ LOG_DEBUG("bin2data=%s", bin2data);
/*
* The directory containing OpenOCD-supplied scripts should be
@@ -129,17 +215,20 @@ static void add_default_dirs(void)
}
#endif
- path = alloc_printf("%s%s%s", run_prefix, PKGDATADIR, "/site");
+ path = alloc_printf("%s/%s/%s", exepath, bin2data, "site");
if (path) {
add_script_search_dir(path);
free(path);
}
- path = alloc_printf("%s%s%s", run_prefix, PKGDATADIR, "/scripts");
+ path = alloc_printf("%s/%s/%s", exepath, bin2data, "scripts");
if (path) {
add_script_search_dir(path);
free(path);
}
+
+ free(exepath);
+ free(bin2data);
}
int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[])
@@ -178,8 +267,10 @@ int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[])
case 'd': /* --debug | -d */
{
char *command = alloc_printf("debug_level %s", optarg ? optarg : "3");
- command_run_line(cmd_ctx, command);
+ int retval = command_run_line(cmd_ctx, command);
free(command);
+ if (retval != ERROR_OK)
+ return retval;
break;
}
case 'l': /* --log_output | -l */
@@ -200,16 +291,26 @@ int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[])
LOG_WARNING("deprecated option: -p/--pipe. Use '-c \"gdb_port pipe; "
"log_output openocd.log\"' instead.");
break;
+ default: /* '?' */
+ /* getopt will emit an error message, all we have to do is bail. */
+ return ERROR_FAIL;
}
}
+ if (optind < argc) {
+ /* Catch extra arguments on the command line. */
+ LOG_OUTPUT("Unexpected command line argument: %s\n", argv[optind]);
+ return ERROR_FAIL;
+ }
+
if (help_flag) {
LOG_OUTPUT("Open On-Chip Debugger\nLicensed under GNU GPL v2\n");
LOG_OUTPUT("--help | -h\tdisplay this help\n");
LOG_OUTPUT("--version | -v\tdisplay OpenOCD version\n");
LOG_OUTPUT("--file | -f\tuse configuration file <name>\n");
LOG_OUTPUT("--search | -s\tdir to search for config files and scripts\n");
- LOG_OUTPUT("--debug | -d\tset debug level <0-3>\n");
+ LOG_OUTPUT("--debug | -d\tset debug level to 3\n");
+ LOG_OUTPUT(" | -d<n>\tset debug level to <level>\n");
LOG_OUTPUT("--log_output | -l\tredirect log output to file <name>\n");
LOG_OUTPUT("--command | -c\trun <command>\n");
exit(-1);
diff --git a/src/helper/types.h b/src/helper/types.h
index 1854ba8..58c9e72 100644
--- a/src/helper/types.h
+++ b/src/helper/types.h
@@ -296,14 +296,21 @@ static inline int parity_u32(uint32_t x)
*/
#if !defined(_STDINT_H)
-#define PRIx32 "x"
#define PRId32 "d"
-#define SCNx32 "x"
#define PRIi32 "i"
+#define PRIo32 "o"
#define PRIu32 "u"
+#define PRIx32 "x"
+#define PRIX32 "X"
+#define SCNx32 "x"
#define PRId8 PRId32
#define SCNx64 "llx"
+#define PRId64 "lld"
+#define PRIi64 "lli"
+#define PRIo64 "llo"
+#define PRIu64 "llu"
#define PRIx64 "llx"
+#define PRIX64 "llX"
typedef CYG_ADDRWORD intptr_t;
typedef int64_t intmax_t;
@@ -337,4 +344,23 @@ typedef uint64_t uintmax_t;
#endif
+#if BUILD_TARGET64
+typedef uint64_t target_addr_t;
+#define TARGET_ADDR_MAX UINT64_MAX
+#define TARGET_PRIdADDR PRId64
+#define TARGET_PRIuADDR PRIu64
+#define TARGET_PRIoADDR PRIo64
+#define TARGET_PRIxADDR PRIx64
+#define TARGET_PRIXADDR PRIX64
+#else
+typedef uint32_t target_addr_t;
+#define TARGET_ADDR_MAX UINT32_MAX
+#define TARGET_PRIdADDR PRId32
+#define TARGET_PRIuADDR PRIu32
+#define TARGET_PRIoADDR PRIo32
+#define TARGET_PRIxADDR PRIx32
+#define TARGET_PRIXADDR PRIX32
+#endif
+#define TARGET_ADDR_FMT "0x%8.8" TARGET_PRIxADDR
+
#endif /* OPENOCD_HELPER_TYPES_H */