]> Zhao Yanbai Git Server - minix.git/commitdiff
Use objcopy to build ramdisk object
authorAntoine Leca <Antoine.Leca.1@gmail.com>
Tue, 17 Jan 2012 15:04:58 +0000 (16:04 +0100)
committerBen Gras <ben@minix3.org>
Fri, 17 Feb 2012 12:56:38 +0000 (12:56 +0000)
. during build, uses much less memory,
  disk space, and time
. lets us throw out bintoc

drivers/memory/Makefile
drivers/memory/imgrd.c [deleted file]
drivers/memory/local.h
drivers/ramdisk/Makefile
drivers/ramdisk/bintoc.c [deleted file]
tools/Makefile

index 494f105c3643f47e8d47d37bbe72187d289d5709..435ea62d423fc2cf01fb03b843b9619b5838f380 100644 (file)
@@ -1,6 +1,7 @@
 # Makefile for memory driver (MEMORY)
 PROG=  memory
-SRCS=  memory.c imgrd.c
+SRCS=  memory.c imgrd.mfs
+OBJS=  ${SRCS:N*.h:R:S/$/.o/g}
 
 DPADD+=        ${LIBBLOCKDRIVER} ${LIBCHARDRIVER} ${LIBSYS}
 LDADD+=        -lblockdriver -lchardriver -lsys
@@ -10,6 +11,22 @@ MAN=
 BINDIR?= /usr/sbin
 
 CPPFLAGS.memory.c+=    -I${MINIXSRCDIR}
-CPPFLAGS.imgrd.c+=     -I${.CURDIR}/../ramdisk 
+
+imgrd.d: touch-genfiles
+touch-genfiles:
+       [ -e ../ramdisk/image ] || touch -t 197001020000.00 ../ramdisk/image
+
+
+.SUFFIXES:      .mfs .c .o
+
+# 'elf32-${ARCH}-minix' below should really be ${MACHINE_GNU_PLATFORM}
+# but bsd.own.mk has to be upgraded for that.
+.mfs.o:
+       ${_MKTARGET_CREATE}
+       ${OBJCOPY} -Ibinary -B${ARCH} -Oelf32-${ARCH}-minix $< $@
+
+imgrd.mfs:
+       ln -s ../ramdisk/image $@
+CLEANFILES+=   imgrd.mfs
 
 .include <minix.bootprog.mk>
diff --git a/drivers/memory/imgrd.c b/drivers/memory/imgrd.c
deleted file mode 100644 (file)
index 947b7ff..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
-Ramdisk that is part of the image
-*/
-
-#include <stddef.h>
-
-#include "local.h"
-
-unsigned char imgrd[]=
-{
-#include "image.c"
-};
-
-size_t imgrd_size= sizeof(imgrd);
index 91a9ad16a5b383b38fb526903a789be9934a99d6..498ef2757df6074f91a569ecbe58e01f2ffbfc09 100644 (file)
@@ -2,5 +2,8 @@
 local defines and declarations 
 */
 
-extern unsigned char imgrd[];
-extern size_t imgrd_size;
+extern unsigned char _binary_imgrd_mfs_start[], *_binary_imgrd_mfs_end;
+
+#define        imgrd   _binary_imgrd_mfs_start
+#define        imgrd_size \
+       ((size_t)(_binary_imgrd_mfs_end - _binary_imgrd_mfs_start))
index 8585da39648b13e6c8ef280556dd82e00b32a8b6..7d3825c80e57f9adf565f6cbf9ed540f6bae00ae 100644 (file)
@@ -23,19 +23,11 @@ PROTO= proto.small
 EXTRA=system.conf master.passwd passwd pwd.db spwd.db rs.single
 
 CPPFLAGS+= -I${MINIXSRCDIR}/servers -I${MINIXSRCDIR}
-CLEANFILES += $(PROGRAMS) $(SCRIPTS) $(EXTRA) bintoc image image.c t proto.gen
+CLEANFILES += $(PROGRAMS) $(SCRIPTS) $(EXTRA) image image.c t proto.gen
 
 install: all
 
