Skip to content

Commit

Permalink
Initial work towards XVCD protocol support in jtagd. Still have to do…
Browse files Browse the repository at this point in the history
… shift command.
  • Loading branch information
azonenberg committed Jan 30, 2019
1 parent c6ee4ba commit 4a6a07a
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 6 deletions.
2 changes: 1 addition & 1 deletion jtagd/CMakeLists.txt
Expand Up @@ -3,7 +3,7 @@
set(PROTOBUF_DIR ${CMAKE_BINARY_DIR}/protobufs)
include_directories(${PROTOBUF_DIR})

set(JTAGD_SOURCES main.cpp ConnectionThread.cpp)
set(JTAGD_SOURCES main.cpp ConnectionThread.cpp XvcdConnectionThread.cpp)

add_executable(jtagd
${JTAGD_SOURCES})
Expand Down
4 changes: 2 additions & 2 deletions jtagd/ConnectionThread.cpp
Expand Up @@ -2,7 +2,7 @@
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2016 Andrew D. Zonenberg *
* Copyright (c) 2012-2019 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
Expand Down Expand Up @@ -38,7 +38,7 @@
using namespace std;

/**
@brief Main function for handling connections
@brief Main function for handling connections using our native protocol
*/
void ProcessConnection(TestInterface* iface, Socket& client)
{
Expand Down
124 changes: 124 additions & 0 deletions jtagd/XvcdConnectionThread.cpp
@@ -0,0 +1,124 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2019 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

/**
@file
@author Andrew D. Zonenberg
@brief Main function for handling connections from client
*/
#include "jtagd.h"
#include "../../lib/jtaghal/ProtobufHelpers.h"

using namespace std;

/**
@brief Main function for handling connections using the XVCD protocol
*/
void ProcessXvcdConnection(TestInterface* iface, Socket& client)
{
try
{
//Set no-delay flag
if(!client.DisableNagle())
{
throw JtagExceptionWrapper(
"Failed to set TCP_NODELAY",
"");
}

//Pre-cache casted versions of the interface.
//JTAG only, no SWD or GPIO supported
auto jface = dynamic_cast<JtagInterface*>(iface);

//"shift:", 32 bit little endian word, strings of bits
//open_hw_target -xvc_url localhost:2542
while(true)
{
//Read command (bytes until we get a colon)
//All commands are at least six bytes long
unsigned char cmdbuf[128] = {0};
client.RecvLooped(cmdbuf, 6);
LogDebug("start: %s\n", cmdbuf);

//Should be "getinfo:", read 2 more bytes to make sure
if(cmdbuf[0] == 'g')
{
client.RecvLooped(cmdbuf+6, 2);
LogDebug("command: %s\n", cmdbuf);
if(0 != strcmp((char*)cmdbuf, "getinfo:"))
{
throw JtagExceptionWrapper(
"Got a garbage command (expected getinfo, got something else)",
"");
}

const char* info = "xvcServer_v1.0:2048\n";
LogDebug("sending %s\n", info);
client.SendLooped((const unsigned char*)info, strlen(info));
}

//Is it a shift command?
else if(!strcmp((char*)cmdbuf, "shift:"))
{
throw JtagExceptionWrapper(
"shift command not supported",
"");
}

//Nope, must be settck
else
{
client.RecvLooped(cmdbuf+6, 1);
if(0 != strcmp((char*)cmdbuf, "settck:"))
{
throw JtagExceptionWrapper(
"Got a garbage command (expected settck, got something else)",
"");
}

//Read the clock speed
uint32_t clock_period_ns;
client.RecvLooped((unsigned char*)&clock_period_ns, 4);
float clock_mhz = 1000.0f / clock_period_ns;
LogDebug("Client requested clock period %d ns (%.2f MHz)\n",
clock_period_ns, clock_mhz);
LogNotice("Ignoring requested clock speed (unimplemented)\n");

client.SendLooped((unsigned char*)&clock_period_ns, 4);
}
}
}
catch(JtagException& ex)
{
//Socket closed? Don't display the message, it just spams the console
if(ex.GetDescription().find("Socket closed") == string::npos)
LogError("%s\n", ex.GetDescription().c_str());
fflush(stdout);
}
}
2 changes: 1 addition & 1 deletion jtagd/jtagd.h
Expand Up @@ -49,11 +49,11 @@
#include "../../lib/xptools/Socket.h"

//TODO: generate git version string somehow?
//#include <svnversion.h>

#include "../../lib/jtaghal/jtaghal.h"
#include "jtagd_opcodes_enum.h"

void ProcessConnection(TestInterface* iface, Socket& client);
void ProcessXvcdConnection(TestInterface* iface, Socket& client);

#endif
41 changes: 39 additions & 2 deletions jtagd/main.cpp
Expand Up @@ -2,7 +2,7 @@
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2017 Andrew D. Zonenberg *
* Copyright (c) 2012-2019 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
Expand Down Expand Up @@ -69,6 +69,12 @@ int main(int argc, char* argv[])
TRANSPORT_SWD
} transport_type = TRANSPORT_JTAG;

enum sock_protocols
{
PROTO_JTAGHAL,
PROTO_XVCD
} socket_protocol = PROTO_JTAGHAL;

Severity console_verbosity = Severity::NOTICE;

//Operations to do
Expand Down Expand Up @@ -133,6 +139,26 @@ int main(int argc, char* argv[])
return 1;
}
}
else if(s == "--proto")
{
if(i+1 >= argc)
{
throw JtagExceptionWrapper(
"Not enough arguments",
"");
}

string st = argv[++i];
if(st == "jtaghal")
socket_protocol = PROTO_JTAGHAL;
else if(st == "xvcd")
socket_protocol = PROTO_XVCD;
else
{
printf("Unrecognized protocol \"%s\", use --help\n", st.c_str());
return 1;
}
}
else if(s == "--help")
op = OP_HELP;
else if(s == "--list")
Expand Down Expand Up @@ -358,7 +384,15 @@ int main(int argc, char* argv[])
if(!client.IsValid())
break;
LogNotice("Client connected\n");
ProcessConnection(iface, client);
switch(socket_protocol)
{
case PROTO_JTAGHAL:
ProcessConnection(iface, client);
break;
case PROTO_XVCD:
ProcessXvcdConnection(iface, client);
break;
}
LogNotice("Client disconnected\n");
}
catch(const JtagException& ex)
Expand Down Expand Up @@ -427,6 +461,9 @@ void ShowUsage()
" --ftdi_layout LAYOUT Specifies the FTDI adapter configuration to use. This argument is mandatory\n"
" if --api ftdi is specified.\n"
" Legal values: jtagkey, hs1\n"
" --protocol jtaghal|xvcd Specifies the socket protocol to use.\n"
" jtaghal: high level protobuf based, supports metadata\n"
" xvcd: low level protocol compatible with Xilinx XVC protocol\n"
" --transport jtag|swd Specifies the protocol the target speaks (JTAG or SWD). Defaults to JTAG.\n"
" Some adapters or targets may only support one mode; some support both.\n"
" --help Displays this message and exits.\n"
Expand Down

0 comments on commit 4a6a07a

Please sign in to comment.