History log of /netbsd-current/usr.sbin/installboot/arch/i386.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.43 05-Dec-2021 msaitoh

s/filesytem/filesystem/ in comment.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 netbsd-9-2-RELEASE cjep_staticlib_x-base netbsd-9-1-RELEASE phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609
# 1.42 07-May-2019 thorpej

Use designated initializers for struct ib_mach.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.41 23-Jun-2018 kamil

branches: 1.41.2;
Fix integer overflow in installboot(8)

Add a sanity check of the disk_buf first three bytes. The original code on
a disk with nul bytes was causing integer overflow and thus calling the
memcmp(3) functin in is_zero() with enormous length.

Verity that the 0th byte is JMP, 1th a signed byte >=9 to prevent overflow
and 2th byte NOP.

Add a comment explaining the check.

Detected with MKSANITIZER and ASan.


Revision tags: netbsd-7-2-RELEASE pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base tls-maxphys-base
# 1.40 14-Jun-2013 msaitoh

branches: 1.40.20; 1.40.26;
Remove trailng whitespaces.


Revision tags: agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5 yamt-pagecache-base4
# 1.39 06-Apr-2012 gson

branches: 1.39.2;
When printing the list of valid console names, don't treat the consoles[]
array as NULL terminated, because it's not.


# 1.38 10-Mar-2012 dsl

Some FAT16 filesystems don't have 'hidden sectors' correctly set to
the offset of the filesystem on the disk.
Let '-b s1blk' be used to fix the value.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.37 14-Aug-2011 christos

branches: 1.37.2;
fix various gcc-4.5 warnings


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 1.36 17-Jan-2010 drochner

Invert the flag bits to control module loading: rename
LOADMODULES->NOMODULES and READBOOTCONF->NOBOOTCONF.
This way, the default value (0) wired into old bootxx_* and installed
to file systems remains valid and we avoid problems on partial updates.


# 1.35 14-Jan-2010 drochner

On i386/amd64, define two flag bits in the boot parameters which control
whether modules are loaded and whether boot.cfg is evaluated, and
set both to "off" per default in the PXE bootloader.
Extend "installboot" to toggle the bits.
This way, pxeboot works with existing dhcp server setups (and as
described in the manpage) out of the box. Also, boot.cfg reading
involves a stat() call which is horribly inefficient with the
TFTP pseudo file system.


# 1.34 23-Dec-2009 mbalmer

Fix typo in comments, no code change.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 1.33 07-May-2009 lukem

refer to FFSv1 instead of UFSv1


# 1.32 05-Apr-2009 lukem

fix sign-compare issues


# 1.31 18-Feb-2009 christos

CID 4393: plug memory leak.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.30 28-Apr-2008 martin

branches: 1.30.8;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.29 06-Mar-2008 dsl

branches: 1.29.2;
Add a large warning about the possible side effect of using '-f'.


Revision tags: matt-armv6-prevmlocking cube-autoconf-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.28 23-Jun-2007 christos

branches: 1.28.4; 1.28.8;
Don't use __arraycount because this is a 700L, and toolz have messed up
includes.


# 1.27 23-Jun-2007 dogcow

unb0rk tools/ builds on systems that don't have __arraycount() defined.


# 1.26 23-Jun-2007 christos

PR/36527: Greg A. Woods: installboot(8) doesn't allow for the valid
consdev=auto setting


# 1.25 15-Feb-2007 dsl

Add a -f (force) parameter to installboot(8).
If specified then checks on the disks BPB are not done, and any existing BPB
is deleted.
This is needed soince newfs(8) doesn't overwrite the BPB - which is basically
the FAT superblock.
Update documentation and add an example of using bootxx_fat16.


# 1.24 07-Jan-2007 dogcow

%d -> %ld, so that building on alpha doesn't fail. (also print more useful
errors - x bytes written, should be y.)


# 1.23 06-Jan-2007 dsl

Support for non-512 byte media.
Automatically enable writes to the 'labelsector' if necessary.
Detect and recover from problems with the write-protected 'labelsector'
stopping writes to nearby sectors when the non-raw disk device is used.
Support the installation of 512-byte pbr boot code (eg fatboot).
Verify that there is enough reserved space in the bpb (if not all zeros) to
avoid overwriting the start of FAT filesystems.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base abandoned-netbsd-4-base netbsd-4-base
# 1.22 18-Feb-2006 dsl

Move the MD definitions into the MD files, leaving machines.c with just
a list of the supported machines.


# 1.21 30-Jan-2006 dsl

