1 /* $NetBSD: md.c,v 1.9 2022/08/28 13:56:56 tsutsui 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 -- atari machine specific routines */ 36 37 #include <stdio.h> 38 #include <stdlib.h> 39 #include <string.h> 40 #include <sys/param.h> 41 #include <sys/sysctl.h> 42 #include <sys/utsname.h> 43 44 #include "defs.h" 45 #include "md.h" 46 #include "msg_defs.h" 47 #include "menu_defs.h" 48 49 void 50 md_init(void) 51 { 52 } 53 54 void 55 md_init_set_status(int flags) 56 { 57 struct utsname instsys; 58 59 (void)flags; 60 61 /* 62 * Get the name of the kernel we are running under and 63 * enable the installation of the corresponding GENERIC-like kernel. 64 */ 65 uname(&instsys); 66 if (strstr(instsys.version, "(ATARITT")) 67 set_kernel_set(SET_KERNEL_1); 68 else if (strstr(instsys.version, "(FALCON")) 69 set_kernel_set(SET_KERNEL_2); 70 else if (strstr(instsys.version, "(SMALL030")) 71 set_kernel_set(SET_KERNEL_3); 72 else if (strstr(instsys.version, "(HADES")) 73 set_kernel_set(SET_KERNEL_4); 74 else if (strstr(instsys.version, "(MILAN-ISAIDE")) 75 set_kernel_set(SET_KERNEL_5); 76 else if (strstr(instsys.version, "(MILAN_PCIIDE")) 77 set_kernel_set(SET_KERNEL_6); 78 } 79 80 bool 81 md_get_info(struct install_partition_desc *install) 82 { 83 return true; 84 } 85 86 /* 87 * md back-end code for menu-driven BSD disklabel editor. 88 */ 89 int 90 md_make_bsd_partitions(struct install_partition_desc *install) 91 { 92 msg_fmt_display(MSG_infoahdilabel, "%s", pm->diskdev); 93 if (ask_noyes(NULL)) { 94 run_program(RUN_DISPLAY, "ahdilabel /dev/r%sc", pm->diskdev); 95 } 96 return make_bsd_partitions(install); 97 } 98 99 /* 100 * any additional partition validation 101 */ 102 bool 103 md_check_partitions(struct install_partition_desc *install) 104 { 105 return true; 106 } 107 108 /* 109 * hook called before writing new disklabel. 110 */ 111 bool 112 md_pre_disklabel(struct install_partition_desc *install, 113 struct disk_partitions *parts) 114 { 115 return true; 116 } 117 118 /* 119 * hook called after writing disklabel to new target disk. 120 */ 121 bool 122 md_post_disklabel(struct install_partition_desc *install, 123 struct disk_partitions *parts) 124 { 125 return true; 126 } 127 128 /* 129 * hook called after upgrade() or install() has finished setting 130 * up the target disk but immediately before the user is given the 131 * ``disks are now set up'' message. 132 */ 133 int 134 md_post_newfs(struct install_partition_desc *install) 135 { 136 static const int mib[2] = {CTL_HW, HW_MODEL}; 137 size_t len; 138 char *cpu_model; 139 int milan; 140 char bootpath[MAXPATHLEN]; 141 int rv; 142 143 /* check machine type via sysctl to select appropriate bootloaders */ 144 milan = 0; /* std is default */ 145 sysctl(mib, 2, NULL, &len, NULL, 0); 146 cpu_model = malloc(len); 147 sysctl(mib, 2, cpu_model, &len, NULL, 0); 148 /* XXX model strings should be a common macro to sync with kernel */ 149 if (strstr(cpu_model, "Milan") != NULL) 150 milan = 1; 151 free(cpu_model); 152 153 /* copy tertiary boot and install boot blocks */ 154 msg_fmt_display(MSG_dobootblks, "%s", pm->diskdev); 155 snprintf(bootpath, sizeof(bootpath), "/usr/mdec/%s/boot.atari", 156 milan ? "milan" : "std"); 157 rv = cp_to_target(bootpath, "/"); 158 if (rv != 0) 159 return rv; 160 161 rv = run_program(RUN_DISPLAY, "/usr/mdec/installboot -v%s /dev/r%sc", 162 milan ? "m" : "", pm->diskdev); 163 164 return rv; 165 } 166 167 int 168 md_post_extract(struct install_partition_desc *install, bool upgrade) 169 { 170 return 0; 171 } 172 173 void 174 md_cleanup_install(struct install_partition_desc *install) 175 { 176 #ifndef DEBUG 177 enable_rc_conf(); 178 #endif 179 } 180 181 int 182 md_pre_update(struct install_partition_desc *install) 183 { 184 return 1; 185 } 186 187 /* Upgrade support */ 188 int 189 md_update(struct install_partition_desc *install) 190 { 191 md_post_newfs(install); 192 return 1; 193 } 194 195 int 196 md_pre_mount(struct install_partition_desc *install, size_t ndx) 197 { 198 return 0; 199 } 200 201 bool 202 md_parts_use_wholedisk(struct disk_partitions *parts) 203 { 204 return parts_use_wholedisk(parts, 0, NULL); 205 } 206 207 #ifdef HAVE_GPT 208 bool 209 md_gpt_post_write(struct disk_partitions *parts, part_id root_id, 210 bool root_is_new, part_id efi_id, bool efi_is_new) 211 { 212 /* no GPT boot support, no special checks needed */ 213 return true; 214 } 215 #endif 216 217