jtag: use proper format with uint32_t
authorAntonio Borneo <borneo.antonio@gmail.com>
Tue, 18 Aug 2020 16:55:25 +0000 (18:55 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 5 Sep 2020 16:12:25 +0000 (17:12 +0100)
Modify the format strings to properly handle uint32_t data types.

Change the prototype of detect_swo_freq_and_prescaler() in
'jlink.c' to avoid an implicit cast in the caller function.

Change the type of the variable retlen in some functions in
'usb_blaster.c' to properly pass their pointer to the local read
and write functions.

Use the proper parser COMMAND_PARSE_NUMBER(u32, ...).

Change-Id: I5227dbce04ee59881f173724db90790b7b9cc7af
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5815
Tested-by: jenkins
18 files changed:
src/jtag/core.c
src/jtag/drivers/amt_jtagaccel.c
src/jtag/drivers/arm-jtag-ew.c
src/jtag/drivers/bitbang.c
src/jtag/drivers/bitq.c
src/jtag/drivers/buspirate.c
src/jtag/drivers/ft232r.c
src/jtag/drivers/ftdi.c
src/jtag/drivers/gw16012.c
src/jtag/drivers/jlink.c
src/jtag/drivers/opendous.c
src/jtag/drivers/rlink.c
src/jtag/drivers/stlink_usb.c
src/jtag/drivers/usb_blaster/usb_blaster.c
src/jtag/drivers/usbprog.c
src/jtag/drivers/vsllink.c
src/jtag/drivers/xds110.c
src/jtag/drivers/xlnx-pcie-xvc.c

index b8d0b74c0111e891910fb55db77ecb52449e1573..03a26bec21af6894ee347935931f4d9933bb19cc 100644 (file)
@@ -1290,7 +1290,7 @@ static int jtag_examine_chain(void)
 
                if ((idcode & 1) == 0) {
                        /* Zero for LSB indicates a device in bypass */
-                       LOG_INFO("TAP %s does not have valid IDCODE (idcode=0x%x)",
+                       LOG_INFO("TAP %s does not have valid IDCODE (idcode=0x%" PRIx32 ")",
                                        tap->dotted_name, idcode);
                        tap->hasidcode = false;
                        tap->idcode = 0;
index f5918a0555127d17caa1eaa8788383acfab18903..81721cbb405fb654b16c2e61e6fa1975b5fe962b 100644 (file)
@@ -374,7 +374,7 @@ static int amt_jtagaccel_execute_queue(void)
                                        free(buffer);
                                break;
                        case JTAG_SLEEP:
-                               LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us);
+                               LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
                                jtag_sleep(cmd->cmd.sleep->us);
                                break;
                        default:
index 405278b9a1596d7d86da708720f7ddc18bac22a7..60b1195484f185177b63b78bd6477eea210e2959 100644 (file)
@@ -160,7 +160,7 @@ static int armjtagew_execute_queue(void)
                                break;
 
                        case JTAG_SLEEP:
-                               LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us);
+                               LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
                                armjtagew_tap_execute();
                                jtag_sleep(cmd->cmd.sleep->us);
                                break;
index 2a78fa248e908d5074d831ed09d145dcaf2f2f33..b33e87f2a4ccf418845b1382565cfa5158601ce2 100644 (file)
@@ -362,7 +362,7 @@ int bitbang_execute_queue(void)
                                        free(buffer);
                                break;
                        case JTAG_SLEEP:
-                               LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us);
+                               LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
                                jtag_sleep(cmd->cmd.sleep->us);
                                break;
                        case JTAG_TMS:
index 2241c13a30ae2bd5d5a18a2212e410e5e1c2e749..97734a92e5ecc804345269d2af8ee57af9ed3df7 100644 (file)
@@ -264,7 +264,7 @@ int bitq_execute_queue(void)
                        break;
 
                case JTAG_SLEEP:
-                       LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us);
+                       LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
                        bitq_interface->sleep(cmd->cmd.sleep->us);
                        if (bitq_interface->in_rdy())
                                bitq_in_proc();
index a6ffe35f57ae6d9e8ffa1e1f2eb5d5578296a94b..2483b434647164d271847e5575a8bdddfb870b4a 100644 (file)
@@ -214,7 +214,7 @@ static int buspirate_execute_queue(void)
 
                        break;
                case JTAG_SLEEP:
-                       LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us);
+                       LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
                        buspirate_tap_execute();
                        jtag_sleep(cmd->cmd.sleep->us);
                                break;