-realall: image.c
-
-image.c:       bintoc image
-       ./bintoc -o $@ image
-
-# Note for cross compilation: this executable has to be compiled for the
-# host system
-bintoc:        bintoc.c
-       $(CC) -o $@ bintoc.c
+realall: image
 
 image: proto.gen mtab rc $(EXTRA)
        mkfs.mfs image proto.gen || { rm -f image; false; }
diff --git a/drivers/ramdisk/bintoc.c b/drivers/ramdisk/bintoc.c
deleted file mode 100644 (file)
index b4c5320..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
-bintoc.c
-
-Convert a (binary) file to a series of comma separated hex values suitable
-for initializing a character array in C.
-*/
-
-#define _POSIX_C_SOURCE 2
-
-#include <errno.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-static char *progname;
-static unsigned char buf[1024];
-
-static void fatal(char *fmt, ...);
-static void usage(void);
-
-int main(int argc, char *argv[])
-{
-       int c, i, r, first;
-       FILE *file_in, *file_out;
-       char *in_name;
-       char *o_arg;
-
-       (progname=strrchr(argv[0],'/')) ? progname++ : (progname=argv[0]);
-
-       o_arg= NULL;
-       while (c= getopt(argc, argv, "?o:"), c != -1)
-       {
-               switch(c)
-               {
-               case '?': usage();
-               case 'o': o_arg= optarg; break;
-               default:  fatal("getopt failed: '%c'\n", c);
-               }
-       }
-
-       if (o_arg)
-       {
-               file_out= fopen(o_arg, "w");
-               if (file_out == NULL)
-               {
-                       fatal("unable to create '%s': %s\n",
-                               o_arg, strerror(errno));
-                       exit(1);
-               }
-       }
-       else
-               file_out= stdout;
-
-       if (optind < argc)
-       {
-               in_name= argv[optind];
-               optind++;
-               file_in= fopen(in_name, "r");
-               if (file_in == NULL)
-               {
-                       fatal("unable to open '%s': %s",
-                               in_name, strerror(errno));
-               }
-       }
-       else
-       {
-               in_name= "(stdin)";
-               file_in= stdin;
-       }
-
-       if (optind != argc)
-               usage();
-
-       first= 1;
-       for (;;)
-       {
-               r= fread(buf, 1, sizeof(buf), file_in);
-               if (r == 0)
-                       break;
-               for (i= 0; i<r; i++)
-               {
-                       if ((i % 8) == 0)
-                       {
-                               if (first)
-                               {
-                                       fprintf(file_out, "\t");
-                                       first= 0;
-                               }
-                               else
-                                       fprintf(file_out, ",\n\t");
-                       }
-                       else
-                               fprintf(file_out, ", ");
-                       fprintf(file_out, "0x%02x", buf[i]);
-               }
-       }
-
-       if (ferror(file_in))
-       {
-               fatal("read error on %s: %s\n",
-                       in_name, strerror(errno));
-       }
-       fprintf(file_out, "\n");
-
-       exit(0);
-}
-
-static void fatal(char *fmt, ...)
-{
-       va_list ap;
-
-       fprintf(stderr, "%s: ", progname);
-
-       va_start(ap, fmt);
-       vfprintf(stderr, fmt, ap);
-       va_end(ap);
-
-       fprintf(stderr, "\n");
-
-       exit(1);
-}
-
-static void usage(void)
-{
-       fprintf(stderr, "Usage: bintoc [-o <out-file>] [<in-file>]\n");
-       exit(1);
-}
index 6ad6574da39e33b717c850a8d60730439a5598b1..99a4ba9ebb3652297cbc7c86f0460f786a3886fb 100644 (file)
@@ -90,11 +90,12 @@ hdboot: image
        cp $$i $$newname;                               \
        if [ -d /boot/image ];                          \
        then    ln -f $$newname /boot/`basename $$i`;   \
-       else    gzip $$newname;                         \
+       else    strip -s $$newname;                     \
+               gzip $$newname;                         \
        fi                                              \
        done
        cp ../kernel/kernel /boot/minix/.temp/
-       strip -s /boot/minix/.temp/*
+       strip -s /boot/minix/.temp/kernel
        [ -d /boot/image ] && ln -f /boot/minix/.temp/kernel /boot/kernel || true
        sh mkboot $@ minix
        exec sh update_bootcfg.sh