jtag_vpi: make the server address configurable

Change-Id: I58e89c789b79ffb0b54ef94d208be876c271ddf7
Signed-off-by: Franck Jullien <franck.jullien@gmail.com>
Reviewed-on: http://openocd.zylin.com/1840
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
This commit is contained in:
Franck Jullien 2013-12-29 16:18:51 +01:00 committed by Spencer Oliver
parent f4947e8b88
commit bc256b17d5
2 changed files with 39 additions and 5 deletions

View File

@ -42,6 +42,7 @@
#define CMD_STOP_SIMU 4
int server_port = SERVER_PORT;
char *server_address;
int sockfd;
struct sockaddr_in serv_addr;
@ -379,7 +380,10 @@ static int jtag_vpi_init(void)
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(server_port);
serv_addr.sin_addr.s_addr = inet_addr(SERVER_ADDRESS);
if (!server_address)
server_address = strdup(SERVER_ADDRESS);
serv_addr.sin_addr.s_addr = inet_addr(server_address);
if (serv_addr.sin_addr.s_addr == INADDR_NONE) {
LOG_ERROR("inet_addr error occured");
@ -388,17 +392,18 @@ static int jtag_vpi_init(void)
if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
close(sockfd);
LOG_ERROR("Can't connect to %s : %u", SERVER_ADDRESS, server_port);
LOG_ERROR("Can't connect to %s : %u", server_address, server_port);
return ERROR_COMMAND_CLOSE_CONNECTION;
}
LOG_INFO("Connection to %s : %u succeed", SERVER_ADDRESS, server_port);
LOG_INFO("Connection to %s : %u succeed", server_address, server_port);
return ERROR_OK;
}
static int jtag_vpi_quit(void)
{
free(server_address);
return close(sockfd);
}
@ -414,6 +419,20 @@ COMMAND_HANDLER(jtag_vpi_set_port)
return ERROR_OK;
}
COMMAND_HANDLER(jtag_vpi_set_address)
{
free(server_address);
if (CMD_ARGC == 0) {
LOG_WARNING("You need to set an address");
server_address = strdup(SERVER_ADDRESS);
} else
server_address = strdup(CMD_ARGV[0]);
LOG_INFO("Set server address to %s", server_address);
return ERROR_OK;
}
static const struct command_registration jtag_vpi_command_handlers[] = {
{
@ -423,6 +442,13 @@ static const struct command_registration jtag_vpi_command_handlers[] = {
.help = "set the port of the VPI server",
.usage = "description_string",
},
{
.name = "jtag_vpi_set_address",
.handler = &jtag_vpi_set_address,
.mode = COMMAND_CONFIG,
.help = "set the address of the VPI server",
.usage = "description_string",
},
COMMAND_REGISTRATION_DONE
};

View File

@ -1,10 +1,18 @@
interface jtag_vpi
# Set the VPI JTAG server address
# Set the VPI JTAG server port
if { [info exists VPI_PORT] } {
set _VPI_PORT $VPI_PORT
} else {
set _VPI_PORT 50020
set _VPI_PORT 5555
}
# Set the VPI JTAG server address
if { [info exists VPI_ADDRESS] } {
set _VPI_ADDRESS $VPI_ADDRESS
} else {
set _VPI_ADDRESS "127.0.0.1"
}
jtag_vpi_set_port $_VPI_PORT
jtag_vpi_set_address $_VPI_ADDRESS