This is an automated email from Gerrit. Jan Matyas (mat...@codasip.com) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/5152
-- gerrit commit feb8cb642939c9b1ac23ad4b603384ed195b3375 Author: Jan Matyas <mat...@codasip.com> Date: Thu May 2 11:53:15 2019 +0200 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 <mat...@codasip.com> diff --git a/src/jtag/drivers/jtag_vpi.c b/src/jtag/drivers/jtag_vpi.c index 35c7031..9a609e0 100644 --- a/src/jtag/drivers/jtag_vpi.c +++ b/src/jtag/drivers/jtag_vpi.c @@ -54,15 +54,38 @@ int sockfd; struct sockaddr_in serv_addr; struct vpi_cmd { - int cmd; + uint32_t cmd; unsigned char buffer_out[XFERT_MAX_SIZE]; unsigned char buffer_in[XFERT_MAX_SIZE]; - int length; - int nb_bits; + uint32_t length; + uint32_t nb_bits; }; +static int is_host_little_endian(void) +{ + return (htonl(25) != 25); +} + +static uint32_t from_little_endian_u32(uint32_t val) +{ + return is_host_little_endian() ? val : htonl(val); +} + +static uint32_t to_little_endian_u32(uint32_t val) +{ + return from_little_endian_u32(val); +} + static int jtag_vpi_send_cmd(struct vpi_cmd *vpi) { + /* Always 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). */ + vpi->cmd = to_little_endian_u32(vpi->cmd); + vpi->length = to_little_endian_u32(vpi->length); + vpi->nb_bits = to_little_endian_u32(vpi->nb_bits); int retval = write_socket(sockfd, vpi, sizeof(struct vpi_cmd)); if (retval <= 0) return ERROR_FAIL; @@ -76,6 +99,11 @@ static int jtag_vpi_receive_cmd(struct vpi_cmd *vpi) if (retval < (int)sizeof(struct vpi_cmd)) return ERROR_FAIL; + /* Always use little endian when transmitting/receiving jtag_vpi cmds. */ + vpi->cmd = from_little_endian_u32(vpi->cmd); + vpi->length = from_little_endian_u32(vpi->length); + vpi->nb_bits = from_little_endian_u32(vpi->nb_bits); + return ERROR_OK; } -- _______________________________________________ OpenOCD-devel mailing list OpenOCD-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openocd-devel