ppcrcd/yaboot: Makefile gunzip.c lib/malloc.c yaboot.c

sparky cvs at pld-linux.org
Thu Jun 16 12:51:13 CEST 2005


Author: sparky
Date: Thu Jun 16 12:51:05 2005
New Revision: 6095

Modified:
   ppcrcd/yaboot/Makefile
   ppcrcd/yaboot/gunzip.c
   ppcrcd/yaboot/lib/malloc.c
   ppcrcd/yaboot/yaboot.c
Log:
- gunzip uses ith own linear malloc
- better memory freeing syntax in lib/malloc.c
- search for yaboot.conf in /boot/ on chrp machines


Modified: ppcrcd/yaboot/Makefile
==============================================================================
--- ppcrcd/yaboot/Makefile	(original)
+++ ppcrcd/yaboot/Makefile	Thu Jun 16 12:51:05 2005
@@ -15,9 +15,12 @@
 
 # Load the bootstrap at 2Mb
 TEXTADDR	= 0x200000
-# Malloc block at 3Mb -> 5Mb
+# Malloc block at 3Mb -> 4.5Mb
 MALLOCADDR	= 0x300000
-MALLOCSIZE	= 0x200000
+MALLOCSIZE	= 0x180000
+# gzMalloc block (4.5->5Mb)
+GZMALLOCADDR    = 0x480000
+GZMALLOCSIZE    = 0x080000
 # Load kernel at 20Mb and ramdisk just after
 KERNELADDR	= 0x01400000
 
@@ -27,6 +30,7 @@
 YBCFLAGS += -DVERSION=\"${VERSION}\"	#"
 YBCFLAGS += -DTEXTADDR=$(TEXTADDR) -DDEBUG=$(DEBUG)
 YBCFLAGS += -DMALLOCADDR=$(MALLOCADDR) -DMALLOCSIZE=$(MALLOCSIZE)
+YBCFLAGS += -DGZMALLOCADDR=$(GZMALLOCADDR) -DGZMALLOCSIZE=$(GZMALLOCSIZE)
 YBCFLAGS += -DKERNELADDR=$(KERNELADDR)
 YBCFLAGS += -I ./include
 

Modified: ppcrcd/yaboot/gunzip.c
==============================================================================
--- ppcrcd/yaboot/gunzip.c	(original)
+++ ppcrcd/yaboot/gunzip.c	Thu Jun 16 12:51:05 2005
@@ -134,6 +134,8 @@
 #include "file.h"
 #include "gunzip.h"
 
+int initialized_gzmalloc = 0;
+
 /* used to tell if "read" should be redirected to "gunzip_read" */
 int compressed_file;
 
@@ -152,6 +154,39 @@
 static void initialize_tables (void);
 
 
+/* malloc replace */
+static char *gzmalloc_ptr = 0;
+static char *gzmalloc_start = 0;
+static char *gzmalloc_top = 0;
+
+void gzmalloc_init(void *bottom, unsigned long size)
+{
+    gzmalloc_start = gzmalloc_ptr = bottom;
+    gzmalloc_top = bottom + size;
+}
+
+void *gzmalloc (unsigned int size)
+{
+	char *caddr;
+
+	if (!gzmalloc_ptr)
+		return NULL;
+	if ((gzmalloc_ptr + size + sizeof(int)) > gzmalloc_top) {
+		prom_printf("malloc for gunzip failed\n");
+		return NULL;
+	}
+	*(int *)gzmalloc_ptr = size;
+	caddr = gzmalloc_ptr + sizeof(int);
+	gzmalloc_ptr += size + sizeof(int);
+	gzmalloc_ptr = (char *) ((((unsigned int) gzmalloc_ptr) + 3) & (~3));
+	return caddr;
+}
+
+void reset_gzmalloc(void) {
+	gzmalloc_ptr = gzmalloc_start;
+}
+
+
 /* internal function for eating variable-length header fields */
 static int
 bad_field (int len)
@@ -259,6 +294,20 @@
     }
 
   gzip_data_offset = gunzip_file.pos;
