1 /* $NetBSD: md.c,v 1.11 2024/01/04 18:09:37 tsutsui Exp $ */
2
3 /*
4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved.
6 *
7 * Based on code written by Philip A. Nelson for Piermont Information
8 * Systems Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of Piermont Information Systems Inc. may not be used to endorse
19 * or promote products derived from this software without specific prior
20 * written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 /* md.c -- atari machine specific routines */
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <sys/param.h>
41 #include <sys/sysctl.h>
42 #include <sys/utsname.h>
43
44 #include "defs.h"
45 #include "md.h"
46 #include "msg_defs.h"
47 #include "menu_defs.h"
48
49 void
md_init(void)50 md_init(void)
51 {
52 }
53
54 void
md_init_set_status(int flags)55 md_init_set_status(int flags)
56 {
57 struct utsname instsys;
58
59 (void)flags;
60
61 /*
62 * Get the name of the kernel we are running under and
63 * enable the installation of the corresponding GENERIC-like kernel.
64 */
65 uname(&instsys);
66 if (strstr(instsys.version, "(ATARITT"))
67 set_kernel_set(SET_KERNEL_1);
68 else if (strstr(instsys.version, "(FALCON"))
69 set_kernel_set(SET_KERNEL_2);
70 else if (strstr(instsys.version, "(SMALL030"))
71 set_kernel_set(SET_KERNEL_3);
72 else if (strstr(instsys.version, "(HADES"))
73 set_kernel_set(SET_KERNEL_4);
74 else if (strstr(instsys.version, "(MILAN-ISAIDE"))
75 set_kernel_set(SET_KERNEL_5);
76 else if (strstr(instsys.version, "(MILAN-PCIIDE"))
77 set_kernel_set(SET_KERNEL_6);
78 }
79
80 bool
md_get_info(struct install_partition_desc * install)81 md_get_info(struct install_partition_desc *install)
82 {
83 set_default_sizemult(pm->diskdev, MEG, pm->sectorsize);
84 return true;
85 }
86
87 /*
88 * md back-end code for menu-driven BSD disklabel editor.
89 */
90 int
md_make_bsd_partitions(struct install_partition_desc * install)91 md_make_bsd_partitions(struct install_partition_desc *install)
92 {
93 msg_fmt_display(MSG_infoahdilabel, "%s", pm->diskdev);
94 if (ask_noyes(NULL)) {
95 run_program(RUN_DISPLAY, "ahdilabel /dev/r%sc", pm->diskdev);
96 }
97 return make_bsd_partitions(install);
98 }
99
100 /*
101 * any additional partition validation
102 */
103 bool
md_check_partitions(struct install_partition_desc * install)104 md_check_partitions(struct install_partition_desc *install)
105 {
106 return true;
107 }
108
109 /*
110 * hook called before writing new disklabel.
111 */
112 bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)113 md_pre_disklabel(struct install_partition_desc *install,
114 struct disk_partitions *parts)
115 {
116 return true;
117 }
118
119 /*
120 * hook called after writing disklabel to new target disk.
121 */
122 bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)123 md_post_disklabel(struct install_partition_desc *install,
124 struct disk_partitions *parts)
125 {
126 return true;
127 }
128
129 /*
130 * hook called after upgrade() or install() has finished setting
131 * up the target disk but immediately before the user is given the
132 * ``disks are now set up'' message.
133 */
134 int
md_post_newfs(struct install_partition_desc * install)135 md_post_newfs(struct install_partition_desc *install)
136 {
137 static const int mib[2] = {CTL_HW, HW_MODEL};
138 size_t len;
139 char *cpu_model;
140 int milan;
141 char bootpath[MAXPATHLEN];
142 int rv;
143
144 /* check machine type via sysctl to select appropriate bootloaders */
145 milan = 0; /* std is default */
146 sysctl(mib, 2, NULL, &len, NULL, 0);
147 cpu_model = malloc(len);
148 sysctl(mib, 2, cpu_model, &len, NULL, 0);
149 /* XXX model strings should be a common macro to sync with kernel */
150 if (strstr(cpu_model, "Milan") != NULL)
151 milan = 1;
152 free(cpu_model);
153
154 /* copy tertiary boot and install boot blocks */
155 msg_fmt_display(MSG_dobootblks, "%s", pm->diskdev);
156 snprintf(bootpath, sizeof(bootpath), "/usr/mdec/%s/boot.atari",
157 milan ? "milan" : "std");
158 rv = cp_to_target(bootpath, "/");
159 if (rv != 0)
160 return rv;
161
162 rv = run_program(RUN_DISPLAY, "/usr/mdec/installboot -v%s /dev/r%sc",
163 milan ? "m" : "", pm->diskdev);
164
165 return rv;
166 }
167
168 int
md_post_extract(struct install_partition_desc * install,bool upgrade)169 md_post_extract(struct install_partition_desc *install, bool upgrade)
170 {
171 return 0;
172 }
173
174 void
md_cleanup_install(struct install_partition_desc * install)175 md_cleanup_install(struct install_partition_desc *install)
176 {
177 #ifndef DEBUG
178 enable_rc_conf();
179 #endif
180 }
181
182 int
md_pre_update(struct install_partition_desc * install)183 md_pre_update(struct install_partition_desc *install)
184 {
185 return 1;
186 }
187
188 /* Upgrade support */
189 int
md_update(struct install_partition_desc * install)190 md_update(struct install_partition_desc *install)
191 {
192 md_post_newfs(install);
193 return 1;
194 }
195
196 int
md_pre_mount(struct install_partition_desc * install,size_t ndx)197 md_pre_mount(struct install_partition_desc *install, size_t ndx)
198 {
199 return 0;
200 }
201
202 bool
md_parts_use_wholedisk(struct disk_partitions * parts)203 md_parts_use_wholedisk(struct disk_partitions *parts)
204 {
205 return parts_use_wholedisk(parts, 0, NULL);
206 }
207
208 #ifdef HAVE_GPT
209 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)210 md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
211 bool root_is_new, part_id efi_id, bool efi_is_new)
212 {
213 /* no GPT boot support, no special checks needed */
214 return true;
215 }
216 #endif
217
218