xref: /netbsd/usr.sbin/sysinst/arch/atari/md.c (revision 5960e8ba)
1*5960e8baSmartin /*	$NetBSD: md.c,v 1.10 2022/12/09 17:02:13 martin Exp $ */
226165e63Sdholland 
326165e63Sdholland /*
426165e63Sdholland  * Copyright 1997 Piermont Information Systems Inc.
526165e63Sdholland  * All rights reserved.
626165e63Sdholland  *
726165e63Sdholland  * Based on code written by Philip A. Nelson for Piermont Information
826165e63Sdholland  * Systems Inc.
926165e63Sdholland  *
1026165e63Sdholland  * Redistribution and use in source and binary forms, with or without
1126165e63Sdholland  * modification, are permitted provided that the following conditions
1226165e63Sdholland  * are met:
1326165e63Sdholland  * 1. Redistributions of source code must retain the above copyright
1426165e63Sdholland  *    notice, this list of conditions and the following disclaimer.
1526165e63Sdholland  * 2. Redistributions in binary form must reproduce the above copyright
1626165e63Sdholland  *    notice, this list of conditions and the following disclaimer in the
1726165e63Sdholland  *    documentation and/or other materials provided with the distribution.
1826165e63Sdholland  * 3. The name of Piermont Information Systems Inc. may not be used to endorse
1926165e63Sdholland  *    or promote products derived from this software without specific prior
2026165e63Sdholland  *    written permission.
2126165e63Sdholland  *
2226165e63Sdholland  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
2326165e63Sdholland  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2426165e63Sdholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2526165e63Sdholland  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
2626165e63Sdholland  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2726165e63Sdholland  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2826165e63Sdholland  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2926165e63Sdholland  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3026165e63Sdholland  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3126165e63Sdholland  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3226165e63Sdholland  * THE POSSIBILITY OF SUCH DAMAGE.
3326165e63Sdholland  */
3426165e63Sdholland 
3526165e63Sdholland /* md.c -- atari machine specific routines */
3626165e63Sdholland 
3726165e63Sdholland #include <stdio.h>
3826165e63Sdholland #include <stdlib.h>
3926165e63Sdholland #include <string.h>
4026165e63Sdholland #include <sys/param.h>
4126165e63Sdholland #include <sys/sysctl.h>
421afcecc5Stsutsui #include <sys/utsname.h>
4326165e63Sdholland 
4426165e63Sdholland #include "defs.h"
4526165e63Sdholland #include "md.h"
4626165e63Sdholland #include "msg_defs.h"
4726165e63Sdholland #include "menu_defs.h"
4826165e63Sdholland 
4926165e63Sdholland void
md_init(void)5026165e63Sdholland md_init(void)
5126165e63Sdholland {
5226165e63Sdholland }
5326165e63Sdholland 
5426165e63Sdholland void
md_init_set_status(int flags)5526165e63Sdholland md_init_set_status(int flags)
5626165e63Sdholland {
571afcecc5Stsutsui 	struct utsname instsys;
581afcecc5Stsutsui 
5926165e63Sdholland 	(void)flags;
601afcecc5Stsutsui 
611afcecc5Stsutsui 	/*
621afcecc5Stsutsui 	 * Get the name of the kernel we are running under and
631afcecc5Stsutsui 	 * enable the installation of the corresponding GENERIC-like kernel.
641afcecc5Stsutsui 	 */
651afcecc5Stsutsui 	uname(&instsys);
661afcecc5Stsutsui 	if (strstr(instsys.version, "(ATARITT"))
671afcecc5Stsutsui 		set_kernel_set(SET_KERNEL_1);
681afcecc5Stsutsui 	else if (strstr(instsys.version, "(FALCON"))
691afcecc5Stsutsui 		set_kernel_set(SET_KERNEL_2);
701afcecc5Stsutsui 	else if (strstr(instsys.version, "(SMALL030"))
711afcecc5Stsutsui 		set_kernel_set(SET_KERNEL_3);
721afcecc5Stsutsui 	else if (strstr(instsys.version, "(HADES"))
731afcecc5Stsutsui 		set_kernel_set(SET_KERNEL_4);
741afcecc5Stsutsui 	else if (strstr(instsys.version, "(MILAN-ISAIDE"))
751afcecc5Stsutsui 		set_kernel_set(SET_KERNEL_5);
761afcecc5Stsutsui 	else if (strstr(instsys.version, "(MILAN_PCIIDE"))
771afcecc5Stsutsui 		set_kernel_set(SET_KERNEL_6);
7826165e63Sdholland }
7926165e63Sdholland 
80dcc57e24Smartin bool
md_get_info(struct install_partition_desc * install)81dcc57e24Smartin md_get_info(struct install_partition_desc *install)
8226165e63Sdholland {
83*5960e8baSmartin 	set_default_sizemult(pm->diskdev, MEG, pm->sectorsize);
84dcc57e24Smartin 	return true;
8526165e63Sdholland }
8626165e63Sdholland 
8726165e63Sdholland /*
8826165e63Sdholland  * md back-end code for menu-driven BSD disklabel editor.
8926165e63Sdholland  */
9080bf2417Smartin int
md_make_bsd_partitions(struct install_partition_desc * install)91dcc57e24Smartin md_make_bsd_partitions(struct install_partition_desc *install)
9226165e63Sdholland {
93f9805030Schristos 	msg_fmt_display(MSG_infoahdilabel, "%s", pm->diskdev);
9486ffd738Smartin 	if (ask_noyes(NULL)) {
95da5a563bSmartin 		run_program(RUN_DISPLAY, "ahdilabel /dev/r%sc", pm->diskdev);
9626165e63Sdholland 	}
97dcc57e24Smartin 	return make_bsd_partitions(install);
9826165e63Sdholland }
9926165e63Sdholland 
10026165e63Sdholland /*
10126165e63Sdholland  * any additional partition validation
10226165e63Sdholland  */
103dcc57e24Smartin bool
md_check_partitions(struct install_partition_desc * install)104dcc57e24Smartin md_check_partitions(struct install_partition_desc *install)
10526165e63Sdholland {
106dcc57e24Smartin 	return true;
10726165e63Sdholland }
10826165e63Sdholland 
10926165e63Sdholland /*
11026165e63Sdholland  * hook called before writing new disklabel.
11126165e63Sdholland  */
112dcc57e24Smartin bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)113dcc57e24Smartin md_pre_disklabel(struct install_partition_desc *install,
114dcc57e24Smartin     struct disk_partitions *parts)
11526165e63Sdholland {
116dcc57e24Smartin 	return true;
11726165e63Sdholland }
11826165e63Sdholland 
11926165e63Sdholland /*
12026165e63Sdholland  * hook called after writing disklabel to new target disk.
12126165e63Sdholland  */
122dcc57e24Smartin bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)123dcc57e24Smartin md_post_disklabel(struct install_partition_desc *install,
124dcc57e24Smartin     struct disk_partitions *parts)
12526165e63Sdholland {
126dcc57e24Smartin 	return true;
12726165e63Sdholland }
12826165e63Sdholland 
12926165e63Sdholland /*
13026165e63Sdholland  * hook called after upgrade() or install() has finished setting
13126165e63Sdholland  * up the target disk but immediately before the user is given the
13226165e63Sdholland  * ``disks are now set up'' message.
13326165e63Sdholland  */
13426165e63Sdholland int
md_post_newfs(struct install_partition_desc * install)135dcc57e24Smartin md_post_newfs(struct install_partition_desc *install)
13626165e63Sdholland {
13726165e63Sdholland 	static const int mib[2] = {CTL_HW, HW_MODEL};
13826165e63Sdholland 	size_t len;
13926165e63Sdholland 	char *cpu_model;
14026165e63Sdholland 	int milan;
14126165e63Sdholland 	char bootpath[MAXPATHLEN];
14226165e63Sdholland 	int rv;
14326165e63Sdholland 
14426165e63Sdholland 	/* check machine type via sysctl to select appropriate bootloaders */
14526165e63Sdholland 	milan = 0;	/* std is default */
14626165e63Sdholland 	sysctl(mib, 2, NULL, &len, NULL, 0);
14726165e63Sdholland 	cpu_model = malloc(len);
14826165e63Sdholland 	sysctl(mib, 2, cpu_model, &len, NULL, 0);
14926165e63Sdholland 	/* XXX model strings should be a common macro to sync with kernel */
15026165e63Sdholland 	if (strstr(cpu_model, "Milan") != NULL)
15126165e63Sdholland 		milan = 1;
15226165e63Sdholland 	free(cpu_model);
15326165e63Sdholland 
15426165e63Sdholland 	/* copy tertiary boot and install boot blocks */
155f9805030Schristos 	msg_fmt_display(MSG_dobootblks, "%s", pm->diskdev);
15626165e63Sdholland 	snprintf(bootpath, sizeof(bootpath), "/usr/mdec/%s/boot.atari",
15726165e63Sdholland 	    milan ? "milan" : "std");
15826165e63Sdholland 	rv = cp_to_target(bootpath, "/");
15926165e63Sdholland 	if (rv != 0)
16026165e63Sdholland 		return rv;
16126165e63Sdholland 
16226165e63Sdholland 	rv = run_program(RUN_DISPLAY, "/usr/mdec/installboot -v%s /dev/r%sc",
163da5a563bSmartin 	    milan ? "m" : "", pm->diskdev);
16426165e63Sdholland 
16526165e63Sdholland 	return rv;
16626165e63Sdholland }
16726165e63Sdholland 
16826165e63Sdholland int
md_post_extract(struct install_partition_desc * install,bool upgrade)169b8b586ecSmartin md_post_extract(struct install_partition_desc *install, bool upgrade)
17026165e63Sdholland {
17126165e63Sdholland 	return 0;
17226165e63Sdholland }
17326165e63Sdholland 
17426165e63Sdholland void
md_cleanup_install(struct install_partition_desc * install)175dcc57e24Smartin md_cleanup_install(struct install_partition_desc *install)
17626165e63Sdholland {
17726165e63Sdholland #ifndef DEBUG
17826165e63Sdholland 	enable_rc_conf();
17926165e63Sdholland #endif
18026165e63Sdholland }
18126165e63Sdholland 
18226165e63Sdholland int
md_pre_update(struct install_partition_desc * install)183dcc57e24Smartin md_pre_update(struct install_partition_desc *install)
18426165e63Sdholland {
18526165e63Sdholland 	return 1;
18626165e63Sdholland }
18726165e63Sdholland 
18826165e63Sdholland /* Upgrade support */
18926165e63Sdholland int
md_update(struct install_partition_desc * install)190dcc57e24Smartin md_update(struct install_partition_desc *install)
19126165e63Sdholland {
192dcc57e24Smartin 	md_post_newfs(install);
19326165e63Sdholland 	return 1;
19426165e63Sdholland }
19526165e63Sdholland 
19626165e63Sdholland int
md_pre_mount(struct install_partition_desc * install,size_t ndx)197d5a9dfe9Smartin md_pre_mount(struct install_partition_desc *install, size_t ndx)
19826165e63Sdholland {
19926165e63Sdholland 	return 0;
20026165e63Sdholland }
201dcc57e24Smartin 
202dcc57e24Smartin bool
md_parts_use_wholedisk(struct disk_partitions * parts)203dcc57e24Smartin md_parts_use_wholedisk(struct disk_partitions *parts)
204dcc57e24Smartin {
205dcc57e24Smartin 	return parts_use_wholedisk(parts, 0, NULL);
206dcc57e24Smartin }
207dcc57e24Smartin 
208dcc57e24Smartin #ifdef HAVE_GPT
209dcc57e24Smartin 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)210dcc57e24Smartin md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
211dcc57e24Smartin     bool root_is_new, part_id efi_id, bool efi_is_new)
212dcc57e24Smartin {
213dcc57e24Smartin 	/* no GPT boot support, no special checks needed */
214dcc57e24Smartin 	return true;
215dcc57e24Smartin }
216dcc57e24Smartin #endif
217dcc57e24Smartin 
218