+
+  if (!initialized_gzmalloc)
+  {
+	  void* gzmalloc_base = NULL;
+	  
+          gzmalloc_base = prom_claim((void *)GZMALLOCADDR, GZMALLOCSIZE, 0);
+          if (gzmalloc_base == (void *)-1) {
+              prom_printf("Can't claim malloc buffer (%d bytes at 0x%08x)\n",
+                           GZMALLOCSIZE, GZMALLOCADDR);
+	      return -1;
+          }
+    	  gzmalloc_init(gzmalloc_base, GZMALLOCSIZE);
+	  initialized_gzmalloc = 1;
+  }
   
   initialize_tables ();
 
@@ -446,33 +495,11 @@
 
 
 /* more function prototypes */
-int huft_free(struct huft *t);
 static int huft_build (unsigned *, unsigned, unsigned, ush *, ush *,
 		       struct huft **, int *);
 static int inflate_codes_in_window (void);
 
 
-int
-huft_free(struct huft *t)         /* table to free */
-/* Free the malloc'ed tables built by huft_build(), which makes a linked
-   list of the tables it made, with the links in a dummy first entry of
-   each table. */
-{
-  register struct huft *p, *q;
-
-  /* Go through linked list, freeing from the malloced (t[-1]) address. */
-  p = t;
-  while (p != (struct huft *)NULL)
-  {
-    q = (--p)->v.t;
-    free((char*)p);
-    p = q;
-  }
-  return 0;
-}
-
-
-
 /* Given a list of code lengths and a maximum table size, make a set of
    tables to decode that set of codes.  Return zero on success, one if
    the given code set is incomplete (the tables are still built in this
@@ -606,12 +633,10 @@
 	      z = 1 << j;	/* table entries for j-bit table */
 
 	      /* allocate and link in new table */
-              if ((q = (struct huft *)malloc( (z + 1)*sizeof(struct huft) )) ==
+              if ((q = (struct huft *)gzmalloc( (z + 1)*sizeof(struct huft) )) ==
                        (struct huft *)NULL)
               {
-		      prom_printf("\ngunzip: malloc failed; not enought memory ?\n");
-                 if (h)
-	             huft_free(u[0]);
+		 prom_printf("\ngunzip: malloc failed; not enought memory ?\n");
                  return 3;             /* not enough memory */
               }
 
@@ -872,7 +897,6 @@
   if ((i = huft_build (l, 30, 0, cpdist, cpdext, &td, &bd)) > 1)
     {
       prom_printf("ERR_BAD_GZIP_DATA: init_fixed_block 2\n");
-      huft_free(tl);
       return;
     }
 
@@ -934,7 +958,6 @@
   if ((i = huft_build (ll, 19, 19, NULL, NULL, &tl, &bl)) != 0)
     {
      prom_printf("ERR_BAD_GZIP_DATA: init_dynamic_block 2\n");
-     huft_free(tl);
       return;
     }
 
@@ -995,8 +1018,7 @@
     }
 
   /* free decoding table for trees */
-  //reset_linalloc
-  huft_free(tl); tl = NULL;
+  reset_gzmalloc();
 
   /* restore the global bit buffer */
   bb = b;
@@ -1007,15 +1029,12 @@
   if ((i = huft_build (ll, nl, 257, cplens, cplext, &tl, &bl)) != 0)
     {
       prom_printf("ERR_BAD_GZIP_DATA: init_dynamic_block 6\n");
-      huft_free(tl);
       return;
     }
   bd = dbits;
   if ((i = huft_build (ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0)
     {
       prom_printf("ERR_BAD_GZIP_DATA: init_dynamic_block 7\n");
-      huft_free(tl);
-      huft_free(td);
       return;
     }
 
@@ -1111,11 +1130,8 @@
        *  Expand other kind of block.
        */
 
-       if ( inflate_codes_in_window() ) {
-               //reset_linalloc
-	       huft_free(tl); tl = NULL;
-               huft_free(td); td = NULL;
-       }
+       if ( inflate_codes_in_window() )
+	       reset_gzmalloc();
     }
 
   saved_filepos += wp; // WSIZE
@@ -1142,9 +1158,7 @@
   block_len = 0;
 
   /* reset memory allocation stuff */
-  //reset_linalloc
-  huft_free(tl); tl = NULL;
-  huft_free(td); td = NULL;
+  reset_gzmalloc();
 }
 
 
