From: jsing Date: Sat, 28 Dec 2013 14:45:57 +0000 (+0000) Subject: Add installboot support for sparc64. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=cccbd07dcf672d7883290faee76410a3cbde0b33;p=openbsd Add installboot support for sparc64. --- diff --git a/usr.sbin/installboot/Makefile b/usr.sbin/installboot/Makefile index 817cf9222d3..21b97416a6b 100644 --- a/usr.sbin/installboot/Makefile +++ b/usr.sbin/installboot/Makefile @@ -1,11 +1,11 @@ -# $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 diff --git a/usr.sbin/installboot/sparc64/Makefile.inc b/usr.sbin/installboot/sparc64/Makefile.inc new file mode 100644 index 00000000000..36106e281d0 --- /dev/null +++ b/usr.sbin/installboot/sparc64/Makefile.inc @@ -0,0 +1,8 @@ +# $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 diff --git a/usr.sbin/installboot/sparc64/sparc64_installboot.c b/usr.sbin/installboot/sparc64/sparc64_installboot.c new file mode 100644 index 00000000000..aafbf39510c --- /dev/null +++ b/usr.sbin/installboot/sparc64/sparc64_installboot.c @@ -0,0 +1,92 @@ +/* $OpenBSD: sparc64_installboot.c,v 1.1 2013/12/28 14:45:57 jsing Exp $ */ + +/* + * Copyright (c) 2012, 2013 Joel Sing + * + * 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 +#include + +#include +#include +#include +#include +#include +#include + +#include + +#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"); +} diff --git a/usr.sbin/installboot/sparc64/sparc64_installboot.h b/usr.sbin/installboot/sparc64/sparc64_installboot.h new file mode 100644 index 00000000000..0f0b5b278f8 --- /dev/null +++ b/usr.sbin/installboot/sparc64/sparc64_installboot.h @@ -0,0 +1,22 @@ +/* $OpenBSD: sparc64_installboot.h,v 1.1 2013/12/28 14:45:57 jsing Exp $ */ + +/* + * Copyright (c) 2013 Joel Sing + * + * 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; diff --git a/usr.sbin/installboot/sparc64/sparc64_softraid.c b/usr.sbin/installboot/sparc64/sparc64_softraid.c new file mode 100644 index 00000000000..7443abd46e2 --- /dev/null +++ b/usr.sbin/installboot/sparc64/sparc64_softraid.c @@ -0,0 +1,101 @@ +/* $OpenBSD: sparc64_softraid.c,v 1.1 2013/12/28 14:45:57 jsing Exp $ */ +/* + * Copyright (c) 2012 Joel Sing + * + * 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 +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#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"); + } +}