1 /* $NetBSD: md.c,v 1.6 2019/08/14 12:55:37 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 /* md.c -- sandpoint machine specific routines */ 36 37 #include <sys/param.h> 38 #include <sys/sysctl.h> 39 #include <sys/utsname.h> 40 41 #include <stdio.h> 42 #include <string.h> 43 #include <util.h> 44 45 #include "defs.h" 46 #include "md.h" 47 #include "msg_defs.h" 48 #include "menu_defs.h" 49 50 static char *prodname; 51 52 void 53 md_init(void) 54 { 55 } 56 57 void 58 md_init_set_status(int flags) 59 { 60 static const char mib_name[] = "machdep.prodfamily"; 61 static char unknown[] = "unknown"; 62 size_t len; 63 64 (void)flags; 65 66 /* 67 * Determine the product family of the board we are running on and 68 * enable the installation of the corresponding GENERIC kernel. 69 * 70 * Note: In md.h the two kernels are disabled. If they are 71 * enabled there the logic here needs to be switched. 72 */ 73 if (sysctlbyname(mib_name, NULL, &len, NULL, 0) != 0) { 74 prodname = unknown; 75 return; 76 } 77 prodname = malloc(len); 78 sysctlbyname(mib_name, prodname, &len, NULL, 0); 79 80 if (strcmp(prodname, "kurobox")==0 || strcmp(prodname, "kurot4")==0) 81 /* 82 * Running on a KuroBox family product, so enable KUROBOX 83 */ 84 set_kernel_set(SET_KERNEL_2); 85 else 86 /* 87 * Otherwise enable GENERIC 88 */ 89 set_kernel_set(SET_KERNEL_1); 90 } 91 92 bool 93 md_get_info(struct install_partition_desc *install) 94 { 95 96 if (pm->no_mbr || pm->no_part) 97 return true; 98 99 if (pm->parts == NULL) { 100 101 const struct disk_partitioning_scheme *ps = 102 select_part_scheme(pm, NULL, true, NULL); 103 104 if (!ps) 105 return false; 106 107 struct disk_partitions *parts = 108 (*ps->create_new_for_disk)(pm->diskdev, 109 0, pm->dlsize, pm->dlsize, true); 110 if (!parts) 111 return false; 112 113 pm->parts = parts; 114 if (ps->size_limit > 0 && pm->dlsize > ps->size_limit) 115 pm->dlsize = ps->size_limit; 116 } 117 118 return set_bios_geom_with_mbr_guess(pm->parts); 119 } 120 121 /* 122 * md back-end code for menu-driven BSD disklabel editor. 123 */ 124 bool 125 md_make_bsd_partitions(struct install_partition_desc *install) 126 { 127 return make_bsd_partitions(install); 128 } 129 130 /* 131 * any additional partition validation 132 */ 133 bool 134 md_check_partitions(struct install_partition_desc *install) 135 { 136 return true; 137 } 138 139 /* 140 * hook called before writing new disklabel. 141 */ 142 bool 143 md_pre_disklabel(struct install_partition_desc *install, 144 struct disk_partitions *parts) 145 { 146 147 if (parts->parent == NULL) 148 return true; /* no outer partitions */ 149 150 parts = parts->parent; 151 152 msg_display_subst(MSG_dofdisk, 3, parts->disk, 153 msg_string(parts->pscheme->name), 154 msg_string(parts->pscheme->short_name)); 155 156 /* write edited "MBR" onto disk. */ 157 if (!parts->pscheme->write_to_disk(parts)) { 158 msg_display(MSG_wmbrfail); 159 process_menu(MENU_ok, NULL); 160 return false; 161 } 162 return true; 163 } 164 165 /* 166 * hook called after writing disklabel to new target disk. 167 */ 168 bool 169 md_post_disklabel(struct install_partition_desc *install, 170 struct disk_partitions *parts) 171 { 172 return true; 173 } 174 175 /* 176 * hook called after upgrade() or install() has finished setting 177 * up the target disk but immediately before the user is given the 178 * ``disks are now set up'' message. 179 */ 180 int 181 md_post_newfs(struct install_partition_desc *install) 182 { 183 /* no boot blocks, we are using altboot */ 184 return 0; 185 } 186 187 int 188 md_post_extract(struct install_partition_desc *install) 189 { 190 return 0; 191 } 192 193 void 194 md_cleanup_install(struct install_partition_desc *install) 195 { 196 #ifndef DEBUG 197 int new_speed; 198 199 enable_rc_conf(); 200 201 /* 202 * Set the console speed in /etc/ttys depending on the board. 203 * The default speed is 115200, which is patched when needed. 204 */ 205 if (strcmp(prodname, "kurobox")==0 || strcmp(prodname, "kurot4")==0) 206 new_speed = 57600; /* KuroBox */ 207 208 else if (strcmp(prodname, "dlink") == 0 || /* D-Link DSM-G600 */ 209 strcmp(prodname, "nhnas") == 0) /* NH23x, All6250 */ 210 new_speed = 9600; 211 212 else 213 new_speed = 0; 214 215 if (new_speed != 0) { 216 run_program(RUN_CHROOT, "sed -an -e 's/115200/%d/;H;$!d;g;w" 217 "/etc/ttys' /etc/ttys", new_speed); 218 } 219 #endif 220 } 221 222 int 223 md_pre_update(struct install_partition_desc *install) 224 { 225 return 1; 226 } 227 228 /* Upgrade support */ 229 int 230 md_update(struct install_partition_desc *install) 231 { 232 md_post_newfs(install); 233 return 1; 234 } 235 236 int 237 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet) 238 { 239 return 2; 240 } 241 242 bool 243 md_parts_use_wholedisk(struct disk_partitions *parts) 244 { 245 return parts_use_wholedisk(parts, 0, NULL); 246 } 247 248 int 249 md_pre_mount(struct install_partition_desc *install, size_t ndx) 250 { 251 return 0; 252 } 253 254 bool 255 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri) 256 { 257 return false; /* no change, no need to write back */ 258 } 259 260 #ifdef HAVE_GPT 261 bool 262 md_gpt_post_write(struct disk_partitions *parts, part_id root_id, 263 bool root_is_new, part_id efi_id, bool efi_is_new) 264 { 265 /* no GPT boot support, nothing needs to be done here */ 266 return true; 267 } 268 #endif 269 270