summaryrefslogtreecommitdiff
path: root/cross/bfd-mdsetimage
diff options
context:
space:
mode:
authorsakamoto <sakamoto>1999-12-20 05:58:34 +0000
committersakamoto <sakamoto>1999-12-20 05:58:34 +0000
commit348ffe02f8a70fd36c3daba87d7940433d0e3d72 (patch)
tree8cb926b6f865b83d64cc56232cc3fe5a2521a195 /cross/bfd-mdsetimage
parent023774fac596dd560a430d28dbe335b0eb890b88 (diff)
downloadpkgsrc-348ffe02f8a70fd36c3daba87d7940433d0e3d72.tar.gz
Initial import of bfd-mdsetimage-1.0
mdsetimage using libbfd. Used for cross-building distributions.
Diffstat (limited to 'cross/bfd-mdsetimage')
-rw-r--r--cross/bfd-mdsetimage/Makefile31
-rw-r--r--cross/bfd-mdsetimage/files/Makefile13
-rw-r--r--cross/bfd-mdsetimage/files/mdsetimage.867
-rw-r--r--cross/bfd-mdsetimage/files/mdsetimage.c251
-rw-r--r--cross/bfd-mdsetimage/pkg/COMMENT1
-rw-r--r--cross/bfd-mdsetimage/pkg/DESCR6
-rw-r--r--cross/bfd-mdsetimage/pkg/PLIST2
7 files changed, 371 insertions, 0 deletions
diff --git a/cross/bfd-mdsetimage/Makefile b/cross/bfd-mdsetimage/Makefile
new file mode 100644
index 00000000000..df243bab6e2
--- /dev/null
+++ b/cross/bfd-mdsetimage/Makefile
@@ -0,0 +1,31 @@
+# $NetBSD: Makefile,v 1.1.1.1 1999/12/20 05:58:34 sakamoto Exp $
+
+DISTNAME= bfd-mdsetimage-1.0
+CATEGORIES= cross
+MASTER_SITES= # empty
+DISTFILES= # empty
+
+MAINTAINER= sakamoto@netbsd.org
+
+DEPENDS= cross-binutils-2.9.1.1:../binutils
+
+EXTRACT_ONLY= # empty
+NO_WRKSUBDIR= yes
+NO_CHECKSUM= yes
+NO_PATCH= yes
+NO_CONFIGURE= yes
+
+USE_CROSSBASE= yes
+BFD_VERSION= 2.9.1
+MAKE_ENV+= BFD_VERSION=${BFD_VERSION} \
+ CPPFLAGS="-I${PREFIX}/include" \
+ LIBS="-L${PREFIX}/lib -Wl,-R${PREFIX}/lib -lbfd-${BFD_VERSION} -liberty"
+
+do-extract:
+ @${MKDIR} ${WRKSRC}
+ @${CP} ${FILESDIR}/* ${WRKSRC}
+
+pre-install:
+ @if [ ! -d ${PREFIX}/bin ];then ${MKDIR} ${PREFIX}/bin;fi
+
+.include "../../mk/bsd.pkg.mk"
diff --git a/cross/bfd-mdsetimage/files/Makefile b/cross/bfd-mdsetimage/files/Makefile
new file mode 100644
index 00000000000..978b086ccad
--- /dev/null
+++ b/cross/bfd-mdsetimage/files/Makefile
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1.1.1 1999/12/20 05:58:34 sakamoto Exp $
+
+PROG= mdsetimage
+SRCS= mdsetimage.c
+#MAN= mdsetimage.8
+MKMAN= no
+
+BINDIR= ${PREFIX}/bin
+
+COPTS+= ${CPPFLAGS}
+LDADD+= ${LIBS}
+
+.include <bsd.prog.mk>
diff --git a/cross/bfd-mdsetimage/files/mdsetimage.8 b/cross/bfd-mdsetimage/files/mdsetimage.8
new file mode 100644
index 00000000000..2a8a47dc336
--- /dev/null
+++ b/cross/bfd-mdsetimage/files/mdsetimage.8
@@ -0,0 +1,67 @@
+.\" $NetBSD: mdsetimage.8,v 1.1.1.1 1999/12/20 05:58:34 sakamoto Exp $
+.\"
+.\" Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Christopher G. Demetriou
+.\" for the NetBSD Project.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+.\"
+.Dd October 3, 1996
+.Dt MDSETIMAGE 8
+.Os
+.Sh NAME
+.Nm mdsetimage
+.Nd set kernel RAM disk image
+.Sh SYNOPSIS
+.Nm
+.Op Fl b Ar bfdname
+.Op Fl v
+.Ar kernel
+.Ar image
+.Sh DESCRIPTION
+The
+.Nm
+command copies the disk image specified by
+.Ar image
+into the memory disk storage area in
+.Ar kernel .
+The file system present in
+.Ar image
+will typically be used by the kernel
+as the root file system.
+.Pp
+To recognize kernel executable format, the
+.Fl b
+flag specifies BFD name of kernel.
+.Pp
+If the
+.Fl v
+flag is given,
+.Nm
+will print out status information as
+it is copying the image.
+.Sh SEE ALSO
+.Xr md 4 ,
+.Xr mdconfig 8
diff --git a/cross/bfd-mdsetimage/files/mdsetimage.c b/cross/bfd-mdsetimage/files/mdsetimage.c
new file mode 100644
index 00000000000..e5f634e809d
--- /dev/null
+++ b/cross/bfd-mdsetimage/files/mdsetimage.c
@@ -0,0 +1,251 @@
+/* $NetBSD: mdsetimage.c,v 1.1.1.1 1999/12/20 05:58:34 sakamoto Exp $ */
+/* NetBSD: mdsetimage.c,v 1.7 1998/08/27 18:03:44 ross Exp */
+
+/*
+ * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christopher G. Demetriou
+ * for the NetBSD Project.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__COPYRIGHT(
+ "@(#) Copyright (c) 1996 Christopher G. Demetriou.\
+ All rights reserved.\n");
+#endif /* not lint */
+
+#ifndef lint
+__RCSID("$NetBSD: mdsetimage.c,v 1.1.1.1 1999/12/20 05:58:34 sakamoto Exp $");
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <bfd.h>
+
+struct symbols {
+ char *name;
+ bfd_vma vma;
+ size_t offset;
+} md_root_symbols[] = {
+#define X_MD_ROOT_IMAGE 0
+ { "_md_root_image", NULL, 0 },
+#define X_MD_ROOT_SIZE 1
+ { "_md_root_size", NULL, 0 },
+ { NULL }
+};
+
+int main __P((int, char *[]));
+static void usage __P((void)) __attribute__((noreturn));
+static int find_md_root __P((bfd *, struct symbols symbols[]));
+
+int verbose;
+
+int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ int ch, kfd, fsfd, rv;
+ struct stat ksb, fssb;
+ size_t md_root_offset;
+ u_int32_t md_root_size;
+ const char *kfile, *fsfile;
+ char *mappedkfile;
+ char *bfdname = NULL;
+ bfd *abfd;
+
+ while ((ch = getopt(argc, argv, "b:v")) != -1)
+ switch (ch) {
+ case 'b':
+ bfdname = optarg;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 2)
+ usage();
+ kfile = argv[0];
+ fsfile = argv[1];
+
+ if ((kfd = open(kfile, O_RDWR, 0)) == -1)
+ err(1, "open %s", kfile);
+
+ bfd_init();
+ if ((abfd = bfd_fdopenr(kfile, bfdname, kfd)) == NULL) {
+ bfd_perror("open");
+ exit(1);
+ }
+ if (!bfd_check_format(abfd, bfd_object)) {
+ bfd_perror("check format");
+ exit(1);
+ }
+
+ if (find_md_root(abfd, md_root_symbols) != 0)
+ errx(1, "could not find symbols in %s", kfile);
+ if (verbose)
+ fprintf(stderr, "got symbols from %s\n", kfile);
+
+ if (fstat(kfd, &ksb) == -1)
+ err(1, "fstat %s", kfile);
+ if (ksb.st_size > SIZE_T_MAX)
+ errx(1, "%s too big to map", kfile);
+
+ if ((mappedkfile = mmap(NULL, ksb.st_size, PROT_READ | PROT_WRITE,
+ MAP_FILE | MAP_SHARED, kfd, 0)) == (caddr_t)-1)
+ err(1, "mmap %s", kfile);
+ if (verbose)
+ fprintf(stderr, "mapped %s\n", kfile);
+
+ md_root_offset = md_root_symbols[X_MD_ROOT_IMAGE].offset;
+ md_root_size =
+ bfd_get_32(abfd, &mappedkfile[md_root_symbols[X_MD_ROOT_SIZE].offset]);
+
+ if ((fsfd = open(fsfile, O_RDONLY, 0)) == -1)
+ err(1, "open %s", fsfile);
+ if (fstat(fsfd, &fssb) == -1)
+ err(1, "fstat %s", fsfile);
+ if (fssb.st_size > SIZE_T_MAX)
+ errx(1, "fs image is too big");
+ if (fssb.st_size > md_root_size)
+ errx(1, "fs image (%qd bytes) too big for buffer (%ld bytes)",
+ (long long)fssb.st_size, (unsigned long)md_root_size);
+
+ if (verbose)
+ fprintf(stderr, "copying image from %s into %s\n", fsfile,
+ kfile);
+ if ((rv = read(fsfd, mappedkfile + md_root_offset,
+ fssb.st_size)) != fssb.st_size) {
+ if (rv == -1)
+ err(1, "read %s", fsfile);
+ else
+ errx(1, "unexpected EOF reading %s", fsfile);
+ }
+ if (verbose)
+ fprintf(stderr, "done copying image\n");
+
+ close(fsfd);
+
+ munmap(mappedkfile, ksb.st_size);
+ close(kfd);
+
+ if (verbose)
+ fprintf(stderr, "exiting\n");
+
+ bfd_close(abfd);
+ exit(0);
+}
+
+static void
+usage()
+{
+ const char **list;
+ extern const char *__progname;
+
+ fprintf(stderr,
+ "usage: %s [-b bfdname] [-v] kernel_file fsimage_file\n",
+ __progname);
+ fprintf(stderr, "supported targets:");
+ for (list = bfd_target_list(); *list != NULL; list++)
+ fprintf(stderr, " %s", *list);
+ fprintf(stderr, "\n");
+ exit(1);
+}
+
+static int
+find_md_root(abfd, symbols)
+ bfd *abfd;
+ struct symbols symbols[];
+{
+ long i;
+ long storage_needed;
+ long number_of_symbols;
+ asymbol **symbol_table = NULL;
+ struct symbols *s;
+ struct sec *p;
+
+ storage_needed = bfd_get_symtab_upper_bound(abfd);
+ if (storage_needed <= 0)
+ return (1);
+
+ symbol_table = (asymbol **)malloc(storage_needed);
+ if (symbol_table == NULL)
+ return (1);
+
+ number_of_symbols = bfd_canonicalize_symtab(abfd, symbol_table);
+ if (number_of_symbols <= 0) {
+ free(symbol_table);
+ return (1);
+ }
+
+ for (i = 0; i < number_of_symbols; i++) {
+ for (s = symbols; s->name != NULL; s++) {
+ const char *sym = bfd_asymbol_name(symbol_table[i]);
+
+ /*
+ * match symbol prefix '_' or ''.
+ */
+ if (!strcmp(s->name, sym) ||
+ !strcmp(s->name + 1, sym)) {
+ s->vma = bfd_asymbol_value(symbol_table[i]);
+ }
+ }
+ }
+
+ free(symbol_table);
+
+ for (s = symbols; s->name != NULL; s++) {
+ if (s->vma == NULL)
+ return (1);
+
+ for (p = abfd->sections; p != NULL; p = p->next) {
+ if (p->vma > s->vma || p->vma + p->_raw_size < s->vma)
+ continue;
+
+ s->offset = (size_t)(p->filepos + (s->vma - p->vma));
+ }
+
+ if (s->offset == 0)
+ return (1);
+ }
+
+ return (0);
+}
diff --git a/cross/bfd-mdsetimage/pkg/COMMENT b/cross/bfd-mdsetimage/pkg/COMMENT
new file mode 100644
index 00000000000..a4c3114b8e2
--- /dev/null
+++ b/cross/bfd-mdsetimage/pkg/COMMENT
@@ -0,0 +1 @@
+mdsetimage using libbfd. Used for cross-building distributions.
diff --git a/cross/bfd-mdsetimage/pkg/DESCR b/cross/bfd-mdsetimage/pkg/DESCR
new file mode 100644
index 00000000000..26f0ff03e23
--- /dev/null
+++ b/cross/bfd-mdsetimage/pkg/DESCR
@@ -0,0 +1,6 @@
+This version of mdsetimage has been written to make use of libbfd. This
+enables it to work for object file formats not normally supported on a
+host.
+
+This version is intended for cross-building snapshots. It is not needed
+to build snapshots of the host architecture type.
diff --git a/cross/bfd-mdsetimage/pkg/PLIST b/cross/bfd-mdsetimage/pkg/PLIST
new file mode 100644
index 00000000000..e37f55a73a7
--- /dev/null
+++ b/cross/bfd-mdsetimage/pkg/PLIST
@@ -0,0 +1,2 @@
+@comment $NetBSD: PLIST,v 1.1.1.1 1999/12/20 05:58:35 sakamoto Exp $
+bin/mdsetimage