@@ -1184,8 +1198,7 @@
       ret += size;
 
       if (last_block) {
-	      huft_free(tl); tl = NULL;
-	      huft_free(td); td = NULL;
+	      reset_gzmalloc();
 	      break;
       }
     }

Modified: ppcrcd/yaboot/lib/malloc.c
==============================================================================
--- ppcrcd/yaboot/lib/malloc.c	(original)
+++ ppcrcd/yaboot/lib/malloc.c	Thu Jun 16 12:51:05 2005
@@ -32,7 +32,7 @@
 
 void malloc_init(void *bottom, unsigned long size)
 {
-	malloc_ptr = bottom;
+	last_alloc = malloc_ptr = bottom;
 	malloc_top = bottom + size;
 }
 
@@ -48,13 +48,14 @@
 
     if (!malloc_ptr)
     	return NULL;
-    if ((malloc_ptr + size + sizeof(int)) > malloc_top) {
+    if ((malloc_ptr + size + 2 * sizeof(int) ) > malloc_top) {
 	prom_printf("malloc failed\n");
     	return NULL;
     }
     *(int *)malloc_ptr = size;
     caddr = malloc_ptr + sizeof(int);
-    malloc_ptr += size + sizeof(int);
+    *(unsigned int *)(malloc_ptr + sizeof(int) + size) = (unsigned int)last_alloc; // put at final init of chunk before it
+    malloc_ptr += size + 2 * sizeof(int);
     last_alloc = caddr;
     malloc_ptr = (char *) ((((unsigned int) malloc_ptr) + 3) & (~3));
     return caddr;
@@ -85,8 +86,12 @@
 {
     if (!malloc_ptr)
     	return;
-    if (m == last_alloc)
+    char *caddr;
+    if (m == last_alloc) {
+	caddr = (char *) *(unsigned int *)(last_alloc + *(int *)(last_alloc - sizeof(int)));
 	malloc_ptr = (char *) last_alloc - sizeof(int);
+	last_alloc = caddr;
+    }
 }
 
 void mark (void **ptr)

Modified: ppcrcd/yaboot/yaboot.c
==============================================================================
--- ppcrcd/yaboot/yaboot.c	(original)
+++ ppcrcd/yaboot/yaboot.c	Thu Jun 16 12:51:05 2005
@@ -295,7 +295,13 @@
 	  prom_printf("%s: Unable to parse\n", msgpath);
 	  goto done;
      }
-
+     
+     msg = malloc(2001 - paging * 1000); /* 2000 for not paged messages, 1000 for paged*/
+     if (!msg)
+	  goto done;
+     else
+	  memset(msg, 0, (2001 - paging * 1000));
+ 
      result = open_file(&msgfile, &file);
      if (result != FILE_ERR_OK) {
 	  prom_printf("%s:%d,", msgfile.dev, msgfile.part);
@@ -305,13 +311,7 @@
      gunzip_file = file;
      gunzip_test_header();
      opened = 1;
-
-     msg = malloc(2001 - paging * 1000); /* 2000 for not paged messages, 1000 for paged*/
-     if (!msg)
-	  goto done;
-     else
-	  memset(msg, 0, (2001 - paging * 1000));
-
+    
      if ( ( compressed_file ?
             gunzip_read(msg, (2000 - paging * 1000)) :
             file.fs->read(&file, (2000 - paging * 1000), msg) 
@@ -375,7 +375,7 @@
 
      /* Build the path to the file */
      if (_machine == _MACH_chrp)
-	  strcpy(conf_path, "/etc/");
+	  strcpy(conf_path, "/boot/");
      else if (path && *path)
 	  strcpy(conf_path, path);
      else



More information about the pld-cvs-commit mailing list