ULINK driver: Implement command to manually force downloading firmware image from...
[openocd.git] / src / jtag / drivers / ulink.c
index f8103942c4e5854f5551a5acb91c602c48866c69..049989bf257a4ba219029620a73a6b027eea1857 100644 (file)
@@ -62,8 +62,7 @@
 /** Delay (in microseconds) to wait while EZ-USB performs ReNumeration. */
 #define ULINK_RENUMERATION_DELAY 1500000
 
-/** Location of OpenULINK firmware image. TODO: Provide some way of modifying
- *  this path, maybe in a separate OpenOCD command? */
+/** Default location of OpenULINK firmware image. */
 #define ULINK_FIRMWARE_FILE      PKGLIBDIR "/OpenULINK/ulink_firmware.hex"
 
 /** Maximum size of a single firmware section. Entire EZ-USB code space = 8kB */
@@ -203,16 +202,16 @@ int ulink_append_led_cmd(struct ulink *device, uint8_t led_state);
 int ulink_append_test_cmd(struct ulink *device);
 
 /* Interface between OpenULINK and OpenOCD */
-int ulink_queue_scan(struct ulink *device, struct jtag_command *cmd);
+static void ulink_set_end_state(tap_state_t endstate);
 int ulink_queue_statemove(struct ulink *device);
-int ulink_queue_reset(struct ulink *device, struct jtag_command *cmd);
-int ulink_queue_runtest(struct ulink *device, struct jtag_command *cmd);
+
+int ulink_queue_scan(struct ulink *device, struct jtag_command *cmd);
 int ulink_queue_tlr_reset(struct ulink *device, struct jtag_command *cmd);
+int ulink_queue_runtest(struct ulink *device, struct jtag_command *cmd);
+int ulink_queue_reset(struct ulink *device, struct jtag_command *cmd);
 int ulink_queue_pathmove(struct ulink *device, struct jtag_command *cmd);
 int ulink_queue_sleep(struct ulink *device, struct jtag_command *cmd);
 
-static void ulink_set_end_state(tap_state_t endstate);
-
 int ulink_post_process_scan(ulink_cmd_t *ulink_cmd);
 int ulink_post_process_queue(struct ulink *device);
 
@@ -378,8 +377,9 @@ int ulink_load_firmware(struct ulink *device, char *filename)
   ulink_firmware_image.base_address = 0;
   ulink_firmware_image.base_address_set = 0;
 
-  ret = image_open(&ulink_firmware_image, ULINK_FIRMWARE_FILE, "ihex");
+  ret = image_open(&ulink_firmware_image, filename, "ihex");
   if (ret != ERROR_OK) {
+    LOG_ERROR("Could not load firmware image");
     return ret;
   }
 
@@ -1232,6 +1232,52 @@ int ulink_append_test_cmd(struct ulink *device)
 
 /******************* Interface between OpenULINK and OpenOCD ******************/
 
+/**
+ * Sets the end state follower (see interface.h) if \a endstate is a stable
+ * state.
+ *
+ * @param endstate the state the end state follower should be set to.
+ */
+static void ulink_set_end_state(tap_state_t endstate)
+{
+  if (tap_is_state_stable(endstate)) {
+    tap_set_end_state(endstate);
+  }
+  else {
+    LOG_ERROR("BUG: %s is not a valid end state", tap_state_name(endstate));
+    exit( EXIT_FAILURE);
+  }
+}
+
+/**
+ * Move from the current TAP state to the current TAP end state.
+ *
+ * @param device pointer to struct ulink identifying ULINK driver instance.
+ * @return on success: ERROR_OK
+ * @return on failure: ERROR_FAIL
+ */
+int ulink_queue_statemove(struct ulink *device)
+{
+  uint8_t tms_sequence, tms_count;
+  int ret;
+
+  if (tap_get_state() == tap_get_end_state()) {
+    /* Do nothing if we are already there */
+    return ERROR_OK;
+  }
+
+  tms_sequence = tap_get_tms_path(tap_get_state(), tap_get_end_state());
+  tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
+
+  ret = ulink_append_clock_tms_cmd(device, tms_count, tms_sequence);
+
+  if (ret == ERROR_OK) {
+    tap_set_state(tap_get_end_state());
+  }
+
+  return ret;
+}
+
 /**
  * Perform a scan operation on a JTAG register.
  *
@@ -1391,78 +1437,24 @@ int ulink_queue_scan(struct ulink *device, struct jtag_command *cmd)
 }
 
 /**
- * Sets the end state follower (see interface.h) if \a endstate is a stable
- * state.
- *
- * @param endstate the state the end state follower should be set to.
- */
-static void ulink_set_end_state(tap_state_t endstate)
-{
-  if (tap_is_state_stable(endstate)) {
-    tap_set_end_state(endstate);
-  }
-  else {
-    LOG_ERROR("BUG: %s is not a valid end state", tap_state_name(endstate));
-    exit( EXIT_FAILURE);
-  }
-}
-
-/**
- * Move from the current TAP state to the current TAP end state.
+ * Move the TAP into the Test Logic Reset state.
  *
  * @param device pointer to struct ulink identifying ULINK driver instance.
+ * @param cmd pointer to the command that shall be executed.
  * @return on success: ERROR_OK
  * @return on failure: ERROR_FAIL
  */
