]> git.ozlabs.org Git - yaboot.git/commitdiff
yaboot does not compile against new e2fsprogs release
authorTony Breeds <tony@bakeyournoodle.com>
Thu, 6 Jan 2011 17:32:13 +0000 (17:32 +0000)
committerTony Breeds <tony@bakeyournoodle.com>
Tue, 18 Oct 2011 04:11:06 +0000 (15:11 +1100)
Add some "hacky" workarounds for missing libc functions required by
e2fsprogs.

Signed-off-by: Tony Breeds <tony@bakeyournoodle.com>
Makefile
include/nonstd.h [new file with mode: 0644]
lib/malloc.c
lib/nonstd.c [new file with mode: 0644]

index f54997782d5a6ff1189b4177ef4c0eff911ae125..b46165fc08ec6dcfcbc59deff0f5bfcc4b35d14f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -84,6 +84,7 @@ OBJS = second/crt0.o second/yaboot.o second/cache.o second/prom.o second/file.o
        second/partition.o second/fs.o second/cfg.o second/setjmp.o second/cmdline.o \
        second/fs_of.o second/fs_ext2.o second/fs_iso.o second/fs_swap.o \
        second/iso_util.o \
+       lib/nonstd.o \
        lib/nosys.o lib/string.o lib/strtol.o lib/vsprintf.o lib/ctype.o lib/malloc.o lib/strstr.o
 
 ifeq ($(USE_MD5_PASSWORDS),y)
diff --git a/include/nonstd.h b/include/nonstd.h
new file mode 100644 (file)
index 0000000..bad5f48
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ *  nonstd.h - A collection of trivial wrappers to allow typical libraries
+ *             to work within the yaboot environment.
+ *
+ *  Copyright 2011 Tony Breeds, IBM Corporation
+ *
+ *  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.
+ */
+
+#ifndef NONSTD_H
+#define NONSTD_H
+
+typedef int FILE;
+
+extern FILE *stdout;
+
+int printf(const char *format, ...);
+int fprintf(FILE *stream, const char *format, ...);
+int fputs(const char *s, FILE *stream);
+int fflush(FILE *stream);
+char *getenv(const char *name);
+
+#endif
index 81d7717b32eb23ff410dc6c7077b32853d993386..0121112a349059a922656074061a8d69685bb17a 100644 (file)
 #include "stddef.h"
 #include "string.h"
 
+/* Copied from asm-generic/errno-base.h */
+#define        ENOMEM          12      /* Out of memory */
+#define        EINVAL          22      /* Invalid argument */
+
 /* Imported functions */
 extern void prom_printf (char *fmt, ...);
 
@@ -60,6 +64,49 @@ void *malloc (unsigned int size)
     return caddr;
 }
 
+/* Do not fall back to the malloc above as posix_memalign is needed by
+ * external libraries not yaboot */
+int posix_memalign(void **memptr, size_t alignment, size_t size)
+{
+    char *caddr;
+    /* size of allocation including the alignment */
+    size_t alloc_size;
+
+    if (!malloc_ptr)
+        return EINVAL;
+
+    /* Minimal aligment is sizeof(void *) */
+    if (alignment < sizeof(void*))
+       alignment = sizeof(void*);
+
+    /* Check for valid alignment and power of 2 */
+    if ((alignment % sizeof(void*) != 0) || ((alignment-1)&alignment))
+        return EINVAL;
+
+    if (size == 0) {
+       *memptr=NULL;
+       return 0;
+    }
+
+    caddr = (char*)(
+             (size_t)((malloc_ptr + sizeof(int))+(alignment-1)) &
+             (~(alignment-1))
+            );
+
+    alloc_size = size + (caddr - (malloc_ptr+sizeof(int)));
+
+    if ((malloc_ptr + alloc_size + sizeof(int)) > malloc_top)
+        return ENOMEM;
+
+    *(int *)(caddr - sizeof(int)) = size;
+    malloc_ptr += alloc_size + sizeof(int);
+    last_alloc = caddr;
+    malloc_ptr = (char *) ((((unsigned int) malloc_ptr) + 3) & (~3));
+    *memptr=(void*)caddr;
+
+    return 0;
+}
+
 void *realloc(void *ptr, unsigned int size)
 {
     char *caddr, *oaddr = ptr;
diff --git a/lib/nonstd.c b/lib/nonstd.c
new file mode 100644 (file)
index 0000000..5aeb0cb
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ *  nonstd.c - A collection of trivial wrappers to allow typical libraries
+ *             to work within the yaboot environment.
+ *
+ *  Copyright 2011 Tony Breeds, IBM Corporation
+ *
+ *  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 "ctype.h"
+#include "types.h"
+#include "stddef.h"
+#include "stdlib.h"
+#include "ctype.h"
+#include "prom.h"
+#include "nonstd.h"
+
+FILE *stdout;
+
+int printf(const char *format, ...)
+{
+       va_list ap;
+       va_start (ap, format);
+       prom_vfprintf (prom_stdout, format, ap);
+       va_end (ap);
+
+       return 0;
+}
+
+int fprintf(FILE *stream, const char *format, ...)
+{
+       va_list ap;
+       va_start (ap, format);
+       prom_vfprintf (prom_stdout, format, ap);
+       va_end (ap);
+
+       return 0;
+}
+
+int fputs(const char *s, FILE *stream)
+{
+       prom_printf("%s", s);
+
+       return 0;
+}
+
+int fflush(FILE *stream)
+{
+       return 0;
+}
+
+char *getenv(const char *name)
+{
+       return NULL;
+}