Fix the detection of the bootstrap magic number when run on big-endian systems.
Correct another typo.


# 1.20 24-Jan-2006 dsl

Fix spelling mistake in message


# 1.19 11-Nov-2005 dsl

Add a -e (edit) option to allow the bootstrap options of an installed
bootstrap or a file containing such a bootstrap to be changed/displayed.
In particular this will (soon) let you modify the parameters for pxeboot.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.18 16-Aug-2004 yamt

revert a part of the previous. (uint -> u_int)
to make tools/installboot compile again.


# 1.17 15-Aug-2004 dsl

Add an option to set bp_consaddr (serial console IO port address)
Only complain about small patch area if we would write something non-zero there.


# 1.16 20-Jun-2004 jmc

Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944


Revision tags: netbsd-2-0-base
# 1.15 14-Mar-2004 lukem

branches: 1.15.2;
fix a typo in a comment, and expand the description of x86_boot_params.


# 1.14 13-Mar-2004 dsl

Add a -o keymap=zyz option that will set the boot keymap.
If a character in the map is typed, it gets replaced by the one following.


# 1.13 27-Oct-2003 lukem

fix typo in comment


# 1.12 27-Oct-2003 lukem

Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).


# 1.11 14-Oct-2003 lukem

Instead of requiring that the BPB is always the FAT32 one, check the
first three bytes to determine how much of the BPB to preserve.
Supported values:
eb 3c 90 FAT16 BPB
eb 58 90 FAT32 BPB
(anything else) don't preserve any BPB

This is because the BPB is generally only the FAT16 one except in the
bootxx_msdos case, where it's the larger FAT32 one.


# 1.10 10-Oct-2003 lukem

Fix compile error on powerpc. Noted by Juergen Hannken-Illjes in private mail.


# 1.9 08-Oct-2003 lukem

Overhaul MBR handling (part 1):

<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.

As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.

<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).

amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.

* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).

* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.

* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.

* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.

* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.

installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)

mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.


Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).


# 1.8 06-Oct-2003 lukem

Replace BP_* with I386_BP_FLAGS_*, for consistency with other stuff in
<sys/bootblock.h>
(CONSDEV_ should be converted as well, but that's more intrusive...)


# 1.7 04-Jul-2003 dsl

Add some htole32() for host endianness independance


# 1.6 08-May-2003 petrov

Format fixes.


# 1.5 18-Apr-2003 bjh21

Use <md5.h> rather than <sys/md5.h>. This is what the man page tells us to
do, and is required for cross-compiling since libnbcompat doesn't provide
<sys/md5.h>.


# 1.4 16-Apr-2003 briggs

Protect use of __RCSID() with a check to ensure that it's defined.
Suggested by Ian Lance Taylor on tech-userlevel@ to help cross-compilation
on Red Hat 7.3.


# 1.3 15-Apr-2003 dsl

Use htole32 so host endianness independant


# 1.2 15-Apr-2003 dsl

Change the way -o options are parsed, now done in MI code with a check after
all the options have been processed that they are supported my the
specific system.
Add i386 MD options (console, password, speed and timeout)
(Approved by christos and lukem)


# 1.1 09-Apr-2003 dsl

Add support for 'new' format i386 bootxx code


# 1.42 07-May-2019 thorpej

Use designated initializers for struct ib_mach.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.41 23-Jun-2018 kamil

Fix integer overflow in installboot(8)

Add a sanity check of the disk_buf first three bytes. The original code on
a disk with nul bytes was causing integer overflow and thus calling the
memcmp(3) functin in is_zero() with enormous length.

Verity that the 0th byte is JMP, 1th a signed byte >=9 to prevent overflow
and 2th byte NOP.

Add a comment explaining the check.

Detected with MKSANITIZER and ASan.


Revision tags: netbsd-7-2-RELEASE pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base tls-maxphys-base
# 1.40 14-Jun-2013 msaitoh

branches: 1.40.20; 1.40.26;
Remove trailng whitespaces.


Revision tags: agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5 yamt-pagecache-base4
# 1.39 06-Apr-2012 gson

branches: 1.39.2;
When printing the list of valid console names, don't treat the consoles[]
array as NULL terminated, because it's not.


# 1.38 10-Mar-2012 dsl

Some FAT16 filesystems don't have 'hidden sectors' correctly set to
the offset of the filesystem on the disk.
Let '-b s1blk' be used to fix the value.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.37 14-Aug-2011 christos

branches: 1.37.2;
fix various gcc-4.5 warnings


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 1.36 17-Jan-2010 drochner

Invert the flag bits to control module loading: rename
LOADMODULES->NOMODULES and READBOOTCONF->NOBOOTCONF.
This way, the default value (0) wired into old bootxx_* and installed
to file systems remains valid and we avoid problems on partial updates.


# 1.35 14-Jan-2010 drochner

On i386/amd64, define two flag bits in the boot parameters which control
whether modules are loaded and whether boot.cfg is evaluated, and
set both to "off" per default in the PXE bootloader.
Extend "installboot" to toggle the bits.
This way, pxeboot works with existing dhcp server setups (and as
described in the manpage) out of the box. Also, boot.cfg reading
involves a stat() call which is horribly inefficient with the
TFTP pseudo file system.


# 1.34 23-Dec-2009 mbalmer

Fix typo in comments, no code change.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 1.33 07-May-2009 lukem

refer to FFSv1 instead of UFSv1


# 1.32 05-Apr-2009 lukem

fix sign-compare issues


# 1.31 18-Feb-2009 christos

CID 4393: plug memory leak.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.30 28-Apr-2008 martin

branches: 1.30.8;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.29 06-Mar-2008 dsl

branches: 1.29.2;
Add a large warning about the possible side effect of using '-f'.


Revision tags: matt-armv6-prevmlocking cube-autoconf-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.28 23-Jun-2007 christos

branches: 1.28.4; 1.28.8;
Don't use __arraycount because this is a 700L, and toolz have messed up
includes.


# 1.27 23-Jun-2007 dogcow

unb0rk tools/ builds on systems that don't have __arraycount() defined.


# 1.26 23-Jun-2007 christos

PR/36527: Greg A. Woods: installboot(8) doesn't allow for the valid
consdev=auto setting


# 1.25 15-Feb-2007 dsl

Add a -f (force) parameter to installboot(8).
If specified then checks on the disks BPB are not done, and any existing BPB
is deleted.
This is needed soince newfs(8) doesn't overwrite the BPB - which is basically
the FAT superblock.
Update documentation and add an example of using bootxx_fat16.


# 1.24 07-Jan-2007 dogcow

%d -> %ld, so that building on alpha doesn't fail. (also print more useful
errors - x bytes written, should be y.)


