Home | History | Annotate | Line # | Download | only in sandpoint
md.c revision 1.1
      1 /*	$NetBSD: md.c,v 1.1 2014/07/26 19:30:47 dholland 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 int
     93 md_get_info(void)
     94 {
     95 	return set_bios_geom_with_mbr_guess();
     96 }
     97 
     98 /*
     99  * md back-end code for menu-driven BSD disklabel editor.
    100  */
    101 int
    102 md_make_bsd_partitions(void)
    103 {
    104 	return make_bsd_partitions();
    105 }
    106 
    107 /*
    108  * any additional partition validation
    109  */
    110 int
    111 md_check_partitions(void)
    112 {
    113 	return 1;
    114 }
    115 
    116 /*
    117  * hook called before writing new disklabel.
    118  */
    119 int
    120 md_pre_disklabel(void)
    121 {
    122 	printf ("%s", msg_string (MSG_dofdisk));
    123 
    124 	/* write edited MBR onto disk. */
    125 	if (write_mbr(diskdev, &mbr, 1) != 0) {
    126 		msg_display(MSG_wmbrfail);
    127 		process_menu(MENU_ok, NULL);
    128 		return 1;
    129 	}
    130 	return 0;
    131 }
    132 
    133 /*
    134  * hook called after writing disklabel to new target disk.
    135  */
    136 int
    137 md_post_disklabel(void)
    138 {
    139 	/* Sector forwarding / badblocks ... */
    140 	if (*doessf) {
    141 		printf ("%s", msg_string (MSG_dobad144));
    142 		return run_program(RUN_DISPLAY, "/usr/sbin/bad144 %s 0",
    143 		    diskdev);
    144 	}
    145 	return 0;
    146 }
    147 
    148 /*
    149  * hook called after upgrade() or install() has finished setting
    150  * up the target disk but immediately before the user is given the
    151  * ``disks are now set up'' message.
    152  */
    153 int
    154 md_post_newfs(void)
    155 {
    156 	/* no boot blocks, we are using altboot */
    157 	return 0;
    158 }
    159 
    160 int
    161 md_post_extract(void)
    162 {
    163 	return 0;
    164 }
    165 
    166 void
    167 md_cleanup_install(void)
    168 {
    169 #ifndef DEBUG
    170 	int new_speed;
    171 
    172 	enable_rc_conf();
    173 
    174 	/*
    175 	 * Set the console speed in /etc/ttys depending on the board.
    176 	 * The default speed is 115200, which is patched when needed.
    177 	 */
    178 	if (strcmp(prodname, "kurobox")==0 || strcmp(prodname, "kurot4")==0)
    179 		new_speed = 57600;			/* KuroBox */
    180 
    181 	else if (strcmp(prodname, "dlink") == 0 ||	/* D-Link DSM-G600 */
    182 	    strcmp(prodname, "nhnas") == 0)		/* NH23x, All6250 */
    183 		new_speed = 9600;
    184 
    185 	else
    186 		new_speed = 0;
    187 
    188 	if (new_speed != 0) {
    189 		run_program(RUN_CHROOT, "sed -an -e 's/115200/%d/;H;$!d;g;w"
    190 		    "/etc/ttys' /etc/ttys", new_speed);
    191 	}
    192 #endif
    193 }
    194 
    195 int
    196 md_pre_update(void)
    197 {
    198 	return 1;
    199 }
    200 
    201 /* Upgrade support */
    202 int
    203 md_update(void)
    204 {
    205 	md_post_newfs();
    206 	return 1;
    207 }
    208 
    209 int
    210 md_check_mbr(mbr_info_t *mbri)
    211 {
    212 	return 2;
    213 }
    214 
    215 int
    216 md_mbr_use_wholedisk(mbr_info_t *mbri)
    217 {
    218 	return mbr_use_wholedisk(mbri);
    219 }
    220 
    221 int
    222 md_pre_mount()
    223 {
    224 	return 0;
    225 }
    226