- }
- break;
- case 2: /* assign */
- if (session) {
- /* can't change session's transport after-the-fact */
- LOG_ERROR("session's transport is already selected.");
- return JIM_ERR;
- }
-
- /* Is this transport supported by our debug adapter?
- * Example, "JTAG-only" means SWD is not supported.
- *
- * NOTE: requires adapter to have been set up, with
- * transports declared via C.
- */
- if (!allowed_transports) {
- LOG_ERROR("Debug adapter doesn't support any transports?");
- return JIM_ERR;
- }
-
- for (unsigned i = 0; allowed_transports[i]; i++) {
-
- if (strcmp(allowed_transports[i], argv[1]->bytes) == 0)
- return transport_select(global_cmd_ctx, argv[1]->bytes);
- }
-
- LOG_ERROR("Debug adapter doesn't support '%s' "
- "transport", argv[1]->bytes);
- return JIM_ERR;
- break;
- default:
- Jim_WrongNumArgs(interp, 1, argv, "[too many parameters]");
- return JIM_ERR;
+ break;
+ case 2: /* assign */
+ if (session) {
+ if (!strcmp(session->name, argv[1]->bytes)) {
+ LOG_WARNING("Transport \"%s\" was already selected", session->name);
+ Jim_SetResultString(interp, session->name, -1);
+ return JIM_OK;
+ } else {
+ LOG_ERROR("Can't change session's transport after the initial selection was made");
+ return JIM_ERR;
+ }
+ }
+
+ /* Is this transport supported by our debug adapter?
+ * Example, "JTAG-only" means SWD is not supported.
+ *
+ * NOTE: requires adapter to have been set up, with
+ * transports declared via C.
+ */
+ if (!allowed_transports) {
+ LOG_ERROR("Debug adapter doesn't support any transports?");
+ return JIM_ERR;
+ }
+
+ for (unsigned i = 0; allowed_transports[i]; i++) {
+
+ if (strcmp(allowed_transports[i], argv[1]->bytes) == 0) {
+ if (transport_select(global_cmd_ctx, argv[1]->bytes) == ERROR_OK) {
+ Jim_SetResultString(interp, session->name, -1);
+ return JIM_OK;
+ }
+ return JIM_ERR;
+ }
+ }
+
+ LOG_ERROR("Debug adapter doesn't support '%s' transport", argv[1]->bytes);
+ return JIM_ERR;
+ break;
+ default:
+ Jim_WrongNumArgs(interp, 1, argv, "[too many parameters]");
+ return JIM_ERR;