4 * Copyright 1997 Piermont Information Systems Inc.
7 * Based on code written by Philip A. Nelson for Piermont Information
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed for the NetBSD Project by
21 * Piermont Information Systems Inc.
22 * 4. The name of Piermont Information Systems Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior
26 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
36 * THE POSSIBILITY OF SUCH DAMAGE.
39 /* md.c -- arc machine specific routines */
41 #include <sys/param.h>
42 #include <sys/sysctl.h>
45 #include <machine/cpu.h>
50 #include "menu_defs.h"
53 * ARC BIOS reognizes only FAT, so we have to have a FAT partition
54 * to store our native bootloader.
56 static int nobootfs
= 0;
57 static int bootpart_fat12
= PART_BOOT_FAT12
;
65 md_init_set_status(int minimal
)
73 return set_bios_geom_with_mbr_guess();
77 * md back-end code for menu-driven BSD disklabel editor.
80 md_make_bsd_partitions(void)
84 int maxpart
= getmaxpartitions();
86 int part_raw
, part_bsd
;
92 * Initialize global variables that track space used on this disk.
93 * Standard 4.4BSD 8-partition labels always cover whole disk.
96 ptsize
= dlsize
- ptstart
;
98 dlsize
= ptstart
+ ptsize
;
101 ptend
= ptstart
+ ptsize
;
103 /* Ask for layout type -- standard or special */
104 msg_display(MSG_layout
,
105 ptsize
/ (MEG
/ sectorsize
),
106 DEFROOTSIZE
+ DEFSWAPSIZE
+ DEFUSRSIZE
,
107 DEFROOTSIZE
+ DEFSWAPSIZE
+ DEFUSRSIZE
+ XNEEDMB
);
109 process_menu(MENU_layout
, NULL
);
111 /* Set so we use the 'real' geometry for rounding, input in MB */
112 current_cylsize
= dlcylsize
;
113 set_sizemultname_meg();
115 /* Build standard partitions */
116 memset(&bsdlabel
, 0, sizeof bsdlabel
);
118 /* Set initial partition types to unused */
119 for (part
= 0 ; part
< maxpart
; ++part
)
120 bsdlabel
[part
].pi_fstype
= FS_UNUSED
;
122 /* Whole disk partition */
123 part_raw
= getrawpartition();
125 part_raw
= PART_C
; /* for sanity... */
126 bsdlabel
[part_raw
].pi_offset
= 0;
127 bsdlabel
[part_raw
].pi_size
= dlsize
;
129 if (part_raw
== PART_D
) {
130 /* Probably a system that expects an i386 style mbr */
132 bsdlabel
[PART_C
].pi_offset
= ptstart
;
133 bsdlabel
[PART_C
].pi_size
= ptsize
;
139 bsdlabel
[PART_BOOT_FAT12
].pi_fstype
= FS_MSDOS
;
140 bsdlabel
[PART_BOOT_FAT12
].pi_size
= bootsize
;
141 bsdlabel
[PART_BOOT_FAT12
].pi_offset
= bootstart
;
142 bsdlabel
[PART_BOOT_FAT12
].pi_flags
|= PART_BOOT_FAT12_PI_FLAGS
;
143 strlcpy(bsdlabel
[PART_BOOT_FAT12
].pi_mount
,
144 PART_BOOT_FAT12_PI_MOUNT
,
145 sizeof bsdlabel
[PART_BOOT_FAT12
].pi_mount
);
149 bsdlabel
[PART_REST
].pi_offset
= 0;
150 bsdlabel
[PART_REST
].pi_size
= ptstart
;
154 * Save any partitions that are outside the area we are
156 * In particular this saves details of the other MBR
157 * partitions on a multiboot i386 system.
159 for (i
= maxpart
; i
--;) {
160 if (bsdlabel
[i
].pi_size
!= 0)
161 /* Don't overwrite special partitions */
164 if (p
->pi_fstype
== FS_UNUSED
|| p
->pi_size
== 0)
166 if (layoutkind
== 4) {
168 p
->pi_flags
|= PIF_MOUNT
;
170 if (p
->pi_offset
< ptstart
+ ptsize
&&
171 p
->pi_offset
+ p
->pi_size
> ptstart
)
172 /* Not outside area we are allocating */
174 if (p
->pi_fstype
== FS_SWAP
)
177 bsdlabel
[i
] = oldlabel
[i
];
180 if (layoutkind
== 4) {
181 /* XXX Check we have a sensible layout */
184 get_ptn_sizes(partstart
, ptend
- partstart
, no_swap
);
187 * OK, we have a partition table. Give the user the chance to
188 * edit it and verify it's OK, or abort altogether.
191 if (edit_and_check_label(bsdlabel
, maxpart
, part_raw
, part_bsd
) == 0) {
192 msg_display(MSG_abort
);
195 if (md_check_partitions() == 0)
199 msg_prompt(MSG_packname
, bsddiskname
, bsddiskname
, sizeof bsddiskname
);
201 /* save label to disk for MI code to update. */
202 (void)savenewlabel(bsdlabel
, maxpart
);
204 /* Everything looks OK. */
209 * any additional partition validation
212 md_check_partitions(void)
216 /* we need to find a boot partition, otherwise we can't write our
217 * bootloader. We make the assumption that the user hasn't done
218 * something stupid, like move it away from the MBR partition.
220 for (part
= PART_A
; part
< MAXPARTITIONS
; part
++)
221 if (bsdlabel
[part
].pi_fstype
== FS_MSDOS
) {
222 bootpart_fat12
= part
;
226 msg_display(MSG_nobootpartdisklabel
);
227 process_menu(MENU_ok
, NULL
);
232 * hook called before writing new disklabel.
235 md_pre_disklabel(void)
237 msg_display(MSG_dofdisk
);
239 /* write edited MBR onto disk. */
240 if (write_mbr(diskdev
, &mbr
, 1) != 0) {
241 msg_display(MSG_wmbrfail
);
242 process_menu(MENU_ok
, NULL
);
249 * hook called after writing disklabel to new target disk.
252 md_post_disklabel(void)
254 if (get_ramsize() <= 32)
255 set_swap(diskdev
, bsdlabel
);
260 * hook called after upgrade() or install() has finished setting
261 * up the target disk but immediately before the user is given the
262 * ``disks are now set up'' message.
268 msg_display(msg_string(MSG_copybootloader
), diskdev
);
269 cp_to_target("/usr/mdec/boot", PART_BOOT_FAT12_PI_MOUNT
);
276 md_post_extract(void)
282 md_cleanup_install(void)
287 msg_display(MSG_howtoboot
);
288 process_menu(MENU_ok
, NULL
);
294 struct mbr_partition
*part
;
298 if (get_ramsize() <= 32)
299 set_swap(diskdev
, NULL
);
301 read_mbr(diskdev
, &mbr
);
302 /* do a sanity check of the partition table */
303 for (ext
= &mbr
; ext
; ext
= ext
->extended
) {
304 part
= ext
->mbr
.mbr_parts
;
305 for (i
= 0; i
< MBR_PART_COUNT
; part
++, i
++) {
306 if (part
->mbrp_type
!= MBR_PTYPE_FAT12
)
308 if (part
->mbrp_size
< (MIN_FAT12_BOOT
/ 512)) {
309 msg_display(MSG_boottoosmall
);
310 msg_display_add(MSG_nobootpart
, 0);
311 process_menu(MENU_yesno
, NULL
);
318 if (md_check_partitions() == 0)
323 /* Upgrade support */
332 md_check_mbr(mbr_info_t
*mbri
)
335 struct mbr_partition
*part
;
338 for (ext
= mbri
; ext
; ext
= ext
->extended
) {
339 part
= ext
->mbr
.mbr_parts
;
340 for (i
= 0; i
< MBR_PART_COUNT
; part
++, i
++) {
341 if (part
->mbrp_type
== MBR_PTYPE_FAT12
) {
342 bootstart
= part
->mbrp_start
;
343 bootsize
= part
->mbrp_size
;
348 if (bootsize
< (MIN_FAT12_BOOT
/ 512)) {
349 msg_display(MSG_boottoosmall
);
350 msg_display_add(MSG_reeditpart
, 0);
351 process_menu(MENU_yesno
, NULL
);
356 if (bootstart
== 0 || bootsize
== 0) {
357 msg_display(MSG_nobootpart
);
358 msg_display_add(MSG_reeditpart
, 0);
359 process_menu(MENU_yesno
, NULL
);
368 md_mbr_use_wholedisk(mbr_info_t
*mbri
)
370 struct mbr_sector
*mbrs
= &mbri
->mbr
;
372 struct mbr_partition
*part
;
374 part
= &mbrs
->mbr_parts
[0];
375 /* Set the partition information for full disk usage. */
376 while ((ext
= mbri
->extended
)) {
377 mbri
->extended
= ext
->extended
;
380 memset(part
, 0, MBR_PART_COUNT
* sizeof *part
);
382 memset(&mbri
->mbrb
, 0, sizeof mbri
->mbrb
);
384 part
[0].mbrp_type
= MBR_PTYPE_FAT12
;
385 part
[0].mbrp_size
= FAT12_BOOT_SIZE
/ 512;
386 part
[0].mbrp_start
= bsec
;
387 part
[0].mbrp_flag
= MBR_PFLAG_ACTIVE
;
389 part
[1].mbrp_type
= MBR_PTYPE_NETBSD
;
390 part
[1].mbrp_size
= dlsize
- (bsec
+ FAT12_BOOT_SIZE
/ 512);
391 part
[1].mbrp_start
= bsec
+ FAT12_BOOT_SIZE
/ 512;
392 part
[1].mbrp_flag
= 0;
394 ptstart
= part
[1].mbrp_start
;
395 ptsize
= part
[1].mbrp_size
;
396 bootstart
= part
[0].mbrp_start
;
397 bootsize
= part
[0].mbrp_size
;