-# $OpenBSD: Makefile,v 1.6 2013/12/28 13:58:15 jsing Exp $
+# $OpenBSD: Makefile,v 1.7 2013/12/28 14:45:57 jsing Exp $
NOMAN=
.if (${MACHINE} == "amd64" || ${MACHINE} == "hp300" || \
${MACHINE} == "hppa" || ${MACHINE} == "hppa64" || \
${MACHINE} == "i386" || ${MACHINE} == "landisk" || \
- ${MACHINE} == "vax")
+ ${MACHINE} == "sparc64" || ${MACHINE} == "vax")
PROG= installboot
--- /dev/null
+# $OpenBSD: Makefile.inc,v 1.1 2013/12/28 14:45:57 jsing Exp $
+
+CPPFLAGS += -I${.CURDIR}/sparc64
+CFLAGS += -DSOFTRAID
+
+.PATH: ${.CURDIR}/sparc64
+SRCS += sparc64_installboot.c
+SRCS += sparc64_softraid.c
--- /dev/null
+/* $OpenBSD: sparc64_installboot.c,v 1.1 2013/12/28 14:45:57 jsing Exp $ */
+
+/*
+ * Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <ufs/ffs/fs.h>
+
+#include "installboot.h"
+
+char *blkstore;
+size_t blksize;
+
+void
+md_init(void)
+{
+ stages = 2;
+ stage1 = "/usr/mdec/bootblk";
+ stage2 = "/boot";
+}
+
+void
+md_loadboot(void)
+{
+ struct stat sb;
+ size_t blocks;
+ int fd;
+
+ if ((fd = open(stage1, O_RDONLY)) < 0)
+ err(1, "open");
+ if (fstat(fd, &sb) == -1)
+ err(1, "fstat");
+
+ blocks = howmany((size_t)sb.st_size, DEV_BSIZE);
+ blksize = blocks * DEV_BSIZE;
+ if (verbose)
+ fprintf(stderr, "boot block is %zu bytes "
+ "(%zu blocks @ %u bytes = %zu bytes)\n",
+ (ssize_t)sb.st_size, blocks, DEV_BSIZE, blksize);
+ if (blksize > SBSIZE - DEV_BSIZE)
+ errx(1, "boot blocks too big (%zu > %d)",
+ blksize, SBSIZE - DEV_BSIZE);
+
+ blkstore = malloc(blksize);
+ if (blkstore == NULL)
+ err(1, "malloc");
+ memset(blkstore, 0, blksize);
+ if (read(fd, blkstore, sb.st_size) != (ssize_t)sb.st_size)
+ err(1, "read");
+
+ close(fd);
+}
+
+void
+md_installboot(int devfd, char *dev)
+{
+ /* XXX - is this necessary? */
+ sync();
+
+ /* Write bootblock into the superblock. */
+ if (lseek(devfd, DEV_BSIZE, SEEK_SET) != DEV_BSIZE)
+ err(1, "lseek");
+ if (verbose)
+ fprintf(stderr, "%s boot block to disk %s\n",
+ (nowrite ? "would write" : "writing"), dev);
+ if (nowrite)
+ return;
+ if (write(devfd, blkstore, blksize) != (ssize_t)blksize)
+ err(1, "write");
+}
--- /dev/null
+/* $OpenBSD: sparc64_installboot.h,v 1.1 2013/12/28 14:45:57 jsing Exp $ */
+
+/*
+ * Copyright (c) 2013 Joel Sing <jsing@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+extern char *blkstore;
+extern char *ldrstore;
+extern size_t blksize;
+extern size_t ldrsize;
--- /dev/null
+/* $OpenBSD: sparc64_softraid.c,v 1.1 2013/12/28 14:45:57 jsing Exp $ */
+/*
+ * Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/disklabel.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+
+#include <dev/biovar.h>
+#include <dev/softraidvar.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <util.h>
+#include <unistd.h>
+
+#include "installboot.h"
+#include "sparc64_installboot.h"
+
+void
+sr_install_bootblk(int devfd, int vol, int disk)
+{
+ struct bioc_disk bd;
+ char *realdev;
+ int diskfd;
+ char part;
+
+ /* Get device name for this disk/chunk. */
+ memset(&bd, 0, sizeof(bd));
+ bd.bd_volid = vol;
+ bd.bd_diskid = disk;
+ if (ioctl(devfd, BIOCDISK, &bd) == -1)
+ err(1, "BIOCDISK");
+
+ /* Check disk status. */
+ if (bd.bd_status != BIOC_SDONLINE && bd.bd_status != BIOC_SDREBUILD) {
+ fprintf(stderr, "softraid chunk %u not online - skipping...\n",
+ disk);
+ return;
+ }
+
+ if (strlen(bd.bd_vendor) < 1)
+ errx(1, "invalid disk name");
+ part = bd.bd_vendor[strlen(bd.bd_vendor) - 1];
+ if (part < 'a' || part >= 'a' + MAXPARTITIONS)
+ errx(1, "invalid partition %c\n", part);
+ bd.bd_vendor[strlen(bd.bd_vendor) - 1] = '\0';
+
+ /* Open device. */
+ if ((diskfd = opendev(bd.bd_vendor, (nowrite ? O_RDONLY : O_RDWR),
+ OPENDEV_PART, &realdev)) < 0)
+ err(1, "open: %s", realdev);
+
+ if (verbose)
+ fprintf(stderr, "%s%c: installing boot blocks on %s\n",
+ bd.bd_vendor, part, realdev);
+
+ /* Write boot blocks to device. */
+ md_installboot(diskfd, realdev);
+
+ close(diskfd);
+}
+
+void
+sr_install_bootldr(int devfd, char *dev)
+{
+ struct bioc_installboot bb;
+
+ /*
+ * Install boot loader into softraid boot loader storage area.
+ */
+ memset(&bb, 0, sizeof(bb));
+ bb.bb_bootldr = "XXX";
+ bb.bb_bootldr_size = sizeof("XXX");
+ bb.bb_bootblk = blkstore;
+ bb.bb_bootblk_size = blksize;
+ strncpy(bb.bb_dev, dev, sizeof(bb.bb_dev));
+ if (!nowrite) {
+ if (verbose)
+ fprintf(stderr, "%s: installing boot loader on "
+ "softraid volume\n", dev);
+ if (ioctl(devfd, BIOCINSTALLBOOT, &bb) == -1)
+ errx(1, "softraid installboot failed");
+ }
+}