From: Andrew Jones <drjones@redhat.com>
To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org
Cc: christoffer.dall@linaro.org, pbonzini@redhat.com
Subject: [PATCH v6 02/17] libfdt: get libfdt to build
Date: Fri, 11 Jul 2014 10:19:32 +0200 [thread overview]
Message-ID: <1405066787-5793-3-git-send-email-drjones@redhat.com> (raw)
In-Reply-To: <1405066787-5793-1-git-send-email-drjones@redhat.com>
Add string functions needed for libfdt, and add a make target for
it. Also split string function declarations out to own string.h.
While at it, add strcpy.
Signed-off-by: Andrew Jones <drjones@redhat.com>
Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
---
v6: split out string.h [Paolo Bonzini]
v4: rewrite strchr w/out use of strlen, drop libfdt_env.h modifications
---
Makefile | 21 +++++++++++++++++++--
lib/libcflat.h | 8 +-------
lib/string.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/string.h | 15 +++++++++++++++
4 files changed, 89 insertions(+), 9 deletions(-)
create mode 100644 lib/string.h
diff --git a/Makefile b/Makefile
index 32ae9a59db5b0..fba58e36f272f 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,13 @@ cflatobjs := \
lib/string.o \
lib/report.o
+# libfdt paths
+LIBFDT_objdir = lib/libfdt
+LIBFDT_srcdir = lib/libfdt
+LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a
+LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES))
+LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION))
+
#include architecure specific make rules
include config/config-$(ARCH).mak
@@ -46,6 +53,11 @@ LDFLAGS += -pthread -lrt
$(libcflat): $(cflatobjs)
$(AR) rcs $@ $^
+include $(LIBFDT_srcdir)/Makefile.libfdt
+$(LIBFDT_archive): CFLAGS += -ffreestanding -I lib -I lib/libfdt -Wno-sign-compare
+$(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
+ $(AR) rcs $@ $^
+
%.o: %.S
$(CC) $(CFLAGS) -c -nostdlib -o $@ $<
@@ -58,10 +70,15 @@ install:
clean: arch_clean
$(RM) lib/.*.d $(libcflat) $(cflatobjs)
-distclean: clean
+libfdt_clean:
+ $(RM) $(LIBFDT_archive) \
+ $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) \
+ $(LIBFDT_objdir)/.*.d
+
+distclean: clean libfdt_clean
$(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.*
-cscope: common_dirs = lib
+cscope: common_dirs = lib lib/libfdt
cscope:
$(RM) ./cscope.*
find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \
diff --git a/lib/libcflat.h b/lib/libcflat.h
index c9577350ec275..5acfee2d9818a 100644
--- a/lib/libcflat.h
+++ b/lib/libcflat.h
@@ -21,6 +21,7 @@
#define __LIBCFLAT_H
#include <stdarg.h>
+#include <string.h>
#define xstr(s) xxstr(s)
#define xxstr(s) #s
@@ -42,19 +43,12 @@ typedef _Bool bool;
extern void exit(int code);
-extern unsigned long strlen(const char *buf);
-extern char *strcat(char *dest, const char *src);
-extern int strcmp(const char *a, const char *b);
-
extern int printf(const char *fmt, ...);
extern int snprintf(char *buf, int size, const char *fmt, ...);
extern int vsnprintf(char *buf, int size, const char *fmt, va_list va);
extern void puts(const char *s);
-extern void *memset(void *s, int c, size_t n);
-extern void *memcpy(void *dest, const void *src, size_t n);
-
extern long atol(const char *ptr);
#define ARRAY_SIZE(_a) (sizeof(_a)/sizeof((_a)[0]))
diff --git a/lib/string.c b/lib/string.c
index 3a9caf720bf2b..026f50252287c 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -20,6 +20,12 @@ char *strcat(char *dest, const char *src)
return dest;
}
+char *strcpy(char *dest, const char *src)
+{
+ *dest = 0;
+ return strcat(dest, src);
+}
+
int strcmp(const char *a, const char *b)
{
while (*a == *b) {
@@ -31,6 +37,14 @@ int strcmp(const char *a, const char *b)
return *a - *b;
}
+char *strchr(const char *s, int c)
+{
+ while (*s != (char)c)
+ if (*s++ == '\0')
+ return NULL;
+ return (char *)s;
+}
+
void *memset(void *s, int c, size_t n)
{
size_t i;
@@ -54,6 +68,46 @@ void *memcpy(void *dest, const void *src, size_t n)
return dest;
}
+int memcmp(const void *s1, const void *s2, size_t n)
+{
+ const unsigned char *a = s1, *b = s2;
+ int ret = 0;
+
+ while (n--) {
+ ret = *a - *b;
+ if (ret)
+ break;
+ ++a, ++b;
+ }
+ return ret;
+}
+
+void *memmove(void *dest, const void *src, size_t n)
+{
+ const unsigned char *s = src;
+ unsigned char *d = dest;
+
+ if (d <= s) {
+ while (n--)
+ *d++ = *s++;
+ } else {
+ d += n, s += n;
+ while (n--)
+ *--d = *--s;
+ }
+ return dest;
+}
+
+void *memchr(const void *s, int c, size_t n)
+{
+ const unsigned char *str = s, chr = (unsigned char)c;
+
+ while (n--)
+ if (*str++ == chr)
+ return (void *)(str - 1);
+ return NULL;
+}
+
long atol(const char *ptr)
{
long acc = 0;
diff --git a/lib/string.h b/lib/string.h
new file mode 100644
index 0000000000000..dbab368b1b9e4
--- /dev/null
+++ b/lib/string.h
@@ -0,0 +1,15 @@
+#ifndef __STRING_H
+#define __STRING_H
+
+extern unsigned long strlen(const char *buf);
+extern char *strcat(char *dest, const char *src);
+extern char *strcpy(char *dest, const char *src);
+extern int strcmp(const char *a, const char *b);
+extern char *strchr(const char *s, int c);
+extern void *memset(void *s, int c, size_t n);
+extern void *memcpy(void *dest, const void *src, size_t n);
+extern int memcmp(const void *s1, const void *s2, size_t n);
+extern void *memmove(void *dest, const void *src, size_t n);
+extern void *memchr(const void *s, int c, size_t n);
+
+#endif /* _STRING_H */
--
1.9.3
next prev parent reply other threads:[~2014-07-11 8:19 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-11 8:19 [PATCH v6 00/17] kvm-unit-tests/arm: initial drop Andrew Jones
2014-07-11 8:19 ` Andrew Jones [this message]
2014-07-11 8:19 ` [PATCH v6 03/17] add support for Linux device trees Andrew Jones
2014-07-11 8:19 ` [PATCH v6 04/17] libcflat: add abort() and assert() Andrew Jones
2014-07-11 8:19 ` [PATCH v6 05/17] Introduce asm-generic/*.h files Andrew Jones
2014-07-11 8:19 ` [PATCH v6 06/17] Introduce alloc_ops Andrew Jones
2014-07-11 8:40 ` Paolo Bonzini
2014-07-11 8:55 ` Andrew Jones
2014-07-11 9:41 ` Paolo Bonzini
2014-07-11 10:07 ` Andrew Jones
2014-07-11 10:12 ` Paolo Bonzini
2014-07-15 17:16 ` Andrew Jones
2014-07-11 8:19 ` [PATCH v6 07/17] add minimal virtio support for devtree virtio-mmio Andrew Jones
2014-07-11 8:32 ` Paolo Bonzini
2014-07-11 9:08 ` Andrew Jones
2014-07-11 9:27 ` Paolo Bonzini
2014-07-11 9:36 ` Andrew Jones
2014-07-15 17:22 ` Andrew Jones
2014-07-11 8:19 ` [PATCH v6 08/17] lib: add asm/page.h and virt_to_phys/phys_to_virt Andrew Jones
2014-07-11 8:19 ` [PATCH v6 09/17] virtio: add minimal support for virtqueues Andrew Jones
2014-07-11 9:23 ` Paolo Bonzini
2014-07-11 9:32 ` Paolo Bonzini
2014-07-11 9:52 ` Andrew Jones
2014-07-11 8:19 ` [PATCH v6 10/17] Introduce chr-testdev Andrew Jones
2014-07-11 8:19 ` [PATCH v6 11/17] libcflat: clean up libcflat.h Andrew Jones
2014-07-11 8:19 ` [PATCH v6 12/17] arm: initial drop Andrew Jones
2014-07-11 8:19 ` [PATCH v6 13/17] arm: Add spinlock implementation Andrew Jones
2014-07-11 8:19 ` [PATCH v6 14/17] arm: Add IO accessors to avoid register-writeback Andrew Jones
2014-07-11 8:19 ` [PATCH v6 15/17] arm: Add arch-specific asm/page.h and __va/__pa Andrew Jones
2014-07-11 8:19 ` [PATCH v6 16/17] arm: add useful headers from the Linux kernel Andrew Jones
2014-07-11 8:19 ` [PATCH v6 17/17] arm: vectors support Andrew Jones
2014-07-11 8:47 ` [PATCH v6 00/17] kvm-unit-tests/arm: initial drop Paolo Bonzini
2014-07-15 17:24 ` Andrew Jones
2014-07-15 20:19 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1405066787-5793-3-git-send-email-drjones@redhat.com \
--to=drjones@redhat.com \
--cc=christoffer.dall@linaro.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox