[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [PATCH ARM v10 2/2] arm: build system



Based on an initial patch by Karim Raslan.

This activates the ARM code added in the previous patches. On ARM,
Mini-OS will boot and display some output on the console. Tested with:

make XEN_TARGET_ARCH=arm32 CROSS_COMPILE=arm-linux-gnueabihf- \
        CONFIG_TEST=y CONFIG_START_NETWORK=n CONFIG_BLKFRONT=n \
        CONFIG_NETFRONT=n CONFIG_FBFRONT=n CONFIG_KBDFRONT=n \
        CONFIG_CONSFRONT=n CONFIG_XC=n -j4

The memmove implementation is from FreeBSD's
contrib/ldns/compat/memmove.c (r246827).

Signed-off-by: Karim Allah Ahmed <karim.allah.ahmed@xxxxxxxxx>
Signed-off-by: Thomas Leonard <talex5@xxxxxxxxx>

---

Same as v9. Note that COPYING contains the BSD license needed for
memmove.
---
 .gitmodules          |  3 +++
 COPYING              | 27 +++++++++++++++++++++++++++
 Config.mk            |  2 ++
 Makefile             | 27 ++++++++++++++++++++++++++-
 arch/arm/Makefile    | 35 +++++++++++++++++++++++++++++++++++
 arch/arm/arch.mk     |  6 ++++++
 dtc                  |  1 +
 include/lib.h        |  4 +++-
 include/libfdt_env.h | 33 +++++++++++++++++++++++++++++++++
 lib/memmove.c        | 45 +++++++++++++++++++++++++++++++++++++++++++++
 lib/string.c         | 12 ++++++++++++
 11 files changed, 193 insertions(+), 2 deletions(-)
 create mode 100644 .gitmodules
 create mode 100755 arch/arm/Makefile
 create mode 100644 arch/arm/arch.mk
 create mode 160000 dtc
 create mode 100644 include/libfdt_env.h
 create mode 100644 lib/memmove.c

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..221102d
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "dtc"]
+       path = dtc
+       url = git://git.kernel.org/pub/scm/utils/dtc/dtc.git
diff --git a/COPYING b/COPYING
index 1d9df6c..b676bb6 100644
--- a/COPYING
+++ b/COPYING
@@ -34,3 +34,30 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.
 
+
+Copyright (c) 2005,2006, NLnetLabs
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+    * Neither the name of NLnetLabs nor the names of its
+      contributors may be used to endorse or promote products derived from this
+      software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/Config.mk b/Config.mk
index e5d8ade..eb53f2d 100644
--- a/Config.mk
+++ b/Config.mk
@@ -54,6 +54,8 @@ export XEN_INTERFACE_VERSION
 # If not x86 then use $(MINIOS_TARGET_ARCH)
 ifeq ($(findstring x86_,$(MINIOS_TARGET_ARCH)),x86_)
 TARGET_ARCH_FAM = x86
+else ifeq ($(findstring arm,$(MINIOS_TARGET_ARCH)),arm)
+TARGET_ARCH_FAM = arm
 else
 TARGET_ARCH_FAM = $(MINIOS_TARGET_ARCH)
 endif
diff --git a/Makefile b/Makefile
index 2cb5e51..d06fc3b 100644
--- a/Makefile
+++ b/Makefile
@@ -54,8 +54,15 @@ DEF_CFLAGS += $(flags-y)
 # Symlinks and headers that must be created before building the C files
 GENERATED_HEADERS := include/list.h $(ARCH_LINKS) include/mini-os 
include/$(TARGET_ARCH_FAM)/mini-os
 
+ifeq ($(MINIOS_TARGET_ARCH),arm32)
+GENERATED_HEADERS += include/fdt.h include/libfdt.h
+endif
+
 EXTRA_DEPS += $(GENERATED_HEADERS)
 
+include/%.h: dtc/libfdt/%.h
+       ln -s ../$^ $@
+
 # Include common mini-os makerules.
 include minios.mk
 
@@ -76,7 +83,18 @@ EXTRA_OBJS =
 TARGET := mini-os
 
 # Subdirectories common to mini-os
-SUBDIRS := lib xenbus console
+SUBDIRS := lib xenbus console dtc/libfdt
+
+FDT_SRC :=
+ifeq ($(MINIOS_TARGET_ARCH),arm32)
+# Need libgcc.a for division helpers
+LDLIBS += `$(CC) -print-libgcc-file-name`
+
+# Device tree support
+FDT_SRC := dtc/libfdt/fdt.c dtc/libfdt/fdt_ro.c dtc/libfdt/fdt_strerror.c
+
+src-y += ${FDT_SRC}
+endif
 
 src-$(CONFIG_BLKFRONT) += blkfront.c
 src-$(CONFIG_TPMFRONT) += tpmfront.c
