changeset 2887:22da989aafa4

Add support for memalloc heaps in RedBoot. See ChangeLogs for details.
author nickg
date Thu, 25 Jun 2009 10:30:59 +0000
parents 7c9e64d8c436
children d5bbba5243dc
files packages/redboot/current/ChangeLog packages/redboot/current/cdl/redboot.cdl packages/redboot/current/src/main.c packages/services/memalloc/common/current/ChangeLog packages/services/memalloc/common/current/src/malloc.cxx
diffstat 5 files changed, 79 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/packages/redboot/current/ChangeLog
+++ b/packages/redboot/current/ChangeLog
@@ -1,3 +1,12 @@
+2009-06-24  Nick Garnett  <nickg@ecoscentric.com>
+
+	* cdl/redboot.cdl:
+	* src/main.c (cyg_start): Added options and code to reinitialize
+ 	the heap, if it exists, to an arena cut off the end of the
+ 	workspace.
+	[Imported from eCosPro sources, mainly to support use of
+	filesystems in RedBoot].
+ 
 2009-06-02  Ross Younger  <wry@ecoscentric.com>
 
 	* redboot.cdl: REDBOOT_IO_FILEIO requires CYGPKG_IO
--- a/packages/redboot/current/cdl/redboot.cdl
+++ b/packages/redboot/current/cdl/redboot.cdl
@@ -1284,6 +1284,32 @@ cdl_package CYGPKG_REDBOOT {
                     size of one flash sector."
             }
         }
+
+        cdl_component CYGMEM_REDBOOT_WORKSPACE_HEAP {
+            display     	"Allocate heap in RedBoot workspace"
+            flavor	    	bool
+            active_if   	CYGPKG_MEMALLOC
+            active_if   	CYGPKG_MEMALLOC_MALLOC_ALLOCATORS
+            default_value	0
+            description 	"
+                    If the MEMALLOC package is present, it usually allocates
+                    the whole of memory not used by the program to the heap.
+                    In RedBoot this is not a good idea, since we need space to
+                    load application programs. Setting this option causes RedBoot
+                    to allocate the heap at the top of RAM by reserving part of
+                    RedBoot's workspace memory, leaving the rest of memory free."
+
+            cdl_option CYGMEM_REDBOOT_WORKSPACE_HEAP_SIZE {
+                display 	"Size of RedBoot heap"
+                flavor  	data
+                default_value   0x10000
+                legal_values    0x4000 to 0x80000000
+                description     "
+                    Size of RedBoot heap. This defines how much memory is to be
+                    allocated for the heap."
+            }
+        }
+
         cdl_option CYGNUM_REDBOOT_GETC_BUFFER {
             display       "Buffer size in getc when loading images"
             flavor        data
--- a/packages/redboot/current/src/main.c
+++ b/packages/redboot/current/src/main.c
@@ -301,6 +301,17 @@ cyg_start(void)
         workspace_end = ram_end;
     }
 
+#if defined(CYGMEM_REDBOOT_WORKSPACE_HEAP)
+    {
+        extern cyg_bool cyg_memalloc_heap_reinit( cyg_uint8 *base, cyg_uint32 size );
+
+        workspace_end -= CYGMEM_REDBOOT_WORKSPACE_HEAP_SIZE;
+
+        if( !cyg_memalloc_heap_reinit( (cyg_uint8 *)workspace_end, CYGMEM_REDBOOT_WORKSPACE_HEAP_SIZE ) )
+            diag_printf("Heap reinitialization failed\n");
+    }
+#endif
+
     workspace_end_init=workspace_end;
 
     // Nothing has ever been loaded into memory
--- a/packages/services/memalloc/common/current/ChangeLog
+++ b/packages/services/memalloc/common/current/ChangeLog
@@ -1,3 +1,13 @@
+2009-06-24  Nick Garnett  <nickg@ecoscentric.com>
+
+	* src/malloc.cxx (cyg_memalloc_heap_reinit): Added this function
+	to reinitialize the heap to a new arena. This should be done
+	during system startup and is present mainly for the use of
+	RedBoot.
+	Permit configurations with multi-region heaps to build.
+	[Imported from eCosPro sources, mainly to support use of
+	filesystems in RedBoot].
+	
 2009-02-03  Simon Kallweit  <simon.kallweit@intefo.ch>
 
 	* include/mvarimpl.inl:
@@ -395,7 +405,7 @@ 2000-07-04  Jonathan Larmour  <jlarmour@
 // ####GPLCOPYRIGHTBEGIN####                                                
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc.
 //
 // This program is free software; you can redistribute it and/or modify     
 // it under the terms of the GNU General Public License as published by     
--- a/packages/services/memalloc/common/current/src/malloc.cxx
+++ b/packages/services/memalloc/common/current/src/malloc.cxx
@@ -8,7 +8,7 @@
 // ####ECOSGPLCOPYRIGHTBEGIN####                                            
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2009 Free Software Foundation, Inc.
 //
 // eCos 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     
@@ -284,6 +284,27 @@ mallinfo( void )
     return ret;
 } // mallinfo()
 
+
+inline void *
+operator new(size_t size,  CYGCLS_MEMALLOC_MALLOC_IMPL *ptr)
+{ return (void *)ptr; };
+
+externC cyg_bool
+cyg_memalloc_heap_reinit( cyg_uint8 *base, cyg_uint32 size )
+{
+#if CYGMEM_HEAP_COUNT == 0
+    CYGCLS_MEMALLOC_MALLOC_IMPL *m = new(&cyg_memalloc_mallocpool)
+        CYGCLS_MEMALLOC_MALLOC_IMPL( base, size );
+    return true;
+#elif CYGMEM_HEAP_COUNT == 1    
+    cygmem_memalloc_heaps[0] = new(cygmem_memalloc_heaps[0])
+        CYGCLS_MEMALLOC_MALLOC_IMPL( base, size );
+    return true;
+#else
+    return false;
+#endif
+}
+
 #endif // ifdef CYGPKG_MEMALLOC_MALLOC_ALLOCATORS
 
 // EOF malloc.cxx