Hello rain,
this should be your solution, I have test it here with an lpc2294 board.
How to solve the problem with newlib from YAGARTO?
Therefore you must know that the libc.a for YAGARTO is created
with the syscalls function. Syscalls provide some functionality for
malloc printf and more.
To overwrite we need a libc.a without the syscalls functionality.
The reason why you get the error with the _write is that this
function is in syscalls.
Now we remove syscalls from the libc.a I have installed YAGARTO at
d:\Compiler, therefore I will find libc.a at the following location:
d:\Compiler\yagarto\arm-elf\lib\libc.a
Go inside the d:\Compiler\yagarto\arm-elf\lib directory
and make a copy of the libc.a for example: libc_with_syscalls.a.
Use now the following command to remove the syscalls from libc.a:
arm-elf-ar -d libc.a syscalls.o
Now you have a libc.a library without the syscalls functionality.
The disavantage is here, you must write this functionality by yourself.
If you compile your program now, you will get a lot of warnings.
Try to use this syscalls.c file and add it to your project.
=============================================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
extern int DebugWrite (const void *buffer, int len);
#define STDIN_FILENO 0 /* standard input file descriptor */
#define STDOUT_FILENO 1 /* standard output file descriptor */
#define STDERR_FILENO 2 /* standard error file descriptor */
void _exit (int n)
{
while(1)
{
n = n;
}
}
int _stat(char *file, struct stat *st) {
return (0);
}
int _fstat (int fd, struct stat * st)
{
if (fd == STDOUT_FILENO)
{
memset(st, 0, sizeof (* st));
st->st_mode = S_IFCHR;
st->st_blksize = 1024;
return 0;
}
else
{
DebugWrite(“Error: _fstat\r\n”, 15);
return(-1);
}
}
register char *stack_ptr asm (“sp”);
caddr_t _sbrk_r(void *reent, size_t incr)
{
extern char end asm (“end”); // Defined by the linker
static char *heap_end;
char *prev_heap_end;
if( heap_end == NULL )
heap_end = &end;
prev_heap_end = heap_end;
if(( heap_end + incr ) > stack_ptr )
{
/* Some of the libstdc+±v3 tests rely upon detecting */
/* out of memory errors, so do not abort here. */
exit(1);
return (caddr_t) -1;
}
heap_end += incr;
return (caddr_t) prev_heap_end;
}
int isatty (int fd)
{
return(1);
}
int _lseek (int fd, int ptr,int dir)
{
return (-1);
}
int _open(const char *name, int mode)
{
return(-1);
}
int _close(int fd)
{
return(0);
}
int _write(int fd, const void *data, unsigned int count)
{
if (fd == STDOUT_FILENO)
{
count = DebugWrite(data, count);
}
else
{
DebugWrite(“Error: _write\r\n”, 15);
count = -1;
}
return(count);
}
int _read(int fd, void *buffer, unsigned int count)
{
return(-1);
}
=====================================================================
Inside the _write function I use DebugWrite, therefore
your application must now provide a DebugWrite function like this:
int DebugWrite (const void *buffer, int len);
Here you get the buffer of the string to write and the len.
You must return the len you have wrote.
int DebugWrite (const void *buffer, int len)
{
int c = len;
char cp = (char)buffer;
while(c–)
{
output(cp++); / You must write this function */
}
return len;
}
Best regards,
Michael