@@ -98,10 +116,13 @@ src-y += sched.c
 src-$(CONFIG_TEST) += test.c
 
 src-y += lib/ctype.c
+ifneq ($(MINIOS_TARGET_ARCH),arm32)
 src-y += lib/math.c
+endif
 src-y += lib/printf.c
 src-y += lib/stack_chk_fail.c
 src-y += lib/string.c
+src-y += lib/memmove.c
 src-y += lib/sys.c
 src-y += lib/xmalloc.c
 src-$(CONFIG_XENBUS) += lib/xs.c
@@ -188,7 +209,11 @@ $(OBJ_DIR)/$(TARGET): $(OBJS) $(APP_O) arch_lib
        $(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) 
-o $@.o
        $(OBJCOPY) -w -G $(GLOBAL_PREFIX)* -G _start $@.o $@.o
        $(LD) $(LDFLAGS) $(LDFLAGS_FINAL) $@.o $(EXTRA_OBJS) -o $@
+ifeq ($(MINIOS_TARGET_ARCH),arm32)
+       $(OBJCOPY) -O binary $@ $@.img
+else
        gzip -f -9 -c $@ >$@.gz
+endif
 
 .PHONY: clean arch_clean
 
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
new file mode 100755
index 0000000..e018dad
--- /dev/null
+++ b/arch/arm/Makefile
@@ -0,0 +1,35 @@
+#
+# ARM architecture specific makefiles.
+#
+
+TOPLEVEL_DIR = $(CURDIR)/../..
+OBJ_DIR=$(CURDIR)
+include ../../Config.mk
+
+# include arch.mk has to be before minios.mk!
+
+include arch.mk
+include ../../minios.mk
+
+include $(MINI-OS_ROOT)/config/MiniOS.mk
+
+
+# Sources here are all *.c (without $(MINIOS_TARGET_ARCH).S)
+# This is handled in $(HEAD_ARCH_OBJ)
+ARCH_SRCS := $(wildcard *.c)
+
+# The objects built from the sources.
+ARCH_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(ARCH_SRCS))
+
+ARCH_OBJS += $(OBJ_DIR)/hypercalls32.o
+
+all: $(OBJ_DIR)/$(ARCH_LIB)
+
+# $(HEAD_ARCH_OBJ) is only built here, needed on linking
+# in ../../Makefile.
+$(OBJ_DIR)/$(ARCH_LIB): $(ARCH_OBJS) $(OBJ_DIR)/$(HEAD_ARCH_OBJ)
+       $(AR) rv $(OBJ_DIR)/$(ARCH_LIB) $(ARCH_OBJS)
+
+clean:
+       rm -f $(OBJ_DIR)/$(ARCH_LIB) $(ARCH_OBJS) $(OBJ_DIR)/$(HEAD_ARCH_OBJ)
+
diff --git a/arch/arm/arch.mk b/arch/arm/arch.mk
new file mode 100644
index 0000000..b4cb65b
--- /dev/null
+++ b/arch/arm/arch.mk
@@ -0,0 +1,6 @@
+ifeq ($(MINIOS_TARGET_ARCH),arm32)
+DEF_ASFLAGS += -march=armv7-a -mfpu=vfpv3
+ARCH_CFLAGS  := -march=armv7-a -marm -fms-extensions -D__arm__ 
-DXEN_HAVE_PV_GUEST_ENTRY #-DCPU_EXCLUSIVE_LDST
+EXTRA_INC += $(TARGET_ARCH_FAM)/$(MINIOS_TARGET_ARCH)
+EXTRA_SRC += arch/$(EXTRA_INC)
+endif
diff --git a/dtc b/dtc
new file mode 160000
index 0000000..64c46b0
--- /dev/null
+++ b/dtc
@@ -0,0 +1 @@
+Subproject commit 64c46b098b969502a74c8b0fd97e6f5e4aa07e21
diff --git a/include/lib.h b/include/lib.h
index 62836c7..326e39f 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -95,6 +95,7 @@ char  *strncpy(char * __restrict, const char * __restrict, 
size_t);
 
 char   *strstr(const char *, const char *);
 
