Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20706 Discussions

jtag interface from user aplication

Altera_Forum
Honored Contributor II
2,808 Views

Hi, 

 

I'm trying to access the jtag port inside the fpga with the alt_jtag_atlantic block (also used in the jtag_uart for the niosII processor).  

 

I need access to the jtag port from a custom C/C++ program. I tried an approach like in this link :  

 

http://nioswiki.jot.com/wikihome/highspeedimagedownloaddemo 

 

but then in Visual studio (not g++). 

 

I have a problem about the "int jtagatlantic_get_error(const char * * other_info);" function from inside the jtag_atlantic dll. 

 

The error is an undefined reference :  

 

error LNK2019: unresolved external symbol "int __cdecl jtagatlantic_get_error(char const * *)" (?jtagatlantic_get_error@@YAHPAPBD@Z) referenced in function _main 

 

Does anyone has experience with this, or knows where I can find more information? 

 

Stefaan
0 Kudos
17 Replies
Altera_Forum
Honored Contributor II
1,673 Views

I think, in Visual Studio you have write an import lib to interface jtag_atlantic_api.dll. That's nothing particular to Nios II or virtual JTAG, just a normal windows procedure. As the imported dll functions are known by name and type, this shouln't be a problem. If you experience any name-mangling problems, they could be imported by index rather than by name.

0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

Indeed, I created an import library, ... did all the dumpbin, lib ... stuff, and still for this one function the undefined reference is still there.... 

 

I can use the open, read, write, close functionality, so it's not an urgent problem.  

Anyway, get the correct error response can save some time.  

 

I wondered if somebody did this before... 

 

Stefaan
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

So, if you created an import library, you should be able to see from symbol files what's wrong. A link error is completely within your self-written code.

0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

I know it's completely on my side. The problem is I did'nt know exactly how to call the jtagatlantic_get_error function.  

 

As in the example on the nioswiki, it returns an int. But here the visual studio compiler compains on (the exammple is made on gcc). 

 

With some tool called "PE explorer", I could find out that the function retuns an enum called JATL_ERROR. Defining the function like this, and the enum, everything works like expected.  

 

Stefaan
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

I rembered your post, when I stumbled upon the same enum issue with MSVC. I can supply now a small example application, including the MSVC import library and modified include file. 

 

Best regards, 

Frank 

 

P.S.: As another comment, jtag_atlantic.dll is only seeing JTAG UART (NODE_ID 0x80) virtual JTAG functions. To interface any other virtual JTAG node type, you have to go through jtag_client.dll. According to the exported functions, sld_hapi.dll is providing an interface similar to virtual JTAG tcl commands provided by quartus_stp, as documented in TclScriptRefMnl.pdf. Unfortunately there's no interface documentation for both DLLs. 

 

Another option is using generic JTAG interfaces and implementing the virtual JTAG protocol, as discussed in other threads.
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

FvM, 

 

I am curious as to the procedure that you used to create the jtag_atlantic.lib import library for use with MSVC environment. Can you tell me how you did it in detail? I would appreciate it.
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

The first step was to extract a *.def file from the dll, I used Borland IMPDEF for this action. I'm not sure if there's a similar MS tool. 

IMPDEF jtag_atlantic.def jtag_atlantic.dll 

 

As the second step, the *.def is compiled to *.lib by MS LIB 

LIB /DEF:jtag_atlantic.def /OUT:jtag_atlantic.lib 

Respectively, a Borland library can be generated by Borland LIB util. 

 

Regarding general Virtual JTAG operation, sld_hapi.dll seems to contain the complete functionality.
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

FvM, 

 

Unfortunately, I am operating in the MSVC world. There is no such utility as IMPDEF.exe. However, using your method a did a bit of research and came up with a method to create the import library successfully. I tested it and it works correctly. I will attach my instructions to this post for others. 

 

Guten Tag und Danke, 

 

RNM
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

As you pointed out, DUMPBIN is the respective MSVC tool. I forgot about it, because I'm equipped with this software stuff very rarely. 

 

The other point is the possible requirement of making some modifications to DLL imports to handle incompatibility issues between tool chains.
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

Hey guys, I was attempting to follow these instructions, and you will have to forgive me, as I am software guy...  

 

So I downloaded the sample aplication, and planned to test it out by writing to my device through the uart jtag, and seeing it recieved using the NIOS IDE debugger.  

 

Unfortunately, I think you can only use 1 device at a time, so I have tried closing out the debugger after programming (to my fpga's ram) and I still could not recieve any text using the sample application. 

 

This lead me to believe that maybe my app wasn't running after I closed out the NIOS IDE, so I preprogrammed the ram with my flashed and redownloaded the image. This also did not work. 

 

Anyone have some tips on what I might be doing wrong? Thanks.
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

 

--- Quote Start ---  

I rembered your post, when I stumbled upon the same enum issue with MSVC. I can supply now a small example application, including the MSVC import library and modified include file. 

 

Best regards, 

Frank 

 

P.S.: As another comment, jtag_atlantic.dll is only seeing JTAG UART (NODE_ID 0x80) virtual JTAG functions. To interface any other virtual JTAG node type, you have to go through jtag_client.dll. According to the exported functions, sld_hapi.dll is providing an interface similar to virtual JTAG tcl commands provided by quartus_stp, as documented in TclScriptRefMnl.pdf. Unfortunately there's no interface documentation for both DLLs. 

 

Another option is using generic JTAG interfaces and implementing the virtual JTAG protocol, as discussed in other threads. 

--- Quote End ---  

 

================== 

Dear Frank, 

 

I tried the example MSVC application you've provided with Quartus 9.1 installed. Got strange issue: 

 

1) jtagatlantic_open (NULL, 0x0, -1, NULL) - OK 

