1*96fc6d0aStsutsui /* $NetBSD: md.c,v 1.11 2024/01/04 18:09:37 tsutsui 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 -- atari machine specific routines */
3650dbef1aSdholland
3750dbef1aSdholland #include <stdio.h>
3850dbef1aSdholland #include <stdlib.h>
3950dbef1aSdholland #include <string.h>
4050dbef1aSdholland #include <sys/param.h>
4150dbef1aSdholland #include <sys/sysctl.h>
42f7ce29baStsutsui #include <sys/utsname.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 {
57f7ce29baStsutsui struct utsname instsys;
58f7ce29baStsutsui
5950dbef1aSdholland (void)flags;
60f7ce29baStsutsui
61f7ce29baStsutsui /*
62f7ce29baStsutsui * Get the name of the kernel we are running under and
63f7ce29baStsutsui * enable the installation of the corresponding GENERIC-like kernel.
64f7ce29baStsutsui */
65f7ce29baStsutsui uname(&instsys);
66f7ce29baStsutsui if (strstr(instsys.version, "(ATARITT"))
67f7ce29baStsutsui set_kernel_set(SET_KERNEL_1);
68f7ce29baStsutsui else if (strstr(instsys.version, "(FALCON"))
69f7ce29baStsutsui set_kernel_set(SET_KERNEL_2);
70f7ce29baStsutsui else if (strstr(instsys.version, "(SMALL030"))
71f7ce29baStsutsui set_kernel_set(SET_KERNEL_3);
72f7ce29baStsutsui else if (strstr(instsys.version, "(HADES"))
73f7ce29baStsutsui set_kernel_set(SET_KERNEL_4);
74f7ce29baStsutsui else if (strstr(instsys.version, "(MILAN-ISAIDE"))
75f7ce29baStsutsui set_kernel_set(SET_KERNEL_5);
76*96fc6d0aStsutsui else if (strstr(instsys.version, "(MILAN-PCIIDE"))
77f7ce29baStsutsui set_kernel_set(SET_KERNEL_6);
7850dbef1aSdholland }
7950dbef1aSdholland
804103857bSmartin bool
md_get_info(struct install_partition_desc * install)814103857bSmartin md_get_info(struct install_partition_desc *install)
8250dbef1aSdholland {
8399162e57Smartin set_default_sizemult(pm->diskdev, MEG, pm->sectorsize);
844103857bSmartin return true;
8550dbef1aSdholland }
8650dbef1aSdholland
8750dbef1aSdholland /*
8850dbef1aSdholland * md back-end code for menu-driven BSD disklabel editor.
8950dbef1aSdholland */
90957b5cd6Smartin int
md_make_bsd_partitions(struct install_partition_desc * install)914103857bSmartin md_make_bsd_partitions(struct install_partition_desc *install)
9250dbef1aSdholland {
9324ecf24eSchristos msg_fmt_display(MSG_infoahdilabel, "%s", pm->diskdev);
94e21052b4Smartin if (ask_noyes(NULL)) {
954b2364d9Smartin run_program(RUN_DISPLAY, "ahdilabel /dev/r%sc", pm->diskdev);
9650dbef1aSdholland }
974103857bSmartin return make_bsd_partitions(install);
9850dbef1aSdholland }
9950dbef1aSdholland
10050dbef1aSdholland /*
10150dbef1aSdholland * any additional partition validation
10250dbef1aSdholland */
1034103857bSmartin bool
md_check_partitions(struct install_partition_desc * install)1044103857bSmartin md_check_partitions(struct install_partition_desc *install)
10550dbef1aSdholland {
1064103857bSmartin return true;
10750dbef1aSdholland }
10850dbef1aSdholland
10950dbef1aSdholland /*
11050dbef1aSdholland * hook called before writing new disklabel.
11150dbef1aSdholland */
1124103857bSmartin bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1134103857bSmartin md_pre_disklabel(struct install_partition_desc *install,
1144103857bSmartin struct disk_partitions *parts)
11550dbef1aSdholland {
1164103857bSmartin return true;
11750dbef1aSdholland }
11850dbef1aSdholland
11950dbef1aSdholland /*
12050dbef1aSdholland * hook called after writing disklabel to new target disk.
12150dbef1aSdholland */
1224103857bSmartin bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1234103857bSmartin md_post_disklabel(struct install_partition_desc *install,
1244103857bSmartin struct disk_partitions *parts)
12550dbef1aSdholland {
1264103857bSmartin return true;
12750dbef1aSdholland }
12850dbef1aSdholland
12950dbef1aSdholland /*
13050dbef1aSdholland * hook called after upgrade() or install() has finished setting
13150dbef1aSdholland * up the target disk but immediately before the user is given the
13250dbef1aSdholland * ``disks are now set up'' message.
13350dbef1aSdholland */
13450dbef1aSdholland int
md_post_newfs(struct install_partition_desc * install)1354103857bSmartin md_post_newfs(struct install_partition_desc *install)
13650dbef1aSdholland {
13750dbef1aSdholland static const int mib[2] = {CTL_HW, HW_MODEL};
13850dbef1aSdholland size_t len;
13950dbef1aSdholland char *cpu_model;
14050dbef1aSdholland int milan;
14150dbef1aSdholland char bootpath[MAXPATHLEN];
14250dbef1aSdholland int rv;
14350dbef1aSdholland
14450dbef1aSdholland /* check machine type via sysctl to select appropriate bootloaders */
14550dbef1aSdholland milan = 0; /* std is default */
14650dbef1aSdholland sysctl(mib, 2, NULL, &len, NULL, 0);
14750dbef1aSdholland cpu_model = malloc(len);
14850dbef1aSdholland sysctl(mib, 2, cpu_model, &len, NULL, 0);
14950dbef1aSdholland /* XXX model strings should be a common macro to sync with kernel */
15050dbef1aSdholland if (strstr(cpu_model, "Milan") != NULL)
15150dbef1aSdholland milan = 1;
15250dbef1aSdholland free(cpu_model);
15350dbef1aSdholland
15450dbef1aSdholland /* copy tertiary boot and install boot blocks */
15524ecf24eSchristos msg_fmt_display(MSG_dobootblks, "%s", pm->diskdev);
15650dbef1aSdholland snprintf(bootpath, sizeof(bootpath), "/usr/mdec/%s/boot.atari",
15750dbef1aSdholland milan ? "milan" : "std");
15850dbef1aSdholland rv = cp_to_target(bootpath, "/");
15950dbef1aSdholland if (rv != 0)
16050dbef1aSdholland return rv;
16150dbef1aSdholland
16250dbef1aSdholland rv = run_program(RUN_DISPLAY, "/usr/mdec/installboot -v%s /dev/r%sc",
1634b2364d9Smartin milan ? "m" : "", pm->diskdev);
16450dbef1aSdholland
16550dbef1aSdholland return rv;
16650dbef1aSdholland }
16750dbef1aSdholland
16850dbef1aSdholland int
md_post_extract(struct install_partition_desc * install,bool upgrade)1694204f810Smartin md_post_extract(struct install_partition_desc *install, bool upgrade)
17050dbef1aSdholland {
17150dbef1aSdholland return 0;
17250dbef1aSdholland }
17350dbef1aSdholland
17450dbef1aSdholland void
md_cleanup_install(struct install_partition_desc * install)1754103857bSmartin md_cleanup_install(struct install_partition_desc *install)
17650dbef1aSdholland {
17750dbef1aSdholland #ifndef DEBUG
17850dbef1aSdholland enable_rc_conf();
17950dbef1aSdholland #endif
18050dbef1aSdholland }
18150dbef1aSdholland
18250dbef1aSdholland int
md_pre_update(struct install_partition_desc * install)1834103857bSmartin md_pre_update(struct install_partition_desc *install)
18450dbef1aSdholland {
18550dbef1aSdholland return 1;
18650dbef1aSdholland }
18750dbef1aSdholland
18850dbef1aSdholland /* Upgrade support */
18950dbef1aSdholland int
md_update(struct install_partition_desc * install)1904103857bSmartin md_update(struct install_partition_desc *install)
19150dbef1aSdholland {
1924103857bSmartin md_post_newfs(install);
19350dbef1aSdholland return 1;
19450dbef1aSdholland }
19550dbef1aSdholland
19650dbef1aSdholland int
md_pre_mount(struct install_partition_desc * install,size_t ndx)1974f30cbf3Smartin md_pre_mount(struct install_partition_desc *install, size_t ndx)
19850dbef1aSdholland {
19950dbef1aSdholland return 0;
20050dbef1aSdholland }
2014103857bSmartin
2024103857bSmartin bool
md_parts_use_wholedisk(struct disk_partitions * parts)2034103857bSmartin md_parts_use_wholedisk(struct disk_partitions *parts)
2044103857bSmartin {
2054103857bSmartin return parts_use_wholedisk(parts, 0, NULL);
2064103857bSmartin }
2074103857bSmartin
2084103857bSmartin #ifdef HAVE_GPT
2094103857bSmartin 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)2104103857bSmartin md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
2114103857bSmartin bool root_is_new, part_id efi_id, bool efi_is_new)
2124103857bSmartin {
2134103857bSmartin /* no GPT boot support, no special checks needed */
2144103857bSmartin return true;
2154103857bSmartin }
2164103857bSmartin #endif
2174103857bSmartin
218