+void *memmove(void *, const void *, size_t);
 void *memset(void *, int, size_t);
 
 char *strchr(const char *p, int ch);
@@ -104,7 +105,8 @@ char *strrchr(const char *p, int ch);
  *     @(#)systm.h     8.7 (Berkeley) 3/29/95
  * $FreeBSD$
  */
-void   *memcpy(void *to, const void *from, size_t len);
+void *memcpy(void *to, const void *from, size_t len);
+void *memchr(const void *s, int c, size_t n);
 
 size_t strnlen(const char *, size_t);
 #endif
diff --git a/include/libfdt_env.h b/include/libfdt_env.h
new file mode 100644
index 0000000..722fac6
--- /dev/null
+++ b/include/libfdt_env.h
@@ -0,0 +1,33 @@
+#ifndef _LIBFDT_ENV_H
+#define _LIBFDT_ENV_H
+
+#include <stddef.h>
+#include <stdint.h>
+#include <lib.h>
+
+typedef uint16_t fdt16_t;
+typedef uint32_t fdt32_t;
+typedef uint64_t fdt64_t;
+
+#define EXTRACT_BYTE(n) ((unsigned long long)((uint8_t *)&x)[n])
+static inline uint16_t fdt16_to_cpu(uint16_t x)
+{
+    return (EXTRACT_BYTE(0) << 8) | EXTRACT_BYTE(1);
+}
+#define cpu_to_fdt16(x) fdt16_to_cpu(x)
+
+static inline uint32_t fdt32_to_cpu(uint32_t x)
+{
+    return (EXTRACT_BYTE(0) << 24) | (EXTRACT_BYTE(1) << 16) | 
(EXTRACT_BYTE(2) << 8) | EXTRACT_BYTE(3);
+}
+#define cpu_to_fdt32(x) fdt32_to_cpu(x)
+
+static inline uint64_t fdt64_to_cpu(uint64_t x)
+{
+    return (EXTRACT_BYTE(0) << 56) | (EXTRACT_BYTE(1) << 48) | 
(EXTRACT_BYTE(2) << 40) | (EXTRACT_BYTE(3) << 32)
+            | (EXTRACT_BYTE(4) << 24) | (EXTRACT_BYTE(5) << 16) | 
(EXTRACT_BYTE(6) << 8) | EXTRACT_BYTE(7);
+}
+#define cpu_to_fdt64(x) fdt64_to_cpu(x)
+#undef EXTRACT_BYTE
+
+#endif /* _LIBFDT_ENV_H */
diff --git a/lib/memmove.c b/lib/memmove.c
new file mode 100644
index 0000000..0298b7c
--- /dev/null
+++ b/lib/memmove.c
@@ -0,0 +1,45 @@
+/*
+ *     memmove.c: memmove compat implementation.
+ *
+ *     Copyright (c) 2001-2008, NLnet Labs. All rights reserved.
+ *
+ * See COPYING for the license.
+*/
+
+#include <os.h>
+#include <mini-os/lib.h>
+
+#ifndef HAVE_LIBC
+
+void *memmove(void *dest, const void *src, size_t n)
+{
+       uint8_t* from = (uint8_t*) src;
+       uint8_t* to = (uint8_t*) dest;
+
+       if (from == to || n == 0)
+               return dest;
+       if (to > from && to-from < (int)n) {
+               /* to overlaps with from */
+               /*  <from......>         */
+               /*         <to........>  */
+               /* copy in reverse, to avoid overwriting from */
+               int i;
+               for(i=n-1; i>=0; i--)
+                       to[i] = from[i];
+               return dest;
+       }
+       if (from > to  && from-to < (int)n) {
+               /* to overlaps with from */
+               /*        <from......>   */
+               /*  <to........>         */
+               /* copy forwards, to avoid overwriting from */
+               size_t i;
+               for(i=0; i<n; i++)
+                       to[i] = from[i];
+               return dest;
+       }
+       memcpy(dest, src, n);
+       return dest;
+}
+
+#endif
diff --git a/lib/string.c b/lib/string.c
index 8b24146..c96ca41 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -225,4 +225,16 @@ int ffs(int i)
    return 0;
 }
 
+void *memchr(const void *s, int c, size_t n)
+{
+    if (n != 0) {
+        const unsigned char *p = s;
+
+        do {
+            if (*p++ == (unsigned char)c)
+                return ((void *)(uintptr_t)(p - 1));
+        } while (--n != 0);
+    }
+    return (NULL);
+}
 #endif
-- 
2.4.6


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/minios-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.