1 /* $OpenBSD: sparc64_softraid.c,v 1.9 2022/11/08 12:08:53 kn Exp $ */
2 /*
3 * Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #include <sys/ioctl.h>
19 #include <sys/stat.h>
20
21 #include <dev/biovar.h>
22
23 #include <err.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <unistd.h>
27
28 #include "installboot.h"
29 #include "sparc64_installboot.h"
30
31 void
sr_install_bootblk(int devfd,int vol,int disk)32 sr_install_bootblk(int devfd, int vol, int disk)
33 {
34 struct bioc_disk bd;
35 char *realdev;
36 int diskfd;
37 char part;
38
39 diskfd = sr_open_chunk(devfd, vol, disk, &bd, &realdev, &part);
40 if (diskfd == -1)
41 return;
42
43 if (verbose)
44 fprintf(stderr, "%s%c: %s boot blocks on %s\n", bd.bd_vendor,
45 part, (nowrite ? "would install" : "installing"), realdev);
46
47 /* Write boot blocks to device. */
48 md_installboot(diskfd, realdev);
49
50 close(diskfd);
51 }
52
53 void
sr_install_bootldr(int devfd,char * dev)54 sr_install_bootldr(int devfd, char *dev)
55 {
56 struct bioc_installboot bb;
57
58 /*
59 * Install boot loader into softraid boot loader storage area.
60 */
61 memset(&bb, 0, sizeof(bb));
62 bb.bb_bootblk = blkstore;
63 bb.bb_bootblk_size = blksize;
64 bb.bb_bootldr = ldrstore;
65 bb.bb_bootldr_size = ldrsize;
66 strncpy(bb.bb_dev, dev, sizeof(bb.bb_dev));
67 if (verbose)
68 fprintf(stderr, "%s: %s boot loader on softraid volume\n", dev,
69 (nowrite ? "would install" : "installing"));
70 if (!nowrite) {
71 if (ioctl(devfd, BIOCINSTALLBOOT, &bb) == -1)
72 errx(1, "softraid installboot failed");
73 sr_status(&bb.bb_bio.bio_status);
74 }
75 }
76