From patchwork Wed Jun 11 14:01:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 4336281 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 55CFABEEAA for ; Wed, 11 Jun 2014 14:02:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2509F2022A for ; Wed, 11 Jun 2014 14:02:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED40020218 for ; Wed, 11 Jun 2014 14:01:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755574AbaFKOBv (ORCPT ); Wed, 11 Jun 2014 10:01:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28088 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753952AbaFKOBu (ORCPT ); Wed, 11 Jun 2014 10:01:50 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5BE1mvP025276 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Jun 2014 10:01:48 -0400 Received: from dhcp-27-201.brq.redhat.com (dhcp-1-235.brq.redhat.com [10.34.1.235]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5BE1ZbX014365; Wed, 11 Jun 2014 10:01:47 -0400 From: Andrew Jones To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: christoffer.dall@linaro.org, pbonzini@redhat.com Subject: [PATCH v5 07/19] libfdt: get libfdt to build Date: Wed, 11 Jun 2014 16:01:22 +0200 Message-Id: <1402495294-30737-8-git-send-email-drjones@redhat.com> In-Reply-To: <1402495294-30737-1-git-send-email-drjones@redhat.com> References: <1402495294-30737-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add string functions needed for libfdt, and add a make target. Signed-off-by: Andrew Jones Acked-by: Christoffer Dall --- v4: rewrite strchr w/out use of strlen, drop libfdt_env.h modifications --- Makefile | 21 +++++++++++++++++++-- lib/libcflat.h | 4 ++++ lib/string.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) 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 cb6663d33ef5a..42b7a41b5f832 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -45,6 +45,7 @@ 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 char *strchr(const char *s, int c); extern int printf(const char *fmt, ...); extern int snprintf(char *buf, int size, const char *fmt, ...); @@ -54,6 +55,9 @@ 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 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); 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..fe90c8b1289f2 100644 --- a/lib/string.c +++ b/lib/string.c @@ -31,6 +31,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 +62,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;