index c9ed304a876b4d588c14ea100768b2366aa8a912..3c54809c066e48268fbd50c20c24a3fcdd9be4a0 100644 (file)
@@ -891,7 +891,7 @@ static int syncbb_execute_queue(void)
                                break;
 
                        case JTAG_SLEEP:
-                               LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us);
+                               LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
 
                                jtag_sleep(cmd->cmd.sleep->us);
                                break;
index f1d28d2fd26e826ded388dd238cb770d8100ec5f..d2b97b96eef17e925244e01b89fb7165c782990d 100644 (file)
@@ -555,11 +555,11 @@ static int ftdi_reset(int trst, int srst)
 
 static void ftdi_execute_sleep(struct jtag_command *cmd)
 {
-       LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us);
+       LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
 
        mpsse_flush(mpsse_ctx);
        jtag_sleep(cmd->cmd.sleep->us);
-       LOG_DEBUG_IO("sleep %" PRIi32 " usec while in %s",
+       LOG_DEBUG_IO("sleep %" PRIu32 " usec while in %s",
                cmd->cmd.sleep->us,
                tap_state_name(tap_get_state()));
 }
index d1699ef01aa302c6920fe642d626f55bd4086c58..cad2e1b99b6299426a633f7ccc852d44b4fd484b 100644 (file)
@@ -331,7 +331,7 @@ static int gw16012_execute_queue(void)
                                        free(buffer);
                                break;
                        case JTAG_SLEEP:
-                               LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us);
+                               LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
                                jtag_sleep(cmd->cmd.sleep->us);
                                break;
                        default:
index 91ecf56e15b89aad44121a2b066162b738ce56d1..57e357b79b441450f94cb0aac9c465f597468629 100644 (file)
@@ -254,7 +254,7 @@ static void jlink_execute_scan(struct jtag_command *cmd)
 
 static void jlink_execute_sleep(struct jtag_command *cmd)
 {
-       LOG_DEBUG_IO("sleep %" PRIi32 "", cmd->cmd.sleep->us);
+       LOG_DEBUG_IO("sleep %" PRIu32 "", cmd->cmd.sleep->us);
        jlink_flush();
        jtag_sleep(cmd->cmd.sleep->us);
 }
@@ -480,7 +480,7 @@ static bool adjust_swd_buffer_size(void)
        }
 
        if (tmp < 143) {
-               LOG_ERROR("Not enough free device internal memory: %u bytes.", tmp);
+               LOG_ERROR("Not enough free device internal memory: %" PRIu32 " bytes.", tmp);
                return false;
        }
 
@@ -1049,7 +1049,7 @@ COMMAND_HANDLER(jlink_handle_free_memory_command)
                return ERROR_FAIL;
        }
 
-       command_print(CMD, "Device has %u bytes of free memory.", tmp);
+       command_print(CMD, "Device has %" PRIu32 " bytes of free memory.", tmp);
 
        return ERROR_OK;
 }
