This is an automated email from Gerrit. Tomasz CEDRO ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/1030
-- gerrit commit 62925effa103f314f889487cbdf451c601440fbd Author: Tomek CEDRO <[email protected]> Date: Sun Nov 11 18:18:12 2012 +0100 Bigger updates in Transport infrastructure - functions renames to contain more consistent prefix oocd_transport_, source code updates that was depending on these functions. IMPORTANT: existing suspicious SWD implementation transport was renamed to OLDSWD so if you want to use old swd drivers please rename your transport to oldswd, it will be removed when transport work is finished." Change-Id: Id1d6724f7e57a237f4662f2cdf7b9278ac8712b5 Signed-off-by: Tomek CEDRO <[email protected]> diff --git a/src/Makefile.am b/src/Makefile.am index f449677..863b111 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -92,7 +92,7 @@ libopenocd_la_LIBADD = \ $(top_builddir)/src/svf/libsvf.la \ $(top_builddir)/src/pld/libpld.la \ $(top_builddir)/src/jtag/libjtag.la \ - $(top_builddir)/src/transport/libtransport.la \ + $(top_builddir)/src/transport/liboocdtransport.la \ $(top_builddir)/src/interface/liboocdinterface.la \ $(top_builddir)/src/flash/libflash.la \ $(top_builddir)/src/target/libtarget.la \ diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index afce288..cdc8784 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -12,6 +12,9 @@ * Copyright (C) 2009 Zachary T Welch * * [email protected] * * * + * Copyright (C) 2011-2012 Tomasz Boleslaw CEDRO * + * [email protected], http://www.tomek.cedro.info * + * * * 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 * @@ -97,11 +100,11 @@ COMMAND_HANDLER(interface_transport_command) char **transports; int retval; - retval = CALL_COMMAND_HANDLER(transport_list_parse, &transports); + retval = CALL_COMMAND_HANDLER(oocd_transport_list_parse, &transports); if (retval != ERROR_OK) return retval; - retval = allow_transports(CMD_CTX, (const char **)transports); + retval = oocd_transport_allow(CMD_CTX, (const char **)transports); if (retval != ERROR_OK) { for (unsigned i = 0; transports[i]; i++) @@ -160,7 +163,7 @@ COMMAND_HANDLER(handle_interface_command) LOG_WARNING("Adapter driver '%s' did not declare " "which transports it allows; assuming " "legacy JTAG-only", jtag_interface->name); - retval = allow_transports(CMD_CTX, jtag_interface->transports + retval = oocd_transport_allow(CMD_CTX, jtag_interface->transports ? jtag_interface->transports : jtag_only); if (ERROR_OK != retval) return retval; diff --git a/src/jtag/core.c b/src/jtag/core.c index 5d5803a..4066a3f 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -1362,11 +1362,11 @@ int adapter_init(struct command_context *cmd_ctx) * transports they allow. Until they all do so, assume * the legacy drivers are JTAG-only */ - if (!transports_are_declared()) { + if (!oocd_transport_declared()) { LOG_ERROR("Adapter driver '%s' did not declare " "which transports it allows; assuming " "JTAG-only", jtag->name); - retval = allow_transports(cmd_ctx, jtag_only); + retval = oocd_transport_allow(cmd_ctx, jtag_only); if (retval != ERROR_OK) return retval; } @@ -1774,7 +1774,7 @@ static int jtag_select(struct command_context *ctx) return xsvf_register_commands(ctx); } -static struct transport jtag_transport = { +oocd_transport_t jtag_transport = { .name = "jtag", .select = jtag_select, .init = jtag_init, @@ -1783,7 +1783,7 @@ static struct transport jtag_transport = { static void jtag_constructor(void) __attribute__((constructor)); static void jtag_constructor(void) { - transport_register(&jtag_transport); + oocd_transport_register(&jtag_transport); } /** Returns true if the current debug session @@ -1791,7 +1791,7 @@ static void jtag_constructor(void) */ bool transport_is_jtag(void) { - return get_current_transport() == &jtag_transport; + return oocd_transport_current_get() == &jtag_transport; } void adapter_assert_reset(void) @@ -1803,9 +1803,9 @@ void adapter_assert_reset(void) jtag_add_reset(0, 1); } else if (transport_is_swd()) swd_add_reset(1); - else if (get_current_transport() != NULL) + else if (oocd_transport_current_get() != NULL) LOG_ERROR("reset is not supported on %s", - get_current_transport()->name); + oocd_transport_current_get()->name); else LOG_ERROR("transport is not selected"); } @@ -1816,9 +1816,9 @@ void adapter_deassert_reset(void) jtag_add_reset(0, 0); else if (transport_is_swd()) swd_add_reset(0); - else if (get_current_transport() != NULL) + else if (oocd_transport_current_get() != NULL) LOG_ERROR("reset is not supported on %s", - get_current_transport()->name); + oocd_transport_current_get()->name); else LOG_ERROR("transport is not selected"); } diff --git a/src/jtag/interface.h b/src/jtag/interface.h index 5d221da..025be46 100644 --- a/src/jtag/interface.h +++ b/src/jtag/interface.h @@ -32,6 +32,7 @@ #include <jtag/jtag.h> #include <interface/interface.h> +#include <transport/transport.h> /* @file * The "Cable Helper API" is what the cable drivers can use to help @@ -315,10 +316,8 @@ struct jtag_interface { */ int (*srst_asserted)(int *srst_asserted); - /** Functions below are for other transports than JTAG, PoC code. */ - /** current transport */ - struct transport *transport; + oocd_transport_t *transport; /** * Generic bitstream transfer from/into interface and char bits array. diff --git a/src/openocd.c b/src/openocd.c index 54f9f85..f093077 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -239,7 +239,7 @@ struct command_context *setup_command_handler(Jim_Interp *interp) &server_register_commands, &gdb_register_commands, &log_register_commands, - &transport_register_commands, + &oocd_transport_register_commands, &interface_register_commands, &oocd_interface_signal_register_commands, &oocd_interface_bitbang_register_commands, diff --git a/src/target/adi_v5_swd.c b/src/target/adi_v5_swd.c index ba3c487..a40d80c 100644 --- a/src/target/adi_v5_swd.c +++ b/src/target/adi_v5_swd.c @@ -54,7 +54,6 @@ #include <helper/time_support.h> #include <transport/transport.h> -#include <jtag/interface.h> #include <jtag/swd.h> @@ -339,8 +338,8 @@ static int swd_init(struct command_context *ctx) } -static struct transport swd_transport = { - .name = "swd", +oocd_transport_t swd_transport = { + .name = "oldswd", .select = swd_select, .init = swd_init, }; @@ -348,7 +347,7 @@ static struct transport swd_transport = { static void swd_constructor(void) __attribute__((constructor)); static void swd_constructor(void) { - transport_register(&swd_transport); + oocd_transport_register(&swd_transport); } /** Returns true if the current debug session @@ -356,5 +355,5 @@ static void swd_constructor(void) */ bool transport_is_swd(void) { - return get_current_transport() == &swd_transport; + return oocd_transport_current_get() == &swd_transport; } diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 7c6224a..faed759 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -1,8 +1,7 @@ include $(top_srcdir)/common.mk -#METASOURCES = AUTO -noinst_LTLIBRARIES = libtransport.la -libtransport_la_SOURCES = \ +noinst_LTLIBRARIES = liboocdtransport.la +liboocdtransport_la_SOURCES = \ transport.c noinst_HEADERS = \ diff --git a/src/transport/transport.c b/src/transport/transport.c index 2f35965..eca85d6 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -1,6 +1,9 @@ /* * Copyright (c) 2010 by David Brownell * + * Copyright (C) 2011-2012 Tomasz Boleslaw CEDRO + * [email protected], http://www.tomek.cedro.info + * * 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 @@ -54,28 +57,28 @@ extern struct command_context *global_cmd_ctx; */ /** List of transports known to OpenOCD. */ -static struct transport *transport_list; +oocd_transport_t *oocd_transport_list_all; /** * NULL-terminated Vector of names of transports which the * currently selected debug adapter supports. This is declared * by the time that adapter is fully set up. */ -static const char **allowed_transports; +static const char **oocd_transport_list_allowed; /** * The transport being used for the current OpenOCD session. */ -static struct transport *session; +oocd_transport_t *session; -static int transport_select(struct command_context *ctx, const char *name) +int oocd_transport_select(struct command_context *ctx, const char *name) { + LOG_INFO("TRANSPORT SELECT: %s", name); /* name may only identify a known transport; * caller guarantees session's transport isn't yet set.*/ - for (struct transport *t = transport_list; t; t = t->next) { + for (oocd_transport_t *t = oocd_transport_list_all; t; t = t->next) { if (strcmp(t->name, name) == 0) { int retval = t->select(ctx); - /* select() registers commands specific to this - * transport, and may also reset the link, e.g. - * forcing it to JTAG or SWD mode. + /* select() registers commands specific to this transport. + * init() will make hardware talk and initialize the target. */ if (retval == ERROR_OK) session = t; @@ -94,7 +97,7 @@ static int transport_select(struct command_context *ctx, const char *name) * to declare the set of transports supported by an adapter. When * there is only one member of that set, it is automatically selected. */ -int allow_transports(struct command_context *ctx, const char **vector) +int oocd_transport_allow(struct command_context *ctx, const char **vector) { /* NOTE: caller is required to provide only a list * of *valid* transport names @@ -106,17 +109,17 @@ int allow_transports(struct command_context *ctx, const char **vector) * of one transport; C code should be definitive about what * can be used when all goes well. */ - if (allowed_transports != NULL || session) { + if (oocd_transport_list_allowed != NULL || session) { LOG_ERROR("Can't modify the set of allowed transports."); return ERROR_FAIL; } - allowed_transports = vector; + oocd_transport_list_allowed = vector; /* autoselect if there's no choice ... */ if (!vector[1]) { LOG_INFO("only one transport option; autoselect '%s'", vector[0]); - return transport_select(ctx, vector[0]); + return oocd_transport_select(ctx, vector[0]); } return ERROR_OK; @@ -125,11 +128,11 @@ int allow_transports(struct command_context *ctx, const char **vector) /** * Used to verify corrrect adapter driver initialization. * - * @returns true iff the adapter declared one or more transports. + * @returns true if the adapter declared one or more transports. */ -bool transports_are_declared(void) +bool oocd_transport_declared(void) { - return allowed_transports != NULL; + return oocd_transport_list_allowed != NULL; } /** @@ -147,11 +150,12 @@ bool transports_are_declared(void) * * @returns ERROR_OK on success, else a fault code. */ -int transport_register(struct transport *new_transport) +int oocd_transport_register(oocd_transport_t *new_transport) { - struct transport *t; + oocd_transport_t *t; + printf("TRANSPORT REGISTER: %s\n", new_transport->name); - for (t = transport_list; t; t = t->next) { + for (t = oocd_transport_list_all; t; t = t->next) { if (strcmp(t->name, new_transport->name) == 0) { LOG_ERROR("transport name already used"); return ERROR_FAIL; @@ -162,8 +166,8 @@ int transport_register(struct transport *new_transport) LOG_ERROR("invalid transport %s", new_transport->name); /* splice this into the list */ - new_transport->next = transport_list; - transport_list = new_transport; + new_transport->next = oocd_transport_list_all; + oocd_transport_list_all = new_transport; LOG_DEBUG("register '%s'", new_transport->name); return ERROR_OK; @@ -175,7 +179,7 @@ int transport_register(struct transport *new_transport) * * @returns handle to the read-only transport entity. */ -struct transport *get_current_transport(void) +oocd_transport_t *oocd_transport_current_get(void) { /* REVISIT -- constify */ return session; @@ -194,7 +198,7 @@ struct transport *get_current_transport(void) * @param vector where the resulting copy is stored, as an argv-style * NULL-terminated vector. */ -COMMAND_HELPER(transport_list_parse, char ***vector) +COMMAND_HELPER(oocd_transport_list_parse, char ***vector) { char **argv; unsigned n = CMD_ARGC; @@ -211,9 +215,9 @@ COMMAND_HELPER(transport_list_parse, char ***vector) return ERROR_FAIL; for (unsigned i = 0; i < n; i++) { - struct transport *t; + oocd_transport_t *t; - for (t = transport_list; t; t = t->next) { + for (t = oocd_transport_list_all; t; t = t->next) { if (strcmp(t->name, CMD_ARGV[i]) != 0) continue; argv[j++] = strdup(CMD_ARGV[i]); @@ -235,14 +239,14 @@ fail: return ERROR_FAIL; } -COMMAND_HANDLER(handle_transport_init) +COMMAND_HANDLER(handle_oocd_transport_init) { LOG_DEBUG("%s", __func__); if (!session) { LOG_ERROR("session's transport is not selected."); /* no session transport configured, print transports then fail */ - const char **vector = allowed_transports; + const char **vector = oocd_transport_list_allowed; while (*vector) { LOG_ERROR("allow transport '%s'", *vector); vector++; @@ -253,14 +257,14 @@ COMMAND_HANDLER(handle_transport_init) return session->init(CMD_CTX); } -COMMAND_HANDLER(handle_transport_list) +COMMAND_HANDLER(handle_oocd_transport_list) { if (CMD_ARGC != 0) return ERROR_COMMAND_SYNTAX_ERROR; command_print(CMD_CTX, "The following transports are available:"); - for (struct transport *t = transport_list; t; t = t->next) + for (oocd_transport_t *t = oocd_transport_list_all; t; t = t->next) command_print(CMD_CTX, "\t%s", t->name); return ERROR_OK; @@ -272,7 +276,7 @@ COMMAND_HANDLER(handle_transport_list) * set supported by the debug adapter being used. Return value * is scriptable (allowing "if swd then..." etc). */ -static int jim_transport_select(Jim_Interp *interp, int argc, Jim_Obj * const *argv) +int oocd_transport_select_jim(Jim_Interp *interp, int argc, Jim_Obj * const *argv) { switch (argc) { case 1: /* return/display */ @@ -297,15 +301,15 @@ static int jim_transport_select(Jim_Interp *interp, int argc, Jim_Obj * const *a * NOTE: requires adapter to have been set up, with * transports declared via C. */ - if (!allowed_transports) { + if (!oocd_transport_list_allowed) { LOG_ERROR("Debug adapter doesn't support any transports?"); return JIM_ERR; } - for (unsigned i = 0; allowed_transports[i]; i++) { + for (unsigned i = 0; oocd_transport_list_allowed[i]; i++) { - if (strcmp(allowed_transports[i], argv[1]->bytes) == 0) - return transport_select(global_cmd_ctx, argv[1]->bytes); + if (strcmp(oocd_transport_list_allowed[i], argv[1]->bytes) == 0) + return oocd_transport_select(global_cmd_ctx, argv[1]->bytes); } LOG_ERROR("Debug adapter doesn't support '%s' transport", argv[1]->bytes); @@ -317,10 +321,10 @@ static int jim_transport_select(Jim_Interp *interp, int argc, Jim_Obj * const *a } } -static const struct command_registration transport_commands[] = { +static const struct command_registration oocd_transport_commands[] = { { .name = "init", - .handler = handle_transport_init, + .handler = handle_oocd_transport_init, /* this would be COMMAND_CONFIG ... except that * it needs to trigger event handlers that may * require COMMAND_EXEC ... @@ -331,14 +335,14 @@ static const struct command_registration transport_commands[] = { }, { .name = "list", - .handler = handle_transport_list, + .handler = handle_oocd_transport_list, .mode = COMMAND_ANY, .help = "list all built-in transports", .usage = "" }, { .name = "select", - .jim_handler = jim_transport_select, + .jim_handler = oocd_transport_select_jim, .mode = COMMAND_ANY, .help = "Select this session's transport", .usage = "[transport_name]", @@ -346,18 +350,18 @@ static const struct command_registration transport_commands[] = { COMMAND_REGISTRATION_DONE }; -static const struct command_registration transport_group[] = { +static const struct command_registration oocd_transport_group[] = { { .name = "transport", .mode = COMMAND_ANY, .help = "Transport command group", - .chain = transport_commands, + .chain = oocd_transport_commands, .usage = "" }, COMMAND_REGISTRATION_DONE }; -int transport_register_commands(struct command_context *ctx) +int oocd_transport_register_commands(struct command_context *ctx) { - return register_commands(ctx, NULL, transport_group); + return register_commands(ctx, NULL, oocd_transport_group); } diff --git a/src/transport/transport.h b/src/transport/transport.h index 6ece39e..634eb25 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -1,24 +1,32 @@ /* + * Transport subsystem header file for OpenOCD. + * * Copyright (c) 2010 by David Brownell - * Copyright (C) 2011 Tomasz Boleslaw CEDRO (http://www.tomek.cedro.info) + * + * Copyright (C) 2011-2012 Tomasz Boleslaw CEDRO + * [email protected], http://www.tomek.cedro.info * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef TRANSPORT_H -#define TRANSPORT_H +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef OOCD_TRANSPORT_H +#define OOCD_TRANSPORT_H #include "helper/command.h" @@ -40,7 +48,7 @@ * For non-debug transports, there may be interfaces used to * write to flash chips. */ -struct transport { +typedef struct oocd_transport { /** * Each transport has a unique name, used to select it * from among the alternatives. Examples might include @@ -66,21 +74,27 @@ struct transport { int (*init)(struct command_context *ctx); /** - * Transports are stored in a singly linked list. + * Quit makes resources free and destroys transport. */ - struct transport *next; -}; - -int transport_register(struct transport *new_transport); - -struct transport *get_current_transport(void); + int (*quit)(struct command_context *ctx); -int transport_register_commands(struct command_context *ctx); + /** + * Transports are stored in a singly linked list. + */ + struct oocd_transport *next; +} oocd_transport_t; -COMMAND_HELPER(transport_list_parse, char ***vector); +int oocd_transport_select(struct command_context *ctx, const char *name); +int oocd_transport_allow(struct command_context *ctx, const char **vector); +bool oocd_transport_declared(void); +int oocd_transport_register(oocd_transport_t *new_transport); +oocd_transport_t *oocd_transport_current_get(void); +int oocd_transport_register_commands(struct command_context *ctx); +int oocd_transport_select_jim(Jim_Interp *interp, int argc, Jim_Obj * const *argv); -int allow_transports(struct command_context *ctx, const char **vector); +COMMAND_HELPER(oocd_transport_list_parse, char ***vector); -bool transports_are_declared(void); +///TODO: Remove ASAP when interface becomes JTAG independent. +#include <jtag/interface.h> #endif -- ------------------------------------------------------------------------------ LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial Remotely access PCs and mobile devices and provide instant support Improve your efficiency, and focus on delivering more value-add services Discover what IT Professionals Know. Rescue delivers http://p.sf.net/sfu/logmein_12329d2d _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
