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