How do I place the libaplc library in external memory ?

Discussion about Parallella (and Epiphany) Software Development

Moderators: amylaar, jeremybennett, simoncook

Re: How do I place the libaplc library in external memory ?

Postby ysapir » Thu Jun 06, 2013 3:02 pm

1. First, please make the distinction between "Parallella" and "Epiphany". Parallella is the name of the computer, including a dual-core ARM processor and an Epiphany coprocessor. When you build "for Parallella", do you actually mean "for Epiphany"?

2.
On the PC under Cygwin, using the latest sdk for Cygwin built from GitHub

Are you referring to the GNU tools repo from the Parallella GitHub, or the eSDK repo from Adapteva GitHub? (we will change the confusing naming soon). Or, is it Cygwin SDK (whatever this may be) that you are referring to, and this has no relationship to Epiphany/Parallella?


3.
On the PC, cross-building a Parallella version, from the .c we have just created

This cross build means building on PC, for Epiphany using the esdk.4.13.04.24? Is this under Cygwin?


4.
On the Arm under Linux, using esdk.4.13.03.30_linux_armv7l.tgz .... So native Arm under Linux version runs OK.

So, you mean that you build on the ZedBoard (Parallella) itself, with ARM as a target? This has nothing to do with the Epiphany?


5.
Cross build on the Arm for Parallella

This means building on the ZedBoard with Epiphany as a target, right?


6.
Turn on function trace

