1 /* $NetBSD: md.c,v 1.3 2015/05/10 10:14:02 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 -- 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 43 #include "defs.h" 44 #include "md.h" 45 #include "msg_defs.h" 46 #include "menu_defs.h" 47 48 void 49 md_init(void) 50 { 51 } 52 53 void 54 md_init_set_status(int flags) 55 { 56 (void)flags; 57 } 58 59 int 60 md_get_info(void) 61 { 62 return 1; 63 } 64 65 /* 66 * md back-end code for menu-driven BSD disklabel editor. 67 */ 68 int 69 md_make_bsd_partitions(void) 70 { 71 msg_display(MSG_infoahdilabel, pm->diskdev); 72 if (ask_noyes(NULL)) { 73 run_program(RUN_DISPLAY, "ahdilabel /dev/r%sc", pm->diskdev); 74 } 75 if (!make_bsd_partitions()) 76 return 0; 77 78 /* 79 * Setup the disktype so /etc/disktab gets proper info 80 */ 81 if (strncmp (pm->diskdev, "sd", 2) == 0) 82 pm->disktype = "SCSI"; 83 else 84 pm->disktype = "ST506"; 85 86 return 1; 87 } 88 89 /* 90 * any additional partition validation 91 */ 92 int 93 md_check_partitions(void) 94 { 95 return 1; 96 } 97 98 /* 99 * hook called before writing new disklabel. 100 */ 101 int 102 md_pre_disklabel(void) 103 { 104 return 0; 105 } 106 107 /* 108 * hook called after writing disklabel to new target disk. 109 */ 110 int 111 md_post_disklabel(void) 112 { 113 return 0; 114 } 115 116 /* 117 * hook called after upgrade() or install() has finished setting 118 * up the target disk but immediately before the user is given the 119 * ``disks are now set up'' message. 120 */ 121 int 122 md_post_newfs(void) 123 { 124 static const int mib[2] = {CTL_HW, HW_MODEL}; 125 size_t len; 126 char *cpu_model; 127 int milan; 128 char bootpath[MAXPATHLEN]; 129 int rv; 130 131 /* check machine type via sysctl to select appropriate bootloaders */ 132 milan = 0; /* std is default */ 133 sysctl(mib, 2, NULL, &len, NULL, 0); 134 cpu_model = malloc(len); 135 sysctl(mib, 2, cpu_model, &len, NULL, 0); 136 /* XXX model strings should be a common macro to sync with kernel */ 137 if (strstr(cpu_model, "Milan") != NULL) 138 milan = 1; 139 free(cpu_model); 140 141 /* copy tertiary boot and install boot blocks */ 142 msg_display(MSG_dobootblks, pm->diskdev); 143 snprintf(bootpath, sizeof(bootpath), "/usr/mdec/%s/boot.atari", 144 milan ? "milan" : "std"); 145 rv = cp_to_target(bootpath, "/"); 146 if (rv != 0) 147 return rv; 148 149 rv = run_program(RUN_DISPLAY, "/usr/mdec/installboot -v%s /dev/r%sc", 150 milan ? "m" : "", pm->diskdev); 151 152 return rv; 153 } 154 155 int 156 md_post_extract(void) 157 { 158 return 0; 159 } 160 161 void 162 md_cleanup_install(void) 163 { 164 #ifndef DEBUG 165 enable_rc_conf(); 166 #endif 167 } 168 169 int 170 md_pre_update(void) 171 { 172 return 1; 173 } 174 175 /* Upgrade support */ 176 int 177 md_update(void) 178 { 179 md_post_newfs(); 180 return 1; 181 } 182 183 int 184 md_pre_mount() 185 { 186 return 0; 187 } 188