Page 1 of 2
What is the equavalint code of the memmory allocation
Posted: Sat Nov 24, 2012 3:46 pm
by robu
I wrote a matrix class in c++ and I would like to test on a Raspberry Pi using ChibiOS/RT. Durring the compilation I hade problem with the memset
Code: Select all
Linking build/ch.elf
/opt/arm_gcc/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text+0x18): undefined reference to `_sbrk'
collect2: error: ld returned 1 exit status
If I take out the memset than I can compile/linke the code. What can be the problem?
I also decided to use the ChibiOS/RT memory allocation, but I haven't found any example regarding this.
For example what is the equivalent code for this:
Code: Select all
double * t = (double *) malloc(2*2*sizeof(double))
memset((void *) t, 0, sizeof(double) * 4);
free(t);
Re: What is the equavalint code of the memmory allocation
Posted: Sat Nov 24, 2012 4:33 pm
by Giovanni
Hi,
chHeapAlloc() is very similar to malloc(), see the documentation page for details, there are examples in the test suite under ./test.
Giovanni
Re: What is the equavalint code of the memmory allocation
Posted: Sat Nov 24, 2012 7:00 pm
by robu
Thanks for your answer!
In my case a I have a matrix class
static MemoryHeap myheap;
Code: Select all
static MemoryHeap myheap;
Matrix::Matrix(size_t rows, size_t cols):rows(rows), cols(cols)
{
data = (double *) chHeapAlloc(&myheap, rows*cols*sizeof(double));
}
Matrix::~Matrix()
{
chHeapFree(data);
}
I'm a bit newbie and I don't understand what is the chHeapInit. My other question that before I used memset and memcpy, I can replace this with a for cycle to initialize or copy the data, I just wan to know that is there an other way to replace this commands?
According this documentation the heap has the same limitation as the C-runtime, what else are the advantages of the heap?
http://www.chibios.org/dokuwiki/doku.ph ... age_memory
Re: What is the equavalint code of the memmory allocation
Posted: Sat Nov 24, 2012 7:05 pm
by robu
Also when I'm using memset and memcpy why do I get the following linking error:
Code: Select all
/opt/arm_gcc/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text+0x18): undefined reference to `_sbrk'
collect2: error: ld returned 1 exit status
make: *** [build/ch.elf] Error 1
Re: What is the equavalint code of the memmory allocation
Posted: Sat Nov 24, 2012 7:09 pm
by Giovanni
Hi,
That is a problem with the C library, you have to provide the implementation of _sbrk(), see the newlib documentation for this. Searching this forum could give you several hits about this.
Under ./os/various there is a file syscall.c, it should provide the required implementations but I never tested it with the RPI port.
Giovanni
Re: What is the equavalint code of the memmory allocation
Posted: Sat Nov 24, 2012 7:13 pm
by robu
Hi,
I tried to include the -lstdc++ in this case I'm receiving a different error:
Code: Select all
/opt/arm_gcc/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/bin/ld: error: no memory region specified for loadable section `.ARM.extab'
collect2: error: ld returned 1 exit status
Thanks,
Robert
Re: What is the equavalint code of the memmory allocation
Posted: Sat Nov 24, 2012 9:00 pm
by Giovanni
Hi,
The linker script needs to be updated to allocate the missing sections, look at the standard linker scripts of your compiler, you should see those sections listed inside.
Giovanni
Re: What is the equavalint code of the memmory allocation
Posted: Sun Nov 25, 2012 11:37 pm
by robu
Hi,
I'm really newbie, I just started to program embedded system a few days ago, I bought a Raspberry PI, and I don't know where can I find this section/file.
Thanks,
Robert
Re: What is the equavalint code of the memmory allocation
Posted: Wed Nov 28, 2012 11:24 pm
by robu
Hi,
This is my linker script:
Code: Select all
/*
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
2011,2012 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* BCM2835 memory setup.
*/
__und_stack_size__ = 0x0004;
__abt_stack_size__ = 0x0004;
__fiq_stack_size__ = 0x0010;
__irq_stack_size__ = 0x0080;
__svc_stack_size__ = 0x0004;
__sys_stack_size__ = 0x0400;
__stacks_total_size__ = __und_stack_size__ + __abt_stack_size__ + __fiq_stack_size__ + __irq_stack_size__ + __svc_stack_size__ + __sys_stack_size__;
MEMORY
{
ram : org = 0x8000, len = 0x06000000 - 0x20
}
__ram_start__ = ORIGIN(ram);
__ram_size__ = LENGTH(ram);
__ram_end__ = __ram_start__ + __ram_size__;
SECTIONS
{
. = 0;
.text : ALIGN(16) SUBALIGN(16)
{
_text = .;
KEEP(*(vectors))
*(.text)
*(.text.*)
*(.rodata)
*(.rodata.*)
*(.glue_7t)
*(.glue_7)
*(.gcc*)
*(.ctors)
*(.dtors)
} > ram
.ARM.extab : {*(.ARM.extab* .gnu.linkonce.armextab.*)}
__exidx_start = .;
.ARM.exidx : {*(.ARM.exidx* .gnu.linkonce.armexidx.*)} > ram
__exidx_end = .;
.eh_frame_hdr : {*(.eh_frame_hdr)}
.eh_frame : ONLY_IF_RO {*(.eh_frame)}
. = ALIGN(4);
_etext = .;
_textdata = _etext;
.data :
{
_data = .;
*(.data)
. = ALIGN(4);
*(.data.*)
. = ALIGN(4);
*(.ramtext)
. = ALIGN(4);
_edata = .;
} > ram
.bss :
{
_bss_start = .;
*(.bss)
. = ALIGN(4);
*(.bss.*)
. = ALIGN(4);
*(COMMON)
. = ALIGN(4);
_bss_end = .;
} > ram
}
PROVIDE(end = .);
_end = .;
__heap_base__ = _end;
__heap_end__ = __ram_end__ - __stacks_total_size__;
__main_thread_stack_base__ = __ram_end__ - __stacks_total_size__;
What should I update?
Thank you for your help.
Re: What is the equavalint code of the memmory allocation
Posted: Thu Nov 29, 2012 8:48 am
by Giovanni
Try changing
.ARM.extab : {*(.ARM.extab* .gnu.linkonce.armextab.*)}
in
.ARM.extab : {*(.ARM.extab* .gnu.linkonce.armextab.*)} > flash
Giovanni