EmbDev.net

Forum: ARM programming with GCC/GNU tools Trouble installing Yagarto


von Eduardo F. (eduardodelpeloso)


Rate this post
useful
not useful
Hi people!

Although I am an experienced C/C++ PC programmer, I am a total newbie in 
the world of ARM C/C++ programming. I am trying to install the Yagarto 
GNU ARM Toolchain according to the instructions at
http://yagarto.de/howto.html
and I am experiencing some troble.

I have already installed and tested OpenOCD according to the 
instructions at http://yagarto.de/howto/openocd/index.html
It works just fine (I used the file openocd-r1888-20090523.exe).

Then I downloaded and installed the file
yagarto-bu-2.19.1_gcc-4.3.3-c-c++_nl-1.17.0_gi-6.8.50_20090329.exe
and started to test it according to the instructions at
http://yagarto.de/howto/yagarto1/index.html

When I try the command
arm-elf-gcc --version
at my cmd prompt it works allright (my OS is Win XP Pro SP3).
However, when I create the file main.c

int main (void)
{
   return(0);
}

and try to compile it with
arm-elf-gcc main.c

I get a gazillion errors.

Here are the error messages I get:

C:\Program files\yagarto\bin>arm-elf-gcc main.c
c:/Program 
files/yagarto/bin/../lib/gcc/arm-elf/4.3.3/../../../../arm-elf/lib\libc. 
a(lib_a-exit.o):  In function `exit':
C:\msys\1.0\home\yagarto\newlib-build\arm-elf\newlib\libc\stdlib/../../. 
./../../newlib-1.17.0/newlib/libc/stdlib/exit.c:65:  undefined reference 
to `_exit'
c:/Program 
files/yagarto/bin/../lib/gcc/arm-elf/4.3.3/../../../../arm-elf/lib\libc. 
a(lib_a-mallocr.o):  In function `malloc_extend_top':
C:\msys\1.0\home\yagarto\newlib-build\arm-elf\newlib\libc\stdlib/../../. 
./../../newlib-1.17.0/newlib/libc/stdlib/mallocr.c:2160:  undefined 
reference to `_sbrk_r'
C:\msys\1.0\home\yagarto\newlib-build\arm-elf\newlib\libc\stdlib/../../. 
./../../newlib-1.17.0/newlib/libc/stdlib/mallocr.c:2197:  undefined 
reference to `_sbrk_r'
c:/Program 
files/yagarto/bin/../lib/gcc/arm-elf/4.3.3/../../../../arm-elf/lib\libc. 
a(lib_a-freer.o):  In function `_malloc_trim_r':
C:\msys\1.0\home\yagarto\newlib-build\arm-elf\newlib\libc\stdlib/../../. 
./../../newlib-1.17.0/newlib/libc/stdlib/mallocr.c:3326:  undefined 
reference to `_sbrk_r'
C:\msys\1.0\home\yagarto\newlib-build\arm-elf\newlib\libc\stdlib/../../. 
./../../newlib-1.17.0/newlib/libc/stdlib/mallocr.c:3335:  undefined 
reference to `_sbrk_r'
C:\msys\1.0\home\yagarto\newlib-build\arm-elf\newlib\libc\stdlib/../../. 
./../../newlib-1.17.0/newlib/libc/stdlib/mallocr.c:3340:  undefined 
reference to `_sbrk_r'
collect2: ld returned 1 exit status

The stragest thing is that I have no
C:\msys
directory in my system... Should I??
Does this mean that there is something that I should have installed that 
I did not?

Googling for "yagarto msys" I found a guy who had the same problem
(http://forums.ladyada.net/viewtopic.php?f=8&t=10790).
Unfortunately, no one in the forum he posted the problem in had any 
knowledge of ARM programming.

Hope someone can help me...

Bye!

von Francis K. (dinosaurkfb)


Attached files:

Rate this post
useful
not useful
It's not an installation problem. just a link problem, when you do: 
arm-elf-gcc main.c
ld will link to libc.a, but many functions in newlibc required your 
system to offer some basic subroutines like sbrk, write, close, etc. So 
you should implement those subroutines in you system. An example is 
provided in my attachment. you can link it with your object.

more to learn, please see newlibc manual.
And you can refer to more examples in Martin THOMAS's project page at 
http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/

von Eduardo F. (eduardodelpeloso)


Rate this post
useful
not useful
Dear Francis Kong:

Thank you for your answer. However, my great lack of experience with 
embedded programming and with "linux-like" environments (commands like 
"ld", and libraries like "newlibc") makes it very difficult to me to 
understand much of it, or to use it to solve my problem. So I have a few 
more questions:

1) Is there a way to modify the installation procedure described at 
http://yagarto.de/howto.html so that I will not have these link 
problems?

2) If not, exactly what should I do? #include your syscalls.cpp source 
file in my main.c file?

Thank you once more!

von Francis K. (dinosaurkfb)


Rate this post
useful
not useful
That's a big problem if you don't understand what those basic concepts 
like ld and newlibc are.
i can tell you how to compile them and link them successfully, but they 
still cannot run in your board, there are a lot stuff to do to run even 
a simple helloworld in a board, so don't beg for a step-to-step howto to 
compile successfully, even if you succeed, you still don't understand 
it.
my suggestion is to learn those concept first, and obviously you don't 
understand embedded programming, you should also make it clear.and the 
more important is to find a board to run a example project in it. by 
studying this project deeply, you may understand how it works and you 
will be close to a embedded programmer.Good luck.

von Eduardo F. (eduardodelpeloso)


Rate this post
useful
not useful
Dear Francis Kong:

Yes, I know I have much work to do... I have already ordered an 
evaluation board. It is a Keil MCB2388, populated by a NXP LPC2388 
processor (an ARM7TDMI-S), and a JTAG.

But before starting to learn how to program the board, I was already 
looking for a free IDE to facilitate my work. That is why I was very 
happy when I found out about Yagarto. It promises integrated compiling 
(via GCC), debugging (via OpenOCD), and a friendly development 
environment (via Eclipse), all free of charge. And more: the JTAG that I 
bought (called JTAGkey) is said to be fully compatible with OpenOCD.

But if I don't get Yagarto to work correctly, it will make my life much, 
much more dificult that necessary. I know I have to learn all the basic 
stuff before being able to become an embedded programmer. But it would 
be much better if I could do so with a programming environment already 
working.

Imagine that you want to teach someone the basics of C programming for a 
PC console application. You would teach things like functions, "int 
main(void){}", printf, how to include stdio, etc. But it would be hell 
for your student if he had to fight alone against a poorly installed 
compiler...

If someone in this forum could help me compile the first program 
correctly, in my PC, without the evaluation board, just like the Yagarto 
home-page instructs, I am totally sure that I could continue my 
education on my own....

von Michael F. (mifi)


Rate this post
useful
not useful
Hello,

sorry, the example:

int main (void)
{
   return(0);
}

is not working anymore with the new version of newlib
which was build to support reentrant stubs. To double
check if your toolchain is working, use one of the
examples from the "How to use the toolchain" section.

Best regards,

Michael

von Francis K. (dinosaurkfb)


Rate this post
useful
not useful
Hi,Eduardo Fernandez del peloso
As I have said at the beginning, it's not your compiler's problem, 
that's to say, your installation of Yagarto is successful, you just 
downloads a example and type make, you'll see it works, if the example 
doesn't work, you can ask people here again.Do not use your own program, 
you missed something.

von Richard S. (Company: Home Use) (shadders)


Rate this post
useful
not useful
Hi,

I am having the same problem too - the reference to _sbrk_r causes a 
compile problem.

I am new to this area also.

The function i am trying to use is sprintf.

Printf works ok.

Can anyone provide the minimal changes to the relevant files to get the 
sprintf working ?

The Yagarto_newlib.txt file references some information, but not how to 
solve the problem easily.

The book i am using is the Elektor C Programming for Embedded 
Microcontrollers which uses the AT91SAM7S-EK board.

Thanks,

Regards,

Richard.

von Tilo Lutz (Guest)


Rate this post
useful
not useful
You need so called system call functions for your hardware. Please check 
the newlib documentation.

btw: You don't really want to use printf or sprintf in small uC 
applications.

von Richard S. (Company: Home Use) (shadders)


Rate this post
useful
not useful
Hi Tilo,

Thanks for the guidance, but the book i am using is a teaching text. As 
such, i am working through the examples.

Although i may not use sprintf in the future, i would like to understand 
how the example can be made to work since the version 4.3.2 Yagarto must 
have worked as the author would not have given this as the example.

So in referencing the <stdio.h> header/library in the main.c, the 
program does not compile. The author does state that the bin code is 
rather large from using the sprintf function - just to make the same 
point as you.

I have examined the newlib documentation online, but again, as per the 
initiator of this thread, i do not know what i need to do to get this 
program to compile - the yagarto_newlib.txt file points to 3 different 
issues on where to read - sourceforge, Bill Gatliff page, and stating 
that the newlib build was bompiled without the syscalls functions 
enabled.

Can you assist further at all ?. Thanks.

Regards,

Richard.

von Tilo Lutz (Guest)


Rate this post
useful
not useful
Well, you could take a look at my tutorial at 
http://www.stud.uni-karlsruhe.de/~usjp/aduc/Tutorial.zip and take a look 
at Tutorial\Model\ADUC7000\aduc.c

At the end of the file there is an exmaple for the function. I had big 
problems with the normal newlib function.
Reason:
Malloc of newlib seems to request memory in 4kb blocks. My uC has only 
8kb ram so the heap collides with the stack in a huge mess. I had to use 
a compile option for newlib (afaik "SMALL_MEMORY) to get it working.

von Richard S. (Company: Home Use) (shadders)


Rate this post
useful
not useful
Hi Tilo,

Thanks.

I have examined the last entry in the file - but a bit confused. It is a 
void function yet returns the value base. Is this correct ?. (still need 
to read up on C - many years ago i used it).

Is your suggestion that i put this code into my main.c text which should 
then link OK later ?.

What i do not understand is that Yagarto implemented :

-DREENTRANT_SYSCALLS_PROVIDED
--disable-newlib-supplied-syscalls

Why is this ?. Shoud i attempt to recompile the newlib with syscalls 
enabled and that will sove the problem ?.

Thanks.

Regards,

Richard.

von Richard S. (Company: Home Use) (shadders)


Rate this post
useful
not useful
Hi,

I have solved this issue - so for those who are new to this area as i 
am, and as such are just learning the basics of the area, the Yagarto 
web site provides 3 different solutions.

1. To examine the Bill Gatliff web site - but this assumes you are 
experienced in C programming to the point of detailed understanding of 
the intricacies.

2. Read the Red Hat web site - again, assumes that you are aware of the 
details of C and are not a novice.

3. Use the syscalls.c provided by Yagarto - but it does not explain what 
is going on.

So i have implemented option 3.

Initially i put the syscalls.c as a #include statement and this compiled 
and ran on the evaluation kit.

I contacted the author and he suggested the following - modify the make 
file to include syscalls.c

Add syscalls.o to the list of object files to be linked:
#----------------------------------------------------------------------- 
-----------
# TODO: Add all the object files generated for you project to the 
framework
# objects listed below
#----------------------------------------------------------------------- 
-----------
OBJS=startup.o \
main.o \
syscalls.o

Add the lines to compile syscalls.c:
#----------------------------------------------------------------------- 
-----------
# TODO: Add your object file compilation instructions
#----------------------------------------------------------------------- 
-----------

main.o: main.c
$(CC) -c $(CCFLAGS) main.c -o main.o

syscalls.o: syscalls.c
$(CC) -c $(CCFLAGS) syscalls.c -o syscalls.o

startup.o: startup.s
$(AS) $(ASFLAGS) startup.s -o startup.o

I hope the above will help others in getting their project to work given 
the changes in library compile options.

Regards,

Richard.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.