# 1.23 06-Jan-2007 dsl

Support for non-512 byte media.
Automatically enable writes to the 'labelsector' if necessary.
Detect and recover from problems with the write-protected 'labelsector'
stopping writes to nearby sectors when the non-raw disk device is used.
Support the installation of 512-byte pbr boot code (eg fatboot).
Verify that there is enough reserved space in the bpb (if not all zeros) to
avoid overwriting the start of FAT filesystems.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base abandoned-netbsd-4-base netbsd-4-base
# 1.22 18-Feb-2006 dsl

Move the MD definitions into the MD files, leaving machines.c with just
a list of the supported machines.


# 1.21 30-Jan-2006 dsl

Fix the detection of the bootstrap magic number when run on big-endian systems.
Correct another typo.


# 1.20 24-Jan-2006 dsl

Fix spelling mistake in message


# 1.19 11-Nov-2005 dsl

Add a -e (edit) option to allow the bootstrap options of an installed
bootstrap or a file containing such a bootstrap to be changed/displayed.
In particular this will (soon) let you modify the parameters for pxeboot.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.18 16-Aug-2004 yamt

revert a part of the previous. (uint -> u_int)
to make tools/installboot compile again.


# 1.17 15-Aug-2004 dsl

Add an option to set bp_consaddr (serial console IO port address)
Only complain about small patch area if we would write something non-zero there.


# 1.16 20-Jun-2004 jmc

Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944


Revision tags: netbsd-2-0-base
# 1.15 14-Mar-2004 lukem

branches: 1.15.2;
fix a typo in a comment, and expand the description of x86_boot_params.


# 1.14 13-Mar-2004 dsl

Add a -o keymap=zyz option that will set the boot keymap.
If a character in the map is typed, it gets replaced by the one following.


# 1.13 27-Oct-2003 lukem

fix typo in comment


# 1.12 27-Oct-2003 lukem

Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).


# 1.11 14-Oct-2003 lukem

Instead of requiring that the BPB is always the FAT32 one, check the
first three bytes to determine how much of the BPB to preserve.
Supported values:
eb 3c 90 FAT16 BPB
eb 58 90 FAT32 BPB
(anything else) don't preserve any BPB

