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