xref: /netbsd-src/usr.sbin/sysinst/arch/sgimips/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 -- sgimips machine specific routines */
3650dbef1aSdholland 
3750dbef1aSdholland #include <sys/types.h>
3850dbef1aSdholland #include <sys/ioctl.h>
3950dbef1aSdholland #include <sys/param.h>
4050dbef1aSdholland #include <sys/utsname.h>
4150dbef1aSdholland #include <stdio.h>
4250dbef1aSdholland #include <curses.h>
4350dbef1aSdholland #include <unistd.h>
4450dbef1aSdholland #include <fcntl.h>
4550dbef1aSdholland #include <util.h>
4650dbef1aSdholland #include <errno.h>
4750dbef1aSdholland 
4850dbef1aSdholland #include "defs.h"
4950dbef1aSdholland #include "md.h"
5050dbef1aSdholland #include "msg_defs.h"
5150dbef1aSdholland #include "menu_defs.h"
5250dbef1aSdholland 
5350dbef1aSdholland 
5450dbef1aSdholland void
md_init(void)5550dbef1aSdholland md_init(void)
5650dbef1aSdholland {
5750dbef1aSdholland }
5850dbef1aSdholland 
5950dbef1aSdholland void
md_init_set_status(int flags)6050dbef1aSdholland md_init_set_status(int flags)
6150dbef1aSdholland {
62a6c219b7Smartin 	struct utsname instsys;
63a6c219b7Smartin 
6450dbef1aSdholland 	(void)flags;
6550dbef1aSdholland 
6650dbef1aSdholland         /*
6750dbef1aSdholland          * Get the name of the Install Kernel we are running under and
6850dbef1aSdholland          * enable the installation of the corresponding GENERIC kernel.
6950dbef1aSdholland          */
7050dbef1aSdholland 	uname(&instsys);
7127aaea9dSjmcneill         if (strstr(instsys.version, "(INSTALL32_IP3x"))
7250dbef1aSdholland                 set_kernel_set(SET_KERNEL_2);
7327aaea9dSjmcneill         else if (strstr(instsys.version, "(INSTALL32_IP2x"))
7450dbef1aSdholland                 set_kernel_set(SET_KERNEL_1);
7527aaea9dSjmcneill 	else if (strstr(instsys.version, "(GENERIC32_IP12"))
7650dbef1aSdholland 		set_kernel_set(SET_KERNEL_3);
7750dbef1aSdholland }
7850dbef1aSdholland 
794103857bSmartin bool
md_get_info(struct install_partition_desc * install)804103857bSmartin md_get_info(struct install_partition_desc *install)
8150dbef1aSdholland {
8250dbef1aSdholland 	struct disklabel disklabel;
8350dbef1aSdholland 	int fd;
8450dbef1aSdholland 	char dev_name[100];
8550dbef1aSdholland 
864b2364d9Smartin 	snprintf(dev_name, 100, "/dev/r%s%c", pm->diskdev, 'a' + getrawpartition());
8750dbef1aSdholland 
8850dbef1aSdholland 	fd = open(dev_name, O_RDONLY, 0);
8950dbef1aSdholland 	if (fd < 0) {
9050dbef1aSdholland 		if (logfp)
9150dbef1aSdholland 			(void)fprintf(logfp, "Can't open %s\n", dev_name);
9250dbef1aSdholland 		endwin();
9350dbef1aSdholland 		fprintf(stderr, "Can't open %s\n", dev_name);
9450dbef1aSdholland 		exit(1);
9550dbef1aSdholland 	}
9650dbef1aSdholland 	if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
9750dbef1aSdholland 		if (logfp)
9850dbef1aSdholland 			(void)fprintf(logfp, "Can't read disklabel on %s.\n",
9950dbef1aSdholland 				dev_name);
10050dbef1aSdholland 		endwin();
10150dbef1aSdholland 		fprintf(stderr, "Can't read disklabel on %s.\n", dev_name);
10250dbef1aSdholland 		close(fd);
10350dbef1aSdholland 		exit(1);
10450dbef1aSdholland 	}
10550dbef1aSdholland 	close(fd);
10650dbef1aSdholland 
1074b2364d9Smartin 	pm->dlcyl = disklabel.d_ncylinders;
1084b2364d9Smartin 	pm->dlhead = disklabel.d_ntracks;
1094b2364d9Smartin 	pm->dlsec = disklabel.d_nsectors;
1104b2364d9Smartin 	pm->sectorsize = disklabel.d_secsize;
1114b2364d9Smartin 	pm->dlcylsize = disklabel.d_secpercyl;
11250dbef1aSdholland 
11350dbef1aSdholland 	/*
1144b2364d9Smartin 	 * Compute whole disk size. Take max of (pm->dlcyl*pm->dlhead*pm->dlsec)
11550dbef1aSdholland 	 * and secperunit,  just in case the disk is already labelled.
11650dbef1aSdholland 	 * (If our new label's RAW_PART size ends up smaller than the
11750dbef1aSdholland 	 * in-core RAW_PART size  value, updating the label will fail.)
11850dbef1aSdholland 	 */
1194b2364d9Smartin 	pm->dlsize = pm->dlcyl*pm->dlhead*pm->dlsec;
1204b2364d9Smartin 	if (disklabel.d_secperunit > pm->dlsize)
1214b2364d9Smartin 		pm->dlsize = disklabel.d_secperunit;
12250dbef1aSdholland 
1234103857bSmartin 	return true;
12450dbef1aSdholland }
12550dbef1aSdholland 
12650dbef1aSdholland /*
12750dbef1aSdholland  * md back-end code for menu-driven BSD disklabel editor.
12850dbef1aSdholland  */
129957b5cd6Smartin int
md_make_bsd_partitions(struct install_partition_desc * install)1304103857bSmartin md_make_bsd_partitions(struct install_partition_desc *install)
13150dbef1aSdholland {
1324103857bSmartin 	return make_bsd_partitions(install);
13350dbef1aSdholland }
13450dbef1aSdholland 
13550dbef1aSdholland /*
13650dbef1aSdholland  * any additional partition validation
13750dbef1aSdholland  */
1384103857bSmartin bool
md_check_partitions(struct install_partition_desc * install)1394103857bSmartin md_check_partitions(struct install_partition_desc *install)
14050dbef1aSdholland {
1414103857bSmartin 	return true;
14250dbef1aSdholland }
14350dbef1aSdholland 
14450dbef1aSdholland /*
14550dbef1aSdholland  * hook called before writing new disklabel.
14650dbef1aSdholland  */
1474103857bSmartin bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1484103857bSmartin md_pre_disklabel(struct install_partition_desc *install,
1494103857bSmartin     struct disk_partitions *parts)
15050dbef1aSdholland {
1514103857bSmartin 	return true;
15250dbef1aSdholland }
15350dbef1aSdholland 
15450dbef1aSdholland /*
15550dbef1aSdholland  * hook called after writing disklabel to new target disk.
15650dbef1aSdholland  */
1574103857bSmartin bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1584103857bSmartin md_post_disklabel(struct install_partition_desc *install,
1594103857bSmartin     struct disk_partitions *parts)
16050dbef1aSdholland {
161a6c219b7Smartin 	struct utsname instsys;
162a6c219b7Smartin 	uname(&instsys);
163a6c219b7Smartin 
16427aaea9dSjmcneill 	if (strstr(instsys.version, "(INSTALL32_IP3x"))
16550dbef1aSdholland 		return run_program(RUN_DISPLAY,
16650dbef1aSdholland 		    "%s %s", "/usr/mdec/sgivol -f -w boot /usr/mdec/ip3xboot",
1674103857bSmartin 		    pm->diskdev) == 0;
16850dbef1aSdholland 
16927aaea9dSjmcneill 	if (strstr(instsys.version, "(INSTALL32_IP2x")) {
17050dbef1aSdholland 		run_program(RUN_DISPLAY,
17150dbef1aSdholland 		  "%s %s", "/usr/mdec/sgivol -f -w aoutboot /usr/mdec/aoutboot",
1724b2364d9Smartin 		  pm->diskdev);
17350dbef1aSdholland 		return run_program(RUN_DISPLAY,
17450dbef1aSdholland 		  "%s %s", "/usr/mdec/sgivol -f -w boot /usr/mdec/ip2xboot",
1754103857bSmartin 		  pm->diskdev) == 0;
17650dbef1aSdholland 	}
17750dbef1aSdholland 
17850dbef1aSdholland 	/* Presumably an IP12, we add the boot code later... */
1794103857bSmartin 	return true;
18050dbef1aSdholland }
18150dbef1aSdholland 
18250dbef1aSdholland /*
18350dbef1aSdholland  * hook called after upgrade() or install() has finished setting
18450dbef1aSdholland  * up the target disk but immediately before the user is given the
18550dbef1aSdholland  * ``disks are now set up'' message.
18650dbef1aSdholland  */
18750dbef1aSdholland int
md_post_newfs(struct install_partition_desc * install)1884103857bSmartin md_post_newfs(struct install_partition_desc *install)
18950dbef1aSdholland {
19050dbef1aSdholland 	return 0;
19150dbef1aSdholland }
19250dbef1aSdholland 
19350dbef1aSdholland int
md_post_extract(struct install_partition_desc * install,bool upgrade)194*4204f810Smartin md_post_extract(struct install_partition_desc *install, bool upgrade)
19550dbef1aSdholland {
19650dbef1aSdholland 	return 0;
19750dbef1aSdholland }
19850dbef1aSdholland 
19950dbef1aSdholland void
md_cleanup_install(struct install_partition_desc * install)2004103857bSmartin md_cleanup_install(struct install_partition_desc *install)
20150dbef1aSdholland {
202a6c219b7Smartin 	struct utsname instsys;
203a6c219b7Smartin 
20450dbef1aSdholland #ifndef DEBUG
20550dbef1aSdholland 	enable_rc_conf();
20650dbef1aSdholland #endif
207a6c219b7Smartin 	uname(&instsys);
20850dbef1aSdholland 
20927aaea9dSjmcneill 	if (strstr(instsys.version, "(GENERIC32_IP12"))
21050dbef1aSdholland 		run_program(0, "/usr/mdec/sgivol -f -w netbsd %s %s",
2114b2364d9Smartin 			    target_expand("/netbsd.ecoff"), pm->diskdev);
21250dbef1aSdholland }
21350dbef1aSdholland 
21450dbef1aSdholland int
md_pre_update(struct install_partition_desc * install)2154103857bSmartin md_pre_update(struct install_partition_desc *install)
21650dbef1aSdholland {
21750dbef1aSdholland 	return 1;
21850dbef1aSdholland }
21950dbef1aSdholland 
22050dbef1aSdholland /* Upgrade support */
22150dbef1aSdholland int
md_update(struct install_partition_desc * install)2224103857bSmartin md_update(struct install_partition_desc *install)
22350dbef1aSdholland {
2244103857bSmartin 	md_post_disklabel(install, pm->parts);
22550dbef1aSdholland 	return 1;
22650dbef1aSdholland }
22750dbef1aSdholland 
22850dbef1aSdholland int
md_pre_mount(struct install_partition_desc * install,size_t ndx)2294f30cbf3Smartin md_pre_mount(struct install_partition_desc *install, size_t ndx)
23050dbef1aSdholland {
23150dbef1aSdholland 	return 0;
23250dbef1aSdholland }
2334103857bSmartin 
2344103857bSmartin bool
md_parts_use_wholedisk(struct disk_partitions * parts)2354103857bSmartin md_parts_use_wholedisk(struct disk_partitions *parts)
2364103857bSmartin {
2374103857bSmartin 	return parts_use_wholedisk(parts, 0, NULL);
2384103857bSmartin }
2394103857bSmartin 
2404103857bSmartin #ifdef HAVE_GPT
2414103857bSmartin 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)2424103857bSmartin md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
2434103857bSmartin     bool root_is_new, part_id efi_id, bool efi_is_new)
2444103857bSmartin {
2454103857bSmartin 	/* no GPT boot support, nothing needs to be done here */
2464103857bSmartin 	return true;
2474103857bSmartin }
2484103857bSmartin #endif
2494103857bSmartin 
250