These basic functions are needed by relocation. To avoid bringing in all string.c functions (and the resulting code bloat for architectures where -ffunction-sections is not used), move these into their own file.
Also tidy up the checkpatch warnings and function comments at the same time. I considered splitting these into two separate files, but I think that is overkill. The justification is that these two functions are needed regardless of what the 'user' code in U-Boot does, just to support relocation. Signed-off-by: Simon Glass <s...@chromium.org> --- Changes in v4: - Add new patch to separate out memcpy(), memset() lib/Makefile | 1 + lib/membasic.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/string.c | 71 -------------------------------------- 3 files changed, 104 insertions(+), 71 deletions(-) create mode 100644 lib/membasic.c diff --git a/lib/Makefile b/lib/Makefile index e6e6ec6..0480824 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -57,6 +57,7 @@ endif COBJS-y += ctype.o COBJS-y += div64.o +COBJS-y += membasic.o COBJS-y += string.o COBJS-y += time.o COBJS-$(CONFIG_BOOTP_PXE) += uuid.o diff --git a/lib/membasic.c b/lib/membasic.c new file mode 100644 index 0000000..2448e4c --- /dev/null +++ b/lib/membasic.c @@ -0,0 +1,103 @@ +/* + * Basic memory routines needed by relocation (memcpy, memset). + * + * Copyright (c) 2011 The Chromium OS Authors. + * Copyright (C) 1991, 1992 Linus Torvalds + * + * See file CREDITS for list of people who contributed to this + * project. + * + * 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 <linux/types.h> +#include <linux/string.h> + + +#ifndef __HAVE_ARCH_MEMSET +/** + * Fill a region of memory with the given value + * + * @param s Pointer to the start of the area. + * @param c The byte to fill the area with + * @param count The size of the area. + * @return pointer to start of the area (as passed in) + * + * Do not use memset() to access IO space, use memset_io() instead. + */ +void *memset(void *s, int c, size_t count) +{ + unsigned long *sl = (unsigned long *) s; + unsigned long cl = 0; + char *s8; + int i; + + /* do it one word at a time (32 bits or 64 bits) while possible */ + if (((ulong)s & (sizeof(*sl) - 1)) == 0) { + for (i = 0; i < sizeof(*sl); i++) { + cl <<= 8; + cl |= c & 0xff; + } + while (count >= sizeof(*sl)) { + *sl++ = cl; + count -= sizeof(*sl); + } + } + /* fill 8 bits at a time */ + s8 = (char *)sl; + while (count--) + *s8++ = c; + + return s; +} +#endif + +#ifndef __HAVE_ARCH_MEMCPY +/** + * Copy one area of memory to another + * + * You should not use this function to access IO space, use memcpy_toio() + * or memcpy_fromio() instead. + * + * @param dest Where to copy to + * @param src Where to copy from + * @param count The size of the area. + * @return destination address (as passed in) + */ +void *memcpy(void *dest, const void *src, size_t count) +{ + unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src; + char *d8, *s8; + + if (src == dest) + return dest; + + /* while all data is aligned (common case), copy a word at a time */ + if ((((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) { + while (count >= sizeof(*dl)) { + *dl++ = *sl++; + count -= sizeof(*dl); + } + } + /* copy the reset one byte at a time */ + d8 = (char *)dl; + s8 = (char *)sl; + while (count--) + *d8++ = *s8++; + + return dest; +} +#endif diff --git a/lib/string.c b/lib/string.c index c3ad055..5db0eaf 100644 --- a/lib/string.c +++ b/lib/string.c @@ -431,42 +431,6 @@ char *strswab(const char *s) } #endif -#ifndef __HAVE_ARCH_MEMSET -/** - * memset - Fill a region of memory with the given value - * @s: Pointer to the start of the area. - * @c: The byte to fill the area with - * @count: The size of the area. - * - * Do not use memset() to access IO space, use memset_io() instead. - */ -void * memset(void * s,int c,size_t count) -{ - unsigned long *sl = (unsigned long *) s; - unsigned long cl = 0; - char *s8; - int i; - - /* do it one word at a time (32 bits or 64 bits) while possible */ - if ( ((ulong)s & (sizeof(*sl) - 1)) == 0) { - for (i = 0; i < sizeof(*sl); i++) { - cl <<= 8; - cl |= c & 0xff; - } - while (count >= sizeof(*sl)) { - *sl++ = cl; - count -= sizeof(*sl); - } - } - /* fill 8 bits at a time */ - s8 = (char *)sl; - while (count--) - *s8++ = c; - - return s; -} -#endif - #ifndef __HAVE_ARCH_BCOPY /** * bcopy - Copy one area of memory to another @@ -491,41 +455,6 @@ char * bcopy(const char * src, char * dest, int count) } #endif -#ifndef __HAVE_ARCH_MEMCPY -/** - * memcpy - Copy one area of memory to another - * @dest: Where to copy to - * @src: Where to copy from - * @count: The size of the area. - * - * You should not use this function to access IO space, use memcpy_toio() - * or memcpy_fromio() instead. - */ -void * memcpy(void *dest, const void *src, size_t count) -{ - unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src; - char *d8, *s8; - - if (src == dest) - return dest; - - /* while all data is aligned (common case), copy a word at a time */ - if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) { - while (count >= sizeof(*dl)) { - *dl++ = *sl++; - count -= sizeof(*dl); - } - } - /* copy the reset one byte at a time */ - d8 = (char *)dl; - s8 = (char *)sl; - while (count--) - *d8++ = *s8++; - - return dest; -} -#endif - #ifndef __HAVE_ARCH_MEMMOVE /** * memmove - Copy one area of memory to another -- 1.7.7.3 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot