Home | History | Annotate | Line # | Download | only in sparc64
      1 /*	$NetBSD: md.c,v 1.8 2022/12/09 17:02:14 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 /* changes from the sparc version made by mrg */
     36 
     37 /* md.c -- sparc64 machine specific routines */
     38 /* This file is in close sync with pmax, vax, and x68k, sparc md.c */
     39 
     40 #include <sys/types.h>
     41 #include <sys/ioctl.h>
     42 #include <sys/param.h>
     43 #include <stdio.h>
     44 #include <curses.h>
     45 #include <unistd.h>
     46 #include <fcntl.h>
     47 #include <util.h>
     48 
     49 #include "defs.h"
     50 #include "md.h"
     51 #include "msg_defs.h"
     52 #include "menu_defs.h"
     53 
     54 static void install_bootblocks(void);
     55 static void install_ofwboot(void);
     56 
     57 void
     58 md_init(void)
     59 {
     60 }
     61 
     62 void
     63 md_init_set_status(int flags)
     64 {
     65 	(void)flags;
     66 }
     67 
     68 bool
     69 md_get_info(struct install_partition_desc *install)
     70 {
     71 
     72 	set_default_sizemult(pm->diskdev, MEG, pm->sectorsize);
     73 	return true;
     74 }
     75 
     76 /*
     77  * md back-end code for menu-driven BSD disklabel editor.
     78  */
     79 int
     80 md_make_bsd_partitions(struct install_partition_desc *install)
     81 {
     82 	return make_bsd_partitions(install);
     83 }
     84 
     85 /*
     86  * any additional partition validation
     87  */
     88 bool
     89 md_check_partitions(struct install_partition_desc *install)
     90 {
     91 	return true;
     92 }
     93 
     94 /*
     95  * hook called before writing new disklabel.
     96  */
     97 bool
     98 md_pre_disklabel(struct install_partition_desc *install,
     99     struct disk_partitions *parts)
    100 {
    101 	return true;
    102 }
    103 
    104 /*
    105  * hook called after writing disklabel to new target disk.
    106  */
    107 bool
    108 md_post_disklabel(struct install_partition_desc *install,
    109     struct disk_partitions *parts)
    110 {
    111 	install_bootblocks();
    112 	return true;
    113 }
    114 
    115 /*
    116  * hook called after upgrade() or install() has finished setting
    117  * up the target disk but immediately before the user is given the
    118  * ``disks are now set up'' message.
    119  */
    120 int
    121 md_post_newfs(struct install_partition_desc *install)
    122 {
    123 	install_ofwboot();
    124 	return 0;
    125 }
    126 
    127 int
    128 md_post_extract(struct install_partition_desc *install, bool upgrade)
    129 {
    130 	return 0;
    131 }
    132 
    133 void
    134 md_cleanup_install(struct install_partition_desc *install)
    135 {
    136 #ifndef DEBUG
    137 	enable_rc_conf();
    138 #endif
    139 }
    140 
    141 int
    142 md_pre_update(struct install_partition_desc *install)
    143 {
    144 	return 1;
    145 }
    146 
    147 /* Upgrade support */
    148 int
    149 md_update(struct install_partition_desc *install)
    150 {
    151 	md_post_newfs(install);
    152 	return 1;
    153 }
    154 
    155 /* install/update bootblocks */
    156 static void
    157 install_bootblocks(void)
    158 {
    159 	/* Install boot blocks before mounting the target disk */
    160 	msg_fmt_display(MSG_dobootblks, "%s", pm->diskdev);
    161 	run_program(RUN_DISPLAY, "/sbin/disklabel -W %s", pm->diskdev);
    162 	run_program(RUN_DISPLAY, "/usr/sbin/installboot /dev/r%sc"
    163 	    " /usr/mdec/bootblk", pm->diskdev);
    164 }
    165 
    166 /* install/update secondary bootstrap */
    167 static void
    168 install_ofwboot(void)
    169 {
    170 	/* copy secondary bootstrap now that the target is mounted */
    171 	msg_fmt_display(MSG_doofwboot, "%s", targetroot_mnt);
    172 	run_program(RUN_DISPLAY, "/bin/cp -p /usr/mdec/ofwboot %s",
    173 	    targetroot_mnt);
    174 }
    175 
    176 int
    177 md_pre_mount(struct install_partition_desc *install, size_t ndx)
    178 {
    179 	if (ndx == 0)
    180 		install_bootblocks();
    181 	return 0;
    182 }
    183 
    184 bool
    185 md_parts_use_wholedisk(struct disk_partitions *parts)
    186 {
    187 	return parts_use_wholedisk(parts, 0, NULL);
    188 }
    189 
    190 
    191 #ifdef HAVE_GPT
    192 /*
    193  * New GPT partitions have been written, update bootloader or remember
    194  * data untill needed in md_post_newfs
    195  */
    196 bool
    197 md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
    198     bool root_is_new, part_id efi_id, bool efi_is_new)
    199 {
    200 	return true;
    201 }
    202 #endif
    203