Home | History | Annotate | Line # | Download | only in sandpoint
md.c revision 1.10
      1 /*	$NetBSD: md.c,v 1.10 2022/01/29 16:01:20 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 -- sandpoint machine specific routines */
     36 
     37 #include <sys/param.h>
     38 #include <sys/sysctl.h>
     39 #include <sys/utsname.h>
     40 
     41 #include <stdio.h>
     42 #include <string.h>
     43 #include <util.h>
     44 
     45 #include "defs.h"
     46 #include "md.h"
     47 #include "msg_defs.h"
     48 #include "menu_defs.h"
     49 
     50 static char *prodname;
     51 
     52 void
     53 md_init(void)
     54 {
     55 }
     56 
     57 void
     58 md_init_set_status(int flags)
     59 {
     60 	static const char mib_name[] = "machdep.prodfamily";
     61 	static char unknown[] = "unknown";
     62 	size_t len;
     63 
     64 	(void)flags;
     65 
     66 	/*
     67 	 * Determine the product family of the board we are running on and
     68 	 * enable the installation of the corresponding GENERIC kernel.
     69 	 *
     70 	 * Note:  In md.h the two kernels are disabled.  If they are
     71 	 *        enabled there the logic here needs to be switched.
     72 	 */
     73 	if (sysctlbyname(mib_name, NULL, &len, NULL, 0) != 0) {
     74 		prodname = unknown;
     75 		return;
     76 	}
     77 	prodname = malloc(len);
     78 	sysctlbyname(mib_name, prodname, &len, NULL, 0);
     79 
     80 	if (strcmp(prodname, "kurobox")==0 || strcmp(prodname, "kurot4")==0)
     81 		/*
     82 		 * Running on a KuroBox family product, so enable KUROBOX
     83 		 */
     84 		set_kernel_set(SET_KERNEL_2);
     85         else
     86 		/*
     87 		 * Otherwise enable GENERIC
     88 		 */
     89 		set_kernel_set(SET_KERNEL_1);
     90 }
     91 
     92 bool
     93 md_get_info(struct install_partition_desc *install)
     94 {
     95 	int res;
     96 
     97 	if (pm->no_mbr || pm->no_part)
     98 		return true;
     99 
    100 again:
    101 	if (pm->parts == NULL) {
    102 
    103 		const struct disk_partitioning_scheme *ps =
    104 		    select_part_scheme(pm, NULL, true, NULL);
    105 
    106 		if (!ps)
    107 			return false;
    108 
    109 		struct disk_partitions *parts =
    110 		   (*ps->create_new_for_disk)(pm->diskdev,
    111 		   0, pm->dlsize, true, NULL);
    112 		if (!parts)
    113 			return false;
    114 
    115 		pm->parts = parts;
    116 		if (ps->size_limit > 0 && pm->dlsize > ps->size_limit)
    117 			pm->dlsize = ps->size_limit;
    118 	}
    119 
    120 	res = set_bios_geom_with_mbr_guess(pm->parts);
    121 	if (res == 0)
    122 		return false;
    123 	else if (res == 1)
    124 		return true;
    125 
    126 	pm->parts->pscheme->destroy_part_scheme(pm->parts);
    127 	pm->parts = NULL;
    128 	goto again;
    129 }
    130 
    131 /*
    132  * md back-end code for menu-driven BSD disklabel editor.
    133  */
    134 int
    135 md_make_bsd_partitions(struct install_partition_desc *install)
    136 {
    137 	return make_bsd_partitions(install);
    138 }
    139 
    140 /*
    141  * any additional partition validation
    142  */
    143 bool
    144 md_check_partitions(struct install_partition_desc *install)
    145 {
    146 	return true;
    147 }
    148 
    149 /*
    150  * hook called before writing new disklabel.
    151  */
    152 bool
    153 md_pre_disklabel(struct install_partition_desc *install,
    154     struct disk_partitions *parts)
    155 {
    156 
    157 	if (parts->parent == NULL)
    158 		return true;	/* no outer partitions */
    159 
    160 	parts = parts->parent;
    161 
    162 	msg_display_subst(MSG_dofdisk, 3, parts->disk,
    163 	    msg_string(parts->pscheme->name),
    164 	    msg_string(parts->pscheme->short_name));
    165 
    166 	/* write edited "MBR" onto disk. */
    167 	if (!parts->pscheme->write_to_disk(parts)) {
    168 		msg_display(MSG_wmbrfail);
    169 		process_menu(MENU_ok, NULL);
    170 		return false;
    171 	}
    172 	return true;
    173 }
    174 
    175 /*
    176  * hook called after writing disklabel to new target disk.
    177  */
    178 bool
    179 md_post_disklabel(struct install_partition_desc *install,
    180     struct disk_partitions *parts)
    181 {
    182 	return true;
    183 }
    184 
    185 /*
    186  * hook called after upgrade() or install() has finished setting
    187  * up the target disk but immediately before the user is given the
    188  * ``disks are now set up'' message.
    189  */
    190 int
    191 md_post_newfs(struct install_partition_desc *install)
    192 {
    193 	/* no boot blocks, we are using altboot */
    194 	return 0;
    195 }
    196 
    197 int
    198 md_post_extract(struct install_partition_desc *install, bool upgrade)
    199 {
    200 	return 0;
    201 }
    202 
    203 void
    204 md_cleanup_install(struct install_partition_desc *install)
    205 {
    206 #ifndef DEBUG
    207 	int new_speed;
    208 
    209 	enable_rc_conf();
    210 
    211 	/*
    212 	 * Set the console speed in /etc/ttys depending on the board.
    213 	 * The default speed is 115200, which is patched when needed.
    214 	 */
    215 	if (strcmp(prodname, "kurobox")==0 || strcmp(prodname, "kurot4")==0)
    216 		new_speed = 57600;			/* KuroBox */
    217 
    218 	else if (strcmp(prodname, "dlink") == 0 ||	/* D-Link DSM-G600 */
    219 	    strcmp(prodname, "nhnas") == 0)		/* NH23x, All6250 */
    220 		new_speed = 9600;
    221 
    222 	else
    223 		new_speed = 0;
    224 
    225 	if (new_speed != 0) {
    226 		run_program(RUN_CHROOT, "sed -an -e 's/115200/%d/;H;$!d;g;w"
    227 		    "/etc/ttys' /etc/ttys", new_speed);
    228 	}
    229 #endif
    230 }
    231 
    232 int
    233 md_pre_update(struct install_partition_desc *install)
    234 {
    235 	return 1;
    236 }
    237 
    238 /* Upgrade support */
    239 int
    240 md_update(struct install_partition_desc *install)
    241 {
    242 	md_post_newfs(install);
    243 	return 1;
    244 }
    245 
    246 int
    247 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
    248 {
    249 	return 2;
    250 }
    251 
    252 bool
    253 md_parts_use_wholedisk(struct disk_partitions *parts)
    254 {
    255 	return parts_use_wholedisk(parts, 0, NULL);
    256 }
    257 
    258 int
    259 md_pre_mount(struct install_partition_desc *install, size_t ndx)
    260 {
    261 	return 0;
    262 }
    263 
    264 bool
    265 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
    266 {
    267 	return false;	/* no change, no need to write back */
    268 }
    269 
    270 #ifdef HAVE_GPT
    271 bool
    272 md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
    273     bool root_is_new, part_id efi_id, bool efi_is_new)
    274 {
    275 	/* no GPT boot support, nothing needs to be done here */
    276 	return true;
    277 }
    278 #endif
    279 
    280