xref: /netbsd-src/usr.sbin/sysinst/arch/hp300/md.c (revision 4204f81037ec1430b81b70ee975f04b277901e24)
1*4204f810Smartin /*	$NetBSD: md.c,v 1.12 2022/01/29 16:01:18 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 -- Machine specific code for hp300 */
3650dbef1aSdholland /* This file is in close sync with pmax, sparc, vax and x68k md.c */
3750dbef1aSdholland 
3850dbef1aSdholland #include <stdio.h>
3950dbef1aSdholland #include <unistd.h>
4050dbef1aSdholland #include <sys/ioctl.h>
4150dbef1aSdholland #include <sys/param.h>
4250dbef1aSdholland #include <util.h>
4350dbef1aSdholland 
4450dbef1aSdholland #include "defs.h"
4550dbef1aSdholland #include "md.h"
4650dbef1aSdholland #include "msg_defs.h"
4750dbef1aSdholland #include "menu_defs.h"
4850dbef1aSdholland 
4950dbef1aSdholland void
md_init(void)5050dbef1aSdholland md_init(void)
5150dbef1aSdholland {
5250dbef1aSdholland }
5350dbef1aSdholland 
5450dbef1aSdholland void
md_init_set_status(int flags)5550dbef1aSdholland md_init_set_status(int flags)
5650dbef1aSdholland {
5750dbef1aSdholland 	(void)flags;
5850dbef1aSdholland }
5950dbef1aSdholland 
604103857bSmartin bool
md_get_info(struct install_partition_desc * install)614103857bSmartin md_get_info(struct install_partition_desc *install)
6250dbef1aSdholland {
6350dbef1aSdholland 	char buf[1024];
6450dbef1aSdholland 	int fd;
6550dbef1aSdholland 	char dev_name[100];
6650dbef1aSdholland 	struct disklabel disklabel;
6750dbef1aSdholland 
684b2364d9Smartin 	snprintf(dev_name, sizeof(dev_name), "/dev/r%sc", pm->diskdev);
6950dbef1aSdholland 
7050dbef1aSdholland 	fd = open(dev_name, O_RDONLY, 0);
7150dbef1aSdholland 	if (fd < 0) {
7250dbef1aSdholland 		if (logfp)
7350dbef1aSdholland 			(void)fprintf(logfp, "Can't open %s\n", dev_name);
7450dbef1aSdholland 		endwin();
7550dbef1aSdholland 		fprintf(stderr, "Can't open %s\n", dev_name);
7650dbef1aSdholland 		exit(1);
7750dbef1aSdholland 	}
7850dbef1aSdholland 	if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
7950dbef1aSdholland 		if (logfp)
8050dbef1aSdholland 			(void)fprintf(logfp, "Can't read disklabel on %s.\n",
8150dbef1aSdholland 				dev_name);
8250dbef1aSdholland 		endwin();
8350dbef1aSdholland 		fprintf(stderr, "Can't read disklabel on %s.\n", dev_name);
8450dbef1aSdholland 		close(fd);
8550dbef1aSdholland 		exit(1);
8650dbef1aSdholland 	}
8750dbef1aSdholland 	if (disklabel.d_secsize != 512) {
8850dbef1aSdholland 		endwin();
8950dbef1aSdholland 		fprintf(stderr, "Non-512byte/sector disk is not supported.\n");
9050dbef1aSdholland 		close(fd);
9150dbef1aSdholland 		exit(1);
9250dbef1aSdholland 	}
9350dbef1aSdholland 
944b2364d9Smartin 	pm->dlcyl = disklabel.d_ncylinders;
954b2364d9Smartin 	pm->dlhead = disklabel.d_ntracks;
964b2364d9Smartin 	pm->dlsec = disklabel.d_nsectors;
974b2364d9Smartin 	pm->sectorsize = disklabel.d_secsize;
984b2364d9Smartin 	pm->dlcylsize = disklabel.d_secpercyl;
994b2364d9Smartin 	pm->dlsize = pm->dlcyl*pm->dlhead*pm->dlsec;
10050dbef1aSdholland 
10150dbef1aSdholland 	if (read(fd, buf, 1024) < 0) {
10250dbef1aSdholland 		endwin();
10350dbef1aSdholland 		fprintf(stderr, "Can't read %s\n", dev_name);
10450dbef1aSdholland 		close(fd);
10550dbef1aSdholland 		exit(1);
10650dbef1aSdholland 	}
10750dbef1aSdholland 
10850dbef1aSdholland 	/* We will preserve the first cylinder as PART_BOOT for bootloader. */
1094b2364d9Smartin 	pm->ptstart = 0;
11050dbef1aSdholland 
11150dbef1aSdholland 	close(fd);
11250dbef1aSdholland 
1134103857bSmartin 	return true;
11450dbef1aSdholland }
11550dbef1aSdholland 
11650dbef1aSdholland /*
11750dbef1aSdholland  * md back-end code for menu-driven BSD disklabel editor.
11850dbef1aSdholland  */
119957b5cd6Smartin int
md_make_bsd_partitions(struct install_partition_desc * install)1204103857bSmartin md_make_bsd_partitions(struct install_partition_desc *install)
12150dbef1aSdholland {
12250dbef1aSdholland 
1234103857bSmartin 	return make_bsd_partitions(install);
12450dbef1aSdholland }
12550dbef1aSdholland 
12650dbef1aSdholland /*
12750dbef1aSdholland  * any additional partition validation
12850dbef1aSdholland  */
1294103857bSmartin bool
md_check_partitions(struct install_partition_desc * install)1304103857bSmartin md_check_partitions(struct install_partition_desc *install)
13150dbef1aSdholland {
13250dbef1aSdholland 	/* hp300 partitions must be in order of the range. */
1334103857bSmartin 	daddr_t last_end = 0;
1344103857bSmartin 	size_t i;
1354103857bSmartin 	char desc[STRSIZE];
13650dbef1aSdholland 
1374103857bSmartin 	for (i = 0; i < install->num; i++) {
1384103857bSmartin 		if (i > 0) {
139bef52f43Smartin 			/* skip raw part and similar */
140bef52f43Smartin 			if (install->infos[i].cur_flags &
141bef52f43Smartin 			    (PTI_SEC_CONTAINER|PTI_PSCHEME_INTERNAL|
142bef52f43Smartin 			    PTI_RAW_PART))
143bef52f43Smartin 				continue;
144bef52f43Smartin 
1454103857bSmartin 			if (install->infos[i].cur_start < last_end) {
1464103857bSmartin 				snprintf(desc, sizeof desc,
1474103857bSmartin 				    "%zu (%s)", i,
1484103857bSmartin 				    install->infos[i].mount);
14924ecf24eSchristos 				msg_fmt_display(MSG_ordering, "%s", desc);
150e21052b4Smartin 				if (ask_yesno(NULL))
1514103857bSmartin 					return false;
15250dbef1aSdholland 			}
15350dbef1aSdholland 		}
1544103857bSmartin 		last_end = install->infos[i].cur_start + install->infos[i].size;
15550dbef1aSdholland 	}
15650dbef1aSdholland 
1574103857bSmartin 	return true;
15850dbef1aSdholland }
15950dbef1aSdholland 
16050dbef1aSdholland /*
16150dbef1aSdholland  * hook called before writing new disklabel.
16250dbef1aSdholland  */
1634103857bSmartin bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1644103857bSmartin md_pre_disklabel(struct install_partition_desc *install,
1654103857bSmartin     struct disk_partitions *parts)
16650dbef1aSdholland {
1674103857bSmartin 	return true;
16850dbef1aSdholland }
16950dbef1aSdholland 
17050dbef1aSdholland /*
17150dbef1aSdholland  * hook called after writing disklabel to new target disk.
17250dbef1aSdholland  */
1734103857bSmartin bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1744103857bSmartin md_post_disklabel(struct install_partition_desc *install,
1754103857bSmartin     struct disk_partitions *parts)
17650dbef1aSdholland {
1774103857bSmartin 	return true;
17850dbef1aSdholland }
17950dbef1aSdholland 
18050dbef1aSdholland /*
18150dbef1aSdholland  * hook called after upgrade() or install() has finished setting
18250dbef1aSdholland  * up the target disk but immediately before the user is given the
18350dbef1aSdholland  * ``disks are now set up'' message.
18450dbef1aSdholland  *
18550dbef1aSdholland  * On hp300, we use this opportunity to install the boot blocks.
18650dbef1aSdholland  */
18750dbef1aSdholland int
md_post_newfs(struct install_partition_desc * install)1884103857bSmartin md_post_newfs(struct install_partition_desc *install)
18950dbef1aSdholland {
19050dbef1aSdholland 	/* boot blocks ... */
19124ecf24eSchristos 	msg_fmt_display(MSG_dobootblks, "%s", pm->diskdev);
19250dbef1aSdholland 	if (run_program(RUN_DISPLAY | RUN_NO_CLEAR,
1934b2364d9Smartin 	    "/usr/sbin/installboot /dev/r%sc /usr/mdec/uboot.lif", pm->diskdev))
19450dbef1aSdholland 		process_menu(MENU_ok,
195b77ea2f7Sjoerg 		    __UNCONST("Warning: disk is probably not bootable"));
19642fb6d79Smartin 
19742fb6d79Smartin 	wclear(stdscr);
19842fb6d79Smartin 	touchwin(stdscr);
19942fb6d79Smartin 	clearok(stdscr, 1);
20042fb6d79Smartin 	refresh();
20142fb6d79Smartin 
20250dbef1aSdholland 	return 0;
20350dbef1aSdholland }
20450dbef1aSdholland 
20550dbef1aSdholland int
md_post_extract(struct install_partition_desc * install,bool upgrade)206*4204f810Smartin md_post_extract(struct install_partition_desc *install, bool upgrade)
20750dbef1aSdholland {
20850dbef1aSdholland 	return 0;
20950dbef1aSdholland }
21050dbef1aSdholland 
21150dbef1aSdholland void
md_cleanup_install(struct install_partition_desc * install)2124103857bSmartin md_cleanup_install(struct install_partition_desc *install)
21350dbef1aSdholland {
21450dbef1aSdholland #ifdef notyet			/* sed is too large for ramdisk */
21550dbef1aSdholland 	enable_rc_conf();
21650dbef1aSdholland #endif
21750dbef1aSdholland }
21850dbef1aSdholland 
21950dbef1aSdholland int
md_pre_update(struct install_partition_desc * install)2204103857bSmartin md_pre_update(struct install_partition_desc *install)
22150dbef1aSdholland {
22250dbef1aSdholland 	return 1;
22350dbef1aSdholland }
22450dbef1aSdholland 
22550dbef1aSdholland /* Upgrade support */
22650dbef1aSdholland int
md_update(struct install_partition_desc * install)2274103857bSmartin md_update(struct install_partition_desc *install)
22850dbef1aSdholland {
2294103857bSmartin 	md_post_newfs(install);
23050dbef1aSdholland 	return 1;
23150dbef1aSdholland }
23250dbef1aSdholland 
23350dbef1aSdholland /*
23450dbef1aSdholland  * Used in bsddisklabel.c as BOOT_SIZE
23550dbef1aSdholland  */
23650dbef1aSdholland int
hp300_boot_size(void)23750dbef1aSdholland hp300_boot_size(void)
23850dbef1aSdholland {
23950dbef1aSdholland 	int i;
24050dbef1aSdholland 
2414b2364d9Smartin 	i = pm->dlcylsize;
24250dbef1aSdholland 	if (i >= 1024) /* XXX: bsddisklabel.c has a hack. */
2434b2364d9Smartin 		i = pm->dlcylsize * pm->sectorsize * 2;
24450dbef1aSdholland 
24550dbef1aSdholland 	return i;
24650dbef1aSdholland }
24750dbef1aSdholland 
24850dbef1aSdholland int
md_pre_mount(struct install_partition_desc * install,size_t ndx)2494f30cbf3Smartin md_pre_mount(struct install_partition_desc *install, size_t ndx)
25050dbef1aSdholland {
25150dbef1aSdholland 	return 0;
25250dbef1aSdholland }
2534103857bSmartin 
2544103857bSmartin #ifdef HAVE_GPT
2554103857bSmartin 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)2564103857bSmartin md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
2574103857bSmartin     bool root_is_new, part_id efi_id, bool efi_is_new)
2584103857bSmartin {
2594103857bSmartin 	/* no GPT boot support, nothing needs to be done here */
2604103857bSmartin 	return true;
2614103857bSmartin }
2624103857bSmartin #endif
2634103857bSmartin 
2644103857bSmartin bool
md_parts_use_wholedisk(struct disk_partitions * parts)2654103857bSmartin md_parts_use_wholedisk(struct disk_partitions *parts)
2664103857bSmartin {
2674103857bSmartin 	return parts_use_wholedisk(parts, 0, NULL);
2684103857bSmartin }
2694103857bSmartin 
270