This is because the BPB is generally only the FAT16 one except in the
bootxx_msdos case, where it's the larger FAT32 one.


# 1.10 10-Oct-2003 lukem

Fix compile error on powerpc. Noted by Juergen Hannken-Illjes in private mail.


# 1.9 08-Oct-2003 lukem

Overhaul MBR handling (part 1):

<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.

As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.

<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).

amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.

* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).

* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.

* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.

* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.

* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.

installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)

mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.


Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).


# 1.8 06-Oct-2003 lukem

Replace BP_* with I386_BP_FLAGS_*, for consistency with other stuff in
<sys/bootblock.h>
(CONSDEV_ should be converted as well, but that's more intrusive...)


# 1.7 04-Jul-2003 dsl

Add some htole32() for host endianness independance


# 1.6 08-May-2003 petrov

Format fixes.


# 1.5 18-Apr-2003 bjh21

Use <md5.h> rather than <sys/md5.h>. This is what the man page tells us to
do, and is required for cross-compiling since libnbcompat doesn't provide
<sys/md5.h>.


# 1.4 16-Apr-2003 briggs

Protect use of __RCSID() with a check to ensure that it's defined.
Suggested by Ian Lance Taylor on tech-userlevel@ to help cross-compilation
on Red Hat 7.3.


# 1.3 15-Apr-2003 dsl

Use htole32 so host endianness independant


# 1.2 15-Apr-2003 dsl

Change the way -o options are parsed, now done in MI code with a check after
all the options have been processed that they are supported my the
specific system.
Add i386 MD options (console, password, speed and timeout)
(Approved by christos and lukem)


# 1.1 09-Apr-2003 dsl

Add support for 'new' format i386 bootxx code


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.41 23-Jun-2018 kamil

Fix integer overflow in installboot(8)

Add a sanity check of the disk_buf first three bytes. The original code on
a disk with nul bytes was causing integer overflow and thus calling the
memcmp(3) functin in is_zero() with enormous length.

Verity that the 0th byte is JMP, 1th a signed byte >=9 to prevent overflow
and 2th byte NOP.

Add a comment explaining the check.

Detected with MKSANITIZER and ASan.


Revision tags: netbsd-7-2-RELEASE pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base tls-maxphys-base
# 1.40 14-Jun-2013 msaitoh

branches: 1.40.20; 1.40.26;
Remove trailng whitespaces.


Revision tags: agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5 yamt-pagecache-base4
# 1.39 06-Apr-2012 gson

branches: 1.39.2;
When printing the list of valid console names, don't treat the consoles[]
array as NULL terminated, because it's not.


# 1.38 10-Mar-2012 dsl

Some FAT16 filesystems don't have 'hidden sectors' correctly set to
the offset of the filesystem on the disk.
Let '-b s1blk' be used to fix the value.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.37 14-Aug-2011 christos

branches: 1.37.2;
fix various gcc-4.5 warnings


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 1.36 17-Jan-2010 drochner

Invert the flag bits to control module loading: rename
LOADMODULES->NOMODULES and READBOOTCONF->NOBOOTCONF.
This way, the default value (0) wired into old bootxx_* and installed
to file systems remains valid and we avoid problems on partial updates.


# 1.35 14-Jan-2010 drochner

On i386/amd64, define two flag bits in the boot parameters which control
whether modules are loaded and whether boot.cfg is evaluated, and
set both to "off" per default in the PXE bootloader.
Extend "installboot" to toggle the bits.
This way, pxeboot works with existing dhcp server setups (and as
described in the manpage) out of the box. Also, boot.cfg reading
involves a stat() call which is horribly inefficient with the
TFTP pseudo file system.


# 1.34 23-Dec-2009 mbalmer

Fix typo in comments, no code change.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 1.33 07-May-2009 lukem

refer to FFSv1 instead of UFSv1


# 1.32 05-Apr-2009 lukem

fix sign-compare issues


# 1.31 18-Feb-2009 christos

CID 4393: plug memory leak.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.30 28-Apr-2008 martin

branches: 1.30.8;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.29 06-Mar-2008 dsl

branches: 1.29.2;
Add a large warning about the possible side effect of using '-f'.


Revision tags: matt-armv6-prevmlocking cube-autoconf-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.28 23-Jun-2007 christos

branches: 1.28.4; 1.28.8;
Don't use __arraycount because this is a 700L, and toolz have messed up
includes.


# 1.27 23-Jun-2007 dogcow

unb0rk tools/ builds on systems that don't have __arraycount() defined.


# 1.26 23-Jun-2007 christos

PR/36527: Greg A. Woods: installboot(8) doesn't allow for the valid
consdev=auto setting


# 1.25 15-Feb-2007 dsl

Add a -f (force) parameter to installboot(8).
If specified then checks on the disks BPB are not done, and any existing BPB
is deleted.
This is needed soince newfs(8) doesn't overwrite the BPB - which is basically
the FAT superblock.
Update documentation and add an example of using bootxx_fat16.


# 1.24 07-Jan-2007 dogcow

%d -> %ld, so that building on alpha doesn't fail. (also print more useful
errors - x bytes written, should be y.)


