EmbDev.net

Forum: ARM programming with GCC/GNU tools linking with libc


Author: Denis Kuzmenko (term)
Posted on:

Rate this post
0 useful
not useful
Hi!

I have a problem, with using <stdio.h> functions
I've downloaded WinARM, and found that examples are not working. There
are much error in Makefile(or I'm doing something wrong)

I tried to use libc functions, including in my main.c file <stdio.h>,
linking with syscalls.c(from WinARM's example), adopted for my needs and
-lc option to the linker(link with libc.a)
but linker said me, that in can't find symbol 'printf'.
here is my Makefile looks like:

all:
  arm-elf-as --traditional-format -mthumb-interwork -k -EL -W
-mcpu=arm7tdmi -o init.o init.asm
  arm-elf-gcc -IC:\WinARM\arm-elf\include -mlittle-endian
-mthumb-interwork -mcpu=arm7tdmi -c -o test.o test.c
  arm-elf-gcc -IC:\WinARM\arm-elf\include -mlittle-endian
-mthumb-interwork -mcpu=arm7tdmi -c -o syscalls.o syscalls.c

  arm-elf-ld -o test.out --entry 0x00 -Ttext 0x00
-LC:\WinARM\arm-elf\lib -lc syscalls.o init.o test.o
  arm-elf-objcopy -O binary test.out prog.bin

I'm feeling that error is very simple, but I can't find it
Help me, please

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Denis Kuzmenko wrote:
> I've downloaded WinARM, and found that examples are not working. There
> are much error in Makefile(or I'm doing something wrong)

Please paste the complete output of a make all for one of the examples
(i.e. WinARM\at91sam7s_example_gamma). Also send the output of make
--version . Do you use MS Vista?

Author: Denis Kuzmenko (term)
Posted on:

Rate this post
0 useful
not useful
Martin Thomas wrote:
> Please paste the complete output of a make all for one of the examples
> (i.e. WinARM\at91sam7s_example_gamma).

C:\WinARM\examples\at91sam7s64_example_gamma>make
MAKE Version 5.2  Copyright (c) 1987, 1998 Inprise C
Error makefile 144: Command syntax error
Error makefile 147: Command syntax error
Error makefile 174: Command syntax error
Error makefile 180: Command syntax error
Error makefile 223: Command syntax error
Error makefile 225: Command syntax error
Error makefile 227: Command syntax error
Error makefile 311: Command syntax error
Error makefile 315: Command syntax error
Error makefile 316: Command syntax error
Error makefile 320: Command syntax error
Error makefile 322: Command syntax error
Error makefile 323: Command syntax error
Error makefile 358: Command syntax error
Error makefile 367: Command syntax error
Error makefile 368: Command syntax error
Error makefile 373: Too many rules for target 'progr
Error makefile 374: Command syntax error
Error makefile 379: Too many rules for target 'progr
Error makefile 380: Command syntax error
Error makefile 381: Command syntax error
Error makefile 413: Colon expected
Error makefile 435: Command syntax error
Error makefile 436: Command syntax error
Error makefile 437: Command syntax error
Error makefile 441: Command syntax error
Error makefile 442: Command syntax error
Error makefile 443: Command syntax error
Error makefile 454: Command syntax error
Error makefile 455: Command syntax error
Error makefile 456: Command syntax error
Error makefile 503: Command syntax error
*** 32 errors during make ***


>Also send the output of make
> --version .

C:\WinARM\examples\at91sam7s64_example_gamma>make --version
MAKE Version 5.2  Copyright (c) 1987, 1998 Inprise Corp.
Incorrect command line argument: --version

Syntax: MAKE [options ...] target[s]
    -B                Builds all targets regardless of dependency dates
    -Dsymbol[=string] Defines symbol [equal to string]
    -Idirectory       Names an include directory
    -K                Keeps (does not erase) temporary files created by
MAKE
    -N                Increases MAKE's compatibility with NMAKE
    -Wfilename        Writes MAKE to filename updating all non-string
options
    -Usymbol          Undefine symbol
    -ffilename        Uses filename as the MAKEFILE
    -a                Performs auto-dependency checks for include files
    -c                Caches auto-dependency information
    -e                Ignores redefinition of environment variable
macros
    -i                Ignores errors returned by commands
    -l+               Enables use of long command lines
    -m                Displays the date and time stamp of each file
    -n                Prints commands but does not do them
    -p                Displays all macro definitions and implicit rules
    -q                Returns zero if target is up-to-date and nonzero
                      if it is not (for use in batch files)
    -r                Ignores rules and macros defined in BUILTINS.MAK
    -s                Silent, does not print commands before doing them
    -? or -h          Prints this message
      Options marked with '+' are on by default. To turn off a default
      option follow it by a '-', for example: -a-
C:\WinARM\examples\at91sam7s64_example_gamma>


>Do you use MS Vista?

no, I'm using Windows XP

Author: Denis Kuzmenko (term)
Posted on:

Rate this post
0 useful
not useful
my WinARM release is 20060606, if this helps you to help me

Author: Denis Kuzmenko (term)
Posted on:

Rate this post
0 useful
not useful
here is my makefile:

all: init.o syscalls.o test.o
  arm-elf-ld -o test.out --entry 0x00 -Ttext 0x00
-LC:\WinARM\arm-elf\lib -lc syscalls.o init.o test.o
  arm-elf-objcopy -O binary test.out prog.bin
  del test.out

#C:\WinARM\lib\gcc\arm-elf\4.1.1\  C:\WinARM\lib

init.o:  init.asm
  arm-elf-as --traditional-format -mthumb-interwork -k -EL -W
-mcpu=arm7tdmi -o init.o init.asm

test.o: test.c
  arm-elf-gcc -IC:\WinARM\arm-elf\include -mlittle-endian
-mthumb-interwork -mcpu=arm7tdmi -c -o test.o test.c

syscalls.o: syscalls.c
  arm-elf-gcc -IC:\WinARM\arm-elf\include -mlittle-endian
-mthumb-interwork -mcpu=arm7tdmi -c -o syscalls.o syscalls.c

clean:
  del *.o load.log prog.bin

load:
  binsize prog.bin
  C:\progra~1\atmelc~1\at91-i~1.10\sam-ba~1.6\sam-ba.exe \usb\ARM0
AT91SAM7S128-EK load.tcl > load.log
  @more load.log

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Denis Kuzmenko wrote:
> Martin Thomas wrote:
>> Please paste the complete output of a make all for one of the examples
>> (i.e. WinARM\at91sam7s_example_gamma).
>
> C:\WinARM\examples\at91sam7s64_example_gamma>make
> MAKE Version 5.2  Copyright (c) 1987, 1998 Inprise C
> ...

(It's a FAQ. You did not read the readme.htm that comes with WinARM.)

The makefiles of WinARM-examples are made for a GNU make not for the
make-utility from Inprise/Borland. Rename the make.exe found the
C-Builder(?) directory to i.e. make_inprise.exe.

> C:\WinARM\examples\at91sam7s64_example_gamma>make --version
> MAKE Version 5.2  Copyright (c) 1987, 1998 Inprise Corp.
> Incorrect command line argument: --version

The output of make --version should start with GNU Make.

Martin Thomas

Author: Denis Kuzmenko (term)
Posted on:

Rate this post
0 useful
not useful
Martin Thomas wrote:
> (It's a FAQ. You did not read the readme.htm that comes with WinARM.)
> The output of make --version should start with GNU Make.
>
> Martin Thomas

I'm sorry, but I've read readme.htm couple of times
I've been added path to WinARM's make in the start of system path and
checked make version
Maybe this happened because I'm using Aston Shell(it replaces Windows
Explorer) and it can't correctly work with PATH environment variable

Found 3(!) Borlands makes and renamed all of them

Now my make version starts with GNU MAKE, and examples are making
correctly
But I steel can't make my own project

Can you, please, look to my makefile?
Maybe, you'll see my problem at first look

Author: Denis Kuzmenko (term)
Posted on:

Rate this post
0 useful
not useful
Hi, again!
I've looked, how object files are linked in examples

and tried to port that command line in my project:

arm-elf-gcc -mlittle-endian -mcpu=arm7tdmi -mthumb-interwork -I. init.o
syscalls.o test.o --output test.out -Wl,--entry=0x00,-Ttext=0x00 -lc
-lm -lc -lgcc

now project is make'ing without errors, but program is not working in
the device

With IDA(disassembler) I've found, that linker places couple of
functions BEFORE code in my init.o file

init.o file includes reset vectors, irq handlers and other
initialization, written in assembler

How can I tell the linker to place code of init.o at the start of .text
section?

Author: Denis Kuzmenko (term)
Posted on:

Rate this post
0 useful
not useful
This is me again

I think, that the answer is close

Now I have command, which links my object files without warnings

arm-elf-ld --entry 0x00 -Ttext 0x00
-LC:\\WinARM\\lib\\gcc\\arm-elf\\4.1.1\\ -Lc:\\winarm\\arm-elf\\lib\\ -o
test.out init.o syscalls.o test.o -lm -lc -lgcc -Tlink.ld

but the output functions are still not working

I wrote functions _write_r and _write to just blink a diode
an saw, that they are not even called, when I call printf function

maybe, I need to use some linker script, to have it working
I've been stuck with this library for a 3 days(!!!)
I'm in panic

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Denis Kuzmenko wrote:

> I'm sorry, but I've read readme.htm couple of times
The issue is mentioned at point 1 of the "remarks"-section of the readme
to WinARM20060606.

> I've been added path to WinARM's make in the start of system path and
> checked make version
> Maybe this happened because I'm using Aston Shell(it replaces Windows
> Explorer) and it can't correctly work with PATH environment variable

Hmm. I don't know this tool. But maybe this has been the reason.

> Found 3(!) Borlands makes and renamed all of them
>
> Now my make version starts with GNU MAKE, and examples are making
> correctly

Well done.

> I've looked, how object files are linked in examples
>
> and tried to port that command line in my project:
>
> arm-elf-gcc -mlittle-endian -mcpu=arm7tdmi -mthumb-interwork -I. init.o
> syscalls.o test.o --output test.out -Wl,--entry=0x00,-Ttext=0x00 -lc
> -lm -lc -lgcc
>
> now project is make'ing without errors, but program is not working in
> the device
>
> With IDA(disassembler) I've found, that linker places couple of
> functions BEFORE code in my init.o file

You can just use arm-elf-objdump to create a disassembly, no need for
extra tools.

> init.o file includes reset vectors, irq handlers and other
> initialization, written in assembler
>
> How can I tell the linker to place code of init.o at the start of .text
> section?

Since you do not provide your own linker-script the default
linker-script is used. You can view it by arm-elf-ld --verbose. As you
can see the instructions placed first need to be in section .init. Did
you add the .section instruction in your startup-code? It may be easier
to use your own linker-script. See the examples that come with WinARM,
read the binutils ld manual and the articles at embedded.com mentioned
in the forum-thread "Embedded.com: Building Bare-Metal ARM Systems with
GNU".

> This is me again
>
> I think, that the answer is close
>
> Now I have command, which links my object files without warnings
>
> arm-elf-ld --entry 0x00 -Ttext 0x00
> -LC:\\WinARM\\lib\\gcc\\arm-elf\\4.1.1\\ -Lc:\\winarm\\arm-elf\\lib\\ -o
> test.out init.o syscalls.o test.o -lm -lc -lgcc -Tlink.ld
>
> but the output functions are still not working

So you managed to get the reset-vector at the first addresse executed by
the core after reset?

> I wrote functions _write_r and _write to just blink a diode
> an saw, that they are not even called, when I call printf function
>
> maybe, I need to use some linker script, to have it working
> I've been stuck with this library for a 3 days(!!!)

Which controller are you using? It might be easier to take one of the
WinARM examples that demonstrates "stdio" (including the makefile and
linker-scripts) and adapt it to your controller. Usualy porting is not
too difficult as long as the same core is in use (examples for ARM7TDMI
are included).

_write_r needs to be implemented since the newlib in WinARM is build for
"reentrant syscalls". Maybe your _write_r-function does not get called
because of the buffering. Try to add a fflush(stdout) after printf and
see if your debug-LED blinks.

Martin Thomas

Author: Denis Kuzmenko (term)
Posted on:

Rate this post
0 useful
not useful
Martin Thomas wrote:
> You can just use arm-elf-objdump to create a disassembly, no need for
> extra tools.

From now, I know, that using IDA is not needed, but this so convenient
;)

> Since you do not provide your own linker-script the default
> linker-script is used. You can view it by arm-elf-ld --verbose. As you
> can see the instructions placed first need to be in section .init. Did
> you add the .section instruction in your startup-code? It may be easier
> to use your own linker-script. See the examples that come with WinARM,
> read the binutils ld manual and the articles at embedded.com mentioned
> in the forum-thread "Embedded.com: Building Bare-Metal ARM Systems with
> GNU".

I've used a linker-script from the examples(just changed memory settings
to AT91SAM7S128)
I didn't found in there some options, that can't be used by me.
I'll try to read all of that, but it is hard to do it, because English
is not my native language(sorry for my English, I think it's on a low
level, but I hope, you can understand me %).

> So you managed to get the reset-vector at the first addresse executed by
> the core after reset?

Yes, I did it with link command line:
arm-elf-ld -EL --entry 0x00 -Ttext 0x00
-LC:\\WinARM\\lib\\gcc\\arm-elf\\4.1.1\\ -Lc:\\winarm\\arm-elf\\lib\\ -o
test.out init.o syscalls.o test.o -lm -lc -lgcc -Tlink.d

> Which controller are you using? It might be easier to take one of the
> WinARM examples that demonstrates "stdio" (including the makefile and
> linker-scripts) and adapt it to your controller. Usualy porting is not
> too difficult as long as the same core is in use (examples for ARM7TDMI
> are included).

As I already said, my controller is AT91SAM7S128.
Maybe, porting example is easily then writing from zero
but I want to deeply understand, what exactly doing makefile, linker
script, etc. I think, this knowledge will help me in future.
That is why I write most of all code myself.

> _write_r needs to be implemented since the newlib in WinARM is build for
> "reentrant syscalls". Maybe your _write_r-function does not get called
> because of the buffering. Try to add a fflush(stdout) after printf and
> see if your debug-LED blinks.
>
> Martin Thomas

I've tried to use fflush(), but this didn't help.

When I try to link with using a ld's script from examples, I see in IDA,
that from zero address appears .text section, then, at address 0x200000
appears .data, then .bss and then "abs"(I don't know, maybe this is not
real section, maybe IDA just shows it for understanding of other code.
However, I found in this section a lot of constants, eg: MODE_IRQ,
MODE_USR(used in asm init to manage modes), end, _bss_ and others)
In this case, on device the program don't even starts(no activity on
LEDs).

But, when I link without script, program works(LEDs are blinking, as
they have to do), printf still not working.
In this case, in IDA, I see, that .text section starts from zero
address(same as previous), but .data and others(.bss, abs) in
difference, of previous case, appears immediately after the .text (IN
FLASH)

this is only difference, I've found
maybe problem is in "abs" section?
meybe, this section really contains constants, which asm code need(and
_sbrk_r too) and script places it in RAM?

that could be a reason, why it not starting

I understand, that without script I have .data and .bss placed in FLASH
As I know, Flash controller in this chip doesn't raise exception if I'll
try to write flash with just STR command. That is why I didn't get a red
LED blinked


I've found, that you are author of WinARM.
You've got a great respect and thanks from me.

Author: Denis Kuzmenko (term)
Posted on:

Rate this post
0 useful
not useful
Maybe, you have i little of time, to look at all my project
ftp://public.ntu-kpi.kiev.ua/incoming/4Den/proj.zip (7.51 kbytes)

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.