2) jtagatlantic_flush - OK 

3) jtagatlantic_write(link, "Hello", 5) returns 5. Should be OK, but nothing is sent to NIOS target 

 

- When using nios2-terminal (command line or NIOS IDE) - works fine - NIOS target receives "Hello". 

- I sniffed JTAGserver on TCP/IP socket 1309 - can see activity at steps 1 and 2 (open, flush), but no activity at step 3. 

 

Also tried other JTAG_Atlantic examples (attached) - they work in Cygwin environment, but behave exactly as described above when compiled in MSVC. 

 

Did you try this sample application with recent releases of Quartus (9/10). May be something changed in JTAG_Atlantic.DLL in recent Quartus releases ? 

 

Would very appreciate your help. 

 

Sincerely, 

Juri Cizas 

Infineon Technologies
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

 

--- Quote Start ---  

Did you try this sample application with recent releases of Quartus (9/10) 

--- Quote End ---  

 

No, I'm not working with JTAG UART at present. It has been my starting point for virtual JTAG interface from PC applications. I have a number of test tools interfacing In-System Source&Probe and Memory Content Editor virtual JTAG function through sld_hapi.dll. Apparently, there are no changes from Quartus version 8 to version 9 related to this usage. 

 

Unfortunately, I have no idea what's going wrong. I'll try to look into it within the next days.  

 

Best regards, 

Frank
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

Dear Frank, 

 

Happy New Year! 

Very appreciate your help! 

By any chance, do you have any short description or example C/C++ code of sld_hapi.dll ? May be I can use it instead of Atlantic ? 

 

Sincerely, 

Juri Cizas
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

The jtag_atlantic_terminal returned some errors when compiling it in MSVC: :confused: 

 

1>JTAG.obj : error LNK2019: unresolved external symbol "void __cdecl jtagatlantic_close(struct JTAGATLANTIC *)" (?jtagatlantic_close@@YAXPAUJTAGATLANTIC@@@Z) referenced in function _main 1>JTAG.obj : error LNK2019: unresolved external symbol "int __cdecl jtagatlantic_flush(struct JTAGATLANTIC *)" (?jtagatlantic_flush@@YAHPAUJTAGATLANTIC@@@Z) referenced in function _main 1>JTAG.obj : error LNK2019: unresolved external symbol "int __cdecl jtagatlantic_write(struct JTAGATLANTIC *,char const *,unsigned int)" (?jtagatlantic_write@@YAHPAUJTAGATLANTIC@@PBDI@Z) referenced in function _main 1>JTAG.obj : error LNK2019: unresolved external symbol "int __cdecl jtagatlantic_get_error(char const * *)" (?jtagatlantic_get_error@@YAHPAPBD@Z) referenced in function _main 1>JTAG.obj : error LNK2019: unresolved external symbol "int __cdecl jtagatlantic_read(struct JTAGATLANTIC *,char *,unsigned int)" (?jtagatlantic_read@@YAHPAUJTAGATLANTIC@@PADI@Z) referenced in function _main 1>JTAG.obj : error LNK2019: unresolved external symbol "struct JTAGATLANTIC * __cdecl jtagatlantic_open(char const *,int,int,char const *)" (?jtagatlantic_open@@YAPAUJTAGATLANTIC@@PBDHH0@Z) referenced in function _main
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

You get unresolved external when not adding jtag_atlantic.lib to the project.

0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

 

--- Quote Start ---  

I have a number of test tools interfacing In-System Source&Probe and Memory Content Editor virtual JTAG function through sld_hapi.dll. 

--- Quote End ---  

 

 

Hi, 

 

Could you tell me how did you find the function prototypes from the sld_hapi.dll ? 

I managed to get a dynamic lib usable in cygwin (following this : http://www.emmestech.com/moron_guides/moron1.html (http://www.emmestech.com/moron_guides/moron1.html) ) but now I can't find prototypes. 

 

I tried to use Dependency Walker but exported function seems to be not "decorated". 

 

Thanks in adavance for your help. 

 

Franck.
0 Kudos
Altera_Forum
Honored Contributor II
1,673 Views

Hi 

 

I'm trying to use the jtagatlantic library, but I have a problem when I call the function jtagatlantic_open(). I want to build a program with Dev-C++ to send data to the Nios II processor in my FPGA board. 

 

If I load the Nios II system in the board and I run the software in the Nios II processor since the Nios II SBT for Eclipse, when I run my C++ program the function jtagAtlantic_open() don't open the link. The function jtagatlantic_get_error() returns the value -6 (Target or port in use, see other_info) and the parameter other_info contains "Nios2 on 127.0.0.1". 

 

In the other hand, If I load the Nios II system but I don´t run any software in the Nios II processor, then the function jtagatlantic_open() run well. 

 

So, I think the problem is that the jtag uart can't be used at the same time by jtag atlantic and the Nios II program. 

 

What can I do about it? 

 

Thanks, 

David
0 Kudos
Reply