-int ulink_queue_statemove(struct ulink *device)
+int ulink_queue_tlr_reset(struct ulink *device, struct jtag_command *cmd)
 {
-  uint8_t tms_sequence, tms_count;
   int ret;
 
-  if (tap_get_state() == tap_get_end_state()) {
-    /* Do nothing if we are already there */
-    return ERROR_OK;
-  }
-
-  tms_sequence = tap_get_tms_path(tap_get_state(), tap_get_end_state());
-  tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
-
-  ret = ulink_append_clock_tms_cmd(device, tms_count, tms_sequence);
+  ret = ulink_append_clock_tms_cmd(device, 5, 0xff);
 
   if (ret == ERROR_OK) {
-    tap_set_state(tap_get_end_state());
-  }
-
-  return ret;
-}
-
-/**
- * Execute a JTAG_RESET command
- *
- * @param cmd pointer to the command that shall be executed.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
- */
-int ulink_queue_reset(struct ulink *device, struct jtag_command *cmd)
-{
-  uint8_t low = 0, high = 0;
-
-  if (cmd->cmd.reset->trst) {
     tap_set_state(TAP_RESET);
-    high |= SIGNAL_TRST;
-  }
-  else {
-    low |= SIGNAL_TRST;
   }
 
-  if (cmd->cmd.reset->srst) {
-    high |= SIGNAL_RESET;
-  }
-  else {
-    low |= SIGNAL_RESET;
-  }
-
-  return ulink_append_set_signals_cmd(device, low, high);
+  return ret;
 }
 
 /**
@@ -1502,24 +1494,32 @@ int ulink_queue_runtest(struct ulink *device, struct jtag_command *cmd)
 }
 
 /**
- * Move the TAP into the Test Logic Reset state.
+ * Execute a JTAG_RESET command
  *
- * @param device pointer to struct ulink identifying ULINK driver instance.
  * @param cmd pointer to the command that shall be executed.
  * @return on success: ERROR_OK
  * @return on failure: ERROR_FAIL
  */
-int ulink_queue_tlr_reset(struct ulink *device, struct jtag_command *cmd)
+int ulink_queue_reset(struct ulink *device, struct jtag_command *cmd)
 {
-  int ret;
-
-  ret = ulink_append_clock_tms_cmd(device, 5, 0xff);
+  uint8_t low = 0, high = 0;
 
-  if (ret == ERROR_OK) {
+  if (cmd->cmd.reset->trst) {
     tap_set_state(TAP_RESET);
+    high |= SIGNAL_TRST;
+  }
+  else {
+    low |= SIGNAL_TRST;
   }
 
-  return ret;
+  if (cmd->cmd.reset->srst) {
+    high |= SIGNAL_RESET;
+  }
+  else {
+    low |= SIGNAL_RESET;
+  }
+
+  return ulink_append_set_signals_cmd(device, low, high);
 }
 
 /**
@@ -1607,10 +1607,10 @@ int ulink_post_process_queue(struct ulink *device)
       case JTAG_SCAN:
         ret = ulink_post_process_scan(current);
         break;
-      case JTAG_RUNTEST:
       case JTAG_TLR_RESET:
-      case JTAG_PATHMOVE:
+      case JTAG_RUNTEST:
       case JTAG_RESET:
+      case JTAG_PATHMOVE:
       case JTAG_SLEEP:
         /* Nothing to do for these commands */
         ret = ERROR_OK;
@@ -1657,18 +1657,18 @@ static int ulink_execute_queue(void)
     case JTAG_SCAN:
       ret = ulink_queue_scan(ulink_handle, cmd);
       break;
-    case JTAG_RUNTEST:
-      ret = ulink_queue_runtest(ulink_handle, cmd);
-      break;
     case JTAG_TLR_RESET:
       ret = ulink_queue_tlr_reset(ulink_handle, cmd);
       break;
-    case JTAG_PATHMOVE:
-      ret = ulink_queue_pathmove(ulink_handle, cmd);
+    case JTAG_RUNTEST:
+      ret = ulink_queue_runtest(ulink_handle, cmd);
       break;
     case JTAG_RESET:
       ret = ulink_queue_reset(ulink_handle, cmd);
       break;
+    case JTAG_PATHMOVE:
+      ret = ulink_queue_pathmove(ulink_handle, cmd);
+      break;
     case JTAG_SLEEP:
       ret = ulink_queue_sleep(ulink_handle, cmd);
       break;
@@ -1678,6 +1678,10 @@ static int ulink_execute_queue(void)
       break;
     }
 
+    if (ret != ERROR_OK) {
+      return ret;
+    }
+
     cmd = cmd->next;
   }
 
@@ -1877,10 +1881,44 @@ static int ulink_quit(void)
   return ret;
 }
 
+/**
+ * Set a custom path to ULINK firmware image and force downloading to ULINK.
+ */
+COMMAND_HANDLER(ulink_download_firmware_handler)
+{
+  int ret;
+
+  if (CMD_ARGC != 1) {
+    LOG_ERROR("Need exactly one argument to ulink_download_firmware");
+    return ERROR_FAIL;
+  }
+
+  LOG_INFO("Downloading ULINK firmware image %s", CMD_ARGV[0]);
+
+  /* Download firmware image in CMD_ARGV[0] */
+  ret = ulink_load_firmware_and_renumerate(&ulink_handle, (char *)CMD_ARGV[0],
+      ULINK_RENUMERATION_DELAY);
+
+  return ret;
+}
+
 /*************************** Command Registration **************************/
 
+static const struct command_registration ulink_command_handlers[] = {
+  {
+    .name = "ulink_download_firmware",
+    .handler = &ulink_download_firmware_handler,
+    .mode = COMMAND_EXEC,
+    .help = "download firmware image to ULINK device",
+    .usage = "path/to/ulink_firmware.hex",
+  },
+  COMMAND_REGISTRATION_DONE,
+};
+
 struct jtag_interface ulink_interface = {
   .name = "ulink",
+
+  .commands = ulink_command_handlers,
   .transports = jtag_only,
 
   .execute_queue = ulink_execute_queue,

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)