aboutsummaryrefslogtreecommitdiff
path: root/src/jtag
diff options
context:
space:
mode:
authorJan Matyas <matyas@codasip.com>2019-05-02 11:53:15 +0200
committerTomas Vanek <vanekt@fbl.cz>2019-12-16 23:27:32 +0000
commit881484708d0399007df1fa1b1a844f0dc95bf0ce (patch)
treea839de2b490438149562b4d8d017da5dd60876ac /src/jtag
parent22b4abc46c552bfc21003853b74e732da773cd1d (diff)
jtag_vpi: ensured constant packet size & endianness
Made sure that size and endianness of jtag_vpi structures sent over the network is the same, regardless of the platform. Little endian chosen to maintain as much compatibility with existing OpenOCD builds as possible. Matching change in the original jtag_vpi server: https://github.com/fjullien/jtag_vpi/pull/4 Change-Id: Ib839fea9bb2d5190b5643c970b89333b286dce71 Signed-off-by: Jan Matyas <matyas@codasip.com> Reviewed-on: http://openocd.zylin.com/5152 Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Tested-by: jenkins
Diffstat (limited to 'src/jtag')
-rw-r--r--src/jtag/drivers/jtag_vpi.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/jtag/drivers/jtag_vpi.c b/src/jtag/drivers/jtag_vpi.c
index 3e39420f..27b9da11 100644
--- a/src/jtag/drivers/jtag_vpi.c
+++ b/src/jtag/drivers/jtag_vpi.c
@@ -53,16 +53,34 @@ char *server_address;
int sockfd;
struct sockaddr_in serv_addr;
+/* One jtag_vpi "packet" as sent over a TCP channel. */
struct vpi_cmd {
- int cmd;
+ union {
+ uint32_t cmd;
+ unsigned char cmd_buf[4];
+ };
unsigned char buffer_out[XFERT_MAX_SIZE];
unsigned char buffer_in[XFERT_MAX_SIZE];
- int length;
- int nb_bits;
+ union {
+ uint32_t length;
+ unsigned char length_buf[4];
+ };
+ union {
+ uint32_t nb_bits;
+ unsigned char nb_bits_buf[4];
+ };
};
static int jtag_vpi_send_cmd(struct vpi_cmd *vpi)
{
+ /* Use little endian when transmitting/receiving jtag_vpi cmds.
+ The choice of little endian goes against usual networking conventions
+ but is intentional to remain compatible with most older OpenOCD builds
+ (i.e. builds on little-endian platforms). */
+ h_u32_to_le(vpi->cmd_buf, vpi->cmd);
+ h_u32_to_le(vpi->length_buf, vpi->length);
+ h_u32_to_le(vpi->nb_bits_buf, vpi->nb_bits);
+
int retval = write_socket(sockfd, vpi, sizeof(struct vpi_cmd));
if (retval <= 0)
return ERROR_FAIL;
@@ -76,6 +94,11 @@ static int jtag_vpi_receive_cmd(struct vpi_cmd *vpi)
if (retval < (int)sizeof(struct vpi_cmd))
return ERROR_FAIL;
+ /* Use little endian when transmitting/receiving jtag_vpi cmds. */
+ vpi->cmd = le_to_h_u32(vpi->cmd_buf);
+ vpi->length = le_to_h_u32(vpi->length_buf);
+ vpi->nb_bits = le_to_h_u32(vpi->nb_bits_buf);
+
return ERROR_OK;
}