[PATCH 3/4] qi-clean-split-utils.c-by-phase.patch

Andy Green andy at openmoko.com
Thu Oct 30 09:00:03 CET 2008


Some of utils.c isn't used until the full Qi image has been loaded into
memory, to save space in 4K steppingstone case on 2442, we split utils.c now
so only the interesting routines for steppingstone time take up space there.

Signed-off-by: Andy Green <andy at openmoko.com>
---

 include/qi.h       |    1 
 src/utils-phase2.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/utils.c        |   79 -------------------------------------
 3 files changed, 113 insertions(+), 78 deletions(-)
 create mode 100644 src/utils-phase2.c

diff --git a/include/qi.h b/include/qi.h
index 90d16cf..1ddf9cb 100644
--- a/include/qi.h
+++ b/include/qi.h
@@ -25,6 +25,7 @@
 #include <qi-ctype.h>
 #include <asm/byteorder.h>
 
+#define MALLOC_POOL_EXTENT (100 * 1024)
 
 #define u32 unsigned int
 #define u16 unsigned short
diff --git a/src/utils-phase2.c b/src/utils-phase2.c
new file mode 100644
index 0000000..f02d5b1
--- /dev/null
+++ b/src/utils-phase2.c
@@ -0,0 +1,111 @@
+/*
+ * (C) Copyright 2008 Openmoko, Inc.
+ * Author: Andy Green <andy at openmoko.org>
+ *
+ * Little utils for print and strings
+ *
+ * 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 the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <qi.h>
+#include <string.h>
+
+extern void (*putc_func)(char);
+
+/*
+ * malloc pool needs to be in phase 2 bss section, we have phase 1 bss in
+ * steppingstone to allow full memory range testing in C
+ */
+u8 malloc_pool[MALLOC_POOL_EXTENT];
+void * malloc_pointer = &malloc_pool[0];
+
+
+/* improbably simple malloc and free for small and non-intense allocation
+ * just moves the allocation ptr forward each time and ignores free
+ */
+
+void *malloc(size_t size)
+{
+	void *p = malloc_pointer;
+
+	malloc_pointer += (size & ~3) + 4;
+
+	if (((u8 *)malloc_pointer - &malloc_pool[0]) > sizeof(malloc_pool)) {
+		puts("Ran out of malloc pool\n");
+		while (1)
+			;
+	}
+
+	return p;
+}
+
+void free(void *ptr)
+{
+}
+
+char *strncpy(char *dest, const char *src, size_t n)
+{
+	char * dest_orig = dest;
+
+	while (*src && n--)
+		*dest++ = *src++;
+
+	if (n)
+		*dest = '\0';
+
+	return dest_orig;
+}
+
+
+int strcmp(const char *s1, const char *s2)
+{
+	while (1) {
+		if (*s1 != *s2)
+			return *s1 - *s2;
+		if (!*s1)
+			return 0;
+		s1++;
+		s2++;
+	}
+}
+
+char *strchr(const char *s, int c)
+{
+	while ((*s) && (*s != c))
+		s++;
+
+	if (*s == c)
+		return (char *)s;
+
+	return NULL;
+}
+
+void hexdump(unsigned char *start, int len)
+{
+	int n;
+
+	while (len > 0) {
+		print32((int)start);
+		(putc_func)(':');
+		(putc_func)(' ');
+		for (n = 0; n < 16; n++) {
+			print8(*start++);
+			(putc_func)(' ');
+		}
+		(putc_func)('\n');
+		len -= 16;
+	}
+}
diff --git a/src/utils.c b/src/utils.c
index fc1e668..82f3e4a 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -23,7 +23,7 @@
 #include <qi.h>
 #include <string.h>
 
-static void (*putc_func)(char) = NULL;
+void (*putc_func)(char) = NULL;
 
 
 void set_putc_func(void (*p)(char))
@@ -52,43 +52,6 @@ char *strcpy(char *dest, const char *src)
 	return dest_orig;
 }
 
-char *strncpy(char *dest, const char *src, size_t n)
-{
-	char * dest_orig = dest;
-
-	while (*src && n--)
-		*dest++ = *src++;
-
-	if (n)
-		*dest = '\0';
-
-	return dest_orig;
-}
-
-
-int strcmp(const char *s1, const char *s2)
-{
-	while (1) {
-		if (*s1 != *s2)
-			return *s1 - *s2;
-		if (!*s1)
-			return 0;
-		s1++;
-		s2++;
-	}
-}
-
-char *strchr(const char *s, int c)
-{
-	while ((*s) && (*s != c))
-		s++;
-
-	if (*s == c)
-		return (char *)s;
-
-	return NULL;
-}
-
 int puts(const char *string)
 {
 	while (*string)
@@ -120,23 +83,6 @@ void print32(unsigned int u)
 	print8(u);
 }
 
-void hexdump(unsigned char *start, int len)
-{
-	int n;
-
-	while (len > 0) {
-		print32((int)start);
-		(putc_func)(':');
-		(putc_func)(' ');
-		for (n = 0; n < 16; n++) {
-			print8(*start++);
-			(putc_func)(' ');
-		}
-		(putc_func)('\n');
-		len -= 16;
-	}
-}
-
 void printdec(int n)
 {
 	int d[] = {
@@ -195,29 +141,6 @@ void *memset(void *s, int c, size_t n)
 	return s;
 }
 
-/* improbably simple malloc and free for small and non-intense allocation
- * just moves the allocation ptr forward each time and ignores free
- */
-
-void *malloc(size_t size)
-{
-	void *p = malloc_pointer;
-
-	malloc_pointer += (size & ~3) + 4;
-
-	if (((u8 *)malloc_pointer - &malloc_pool[0]) > sizeof(malloc_pool)) {
-		puts("Ran out of malloc pool\n");
-		while (1)
-			;
-	}
-
-	return p;
-}
-
-void free(void *ptr)
-{
-}
-
 int q;
 
 void udelay(int n)




More information about the openmoko-kernel mailing list