1 /* $NetBSD: md.c,v 1.6 2020/10/12 16:14:36 martin Exp $ */ 2 3 /* 4 * Copyright 1997 Piermont Information Systems Inc. 5 * All rights reserved. 6 * 7 * Based on code written by Philip A. Nelson for Piermont Information 8 * Systems Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. The name of Piermont Information Systems Inc. may not be used to endorse 19 * or promote products derived from this software without specific prior 20 * written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 * THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 /* changes from the sparc version made by mrg */ 36 37 /* md.c -- sparc64 machine specific routines */ 38 /* This file is in close sync with pmax, vax, and x68k, sparc md.c */ 39 40 #include <sys/types.h> 41 #include <sys/ioctl.h> 42 #include <sys/param.h> 43 #include <stdio.h> 44 #include <curses.h> 45 #include <unistd.h> 46 #include <fcntl.h> 47 #include <util.h> 48 49 #include "defs.h" 50 #include "md.h" 51 #include "msg_defs.h" 52 #include "menu_defs.h" 53 54 static void install_bootblocks(void); 55 static void install_ofwboot(void); 56 57 void 58 md_init(void) 59 { 60 } 61 62 void 63 md_init_set_status(int flags) 64 { 65 (void)flags; 66 } 67 68 bool 69 md_get_info(struct install_partition_desc *install) 70 { 71 return true; 72 } 73 74 /* 75 * md back-end code for menu-driven BSD disklabel editor. 76 */ 77 int 78 md_make_bsd_partitions(struct install_partition_desc *install) 79 { 80 return make_bsd_partitions(install); 81 } 82 83 /* 84 * any additional partition validation 85 */ 86 bool 87 md_check_partitions(struct install_partition_desc *install) 88 { 89 return true; 90 } 91 92 /* 93 * hook called before writing new disklabel. 94 */ 95 bool 96 md_pre_disklabel(struct install_partition_desc *install, 97 struct disk_partitions *parts) 98 { 99 return true; 100 } 101 102 /* 103 * hook called after writing disklabel to new target disk. 104 */ 105 bool 106 md_post_disklabel(struct install_partition_desc *install, 107 struct disk_partitions *parts) 108 { 109 install_bootblocks(); 110 return true; 111 } 112 113 /* 114 * hook called after upgrade() or install() has finished setting 115 * up the target disk but immediately before the user is given the 116 * ``disks are now set up'' message. 117 */ 118 int 119 md_post_newfs(struct install_partition_desc *install) 120 { 121 install_ofwboot(); 122 return 0; 123 } 124 125 int 126 md_post_extract(struct install_partition_desc *install) 127 { 128 return 0; 129 } 130 131 void 132 md_cleanup_install(struct install_partition_desc *install) 133 { 134 #ifndef DEBUG 135 enable_rc_conf(); 136 #endif 137 } 138 139 int 140 md_pre_update(struct install_partition_desc *install) 141 { 142 return 1; 143 } 144 145 /* Upgrade support */ 146 int 147 md_update(struct install_partition_desc *install) 148 { 149 md_post_newfs(install); 150 return 1; 151 } 152 153 /* install/update bootblocks */ 154 static void 155 install_bootblocks(void) 156 { 157 /* Install boot blocks before mounting the target disk */ 158 msg_fmt_display(MSG_dobootblks, "%s", pm->diskdev); 159 run_program(RUN_DISPLAY, "/sbin/disklabel -W %s", pm->diskdev); 160 run_program(RUN_DISPLAY, "/usr/sbin/installboot /dev/r%sc" 161 " /usr/mdec/bootblk", pm->diskdev); 162 } 163 164 /* install/update secondary bootstrap */ 165 static void 166 install_ofwboot(void) 167 { 168 /* copy secondary bootstrap now that the target is mounted */ 169 msg_fmt_display(MSG_doofwboot, "%s", targetroot_mnt); 170 run_program(RUN_DISPLAY, "/bin/cp -p /usr/mdec/ofwboot %s", 171 targetroot_mnt); 172 } 173 174 int 175 md_pre_mount(struct install_partition_desc *install, size_t ndx) 176 { 177 if (ndx == 0) 178 install_bootblocks(); 179 return 0; 180 } 181 182 bool 183 md_parts_use_wholedisk(struct disk_partitions *parts) 184 { 185 return parts_use_wholedisk(parts, 0, NULL); 186 } 187 188 189 #ifdef HAVE_GPT 190 /* 191 * New GPT partitions have been written, update bootloader or remember 192 * data untill needed in md_post_newfs 193 */ 194 bool 195 md_gpt_post_write(struct disk_partitions *parts, part_id root_id, 196 bool root_is_new, part_id efi_id, bool efi_is_new) 197 { 198 return true; 199 } 200 #endif 201