Porting newlib to new target using libgloss
Wed Jun 29 11:07:00 GMT 2011
On Tue, Jun 28, 2011 at 1:26 AM, Hard Maker <email@example.com> wrote:
> Hi list,
> I'm trying to port newlib for use in a development kit. This use a Cortex
> M3, so I need to port only the specific system calls to work with the
> asociated hardware.
> There are some "guide" to do this? I'm googling from a week's and I can make
> the port using a custom CRT0, but I don't know how to reuse the startup code
> from libgloss for Cortex and add my code for the peripherical hardware.
> Other question, when use newlib witch gcc, in C and C++ lenguage: ¿where can
> I read about the definitions needed in the linker script? I'm test with a
> linker script finded in internet but I know are some linkers script builded
> with the source, but I don't know how and which I need use (hosted or
> semihosted). Again, I'm using a cortex m3.
> Thank's a lot.
I've been working on something similar, so might be able to help -
although my port
is to Sparc Leon, so there will be some differences. I can perhaps
point you to some
useful resources however.
Three documents I found helpful were Jeremy Bennett's "Simple Guide" :-
Bill Gatliff's "Porting and Using Newlib" (see section 6 on porting) :-
and (even though it's quite old and probably could do with an update) :-
and there are lots of other bits of info around the net, as I'm sure
There are 18 functions which you need to implement, although most of them will
just be stubs returning an error code.
In my case the only things I needed were "sbrk" for malloc support, and simple
character I/O for printf debugging. If you're not supporting a file system, or
processes, then you probably won't need much more.
I looked at the crt0 and linker scripts in the Newlib download, but
ended up writing
my own in both cases, so I could get exactly what I wanted. Like you
I wanted to
add special hardware initialisation, so I put that into the startup
sequence in crt0.
For my linker script I used similar ideas to those in Newlib, and
symbols which crt0 could check to control initialisation. You can
create any symbols
you like in the script, and refer to them in crt0, or in your own
libraries. This can be
quite useful - for example I can pass a "_debugging" flag to the
linker which enables
the character I/O, allocates buffers etc. for debug builds only.
To simplify the command line for linking, I added a couple of references in the
script file as well :-
INPUT(crti.o crtbegin.o crtend.o crtn.o)
GROUP(-lleon -lc -lstdc++ -lgcc)
I hope this is of some help to you, and if there's anything I can help
ask, although I probably can't help too much on Cortex-specific issues.
More information about the Newlib