# 1.23 06-Jan-2007 dsl

Support for non-512 byte media.
Automatically enable writes to the 'labelsector' if necessary.
Detect and recover from problems with the write-protected 'labelsector'
stopping writes to nearby sectors when the non-raw disk device is used.
Support the installation of 512-byte pbr boot code (eg fatboot).
Verify that there is enough reserved space in the bpb (if not all zeros) to
avoid overwriting the start of FAT filesystems.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base abandoned-netbsd-4-base netbsd-4-base
# 1.22 18-Feb-2006 dsl

Move the MD definitions into the MD files, leaving machines.c with just
a list of the supported machines.


# 1.21 30-Jan-2006 dsl

Fix the detection of the bootstrap magic number when run on big-endian systems.
Correct another typo.


# 1.20 24-Jan-2006 dsl

Fix spelling mistake in message


# 1.19 11-Nov-2005 dsl

Add a -e (edit) option to allow the bootstrap options of an installed
bootstrap or a file containing such a bootstrap to be changed/displayed.
In particular this will (soon) let you modify the parameters for pxeboot.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.18 16-Aug-2004 yamt

revert a part of the previous. (uint -> u_int)
to make tools/installboot compile again.


# 1.17 15-Aug-2004 dsl

Add an option to set bp_consaddr (serial console IO port address)
Only complain about small patch area if we would write something non-zero there.


# 1.16 20-Jun-2004 jmc

Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944


Revision tags: netbsd-2-0-base
# 1.15 14-Mar-2004 lukem

branches: 1.15.2;
fix a typo in a comment, and expand the description of x86_boot_params.


# 1.14 13-Mar-2004 dsl

Add a -o keymap=zyz option that will set the boot keymap.
If a character in the map is typed, it gets replaced by the one following.


# 1.13 27-Oct-2003 lukem

fix typo in comment


# 1.12 27-Oct-2003 lukem

Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).


# 1.11 14-Oct-2003 lukem

Instead of requiring that the BPB is always the FAT32 one, check the
first three bytes to determine how much of the BPB to preserve.
Supported values:
eb 3c 90 FAT16 BPB
eb 58 90 FAT32 BPB
(anything else) don't preserve any BPB

This is because the BPB is generally only the FAT16 one except in the
bootxx_msdos case, where it's the larger FAT32 one.


# 1.10 10-Oct-2003 lukem

Fix compile error on powerpc. Noted by Juergen Hannken-Illjes in private mail.


# 1.9 08-Oct-2003 lukem

Overhaul MBR handling (part 1):

<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.

As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.

<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).

amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.

* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).

* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.

* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.

* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.

* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.

installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)

mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.


Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).


# 1.8 06-Oct-2003 lukem

Replace BP_* with I386_BP_FLAGS_*, for consistency with other stuff in
<sys/bootblock.h>
(CONSDEV_ should be converted as well, but that's more intrusive...)


# 1.7 04-Jul-2003 dsl

Add some htole32() for host endianness independance


# 1.6 08-May-2003 petrov

Format fixes.


# 1.5 18-Apr-2003 bjh21

Use <md5.h> rather than <sys/md5.h>. This is what the man page tells us to
do, and is required for cross-compiling since libnbcompat doesn't provide
<sys/md5.h>.


# 1.4 16-Apr-2003 briggs

Protect use of __RCSID() with a check to ensure that it's defined.
Suggested by Ian Lance Taylor on tech-userlevel@ to help cross-compilation
on Red Hat 7.3.


# 1.3 15-Apr-2003 dsl

Use htole32 so host endianness independant


# 1.2 15-Apr-2003 dsl

Change the way -o options are parsed, now done in MI code with a check after
all the options have been processed that they are supported my the
specific system.
Add i386 MD options (console, password, speed and timeout)
(Approved by christos and lukem)


# 1.1 09-Apr-2003 dsl

Add support for 'new' format i386 bootxx code