xref: /netbsd-src/usr.sbin/sysinst/arch/sandpoint/md.c (revision 4204f81037ec1430b81b70ee975f04b277901e24)
1*4204f810Smartin /*	$NetBSD: md.c,v 1.10 2022/01/29 16:01:20 martin Exp $ */
250dbef1aSdholland 
350dbef1aSdholland /*
450dbef1aSdholland  * Copyright 1997 Piermont Information Systems Inc.
550dbef1aSdholland  * All rights reserved.
650dbef1aSdholland  *
750dbef1aSdholland  * Based on code written by Philip A. Nelson for Piermont Information
850dbef1aSdholland  * Systems Inc.
950dbef1aSdholland  *
1050dbef1aSdholland  * Redistribution and use in source and binary forms, with or without
1150dbef1aSdholland  * modification, are permitted provided that the following conditions
1250dbef1aSdholland  * are met:
1350dbef1aSdholland  * 1. Redistributions of source code must retain the above copyright
1450dbef1aSdholland  *    notice, this list of conditions and the following disclaimer.
1550dbef1aSdholland  * 2. Redistributions in binary form must reproduce the above copyright
1650dbef1aSdholland  *    notice, this list of conditions and the following disclaimer in the
1750dbef1aSdholland  *    documentation and/or other materials provided with the distribution.
1850dbef1aSdholland  * 3. The name of Piermont Information Systems Inc. may not be used to endorse
1950dbef1aSdholland  *    or promote products derived from this software without specific prior
2050dbef1aSdholland  *    written permission.
2150dbef1aSdholland  *
2250dbef1aSdholland  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
2350dbef1aSdholland  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2450dbef1aSdholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2550dbef1aSdholland  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
2650dbef1aSdholland  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2750dbef1aSdholland  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2850dbef1aSdholland  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2950dbef1aSdholland  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3050dbef1aSdholland  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3150dbef1aSdholland  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3250dbef1aSdholland  * THE POSSIBILITY OF SUCH DAMAGE.
3350dbef1aSdholland  */
3450dbef1aSdholland 
3550dbef1aSdholland /* md.c -- sandpoint machine specific routines */
3650dbef1aSdholland 
3750dbef1aSdholland #include <sys/param.h>
3850dbef1aSdholland #include <sys/sysctl.h>
3950dbef1aSdholland #include <sys/utsname.h>
4050dbef1aSdholland 
4150dbef1aSdholland #include <stdio.h>
4250dbef1aSdholland #include <string.h>
4350dbef1aSdholland #include <util.h>
4450dbef1aSdholland 
4550dbef1aSdholland #include "defs.h"
4650dbef1aSdholland #include "md.h"
4750dbef1aSdholland #include "msg_defs.h"
4850dbef1aSdholland #include "menu_defs.h"
4950dbef1aSdholland 
5050dbef1aSdholland static char *prodname;
5150dbef1aSdholland 
5250dbef1aSdholland void
md_init(void)5350dbef1aSdholland md_init(void)
5450dbef1aSdholland {
5550dbef1aSdholland }
5650dbef1aSdholland 
5750dbef1aSdholland void
md_init_set_status(int flags)5850dbef1aSdholland md_init_set_status(int flags)
5950dbef1aSdholland {
6050dbef1aSdholland 	static const char mib_name[] = "machdep.prodfamily";
6150dbef1aSdholland 	static char unknown[] = "unknown";
6250dbef1aSdholland 	size_t len;
6350dbef1aSdholland 
6450dbef1aSdholland 	(void)flags;
6550dbef1aSdholland 
6650dbef1aSdholland 	/*
6750dbef1aSdholland 	 * Determine the product family of the board we are running on and
6850dbef1aSdholland 	 * enable the installation of the corresponding GENERIC kernel.
6950dbef1aSdholland 	 *
7050dbef1aSdholland 	 * Note:  In md.h the two kernels are disabled.  If they are
7150dbef1aSdholland 	 *        enabled there the logic here needs to be switched.
7250dbef1aSdholland 	 */
7350dbef1aSdholland 	if (sysctlbyname(mib_name, NULL, &len, NULL, 0) != 0) {
7450dbef1aSdholland 		prodname = unknown;
7550dbef1aSdholland 		return;
7650dbef1aSdholland 	}
7750dbef1aSdholland 	prodname = malloc(len);
7850dbef1aSdholland 	sysctlbyname(mib_name, prodname, &len, NULL, 0);
7950dbef1aSdholland 
8050dbef1aSdholland 	if (strcmp(prodname, "kurobox")==0 || strcmp(prodname, "kurot4")==0)
8150dbef1aSdholland 		/*
8250dbef1aSdholland 		 * Running on a KuroBox family product, so enable KUROBOX
8350dbef1aSdholland 		 */
8450dbef1aSdholland 		set_kernel_set(SET_KERNEL_2);
8550dbef1aSdholland         else
8650dbef1aSdholland 		/*
8750dbef1aSdholland 		 * Otherwise enable GENERIC
8850dbef1aSdholland 		 */
8950dbef1aSdholland 		set_kernel_set(SET_KERNEL_1);
9050dbef1aSdholland }
9150dbef1aSdholland 
924103857bSmartin bool
md_get_info(struct install_partition_desc * install)934103857bSmartin md_get_info(struct install_partition_desc *install)
9450dbef1aSdholland {
95957b5cd6Smartin 	int res;
96e11b8d25Smartin 
97e11b8d25Smartin 	if (pm->no_mbr || pm->no_part)
98e11b8d25Smartin 		return true;
99e11b8d25Smartin 
100957b5cd6Smartin again:
101e11b8d25Smartin 	if (pm->parts == NULL) {
102e11b8d25Smartin 
103e11b8d25Smartin 		const struct disk_partitioning_scheme *ps =
104e11b8d25Smartin 		    select_part_scheme(pm, NULL, true, NULL);
105e11b8d25Smartin 
106e11b8d25Smartin 		if (!ps)
1076fec6798Smartin 			return false;
108e11b8d25Smartin 
109e11b8d25Smartin 		struct disk_partitions *parts =
110e11b8d25Smartin 		   (*ps->create_new_for_disk)(pm->diskdev,
11186906049Smartin 		   0, pm->dlsize, true, NULL);
112e11b8d25Smartin 		if (!parts)
113e11b8d25Smartin 			return false;
114e11b8d25Smartin 
115e11b8d25Smartin 		pm->parts = parts;
116e11b8d25Smartin 		if (ps->size_limit > 0 && pm->dlsize > ps->size_limit)
117e11b8d25Smartin 			pm->dlsize = ps->size_limit;
118e11b8d25Smartin 	}
119e11b8d25Smartin 
120957b5cd6Smartin 	res = set_bios_geom_with_mbr_guess(pm->parts);
121957b5cd6Smartin 	if (res == 0)
122957b5cd6Smartin 		return false;
123957b5cd6Smartin 	else if (res == 1)
124957b5cd6Smartin 		return true;
125957b5cd6Smartin 
126957b5cd6Smartin 	pm->parts->pscheme->destroy_part_scheme(pm->parts);
127957b5cd6Smartin 	pm->parts = NULL;
128957b5cd6Smartin 	goto again;
12950dbef1aSdholland }
13050dbef1aSdholland 
13150dbef1aSdholland /*
13250dbef1aSdholland  * md back-end code for menu-driven BSD disklabel editor.
13350dbef1aSdholland  */
134957b5cd6Smartin int
md_make_bsd_partitions(struct install_partition_desc * install)1354103857bSmartin md_make_bsd_partitions(struct install_partition_desc *install)
13650dbef1aSdholland {
1374103857bSmartin 	return make_bsd_partitions(install);
13850dbef1aSdholland }
13950dbef1aSdholland 
14050dbef1aSdholland /*
14150dbef1aSdholland  * any additional partition validation
14250dbef1aSdholland  */
1434103857bSmartin bool
md_check_partitions(struct install_partition_desc * install)1444103857bSmartin md_check_partitions(struct install_partition_desc *install)
14550dbef1aSdholland {
1464103857bSmartin 	return true;
14750dbef1aSdholland }
14850dbef1aSdholland 
14950dbef1aSdholland /*
15050dbef1aSdholland  * hook called before writing new disklabel.
15150dbef1aSdholland  */
1524103857bSmartin bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1534103857bSmartin md_pre_disklabel(struct install_partition_desc *install,
1544103857bSmartin     struct disk_partitions *parts)
15550dbef1aSdholland {
15650dbef1aSdholland 
1574103857bSmartin 	if (parts->parent == NULL)
1584103857bSmartin 		return true;	/* no outer partitions */
1594103857bSmartin 
1604103857bSmartin 	parts = parts->parent;
1614103857bSmartin 
1624103857bSmartin 	msg_display_subst(MSG_dofdisk, 3, parts->disk,
1634103857bSmartin 	    msg_string(parts->pscheme->name),
1644103857bSmartin 	    msg_string(parts->pscheme->short_name));
1654103857bSmartin 
1664103857bSmartin 	/* write edited "MBR" onto disk. */
1674103857bSmartin 	if (!parts->pscheme->write_to_disk(parts)) {
16850dbef1aSdholland 		msg_display(MSG_wmbrfail);
16950dbef1aSdholland 		process_menu(MENU_ok, NULL);
1704103857bSmartin 		return false;
17150dbef1aSdholland 	}
1724103857bSmartin 	return true;
17350dbef1aSdholland }
17450dbef1aSdholland 
17550dbef1aSdholland /*
17650dbef1aSdholland  * hook called after writing disklabel to new target disk.
17750dbef1aSdholland  */
1784103857bSmartin bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1794103857bSmartin md_post_disklabel(struct install_partition_desc *install,
1804103857bSmartin     struct disk_partitions *parts)
18150dbef1aSdholland {
1824103857bSmartin 	return true;
18350dbef1aSdholland }
18450dbef1aSdholland 
18550dbef1aSdholland /*
18650dbef1aSdholland  * hook called after upgrade() or install() has finished setting
18750dbef1aSdholland  * up the target disk but immediately before the user is given the
18850dbef1aSdholland  * ``disks are now set up'' message.
18950dbef1aSdholland  */
19050dbef1aSdholland int
md_post_newfs(struct install_partition_desc * install)1914103857bSmartin md_post_newfs(struct install_partition_desc *install)
19250dbef1aSdholland {
19350dbef1aSdholland 	/* no boot blocks, we are using altboot */
19450dbef1aSdholland 	return 0;
19550dbef1aSdholland }
19650dbef1aSdholland 
19750dbef1aSdholland int
md_post_extract(struct install_partition_desc * install,bool upgrade)198*4204f810Smartin md_post_extract(struct install_partition_desc *install, bool upgrade)
19950dbef1aSdholland {
20050dbef1aSdholland 	return 0;
20150dbef1aSdholland }
20250dbef1aSdholland 
20350dbef1aSdholland void
md_cleanup_install(struct install_partition_desc * install)2044103857bSmartin md_cleanup_install(struct install_partition_desc *install)
20550dbef1aSdholland {
20650dbef1aSdholland #ifndef DEBUG
20750dbef1aSdholland 	int new_speed;
20850dbef1aSdholland 
20950dbef1aSdholland 	enable_rc_conf();
21050dbef1aSdholland 
21150dbef1aSdholland 	/*
21250dbef1aSdholland 	 * Set the console speed in /etc/ttys depending on the board.
21350dbef1aSdholland 	 * The default speed is 115200, which is patched when needed.
21450dbef1aSdholland 	 */
21550dbef1aSdholland 	if (strcmp(prodname, "kurobox")==0 || strcmp(prodname, "kurot4")==0)
21650dbef1aSdholland 		new_speed = 57600;			/* KuroBox */
21750dbef1aSdholland 
21850dbef1aSdholland 	else if (strcmp(prodname, "dlink") == 0 ||	/* D-Link DSM-G600 */
21950dbef1aSdholland 	    strcmp(prodname, "nhnas") == 0)		/* NH23x, All6250 */
22050dbef1aSdholland 		new_speed = 9600;
22150dbef1aSdholland 
22250dbef1aSdholland 	else
22350dbef1aSdholland 		new_speed = 0;
22450dbef1aSdholland 
22550dbef1aSdholland 	if (new_speed != 0) {
22650dbef1aSdholland 		run_program(RUN_CHROOT, "sed -an -e 's/115200/%d/;H;$!d;g;w"
22750dbef1aSdholland 		    "/etc/ttys' /etc/ttys", new_speed);
22850dbef1aSdholland 	}
22950dbef1aSdholland #endif
23050dbef1aSdholland }
23150dbef1aSdholland 
23250dbef1aSdholland int
md_pre_update(struct install_partition_desc * install)2334103857bSmartin md_pre_update(struct install_partition_desc *install)
23450dbef1aSdholland {
23550dbef1aSdholland 	return 1;
23650dbef1aSdholland }
23750dbef1aSdholland 
23850dbef1aSdholland /* Upgrade support */
23950dbef1aSdholland int
md_update(struct install_partition_desc * install)2404103857bSmartin md_update(struct install_partition_desc *install)
24150dbef1aSdholland {
2424103857bSmartin 	md_post_newfs(install);
24350dbef1aSdholland 	return 1;
24450dbef1aSdholland }
24550dbef1aSdholland 
24650dbef1aSdholland int
md_check_mbr(struct disk_partitions * parts,mbr_info_t * mbri,bool quiet)2474103857bSmartin md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
24850dbef1aSdholland {
24950dbef1aSdholland 	return 2;
25050dbef1aSdholland }
25150dbef1aSdholland 
2524103857bSmartin bool
md_parts_use_wholedisk(struct disk_partitions * parts)2534103857bSmartin md_parts_use_wholedisk(struct disk_partitions *parts)
25450dbef1aSdholland {
2554103857bSmartin 	return parts_use_wholedisk(parts, 0, NULL);
25650dbef1aSdholland }
25750dbef1aSdholland 
25850dbef1aSdholland int
md_pre_mount(struct install_partition_desc * install,size_t ndx)2594f30cbf3Smartin md_pre_mount(struct install_partition_desc *install, size_t ndx)
26050dbef1aSdholland {
26150dbef1aSdholland 	return 0;
26250dbef1aSdholland }
2634103857bSmartin 
2644103857bSmartin bool
md_mbr_update_check(struct disk_partitions * parts,mbr_info_t * mbri)2654103857bSmartin md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
2664103857bSmartin {
2674103857bSmartin 	return false;	/* no change, no need to write back */
2684103857bSmartin }
2694103857bSmartin 
2704103857bSmartin #ifdef HAVE_GPT
2714103857bSmartin bool
md_gpt_post_write(struct disk_partitions * parts,part_id root_id,bool root_is_new,part_id efi_id,bool efi_is_new)2724103857bSmartin md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
2734103857bSmartin     bool root_is_new, part_id efi_id, bool efi_is_new)
2744103857bSmartin {
2754103857bSmartin 	/* no GPT boot support, nothing needs to be done here */
2764103857bSmartin 	return true;
2774103857bSmartin }
2784103857bSmartin #endif
2794103857bSmartin 
280