@@ -1288,7 +1288,7 @@ static bool calculate_swo_prescaler(unsigned int traceclkin_freq,
 }
 
 static bool detect_swo_freq_and_prescaler(struct jaylink_swo_speed speed,
-               unsigned int traceclkin_freq, uint32_t *trace_freq,
+               unsigned int traceclkin_freq, unsigned int *trace_freq,
                uint16_t *prescaler)
 {
        uint32_t divider;
@@ -1378,11 +1378,11 @@ static int config_trace(bool enabled, enum tpiu_pin_protocol pin_protocol,
                max_freq = speed.freq / speed.min_div;
 
                if (*trace_freq > max_freq) {
-                       LOG_INFO("Given SWO frequency too high, using %u Hz instead.",
+                       LOG_INFO("Given SWO frequency too high, using %" PRIu32 " Hz instead.",
                                max_freq);
                        *trace_freq = max_freq;
                } else if (*trace_freq < min_freq) {
-                       LOG_INFO("Given SWO frequency too low, using %u Hz instead.",
+                       LOG_INFO("Given SWO frequency too low, using %" PRIu32 " Hz instead.",
                                min_freq);
                        *trace_freq = min_freq;
                } else if (*trace_freq != speed.freq / divider) {
@@ -1420,7 +1420,7 @@ static int config_trace(bool enabled, enum tpiu_pin_protocol pin_protocol,
                return ERROR_FAIL;
        }
 
-       LOG_DEBUG("Using %u bytes device memory for trace capturing.",
+       LOG_DEBUG("Using %" PRIu32 " bytes device memory for trace capturing.",
                buffer_size);
 
        /*
index 5572c4a0edcd86771084ddfc5bac3e419504a46a..bccd3ddb0297b727a8fad1d11be8290de5e8c63f 100644 (file)
@@ -310,7 +310,7 @@ static int opendous_execute_queue(void)
                                break;
 
                        case JTAG_SLEEP:
-                               LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us);
+                               LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
                                opendous_tap_execute();
                                jtag_sleep(cmd->cmd.sleep->us);
                                break;
index 28435646633e4c4f5c7114fea63258f8645310a4..be4ad08bf2d3c126a3d380ce88842b5b4864c19a 100644 (file)
@@ -1340,7 +1340,7 @@ static int rlink_execute_queue(void)
                                        retval = ERROR_FAIL;
                                break;
                        case JTAG_SLEEP:
-                               LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us);
+                               LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
                                jtag_sleep(cmd->cmd.sleep->us);
                                break;
                        default:
index 6ae9e3e817d54931b34fc7cdf53d8a44a7a347b1..ce55b94a556e3620f757177d2d8b5b3babbc8a45 100644 (file)
@@ -3092,7 +3092,7 @@ static int stlink_read_dap_register(void *handle, unsigned short dap_port,
 
        retval = stlink_usb_xfer_errcheck(handle, h->databuf, 8);
        *val = le_to_h_u32(h->databuf + 4);
-       LOG_DEBUG_IO("dap_port_read = %d, addr =  0x%x, value = 0x%x", dap_port, addr, *val);
+       LOG_DEBUG_IO("dap_port_read = %d, addr =  0x%x, value = 0x%" PRIx32, dap_port, addr, *val);
        return retval;
 }
 
@@ -3107,7 +3107,7 @@ static int stlink_write_dap_register(void *handle, unsigned short dap_port,
        if (!(h->version.flags & STLINK_F_HAS_DAP_REG))
                return ERROR_COMMAND_NOTFOUND;
 
-       LOG_DEBUG_IO("dap_write port = %d, addr = 0x%x, value = 0x%x", dap_port, addr, val);
+       LOG_DEBUG_IO("dap_write port = %d, addr = 0x%x, value = 0x%" PRIx32, dap_port, addr, val);
        stlink_usb_init_buffer(handle, h->rx_ep, 16);
        h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
        h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_WRITE_DAP_REG;
@@ -3531,7 +3531,7 @@ static int stlink_swim_op_read_mem(uint32_t addr, uint32_t size,
        int retval;
        uint32_t bytes_remaining;
 
-       LOG_DEBUG_IO("read at 0x%08x len %d*0x%08x", addr, size, count);
+       LOG_DEBUG_IO("read at 0x%08" PRIx32 " len %" PRIu32 "*0x%08" PRIx32, addr, size, count);
        count *= size;
 
        while (count) {
@@ -3554,7 +3554,7 @@ static int stlink_swim_op_write_mem(uint32_t addr, uint32_t size,
        int retval;
        uint32_t bytes_remaining;
 
-       LOG_DEBUG_IO("write at 0x%08x len %d*0x%08x", addr, size, count);
+       LOG_DEBUG_IO("write at 0x%08" PRIx32 " len %" PRIu32 "*0x%08" PRIx32, addr, size, count);
        count *= size;
 
        while (count) {
index b5f252164354baa653cf9fa6d1cc6eb48ebd2322..3c9c3a769ecdd8bdb4d2db719c7006f548d908b0 100644 (file)
@@ -174,7 +174,7 @@ static int ublast_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
        int ret = info.drv->read(info.drv, buf, size, bytes_read);
        char *str = hexdump(buf, *bytes_read);
 
-       LOG_DEBUG_IO("(size=%d, buf=[%s]) -> %u", size, str,
+       LOG_DEBUG_IO("(size=%d, buf=[%s]) -> %" PRIu32, size, str,
                      *bytes_read);
        free(str);
        return ret;
@@ -185,7 +185,7 @@ static int ublast_buf_write(uint8_t *buf, int size, uint32_t *bytes_written)
        int ret = info.drv->write(info.drv, buf, size, bytes_written);
        char *str = hexdump(buf, *bytes_written);
 
-       LOG_DEBUG_IO("(size=%d, buf=[%s]) -> %u", size, str,
+       LOG_DEBUG_IO("(size=%d, buf=[%s]) -> %" PRIu32, size, str,
                      *bytes_written);
        free(str);
        return ret;
@@ -198,7 +198,7 @@ static int nb_buf_remaining(void)
 
 static void ublast_flush_buffer(void)
 {
-       unsigned int retlen;
+       uint32_t retlen;
        int nb = info.bufidx, ret = ERROR_OK;
 
        while (ret == ERROR_OK && nb > 0) {
@@ -538,7 +538,7 @@ static void ublast_state_move(tap_state_t state, int skip)
  */
 static int ublast_read_byteshifted_tdos(uint8_t *buf, int nb_bytes)
 {
-       unsigned int retlen;
+       uint32_t retlen;
        int ret = ERROR_OK;
 
        LOG_DEBUG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bytes * 8);
@@ -570,7 +570,7 @@ static int ublast_read_bitbang_tdos(uint8_t *buf, int nb_bits)
 {
        int nb1 = nb_bits;
        int i, ret = ERROR_OK;
-       unsigned int retlen;
+       uint32_t retlen;
        uint8_t tmp[8];
 
        LOG_DEBUG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bits);
@@ -902,7 +902,7 @@ static int ublast_init(void)
 static int ublast_quit(void)
 {
        uint8_t byte0 = 0;
-       unsigned int retlen;
+       uint32_t retlen;
 
        ublast_buf_write(&byte0, 1, &retlen);
        return info.drv->close(info.drv);
index 67cad58f4c8e85be882dddbe7b4a41ef354ce74c..dd7dcdb4b5628fffea3972feeb95c65eeb0e796a 100644 (file)
@@ -141,7 +141,7 @@ static int usbprog_execute_queue(void)
                                free(buffer);
                        break;
                case JTAG_SLEEP:
-                       LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us);
+                       LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
                        jtag_sleep(cmd->cmd.sleep->us);
                        break;
                default:
index 5fb9bcdcc9e69adc3aa87d144e71f78ac452b1a2..6f2296e6d1ee1aa4289fa0545eb62e7a2d08bd8f 100644 (file)
@@ -165,7 +165,7 @@ static int vsllink_execute_queue(void)
                                break;
 
                        case JTAG_SLEEP:
-                               LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us);
+                               LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
                                vsllink_tap_execute();
                                jtag_sleep(cmd->cmd.sleep->us);
                                break;
index 67c4a3b12990481863de76f8c2537d4ba325a988..fb04d51a4597fb274e1200e2f4ca03479e617910 100644 (file)
@@ -655,7 +655,7 @@ static bool xds_execute(uint32_t out_length, uint32_t in_length,
                        if (bytes_read != in_length) {
                                /* Unexpected amount of data returned */
                                success = false;
-                               LOG_DEBUG("XDS110: command 0x%02x return %d bytes, expected %d",
+                               LOG_DEBUG("XDS110: command 0x%02x return %" PRIu32 " bytes, expected %" PRIu32,
                                        xds110.write_payload[0], bytes_read, in_length);
                        } else {
                                /* Extract error code from return packet */
@@ -1389,7 +1389,7 @@ static void xds110_show_info(void)
        uint32_t firmware = xds110.firmware;
 
        LOG_INFO("XDS110: vid/pid = %04x/%04x", xds110.vid, xds110.pid);
-       LOG_INFO("XDS110: firmware version = %d.%d.%d.%d",
+       LOG_INFO("XDS110: firmware version = %" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32,
                (((firmware >> 28) & 0xf) * 10) + ((firmware >> 24) & 0xf),
                (((firmware >> 20) & 0xf) * 10) + ((firmware >> 16) & 0xf),
                (((firmware >> 12) & 0xf) * 10) + ((firmware >>  8) & 0xf),
@@ -1399,10 +1399,10 @@ static void xds110_show_info(void)
                LOG_INFO("XDS110: serial number = %s", xds110.serial);
        if (xds110.is_swd_mode) {
                LOG_INFO("XDS110: connected to target via SWD");
-               LOG_INFO("XDS110: SWCLK set to %d kHz", xds110.speed);
+               LOG_INFO("XDS110: SWCLK set to %" PRIu32 " kHz", xds110.speed);
        } else {
                LOG_INFO("XDS110: connected to target via JTAG");
-               LOG_INFO("XDS110: TCK set to %d kHz", xds110.speed);
+               LOG_INFO("XDS110: TCK set to %" PRIu32 " kHz", xds110.speed);
        }
 
        /* Alert user that there's a better firmware to use */
@@ -1756,7 +1756,7 @@ static void xds110_queue_scan(struct jtag_command *cmd)
 
        /* Check if this single request is too large to fit */
        if ((1 + total_bytes + sizeof(end_state) + 1) > MAX_DATA_BLOCK) {
-               LOG_ERROR("BUG: JTAG scan request is too large to handle (%d bits)",
+               LOG_ERROR("BUG: JTAG scan request is too large to handle (%" PRIu32 " bits)",
                        total_bits);
                /* Failing to run this scan mucks up debug on this target */
                exit(-1);
@@ -2057,7 +2057,7 @@ COMMAND_HANDLER(xds110_handle_supply_voltage_command)
        uint32_t voltage = 0;
 
        if (CMD_ARGC == 1) {
-               COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], voltage);
+               COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], voltage);
                if (voltage == 0 || (voltage >= XDS110_MIN_VOLTAGE && voltage
                        <= XDS110_MAX_VOLTAGE)) {
                        /* Requested voltage is in range */
index 43993c897479e2d5670c55e0bbdebcb541c588e6..1dca5def8f4a6dabe006b3f9faa2e96d1dce29a6 100644 (file)
@@ -82,7 +82,7 @@ static int xlnx_pcie_xvc_write_reg(const int offset, const uint32_t val)
        err = pwrite(xlnx_pcie_xvc->fd, &val, sizeof(val),
                     xlnx_pcie_xvc->offset + offset);
        if (err != sizeof(val)) {
-               LOG_ERROR("Failed to write offset: %x with value: %x",
+               LOG_ERROR("Failed to write offset: %x with value: %" PRIx32,
                          offset, val);
                return ERROR_JTAG_DEVICE_ERROR;
        }
@@ -112,10 +112,10 @@ static int xlnx_pcie_xvc_transact(size_t num_bits, uint32_t tms, uint32_t tdi,
                return err;
 
        if (tdo)
-               LOG_DEBUG_IO("Transact num_bits: %zu, tms: %x, tdi: %x, tdo: %x",
+               LOG_DEBUG_IO("Transact num_bits: %zu, tms: %" PRIx32 ", tdi: %" PRIx32 ", tdo: %" PRIx32,
                             num_bits, tms, tdi, *tdo);
        else
-               LOG_DEBUG_IO("Transact num_bits: %zu, tms: %x, tdi: %x, tdo: <null>",
+               LOG_DEBUG_IO("Transact num_bits: %zu, tms: %" PRIx32 ", tdi: %" PRIx32 ", tdo: <null>",
                             num_bits, tms, tdi);
        return ERROR_OK;
 }
@@ -304,7 +304,7 @@ static void xlnx_pcie_xvc_execute_reset(struct jtag_command *cmd)
 
 static void xlnx_pcie_xvc_execute_sleep(struct jtag_command *cmd)
 {
-       LOG_DEBUG("sleep %" PRIi32 "", cmd->cmd.sleep->us);
+       LOG_DEBUG("sleep %" PRIu32 "", cmd->cmd.sleep->us);
        usleep(cmd->cmd.sleep->us);
 }
 
@@ -405,7 +405,7 @@ static int xlnx_pcie_xvc_init(void)
                err = xlnx_pcie_xvc_read_reg(XLNX_XVC_EXT_CAP, &cap);
                if (err != ERROR_OK)
                        return err;
-               LOG_DEBUG("Checking capability at 0x%x; id=0x%04x version=0x%x next=0x%x",
+               LOG_DEBUG("Checking capability at 0x%x; id=0x%04" PRIx32 " version=0x%" PRIx32 " next=0x%" PRIx32,
                         xlnx_pcie_xvc->offset,
                         PCI_EXT_CAP_ID(cap),
                         PCI_EXT_CAP_VER(cap),
@@ -414,7 +414,7 @@ static int xlnx_pcie_xvc_init(void)
                        err = xlnx_pcie_xvc_read_reg(XLNX_XVC_VSEC_HDR, &vh);
                        if (err != ERROR_OK)
                                return err;
-                       LOG_DEBUG("Checking possible match at 0x%x; id: 0x%x; rev: 0x%x; length: 0x%x",
+                       LOG_DEBUG("Checking possible match at 0x%x; id: 0x%" PRIx32 "; rev: 0x%" PRIx32 "; length: 0x%" PRIx32,
                                 xlnx_pcie_xvc->offset,
                                 PCI_VNDR_HEADER_ID(vh),
                                 PCI_VNDR_HEADER_REV(vh),