This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

redboot memory usage optimization (redboot_2.diff)


This patch modifies RedBoot to use less RAM when both
CYGBLD_BUILD_REDBOOT_WITH_ZLIB and CYGBLD_BUILD_REDBOOT_WITH_ZLIB
are enabled, by sharing a common RAM buffer for FIS directory manipulations
and the zlib workspace. This results in substantial savings, especially
when flash sectors are large.

tk
----------------------------------------------- 
Thomas Koeller, Software Development 

Basler Vision Technologies 
An der Strusbek 60-62 
22926 Ahrensburg 
Germany 

Tel +49 (4102) 463-390 
Fax +49 (4102) 463-46390

mailto:Thomas.Koeller@baslerweb.com 
http://www.baslerweb.com 






diff --strip-trailing-cr -ru packages-orig/redboot/current/ChangeLog
packages/redboot/current/ChangeLog
--- packages-orig/redboot/current/ChangeLog	2002-08-20
11:37:07.000000000 +0200
+++ packages/redboot/current/ChangeLog	2002-08-20 18:21:36.000000000 +0200
@@ -1,3 +1,12 @@
+2002-08-20  Thomas Koeller  <thomas@koeller.dyndns.org>
+
+    	* cdl/redboot.cdl:
+    	* include/redboot.h:
+    	* src/main.c:
+    	* src/flash.c:
+    	* src/decompress.c: Use a common buffer for FIS directory
+    	manipulation and zlib workspace to conserve RAM.
+
 2002-08-16  Jani Monoses  <jani@iv.ro>
 
 	* src/io.c: Do not add empty lines to command history.
diff --strip-trailing-cr -ru packages-orig/redboot/current/cdl/redboot.cdl
packages/redboot/current/cdl/redboot.cdl
--- packages-orig/redboot/current/cdl/redboot.cdl	2002-08-20
11:37:07.000000000 +0200
+++ packages/redboot/current/cdl/redboot.cdl	2002-08-20
18:18:03.000000000 +0200
@@ -43,7 +43,7 @@
 #
 # Author(s):      gthomas
 # Original data:  gthomas
-# Contributors:   Philippe Robin, Andrew Lunn
+# Contributors:   Philippe Robin, Andrew Lunn, tkoeller
 # Date:           2000-05-01
 #
 #####DESCRIPTIONEND####
@@ -822,6 +822,28 @@
 	    no_define
 	}
     }
+
+    cdl_component CYGOPT_REDBOOT_FIS_ZLIB_COMMON_BUFFER {
+    	display     	"Use a common buffer for Zlib and FIS"
+	flavor	    	bool
+	active_if   	{ CYGBLD_BUILD_REDBOOT_WITH_ZLIB && \
+    	    	    	  CYGOPT_REDBOOT_FIS }
+	default_value	0
+	description 	"
+	    Use a common memory buffer for both the zlib workspace
+	    and FIS directory operations. This can save a substantial
+	    amount of RAM, especially when flash sectors are large."
+
+    	cdl_option CYGNUM_REDBOOT_FIS_ZLIB_COMMON_BUFFER_SIZE {
+	    display 	    "Size of Zlib/FIS common buffer"
+	    flavor  	    data
+	    default_value   0xc000
+	    legal_values    0x4000 to 0x80000000
+	    description     "
+	    	Size of common buffer to allocate. Must be at least the
+		size of one flash sector."
+	}
+    }
 }
 
 # EOF redboot.cdl
diff --strip-trailing-cr -ru packages-orig/redboot/current/include/redboot.h
packages/redboot/current/include/redboot.h
--- packages-orig/redboot/current/include/redboot.h	2002-08-20
11:37:07.000000000 +0200
+++ packages/redboot/current/include/redboot.h	2002-08-20
18:18:03.000000000 +0200
@@ -42,7 +42,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    gthomas
-// Contributors: gthomas
+// Contributors: gthomas, tkoeller
 // Date:         2000-07-14
 // Purpose:      
 // Description:  
@@ -116,6 +116,10 @@
 #endif
 #endif
 
+#ifdef CYGOPT_REDBOOT_FIS_ZLIB_COMMON_BUFFER
+EXTERN unsigned char *fis_zlib_common_buffer;
+#endif
+
 // Prototypes
 typedef int _printf_fun(const char *fmt, ...);
 externC int  strcasecmp(const char *s1, const char *s2);
diff --strip-trailing-cr -ru packages-orig/redboot/current/src/decompress.c
packages/redboot/current/src/decompress.c
--- packages-orig/redboot/current/src/decompress.c	2002-08-20
11:37:07.000000000 +0200
+++ packages/redboot/current/src/decompress.c	2002-08-20
18:18:03.000000000 +0200
@@ -41,7 +41,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    jskov
-// Contributors: jskov, gthomas
+// Contributors: jskov, gthomas, tkoeller
 // Date:         2001-03-08
 // Purpose:      
 // Description:  
@@ -74,7 +74,11 @@
 };
 static struct _block *memlist;
 
-#define ZLIB_COMPRESSION_OVERHEAD 0xC000
+#ifdef CYGOPT_REDBOOT_FIS_ZLIB_COMMON_BUFFER
+# define ZLIB_COMPRESSION_OVERHEAD
CYGNUM_REDBOOT_FIS_ZLIB_COMMON_BUFFER_SIZE
+#else
+# define ZLIB_COMPRESSION_OVERHEAD 0xC000
+#endif
 static void *zlib_workspace;
 
 //
