From fa6c4a2580c20ed58b171f7dadfac820bc5f1bbc Mon Sep 17 00:00:00 2001 From: Evgeniy Ivanov Date: Tue, 10 Jan 2012 13:45:46 +0400 Subject: [PATCH] Port installboot as installboot_nbsd and rename the old one. Also following functionality was added: - Add install_master to the installboot from NetBSD. - Check if enough space for bootxx. Old installboot was renamed to installboot_minix. --- boot/installboot/Makefile | 2 +- boot/updateboot.sh | 2 +- docs/UPDATING | 9 ++ tools/Makefile | 2 +- tools/mkboot | 4 +- tools/release.functions | 8 +- tools/release.sh | 2 +- usr.sbin/installboot/Makefile | 46 +++--- usr.sbin/installboot/arch/i386.c | 8 + usr.sbin/installboot/install_master.c | 122 +++++++++++++++ usr.sbin/installboot/installboot.c | 21 +++ usr.sbin/installboot/installboot.h | 12 ++ .../{installboot.8 => installboot_nbsd.8} | 80 +++------- usr.sbin/installboot/machines.c | 6 + usr.sbin/installboot/minixfs3.c | 142 ++++++++++++++++++ 15 files changed, 380 insertions(+), 86 deletions(-) create mode 100644 usr.sbin/installboot/install_master.c rename usr.sbin/installboot/{installboot.8 => installboot_nbsd.8} (92%) create mode 100644 usr.sbin/installboot/minixfs3.c diff --git a/boot/installboot/Makefile b/boot/installboot/Makefile index 4454e8d16..4508afe08 100644 --- a/boot/installboot/Makefile +++ b/boot/installboot/Makefile @@ -1,6 +1,6 @@ # installboot: install the boot package; runs on the installer's machine -PROG= installboot +PROG= installboot_minix BINDIR= /usr/bin SRCS= installboot.c rawfs.c diff --git a/boot/updateboot.sh b/boot/updateboot.sh index 11234e962..37ae08364 100755 --- a/boot/updateboot.sh +++ b/boot/updateboot.sh @@ -24,5 +24,5 @@ echo Installing boot monitor into $BOOT. cp $MDEC/boot $BOOT echo Patching position of $BOOT into $ROOT. -installboot -d "$ROOT" $MDEC/bootblock $BOOT +installboot_minix -d "$ROOT" $MDEC/bootblock $BOOT sync diff --git a/docs/UPDATING b/docs/UPDATING index 272ae0fe8..53f5544ea 100644 --- a/docs/UPDATING +++ b/docs/UPDATING @@ -1,3 +1,12 @@ +20120202 + Rename installboot to installboot_minix. + + Do this BEFORE a 'make world': + # rm -f /usr/bin/installboot /usr/sbin/installboot + # make -C boot/installboot clean install + # make -C usr.sbin/installboot clean install + Then 'make clean world' as usual. + 20120119: Follow up to previous entry. The same problem also exists for the man pages. diff --git a/tools/Makefile b/tools/Makefile index 3662de7fd..3e7de5d1b 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -75,7 +75,7 @@ image: includes services .else image: includes services ${PAD_KERNEL_TEXT} - installboot -image $@ $(KERNEL) $(PROGRAMS) + installboot_minix -image $@ $(KERNEL) $(PROGRAMS) .endif # rebuild the program or system libraries diff --git a/tools/mkboot b/tools/mkboot index a53289880..ca2b67e19 100755 --- a/tools/mkboot +++ b/tools/mkboot @@ -51,7 +51,7 @@ bootable) # Install the boot monitor on the root device and make it bootable. install -cs -m 644 $mdec/boot $rootdir/boot/boot || exit sync - installboot -device $root $mdec/bootblock /boot/boot || exit + installboot_minix -device $root $mdec/bootblock /boot/boot || exit test $realroot != $root && umount $root ;; hdboot) @@ -163,7 +163,7 @@ fdboot) umount $dev || exit # Make bootable and copy the boot parameters. - installboot -d $dev $mdec/bootblock /boot/boot || exit + installboot_minix -d $dev $mdec/bootblock /boot/boot || exit pfile=fdbootparams if [ -f $pfile ] then echo "Using floppy boot parameters from file $pfile." diff --git a/tools/release.functions b/tools/release.functions index 0a4f5e790..c95dd6af0 100644 --- a/tools/release.functions +++ b/tools/release.functions @@ -12,7 +12,7 @@ make_hdimage() # installboot -m needs at least 1KB dd < /dev/zero >tmpimage count=2 partition -fm tmpimage 2 81:$rootsects* 0:0 81:$usrsects - installboot -m tmpimage /usr/mdec/masterboot + installboot_minix -m tmpimage /usr/mdec/masterboot dd < tmpimage > subpart count=1 primsects=`expr 1 + $rootsects + $usrsects` @@ -26,7 +26,7 @@ make_hdimage() dd < /dev/zero count=$padsects } > hdimage partition -m hdimage 81:`expr $primsects + $padsects`* - installboot -m hdimage /usr/mdec/masterboot + installboot_minix -m hdimage /usr/mdec/masterboot } retrieve() @@ -62,7 +62,7 @@ save' hdemu_root_changes() { - $RELEASEDIR/usr/bin/installboot -d $TMPDISKROOT \ + $RELEASEDIR/usr/bin/installboot_minix -d $TMPDISKROOT \ $RELEASEDIR/usr/mdec/bootblock boot/boot echo \ 'bootcd=2 @@ -77,7 +77,7 @@ save' | $RELEASEDIR/usr/bin/edparams $TMPDISKROOT usb_root_changes() { - $RELEASEDIR/usr/bin/installboot -d $TMPDISKROOT \ + $RELEASEDIR/usr/bin/installboot_minix -d $TMPDISKROOT \ $RELEASEDIR/usr/mdec/bootblock boot/boot echo \ 'bios_wini=yes diff --git a/tools/release.sh b/tools/release.sh index 10ed4b941..333228e64 100755 --- a/tools/release.sh +++ b/tools/release.sh @@ -406,7 +406,7 @@ else dd if=$TMPDISKUSR bs=$BS count=$USRBLOCKS ) >m mv m $IMG # Make CD partition table - installboot -m $IMG /usr/mdec/masterboot + installboot_minix -m $IMG /usr/mdec/masterboot # Make sure there is no hole..! Otherwise the ISO format is # unreadable. partition -m $IMG 0 81:$isosects 81:$ROOTSECTS 81:$USRSECTS diff --git a/usr.sbin/installboot/Makefile b/usr.sbin/installboot/Makefile index b631a32e8..231c1e789 100644 --- a/usr.sbin/installboot/Makefile +++ b/usr.sbin/installboot/Makefile @@ -3,18 +3,20 @@ .include -PROG= installboot -MAN= installboot.8 -SRCS= installboot.c sum.c machines.c fstypes.c +PROG= installboot_nbsd +MAN= installboot_nbsd.8 +SRCS= installboot.c sum.c machines.c fstypes.c install_master.c -ARCH_XLAT= amd64-i386.c news68k-news.c newsmips-news.c -ARCH_XLAT+= sun2-sun68k.c sun3-sun68k.c +ARCH_XLAT= amd64-i386.c +#ARCH_XLAT= amd64-i386.c news68k-news.c newsmips-news.c +#ARCH_XLAT+= sun2-sun68k.c sun3-sun68k.c .if !defined(SMALLPROG) && !defined(ARCH_FILES) -ARCH_FILES= alpha.c amiga.c emips.c ews4800mips.c hp300.c hp700.c i386.c -ARCH_FILES+= landisk.c macppc.c news.c next68k.c pmax.c -ARCH_FILES+= sparc.c sparc64.c sun68k.c vax.c x68k.c +ARCH_FILES= i386.c +#ARCH_FILES= alpha.c amiga.c emips.c ews4800mips.c hp300.c hp700.c i386.c +#ARCH_FILES+= landisk.c macppc.c news.c next68k.c pmax.c +#ARCH_FILES+= sparc.c sparc64.c sun68k.c vax.c x68k.c .else ARCH_FILES?= ${ARCH_XLAT:M${MACHINE}-*:S/${MACHINE}-//} .if empty(ARCH_FILES) @@ -24,24 +26,28 @@ ARCH_FILES= ${MACHINE}.c SRCS+=${ARCH_FILES} -.if empty(ARCH_FILES:C/(macppc|news|sparc|sun68k|x68k)/stg2/:Mstg2.c) CPPFLAGS += -DNO_STAGE2 -.else -SRCS+= bbinfo.c +#.if empty(ARCH_FILES:C/(macppc|news|sparc|sun68k|x68k)/stg2/:Mstg2.c) +#CPPFLAGS += -DNO_STAGE2 +#.else +#SRCS+= bbinfo.c # fstypes are only needed for 'stage2' and then only from bbinfo. -SRCS+= ffs.c -.if SMALLPROG -CPPFLAGS+= -DNO_FFS_SWAP -.else -SRCS+= ffs_bswap.c -.endif +#SRCS+= ffs.c +#.if SMALLPROG +#CPPFLAGS+= -DNO_FFS_SWAP +#.else +#SRCS+= ffs_bswap.c +#.endif #SRCS+= ext2fs.c ext2fs_bswap.c -.endif +#.endif + +SRCS+= minixfs3.c -UFSSRC= ${NETBSDSRCDIR}/sys/ufs +#UFSSRC= ${NETBSDSRCDIR}/sys/ufs +#.PATH: ${.CURDIR}/arch ${UFSSRC}/ffs ${UFSSRC}/ext2fs +.PATH: ${.CURDIR}/arch CPPFLAGS+= -I${.CURDIR} -I. -.PATH: ${.CURDIR}/arch ${UFSSRC}/ffs ${UFSSRC}/ext2fs .if !defined(HOSTPROGNAME) .if defined(HAVE_GCC) || defined(HAVE_PCC) diff --git a/usr.sbin/installboot/arch/i386.c b/usr.sbin/installboot/arch/i386.c index 64a6b0dd1..85b8ff2a3 100644 --- a/usr.sbin/installboot/arch/i386.c +++ b/usr.sbin/installboot/arch/i386.c @@ -81,6 +81,14 @@ struct ib_mach ib_mach_i386 = IB_KEYMAP | IB_PASSWORD | IB_TIMEOUT | IB_MODULES | IB_BOOTCONF }; +#ifdef __minix +struct ib_mach ib_mach_i686 = + { "i686", i386_setboot, no_clearboot, i386_editboot, + IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED | IB_CONSADDR | + IB_KEYMAP | IB_PASSWORD | IB_TIMEOUT | + IB_MODULES | IB_BOOTCONF }; +#endif + struct ib_mach ib_mach_amd64 = { "amd64", i386_setboot, no_clearboot, i386_editboot, IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED | IB_CONSADDR | diff --git a/usr.sbin/installboot/install_master.c b/usr.sbin/installboot/install_master.c new file mode 100644 index 000000000..45f60038f --- /dev/null +++ b/usr.sbin/installboot/install_master.c @@ -0,0 +1,122 @@ +/* Based on original installboot from MINIX 3. + * + * installboot 3.0 - Make a device bootable Author: Kees J. Bot + * 21 Dec 1991 + */ + +#define _POSIX_SOURCE 1 +#define _MINIX 1 + +#include +#include +#include +#include +#include +#include +#include +#include + +#define BOOTBLOCK 0 /* Of course */ +#define BOOT_BLOCK_SIZE 1024 +#define SIGNATURE 0xAA55 /* Boot block signature. */ +#define SIGPOS 510 /* Where to put signature word. */ +#define PARTPOS 446 /* Offset to the partition table in a master + * boot block. + */ + + +static int rawfd; /* File descriptor to open device. */ +static const char *rawdev; /* Name of device. */ + + +static void report(const char *label) +/* installboot: label: No such file or directory */ +{ + fprintf(stderr, "installboot: %s: %s\n", label, strerror(errno)); +} + +static void fatal(const char *label) +{ + report(label); + exit(1); +} + +static void bread(FILE *f, char *name, void *buf, size_t len) +/* Read len bytes. Don't dare return without them. */ +{ + if (len > 0 && fread(buf, len, 1, f) != 1) { + if (ferror(f)) fatal(name); + fprintf(stderr, "installboot: Unexpected EOF on %s\n", name); + exit(1); + } +} + +static void readblock(off_t blk, char *buf, int block_size) +/* For rawfs, so that it can read blocks. */ +{ + int n; + + if (lseek(rawfd, blk * block_size, SEEK_SET) < 0 + || (n= read(rawfd, buf, block_size)) < 0 + ) fatal(rawdev); + + if (n < block_size) { + fprintf(stderr, "installboot: Unexpected EOF on %s\n", rawdev); + exit(1); + } +} + +static void writeblock(off_t blk, const char *buf, int block_size) +/* Add a function to write blocks for local use. */ +{ + if (lseek(rawfd, blk * block_size, SEEK_SET) < 0 + || write(rawfd, buf, block_size) < 0 + ) fatal(rawdev); +} + + +/* A temp stub until fdisk is ported to MINIX */ +void install_master(const char *device, char *masterboot, char **guide) +/* Booting a hard disk is a two stage process: The master bootstrap in sector + * 0 loads the bootstrap from sector 0 of the active partition which in turn + * starts the operating system. This code installs such a master bootstrap + * on a hard disk. If guide[0] is non-null then the master bootstrap is + * guided into booting a certain device. + */ +{ + FILE *masf; + unsigned long size; + static char buf[_MAX_BLOCK_SIZE]; + + /* Open device. */ + if ((rawfd= open(rawdev= device, O_RDWR)) < 0) fatal(device); + + /* Open the master boot code. */ + if ((masf= fopen(masterboot, "r")) == NULL) fatal(masterboot); + + size= PARTPOS; + + /* Read the master boot block, patch it, write. */ + readblock(BOOTBLOCK, buf, BOOT_BLOCK_SIZE); + + memset(buf, 0, PARTPOS); + (void) bread(masf, masterboot, buf, size); + + /* Install signature. */ + buf[SIGPOS+0]= (SIGNATURE >> 0) & 0xFF; + buf[SIGPOS+1]= (SIGNATURE >> 8) & 0xFF; + + writeblock(BOOTBLOCK, buf, BOOT_BLOCK_SIZE); +} + +int isoption(const char *option, const char *test) +/* Check if the option argument is equals "test". Also accept -i as short + * for -image, and the special case -x for -extract. + */ +{ + if (strcmp(option, test) == 0) return 1; + if (option[0] != '-' && strlen(option) != 2) return 0; + if (option[1] == test[1]) return 1; + if (option[1] == 'x' && test[1] == 'e') return 1; + return 0; +} diff --git a/usr.sbin/installboot/installboot.c b/usr.sbin/installboot/installboot.c index 4de3603f5..c4e6a7a0e 100644 --- a/usr.sbin/installboot/installboot.c +++ b/usr.sbin/installboot/installboot.c @@ -40,6 +40,7 @@ __RCSID("$NetBSD: installboot.c,v 1.36 2011/11/03 20:46:41 martin Exp $"); #include #include +#include #include #include @@ -106,6 +107,12 @@ main(int argc, char *argv[]) const char *op; ib_flags unsupported_flags; + /* XXX Temp stuff for MINIX until fdisk is ported */ + if ((4 <= argc && argc <= 6) && isoption(argv[1], "-master")) { + install_master(argv[2], argv[3], argv + 4); + exit(0); + } + setprogname(argv[0]); params = &installboot_params; memset(params, 0, sizeof(*params)); @@ -237,6 +244,20 @@ main(int argc, char *argv[]) op = "write"; mode = O_RDWR; } + + if (minixfs3_is_minix_partition(params->filesystem)) { + /* Old setups has just 1 sector for bootblock, + * but bootxx_minixfs is ~8Kb, so we require new setups + * to have 32 sectors before the first subpartition. + * This prevents from overwriting FS on old setups. + */ + if (!minixfs3_has_bootblock_space(params->filesystem)) { + err(1, "No space for bootxx, you should have 32 sectors" + " before the first subpartition on %s", + params->filesystem); + } + } + /* XXX should be specified via option */ params->sectorsize = DFL_SECSIZE; if ((params->fsfd = open(params->filesystem, mode, 0600)) == -1) diff --git a/usr.sbin/installboot/installboot.h b/usr.sbin/installboot/installboot.h index 00cb0c999..c66fc2ec9 100644 --- a/usr.sbin/installboot/installboot.h +++ b/usr.sbin/installboot/installboot.h @@ -161,6 +161,15 @@ int raw_findstage2(ib_params *, uint32_t *, ib_block *); int ext2fs_match(ib_params *); int ext2fs_findstage2(ib_params *, uint32_t *, ib_block *); + /* install_master.c */ +void install_master(const char *device, char *masterboot, char **guide); +int isoption(const char *option, const char *test); + + /* minixfs3.c */ +int minixfs3_is_minix_partition(const char* partition); +int minixfs3_has_bootblock_space(const char* partition); + + /* machines.c */ extern struct ib_mach ib_mach_alpha; extern struct ib_mach ib_mach_amd64; @@ -169,6 +178,9 @@ extern struct ib_mach ib_mach_ews4800mips; extern struct ib_mach ib_mach_hp300; extern struct ib_mach ib_mach_hp700; extern struct ib_mach ib_mach_i386; +#ifdef __minix +extern struct ib_mach ib_mach_i386; +#endif extern struct ib_mach ib_mach_landisk; extern struct ib_mach ib_mach_macppc; extern struct ib_mach ib_mach_news68k; diff --git a/usr.sbin/installboot/installboot.8 b/usr.sbin/installboot/installboot_nbsd.8 similarity index 92% rename from usr.sbin/installboot/installboot.8 rename to usr.sbin/installboot/installboot_nbsd.8 index cab63aadd..ec0b6d1cd 100644 --- a/usr.sbin/installboot/installboot.8 +++ b/usr.sbin/installboot/installboot_nbsd.8 @@ -1,4 +1,4 @@ -.\" $NetBSD: installboot.8,v 1.79 2011/11/03 20:09:18 martin Exp $ +.\" $NetBSD: installboot_nbsd.8,v 1.79 2011/11/03 20:09:18 martin Exp $ .\" .\" Copyright (c) 2002-2009 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -31,7 +31,7 @@ .Dt INSTALLBOOT 8 .Os .Sh NAME -.Nm installboot +.Nm installboot_nbsd .Nd install disk bootstrap software . .Sh SYNOPSIS @@ -39,7 +39,6 @@ .Op Fl fnv .Op Fl B Ar s2bno .Op Fl b Ar s1bno -.Op Fl m Ar machine .Op Fl o Ar options .Op Fl t Ar fstype .Ar filesystem @@ -48,16 +47,18 @@ .Nm .Fl c .Op Fl fnv -.Op Fl m Ar machine .Op Fl o Ar options .Op Fl t Ar fstype .Ar filesystem .Nm .Fl e .Op Fl fnv -.Op Fl m Ar machine .Op Fl o Ar options .Ar bootstrap +.Nm +.Fl m(aster) +.Ar device +.Ar masterboot . .Sh DESCRIPTION The @@ -189,39 +190,6 @@ Forces .Nm to ignore some errors. . -.It Fl m Ar machine -Use -.Ar machine -as the target machine type. -The default machine is determined from -.Xr uname 3 -and then -.Ev MACHINE . -The following machines are currently supported by -.Nm : -.Bd -ragged -offset indent -.Sy alpha , -.Sy amd64 , -.Sy amiga , -.Sy ews4800mips , -.Sy hp300 , -.Sy hp700 , -.Sy i386 , -.Sy landisk , -.Sy macppc , -.Sy news68k , -.Sy newsmips , -.Sy next68k , -.Sy pmax , -.Sy sparc , -.Sy sparc64 , -.Sy sun2 , -.Sy sun3 , -.Sy vax , -.Sy x68k -.Ed -. -. .It Fl n Do not write to .Ar filesystem . @@ -574,7 +542,7 @@ secondary bootstrap. .Ss common Verbosely install the Berkeley Fast File System primary bootstrap on to disk .Sq sd0 : -.Dl Ic installboot -v /dev/rsd0c /usr/mdec/bootxx_ffs +.Dl Ic installboot_nbsd -v /dev/rsd0c /usr/mdec/bootxx_ffs Note: the .Dq whole disk partition (c on some ports, d on others) is used here, since the a partition @@ -586,12 +554,12 @@ would not be able to access it. .Pp Remove the primary bootstrap from disk .Sq sd1 : -.Dl Ic installboot -c /dev/rsd1c +.Dl Ic installboot_nbsd -c /dev/rsd1c . .Ss Nx Ns Tn /amiga Modify the command line to change the default from "netbsd -ASn2" to "netbsd -S": -.Dl Ic installboot -m amiga -o command="netbsd -S" /dev/rsd0a /usr/mdec/bootxx_ffs +.Dl Ic installboot_nbsd -m amiga -o command="netbsd -S" /dev/rsd0a /usr/mdec/bootxx_ffs . .Ss Nx Ns Tn /ews4800mips Install the System V Boot File System primary bootstrap on to disk @@ -599,7 +567,7 @@ Install the System V Boot File System primary bootstrap on to disk with the secondary bootstrap .Sq Pa /boot already present in the SysVBFS partition on the disk: -.Dl Ic installboot /dev/rsd0c /usr/mdec/bootxx_bfs +.Dl Ic installboot_nbsd /dev/rsd0c /usr/mdec/bootxx_bfs . .Ss Nx Ns Tn /i386 and Nx Ns Tn /amd64 Install new boot blocks on an existing mounted root file system on @@ -607,7 +575,7 @@ Install new boot blocks on an existing mounted root file system on setting the timeout to five seconds, after copying a new secondary bootstrap: .Dl Ic cp /usr/mdec/boot /boot -.Dl Ic installboot -v -o timeout=5 /dev/rwd0a /usr/mdec/bootxx_ffsv1 +.Dl Ic installboot_nbsd -v -o timeout=5 /dev/rwd0a /usr/mdec/bootxx_ffsv1 . .Pp Create a bootable CD-ROM with an ISO9660 @@ -616,7 +584,7 @@ file system for an i386 system with a serial console: .Dl Ic cp sys/arch/i386/compile/mykernel/netbsd cdrom/netbsd .Dl Ic cp /usr/mdec/boot cdrom/boot .Dl Ic cp /usr/mdec/bootxx_cd9660 bootxx -.Dl Ic installboot -o console=com0,speed=19200 -m i386 -e bootxx +.Dl Ic installboot_nbsd -o console=com0,speed=19200 -m i386 -e bootxx .Dl Ic makefs -t cd9660 -o 'bootimage=i386;bootxx,no-emul-boot' boot.iso \ cdrom . @@ -636,7 +604,7 @@ which is not a problem for a floppy disk. .Dl Ic cp /usr/mdec/boot /mnt/boot .Dl Ic gzip -9 \*[Lt] sys/arch/i386/compile/mykernel/netbsd \*[Gt] /mnt/netbsd.gz .Dl Ic umount /mnt -.Dl Ic installboot -v /dev/rfd0a /usr/mdec/bootxx_ffsv1 +.Dl Ic installboot_nbsd -v /dev/rfd0a /usr/mdec/bootxx_ffsv1 . .Pp Create a bootable FAT file system on @@ -664,7 +632,7 @@ changed to this value. .Dl Ic cp /usr/mdec/boot /mnt/boot .Dl Ic cp path/to/kernel /mnt/netbsd .Dl Ic umount /mnt -.Dl Ic installboot -t raw /dev/rwd1a /usr/mdec/bootxx_msdos +.Dl Ic installboot_nbsd -t raw /dev/rwd1a /usr/mdec/bootxx_msdos .Pp Make the existing FAT16 filesystem on .Sq sd0e @@ -675,7 +643,7 @@ sectors and that the manufacturer correctly initialised the file system. .Dl Ic cp /usr/mdec/boot /mnt/boot .Dl Ic cp path/to/kernel /mnt/netbsd .Dl Ic umount /mnt -.Dl Ic installboot /dev/rsd0e /usr/mdec/bootxx_fat16 +.Dl Ic installboot_nbsd /dev/rsd0e /usr/mdec/bootxx_fat16 It may also be necessary to use .Nm fdisk to make the device itself bootable. @@ -683,7 +651,7 @@ to make the device itself bootable. .Pp Switch the existing installed bootstrap to use a serial console without reinstalling or altering other options such as timeout. -.Dl Ic installboot -e -o console=com0 /dev/rwd0a +.Dl Ic installboot_nbsd -e -o console=com0 /dev/rwd0a .Ss Nx Ns Tn /macppc Note the .Nm @@ -694,7 +662,7 @@ map. .Pp Install the Berkeley Fast File System primary bootstrap on to disk .Sq wd0 : -.Dl Ic installboot /dev/rwd0c /usr/mdec/bootxx /ofwboot +.Dl Ic installboot_nbsd /dev/rwd0c /usr/mdec/bootxx /ofwboot .Pp The secondary .Nx Ns Tn /macppc @@ -709,20 +677,20 @@ which is used for the OpenFirmware to load kernels. .Ss Nx Ns Tn /next68k Install the bootstrap on to disk .Sq sd0 : -.Dl Ic installboot /dev/rsd0c /usr/mdec/boot +.Dl Ic installboot_nbsd /dev/rsd0c /usr/mdec/boot .Pp . .Ss Nx Ns Tn /pmax Install the Berkeley Fast File System primary bootstrap on to disk .Sq sd0 : -.Dl Ic installboot /dev/rsd0c /usr/mdec/bootxx_ffs +.Dl Ic installboot_nbsd /dev/rsd0c /usr/mdec/bootxx_ffs .Pp .Nx Ns Tn /pmax requires that this file system starts at block 0 of the disk. .Pp Install the ISO 9660 primary bootstrap in the file .Pa /tmp/cd-image : -.Dl Ic installboot -m pmax /tmp/cd-image /usr/mdec/bootxx_cd9660 +.Dl Ic installboot_nbsd -m pmax /tmp/cd-image /usr/mdec/bootxx_cd9660 .Pp Make an ISO 9660 filesystem in the file .Pa /tmp/cd-image @@ -736,7 +704,7 @@ and the secondary bootstrap .Dl ... .Dl 48 51 iso-source-dir/bootxx_cd9660 .Dl ... -.Dl Ic installboot -b `expr 48 \e* 4` /tmp/cd-image /usr/mdec/bootxx_cd9660 +.Dl Ic installboot_nbsd -b `expr 48 \e* 4` /tmp/cd-image /usr/mdec/bootxx_cd9660 . .Ss Nx Ns Tn /sparc Install the Berkeley Fast File System primary bootstrap on to disk @@ -744,12 +712,12 @@ Install the Berkeley Fast File System primary bootstrap on to disk with the secondary bootstrap .Sq Pa /boot already present: -.Dl Ic installboot /dev/rsd0c /usr/mdec/bootxx /boot +.Dl Ic installboot_nbsd /dev/rsd0c /usr/mdec/bootxx /boot . .Ss Nx Ns Tn /sparc64 Install the primary bootstrap on to disk .Sq sd0 : -.Dl Ic installboot /dev/rsd0c /usr/mdec/bootblk +.Dl Ic installboot_nbsd /dev/rsd0c /usr/mdec/bootblk .Pp The secondary .Nx Ns Tn /sparc64 @@ -762,7 +730,7 @@ Install the Berkeley Fast File System primary bootstrap on to disk with the secondary bootstrap .Sq Pa /boot already present: -.Dl Ic installboot /dev/rsd0c /usr/mdec/bootxx /boot +.Dl Ic installboot_nbsd /dev/rsd0c /usr/mdec/bootxx /boot . .Sh SEE ALSO .Xr uname 3 , diff --git a/usr.sbin/installboot/machines.c b/usr.sbin/installboot/machines.c index 9320b0afe..736b22bc2 100644 --- a/usr.sbin/installboot/machines.c +++ b/usr.sbin/installboot/machines.c @@ -55,6 +55,9 @@ struct ib_mach ib_mach_hp300, ib_mach_hp700, ib_mach_i386, +#ifdef __minix + ib_mach_i686, +#endif ib_mach_landisk, ib_mach_macppc, ib_mach_news68k, @@ -77,6 +80,9 @@ struct ib_mach * const machines[] = { &ib_mach_hp300, &ib_mach_hp700, &ib_mach_i386, +#ifdef __minix + &ib_mach_i686, +#endif &ib_mach_landisk, &ib_mach_macppc, &ib_mach_news68k, diff --git a/usr.sbin/installboot/minixfs3.c b/usr.sbin/installboot/minixfs3.c new file mode 100644 index 000000000..ab7607ee4 --- /dev/null +++ b/usr.sbin/installboot/minixfs3.c @@ -0,0 +1,142 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef DFL_SECSIZE +#define DFL_SECSIZE 512 +#endif + +#define MFS_FIRST_SUBP_OFFSET 32 + +static int minixfs3_read_mbr(const char* device, char* buf) +{ + int fd; + int bytes; + int n; + + fd = open(device, O_RDONLY); + if (fd == -1) { + fprintf(stderr, "Can't open %s: %s\n", device, strerror(errno)); + return 1; + } + + if (lseek(fd, MBR_PART_OFFSET, SEEK_SET) != MBR_PART_OFFSET) { + fprintf(stderr, "Can't seek in %s to %d: %s\n", + device, MBR_PART_OFFSET, strerror(errno)); + close(fd); + return 1; + } + + bytes = DFL_SECSIZE - MBR_PART_OFFSET; + + if ((n = read(fd, buf, bytes)) != bytes) { + fprintf(stderr, "Can't read %d bytes from %s, %d read instead" + ": %s\n", + bytes, device, n, strerror(errno)); + close(fd); + return 1; + } + + if ((uint8_t)buf[bytes-2] != 0x55 || (uint8_t)buf[bytes-1] != 0xAA) { + fprintf(stderr, "No MBR on %s, signature is %x\n", + device, *(uint16_t*)(&buf[bytes-2])); + close(fd); + return 1; + } + + close(fd); + return 0; +} + + +int minixfs3_is_minix_partition(const char* partition) +{ + char buf[DFL_SECSIZE]; /* part table + signature */ + int name_length = strlen(partition); + + /* partition must be 0-3 */ + if (atol(&partition[name_length-1]) >= 4) { + fprintf(stderr, "Wrong device %s, must be /.../cxdyp[0-3]\n", + partition); + return 0; + } + + /* it should be partition device, not disk */ + if (partition[name_length-2] != 'p') { + fprintf(stderr, "Wrong device %s, must be /.../cxdyp[0-3]\n", + partition); + return 0; + } + + /* MINIX 3 partition with current scheme *must* have subpartitions, + * thus MBR has signature. minixfs3_read_mbr checks the signature. + */ + if (minixfs3_read_mbr(partition, buf)) + return 0; + return 1; +} + +/* bootxx from NetBSD is ~8Kb, and old MINIX installations have just + * 1Kb of space for their bootblock. Check if there is enough space + * to install bootxx_minixfs3. New installation should have 16Kb before + * the first subpartition. + */ +int minixfs3_has_bootblock_space(const char* partition) +{ + char buf[DFL_SECSIZE]; /* part table + signature */ + char disk[NAME_MAX]; + struct mbr_partition *part; + uint32_t first_subpartition = (uint32_t) ~0; + uint32_t parent_partition = 0; + int i; + int name_length = strlen(partition); + + /* partition must be 0-3 */ + if (atol(&partition[name_length-1]) >= 4) { + fprintf(stderr, "Wrong device %s, must be /.../cxdyp[0-3]\n", + partition); + exit(1); + } + /* it should be partition device, not disk */ + if (partition[name_length-2] != 'p') { + fprintf(stderr, "Wrong device %s, must be /.../cxdyp[0-3]\n", + partition); + exit(1); + } + + if (minixfs3_read_mbr(partition, buf)) + exit(1); + + part = (struct mbr_partition *) buf; + + for (i = 0; i < 4; i++) { + if (part[i].mbrp_size && part[i].mbrp_start < first_subpartition) + first_subpartition = part[i].mbrp_start; + } + + strncpy(disk, partition, name_length - 2); + disk[name_length - 2] = '\0'; + + if (minixfs3_read_mbr(disk, buf)) + exit(1); + + for (i = 0; i < 4; i++) { + struct mbr_partition *p = &part[i]; + if (p->mbrp_size && p->mbrp_start <= first_subpartition + && (p->mbrp_start + p->mbrp_size) > first_subpartition) { + parent_partition = p->mbrp_start; + break; + } + } + + if ((first_subpartition - parent_partition) < MFS_FIRST_SUBP_OFFSET) + return 0; + else + return 1; +} -- 2.44.0