@@ -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 \
@@ -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]))
@@ -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;
new file mode 100644
@@ -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 */