@@ -87,9 +91,13 @@
 static void
 _zlib_init(void)
 {
+#ifdef CYGOPT_REDBOOT_FIS_ZLIB_COMMON_BUFFER
+    zlib_workspace = fis_zlib_common_buffer;
+#else
     // Allocate some RAM for use by the gzip/zlib routines
     workspace_end -= ZLIB_COMPRESSION_OVERHEAD;
     zlib_workspace = workspace_end;
+#endif
 }
 
 RedBoot_init(_zlib_init, RedBoot_INIT_FIRST);
diff --strip-trailing-cr -ru packages-orig/redboot/current/src/flash.c
packages/redboot/current/src/flash.c
--- packages-orig/redboot/current/src/flash.c	2002-08-20
11:37:07.000000000 +0200
+++ packages/redboot/current/src/flash.c	2002-08-20
18:20:17.000000000 +0200
@@ -41,7 +41,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    gthomas
-// Contributors: gthomas
+// Contributors: gthomas, tkoeller
 // Date:         2000-07-28
 // Purpose:      
 // Description:  
@@ -477,7 +477,7 @@
     {
         return;
     }
-    img = (struct fis_image_desc *)fis_work_block;
+    img = (struct fis_image_desc *) fis_addr;
     // Let diag_printf do the formatting in both cases, rather than
counting
     // cols by hand....
     diag_printf("%-16s  %-10s  %-10s  %-10s  %-s\n",
@@ -619,6 +619,7 @@
         return;
     }
 
+    memcpy(fis_work_block, fis_addr, fisdir_size);
     defaults_assumed = false;
     if (name) {
         // Search existing files to acquire defaults for params not
specified:
@@ -819,6 +820,7 @@
     num_reserved++;
 #endif
 
+    memcpy(fis_work_block, fis_addr, fisdir_size);
     img = fis_lookup(name, &i);
     if (img) {
         if (i < num_reserved) {
@@ -874,6 +876,7 @@
         fis_usage("invalid arguments");
         return;
     }
+    memcpy(fis_work_block, fis_addr, fisdir_size);
     if ((img = fis_lookup(name, NULL)) == (struct fis_image_desc *)0) {
         diag_printf("No image '%s' found\n", name);
         return;
@@ -915,6 +918,9 @@
         // Set load address/top
         load_address = mem_addr;
         load_address_end = (unsigned long)p->out_buf;
+
+    	// Reload fis directory
+	memcpy(fis_work_block, fis_addr, fisdir_size);
     } else // dangling block
 #endif
     {
@@ -1092,6 +1098,7 @@
     /* Get parameters from image if specified */
     if (name) {
         struct fis_image_desc *img;
+	memcpy(fis_work_block, fis_addr, fisdir_size);
         if ((img = fis_lookup(name, NULL)) == (struct fis_image_desc *)0) {
             diag_printf("No image '%s' found\n", name);
             return;
@@ -1138,6 +1145,7 @@
 
     if (name) {
         struct fis_image_desc *img;
+	memcpy(fis_work_block, fis_addr, fisdir_size);
         if ((img = fis_lookup(name, NULL)) == (struct fis_image_desc *)0) {
             diag_printf("No image '%s' found\n", name);
             return;
@@ -1190,8 +1198,17 @@
         flash_get_block_info(&flash_block_size, &flash_num_blocks);
         workspace_end = (unsigned char
*)(workspace_end-FLASH_MIN_WORKSPACE);
 #ifdef CYGOPT_REDBOOT_FIS
+# ifdef CYGOPT_REDBOOT_FIS_ZLIB_COMMON_BUFFER
+	fis_work_block = fis_zlib_common_buffer;
+	if(CYGNUM_REDBOOT_FIS_ZLIB_COMMON_BUFFER_SIZE < flash_block_size) {
+            diag_printf("FLASH: common buffer too small\n");
+	    workspace_end += FLASH_MIN_WORKSPACE;
+            return false;
+	}
+# else
         workspace_end = (unsigned char *)(workspace_end-flash_block_size);
         fis_work_block = workspace_end;
+# endif
         fisdir_size = flash_block_size;
         if (CYGNUM_REDBOOT_FIS_DIRECTORY_BLOCK < 0) {
             fis_addr = (void *)((CYG_ADDRESS)flash_end + 1 +
@@ -1230,9 +1247,6 @@
         diag_printf("Sorry, no FLASH memory is available\n");
         return;
     }
-#ifdef CYGOPT_REDBOOT_FIS
-    memcpy(fis_work_block, fis_addr, flash_block_size);
-#endif
     if ((cmd = cmd_search(__FIS_cmds_TAB__, &__FIS_cmds_TAB_END__, 
                           argv[1])) != (struct cmd *)0) {
         (cmd->fun)(argc, argv);
diff --strip-trailing-cr -ru packages-orig/redboot/current/src/main.c
packages/redboot/current/src/main.c
--- packages-orig/redboot/current/src/main.c	2002-08-20
11:37:07.000000000 +0200
+++ packages/redboot/current/src/main.c	2002-08-20 18:18:03.000000000 +0200
@@ -42,7 +42,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    gthomas
-// Contributors: gthomas
+// Contributors: gthomas, tkoeller
 // Date:         2000-07-14
 // Purpose:      
 // Description:  
@@ -223,6 +223,11 @@
 
     bist();
 
+#ifdef CYGOPT_REDBOOT_FIS_ZLIB_COMMON_BUFFER
+    fis_zlib_common_buffer =
+    workspace_end -= CYGNUM_REDBOOT_FIS_ZLIB_COMMON_BUFFER_SIZE;
+#endif
+
     for (init_entry = __RedBoot_INIT_TAB__; init_entry !=
&__RedBoot_INIT_TAB_END__;  init_entry++) {
         (*init_entry->fun)();
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]