ET_ILLEGAL_RESSOURCE in xtcp

Technical questions regarding the XTC tools and programming with XMOS.
DemoniacMilk
XCore Addict
Posts: 191
Joined: Tue Jul 05, 2016 2:19 pm

ET_ILLEGAL_RESSOURCE in xtcp

Post by DemoniacMilk »

Using TFTP for firmware uploads, im running into an interesting problem:

The first file upload works well, while the second file upload will lead to an ET_ILLEGAL_RESSOURCE exception in xtcp, in file xtcp_server.xc, at location:
et_illegal_ressource.PNG
(or, as a non image version:

Code: Select all

static transaction do_recv(chanend xtcp, int &client_ready,
                           int datalen, unsigned char data[])
{
  xtcp :> client_ready;  <--- ET_ILLEGAL_RESSOURCE exception here
  if (client_ready) {
    xtcp <: datalen;
    for (int i=0;i<datalen;i++)
      xtcp <: data[i];
  }
}
)

the debug info (info reg/program/stack)

Code: Select all

info reg
r0             0x80021802	-2147346430
r1             0x0	0
r2             0x45	69
r3             0x67fdc	425948
r4             0x80021802	-2147346430
r5             0x67fdc	425948
r6             0x2	2
r7             0x1	1
r8             0x7fbf8	523256
r9             0x67fe0	425952
r10            0x1	1
r11            0xffffffff	-1
cp             0x53cc8	343240
dp             0x55190	348560
sp             0x7f470	521328
lr             0x40088	262280	 _InitChildThread + 0
pc             0x4ad3c	306492	 xtcpd_recv + 76
sr             0x10	16
spc            0x4ad3c	306492	 xtcpd_recv + 76
ssr            0x100	256
et             0x14	20
ed             0x80021802	-2147346430
sed            0x80021802	-2147346430
kep            0x40080	262272
ksp            0x4ba30	309808

info program
Program stopped at 0x4ad3c.
It stopped with signal ET_ILLEGAL_RESOURCE, Resource exception.
Type "info stack" or "info registers" for more information.

info stack
#0  do_recv () at C:/Users/Lars/Desktop/xCoreWorkspaceTest/lib_xtcp_xor/src/xtcp_server.xc:337
#1  xtcpd_recv (xtcp=@0x7fbf8, linknum=1, num_xtcp=2, s=@0x67fdc, datalen=25, data=<value optimized out>) at C:/Users/Lars/Desktop/xCoreWorkspaceTest/lib_xtcp_xor/src/xtcp_server.xc:361
#2  0x00053c14 in xtcpd_recv.thunk.10 ()
#3  0xffffffff in ?? ()
Backtrace stopped: frame did not save the PC
pc and spc have the same value, is that to be expected?

and the disassembly:

Code: Select all

361           master do_recv(xtcp[linknum], client_ready, datalen, data);
0004ad38:   outct (rus)     res[r4], 0x1 *
0004ad3a:   nop (0r)        
337         xtcp :> client_ready;
0004ad3c:   in (2r)         r0, res[r4] *   <--- ET_ILLEGAL_RESSOURCE exception here
0004ad3e:   nop (0r)        
338         if (client_ready) {
0004ad40:   bf (lru6)       r0, -0xa
0004ad44:   ldc (ru6)       r0, 0x0
In general, what might be the cause for this exception, especially if it occurs on the second file transfer and not the first? (First send is fine, second does not get to sending a response for the first packet/block 0 in tftp connection establishment).
Based on what I understand, xtcp :> client_ready; should grab data from the channel and block/wait for data if no data is available, so the illegal ressource must be the channel itself? As the first file transfer works, the channel should be ok?
You do not have the required permissions to view the files attached to this post.
louis
Member
Posts: 9
Joined: Thu Sep 08, 2016 11:27 am

Post by louis »

Hi DemoniacMilk,

I've seen similar problems with XTCP, but not this specific case. One reason for an ET_ILLEGAL_RESOURCE can be when a command token is being sent on the channel and receiver is trying to use it as a value (such as when two threads are communicating out of sync), which could be what is happening here.

Future versions of this library don't use this interaction method (it uses interfaces instead) so should be free from this bug. It currently lives as a pull request on XMOS github, but will be merged in at some point in the next 4-6 weeks. If you'd like to have a go with it, you can find it here: https://github.com/louisja/lib_xtcp (and as a pull request here: https://github.com/xmos/lib_xtcp/pull/20).

Let me know if you do decide to have a go!

Cheers,
Louis
DemoniacMilk
XCore Addict
Posts: 191
Joined: Tue Jul 05, 2016 2:19 pm

Post by DemoniacMilk »

Thanks for letting me know, I'll finish up some more stuff related to what I am currently working on, then give it a go.
DemoniacMilk
XCore Addict
Posts: 191
Joined: Tue Jul 05, 2016 2:19 pm

Post by DemoniacMilk »

I was about to switch to the xtcp lib version you linked. It requires lib_crypto, that I do not find.

Are the webserver and tftp supported?
louis
Member
Posts: 9
Joined: Thu Sep 08, 2016 11:27 am

Post by louis »

I've just removed the dependancy on lib_crypto (thanks for that).

Unfortunately lib_webserver has yet to be updated on the main thread. However there is once again a fork that you can look at (not properly tested).

TFTP has not been migrated to the new version of lib_xtcp, although I will do this today, as it's a small fix. I'll post here once that's done.

Sorry about the patchiness of this library!

Cheers,
Louis

edit: It's a slightly more involved fix for TFTP that I first thought, although I will try and look at it early next week.
DemoniacMilk
XCore Addict
Posts: 191
Joined: Tue Jul 05, 2016 2:19 pm

Post by DemoniacMilk »

I might not be able to implement this in time then as I need to finish programming in about a week.

Would still love to test the new version after the current project is finished.