1 /* $NetBSD: md.c,v 1.12 2026/01/09 22:54:34 jmcneill Exp $ */ 2 3 /* 4 * Copyright 1997,2002 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 /* md.c -- evbppc machine specific routines */ 36 37 #include <sys/param.h> 38 #include <sys/sysctl.h> 39 #include <sys/utsname.h> 40 #include <stdio.h> 41 #include <util.h> 42 43 #include "defs.h" 44 #include "md.h" 45 #include "msg_defs.h" 46 #include "menu_defs.h" 47 48 static bool cpu_espresso; 49 50 void 51 md_init(void) 52 { 53 static const int mib[2] = {CTL_HW, HW_MODEL}; 54 size_t len; 55 char *cpu_model; 56 57 sysctl(mib, 2, NULL, &len, NULL, 0); 58 cpu_model = malloc(len); 59 sysctl(mib, 2, cpu_model, &len, NULL, 0); 60 61 cpu_espresso = strstr(cpu_model, "Espresso") != NULL; 62 63 free(cpu_model); 64 } 65 66 void 67 md_init_set_status(int flags) 68 { 69 struct utsname instsys; 70 71 (void)flags; 72 73 /* 74 * Get the name of the install kernel we are running under and 75 * enable the installation of the corresponding kernel. 76 */ 77 uname(&instsys); 78 if (strstr(instsys.version, "(INSTALL_NINTENDO")) { 79 if (cpu_espresso) { 80 set_kernel_set(EVBPPC_SET_KERNEL_NINTENDO_MP); 81 set_noextract_set(EVBPPC_SET_KERNEL_NINTENDO_MP); 82 } else { 83 set_kernel_set(EVBPPC_SET_KERNEL_NINTENDO); 84 set_noextract_set(EVBPPC_SET_KERNEL_NINTENDO); 85 } 86 } 87 } 88 89 bool 90 md_get_info(struct install_partition_desc *install) 91 { 92 int res; 93 94 if (pm->no_mbr || pm->no_part) 95 return true; 96 97 again: 98 if (pm->parts == NULL) { 99 100 const struct disk_partitioning_scheme *ps = 101 select_part_scheme(pm, NULL, true, NULL); 102 103 if (!ps) 104 return false; 105 106 struct disk_partitions *parts = 107 (*ps->create_new_for_disk)(pm->diskdev, 108 0, pm->dlsize, true, NULL); 109 if (!parts) 110 return false; 111 112 pm->parts = parts; 113 if (ps->size_limit > 0 && pm->dlsize > ps->size_limit) 114 pm->dlsize = ps->size_limit; 115 } 116 117 res = set_bios_geom_with_mbr_guess(pm->parts); 118 if (res == 0) 119 return false; 120 else if (res == 1) 121 return true; 122 123 pm->parts->pscheme->destroy_part_scheme(pm->parts); 124 pm->parts = NULL; 125 goto again; 126 } 127 128 /* 129 * md back-end code for menu-driven BSD disklabel editor. 130 */ 131 int 132 md_make_bsd_partitions(struct install_partition_desc *install) 133 { 134 return make_bsd_partitions(install); 135 } 136 137 /* 138 * any additional partition validation 139 */ 140 bool 141 md_check_partitions(struct install_partition_desc *install) 142 { 143 return true; 144 } 145 146 /* 147 * hook called before writing new disklabel. 148 */ 149 bool 150 md_pre_disklabel(struct install_partition_desc *install, 151 struct disk_partitions *parts) 152 { 153 154 if (parts->parent == NULL) 155 return true; /* no outer partitions */ 156 157 parts = parts->parent; 158 159 msg_display_subst(MSG_dofdisk, 3, parts->disk, 160 msg_string(parts->pscheme->name), 161 msg_string(parts->pscheme->short_name)); 162 163 /* write edited "MBR" onto disk. */ 164 if (!parts->pscheme->write_to_disk(parts)) { 165 msg_display(MSG_wmbrfail); 166 process_menu(MENU_ok, NULL); 167 return false; 168 } 169 return true; 170 } 171 172 /* 173 * hook called after writing disklabel to new target disk. 174 */ 175 bool 176 md_post_disklabel(struct install_partition_desc *install, 177 struct disk_partitions *parts) 178 { 179 return true; 180 } 181 182 /* 183 * hook called after upgrade() or install() has finished setting 184 * up the target disk but immediately before the user is given the 185 * ``disks are now set up'' message. 186 */ 187 int 188 md_post_newfs(struct install_partition_desc *install) 189 { 190 /* Walnut doesn't do bootblocks */ 191 return 0; 192 } 193 194 int 195 md_post_extract(struct install_partition_desc *install, bool upgrade) 196 { 197 return 0; 198 } 199 200 void 201 md_cleanup_install(struct install_partition_desc *install) 202 { 203 #ifndef DEBUG 204 enable_rc_conf(); 205 #endif 206 } 207 208 int 209 md_pre_update(struct install_partition_desc *install) 210 { 211 return 1; 212 } 213 214 /* Upgrade support */ 215 int 216 md_update(struct install_partition_desc *install) 217 { 218 md_post_newfs(install); 219 return 1; 220 } 221 222 int 223 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet) 224 { 225 return 2; 226 } 227 228 bool 229 md_parts_use_wholedisk(struct disk_partitions *parts) 230 { 231 return parts_use_wholedisk(parts, 0, NULL); 232 } 233 234 int 235 md_pre_mount(struct install_partition_desc *install, size_t ndx) 236 { 237 return 0; 238 } 239 240 bool 241 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri) 242 { 243 return false; /* no change, no need to write back */ 244 } 245 246 #ifdef HAVE_GPT 247 bool 248 md_gpt_post_write(struct disk_partitions *parts, part_id root_id, 249 bool root_is_new, part_id efi_id, bool efi_is_new) 250 { 251 /* no GPT boot support, nothing needs to be done here */ 252 return true; 253 } 254 #endif 255