[PATCH 13/15] tidy-strings.patch

Andy Green andy at openmoko.com
Wed Aug 13 01:59:54 CEST 2008


Move things around to tidy them up

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

 src/kboot.h  |    1 
 src/phase2.c |   25 ------------
 src/serial.c |   67 ---------------------------------
 src/utils.c  |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 118 insertions(+), 92 deletions(-)
 create mode 100644 src/utils.c

diff --git a/src/kboot.h b/src/kboot.h
index 1c70dda..6ad28de 100644
--- a/src/kboot.h
+++ b/src/kboot.h
@@ -12,6 +12,7 @@ int puts(const char *string);
 void printhex(unsigned char v);
 void print32(unsigned int u);
 void hexdump(unsigned char *start, int len);
+unsigned int _ntohl(unsigned int n);
 
 #endif
 
diff --git a/src/phase2.c b/src/phase2.c
index 75ae2fd..4c4fedf 100644
--- a/src/phase2.c
+++ b/src/phase2.c
@@ -23,31 +23,6 @@ typedef unsigned int uint32_t;
 #define C1_IC           (1<<12)         /* icache off/on */
 #define C1_HIGH_VECTORS (1<<13)         /* location of vectors: low/high addresses */
 
-size_t strlen(const char *s)
-{
-	size_t n = 0;
-
-	while (*s++)
-		n++;
-
-	return n;
-}
-
-char *strcpy(char *dest, const char *src)
-{
-	char * dest_orig = dest;
-
-	while (*src)
-		*dest++ = *src++;
-
-	return dest_orig;
-}
-
-unsigned int _ntohl(unsigned int n) {
-	return ((n & 0xff) << 24) | ((n & 0xff00) << 8) |
-			       ((n & 0xff0000) >> 8) | ((n & 0xff000000) >> 24);
-}
-
 void bootloader_second_phase(void)
 {
 	image_header_t	*hdr;
diff --git a/src/serial.c b/src/serial.c
index 5fb8b04..7b56fe6 100644
--- a/src/serial.c
+++ b/src/serial.c
@@ -23,8 +23,6 @@
 #include "blink_led.h"
 #include "kboot.h"
 
-#define DEBUG_CONSOLE_UART UART2
-
 void serial_init (const int ubrdiv_val,const int uart)
 {
   switch(uart)
@@ -77,71 +75,6 @@ void serial_putc (const int uart,const char c)
     }
 }
 
-int puts(const char *string)
-{
-	while (*string)
-		serial_putc(DEBUG_CONSOLE_UART, *string++);
-	serial_putc(DEBUG_CONSOLE_UART, '\n');
-
-	return 1;
-}
-
-/* done like this to avoid needing statics in steppingstone */
-void printnybble(unsigned char n)
-{
-	if (n < 10)
-		serial_putc(DEBUG_CONSOLE_UART, '0' + n);
-	else
-		serial_putc(DEBUG_CONSOLE_UART, 'a' + n - 10);
-}
-
-void printhex(unsigned char n)
-{
-	printnybble((n >> 4) & 15);
-	printnybble(n & 15);
-}
-
-void print32(unsigned int u)
-{
-	printhex(u >> 24);
-	printhex(u >> 16);
-	printhex(u >> 8);
-	printhex(u);
-}
-
-void hexdump(unsigned char *start, int len)
-{
-	int n;
-
-	while (len > 0) {
-		print32((int)start);
-		serial_putc(DEBUG_CONSOLE_UART, ':');
-		serial_putc(DEBUG_CONSOLE_UART, ' ');
-		for (n = 0; n < 16; n++) {
-			printhex(*start++);
-			serial_putc(DEBUG_CONSOLE_UART, ' ');
-		}
-		serial_putc(DEBUG_CONSOLE_UART, '\n');
-		len -= 16;
-	}
-}
-
-int printk(const char *fmt, ...)
-{
-	va_list args;
-	int r;
-	static char buf[512];
-	const char *p = buf;
-
-	va_start(args, fmt);
-	r = vsprintf(buf, fmt, args);
-	va_end(args);
-	p = fmt;
-	while (*p)
-		serial_putc(DEBUG_CONSOLE_UART, *p++);
-
-	return r;
-}
 
 /*
  * =====================================================================
diff --git a/src/utils.c b/src/utils.c
new file mode 100644
index 0000000..cb444d7
--- /dev/null
+++ b/src/utils.c
@@ -0,0 +1,117 @@
+/*
+ * (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 "kboot.h"
+#include <string.h>
+
+#define DEBUG_CONSOLE_UART UART2
+
+size_t strlen(const char *s)
+{
+	size_t n = 0;
+
+	while (*s++)
+		n++;
+
+	return n;
+}
+
+char *strcpy(char *dest, const char *src)
+{
+	char * dest_orig = dest;
+
+	while (*src)
+		*dest++ = *src++;
+
+	return dest_orig;
+}
+
+unsigned int _ntohl(unsigned int n) {
+	return ((n & 0xff) << 24) | ((n & 0xff00) << 8) |
+			       ((n & 0xff0000) >> 8) | ((n & 0xff000000) >> 24);
+}
+
+int puts(const char *string)
+{
+	while (*string)
+		serial_putc(DEBUG_CONSOLE_UART, *string++);
+	serial_putc(DEBUG_CONSOLE_UART, '\n');
+
+	return 1;
+}
+
+/* done like this to avoid needing statics in steppingstone */
+void printnybble(unsigned char n)
+{
+	if (n < 10)
+		serial_putc(DEBUG_CONSOLE_UART, '0' + n);
+	else
+		serial_putc(DEBUG_CONSOLE_UART, 'a' + n - 10);
+}
+
+void printhex(unsigned char n)
+{
+	printnybble((n >> 4) & 15);
+	printnybble(n & 15);
+}
+
+void print32(unsigned int u)
+{
+	printhex(u >> 24);
+	printhex(u >> 16);
+	printhex(u >> 8);
+	printhex(u);
+}
+
+void hexdump(unsigned char *start, int len)
+{
+	int n;
+
+	while (len > 0) {
+		print32((int)start);
+		serial_putc(DEBUG_CONSOLE_UART, ':');
+		serial_putc(DEBUG_CONSOLE_UART, ' ');
+		for (n = 0; n < 16; n++) {
+			printhex(*start++);
+			serial_putc(DEBUG_CONSOLE_UART, ' ');
+		}
+		serial_putc(DEBUG_CONSOLE_UART, '\n');
+		len -= 16;
+	}
+}
+
+int printk(const char *fmt, ...)
+{
+	va_list args;
+	int r;
+	static char buf[512];
+	const char *p = buf;
+
+	va_start(args, fmt);
+	r = vsprintf(buf, fmt, args);
+	va_end(args);
+	p = fmt;
+	while (*p)
+		serial_putc(DEBUG_CONSOLE_UART, *p++);
+
+	return r;
+}





More information about the openmoko-kernel mailing list