Change return value on error.
[openocd.git] / src / jtag / drivers / buspirate.c
index 836a4d18a9bf9fa0f16d0309aedb4c66907401a6..f3edc8a52ba52a003493324266a59d9ade6d3cb1 100644 (file)
@@ -45,7 +45,7 @@ static void buspirate_scan(bool ir_scan, enum scan_type type,
        uint8_t *buffer, int scan_size, struct scan_command *command);
 
 
-#define CMD_UNKOWN        0x00
+#define CMD_UNKNOWN       0x00
 #define CMD_PORT_MODE     0x01
 #define CMD_FEATURE       0x02
 #define CMD_READ_ADCS     0x03
@@ -55,6 +55,11 @@ static void buspirate_scan(bool ir_scan, enum scan_type type,
 #define CMD_UART_SPEED    0x07
 #define CMD_JTAG_SPEED    0x08
 
+/* Not all OSes have this speed defined */
+#if !defined(B1000000)
+#define  B1000000 0010010
+#endif
+
 enum {
        MODE_HIZ = 0,
        MODE_JTAG = 1,          /* push-pull outputs */
@@ -212,13 +217,13 @@ static int buspirate_execute_queue(void)
 static int buspirate_init(void)
 {
        if (buspirate_port == NULL) {
-               LOG_ERROR("You need to specify port !");
+               LOG_ERROR("You need to specify the serial port!");
                return ERROR_JTAG_INIT_FAILED;
        }
 
        buspirate_fd = buspirate_serial_open(buspirate_port);
        if (buspirate_fd == -1) {
-               LOG_ERROR("Could not open serial port.");
+               LOG_ERROR("Could not open serial port");
                return ERROR_JTAG_INIT_FAILED;
        }
 
@@ -244,7 +249,7 @@ static int buspirate_init(void)
 
 static int buspirate_quit(void)
 {
-       LOG_INFO("Shuting down buspirate ");
+       LOG_INFO("Shutting down buspirate.");
        buspirate_jtag_set_mode(buspirate_fd, MODE_HIZ);
 
        buspirate_jtag_set_speed(buspirate_fd, SERIAL_NORMAL);
@@ -275,8 +280,7 @@ COMMAND_HANDLER(buspirate_handle_adc_command)
 COMMAND_HANDLER(buspirate_handle_vreg_command)
 {
        if (CMD_ARGC < 1) {
-               LOG_ERROR("usage: buspirate_vreg <1|0>");
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        if (atoi(CMD_ARGV[0]) == 1)
@@ -293,8 +297,7 @@ COMMAND_HANDLER(buspirate_handle_vreg_command)
 COMMAND_HANDLER(buspirate_handle_pullup_command)
 {
        if (CMD_ARGC < 1) {
-               LOG_ERROR("usage: buspirate_pullup <1|0>");
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        if (atoi(CMD_ARGV[0]) == 1)
@@ -311,8 +314,7 @@ COMMAND_HANDLER(buspirate_handle_pullup_command)
 COMMAND_HANDLER(buspirate_handle_led_command)
 {
        if (CMD_ARGC < 1) {
-               LOG_ERROR("usage: buspirate_led <1|0>");
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        if (atoi(CMD_ARGV[0]) == 1) {
@@ -334,8 +336,7 @@ COMMAND_HANDLER(buspirate_handle_led_command)
 COMMAND_HANDLER(buspirate_handle_mode_command)
 {
        if (CMD_ARGC < 1) {
-               LOG_ERROR("usage: buspirate_mode <normal|open-drain>");
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        if (CMD_ARGV[0][0] == 'n')
@@ -352,8 +353,7 @@ COMMAND_HANDLER(buspirate_handle_mode_command)
 COMMAND_HANDLER(buspirate_handle_speed_command)
 {
        if (CMD_ARGC < 1) {
-               LOG_ERROR("usage: buspirate_speed <normal|fast>");
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        if (CMD_ARGV[0][0] == 'n')
@@ -370,8 +370,7 @@ COMMAND_HANDLER(buspirate_handle_speed_command)
 COMMAND_HANDLER(buspirate_handle_port_command)
 {
        if (CMD_ARGC < 1) {
-               LOG_ERROR("usage: buspirate_port /dev/ttyUSB0");
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        if (buspirate_port == NULL)
@@ -390,36 +389,42 @@ static const struct command_registration buspirate_command_handlers[] = {
        },
        {
                .name = "buspirate_vreg",
+               .usage = "<1|0>",
                .handler = &buspirate_handle_vreg_command,
                .mode = COMMAND_CONFIG,
                .help = "changes the state of voltage regulators",
        },
        {
                .name = "buspirate_pullup",
+               .usage = "<1|0>",
                .handler = &buspirate_handle_pullup_command,
                .mode = COMMAND_CONFIG,
                .help = "changes the state of pullup",
        },
        {
                .name = "buspirate_led",
+               .usage = "<1|0>",
                .handler = &buspirate_handle_led_command,
                .mode = COMMAND_EXEC,
                .help = "changes the state of led",
        },
        {
                .name = "buspirate_speed",
+               .usage = "<normal|fast>",
                .handler = &buspirate_handle_speed_command,
                .mode = COMMAND_CONFIG,
                .help = "speed of the interface",
        },
        {
                .name = "buspirate_mode",
+               .usage = "<normal|open-drain>",
                .handler = &buspirate_handle_mode_command,
                .mode = COMMAND_CONFIG,
                .help = "pin mode of the interface",
        },
        {
                .name = "buspirate_port",
+               .usage = "/dev/ttyUSB0",
                .handler = &buspirate_handle_port_command,
                .mode = COMMAND_CONFIG,
                .help = "name of the serial port to open",
@@ -603,6 +608,10 @@ static int buspirate_tap_execute(void)
        }
 
        ret = buspirate_serial_read(buspirate_fd, tmp, bytes_to_send + 3);
+       if (ret != bytes_to_send + 3) {
+               LOG_ERROR("error reading");
+               return ERROR_FAIL;
+       }
        in_buf = (uint8_t *)(&tmp[3]);
 
        /* parse the scans */
@@ -660,7 +669,7 @@ static void buspirate_tap_append(int tms, int tdi)
 
                tap_chain_index++;
        } else
-               LOG_ERROR("tap_chain overflow, Bad things will happen");
+               LOG_ERROR("tap_chain overflow, bad things will happen");
 
 }
 
@@ -719,30 +728,34 @@ static void buspirate_jtag_enable(int fd)
        while (!done) {
                ret = buspirate_serial_read(fd, tmp, 4);
                if (ret != 4) {
-                       LOG_ERROR("Buspirate error. Is is binary/"
+                       LOG_ERROR("Buspirate error. Is binary"
                                "/OpenOCD support enabled?");
                        exit(-1);
                }
                if (strncmp(tmp, "BBIO", 4) == 0) {
                        ret = buspirate_serial_read(fd, tmp, 1);
                        if (ret != 1) {
-                               LOG_ERROR("Buspirate did not correctly! "
+                               LOG_ERROR("Buspirate did not answer correctly! "
                                        "Do you have correct firmware?");
                                exit(-1);
                        }
                        if (tmp[0] != '1') {
-                               LOG_ERROR("Unsupported binary protocol ");
+                               LOG_ERROR("Unsupported binary protocol");
                                exit(-1);
                        }
                        if (cmd_sent == 0) {
                                cmd_sent = 1;
                                tmp[0] = CMD_ENTER_OOCD;
                                ret = buspirate_serial_write(fd, tmp, 1);
+                               if (ret != 1) {
+                                       LOG_ERROR("error reading");
+                                       exit(-1);
+                               }
                        }
                } else if (strncmp(tmp, "OCD1", 4) == 0)
                        done = 1;
                else {
-                       LOG_ERROR("Buspirate did not correctly! "
+                       LOG_ERROR("Buspirate did not answer correctly! "
                                "Do you have correct firmware?");
                        exit(-1);
                }
@@ -752,13 +765,13 @@ static void buspirate_jtag_enable(int fd)
 
 static void buspirate_jtag_reset(int fd)
 {
-       int ret;
        char tmp[5];
 
        tmp[0] = 0x00; /* exit OCD1 mode */
        buspirate_serial_write(fd, tmp, 1);
        usleep(10000);
-       ret = buspirate_serial_read(fd, tmp, 5);
+       /* We ignore the return value here purposly, nothing we can do */
+       buspirate_serial_read(fd, tmp, 5);
        if (strncmp(tmp, "BBIO1", 5) == 0) {
                tmp[0] = 0x0F; /*  reset BP */
                buspirate_serial_write(fd, tmp, 1);
@@ -789,7 +802,7 @@ static void buspirate_jtag_set_speed(int fd, char speed)
                exit(-1);
        }
        if ((tmp[0] != CMD_UART_SPEED) || (tmp[1] != speed)) {
-               LOG_ERROR("Buspirate didn't reply as expected");
+               LOG_ERROR("Buspirate did not reply as expected");
                exit(-1);
        }
        LOG_INFO("Buspirate switched to %s mode",

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)