Create a FAT12 partition and copy bootloader into there after partitioning.

Based on the simliar code on prep and ofppc.
This commit is contained in:
tsutsui 2008-02-02 04:20:02 +00:00
parent d11c48442b
commit c14c9fe83a
3 changed files with 320 additions and 34 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.c,v 1.28 2008/01/28 02:47:13 rumble Exp $ */
/* $NetBSD: md.c,v 1.29 2008/02/02 04:20:02 tsutsui Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -40,33 +40,37 @@
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/exec.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <machine/cpu.h>
#include <stdio.h>
#include <util.h>
#include <dirent.h>
#include <machine/cpu.h>
#include "defs.h"
#include "md.h"
#include "msg_defs.h"
#include "menu_defs.h"
#include "md.h"
/*
* ARC BIOS reognizes only FAT, so we have to have a FAT partition
* to store our native bootloader.
*/
static int nobootfs = 0;
static int bootpart_fat12 = PART_BOOT_FAT12;
int
md_get_info(void)
{
read_mbr(diskdev, &mbr);
md_bios_info(diskdev);
edit_mbr(&mbr);
return 1;
return edit_mbr(&mbr);
}
int
md_pre_disklabel(void)
{
msg_display(MSG_dofdisk);
/* write edited MBR onto disk. */
@ -81,15 +85,10 @@ md_pre_disklabel(void)
int
md_post_disklabel(void)
{
if (get_ramsize() <= 32)
set_swap(diskdev, bsdlabel);
/* Sector forwarding / badblocks ... */
if (*doessf) {
msg_display(MSG_dobad144);
return run_program(RUN_DISPLAY, "/usr/sbin/bad144 %s 0",
diskdev);
}
return 0;
}
@ -97,13 +96,18 @@ int
md_post_newfs(void)
{
/* XXX ARC port needs native bootloader. */
if (!nobootfs) {
msg_display(msg_string(MSG_copybootloader), diskdev);
cp_to_target("/usr/mdec/boot", "/boot");
}
return 0;
}
int
md_copy_filesystem(void)
{
return 0;
}
@ -111,20 +115,181 @@ md_copy_filesystem(void)
int
md_make_bsd_partitions(void)
{
return make_bsd_partitions();
int i;
int part;
int maxpart = getmaxpartitions();
int partstart;
int part_raw, part_bsd;
int ptend;
int no_swap = 0;
partinfo *p;
/*
* Initialize global variables that track space used on this disk.
* Standard 4.4BSD 8-partition labels always cover whole disk.
*/
if (ptsize == 0)
ptsize = dlsize - ptstart;
if (dlsize == 0)
dlsize = ptstart + ptsize;
partstart = ptstart;
ptend = ptstart + ptsize;
/* Ask for layout type -- standard or special */
msg_display(MSG_layout,
ptsize / (MEG / sectorsize),
DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE,
DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE + XNEEDMB);
process_menu(MENU_layout, NULL);
/* Set so we use the 'real' geometry for rounding, input in MB */
current_cylsize = dlcylsize;
set_sizemultname_meg();
/* Build standard partitions */
memset(&bsdlabel, 0, sizeof bsdlabel);
/* Set initial partition types to unused */
for (part = 0 ; part < maxpart ; ++part)
bsdlabel[part].pi_fstype = FS_UNUSED;
/* Whole disk partition */
part_raw = getrawpartition();
if (part_raw == -1)
part_raw = PART_C; /* for sanity... */
bsdlabel[part_raw].pi_offset = 0;
bsdlabel[part_raw].pi_size = dlsize;
if (part_raw == PART_D) {
/* Probably a system that expects an i386 style mbr */
part_bsd = PART_C;
bsdlabel[PART_C].pi_offset = ptstart;
bsdlabel[PART_C].pi_size = ptsize;
} else {
part_bsd = part_raw;
}
if (bootsize != 0) {
bsdlabel[PART_BOOT_FAT12].pi_fstype = FS_MSDOS;
bsdlabel[PART_BOOT_FAT12].pi_size = bootsize;
bsdlabel[PART_BOOT_FAT12].pi_offset = bootstart;
bsdlabel[PART_BOOT_FAT12].pi_flags |= PART_BOOT_FAT12_PI_FLAGS;
strlcpy(bsdlabel[PART_BOOT_FAT12].pi_mount,
PART_BOOT_FAT12_PI_MOUNT,
sizeof bsdlabel[PART_BOOT_FAT12].pi_mount);
}
#ifdef PART_REST
bsdlabel[PART_REST].pi_offset = 0;
bsdlabel[PART_REST].pi_size = ptstart;
#endif
/*
* Save any partitions that are outside the area we are
* going to use.
* In particular this saves details of the other MBR
* partitions on a multiboot i386 system.
*/
for (i = maxpart; i--;) {
if (bsdlabel[i].pi_size != 0)
/* Don't overwrite special partitions */
continue;
p = &oldlabel[i];
if (p->pi_fstype == FS_UNUSED || p->pi_size == 0)
continue;
if (layoutkind == 4) {
if (PI_ISBSDFS(p))
p->pi_flags |= PIF_MOUNT;
} else {
if (p->pi_offset < ptstart + ptsize &&
p->pi_offset + p->pi_size > ptstart)
/* Not outside area we are allocating */
continue;
if (p->pi_fstype == FS_SWAP)
no_swap = 1;
}
bsdlabel[i] = oldlabel[i];
}
if (layoutkind == 4) {
/* XXX Check we have a sensible layout */
;
} else
get_ptn_sizes(partstart, ptend - partstart, no_swap);
/*
* OK, we have a partition table. Give the user the chance to
* edit it and verify it's OK, or abort altogether.
*/
edit_check:
if (edit_and_check_label(bsdlabel, maxpart, part_raw, part_bsd) == 0) {
msg_display(MSG_abort);
return 0;
}
if (md_check_partitions() == 0)
goto edit_check;
/* Disk name */
msg_prompt(MSG_packname, bsddiskname, bsddiskname, sizeof bsddiskname);
/* save label to disk for MI code to update. */
(void)savenewlabel(bsdlabel, maxpart);
/* Everything looks OK. */
return 1;
}
int
md_check_partitions(void)
{
return 1;
int part;
/* we need to find a boot partition, otherwise we can't write our
* bootloader. We make the assumption that the user hasn't done
* something stupid, like move it away from the MBR partition.
*/
for (part = PART_A; part < MAXPARTITIONS; part++)
if (bsdlabel[part].pi_fstype == FS_MSDOS) {
bootpart_fat12 = part;
return 1;
}
msg_display(MSG_nobootpartdisklabel);
process_menu(MENU_ok, NULL);
return 0;
}
int
md_pre_update(void)
{
if (get_ramsize() <= 8)
struct mbr_partition *part;
mbr_info_t *ext;
int i;
if (get_ramsize() <= 32)
set_swap(diskdev, NULL);
read_mbr(diskdev, &mbr);
/* do a sanity check of the partition table */
for (ext = &mbr; ext; ext = ext->extended) {
part = ext->mbr.mbr_parts;
for (i = 0; i < MBR_PART_COUNT; part++, i++) {
if (part->mbrp_type != MBR_PTYPE_FAT12)
continue;
if (part->mbrp_size < (MIN_FAT12_BOOT / 512)) {
msg_display(MSG_boottoosmall);
msg_display_add(MSG_nobootpart, 0);
process_menu(MENU_yesno, NULL);
if (!yesno)
return 0;
nobootfs = 1;
}
}
}
if (md_check_partitions() == 0)
nobootfs = 1;
return 1;
}
@ -133,6 +298,7 @@ md_pre_update(void)
int
md_update(void)
{
endwin();
md_copy_filesystem();
md_post_newfs();
@ -153,6 +319,9 @@ md_cleanup_install(void)
run_program(0, "rm -f %s", target_expand("/sysinst"));
run_program(0, "rm -f %s", target_expand("/.termcap"));
run_program(0, "rm -f %s", target_expand("/.profile"));
msg_display(MSG_howtoboot);
process_menu(MENU_ok, NULL);
}
int
@ -171,28 +340,90 @@ md_bios_info(char *dev)
void
md_init(void)
{
/* Nothing to do */
}
void
md_init_set_status(int minimal)
{
(void)minimal;
}
int
md_post_extract(void)
{
return 0;
}
int
md_check_mbr(mbr_info_t *mbri)
{
mbr_info_t *ext;
struct mbr_partition *part;
int i;
for (ext = mbri; ext; ext = ext->extended) {
part = ext->mbr.mbr_parts;
for (i = 0; i < MBR_PART_COUNT; part++, i++) {
if (part->mbrp_type == MBR_PTYPE_FAT12) {
bootstart = part->mbrp_start;
bootsize = part->mbrp_size;
break;
}
}
}
if (bootsize < (MIN_FAT12_BOOT / 512)) {
msg_display(MSG_boottoosmall);
msg_display_add(MSG_reeditpart, 0);
process_menu(MENU_yesno, NULL);
if (!yesno)
return 0;
return 1;
}
if (bootstart == 0 || bootsize == 0) {
msg_display(MSG_nobootpart);
msg_display_add(MSG_reeditpart, 0);
process_menu(MENU_yesno, NULL);
if (!yesno)
return 0;
return 1;
}
return 2;
}
int
md_mbr_use_wholedisk(mbr_info_t *mbri)
{
return mbr_use_wholedisk(mbri);
struct mbr_sector *mbrs = &mbri->mbr;
mbr_info_t *ext;
struct mbr_partition *part;
part = &mbrs->mbr_parts[0];
/* Set the partition information for full disk usage. */
while ((ext = mbri->extended)) {
mbri->extended = ext->extended;
free(ext);
}
memset(part, 0, MBR_PART_COUNT * sizeof *part);
#ifdef BOOTSEL
memset(&mbri->mbrb, 0, sizeof mbri->mbrb);
#endif
part[0].mbrp_type = MBR_PTYPE_FAT12;
part[0].mbrp_size = FAT12_BOOT_SIZE / 512;
part[0].mbrp_start = bsec;
part[0].mbrp_flag = MBR_PFLAG_ACTIVE;
part[1].mbrp_type = MBR_PTYPE_NETBSD;
part[1].mbrp_size = dlsize - (bsec + FAT12_BOOT_SIZE / 512);
part[1].mbrp_start = bsec + FAT12_BOOT_SIZE / 512;
part[1].mbrp_flag = 0;
ptstart = part[1].mbrp_start;
ptsize = part[1].mbrp_size;
bootstart = part[0].mbrp_start;
bootsize = part[0].mbrp_size;
return 1;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.h,v 1.13 2007/11/12 15:07:34 jmmv Exp $ */
/* $NetBSD: md.h,v 1.14 2008/02/02 04:20:02 tsutsui Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -49,10 +49,31 @@
#include "mbr.h"
/* constants and defines */
#define FAT12_BOOT_SIZE (2 * 1024 * 1024) /* 2MB boot partition */
#define MIN_FAT12_BOOT (1 * 1024 * 1024) /* 1MB minimum */
#define PART_ROOT PART_A
#define PART_SWAP PART_B
#define PART_BSD PART_C
#define PART_RAW PART_D
#define PART_BOOT_FAT12 PART_E
#define PART_USR PART_F
#define PART_FIRST_FREE PART_G
/* We want the boot MSDOS partition mounted on /boot */
#define USE_NEWFS_MSDOS
#define PART_BOOT_FAT12_PI_FLAGS (PIF_NEWFS|PIF_MOUNT)
#define PART_BOOT_FAT12_PI_MOUNT "/msdos"
/* default partition size */
#define DEFSWAPRAM 32 /* Assume at least this RAM for swap calc */
#define DEFSWAPSIZE 128 /* Default swap size */
#define DEFROOTSIZE 64 /* Default root size, if created */
#define DEFVARSIZE 64 /* Default /var size, if created */
#define DEFUSRSIZE 256 /* Default /usr size, if created */
/* Megs required for a full X installation. */
#define XNEEDMB 50
#define XNEEDMB 100
/*
@ -60,8 +81,8 @@
* or upgrade. The standard sets are:
* base etc comp games man misc tests text xbase xcomp xetc xfont xserver
*/
#define SET_KERNEL_1_NAME "kern-GENERIC"
#define MD_SETS_SELECTED SET_KERNEL_1, SET_SYSTEM, SET_X11_NOSERVERS
/*
* Machine-specific command to write a new label to a disk.
@ -73,10 +94,3 @@
* hand-edited disklabel will NOT be written by MI code.
*/
#define DISKLABEL_CMD "disklabel -w -r"
/*
* prototypes for MD code.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg.md.en,v 1.8 2003/06/12 10:51:39 dsl Exp $ */
/* $NetBSD: msg.md.en,v 1.9 2008/02/02 04:20:02 tsutsui Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -39,7 +39,8 @@
/* MD Message catalog -- English, arc version */
message md_hello
{If you booted from a floppy, you may now remove the disk.
{Make sure you have a backup of your disk if needed since
sysinst on this port is still experimental.
}
@ -47,5 +48,45 @@ message dobad144
{Installing the bad block table ...
}
message dobootblks
{Installing boot blocks on %s....
}
message pickdisk
{Choose disk: }
message partabovechs
{The NetBSD part of the disk lies outside of the range that the BIOS on
your machine can address. Booting from it may not be possible. Are you
sure you that you want to do this?
(Answering 'no' will take you back to the partition edit menu.)}
message nobootpart
{There is no FAT12 MS-DOS partition in the MBR partition table.}
message boottoosmall
{The MS-DOS FAT12 partition to install the native bootloader is too small.
It needs to be at least 1MB in size, however a size of at least 2MB is
reccomended.}
message nobootpartdisklabel
{There is no boot partition in the disklabel. The boot partition should
match the boot partition you set up in the MBR partition table.}
message copybootloader
{Copying bootloader into the MS-DOS FAT12 partition on %s...
}
message howtoboot
{The installation is almost complete. Note the installer doesn't set
ARC BIOS environments for the BIOS to load NetBSD's bootloader by default.
To boot NetBSD, you need to specify the following boot command on
'Run a program' prompt of the ARC BIOS menu.
scsi()disk()rdisk()partition(1)boot scsi()disk()rdisk()partition(2)netbsd
}
message set_kernel_1
{Kernel (GENERIC)}