summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/shared/bootcard.c
diff options
context:
space:
mode:
authorThomas Doerfler <Thomas.Doerfler@embedded-brains.de>2008-07-29 07:11:21 +0000
committerThomas Doerfler <Thomas.Doerfler@embedded-brains.de>2008-07-29 07:11:21 +0000
commitcc54cc91758daa47c7c1172781e44d37b185a48a (patch)
tree7330e231616ad8a2cdf622f95dcda042f02b94a3 /c/src/lib/libbsp/shared/bootcard.c
parent2008-07-29 Chris Johns <chrisj@rtems.org> (diff)
downloadrtems-cc54cc91758daa47c7c1172781e44d37b185a48a.tar.bz2
src/irq-legacy.c: Free allocated memory in hander remove
bootcard.c: Check if the heap fits into the work area
Diffstat (limited to 'c/src/lib/libbsp/shared/bootcard.c')
-rw-r--r--c/src/lib/libbsp/shared/bootcard.c88
1 files changed, 53 insertions, 35 deletions
diff --git a/c/src/lib/libbsp/shared/bootcard.c b/c/src/lib/libbsp/shared/bootcard.c
index 4f461f6b3d..d7539c75ed 100644
--- a/c/src/lib/libbsp/shared/bootcard.c
+++ b/c/src/lib/libbsp/shared/bootcard.c
@@ -58,36 +58,49 @@ char *rtems_progname;
* the RTEMS Workspace and C Program Heap.
*/
#if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION)
- static void bootcard_bsp_libc_helper(
+ static rtems_status_code bootcard_bsp_libc_helper(
void *work_area_start,
size_t work_area_size,
void *heap_start,
size_t heap_size
)
{
+ size_t heap_size_default = 0;
+
if (heap_start == BSP_BOOTCARD_HEAP_USES_WORK_AREA) {
/* Use the work area start as heap start */
heap_start = work_area_start;
/* Ensure proper alignement */
if ((uintptr_t) heap_start & (CPU_ALIGNMENT - 1)) {
- heap_start = (void *) (((uintptr_t) heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT - 1));
+ heap_start = (void *) (((uintptr_t) heap_start + CPU_ALIGNMENT)
+ & ~(CPU_ALIGNMENT - 1));
}
/*
- * Use the free space from the start of the work area up to the work
- * space start as heap area.
+ * For the default heap size use the free space from the start of the
+ * work area up to the work space start as heap area.
*/
- if (heap_size == BSP_BOOTCARD_HEAP_SIZE_DEFAULT) {
- heap_size = (char *) Configuration.work_space_start
- - (char *) work_area_start;
+ heap_size_default = (char *) Configuration.work_space_start
+ - (char *) work_area_start;
+
+ /* Keep it as a multiple of 16 bytes */
+ heap_size_default &= ~((size_t) 0xf);
- /* Keep it as a multiple of 16 bytes */
- heap_size &= 0xfffffff0;
+ /* Use default heap size if requested */
+ if (heap_size == BSP_BOOTCARD_HEAP_SIZE_DEFAULT) {
+ heap_size = heap_size_default;
+ }
+
+ /* Check heap size */
+ if (heap_size > heap_size_default) {
+ return RTEMS_INVALID_SIZE;
}
}
bsp_libc_init( heap_start, (uint32_t) heap_size, 0);
+
+ return RTEMS_SUCCESSFUL;
}
#endif
@@ -109,6 +122,7 @@ int boot_card(
char **envp_p = &envp_pointer;
rtems_interrupt_level bsp_isr_level;
#if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION)
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
void *work_area_start = NULL;
size_t work_area_size = 0;
void *heap_start = NULL;
@@ -150,32 +164,31 @@ int boot_card(
* the RTEMS Workspace and the C Program Heap is.
*/
#if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION)
- {
- void *work_space_start = NULL;
-
- bsp_get_work_area(
- &work_area_start,
- &work_area_size,
- &heap_start,
- &heap_size
- );
-
- work_space_start = (char *) work_area_start + work_area_size
- - rtems_configuration_get_work_space_size();
-
- if ((uintptr_t) work_space_start <= (uintptr_t) work_area_start) {
- printk( "bootcard: Not enough RAM!!!\n" );
- bsp_cleanup();
- return -1;
+ {
+ void *work_space_start = NULL;
+
+ bsp_get_work_area(
+ &work_area_start,
+ &work_area_size,
+ &heap_start,
+ &heap_size
+ );
+
+ work_space_start = (char *) work_area_start + work_area_size
+ - rtems_configuration_get_work_space_size();
+
+ if ((uintptr_t) work_space_start <= (uintptr_t) work_area_start) {
+ printk( "bootcard: Work space to big for work area!\n");
+ bsp_cleanup();
+ return -1;
+ }
+
+ Configuration.work_space_start = work_space_start;
+
+ #if (BSP_DIRTY_MEMORY == 1)
+ memset( work_area_start, 0xCF, work_area_size);
+ #endif
}
-
- Configuration.work_space_start = work_space_start;
-
- #if (BSP_DIRTY_MEMORY == 1)
- memset( work_area_start, 0xCF, work_area_size);
- #endif
- }
-
#endif
/*
@@ -193,12 +206,17 @@ int boot_card(
* framework.
*/
#if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION)
- bootcard_bsp_libc_helper(
+ sc = bootcard_bsp_libc_helper(
work_area_start,
work_area_size,
heap_start,
heap_size
);
+ if (sc != RTEMS_SUCCESSFUL) {
+ printk( "bootcard: Cannot initialize C library!\n");
+ bsp_cleanup();
+ return -1;
+ }
#endif
/*