This is just instrumentation added to the C program, right (merely printf's at keypoints in the C functions)?


7.
sprintf(pointer++,"%c",trs1.value.cp[i3]);

Why "pointer++" and not just "pointer"? Oh wait... are you trying to print the string in cp[] one character at a time in a loop (on i3)? Why? Are you sure that the content of cp[] are ASCII letters, and not some numerical values (unprintable control characters)? In other words, does cp[] contain the values {1,2,3..9}, or the characters {'1', '2', '3',...'9'}?


8.
So the simpler sprintf statements work, but the more complex ones, which should be outputting after above messages, are failing silently again under this newlib.

So if I understand correctly, the problem is that sprintf() with format specifiers basically does not parse the format string and not read the data arguments? Like "sprintf(p, "ABC");" works fine, but "sprintf(p, "ABC %d", 32);" does not?


9. Lastly, when building for Epiphany, are you using the legacy.ldf from the Zed_E16G3_512mb BSP?
User avatar
ysapir
 
Posts: 393
Joined: Tue Dec 11, 2012 7:05 pm

Re: How do I place the libaplc library in external memory ?

Postby ysapir » Thu Jun 06, 2013 3:16 pm

By default, the e-run simulator uses a memory map different than that of the actual ZedBoard. When using external memory, I'd expect receiving error messages when addressing the Zed's external mem range in a simulated session. This is basically what you do when compiling with legacy.ldf and using the heap.

However, on your printouts, I see no such error messages. This suggests that the linker places the code internally (could you please check that with e-objdump?) and that the simple printf() does not require the heap (which makes sense). OTOH, more complex format strings do require dynamic memory allocation so heap is used. Then, I'd expect to see some errors.

When using e-run for ZedBoard built programs, please add the option: "--memory-region 0x8e000000,0x02000000" to the command line.
User avatar
ysapir
 
Posts: 393
Joined: Tue Dec 11, 2012 7:05 pm

Re: How do I place the libaplc library in external memory ?

Postby Dr.BeauWebber » Thu Jun 06, 2013 8:34 pm

Phew a lot of questions - I will see what I can answer - it is 15 years since I have interacted much with the innards of c, I have mainly been working for my porous media research with APL interpreters.

1.
First, please make the distinction between "Parallella" and "Epiphany". Parallella is the name of the computer, including a dual-core ARM processor and an Epiphany coprocessor. When you build "for Parallella", do you actually mean "for Epiphany"?

OK thanks, I had this the wrong way round.

Following on from this, most important - when I am building the cross-compiling version of Apl, may I ask what the fully specified name for the system (i.e for my i7 laptop in Cygwin, it is i686-pc-cygwin) - what I currently have must be wrong, and we wish to build a tidy version of the current aplc for all the machines I have recently ported it to, including the Raspberry Pi (armv6), XMOS and both Parallella (armv7) and Epiphany.
2.
"On the PC under Cygwin, using the latest sdk for Cygwin built from GitHub."
Are you referring to the GNU tools repo from the Parallella GitHub, or the eSDK repo from Adapteva GitHub? (we will change the confusing naming soon). Or, is it Cygwin SDK (whatever this may be) that you are referring to, and this has no relationship to Epiphany/Parallella?

OK, for installing on my laptop I used the source of the sdk / gcc & e-gcc tool-chain using github, at [url]github.com/parallella/epiphany-sdk/wiki/Downloading-the-SDK[/url]
updated the tools as specified, and built a working copy.
3.
"On the PC, cross-building a Parallella version, from the .c we have just created"
This cross build means building on PC, for Epiphany using the esdk.4.13.04.24? Is this under Cygwin?

Almost; did it using the above sdk from github, yes under Cygwin.
I only found the esdk.4.13.04.24 later, and although I have downloaded it I have not yet fully understood how and where to deploy it with the other tools - it says it needs the gcc toolchain as well.
4.
"On the Arm under Linux, using esdk.4.13.03.30_linux_armv7l.tgz .... So native Arm under Linux version runs OK."
So, you mean that you build on the ZedBoard (Parallella) itself, with ARM as a target? This has nothing to do with the Epiphany?

Yes, as I say I had the names swapped.
5.
"Cross build on the Arm for Parallella"
This means building on the ZedBoard with Epiphany as a target, right?

Yes, Ditto.
6.
Turn on function trace
This is just instrumentation added to the C program, right (merely printf's at keypoints in the C functions)?

Slightly more complicated - turning on a function call that is already there, but yes.
7.a
Wsprintf(pointer++,"%c",trs1.value.cp[i3]);"
Why "pointer++" and not just "pointer"? Oh wait... are you trying to print the string in cp[] one character at a time in a loop (on i3)? Why?

Seems stupid for this simple case of printing a vector already in memory, but actually normally it might more generally be the output of a complex set of array and selection operations mapping values and structures all over the place. One could add (think I have) special case handling, but it just makes the compiler bigger and more complicated to maintain and this has been junked.
7.b
Are you sure that the content of cp[] are ASCII letters, and not some numerical values (unprintable control characters)? In other words, does cp[] contain the values {1,2,3..9}, or the characters {'1', '2', '3',...'9'}?

Ah but the Aplc compiler goes to a lot of trouble to check inputs and keep track of all the transforms that change these, so it knows and outputs code appropriately.
A simple mixed example :

Code: Select all
A .is 5 7 .rho .iota 35
A
Txt .is 'Hello'
Txt
A[;2 7] .is 0
A
A[3;2 3 4  5 6] .is Txt
A


Code: Select all
  1  2  3  4  5  6  7
  8  9 10 11 12 13 14
 15 16 17 18 19 20 21
 22 23 24 25 26 27 28
 29 30 31 32 33 34 35
Hello
  1 0  3  4  5  6 0
  8 0 10 11 12 13 0
 15 0 17 18 19 20 0
 22 0 24 25 26 27 0
 29 0 31 32 33 34 0
+---+--+---+---+---+---+--+
| 1 | 0| 3 | 4 | 5 | 6 | 0|
+---+--+---+---+---+---+--+
| 8 | 0| 10| 11| 12| 13| 0|
+---+--+---+---+---+---+--+
| 15|H |e  |l  |l  |o  | 0|
+---+--+---+---+---+---+--+
| 22| 0| 24| 25| 26| 27| 0|
+---+--+---+---+---+---+--+
| 29| 0| 31| 32| 33| 34| 0|
+---+--+---+---+---+---+--+

(boxed output to indicate mixed output, but boxing can be turned off)
8.
"So the simpler sprintf statements work, but the more complex ones, which should be outputting after above messages, are failing silently again under this newlib."
So if I understand correctly, the problem is that sprintf() with format specifiers basically does not parse the format string and not read the data arguments? Like "sprintf(p, "ABC");" works fine, but "sprintf(p, "ABC %d", 32);" does not?

Yes I believe so - also fprintf fails in same way. As I say, works fine using e-run on my machine.
9. Lastly, when building for Epiphany, are you using the legacy.ldf from the Zed_E16G3_512mb BSP?

Not sure, it is the one in the same directory that the hello_world.c example points at : /opt/adapteva/esdk/bsps/current
Ah yes I was advised to upgrade the BSP package early on, But I can't right now find which version.
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England

Re: How do I place the libaplc library in external memory ?

Postby Dr.BeauWebber » Thu Jun 06, 2013 8:38 pm

When using e-run for ZedBoard built programs, please add the option: "--memory-region 0x8e000000,0x02000000" to the command line.

Ah thanks, I did not realise it was actually possible to still use e-run for these programs set up actually for the hardware.
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England

Re: How do I place the libaplc library in external memory ?

Postby Dr.BeauWebber » Fri Jun 07, 2013 10:54 am

OK I have prepared a set of .out files on the PC, and copied them to the ZedBoard.
All of these now run fine using e-run :
i.e.:
Code: Select all
$ e-run aplc_helloworld.out
Hello World from Aplc

Code: Select all
$ e-run vector_sum.out
 1 2 3 4 5 6 7 8 9
 45

Code: Select all
$ e-run matrix.out
A:
 1 2 3 4 5

B:
 1 2 3 4 5 6 7 8 9

C: outer product:
 1  2  3  4  5  6  7  8  9
 2  4  6  8 10 12 14 16 18
 3  6  9 12 15 18 21 24 27
 4  8 12 16 20 24 28 32 36
 5 10 15 20 25 30 35 40 45

T: transpose:
 1  2  3  4  5
 2  4  6  8 10
 3  6  9 12 15
 4  8 12 16 20
 5 10 15 20 25
 6 12 18 24 30
 7 14 21 28 35
 8 16 24 32 40
 9 18 27 36 45

O: inner product (matrix multiply):
  285  570  855 1140 1425
  570 1140 1710 2280 2850
  855 1710 2565 3420 4275
 1140 2280 3420 4560 5700
 1425 2850 4275 5700 7125

S: solve matrix:
 1 2 3 4 5 6 7 8 9

Code: Select all
$ e-run mixed.out
  1  2  3  4  5  6  7
  8  9 10 11 12 13 14
 15 16 17 18 19 20 21
 22 23 24 25 26 27 28
 29 30 31 32 33 34 35
Hello
  1 0  3  4  5  6 0
  8 0 10 11 12 13 0
 15 0 17 18 19 20 0
 22 0 24 25 26 27 0
 29 0 31 32 33 34 0
+---+--+---+---+---+---+--+
| 1 | 0| 3 | 4 | 5 | 6 | 0|
+---+--+---+---+---+---+--+
| 8 | 0| 10| 11| 12| 13| 0|
+---+--+---+---+---+---+--+
| 15|H |e  |l  |l  |o  | 0|
+---+--+---+---+---+---+--+
| 22| 0| 24| 25| 26| 27| 0|
+---+--+---+---+---+---+--+
| 29| 0| 31| 32| 33| 34| 0|
+---+--+---+---+---+---+--+

So now to see what happens for the code running on Epiphany.
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England

Re: How do I place the libaplc library in external memory ?

Postby Dr.BeauWebber » Fri Jun 07, 2013 6:46 pm

OK, to see if I can build code that will run on the Epiphany cores, by building on my PC :

I have copied the directory where I build it to my PC;
Edit files so as to satisfy include and library calls;
Build new .elf and .srec files;
Copy these to the Debug folder on the ZedBoard.
Run the run script.

This procedure appears to be intact, in that I can change the text emitted by simple sprintf statements.
However I have failed to obtain text from the more complex sprintf statements.

Thus I conclude that in my libraries fprintf has been fixed, but sprintf is still effectively a no-op.

Until the c to .elf translation is fixed for fprintf and sprintf I can not think of anything more I can do to get Apl ported to the Epiphany cores. As I show in my previous posting, I can produce versions on my laptop that e-run on the Parallella armv7.
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England

Re: How do I place the libaplc library in external memory ?

Postby aolofsson » Fri Jun 07, 2013 9:37 pm

Just want to throw in my two cents in case it was missed. You can load programs into the the Epiphany cores by using the e-gdb and e-server (as described in the SDK reference). What may not have been clear in the manual is that this allows the Epiphany core to "tunnel" through the gdb client to do file IO. (although there may be limitations, we have mostly used it for printf() )

Andreas
User avatar
aolofsson
 
Posts: 1005
Joined: Tue Dec 11, 2012 6:59 pm
Location: Lexington, Massachusetts,USA

Re: How do I place the libaplc library in external memory ?

Postby Dr.BeauWebber » Fri Jun 07, 2013 9:45 pm

Oh, that could be just what we need.
I will go read this documentation.
If you have an printf example, I can try it very quickly by turning on the Trace mode, which used printf.
Thanks indeed and congratulations to the whole team - I have just read the latest Kickstarter news item.
cheers, and all the best,
Beau
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England

Re: How do I place the libaplc library in external memory ?

Postby ysapir » Sat Jun 08, 2013 1:36 am

A simple C "hello world" standard program should be fine for testing printf() with the debugger.

Note what Andreas offered is intended to run an Epiphany program, not a host-device program. As far as I understand, your host program merely serves as a print server, so you should be fine with replacing it by the debugger.
User avatar
ysapir
 
Posts: 393
Joined: Tue Dec 11, 2012 7:05 pm

Re: How do I place the libaplc library in external memory ?

Postby Dr.BeauWebber » Sat Jun 08, 2013 12:59 pm

Hmm, it is a long time since I have had to use a debugger.
But the text in the SDK manual is very simple and clear, and I have followed it.
But I am still having problems, it seems to be hanging just where I am expecting output from either program.
Help appreciated. Am I doing something wrong ?

I have been able to load and step part-way through both a simple helloworld.c program (below) to which I have just added the #include "e_lib.h" statement, and an aplc vector_sum.c program.
helloworld.c :
Code: Select all
/* Hello World program */
#include<stdio.h>
#include "e_lib.h"

main()
{
    printf("Hello World\n");

}

this compiles and runs fine under e-run, using just
Code: Select all
e-gcc -g helloworld.c


But to get a version that will run in e-gdb, I have used :
Code: Select all
 e-gcc -g -T ${ELDF} -I $EINCS  -L ${ELIBS}   src/$PROGRAM.c -o Debug/$TARGET.elf -le-lib

with ELDF=${ESDK}/bsps/current/legacy.ldf
Is this right ?

I can then follow the steps for e-db :
Code: Select all
e-gdb target.elf
GNU gdb (Epiphany toolchain 20120120 (built 20130104)) 7.4.50.20120120-cvs
......
Reading symbols from /home/linaro/Src/Parallella/e-examples/Skeleton/Debug/target.elf...done.
(gdb) target remote:51000
Remote debugging using :51000
0x00000000 in start ()
(gdb) load
Loading section ivt_reset, size 0x4 lma 0x0
Loading section .reserved_crt0, size 0xe lma 0x32
Loading section NEW_LIB_RO, size 0x2a74 lma 0x8e000000
Loading section NEW_LIB_WR, size 0x864 lma 0x8e002a74
Loading section GNU_C_BUILTIN_LIB_RO, size 0x6 lma 0x8e0032d8
Loading section .init, size 0x10 lma 0x8e0032de
Loading section .text, size 0x188 lma 0x8e0032f0
Loading section .fini, size 0x10 lma 0x8e003478
Loading section .init_array, size 0x4 lma 0x8e003488
Loading section .fini_array, size 0x4 lma 0x8e00348c
Loading section .jcr, size 0x4 lma 0x8e003490
Loading section .data, size 0x4 lma 0x8e003494
Loading section .rodata, size 0x20 lma 0x8e003498
Start address 0x0, load size 13512
Transfer rate: 82 KB/sec, 450 bytes/write.
(gdb) b main
Breakpoint 1 at 0x8e003450: file src/helloworld.c, line 9.
(gdb) c
Continuing.

Breakpoint 1, main () at src/helloworld.c:9
9           printf("Hello World\n");
(gdb) c
Continuing.
^C
Program received signal SIGHUP, Hangup.
_puts_r (ptr=0x8e002a80, s=0x8e003498 "Hello World")
    at /home/linaro/work/epiphany/sdk/../srcw/newlib/libc/stdio/puts.c:81
81      /home/linaro/work/epiphany/sdk/../srcw/newlib/libc/stdio/puts.c: No such file or directory.
(gdb) quit

I have tried building the .elf file on both the Parallella Arm and on the PC.
Hmm there seems to be something wrong with that path to newlib ... chasing.
Ah, I think that is where the sources were when the e-libraries were compiled - can't find them anywhere now.
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England

PreviousNext

Return to Programming Q & A

Who is online

Users browsing this forum: No registered users and 4 guests

cron